Skip to content

Commit 0a7a0f5

Browse files
MDEV-19574 innodb_stats_method is not honored when innodb_stats_persistent=ON
Problem: ======= InnoDB persistent statistics doesn't take innodb_stats_method variable while calculating n_diff_pfx for the n-prefix index columns. InnoDB persistent statistics doesn't calculate number of non-null key values for n-prefix index columns. Solution: ========= To address the above issues, InnoDB consider all nulls as different value when innodb_stats_method is set to NULLS_UNEQUAL and NULLS_IGNORED. It also adds the n_nonnull_pfx01, n_nonull_pfx02 etc stats description to indicate how many non-nulls exist for n-prefix index
1 parent 1537784 commit 0a7a0f5

18 files changed

+356
-58
lines changed

mysql-test/main/mysqldump-system.result

+6
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ REPLACE INTO `innodb_index_stats` VALUES
121121
('test','tz','PRIMARY','2019-12-31 21:00:00','n_diff_pfx01',5,1,'Time_zone_id'),
122122
('test','tz','PRIMARY','2019-12-31 21:00:00','n_diff_pfx02',394,1,'Time_zone_id,Transition_time'),
123123
('test','tz','PRIMARY','2019-12-31 21:00:00','n_leaf_pages',1,NULL,'Number of leaf pages in the index'),
124+
('test','tz','PRIMARY','2019-12-31 21:00:00','n_nonnull_pfx01',0,1,'Time_zone_id'),
125+
('test','tz','PRIMARY','2019-12-31 21:00:00','n_nonnull_pfx02',0,1,'Time_zone_id,Transition_time'),
124126
('test','tz','PRIMARY','2019-12-31 21:00:00','size',1,NULL,'Number of pages in the index');
125127
/*!40000 ALTER TABLE `innodb_index_stats` ENABLE KEYS */;
126128
UNLOCK TABLES;
@@ -741,6 +743,8 @@ REPLACE INTO `innodb_index_stats` VALUES
741743
('test','tz','PRIMARY','2019-12-31 21:00:00','n_diff_pfx01',5,1,'Time_zone_id'),
742744
('test','tz','PRIMARY','2019-12-31 21:00:00','n_diff_pfx02',394,1,'Time_zone_id,Transition_time'),
743745
('test','tz','PRIMARY','2019-12-31 21:00:00','n_leaf_pages',1,NULL,'Number of leaf pages in the index'),
746+
('test','tz','PRIMARY','2019-12-31 21:00:00','n_nonnull_pfx01',0,1,'Time_zone_id'),
747+
('test','tz','PRIMARY','2019-12-31 21:00:00','n_nonnull_pfx02',0,1,'Time_zone_id,Transition_time'),
744748
('test','tz','PRIMARY','2019-12-31 21:00:00','size',1,NULL,'Number of pages in the index');
745749
/*!40000 ALTER TABLE `innodb_index_stats` ENABLE KEYS */;
746750
UNLOCK TABLES;
@@ -1338,6 +1342,8 @@ INSERT IGNORE INTO `innodb_index_stats` VALUES
13381342
('test','tz','PRIMARY','2019-12-31 21:00:00','n_diff_pfx01',5,1,'Time_zone_id'),
13391343
('test','tz','PRIMARY','2019-12-31 21:00:00','n_diff_pfx02',394,1,'Time_zone_id,Transition_time'),
13401344
('test','tz','PRIMARY','2019-12-31 21:00:00','n_leaf_pages',1,NULL,'Number of leaf pages in the index'),
1345+
('test','tz','PRIMARY','2019-12-31 21:00:00','n_nonnull_pfx01',0,1,'Time_zone_id'),
1346+
('test','tz','PRIMARY','2019-12-31 21:00:00','n_nonnull_pfx02',0,1,'Time_zone_id,Transition_time'),
13411347
('test','tz','PRIMARY','2019-12-31 21:00:00','size',1,NULL,'Number of pages in the index');
13421348
/*!40000 ALTER TABLE `innodb_index_stats` ENABLE KEYS */;
13431349
UNLOCK TABLES;

mysql-test/suite/innodb/r/innodb-index-online.result

