mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
MDEV-29129: Performance regression starting in 10.6: select order by limit ...
The cause of regression was handling for ROWNUM() function. For queries like SELECT ROWNUM() FROM ... ORDER BY ... ROWNUM() should be computed before the ORDER BY. The computation was moved to be before the ORDER BY for any entries in the select list that had RAND_TABLE_BIT set. This had a negative impact on queries in form: SELECT sp_func() FROM t1 ORDER BY ... LIMIT n where sp_func() is NOT declared as DETERMINISTIC (and so has RAND_TABLE_BIT set). The fix is to require evaluation for sorting only for the ROWNUM() function. Functions that just have RAND_TABLE_BIT() can be computed after ORDER BY ... LIMIT is applied. (think about a possible index that satisfies the ORDER BY clause. In that case, the the rows would be read in the needed order and we would stop after reading LIMIT rows, achieving the same effect).
This commit is contained in:
@ -372,14 +372,14 @@ insert into t1 (b) values (10), (30), (10), (10);
|
||||
set @var := 0;
|
||||
explain select if(b=@var, 999, b) , @var := b from t1 order by b;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using temporary; Using filesort
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using filesort
|
||||
set @var := 0;
|
||||
select if(b=@var, 999, b) , @var := b from t1 order by b;
|
||||
if(b=@var, 999, b) @var := b
|
||||
10 10
|
||||
10 10
|
||||
30 30
|
||||
999 10
|
||||
999 10
|
||||
drop table t1;
|
||||
create temporary table t1 (id int);
|
||||
insert into t1 values (2), (3), (3), (4);
|
||||
|
Reference in New Issue
Block a user