我有这个查询:
SELECT article.id
FROM article
INNER JOIN article_cCountry ON article.id = ID1 AND ID2 = 1
INNER JOIN user_cCountry ON article.uId = user_cCountry.ID1 AND user_cCountry.ID2 = 1
LEFT JOIN user ON article.uId = user.ID
WHERE article.released = "TRUE"
AND article.sDate < now()
AND article.cDate != "0000-00-00 00:00:00"
AND (article.eDate > now() OR article.eDate = 0)
AND ( (user.released = true) OR (article.uId = 0) )
ORDER BY article.cDate DESC
LIMIT 0, 10
查询大约需要 0.3 秒,没有 ORDER BY 只需大约 0.001 秒。
知道为什么 ORDER BY 这么慢吗?
最佳答案
如果没有 ORDER BY
,您的查询将在 10 行后终止(LIMIT)。
使用 ORDER BY
需要生成完整的结果集,排序,然后返回前 10 行。
关于mysql - 使用 ORDER BY 时 MySQL 查询速度慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31740896/