+5-1
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,11 @@ SELECT * FROM mysql.innodb_index_stats WHERE table_name IN ('t1');
132132
database_name table_name index_name last_update stat_name stat_value sample_size stat_description
133133
test t1 PRIMARY LAST_UPDATE n_diff_pfx01 5 1 c1
134134
test t1 PRIMARY LAST_UPDATE n_leaf_pages 1 NULL Number of leaf pages in the index
135+
test t1 PRIMARY LAST_UPDATE n_nonnull_pfx01 0 1 c1
135136
test t1 PRIMARY LAST_UPDATE size 1 NULL Number of pages in the index
136137
test t1 c2 LAST_UPDATE n_diff_pfx01 5 1 c2
137138
test t1 c2 LAST_UPDATE n_leaf_pages 1 NULL Number of leaf pages in the index
139+
test t1 c2 LAST_UPDATE n_nonnull_pfx01 0 1 c2
138140
test t1 c2 LAST_UPDATE size 1 NULL Number of pages in the index
139141
CREATE TABLE t1_c2_stats SELECT * FROM mysql.innodb_index_stats
140142
WHERE database_name = 'test' AND table_name = 't1' and index_name = 'c2';
@@ -148,9 +150,11 @@ SELECT * FROM mysql.innodb_index_stats WHERE table_name IN ('t1', 't1_c2_stats')
148150
database_name table_name index_name last_update stat_name stat_value sample_size stat_description
149151
test t1 PRIMARY LAST_UPDATE n_diff_pfx01 5 1 c1
150152
test t1 PRIMARY LAST_UPDATE n_leaf_pages 1 NULL Number of leaf pages in the index
153+
test t1 PRIMARY LAST_UPDATE n_nonnull_pfx01 0 1 c1
151154
test t1 PRIMARY LAST_UPDATE size 1 NULL Number of pages in the index
152-
test t1_c2_stats GEN_CLUST_INDEX LAST_UPDATE n_diff_pfx01 3 1 DB_ROW_ID
155+
test t1_c2_stats GEN_CLUST_INDEX LAST_UPDATE n_diff_pfx01 4 1 DB_ROW_ID
153156
test t1_c2_stats GEN_CLUST_INDEX LAST_UPDATE n_leaf_pages 1 NULL Number of leaf pages in the index
157+
test t1_c2_stats GEN_CLUST_INDEX LAST_UPDATE n_nonnull_pfx01 0 1 DB_ROW_ID
154158
test t1_c2_stats GEN_CLUST_INDEX LAST_UPDATE size 1 NULL Number of pages in the index
155159
connection con1;
156160
KILL QUERY @id;

mysql-test/suite/innodb/r/innodb_stats_auto_recalc.result

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ index_name PRIMARY
1010
stat_name n_leaf_pages
1111
stat_value 1
1212
index_name PRIMARY
13+
stat_name n_nonnull_pfx01
14+
stat_value 0
15+
index_name PRIMARY
1316
stat_name size
1417
stat_value 1
1518
INSERT INTO autorecalc VALUES (1);
@@ -25,6 +28,9 @@ index_name PRIMARY
2528
stat_name n_leaf_pages
2629
stat_value 1
2730
index_name PRIMARY
31+
stat_name n_nonnull_pfx01
32+
stat_value 0
33+
index_name PRIMARY
2834
stat_name size
2935
stat_value 1
3036
DELETE FROM autorecalc;
@@ -39,6 +45,9 @@ index_name PRIMARY
3945
stat_name n_leaf_pages
4046
stat_value 1
4147
index_name PRIMARY
48+
stat_name n_nonnull_pfx01
49+
stat_value 0
50+
index_name PRIMARY
4251
stat_name size
4352
stat_value 1
4453
DROP TABLE autorecalc;

mysql-test/suite/innodb/r/innodb_stats_auto_recalc_ddl.result

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ index_name PRIMARY
1212
stat_name n_leaf_pages
1313
stat_value 1
1414
index_name PRIMARY
15+
stat_name n_nonnull_pfx01
16+
stat_value 0
17+
index_name PRIMARY
1518
stat_name size
1619
stat_value 1
1720
DROP TABLE arddl;
@@ -29,6 +32,9 @@ index_name PRIMARY
2932
stat_name n_leaf_pages
3033
stat_value 1
3134
index_name PRIMARY
35+
stat_name n_nonnull_pfx01
36+
stat_value 0
37+
index_name PRIMARY
3238
stat_name size
3339
stat_value 1
3440
DROP TABLE arddl;

