[MDEV-6081] ORDER BY+ref(const): selectivity is very incorrect (MySQL Bug#14338686) Created: 2014-04-11 Updated: 2014-04-12 Resolved: 2014-04-12 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 10.0.10 |
| Fix Version/s: | 10.0.11 |
| Type: | Bug | Priority: | Major |
| Reporter: | Sergei Petrunia | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
The optimizer may make a very wrong choice in select ... where key1=const ORDER BY key2. This bug originates from me analyzing the testcase from Create the test dataset:
Then run the query:
Query plan in MariaDB:
This is a very inefficient plan. Assume key1 and key2 are not correlated. The plan shows that we will use full index scan on "key2". However, we know that we need to find a record that matches condition "tsubq.key1 = t1.a", which is very selective. We will have to scan a lot of rows before finding a match. It is much cheaper to use ref access on key1 and then use filesort. MySQL has fixed this in 5.6. Starting from 5.6, one gets:
|
| Comments |
| Comment by Sergei Petrunia [ 2014-04-12 ] |
|
Fix pushed to 10.0 tree |