开发者

mysql index optimization problem

开发者 https://www.devze.com 2023-03-23 10:36 出处:网络
I have a query like below. SE开发者_如何学PythonLECT a,b,c,d FROM table_name WHERE e=1 AND f=0 GROUP BY d

I have a query like below.

SE开发者_如何学PythonLECT a,b,c,d 
FROM table_name  
WHERE e=1 AND f=0 
GROUP BY d 
ORDER BY id DESC LIMIT 5

when I indexed (e,f,d) query time : 4 sec.

when I indexed (d,e,f) query time : 20 sec.

So that I understand that index colums ordering is important. Which index would be better for mysql?


Indexes should first satisfy the where clause, then the group or order clause. Always use EXPLAIN on your query to see how it is performed

0

精彩评论

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