summaryrefslogtreecommitdiffstats
path: root/mysql-test/main/selectivity_notembedded.test
blob: 6752bd3c7e1ca031e497e60ee2dbc5f711bb2354 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
--source include/no_valgrind_without_big.inc
--source include/have_stat_tables.inc
--source include/have_sequence.inc
--source include/default_charset.inc
--source include/not_embedded.inc

--disable_warnings
drop table if exists t0,t1,t2,t3;
--enable_warnings

select @@global.use_stat_tables;
select @@session.use_stat_tables;

set @save_use_stat_tables=@@use_stat_tables;
set use_stat_tables='preferably';

--source include/default_optimizer_switch.inc
set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity;
set @save_histogram_size=@@histogram_size;
set @save_histogram_type=@@histogram_type;
set join_cache_level=2;
set @@global.histogram_size=0,@@local.histogram_size=0;
set histogram_type='single_prec_hb';

# check that statistics on nulls is used

set optimizer_use_condition_selectivity=3;

--echo #
--echo # MDEV-31067: selectivity_from_histogram >1.0 for a DOUBLE_PREC_HB histogram
--echo #
create table t0(a int);  # This holds how many rows we hold in a bucket.
insert into t0 select 1 from seq_1_to_78;

create table t1(a int);  # one-third of a bucket
insert into t1 select 1 from seq_1_to_26;

create table t10 (a int);
insert into t10 select 0 from t0, seq_1_to_4;

insert into t10 select 8693 from t1;
insert into t10 select 8694 from t1;
insert into t10 select 8695 from t1;


insert into t10 select 34783 from t1;
insert into t10 select 34784 from t1;
insert into t10 select 34785 from t1;


insert into t10 select 34785 from t0, seq_1_to_8;

insert into t10 select 65214 from t1;
insert into t10 select 65215 from t1;
insert into t10 select 65216 from t1;

insert into t10 select 65216 from t0, seq_1_to_52;

insert into t10 select 65217 from t1;
insert into t10 select 65218 from t1;
insert into t10 select 65219 from t1;

insert into t10 select 65219 from t0;


insert into t10 select 73913 from t1;
insert into t10 select 73914 from t1;
insert into t10 select 73915 from t1;

insert into t10 select 73915 from t0, seq_1_to_40;


insert into t10 select 78257 from t1;
insert into t10 select 78258 from t1;
insert into t10 select 78259 from t1;

insert into t10 select 91300 from t1;
insert into t10 select 91301 from t1;
insert into t10 select 91302 from t1;

insert into t10 select 91302 from t0, seq_1_to_6;

insert into t10 select 91303 from t1; # Only 1/3rd of bucket matches the search tuple
insert into t10 select 91304 from t1;
insert into t10 select 91305 from t1;

insert into t10 select 91305 from t0, seq_1_to_8;

insert into t10 select  99998 from t1;
insert into t10 select  99999 from t1;
insert into t10 select 100000 from t1;

set use_stat_tables=preferably;
analyze table t10 persistent for all;
flush tables;

set @tmp=@@optimizer_trace;
set optimizer_trace=1;
explain select * from t10  where a in (91303);

--echo # Must have selectivity_from_histogram <= 1.0:
select json_detailed(json_extract(trace, '$**.selectivity_for_columns')) as sel
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 # Clean up
--echo #
--source include/restore_charset.inc
set @@global.histogram_size=@save_histogram_size;