You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MDEV-36761: Put NULL-aware cardinality estimation under new_mode flag
The NULL-aware index statistics fix is now controlled by the
FIX_INDEX_STATS_FOR_ALL_NULLS flag and disabled by default
for preserving execution plan stability in stable versions.
To enable:
SET @@new_mode = 'FIX_INDEX_STATS_FOR_ALL_NULLS';
Or via command line:
--new-mode=FIX_INDEX_STATS_FOR_ALL_NULLS
Or in configuration file:
[mysqld]
new_mode=FIX_INDEX_STATS_FOR_ALL_NULLS
`all_nulls_key_parts` bitmap is now calculated at set_statistics_for_table()
Copy file name to clipboardExpand all lines: mysql-test/main/null_aware_cardinality.result
+12-4Lines changed: 12 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,4 @@
1
+
SET @session_start_value = @@new_mode;
1
2
# Small driving table
2
3
CREATE TABLE t1 (a INT, b INT);
3
4
INSERT INTO t1 VALUES (1, 1), (2, 2000),(3,300);
@@ -13,6 +14,7 @@ ANALYZE TABLE t2 PERSISTENT FOR ALL;
13
14
Table Op Msg_type Msg_text
14
15
test.t2 analyze status Engine-independent statistics collected
15
16
test.t2 analyze status Table is already up to date
17
+
SET @@new_mode = "FIX_INDEX_STATS_FOR_ALL_NULLS";
16
18
# NULL-rejecting equality t1.b = t2.b will not return any matches
17
19
# because all values of t2.b are NULL. So "rows" = 1 for t2 where 1 is
18
20
# a special value meaning "very few" rows
@@ -30,10 +32,6 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
30
32
1 SIMPLE t2 ref key_b key_b 5 test.t1.b 11 100.00 Using index condition; Using where
31
33
Warnings:
32
34
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` <=> `test`.`t2`.`b`
33
-
ANALYZE SELECT * FROM t1 JOIN t2 ON t1.a = t2.a AND t1.b <=> t2.b;
34
-
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE t2 ref key_b key_b 5 test.t1.b 11 0.00 100.00 100.00 Using index condition; Using where
37
35
# Insert some non-NULL values and re-collect the stats
38
36
INSERT INTO t2 SELECT 1, 1 FROM seq_1_to_100;
39
37
ANALYZE TABLE t2 PERSISTENT FOR COLUMNS (b) INDEXES (key_b);
@@ -82,12 +80,21 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
82
80
1 SIMPLE t3 ref key_ab key_ab 10 test.t1.a,const 11 100.00 Using where; Using index
83
81
Warnings:
84
82
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t1` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t1`.`a` and `test`.`t3`.`b` is null
83
+
# In the old mode (null-aware estimation is not enabled), "rows" > 1
84
+
SET @@new_mode = "";
85
+
EXPLAIN EXTENDED SELECT * FROM t1 JOIN t2 ON t1.a = t2.a AND t1.b = t2.b;
86
+
id select_type table type possible_keys key key_len ref rows filtered Extra
87
+
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
88
+
1 SIMPLE t2 ref key_b key_b 5 test.t1.b 100 100.00 Using where
89
+
Warnings:
90
+
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t2`.`b` = `test`.`t1`.`b`
85
91
# Insert some non-NULL values and re-collect the stats
86
92
INSERT INTO t3 SELECT 1, 1 FROM seq_1_to_100;
87
93
ANALYZE TABLE t3 PERSISTENT FOR COLUMNS (b) INDEXES (key_ab);
88
94
Table Op Msg_type Msg_text
89
95
test.t3 analyze status Engine-independent statistics collected
90
96
test.t3 analyze status OK
97
+
SET @@new_mode = "FIX_INDEX_STATS_FOR_ALL_NULLS";
91
98
EXPLAIN EXTENDED SELECT * FROM t1 JOIN t3 ON t1.a = t3.a AND t1.b = t3.b;
92
99
id select_type table type possible_keys key key_len ref rows filtered Extra
93
100
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
@@ -147,4 +154,5 @@ EXPLAIN SELECT * FROM t1, t2 WHERE t2.a=t1.a AND t2.b=t1.a;
147
154
id select_type table type possible_keys key key_len ref rows Extra
148
155
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
149
156
1 SIMPLE t2 ref i1 i1 21 test.t1.a,test.t1.a 1 Using where
0 commit comments