Bug #65792 an unecessary Using temporary in distinct query
Submitted: 3 Jul 2012 2:19 Modified: 3 Jul 2012 4:17
Reporter: xiaobin lin (OCA) Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: Optimizer Severity:S5 (Performance)
Version:5.1,5.5 OS:Any
Assigned to: CPU Architecture:Any
Tags: distinct, temporary

[3 Jul 2012 2:19] xiaobin lin
Look into this case http://ww1.sinaimg.cn/large/733db945gw1duinwgwjwij.jpg

When the optimizer decide whether the query can use the index (a,b), it use the function test_if_order_by_key. So the (b, a) in query can not use this index. 

It is distinct here, but not "order by b, a", perhaps it is better to use the way that ignore the column order in index ? 

This cause about 20% performance decrease.

How to repeat:
as above

Suggested fix:
Use a check function that ignore the order of column in index. In fact, when columns satisfy the left-most of an index,  the index can be used.
[3 Jul 2012 4:17] Valeriy Kravchuk
Sounds like a reasonable feature request.