mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-9750: Quick memory exhaustion with 'extended_keys=on' ...
(Variant #5, full patch, for 10.5) Do not produce SEL_ARG graphs that would yield huge numbers of ranges. Introduce a concept of SEL_ARG graph's "weight". If we are about to produce a graph whose "weight" exceeds the limit, remove the parts of SEL_ARG graph that represent the biggest key parts. Do so until the graph's is within the limit. Includes - debug code to verify SEL_ARG graph weight - A user-visible @@optimizer_max_sel_arg_weight to control the optimization - Logging the optimization into the optimizer trace.
This commit is contained in:
@ -31,3 +31,69 @@ from information_schema.optimizer_trace;
|
||||
set optimizer_trace=@tmp_21958;
|
||||
|
||||
drop table t2;
|
||||
--echo #
|
||||
--echo # MDEV-9750: Quick memory exhaustion with 'extended_keys=on'...
|
||||
--echo #
|
||||
|
||||
create table t1 (
|
||||
kp1 int,
|
||||
kp2 int,
|
||||
kp3 int,
|
||||
kp4 int,
|
||||
key key1(kp1, kp2, kp3,kp4)
|
||||
);
|
||||
|
||||
insert into t1 values (1,1,1,1),(2,2,2,2),(3,3,3,3);
|
||||
analyze table t1;
|
||||
|
||||
show variables like 'optimizer_max_sel_arg_weight';
|
||||
|
||||
# 20 * 20 * 20 *20 = 400*400 = 160,000 ranges
|
||||
set @tmp_9750=@@optimizer_trace;
|
||||
set optimizer_trace=1;
|
||||
explain select * from t1 where
|
||||
kp1 in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20) and
|
||||
kp2 in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20) and
|
||||
kp3 in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20) and
|
||||
kp4 in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)
|
||||
;
|
||||
|
||||
set @json= (select json_detailed(JSON_EXTRACT(trace, '$**.range_scan_alternatives'))
|
||||
from information_schema.optimizer_trace);
|
||||
--echo # This will show 3-component ranges.
|
||||
--echo # The ranges were produced, but the optimizer has cut away kp4
|
||||
--echo # to keep the number of ranges at manageable level:
|
||||
select left(@json, 500);
|
||||
|
||||
--echo ## Repeat the above with low max_weight:
|
||||
set @tmp9750_weight=@@optimizer_max_sel_arg_weight;
|
||||
set optimizer_max_sel_arg_weight=20;
|
||||
explain select * from t1 where
|
||||
kp1 in (1,2,3,4,5,6,7,8,9,10) and
|
||||
kp2 in (1,2,3,4,5,6,7,8,9,10) and
|
||||
kp3 in (1,2,3,4,5,6,7,8,9,10) and
|
||||
kp4 in (1,2,3,4,5,6,7,8,9,10)
|
||||
;
|
||||
set @trace= (select trace from information_schema.optimizer_trace);
|
||||
set @json= json_detailed(json_extract(@trace, '$**.range_scan_alternatives'));
|
||||
select left(@json, 500);
|
||||
|
||||
set @json= json_detailed(json_extract(@trace, '$**.setup_range_conditions'));
|
||||
select left(@json, 2500);
|
||||
|
||||
--echo ## Repeat the above with a bit higher max_weight:
|
||||
set @tmp9750_weight=@@optimizer_max_sel_arg_weight;
|
||||
set optimizer_max_sel_arg_weight=120;
|
||||
explain select * from t1 where
|
||||
kp1 in (1,2,3,4,5,6,7,8,9,10) and
|
||||
kp2 in (1,2,3,4,5,6,7,8,9,10) and
|
||||
kp3 in (1,2,3,4,5,6,7,8,9,10) and
|
||||
kp4 in (1,2,3,4,5,6,7,8,9,10)
|
||||
;
|
||||
set @json= (select json_detailed(JSON_EXTRACT(trace, '$**.range_scan_alternatives'))
|
||||
from information_schema.optimizer_trace);
|
||||
select left(@json, 1500);
|
||||
|
||||
set optimizer_max_sel_arg_weight= @tmp9750_weight;
|
||||
set optimizer_trace=@tmp_9750;
|
||||
drop table t1;
|
||||
|
Reference in New Issue
Block a user