1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

Rewrite cost computation for filesort operations

This is a rework of how filesort calculates costs to allow functions
like test_if_skip_sort_order() to calculate the cost of filesort to
decide between filesort and using a key to resolve ORDER BY.

Changes:
- Split cost calculation of qsort + optional merge sort and priority queue
  to dedicated functions.
- Fixed some wrong calculations of cost in old code (use of log() instead
  of log2()).
- Added costs realted to fetching the rows if addon fields are not used.
- Updated get_merge_cost() to take into account that we are going to
  read data from temporary files in big chuncks (DISK_CHUNCK_SIZE (64K) and
  not in IO_SIZE (4K).
- More code documentation including various variables in Sort_param.

One effect of the cost update is that the cost of priority queue
with addon field has decreased slightly and is used in more cases.
When the rowid is large (like with InnoDB where rowid is the priority key),
using addon fields is in many cases preferable.

Reviewer: Monty
This commit is contained in:
Vicențiu Ciorbaru
2022-06-30 14:31:54 +03:00
committed by Sergei Petrunia
parent 06be2c64bc
commit 50e9f7aee5
8 changed files with 474 additions and 233 deletions

View File

@ -349,8 +349,15 @@ order by first_name, last_name
offset 1 rows
fetch first 3 rows with ties;
--source include/analyze-format.inc
analyze FORMAT=JSON
select * from t1
order by first_name, last_name
order by first_name, last_name, score
offset 2 rows
fetch first 3 rows only;
select * from t1
order by first_name, last_name, score
offset 2 rows
fetch first 3 rows only;
@ -360,7 +367,7 @@ offset 2 rows
fetch first 3 rows with ties;
select * from t1
order by first_name, last_name
order by first_name, last_name, score
offset 3 rows
fetch first 3 rows only;