mysql-test/suite/innodb/r/innodb_stats_auto_recalc_on_nonexistent.result

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ CREATE TABLE t (a INT, PRIMARY KEY (a)) ENGINE=INNODB;
33
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
44
COUNT(*) 1
55
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
6-
COUNT(*) 3
6+
COUNT(*) 4
77
SELECT * FROM t;
88
DELETE FROM mysql.innodb_index_stats WHERE table_name = 't';
99
DELETE FROM mysql.innodb_table_stats WHERE table_name = 't';
@@ -16,14 +16,14 @@ SELECT * FROM t;
1616
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
1717
COUNT(*) 1
1818
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
19-
COUNT(*) 3
19+
COUNT(*) 4
2020
DROP TABLE t;
2121
Test with explicit enable
2222
CREATE TABLE t (a INT, PRIMARY KEY (a)) ENGINE=INNODB STATS_AUTO_RECALC=1;
2323
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
2424
COUNT(*) 1
2525
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
26-
COUNT(*) 3
26+
COUNT(*) 4
2727
SELECT * FROM t;
2828
DELETE FROM mysql.innodb_index_stats WHERE table_name = 't';
2929
DELETE FROM mysql.innodb_table_stats WHERE table_name = 't';
@@ -36,14 +36,14 @@ SELECT * FROM t;
3636
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
3737
COUNT(*) 1
3838
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
39-
COUNT(*) 3
39+
COUNT(*) 4
4040
DROP TABLE t;
4141
Test with explicit disable
4242
CREATE TABLE t (a INT, PRIMARY KEY (a)) ENGINE=INNODB STATS_AUTO_RECALC=0;
4343
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
4444
COUNT(*) 1
4545
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
46-
COUNT(*) 3
46+
COUNT(*) 4
4747
SELECT * FROM t;
4848
DELETE FROM mysql.innodb_index_stats WHERE table_name = 't';
4949
DELETE FROM mysql.innodb_table_stats WHERE table_name = 't';

mysql-test/suite/innodb/r/innodb_stats_drop_locked.result

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ innodb_stats_drop_locked
2525
innodb_stats_drop_locked
2626
innodb_stats_drop_locked
2727
innodb_stats_drop_locked
28+
innodb_stats_drop_locked
29+
innodb_stats_drop_locked
30+
innodb_stats_drop_locked
2831
connect con1,localhost,root,,;
2932
SET innodb_lock_wait_timeout=1;
3033
ALTER TABLE innodb_stats_drop_locked DROP INDEX c_key;
@@ -58,13 +61,17 @@ innodb_stats_drop_locked
5861
innodb_stats_drop_locked
5962
innodb_stats_drop_locked
6063
innodb_stats_drop_locked
64+
innodb_stats_drop_locked
65+
innodb_stats_drop_locked
66+
innodb_stats_drop_locked
6167
ALTER TABLE innodb_stats_drop_locked DROP INDEX c_key;
6268
SELECT table_name FROM mysql.innodb_index_stats
6369
WHERE table_name='innodb_stats_drop_locked';
6470
table_name
6571
innodb_stats_drop_locked
6672
innodb_stats_drop_locked
6773
innodb_stats_drop_locked
74+
innodb_stats_drop_locked
6875
DROP TABLE innodb_stats_drop_locked;
6976
SELECT table_name FROM mysql.innodb_table_stats
7077
WHERE table_name='innodb_stats_drop_locked';

mysql-test/suite/innodb/r/innodb_stats_fetch.result

+30
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ stat_value 1
3636
sample_size NULL
3737
stat_description Number of leaf pages in the index
3838
index_name PRIMARY
39+
stat_name n_nonnull_pfx01
40+
stat_value 0
41+
sample_size 1
42+
stat_description a
43+
index_name PRIMARY
44+
stat_name n_nonnull_pfx02
45+
stat_value 0
46+
sample_size 1
47+
stat_description a,b
48+
index_name PRIMARY
3949
stat_name size
4050
stat_value 1
4151
sample_size NULL
@@ -66,6 +76,26 @@ stat_value 1
6676
sample_size NULL
6777
stat_description Number of leaf pages in the index
6878
index_name idx
79+
stat_name n_nonnull_pfx01
80+
stat_value 0
81+
sample_size 1
82+
stat_description c
83+
index_name idx
84+
stat_name n_nonnull_pfx02
85+
stat_value 0
86+
sample_size 1
87+
stat_description c,d
88+
index_name idx
89+
stat_name n_nonnull_pfx03
90+
stat_value 0
91+
sample_size 1
92+
stat_description c,d,a
93+
index_name idx
94+
stat_name n_nonnull_pfx04
95+
stat_value 0
96+
sample_size 1
97+
stat_description c,d,a,b
98+
index_name idx
6999
stat_name size
70100
stat_value 1
71101
sample_size NULL

