@@ -843,7 +843,7 @@ flush table t1;
843
843
set optimizer_use_condition_selectivity=4;
844
844
explain extended select * from t1 where a=0;
845
845
id select_type table type possible_keys key key_len ref rows filtered Extra
846
- 1 SIMPLE t1 ALL NULL NULL NULL NULL 1025 0.39 Using where
846
+ 1 SIMPLE t1 ALL NULL NULL NULL NULL 1025 0.78 Using where
847
847
Warnings:
848
848
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = 0
849
849
drop table t1;
@@ -1659,7 +1659,7 @@ test.t1 analyze status OK
1659
1659
# Check what info the optimizer has about selectivities
1660
1660
explain extended select * from t1 use index () where a in (17,51,5);
1661
1661
id select_type table type possible_keys key key_len ref rows filtered Extra
1662
- 1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 3.90 Using where
1662
+ 1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 3.91 Using where
1663
1663
Warnings:
1664
1664
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` USE INDEX () where `test`.`t1`.`a` in (17,51,5)
1665
1665
explain extended select * from t1 use index () where b=2;
@@ -1945,11 +1945,78 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1945
1945
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 25.00 Using where
1946
1946
Warnings:
1947
1947
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = 2
1948
+ DROP TABLE t1;
1949
+ # End of 10.2 tests
1950
+ #
1951
+ # MDEV-31067: selectivity_from_histogram >1.0 for a DOUBLE_PREC_HB histogram
1952
+ #
1953
+ create table t0(a int);
1954
+ insert into t0 select 1 from seq_1_to_78;
1955
+ create table t1(a int);
1956
+ insert into t1 select 1 from seq_1_to_26;
1957
+ create table t10 (a int);
1958
+ insert into t10 select 0 from t0, seq_1_to_4;
1959
+ insert into t10 select 8693 from t1;
1960
+ insert into t10 select 8694 from t1;
1961
+ insert into t10 select 8695 from t1;
1962
+ insert into t10 select 34783 from t1;
1963
+ insert into t10 select 34784 from t1;
1964
+ insert into t10 select 34785 from t1;
1965
+ insert into t10 select 34785 from t0, seq_1_to_8;
1966
+ insert into t10 select 65214 from t1;
1967
+ insert into t10 select 65215 from t1;
1968
+ insert into t10 select 65216 from t1;
1969
+ insert into t10 select 65216 from t0, seq_1_to_52;
1970
+ insert into t10 select 65217 from t1;
1971
+ insert into t10 select 65218 from t1;
1972
+ insert into t10 select 65219 from t1;
1973
+ insert into t10 select 65219 from t0;
1974
+ insert into t10 select 73913 from t1;
1975
+ insert into t10 select 73914 from t1;
1976
+ insert into t10 select 73915 from t1;
1977
+ insert into t10 select 73915 from t0, seq_1_to_40;
1978
+ insert into t10 select 78257 from t1;
1979
+ insert into t10 select 78258 from t1;
1980
+ insert into t10 select 78259 from t1;
1981
+ insert into t10 select 91300 from t1;
1982
+ insert into t10 select 91301 from t1;
1983
+ insert into t10 select 91302 from t1;
1984
+ insert into t10 select 91302 from t0, seq_1_to_6;
1985
+ insert into t10 select 91303 from t1;
1986
+ insert into t10 select 91304 from t1;
1987
+ insert into t10 select 91305 from t1;
1988
+ insert into t10 select 91305 from t0, seq_1_to_8;
1989
+ insert into t10 select 99998 from t1;
1990
+ insert into t10 select 99999 from t1;
1991
+ insert into t10 select 100000 from t1;
1992
+ set use_stat_tables=preferably;
1993
+ analyze table t10 persistent for all;
1994
+ Table Op Msg_type Msg_text
1995
+ test.t10 analyze status Engine-independent statistics collected
1996
+ test.t10 analyze status OK
1997
+ flush tables;
1998
+ set statement optimizer_trace=1 for
1999
+ explain select * from t10 where a in (91303);
2000
+ id select_type table type possible_keys key key_len ref rows Extra
2001
+ 1 SIMPLE t10 ALL NULL NULL NULL NULL 9984 Using where
2002
+ # Must have selectivity_from_histogram <= 1.0:
2003
+ select json_detailed(json_extract(trace, '$**.selectivity_for_columns'))
2004
+ from information_schema.optimizer_trace;
2005
+ json_detailed(json_extract(trace, '$**.selectivity_for_columns'))
2006
+ [
2007
+ [
2008
+ {
2009
+ "column_name": "a",
2010
+ "ranges":
2011
+ ["91303 <= a <= 91303"],
2012
+ "selectivity_from_histogram": 0.035714283
2013
+ }
2014
+ ]
2015
+ ]
2016
+ drop table t0,t1,t10;
1948
2017
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
1949
2018
set histogram_size=@save_histogram_size;
1950
2019
set use_stat_tables= @save_use_stat_tables;
1951
- DROP TABLE t1;
1952
- # End of 10.2 tests
1953
2020
set @@global.histogram_size=@save_histogram_size;
1954
2021
set optimizer_switch=@save_optimizer_switch_for_selectivity_test;
1955
2022
set @tmp_ust= @@use_stat_tables;
0 commit comments