Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDEV-19574 innodb_stats_method is not honored when innodb_stats_persistent=ON #3886

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions mysql-test/main/mysqldump-system.result
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ REPLACE INTO `innodb_index_stats` VALUES
('test','tz','PRIMARY','2019-12-31 21:00:00','n_diff_pfx01',5,1,'Time_zone_id'),
('test','tz','PRIMARY','2019-12-31 21:00:00','n_diff_pfx02',394,1,'Time_zone_id,Transition_time'),
('test','tz','PRIMARY','2019-12-31 21:00:00','n_leaf_pages',1,NULL,'Number of leaf pages in the index'),
('test','tz','PRIMARY','2019-12-31 21:00:00','n_nonnull_pfx01',0,1,'Time_zone_id'),
('test','tz','PRIMARY','2019-12-31 21:00:00','n_nonnull_pfx02',0,1,'Time_zone_id,Transition_time'),
('test','tz','PRIMARY','2019-12-31 21:00:00','size',1,NULL,'Number of pages in the index');
/*!40000 ALTER TABLE `innodb_index_stats` ENABLE KEYS */;
UNLOCK TABLES;
Expand Down Expand Up @@ -741,6 +743,8 @@ REPLACE INTO `innodb_index_stats` VALUES
('test','tz','PRIMARY','2019-12-31 21:00:00','n_diff_pfx01',5,1,'Time_zone_id'),
('test','tz','PRIMARY','2019-12-31 21:00:00','n_diff_pfx02',394,1,'Time_zone_id,Transition_time'),
('test','tz','PRIMARY','2019-12-31 21:00:00','n_leaf_pages',1,NULL,'Number of leaf pages in the index'),
('test','tz','PRIMARY','2019-12-31 21:00:00','n_nonnull_pfx01',0,1,'Time_zone_id'),
('test','tz','PRIMARY','2019-12-31 21:00:00','n_nonnull_pfx02',0,1,'Time_zone_id,Transition_time'),
('test','tz','PRIMARY','2019-12-31 21:00:00','size',1,NULL,'Number of pages in the index');
/*!40000 ALTER TABLE `innodb_index_stats` ENABLE KEYS */;
UNLOCK TABLES;
Expand Down Expand Up @@ -1338,6 +1342,8 @@ INSERT IGNORE INTO `innodb_index_stats` VALUES
('test','tz','PRIMARY','2019-12-31 21:00:00','n_diff_pfx01',5,1,'Time_zone_id'),
('test','tz','PRIMARY','2019-12-31 21:00:00','n_diff_pfx02',394,1,'Time_zone_id,Transition_time'),
('test','tz','PRIMARY','2019-12-31 21:00:00','n_leaf_pages',1,NULL,'Number of leaf pages in the index'),
('test','tz','PRIMARY','2019-12-31 21:00:00','n_nonnull_pfx01',0,1,'Time_zone_id'),
('test','tz','PRIMARY','2019-12-31 21:00:00','n_nonnull_pfx02',0,1,'Time_zone_id,Transition_time'),
('test','tz','PRIMARY','2019-12-31 21:00:00','size',1,NULL,'Number of pages in the index');
/*!40000 ALTER TABLE `innodb_index_stats` ENABLE KEYS */;
UNLOCK TABLES;
Expand Down
42 changes: 42 additions & 0 deletions mysql-test/suite/gcol/r/innodb_virtual_stats.result
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@ WHERE database_name = 'test' AND table_name = 't';
index_name stat_name stat_description
GEN_CLUST_INDEX n_diff_pfx01 DB_ROW_ID
GEN_CLUST_INDEX n_leaf_pages Number of leaf pages in the index
GEN_CLUST_INDEX n_nonnull_pfx01 DB_ROW_ID
GEN_CLUST_INDEX size Number of pages in the index
idxa n_diff_pfx01 a
idxa n_diff_pfx02 a,DB_ROW_ID
idxa n_leaf_pages Number of leaf pages in the index
idxa n_nonnull_pfx01 a
idxa n_nonnull_pfx02 a,DB_ROW_ID
idxa size Number of pages in the index
vidxcd n_diff_pfx01 c
vidxcd n_diff_pfx02 c,d
vidxcd n_diff_pfx03 c,d,DB_ROW_ID
vidxcd n_leaf_pages Number of leaf pages in the index
vidxcd n_nonnull_pfx01 c
vidxcd n_nonnull_pfx02 c,d
vidxcd n_nonnull_pfx03 c,d,DB_ROW_ID
vidxcd size Number of pages in the index
ALTER TABLE t ADD COLUMN e INT GENERATED ALWAYS AS(a+a+b), ADD INDEX idxb (b), ALGORITHM=INPLACE;
select count(*) from t;
Expand All @@ -33,19 +39,27 @@ WHERE database_name = 'test' AND table_name = 't';
index_name stat_name stat_description
GEN_CLUST_INDEX n_diff_pfx01 DB_ROW_ID
GEN_CLUST_INDEX n_leaf_pages Number of leaf pages in the index
GEN_CLUST_INDEX n_nonnull_pfx01 DB_ROW_ID
GEN_CLUST_INDEX size Number of pages in the index
idxa n_diff_pfx01 a
idxa n_diff_pfx02 a,DB_ROW_ID
idxa n_leaf_pages Number of leaf pages in the index
idxa n_nonnull_pfx01 a
idxa n_nonnull_pfx02 a,DB_ROW_ID
idxa size Number of pages in the index
idxb n_diff_pfx01 b
idxb n_diff_pfx02 b,DB_ROW_ID
idxb n_leaf_pages Number of leaf pages in the index
idxb n_nonnull_pfx01 b
idxb n_nonnull_pfx02 b,DB_ROW_ID
idxb size Number of pages in the index
vidxcd n_diff_pfx01 c
vidxcd n_diff_pfx02 c,d
vidxcd n_diff_pfx03 c,d,DB_ROW_ID
vidxcd n_leaf_pages Number of leaf pages in the index
vidxcd n_nonnull_pfx01 c
vidxcd n_nonnull_pfx02 c,d
vidxcd n_nonnull_pfx03 c,d,DB_ROW_ID
vidxcd size Number of pages in the index
ALTER TABLE t DROP COLUMN c, DROP INDEX idxa, ALGORITHM=INPLACE;
select count(*) from t;
Expand All @@ -57,14 +71,19 @@ WHERE database_name = 'test' AND table_name = 't';
index_name stat_name stat_description
GEN_CLUST_INDEX n_diff_pfx01 DB_ROW_ID
GEN_CLUST_INDEX n_leaf_pages Number of leaf pages in the index
GEN_CLUST_INDEX n_nonnull_pfx01 DB_ROW_ID
GEN_CLUST_INDEX size Number of pages in the index
idxb n_diff_pfx01 b
idxb n_diff_pfx02 b,DB_ROW_ID
idxb n_leaf_pages Number of leaf pages in the index
idxb n_nonnull_pfx01 b
idxb n_nonnull_pfx02 b,DB_ROW_ID
idxb size Number of pages in the index
vidxcd n_diff_pfx01 d
vidxcd n_diff_pfx02 d,DB_ROW_ID
vidxcd n_leaf_pages Number of leaf pages in the index
vidxcd n_nonnull_pfx01 d
vidxcd n_nonnull_pfx02 d,DB_ROW_ID
vidxcd size Number of pages in the index
ALTER TABLE t ADD INDEX vidxe (e), ALGORITHM=INPLACE;
select count(*) from t;
Expand All @@ -76,18 +95,25 @@ WHERE database_name = 'test' AND table_name = 't';
index_name stat_name stat_description
GEN_CLUST_INDEX n_diff_pfx01 DB_ROW_ID
GEN_CLUST_INDEX n_leaf_pages Number of leaf pages in the index
GEN_CLUST_INDEX n_nonnull_pfx01 DB_ROW_ID
GEN_CLUST_INDEX size Number of pages in the index
idxb n_diff_pfx01 b
idxb n_diff_pfx02 b,DB_ROW_ID
idxb n_leaf_pages Number of leaf pages in the index
idxb n_nonnull_pfx01 b
idxb n_nonnull_pfx02 b,DB_ROW_ID
idxb size Number of pages in the index
vidxcd n_diff_pfx01 d
vidxcd n_diff_pfx02 d,DB_ROW_ID
vidxcd n_leaf_pages Number of leaf pages in the index
vidxcd n_nonnull_pfx01 d
vidxcd n_nonnull_pfx02 d,DB_ROW_ID
vidxcd size Number of pages in the index
vidxe n_diff_pfx01 e
vidxe n_diff_pfx02 e,DB_ROW_ID
vidxe n_leaf_pages Number of leaf pages in the index
vidxe n_nonnull_pfx01 e
vidxe n_nonnull_pfx02 e,DB_ROW_ID
vidxe size Number of pages in the index
Comment on lines 106 to 117
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name nonnull is rather misleading here. In MariaDB, virtual columns cannot ever be NOT NULL; in MariaDB they can.

