mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
MDEV-16934 Query with very large IN clause lists runs slowly
This patch introduces support for the system variable eq_range_index_dive_limit that existed in MySQL starting from 5.6. The variable sets a limit for index dives into equality ranges. Index dives are performed by optimizer to estimate the number of rows in range scans. Index dives usually provide good estimate but they are pretty expensive. To estimate the number of rows in equality ranges statistical data on indexes can be employed. Its usage gives not so good estimates but it's cheap. So if the number of equality dives required by an index scan exceeds the set limit no dives for equality ranges are performed by the optimizer for this index. As the new system variable is introduced in a stable version the default value for it is set to a special value meaning there is no limit for the number of index dives performed by the optimizer. The patch partially uses the MySQL code for WL 5957 'Statistics-based Range optimization for many ranges'.
This commit is contained in:
@ -3002,5 +3002,46 @@ deallocate prepare stmt;
|
||||
set optimizer_switch=@save_optimizer_switch;
|
||||
drop table t1,t2,t3;
|
||||
#
|
||||
# MDEV-16934: using system variable eq_range_index_dive_limit
|
||||
# to reduce the number of index dives
|
||||
#
|
||||
create table t1 (a int, b varchar(31), index idx(a));
|
||||
insert into t1 values
|
||||
(7,'xxxx'), (1,'yy'), (3,'aaa'), (1,'bbb'), (2,'zz'),
|
||||
(4,'vvvvv'), (7,'ddd'), (9,'zzzzz'), (1,'cc'), (5,'ffff');
|
||||
insert into t1 select a+10, concat(b,'zz') from t1;
|
||||
insert into t1 select a+15, concat(b,'yy') from t1;
|
||||
insert into t1 select a+100, concat(b,'xx') from t1;
|
||||
analyze table t1;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 analyze status OK
|
||||
select cast(count(a)/count(distinct a) as unsigned) as rec_per_key from t1;
|
||||
rec_per_key
|
||||
2
|
||||
set eq_range_index_dive_limit=0;
|
||||
explain select * from t1 where a in (8, 15, 31, 1, 9);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 range idx idx 5 NULL 7 Using index condition
|
||||
select * from t1 where a in (8, 15, 31, 1, 9);
|
||||
a b
|
||||
1 yy
|
||||
1 bbb
|
||||
1 cc
|
||||
9 zzzzz
|
||||
15 ffffzz
|
||||
set eq_range_index_dive_limit=2;
|
||||
explain select * from t1 where a in (8, 15, 31, 1, 9);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 range idx idx 5 NULL 10 Using index condition
|
||||
select * from t1 where a in (8, 15, 31, 1, 9);
|
||||
a b
|
||||
1 yy
|
||||
1 bbb
|
||||
1 cc
|
||||
9 zzzzz
|
||||
15 ffffzz
|
||||
set eq_range_index_dive_limit=default;
|
||||
drop table t1;
|
||||
#
|
||||
# End of 10.2 tests
|
||||
#
|
||||
|
Reference in New Issue
Block a user