--source include/have_innodb.inc --source include/have_sequence.inc --source include/big_test.inc --source include/not_valgrind.inc --source include/not_embedded.inc select @@global.innodb_stats_persistent; 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; --echo # 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'); INSERT INTO t1 SELECT seq, REPEAT('A', 256) FROM seq_1025_to_2048; --echo # Persistent stats recorded. select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_page_split'); select * from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_pages_freed'); select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_leaf_pages_defrag'); --echo # Delete some rows. let $num_delete = 20; while ($num_delete) { let $j = 100 * $num_delete; eval delete from t1 where a between $j and $j + 30; dec $num_delete; } --source include/restart_mysqld.inc --echo # Server Restarted --echo # 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'); select * from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_pages_freed'); select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_leaf_pages_defrag'); optimize table t1; select sleep(2); select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_page_split'); select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_pages_freed'); select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_leaf_pages_defrag'); 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'); select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_pages_freed'); select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_leaf_pages_defrag'); 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'); select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_pages_freed'); select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't1' and stat_name in ('n_leaf_pages_defrag'); --echo # Table rename should cause stats rename. rename table t1 to t2; select * from mysql.innodb_index_stats where table_name = 't1'; select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't2' and stat_name in ('n_page_split'); select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't2' and stat_name in ('n_pages_freed'); select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't2' and stat_name in ('n_leaf_pages_defrag'); --echo # 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'; --source include/restart_mysqld.inc --echo Server Restarted select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't2' and stat_name in ('n_page_split'); select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't2' and stat_name in ('n_pages_freed'); select count(stat_value) > 0 from mysql.innodb_index_stats where table_name = 't2' and stat_name in ('n_leaf_pages_defrag'); --echo # Clean up DROP TABLE t2; select * from mysql.innodb_index_stats where table_name = 't2';