revision-id: 62bdb8ec966a0f44db82955a126b10c646fa6265 (mariadb-10.3.6-102-g62bdb8ec966) parent(s): 33907360f56789cd9b467b40e66412eb0a0aff28 author: Sergei Petrunia committer: Sergei Petrunia timestamp: 2019-02-06 02:38:47 +0300 message: Make sure MyRocks tables do not have stats.records=0 as that confuses the optimizer. They generally don't have stats.records=0, the the statistics are computed based on GetApproximateSizes and GetApproximateMemTableStats. Still, when there's nothing on disk and only a few records are in the MemTable, it is possible that both calls will return 0, and the optimizer will see stats.records=0, which may cause "impossible range" condition (even if records_in_range() returned a non-zero value) --- storage/rocksdb/ha_rocksdb.cc | 5 +++++ storage/rocksdb/mysql-test/rocksdb/r/records_in_range.result | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index 9f73b95cb4d..a940e451f75 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -10755,6 +10755,11 @@ int ha_rocksdb::info(uint flag) { stats.data_file_length += m_table_handler->m_mtcache_size; } + // Do like InnoDB does. stats.records=0 confuses the optimizer + if (stats.records == 0 && !(flag & (HA_STATUS_TIME | HA_STATUS_OPEN))) { + stats.records++; + } + if (rocksdb_debug_optimizer_n_rows > 0) stats.records = rocksdb_debug_optimizer_n_rows; } diff --git a/storage/rocksdb/mysql-test/rocksdb/r/records_in_range.result b/storage/rocksdb/mysql-test/rocksdb/r/records_in_range.result index 9bbbdec4794..228e1313e74 100644 --- a/storage/rocksdb/mysql-test/rocksdb/r/records_in_range.result +++ b/storage/rocksdb/mysql-test/rocksdb/r/records_in_range.result @@ -183,7 +183,7 @@ insert into linktable values (1,1,4,1,1,1,1,1,1); set global rocksdb_force_flush_memtable_now = true; explain select id1, id2, link_type, visibility, data, time, version from linktable where id1 = 1 and link_type = 1 and id2 in (1, 2); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE linktable range PRIMARY,id1_type PRIMARY 24 NULL 2 Using where +1 SIMPLE linktable ref PRIMARY,id1_type PRIMARY 16 const,const 2 Using where drop table linktable; CREATE TABLE `linktable` ( `id1` bigint(20) unsigned NOT NULL DEFAULT '0', @@ -205,6 +205,6 @@ insert into linktable values (1,1,4,1,1,1,1,1,1); set global rocksdb_force_flush_memtable_now = true; explain select id1, id2, link_type, visibility, data, time, version from linktable where id1 = 1 and link_type = 1 and id2 in (1, 2); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE linktable range PRIMARY,id1_type PRIMARY 24 NULL 2 Using where +1 SIMPLE linktable ref PRIMARY,id1_type PRIMARY 16 const,const 2 Using where drop table linktable; DROP TABLE t1;