Commit f8604ed9 authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-17414: MyROCKS order desc limit 1 fails : Backport to 10.2

- Use the correct range bounds when doing a reverse-ordered range scan
  (this was already done for HA_READ_PREFIX_LAST_OR_PREV but not for
   HA_READ_BEFORE_KEY).
parent a6ffeeea
......@@ -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,
......
......@@ -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;
......@@ -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;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment