mysql - 使用 ORDER BY 时 MySQL 查询速度慢

标签 mysql performance

我有这个查询:

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 这么慢吗?

编辑 解释: enter image description here

编辑2 指数 enter image description here

最佳答案

如果没有 ORDER BY,您的查询将在 10 行后终止(LIMIT)。

使用 ORDER BY 需要生成完整的结果集,排序,然后返回前 10 行。

关于mysql - 使用 ORDER BY 时 MySQL 查询速度慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31740896/

相关文章:

mysql - 连接相同的列名

mysql - 按受监管员工数量分组 SELECT 查询

Django 中的 Mysql OPTIMIZE TABLE 命令

python - python/cython 中绝对最快的查找

performance - 为了提高性能,建议安装 Perl 的方法是什么?

MySQL 以多个时间间隔执行查询

mysql - 如何更改带有 #(哈希)符号的 MySQL 列名

javascript - DevTools 性能工具中的解析、编译和评估是什么?

java - 从一个数组迭代计算多个结果

c# - foreach 与多个字段的总和