From 3206c4b46444d8f479561ae19f412f7d71d5697d Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Tue, 20 Oct 2026 13:18:50 +0300 Subject: [PATCH] MDEV-20266 rocksdb.mariadb_port_fixes fails in BB about twice a day The EXPLAIN of MDEV-14563 test case sporadically shows ALL instead of range: -1 SIMPLE t2 range a a 32 NULL # Using where +1 SIMPLE t2 ALL a NULL NULL NULL # Using where The two rows of t1 and t2 are still in the memtable when EXPLAIN runs. ha_rocksdb::info() takes stats.records and records_in_range() takes the range estimate from GetApproximateMemTableStats(), which counts skiplist nodes of random height. The memtable of the default column family also holds the data of the tests run before on the same server. So both estimates vary between runs, and when the range estimate is not less than stats.records, the optimizer prefers the table scan. The fix flushes the memtable and runs ANALYZE TABLE before each EXPLAIN, like index_merge_rocksdb.test does. Then the estimates come from the SST file statistics. Both statements are hidden from the result, so the result file is unchanged. --- .../rocksdb/t/mariadb_port_fixes.test | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/storage/rocksdb/mysql-test/rocksdb/t/mariadb_port_fixes.test b/storage/rocksdb/mysql-test/rocksdb/t/mariadb_port_fixes.test index 99d4e2d117c..dec728dddf5 100644 --- a/storage/rocksdb/mysql-test/rocksdb/t/mariadb_port_fixes.test +++ b/storage/rocksdb/mysql-test/rocksdb/t/mariadb_port_fixes.test @@ -38,6 +38,15 @@ CREATE TABLE t1( KEY (a) ) ENGINE=ROCKSDB DEFAULT CHARSET=utf8; insert into t1 values (1,1,1),(2,2,2); + +# MDEV-20266: memtable row estimates are random and make the plan unstable +--disable_query_log +set global rocksdb_force_flush_memtable_now=1; +--disable_result_log +analyze table t1; +--enable_result_log +--enable_query_log + --replace_column 9 # explain select a from t1 where a <'zzz'; @@ -48,6 +57,14 @@ CREATE TABLE t2( KEY (a) ) ENGINE=ROCKSDB DEFAULT CHARSET=utf8; insert into t2 values (1,1,1),(2,2,2); + +--disable_query_log +set global rocksdb_force_flush_memtable_now=1; +--disable_result_log +analyze table t2; +--enable_result_log +--enable_query_log + --replace_column 9 # explain select a from t2 where a <'zzz';