开发者

Using temporary, Using filesort with order and group by

Query

SELECT *
FRO开发者_运维知识库M 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 ?


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