mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-5926: EITS: Histogram estimates for column=least_possible_value are wrong
[Attempt #2] - Use a new selectivity calculation formula in Histogram::point_selectivity. The formula is different from the old one because it was developed from scratch. it doesn't have any possible division-by-zero problems.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
SET SESSION STORAGE_ENGINE='InnoDB';
|
||||
set @save_optimizer_switch_for_selectivity_test=@@optimizer_switch;
|
||||
set optimizer_switch='extended_keys=on';
|
||||
drop table if exists t1,t2,t3;
|
||||
drop table if exists t0,t1,t2,t3;
|
||||
select @@global.use_stat_tables;
|
||||
@@global.use_stat_tables
|
||||
COMPLEMENTARY
|
||||
@ -835,7 +835,7 @@ flush table t1;
|
||||
set optimizer_use_condition_selectivity=4;
|
||||
explain extended select * from t1 where a=0;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 1025 49.61 Using where
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 1025 0.39 Using where
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 0)
|
||||
drop table t1;
|
||||
@ -1318,15 +1318,54 @@ test.t2 analyze status OK
|
||||
# The following two must have the same in 'Extra' column:
|
||||
explain extended select * from t2 where col1 IN (20, 180);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 1100 1.37 Using where
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 1100 1.35 Using where
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t2`.`col1` AS `col1` from `test`.`t2` where (`test`.`t2`.`col1` in (20,180))
|
||||
explain extended select * from t2 where col1 IN (180, 20);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 1100 1.37 Using where
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 1100 1.35 Using where
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t2`.`col1` AS `col1` from `test`.`t2` where (`test`.`t2`.`col1` in (180,20))
|
||||
drop table t1, t2;
|
||||
#
|
||||
# MDEV-5926: EITS: Histogram estimates for column=least_possible_value are wrong
|
||||
#
|
||||
create table t0(a int);
|
||||
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
||||
create table t1(a int);
|
||||
insert into t1 select A.a from t0 A, t0 B, t0 C;
|
||||
set histogram_size=20;
|
||||
set histogram_type='single_prec_hb';
|
||||
analyze table t1 persistent for all;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 analyze status OK
|
||||
set use_stat_tables='preferably';
|
||||
set optimizer_use_condition_selectivity=4;
|
||||
# Should select about 10%:
|
||||
explain extended select * from t1 where a=2;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 9.52 Using where
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2)
|
||||
# Should select about 10%:
|
||||
explain extended select * from t1 where a=1;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 9.52 Using where
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 1)
|
||||
# Must not have filtered=100%:
|
||||
explain extended select * from t1 where a=0;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 9.52 Using where
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 0)
|
||||
# Again, must not have filtered=100%:
|
||||
explain extended select * from t1 where a=-1;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 9.52 Using where
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = <cache>(-(1)))
|
||||
drop table t0, t1;
|
||||
set histogram_type=@save_histogram_type;
|
||||
set histogram_size=@save_histogram_size;
|
||||
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
|
||||
|
Reference in New Issue
Block a user