mysql-test/suite/innodb/r/innodb_stats_rename_table.result

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ stat_name n_leaf_pages
2424
stat_value 1
2525
table_name stats_rename_old
2626
index_name PRIMARY
27+
stat_name n_nonnull_pfx01
28+
stat_value 0
29+
table_name stats_rename_old
30+
index_name PRIMARY
2731
stat_name size
2832
stat_value 1
2933
RENAME TABLE stats_rename_old TO stats_rename_new;
@@ -45,6 +49,10 @@ stat_name n_leaf_pages
4549
stat_value 1
4650
table_name stats_rename_new
4751
index_name PRIMARY
52+
stat_name n_nonnull_pfx01
53+
stat_value 0
54+
table_name stats_rename_new
55+
index_name PRIMARY
4856
stat_name size
4957
stat_value 1
5058
DROP TABLE stats_rename_new;

mysql-test/suite/innodb/r/innodb_stats_rename_table_if_exists.result

+24
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ stat_name n_leaf_pages
4444
stat_value 1
4545
table_name stats_rename1
4646
index_name PRIMARY
47+
stat_name n_nonnull_pfx01
48+
stat_value 0
49+
table_name stats_rename1
50+
index_name PRIMARY
4751
stat_name size
4852
stat_value 1
4953
table_name stats_rename1
@@ -56,6 +60,10 @@ stat_name n_leaf_pages
5660
stat_value 1
5761
table_name stats_rename1
5862
index_name b
63+
stat_name n_nonnull_pfx01
64+
stat_value 0
65+
table_name stats_rename1
66+
index_name b
5967
stat_name size
6068
stat_value 1
6169
table_name stats_rename2
@@ -68,6 +76,10 @@ stat_name n_leaf_pages
6876
stat_value 567
6977
table_name stats_rename2
7078
index_name PRIMARY
79+
stat_name n_nonnull_pfx01
80+
stat_value 567
81+
table_name stats_rename2
82+
index_name PRIMARY
7183
stat_name size
7284
stat_value 567
7385
table_name stats_rename2
@@ -80,6 +92,10 @@ stat_name n_leaf_pages
8092
stat_value 567
8193
table_name stats_rename2
8294
index_name b
95+
stat_name n_nonnull_pfx01
96+
stat_value 567
97+
table_name stats_rename2
98+
index_name b
8399
stat_name size
84100
stat_value 567
85101
RENAME TABLE stats_rename1 TO stats_rename2;
@@ -114,6 +130,10 @@ stat_name n_leaf_pages
114130
stat_value 1
115131
table_name stats_rename2
116132
index_name PRIMARY
133+
stat_name n_nonnull_pfx01
134+
stat_value 0
135+
table_name stats_rename2
136+
index_name PRIMARY
117137
stat_name size
118138
stat_value 1
119139
table_name stats_rename2
@@ -126,6 +146,10 @@ stat_name n_leaf_pages
126146
stat_value 1
127147
table_name stats_rename2
128148
index_name c
149+
stat_name n_nonnull_pfx01
150+
stat_value 0
151+
table_name stats_rename2
152+
index_name c
129153
stat_name size
130154
stat_value 1
131155
DROP TABLE stats_rename2;

mysql-test/suite/innodb/r/instant_alter_index_rename.result

