diff options
-rw-r--r-- | storage/rocksdb/ha_rocksdb.cc | 10 | ||||
-rw-r--r-- | storage/rocksdb/mysql-test/rocksdb/r/rocksdb_range2.result | 17 | ||||
-rw-r--r-- | storage/rocksdb/mysql-test/rocksdb/t/rocksdb_range2.test | 12 |
3 files changed, 38 insertions, 1 deletions
diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index d05f336ee18..03794291575 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -8560,9 +8560,17 @@ int ha_rocksdb::index_read_map_impl(uchar *const buf, const uchar *const key, packed_size); uint end_key_packed_size = 0; + /* + In MariaDB, the end_key is always the bigger end of the range. + If we are doing a reverse-ordered scan (that is, walking from the bigger + key values to smaller), we should use the smaller end of range as end_key. + */ const key_range *cur_end_key= end_key; - if (find_flag == HA_READ_PREFIX_LAST_OR_PREV) + if (find_flag == HA_READ_PREFIX_LAST_OR_PREV || + find_flag == HA_READ_BEFORE_KEY) + { cur_end_key= m_start_range; + } const uint eq_cond_len = calc_eq_cond_len(kd, find_flag, slice, bytes_changed_by_succ, cur_end_key, diff --git a/storage/rocksdb/mysql-test/rocksdb/r/rocksdb_range2.result b/storage/rocksdb/mysql-test/rocksdb/r/rocksdb_range2.result index 10a6a02008e..a925c21e188 100644 --- a/storage/rocksdb/mysql-test/rocksdb/r/rocksdb_range2.result +++ b/storage/rocksdb/mysql-test/rocksdb/r/rocksdb_range2.result @@ -9,3 +9,20 @@ explain select c1 from t1 where c1 > 5 limit 10; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range i i 9 NULL # Using where; Using index drop table t1; +# +# MDEV-17414: MyROCKS order desc limit 1 fails +# +create table t1 (date date); +insert into t1 values ('2018-10-04'), ('2018-10-05'); +select * from t1 where date < '2018-10-09' order by date desc limit 1; +date +2018-10-05 +alter table t1 add index date_index (date); +select * from t1 where date < '2018-10-05' order by date desc limit 1; +date +2018-10-04 +# this should not produce an empty set: +select * from t1 where date < '2018-10-09' order by date desc limit 1; +date +2018-10-05 +drop table t1; diff --git a/storage/rocksdb/mysql-test/rocksdb/t/rocksdb_range2.test b/storage/rocksdb/mysql-test/rocksdb/t/rocksdb_range2.test index a7ac236451e..28010d13753 100644 --- a/storage/rocksdb/mysql-test/rocksdb/t/rocksdb_range2.test +++ b/storage/rocksdb/mysql-test/rocksdb/t/rocksdb_range2.test @@ -19,3 +19,15 @@ select count(*) from t1; explain select c1 from t1 where c1 > 5 limit 10; drop table t1; +--echo # +--echo # MDEV-17414: MyROCKS order desc limit 1 fails +--echo # +create table t1 (date date); +insert into t1 values ('2018-10-04'), ('2018-10-05'); +select * from t1 where date < '2018-10-09' order by date desc limit 1; # Works as expected +alter table t1 add index date_index (date); +select * from t1 where date < '2018-10-05' order by date desc limit 1; # Works as expected +--echo # this should not produce an empty set: +select * from t1 where date < '2018-10-09' order by date desc limit 1; +drop table t1; + |