From c5d41c9f9dd5beba9092bc786a5fb907597173a8 Mon Sep 17 00:00:00 2001 From: Yoshinori Matsunobu Date: Mon, 4 Jan 2016 09:20:27 -0800 Subject: [PATCH] Skip calling rocksdb::GetApproximateSize is start >= limit (#131) Summary: When kd::successor() is called in records_in_range, there is a possiblity of range.start >= range.limit. RocksDB has an assertion "v->cfd_->internal_comparator().Compare(start, end) <= 0'" so range should not be passed to rocksdb::GetApproximateSize in that case. This diff skips calling rocksdb::GetApproximateSize() and just returns 0. Differential Revision: https://reviews.facebook.net/D52491 --- mysql-test/suite/rocksdb/r/rocksdb.result | 11 +++++++++++ mysql-test/suite/rocksdb/t/rocksdb.test | 9 +++++++++ storage/rocksdb/ha_rocksdb.cc | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/mysql-test/suite/rocksdb/r/rocksdb.result b/mysql-test/suite/rocksdb/r/rocksdb.result index 82168f46d635..09bb56e21766 100644 --- a/mysql-test/suite/rocksdb/r/rocksdb.result +++ b/mysql-test/suite/rocksdb/r/rocksdb.result @@ -2172,4 +2172,15 @@ insert into t2 select concat('v-', 100 + A.a*100 + B.a), 12345 from t1 A, t1 B; update t2 set a=concat('x-', a) where a between 'v-1002' and 'v-1004'; drop table t1,t2; +# +# Issue #131: Assertion `v->cfd_->internal_comparator().Compare(start, end) <= 0' failed +# +CREATE TABLE t2(c1 INTEGER UNSIGNED NOT NULL, c2 INTEGER NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INT, c7 BIGINT, PRIMARY KEY(c1,c6)) ENGINE=RocksDB; +INSERT INTO t2 VALUES (1,1,1,1,1,1,1); +SELECT * FROM t2 WHERE c1 > 4294967295 ORDER BY c1,c6; +c1 c2 c3 c4 c5 c6 c7 +EXPLAIN SELECT * FROM t2 WHERE c1 > 4294967295 ORDER BY c1,c6; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +drop table t2; SET GLOBAL ROCKSDB_PAUSE_BACKGROUND_WORK = @ORIG_PAUSE_BACKGROUND_WORK; diff --git a/mysql-test/suite/rocksdb/t/rocksdb.test b/mysql-test/suite/rocksdb/t/rocksdb.test index ef8c098b028e..518ba0edd15a 100644 --- a/mysql-test/suite/rocksdb/t/rocksdb.test +++ b/mysql-test/suite/rocksdb/t/rocksdb.test @@ -1744,4 +1744,13 @@ update t2 set a=concat('x-', a) where a between 'v-1002' and 'v-1004'; drop table t1,t2; +--echo # +--echo # Issue #131: Assertion `v->cfd_->internal_comparator().Compare(start, end) <= 0' failed +--echo # +CREATE TABLE t2(c1 INTEGER UNSIGNED NOT NULL, c2 INTEGER NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INT, c7 BIGINT, PRIMARY KEY(c1,c6)) ENGINE=RocksDB; +INSERT INTO t2 VALUES (1,1,1,1,1,1,1); +SELECT * FROM t2 WHERE c1 > 4294967295 ORDER BY c1,c6; +EXPLAIN SELECT * FROM t2 WHERE c1 > 4294967295 ORDER BY c1,c6; +drop table t2; + SET GLOBAL ROCKSDB_PAUSE_BACKGROUND_WORK = @ORIG_PAUSE_BACKGROUND_WORK; diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index 9582a9786210..cf471c66b172 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -6436,6 +6436,12 @@ ha_rows ha_rocksdb::records_in_range(uint inx, key_range *min_key, rocksdb::Slice slice1((const char*) sec_key_packed_tuple, size1); rocksdb::Slice slice2((const char*) sec_key_packed_tuple_old, size2); + // slice1 >= slice2 means no row will match + if (slice1.compare(slice2) >= 0) + { + DBUG_RETURN(0); + } + rocksdb::Range r( kd->is_reverse_cf ? slice2 : slice1, kd->is_reverse_cf ? slice1 : slice2