1
0
mirror of https://github.com/MariaDB/server.git synced 2025-12-04 17:23:46 +03:00

MDEV-17761: Odd optimizer choice with ORDER BY LIMIT and condition selectivity

Make the "ORDER BY ... LIMIT n" optimizer take into account condition
selectivity data from EITS (not just from potential range accesses).
This commit is contained in:
Sergei Petrunia
2019-01-23 15:49:49 +03:00
parent 36a2a185fe
commit b7a784ae25
5 changed files with 145 additions and 0 deletions

View File

@@ -3253,3 +3253,40 @@ Warnings:
Note 1003 select `test`.`wings`.`id` AS `wing_id`,`test`.`wings`.`department_id` AS `department_id` from `test`.`wings` semi join (`test`.`books`) where `test`.`books`.`library_id` = 8663 and `test`.`books`.`scheduled_for_removal` = 0 and `test`.`wings`.`id` = `test`.`books`.`wings_id` order by `test`.`wings`.`id`
set optimizer_switch= @save_optimizer_switch;
DROP TABLE books, wings;
#
# MDEV-17761: Odd optimizer choice with ORDER BY LIMIT and condition selectivity
#
create table t1(a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2(a int);
insert into t2 select A.a + B.a* 10 + C.a * 100 from t1 A, t1 B, t1 C;
create table t3(a int);
insert into t3 select A.a + 1000 *B.a from t2 A, t1 B;
create table t4 (
a int,
b int,
c int,
filler1 char(255),
filler2 char(255),
key(a)
);
insert into t4 select a,a,a, a,a from t3;
set @tmp_h=@@histogram_size, @tmp_u=@@use_stat_tables,
@tmp_o=@@optimizer_use_condition_selectivity;
set histogram_size=100;
set use_stat_tables=preferably;
set optimizer_use_condition_selectivity=4;
analyze table t4 persistent for columns(b) indexes ();
Table Op Msg_type Msg_text
test.t4 analyze status Engine-independent statistics collected
test.t4 analyze status Table is already up to date
# rows must be around 1200, not 600:
explain extended
select * from t4 where b < 5000 order by a limit 600;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t4 index NULL a 5 NULL 1188 100.00 Using where
Warnings:
Note 1003 select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t4`.`c` AS `c`,`test`.`t4`.`filler1` AS `filler1`,`test`.`t4`.`filler2` AS `filler2` from `test`.`t4` where `test`.`t4`.`b` < 5000 order by `test`.`t4`.`a` limit 600
set histogram_size=@tmp_h, use_stat_tables=@tmp_u,
optimizer_use_condition_selectivity=@tmp_o;
drop table t1,t2,t3,t4;