Can we have a more descriptive name, such as replacing the nonnull with diff_null if these statistics are covering different prefixes for NULLS_UNEQUAL? In the commit message it is unclear which values were stored by the n_diff_pfx statistics up until now, and how that would be changing here.

ALTER TABLE t ADD COLUMN f INT GENERATED ALWAYS AS(a + a), ADD INDEX vidxf (f), ALGORITHM=INPLACE;
select count(*) from t;
Expand All @@ -99,22 +125,31 @@ WHERE database_name = 'test' AND table_name = 't';
index_name stat_name stat_description
GEN_CLUST_INDEX n_diff_pfx01 DB_ROW_ID
GEN_CLUST_INDEX n_leaf_pages Number of leaf pages in the index
GEN_CLUST_INDEX n_nonnull_pfx01 DB_ROW_ID
GEN_CLUST_INDEX size Number of pages in the index
idxb n_diff_pfx01 b
idxb n_diff_pfx02 b,DB_ROW_ID
idxb n_leaf_pages Number of leaf pages in the index
idxb n_nonnull_pfx01 b
idxb n_nonnull_pfx02 b,DB_ROW_ID
idxb size Number of pages in the index
vidxcd n_diff_pfx01 d
vidxcd n_diff_pfx02 d,DB_ROW_ID
vidxcd n_leaf_pages Number of leaf pages in the index
vidxcd n_nonnull_pfx01 d
vidxcd n_nonnull_pfx02 d,DB_ROW_ID
vidxcd size Number of pages in the index
vidxe n_diff_pfx01 e
vidxe n_diff_pfx02 e,DB_ROW_ID
vidxe n_leaf_pages Number of leaf pages in the index
vidxe n_nonnull_pfx01 e
vidxe n_nonnull_pfx02 e,DB_ROW_ID
vidxe size Number of pages in the index
vidxf n_diff_pfx01 f
vidxf n_diff_pfx02 f,DB_ROW_ID
vidxf n_leaf_pages Number of leaf pages in the index
vidxf n_nonnull_pfx01 f
vidxf n_nonnull_pfx02 f,DB_ROW_ID
vidxf size Number of pages in the index
ALTER TABLE t DROP INDEX vidxcd;
SELECT index_name, stat_name, stat_description
Expand All @@ -123,17 +158,24 @@ WHERE database_name = 'test' AND table_name = 't';
index_name stat_name stat_description
GEN_CLUST_INDEX n_diff_pfx01 DB_ROW_ID
GEN_CLUST_INDEX n_leaf_pages Number of leaf pages in the index
GEN_CLUST_INDEX n_nonnull_pfx01 DB_ROW_ID
GEN_CLUST_INDEX size Number of pages in the index
idxb n_diff_pfx01 b
idxb n_diff_pfx02 b,DB_ROW_ID
idxb n_leaf_pages Number of leaf pages in the index
idxb n_nonnull_pfx01 b
idxb n_nonnull_pfx02 b,DB_ROW_ID
idxb size Number of pages in the index
vidxe n_diff_pfx01 e
vidxe n_diff_pfx02 e,DB_ROW_ID
vidxe n_leaf_pages Number of leaf pages in the index
vidxe n_nonnull_pfx01 e
vidxe n_nonnull_pfx02 e,DB_ROW_ID
vidxe size Number of pages in the index
vidxf n_diff_pfx01 f
vidxf n_diff_pfx02 f,DB_ROW_ID
vidxf n_leaf_pages Number of leaf pages in the index
vidxf n_nonnull_pfx01 f
vidxf n_nonnull_pfx02 f,DB_ROW_ID
vidxf size Number of pages in the index
DROP TABLE t;
6 changes: 5 additions & 1 deletion mysql-test/suite/innodb/r/innodb-index-online.result
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ SELECT * FROM mysql.innodb_index_stats WHERE table_name IN ('t1');
database_name table_name index_name last_update stat_name stat_value sample_size stat_description
test t1 PRIMARY LAST_UPDATE n_diff_pfx01 5 1 c1
test t1 PRIMARY LAST_UPDATE n_leaf_pages 1 NULL Number of leaf pages in the index
test t1 PRIMARY LAST_UPDATE n_nonnull_pfx01 0 1 c1
test t1 PRIMARY LAST_UPDATE size 1 NULL Number of pages in the index
test t1 c2 LAST_UPDATE n_diff_pfx01 5 1 c2
test t1 c2 LAST_UPDATE n_leaf_pages 1 NULL Number of leaf pages in the index
test t1 c2 LAST_UPDATE n_nonnull_pfx01 0 1 c2
test t1 c2 LAST_UPDATE size 1 NULL Number of pages in the index
CREATE TABLE t1_c2_stats SELECT * FROM mysql.innodb_index_stats
WHERE database_name = 'test' AND table_name = 't1' and index_name = 'c2';
Expand All @@ -148,9 +150,11 @@ SELECT * FROM mysql.innodb_index_stats WHERE table_name IN ('t1', 't1_c2_stats')
database_name table_name index_name last_update stat_name stat_value sample_size stat_description
test t1 PRIMARY LAST_UPDATE n_diff_pfx01 5 1 c1
test t1 PRIMARY LAST_UPDATE n_leaf_pages 1 NULL Number of leaf pages in the index
test t1 PRIMARY LAST_UPDATE n_nonnull_pfx01 0 1 c1
test t1 PRIMARY LAST_UPDATE size 1 NULL Number of pages in the index
test t1_c2_stats GEN_CLUST_INDEX LAST_UPDATE n_diff_pfx01 3 1 DB_ROW_ID
test t1_c2_stats GEN_CLUST_INDEX LAST_UPDATE n_diff_pfx01 4 1 DB_ROW_ID
test t1_c2_stats GEN_CLUST_INDEX LAST_UPDATE n_leaf_pages 1 NULL Number of leaf pages in the index
test t1_c2_stats GEN_CLUST_INDEX LAST_UPDATE n_nonnull_pfx01 0 1 DB_ROW_ID
test t1_c2_stats GEN_CLUST_INDEX LAST_UPDATE size 1 NULL Number of pages in the index
connection con1;
KILL QUERY @id;
Expand Down
9 changes: 9 additions & 0 deletions mysql-test/suite/innodb/r/innodb_stats_auto_recalc.result
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ index_name PRIMARY
stat_name n_leaf_pages
stat_value 1
index_name PRIMARY
stat_name n_nonnull_pfx01
stat_value 0
index_name PRIMARY
stat_name size
stat_value 1
INSERT INTO autorecalc VALUES (1);
Expand All @@ -25,6 +28,9 @@ index_name PRIMARY
stat_name n_leaf_pages
stat_value 1
index_name PRIMARY
stat_name n_nonnull_pfx01
stat_value 0
index_name PRIMARY
stat_name size
stat_value 1
DELETE FROM autorecalc;
Expand All @@ -39,6 +45,9 @@ index_name PRIMARY
stat_name n_leaf_pages
stat_value 1
index_name PRIMARY
stat_name n_nonnull_pfx01
stat_value 0
index_name PRIMARY
stat_name size
stat_value 1
DROP TABLE autorecalc;
6 changes: 6 additions & 0 deletions mysql-test/suite/innodb/r/innodb_stats_auto_recalc_ddl.result
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ index_name PRIMARY
stat_name n_leaf_pages
stat_value 1
index_name PRIMARY
stat_name n_nonnull_pfx01
stat_value 0
index_name PRIMARY
stat_name size
stat_value 1
DROP TABLE arddl;
Expand All @@ -29,6 +32,9 @@ index_name PRIMARY
stat_name n_leaf_pages
stat_value 1
index_name PRIMARY
stat_name n_nonnull_pfx01
stat_value 0
index_name PRIMARY
stat_name size
stat_value 1
DROP TABLE arddl;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CREATE TABLE t (a INT, PRIMARY KEY (a)) ENGINE=INNODB;
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
COUNT(*) 1
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
COUNT(*) 3
COUNT(*) 4
SELECT * FROM t;
DELETE FROM mysql.innodb_index_stats WHERE table_name = 't';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 't';
Expand All @@ -16,14 +16,14 @@ SELECT * FROM t;
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
COUNT(*) 1
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
COUNT(*) 3
COUNT(*) 4
DROP TABLE t;
Test with explicit enable
CREATE TABLE t (a INT, PRIMARY KEY (a)) ENGINE=INNODB STATS_AUTO_RECALC=1;
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
COUNT(*) 1
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
COUNT(*) 3
COUNT(*) 4
SELECT * FROM t;
DELETE FROM mysql.innodb_index_stats WHERE table_name = 't';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 't';
Expand All @@ -36,14 +36,14 @@ SELECT * FROM t;
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
COUNT(*) 1
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
COUNT(*) 3
COUNT(*) 4
DROP TABLE t;
Test with explicit disable
CREATE TABLE t (a INT, PRIMARY KEY (a)) ENGINE=INNODB STATS_AUTO_RECALC=0;
SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE table_name = 't';
COUNT(*) 1
SELECT COUNT(*) FROM mysql.innodb_index_stats WHERE table_name = 't';
COUNT(*) 3
COUNT(*) 4
SELECT * FROM t;
DELETE FROM mysql.innodb_index_stats WHERE table_name = 't';
DELETE FROM mysql.innodb_table_stats WHERE table_name = 't';
Expand Down
7 changes: 7 additions & 0 deletions mysql-test/suite/innodb/r/innodb_stats_drop_locked.result
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ innodb_stats_drop_locked
innodb_stats_drop_locked
innodb_stats_drop_locked
innodb_stats_drop_locked
innodb_stats_drop_locked
innodb_stats_drop_locked
innodb_stats_drop_locked
connect con1,localhost,root,,;
SET innodb_lock_wait_timeout=1;
ALTER TABLE innodb_stats_drop_locked DROP INDEX c_key;
Expand Down Expand Up @@ -58,13 +61,17 @@ innodb_stats_drop_locked
innodb_stats_drop_locked
innodb_stats_drop_locked
innodb_stats_drop_locked
innodb_stats_drop_locked
innodb_stats_drop_locked
innodb_stats_drop_locked
ALTER TABLE innodb_stats_drop_locked DROP INDEX c_key;
SELECT table_name FROM mysql.innodb_index_stats
WHERE table_name='innodb_stats_drop_locked';
table_name
innodb_stats_drop_locked
innodb_stats_drop_locked
innodb_stats_drop_locked
innodb_stats_drop_locked
DROP TABLE innodb_stats_drop_locked;
SELECT table_name FROM mysql.innodb_table_stats
WHERE table_name='innodb_stats_drop_locked';
Expand Down
30 changes: 30 additions & 0 deletions mysql-test/suite/innodb/r/innodb_stats_fetch.result
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ stat_value 1
sample_size NULL
stat_description Number of leaf pages in the index
index_name PRIMARY
stat_name n_nonnull_pfx01
stat_value 0
sample_size 1
stat_description a
index_name PRIMARY
stat_name n_nonnull_pfx02
stat_value 0
sample_size 1
stat_description a,b
index_name PRIMARY
stat_name size
stat_value 1
sample_size NULL
Expand Down Expand Up @@ -66,6 +76,26 @@ stat_value 1
sample_size NULL
stat_description Number of leaf pages in the index
index_name idx
stat_name n_nonnull_pfx01
stat_value 0
sample_size 1
stat_description c
index_name idx
stat_name n_nonnull_pfx02
stat_value 0
sample_size 1
stat_description c,d
index_name idx
stat_name n_nonnull_pfx03
stat_value 0
sample_size 1
stat_description c,d,a
index_name idx
stat_name n_nonnull_pfx04
stat_value 0
sample_size 1
stat_description c,d,a,b
index_name idx
stat_name size
stat_value 1
sample_size NULL
Expand Down
8 changes: 8 additions & 0 deletions mysql-test/suite/innodb/r/innodb_stats_rename_table.result
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ stat_name n_leaf_pages
stat_value 1
table_name stats_rename_old
index_name PRIMARY
stat_name n_nonnull_pfx01
stat_value 0
table_name stats_rename_old
index_name PRIMARY
stat_name size
stat_value 1
RENAME TABLE stats_rename_old TO stats_rename_new;
Expand All @@ -45,6 +49,10 @@ stat_name n_leaf_pages
stat_value 1
table_name stats_rename_new
index_name PRIMARY
stat_name n_nonnull_pfx01
stat_value 0
table_name stats_rename_new
index_name PRIMARY
stat_name size
stat_value 1
DROP TABLE stats_rename_new;
Loading