select @@global.innodb_stats_persistent; @@global.innodb_stats_persistent 0 set global innodb_defragment_stats_accuracy = 20; CREATE TABLE t1(a INT PRIMARY KEY, b VARCHAR(256), KEY SECOND(a, b)) ENGINE=INNODB; INSERT INTO t1 SELECT seq, REPEAT('A', 256) FROM seq_1_to_1024; # Not enough page splits to trigger persistent stats write yet. select * from mysql.innodb_index_stats where table_name='t1' and stat_name in ('n_page_split','n_pages_freed,n_leaf_pages_defrag'); database_name table_name index_name last_update stat_name stat_value sample_size stat_description INSERT INTO t1 SELECT seq, REPEAT('A', 256) FROM seq_1025_to_2048; # Persistent stats recorded. select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_page_split'); count(stat_value) > 0 1 select * from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_pages_freed'); database_name table_name index_name last_update stat_name stat_value sample_size stat_description select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_leaf_pages_defrag'); count(stat_value) > 0 1 # Delete some rows. delete from t1 where a between 100 * 20 and 100 * 20 + 30; delete from t1 where a between 100 * 19 and 100 * 19 + 30; delete from t1 where a between 100 * 18 and 100 * 18 + 30; delete from t1 where a between 100 * 17 and 100 * 17 + 30; delete from t1 where a between 100 * 16 and 100 * 16 + 30; delete from t1 where a between 100 * 15 and 100 * 15 + 30; delete from t1 where a between 100 * 14 and 100 * 14 + 30; delete from t1 where a between 100 * 13 and 100 * 13 + 30; delete from t1 where a between 100 * 12 and 100 * 12 + 30; delete from t1 where a between 100 * 11 and 100 * 11 + 30; delete from t1 where a between 100 * 10 and 100 * 10 + 30; delete from t1 where a between 100 * 9 and 100 * 9 + 30; delete from t1 where a between 100 * 8 and 100 * 8 + 30; delete from t1 where a between 100 * 7 and 100 * 7 + 30; delete from t1 where a between 100 * 6 and 100 * 6 + 30; delete from t1 where a between 100 * 5 and 100 * 5 + 30; delete from t1 where a between 100 * 4 and 100 * 4 + 30; delete from t1 where a between 100 * 3 and 100 * 3 + 30; delete from t1 where a between 100 * 2 and 100 * 2 + 30; delete from t1 where a between 100 * 1 and 100 * 1 + 30; # restart # Server Restarted # Confirm persistent stats still there after restart. select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_page_split'); count(stat_value) > 0 1 select * from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_pages_freed'); database_name table_name index_name last_update stat_name stat_value sample_size stat_description select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_leaf_pages_defrag'); count(stat_value) > 0 1 optimize table t1; Table Op Msg_type Msg_text test.t1 optimize status OK select sleep(2); sleep(2) 0 select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_page_split'); count(stat_value) > 0 1 select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_pages_freed'); count(stat_value) > 0 1 select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_leaf_pages_defrag'); count(stat_value) > 0 1 set global innodb_defragment_stats_accuracy = 40; INSERT INTO t1 SELECT seq, REPEAT('A', 256) FROM seq_2049_to_4096; select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_page_split'); count(stat_value) > 0 1 select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_pages_freed'); count(stat_value) > 0 1 select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_leaf_pages_defrag'); count(stat_value) > 0 1 INSERT INTO t1 SELECT seq, REPEAT('A', 256) FROM seq_4097_to_8192; select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_page_split'); count(stat_value) > 0 1 select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_pages_freed'); count(stat_value) > 0 1 select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_leaf_pages_defrag'); count(stat_value) > 0 1 # Table rename should cause stats rename. rename table t1 to t2; select * from mysql.innodb_index_stats where table_name = 't1'; database_name table_name index_name last_update stat_name stat_value sample_size stat_description select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't2' and stat_name in ('n_page_split'); count(stat_value) > 0 1 select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't2' and stat_name in ('n_pages_freed'); count(stat_value) > 0 1 select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't2' and stat_name in ('n_leaf_pages_defrag'); count(stat_value) > 0 1 # Drop index should cause stats drop. drop index SECOND on t2; select * from mysql.innodb_index_stats where table_name = 't2' and index_name = 'SECOND'; database_name table_name index_name last_update stat_name stat_value sample_size stat_description # restart Server Restarted select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't2' and stat_name in ('n_page_split'); count(stat_value) > 0 1 select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't2' and stat_name in ('n_pages_freed'); count(stat_value) > 0 1 select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't2' and stat_name in ('n_leaf_pages_defrag'); count(stat_value) > 0 1 # Clean up DROP TABLE t2; select * from mysql.innodb_index_stats where table_name = 't2'; database_name table_name index_name last_update stat_name stat_value sample_size stat_description