[MDEV-23978] Select Query with order by on indexed columns is using filesort Created: 2020-10-19 Updated: 2021-10-06 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.4.13 |
| Fix Version/s: | 10.4 |
| Type: | Bug | Priority: | Major |
| Reporter: | Lakshmi Praveena | Assignee: | Sergei Petrunia |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
The below Query uses filesort and doesn't use Index scan (The index is `test_idx1` and was created on (`record_type`,`sequence`,`code_value`) )
Explain Plan -
The below Query uses Index scan (may be based of Primary Key)
Explain Plan -
I think the behavior is,
|
| Comments |
| Comment by Lakshmi Praveena [ 2020-10-27 ] | |||||
|
Is it possible to expedite this ticket ? i believe, this is a open bug in all MariaDB versions | |||||
| Comment by Sergei Petrunia [ 2021-03-19 ] | |||||
This makes sense. The ORDER BY clause matches the index test_idx1, but the query reads columns that are not part of that index. The query has no WHERE clause, so it will need to read all rows. Reading all rows through the secondary index will cause random index lookups to be made when fetching the row data. This is typically slower than doing a sequential read + sorting. The optimizer makes use of this assumption and so does not consider an index-based plan.
Right. In innodb, the primary key is clustered, so doing a full table scan is the same as doing a scan on PK. That is, we get rows in PK order for free. The optimizer makes use of this property and avoids sorting. | |||||
| Comment by Sergei Petrunia [ 2021-03-19 ] | |||||
|
I don't consider this behavior to be a bug.
Feel free to reopen if you can show this is really a performance problem. | |||||
| Comment by Lakshmi Praveena [ 2021-03-22 ] | |||||
|
Thanks @sergei petrunia for these details. i have about 60k records on the table and yes, its taking about 15-20 minutes to read all rows in sorted manner. I would like to re-open this bug because the performance problem do exists My requirement, is real all rows (~ 60k) on the table and write to file in a sorted manner. Please let me what else can be done. Thanks ! | |||||
| Comment by Lakshmi Praveena [ 2021-03-22 ] | |||||
|
@sergei petrunia Btw, I'm not able to re-open this bug. Appreciate your help, if you can re-open this bug on behalf of me | |||||
| Comment by Sergei Petrunia [ 2021-03-23 ] | |||||
|
(Just pressed the re-open button for now. Will get back to analyzing the provided info) | |||||
| Comment by Lakshmi Praveena [ 2021-03-23 ] | |||||
|
Thanks much Sergei Petrunia | |||||
| Comment by Lakshmi Praveena [ 2021-10-06 ] | |||||
|
Any updates on this would be highly appreciated !! |