Bug #41135 | USE INDEX FOR ORDER BY hint has no effect for LIMIT n queries | ||
---|---|---|---|
Submitted: | 30 Nov 2008 14:10 | Modified: | 11 Dec 2008 14:11 |
Reporter: | Sergey Petrunya | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
Version: | 5.1, 6.0 | OS: | Any |
Assigned to: | Georgi Kodinov | CPU Architecture: | Any |
[30 Nov 2008 14:10]
Sergey Petrunya
[30 Nov 2008 16:17]
MySQL Verification Team
Thank you for the bug report.
[11 Dec 2008 14:11]
Georgi Kodinov
USE INDEX FOR GROUP BY is just telling the optimizer which indexes it *can* use. The optimizer is free to decide whether to use an index or not. FORCE INDEX FOR GROUP BY according to our docs (http://dev.mysql.com/doc/refman/5.1/en/index-hints.html) : "... acts like USE INDEX (index_list) but with the addition that a table scan is assumed to be very expensive. In other words, a table scan is used only if there is no way to use one of the given indexes to find rows in the table." I've replaced USE INDEX with FORCE INDEX in your example and I'm getting them both to prefer the index over the table scan: explain select * from t1 force index for order by (a) where a+1 >5 order by a limit 1 id 1 select_type SIMPLE table t1 type index possible_keys NULL key a key_len 5 ref NULL rows 1 Extra Using where explain select * from t1 force index for order by (a) where a+1 >5 order by a limit 10;; id 1 select_type SIMPLE table t1 type index possible_keys NULL key a key_len 5 ref NULL rows 10 Extra Using where
[12 Dec 2008 15:51]
Sergey Petrunya
Agree with Joro's verdict. The described behavior is not a bug.