@@ -843,7 +843,7 @@ flush table t1;
843843set optimizer_use_condition_selectivity=4;
844844explain extended select * from t1 where a=0;
845845id 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
847847Warnings:
848848Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = 0
849849drop table t1;
@@ -1659,7 +1659,7 @@ test.t1 analyze status OK
16591659# Check what info the optimizer has about selectivities
16601660explain extended select * from t1 use index () where a in (17,51,5);
16611661id 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
16631663Warnings:
16641664Note 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)
16651665explain 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
194519451 SIMPLE t1 ALL NULL NULL NULL NULL 5 25.00 Using where
19461946Warnings:
19471947Note 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;
19482017set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
19492018set histogram_size=@save_histogram_size;
19502019set use_stat_tables= @save_use_stat_tables;
1951- DROP TABLE t1;
1952- # End of 10.2 tests
19532020set @@global.histogram_size=@save_histogram_size;
19542021set optimizer_switch=@save_optimizer_switch_for_selectivity_test;
19552022set @tmp_ust= @@use_stat_tables;
0 commit comments