mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-33314: Crash in calculate_cond_selectivity_for_table() with many columns
Variant#3: moved the logic out of create_key_parts_for_pseudo_indexes Range Analyzer (get_mm_tree functions) can only process up to MAX_KEY=64 indexes. The problem was that calculate_cond_selectivity_for_table used it to estimate selectivities for columns, and since a table can have > MAX_KEY columns, would invoke Range Analyzer with more than MAX_KEY "pseudo-indexes". Fixed by making calculate_cond_selectivity_for_table() to run Range Analyzer with at most MAX_KEY pseudo-indexes. If there are more columns to process, Range Analyzer will be invoked multiple times. Also made this change: - param.real_keynr[0]= 0; + MEM_UNDEFINED(¶m.real_keynr, sizeof(param.real_keynr)); Range Analyzer should have no use on real_keynr when it is run with pseudo-indexes.
This commit is contained in:
@ -105,17 +105,113 @@ from information_schema.optimizer_trace;
|
||||
set optimizer_trace=@tmp;
|
||||
drop table t0,t1,t10;
|
||||
|
||||
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
|
||||
set histogram_size=@save_histogram_size;
|
||||
set use_stat_tables= @save_use_stat_tables;
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # End of 10.4 tests
|
||||
--echo #
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-33314: Crash inside calculate_cond_selectivity_for_table() with many columns
|
||||
--echo #
|
||||
set optimizer_use_condition_selectivity= 4;
|
||||
set use_stat_tables= preferably;
|
||||
|
||||
let $N_CONDS=160;
|
||||
let $N_LAST_COND=159;
|
||||
--echo #
|
||||
--echo # create table t1 (col0 int, col1 int, col2 int, ...);
|
||||
--echo #
|
||||
let $create_tbl= create table t1 ( col0 int;
|
||||
let $i=1;
|
||||
|
||||
while ($i < $N_CONDS) {
|
||||
let $create_tbl= $create_tbl, col$i int;
|
||||
let $i=`select $i + 1`;
|
||||
}
|
||||
|
||||
let $create_tbl= $create_tbl );
|
||||
#echo $create_tbl;
|
||||
evalp $create_tbl;
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # insert into t1 select seq, ... seq from seq_1_to_10;
|
||||
--echo #
|
||||
let $insert_cmd= insert into t1 select seq;
|
||||
let $i=1;
|
||||
|
||||
while ($i < $N_CONDS) {
|
||||
let $insert_cmd = $insert_cmd ,seq;
|
||||
let $i=`select $i + 1`;
|
||||
}
|
||||
let $insert_cmd= $insert_cmd from seq_1_to_100;
|
||||
|
||||
# echo $insert_cmd;
|
||||
evalp $insert_cmd;
|
||||
|
||||
analyze table t1 persistent for all;
|
||||
set @trace_tmp=@@optimizer_trace;
|
||||
set optimizer_trace=1;
|
||||
|
||||
--echo #
|
||||
--echo # Basic testcase: don't crash for many-column selectivity
|
||||
--echo # explain extended select * from t1 where col0>1 and col1>1 and col2>1 and ...
|
||||
--echo #
|
||||
let $query_tbl= explain format=json select * from t1 where col0>1;
|
||||
|
||||
let $i=1;
|
||||
while ($i < $N_CONDS) {
|
||||
let $query_tbl= $query_tbl and col$i>1;
|
||||
let $i=`select $i + 1`;
|
||||
}
|
||||
|
||||
#echo $query_tbl;
|
||||
evalp $query_tbl;
|
||||
|
||||
select
|
||||
json_detailed(json_extract(trace,'$**.selectivity_for_columns[0]')) as JS
|
||||
from
|
||||
information_schema.optimizer_trace;
|
||||
|
||||
evalp $query_tbl;
|
||||
eval select
|
||||
json_detailed(json_extract(trace,'\$**.selectivity_for_columns[$N_LAST_COND]')) as JS
|
||||
from
|
||||
information_schema.optimizer_trace;
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # Check if not being able to infer anything for the first MAX_KEY
|
||||
--echo # columns doesn't prevent further inferences.
|
||||
--echo #
|
||||
--echo # explain extended select * from t1
|
||||
--echo # where (1>2 or col0>1 or col1>1 or ...) and col99>1
|
||||
--echo #
|
||||
let $query_tbl= explain format=json select * from t1 where (1>2 ;
|
||||
|
||||
let $i=1;
|
||||
while ($i < $N_LAST_COND) {
|
||||
let $query_tbl= $query_tbl or col$i>1;
|
||||
let $i=`select $i + 1`;
|
||||
}
|
||||
let $query_tbl= $query_tbl) and col$N_LAST_COND>1;
|
||||
|
||||
#echo $query_tbl;
|
||||
evalp $query_tbl;
|
||||
|
||||
select
|
||||
json_detailed(json_extract(trace,'$**.selectivity_for_columns')) as JS
|
||||
from
|
||||
information_schema.optimizer_trace;
|
||||
|
||||
set optimizer_trace=@trace_tmp;
|
||||
drop table t1;
|
||||
|
||||
--echo #
|
||||
--echo # Clean up
|
||||
--echo #
|
||||
--source include/restore_charset.inc
|
||||
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
|
||||
set use_stat_tables= @save_use_stat_tables;
|
||||
set @@global.histogram_size=@save_histogram_size;
|
||||
|
Reference in New Issue
Block a user