1--source include/have_rocksdb.inc 2 3# 4# First set sampling rate to 100% and make sure that the baseline is 5# correct and we get the correct number of rows as a result. 6# 7SET @ORIG_PCT = @@ROCKSDB_TABLE_STATS_SAMPLING_PCT; 8SET @@global.ROCKSDB_TABLE_STATS_SAMPLING_PCT = 100; 9 10create table t1 (pk int primary key) engine=rocksdb; 11 12--disable_query_log 13let $i = 0; 14let $n = 10000; 15 16while ($i < $n) 17{ 18 inc $i; 19 eval insert t1(pk) values($i); 20} 21--enable_query_log 22 23set global rocksdb_force_flush_memtable_now = true; 24 25# This should return 10K rows. 26select table_rows from information_schema.tables 27where table_schema = database() and table_name = 't1'; 28 29let $t1_len = `select data_length from information_schema.tables where table_schema = database() and table_name = 't1'`; 30 31drop table t1; 32 33# 34# Now, set the sampling rate to 10% and expect to see the same amount of 35# rows. 36# 37SET @@global.ROCKSDB_TABLE_STATS_SAMPLING_PCT = 10; 38 39create table t2 (pk int primary key) engine=rocksdb; 40 41--disable_query_log 42let $i = 0; 43let $n = 10000; 44 45while ($i < $n) 46{ 47 inc $i; 48 eval insert t2(pk) values($i); 49} 50--enable_query_log 51 52set global rocksdb_force_flush_memtable_now = true; 53 54# This should return 10K rows as well. 55select table_rows from information_schema.tables 56where table_schema = database() and table_name = 't2'; 57 58let $t2_len = `select data_length from information_schema.tables where table_schema = database() and table_name = 't2'`; 59let $diff = `select abs($t1_len - $t2_len)`; 60 61# 62# Table sizes are approximations and for this particular case we allow about 63# 10% deviation. 64# 65if ($diff < 6000) { 66 select table_name from information_schema.tables where table_schema = database() and table_name = 't2'; 67} 68 69drop table t2; 70 71SET GLOBAL ROCKSDB_TABLE_STATS_SAMPLING_PCT = @ORIG_PCT; 72