Bug #57599 | ORDER BY .. LIMIT stops using a key after removing partitioning on a table | ||
---|---|---|---|
Submitted: | 20 Oct 2010 11:59 | Modified: | 28 Oct 2010 18:31 |
Reporter: | Elena Stepanova | Email Updates: | |
Status: | Won't fix | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
Version: | 5.1, 5.5 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[20 Oct 2010 11:59]
Elena Stepanova
[28 Oct 2010 18:31]
Konstantin Osipov
This is not a bug. The optimizer is making the right choice. InnoDB stores a secondary index separately. Since you perform ORDER BY k, but SELECT all columns, InnoDB has to scan twice as many pages to retrieve the result if an index is used. A full table scan in your case is fully justified. Try adding more rows to the table, and you'll notice that the optimizer chooses a different plan. I agree that the effect of partitioning is not obvious. Perhaps partition pruning is causing the change in the plan.
[31 Oct 2010 12:52]
Elena Stepanova
Okay. I found the effect surprising mostly because if I create the table without partitioning from the start, the index is used, so it was not even partitioning itself, but the operation of removing partitioning that seemed to be causing the change in the plan; so I was wondering if the behavior was expected. However, it is indeed not a problem in itself as there are only few rows in the table.