[MDEV-11421] Wrong index selected by optimizer for WHERE + ORDER BY Created: 2016-11-29 Updated: 2017-02-16 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.1.19 |
| Fix Version/s: | 10.1 |
| Type: | Bug | Priority: | Major |
| Reporter: | Nochum Sossonko | Assignee: | Sergei Petrunia |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | order-by-optimization | ||
| Environment: |
Ubuntu 14.04 LTS |
||
| Description |
|
For a query like:
The query optimizer returns:
The query takes a couple of seconds to complete. If I just add an index hint to PRIMARY on the parts table (alias `a`), the query takes 0.00 sec to complete. Every attribute used in the example is indexed. |
| Comments |
| Comment by Elena Stepanova [ 2016-11-30 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Please paste the output of SHOW CREATE TABLE ... and SHOW INDEX IN ... for all involved tables. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Nochum Sossonko [ 2016-11-30 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Nochum Sossonko [ 2017-01-03 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
If I remove the the index on `logins`.`type` the plan is much better (uses `a`.`id` with no file sorting). I need that index though for other queries, so I'm really not sure what to do here. Index hinting is not really an option for me in my application. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Nochum Sossonko [ 2017-01-10 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
If anyone can think of a workaround (outside of index hinting) I'd greatly appreciate it. Some way to get the query planner to stick with the primary and eq_ref the rest. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Nochum Sossonko [ 2017-02-16 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I think this is the same (or very similar) as MDEV-8306 |