[MDEV-7447] Optimizer choose different index depends on scan rows in ORDER BY DESC Created: 2015-01-12 Updated: 2021-12-02 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.0.15, 10.4.21 |
| Fix Version/s: | 10.4 |
| Type: | Bug | Priority: | Minor |
| Reporter: | Benjamin Lin | Assignee: | Sergei Petrunia |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||||||
| Description |
|
I am not sure if this is related to size: 110G there are two secondary indexes/columns involving in this issue, one is userid ( INT ), one is access ( datetime ) example query:
So if the scan rows are little, optimizer will just use 'userid' index to retrieve the rows.
However, if we hit some userids that have more historical data, then optimizer intends to use 'access' index to help in sorting and retrieving rows in the same time if my understanding is correct.
Apparently, the second execution plan runs forever, > 1 hour, but the first execution plan runs < 7 secs. I have to 'FORCE INDEX (userid)' to make sure a stable execution plan, but maybe there is more thing we can consider in this kind of optimization like checking the size of 'access' index before using it or something like that? |
| Comments |
| Comment by Brad Jorgensen [ 2015-02-26 ] |
|
This behavior is related to the optimizer not knowing enough about the selectivity of the non-ordering index in relation to the ordering index's ranges as with |