使用临时文件,使用带有 order 和 group by 的文件排序
查询
SELECT *
FROM table11
WHERE table1.field1 = 1
GROUP BY table1.field2
ORDER BY table1.field3 DESC
我尝试了所有这些
(field1,field2,field3)
(field1,field3,field2)
索引,但仍然解释计划显示使用临时和使用文件排序。
有什么解决办法吗?
Query
SELECT *
FROM table11
WHERE table1.field1 = 1
GROUP BY table1.field2
ORDER BY table1.field3 DESC
I tried all these
(field1,field2,field3)
(field1,field3,field2)
indexes but still explain plan shows using temporary and using filesort.
Any solution ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在尝试按 field3 对数据进行排序,该字段不属于 group by 子句。这意味着field3参与了分组过程,并返回field3的随机值,因此文件排序是不可避免的。
在这种情况下,最好的索引是
(field1, field2)
。You are trying to sort the data by field3 which is not part of group by clause. This means that field3 participates in the process of grouping which returns random values of field3, so the filesort is inevitable.
In this case the best possible index is
(field1, field2)
.