select @@global.rocksdb_table_stats_use_table_scan;
@@global.rocksdb_table_stats_use_table_scan
1
set @old_debug = @@global.debug;
create table t (i int auto_increment,
j int,
k int,
primary key(i, j, k), key `secondary_key` (j, k)) engine=rocksdb;
set @@global.debug = '+d,rocksdb_is_bg_thread';
insert into t(j, k)  values (1, 1), (1, 1), (2, 1), (2, 1),
(3, 2), (3, 2), (4, 2), (4, 2);
set @@global.rocksdb_force_flush_memtable_now = true;
set debug_sync = "now signal ready_to_calculate_index_stats";
analyze table t;
Table	Op	Msg_type	Msg_text
test.t	analyze	status	OK
show indexes in t;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment
t	0	PRIMARY	1	i	A	8	NULL	NULL		LSMTREE		
t	0	PRIMARY	2	j	A	8	NULL	NULL		LSMTREE		
t	0	PRIMARY	3	k	A	8	NULL	NULL		LSMTREE		
t	1	secondary_key	1	j	A	4	NULL	NULL		LSMTREE		
t	1	secondary_key	2	k	A	4	NULL	NULL		LSMTREE		
select table_name, table_rows from information_schema.tables where table_schema = database() and table_name = "t";
table_name	table_rows
t	8
set debug_sync = "now wait_for index_stats_calculation_done";
flush tables t;
index stats should not change after the background thread finishes calculation
show indexes in t;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment
t	0	PRIMARY	1	i	A	8	NULL	NULL		LSMTREE		
t	0	PRIMARY	2	j	A	8	NULL	NULL		LSMTREE		
t	0	PRIMARY	3	k	A	8	NULL	NULL		LSMTREE		
t	1	secondary_key	1	j	A	4	NULL	NULL		LSMTREE		
t	1	secondary_key	2	k	A	4	NULL	NULL		LSMTREE		
select table_name, table_rows from information_schema.tables where table_schema = database() and table_name = "t";
table_name	table_rows
t	8
set @@global.debug = @old_debug;
drop table t;
create table t (i int auto_increment,
j int,
k int,
primary key(i, j, k), key `secondary_key` (j, k)) engine=rocksdb;
set @@global.debug = '+d,rocksdb_is_bg_thread_drop_table';
insert into t(j, k)  values (1, 1), (1, 1), (2, 1), (2, 1),
(3, 2), (3, 2), (4, 2), (4, 2);
set @@global.rocksdb_force_flush_memtable_now = true;
set debug_sync = "now wait_for ready_to_drop_table";
drop table t;
set debug_sync = "now signal ready_to_save_table_stats";
show indexes in t;
ERROR 42S02: Table 'test.t' doesn't exist
select table_name, table_rows, data_length, index_length from information_schema.tables where table_schema = database() and table_name = "t";
table_name	table_rows	data_length	index_length
set @@global.debug = @old_debug;
create table t (i int auto_increment,
j int,
k int,
primary key(i, j, k),  key `secondary_key` (j, k)) engine=rocksdb;
show indexes in t;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment
t	0	PRIMARY	1	i	A	NULL	NULL	NULL		LSMTREE		
t	0	PRIMARY	2	j	A	NULL	NULL	NULL		LSMTREE		
t	0	PRIMARY	3	k	A	NULL	NULL	NULL		LSMTREE		
t	1	secondary_key	1	j	A	NULL	NULL	NULL		LSMTREE		
t	1	secondary_key	2	k	A	NULL	NULL	NULL		LSMTREE		
select table_name, table_rows from information_schema.tables where table_schema = database() and table_name = "t";
table_name	table_rows
t	0
set @@global.debug = '+d,rocksdb_is_bg_thread';
set @@global.debug = '+d,rocksdb_calculate_stats';
insert into t(j, k)  values (1, 1), (1, 1), (2, 1), (2, 1),
(3, 2), (3, 2), (4, 2), (4, 2);
set @@global.rocksdb_force_flush_memtable_now = true;
set debug_sync = "now signal ready_to_calculate_index_stats";
set debug_sync = "now wait_for ready_to_drop_index";
alter table t drop index secondary_key;
set debug_sync = "now signal ready_to_save_index_stats";
set debug_sync = "now wait_for index_stats_calculation_done";
flush tables t;
show indexes in t;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment
t	0	PRIMARY	1	i	A	8	NULL	NULL		LSMTREE		
t	0	PRIMARY	2	j	A	8	NULL	NULL		LSMTREE		
t	0	PRIMARY	3	k	A	8	NULL	NULL		LSMTREE		
select table_name, table_rows from information_schema.tables where table_schema = database() and table_name = "t";
table_name	table_rows
t	8
set @@global.debug = @old_debug;
drop table t;
