1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-18094: Query with order by limit picking index scan over filesort

In the function test_if_cheaper_ordering we make a decision if using an index is better than
using filesort for ordering. If we chose to do range access then in test_quick_select we
should make sure that cost for table scan is set to DBL_MAX so that it is not picked.
This commit is contained in:
Varun Gupta
2019-09-21 12:14:05 +05:30
parent 7a4019a1c7
commit 896974fc3d
6 changed files with 62 additions and 9 deletions

View File

@ -2420,12 +2420,16 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
records= head->stat_records();
if (!records)
records++; /* purecov: inspected */
scan_time= (double) records / TIME_FOR_COMPARE + 1;
read_time= (double) head->file->scan_time() + scan_time + 1.1;
if (head->force_index)
if (head->force_index || force_quick_range)
scan_time= read_time= DBL_MAX;
if (limit < records)
read_time= (double) records + scan_time + 1; // Force to use index
else
{
scan_time= (double) records / TIME_FOR_COMPARE + 1;
read_time= (double) head->file->scan_time() + scan_time + 1.1;
if (limit < records)
read_time= (double) records + scan_time + 1; // Force to use index
}
possible_keys.clear_all();