我正在使用 MySQL,但此查询存在一些性能问题:
SELECT s.ID, headline, uId, teaser, hide_image_archiv, image, image_caption, date_format(cDate, '%d.%m.%Y | %H:%i Uhr') as date, channelid, channel_article.name FROM
(SELECT article.ID, uId, headline, teaser, cDate, image, image_caption, channelid, hide_image_archiv
FROM article
inner join article_cCountry on article.ID = ID1 and ID2 = 1
WHERE sDate < now()
and (eDate > now() or eDate = 0)
and released = 'TRUE'
and (uId in (select ID from user where released = 1) or uId = 0)
ORDER BY cDate DESC) AS s, channel_article where channelid = channel_article.ID AND channelid = 8 order by cDate desc LIMIT 3
解释:
大约需要 0.30 - 0.40 秒
有什么办法可以优化吗?
最佳答案
查询:
SELECT article.ID,
uId,
headline,
teaser,
cDate,
image,
image_caption,
channelid,
hide_image_archiv,
channel_article.name
FROM article
INNER JOIN article_cCountry ON article.ID = ID1
AND ID2 = 1
INNER JOIN channel_article
ON channelid = channel_article.ID
AND channelid = 8
WHERE sDate < now()
AND (eDate > now()
OR eDate = 0)
AND released = 'TRUE'
AND (uId IN
(SELECT ID
FROM USER
WHERE released = 1)
OR uId = 0)
ORDER BY cDate DESC LIMIT 3
关于php - 优化缓慢的 MySQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20561311/