+13
Original file line numberDiff line numberDiff line change
@@ -208,39 +208,52 @@ SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
208208
table_name index_name stat_name
209209
t1 GEN_CLUST_INDEX n_diff_pfx01
210210
t1 GEN_CLUST_INDEX n_leaf_pages
211+
t1 GEN_CLUST_INDEX n_nonnull_pfx01
211212
t1 GEN_CLUST_INDEX size
212213
t1 ind1 n_diff_pfx01
213214
t1 ind1 n_diff_pfx02
214215
t1 ind1 n_leaf_pages
216+
t1 ind1 n_nonnull_pfx01
217+
t1 ind1 n_nonnull_pfx02
215218
t1 ind1 size
216219
t1 ind2 n_diff_pfx01
217220
t1 ind2 n_diff_pfx02
218221
t1 ind2 n_leaf_pages
222+
t1 ind2 n_nonnull_pfx01
223+
t1 ind2 n_nonnull_pfx02
219224
t1 ind2 size
220225
ALTER TABLE t1 DROP INDEX ind2, ADD INDEX ind3(b),
221226
DROP INDEX ind1, ADD INDEX ind2(c);
222227
SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
223228
table_name index_name stat_name
224229
t1 GEN_CLUST_INDEX n_diff_pfx01
225230
t1 GEN_CLUST_INDEX n_leaf_pages
231+
t1 GEN_CLUST_INDEX n_nonnull_pfx01
226232
t1 GEN_CLUST_INDEX size
227233
t1 ind2 n_diff_pfx01
228234
t1 ind2 n_diff_pfx02
229235
t1 ind2 n_leaf_pages
236+
t1 ind2 n_nonnull_pfx01
237+
t1 ind2 n_nonnull_pfx02
230238
t1 ind2 size
231239
t1 ind3 n_diff_pfx01
232240
t1 ind3 n_diff_pfx02
233241
t1 ind3 n_leaf_pages
242+
t1 ind3 n_nonnull_pfx01
243+
t1 ind3 n_nonnull_pfx02
234244
t1 ind3 size
235245
ALTER TABLE t1 DROP b, FORCE;
236246
SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
237247
table_name index_name stat_name
238248
t1 GEN_CLUST_INDEX n_diff_pfx01
239249
t1 GEN_CLUST_INDEX n_leaf_pages
250+
t1 GEN_CLUST_INDEX n_nonnull_pfx01
240251
t1 GEN_CLUST_INDEX size
241252
t1 ind2 n_diff_pfx01
242253
t1 ind2 n_diff_pfx02
243254
t1 ind2 n_leaf_pages
255+
t1 ind2 n_nonnull_pfx01
256+
t1 ind2 n_nonnull_pfx02
244257
t1 ind2 size
245258
UPDATE t1 SET a = 1 WHERE c = 'foo';
246259
DROP TABLE t1;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- stats_method.result 2025-03-10 15:30:38.087625820 +0530
2+
+++ stats_method.reject 2025-03-10 15:34:26.697129924 +0530
3+
@@ -19,7 +19,7 @@
4+
n_nonnull_pfx02 0 f1,f3
5+
n_nonnull_pfx03 0 f1,f3,DB_ROW_ID
6+
size 19 Number of pages in the index
7+
-n_diff_pfx01 16384 f3
8+
+n_diff_pfx01 1 f3
9+
n_diff_pfx02 16384 f3,DB_ROW_ID
10+
n_leaf_pages 1 Number of leaf pages in the index
11+
n_nonnull_pfx01 0 f3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--- stats_method.result 2025-03-10 15:30:38.087625820 +0530
2+
+++ stats_method.reject 2025-03-10 15:35:21.741953192 +0530
3+
@@ -9,13 +9,13 @@
4+
stat_name stat_value stat_description
5+
n_diff_pfx01 16341 DB_ROW_ID
6+
n_leaf_pages 37 Number of leaf pages in the index
7+
-n_nonnull_pfx01 0 DB_ROW_ID
8+
+n_nonnull_pfx01 16378 DB_ROW_ID
9+
size 97 Number of pages in the index
10+
n_diff_pfx01 16384 f1
11+
n_diff_pfx02 16384 f1,f3
12+
n_diff_pfx03 16384 f1,f3,DB_ROW_ID
13+
n_leaf_pages 1 Number of leaf pages in the index
14+
-n_nonnull_pfx01 0 f1
15+
+n_nonnull_pfx01 16384 f1
16+
n_nonnull_pfx02 0 f1,f3
17+
n_nonnull_pfx03 0 f1,f3,DB_ROW_ID
18+
size 19 Number of pages in the index

0 commit comments

Comments
 (0)