[MDEV-17414] MyROCKS order desc limit 1 fails Created: 2018-10-09 Updated: 2018-10-29 Resolved: 2018-10-29 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer, Storage Engine - RocksDB |
| Affects Version/s: | 10.3.10, 10.2, 10.3 |
| Fix Version/s: | 10.3.11, 10.2.19 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Henry Baragar | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Ubuntu 18.04.1 LTS |
||
| Description |
|
select * from days where date < '2018-10-09' order by date desc limit 1 fails if there is an index on date and a record for 2018-10-09 does not exist in the table. To recreate .... create table days (date date); |
| Comments |
| Comment by Elena Stepanova [ 2018-10-23 ] | ||||||||||||||
|
Thanks for the report and test case. Reproducible as described. | ||||||||||||||
| Comment by Sergei Petrunia [ 2018-10-27 ] | ||||||||||||||
|
Not reproducible on the upstream. MariaDB:
Upstream, current FB/mysql-5.6
... but if I add more rows to the table I can get it to also pick the range plan, and it will produce the correct result. | ||||||||||||||
| Comment by Sergei Petrunia [ 2018-10-27 ] | ||||||||||||||
|
Investigation: The range we are scanning is actually NULL < date < '2018-10-09' Date column is 3 bytes + 1 NULL byte.
| ||||||||||||||
| Comment by Sergei Petrunia [ 2018-10-27 ] | ||||||||||||||
|
Inside myrocks::ha_rocksdb::calc_eq_cond_len, myrocks::ha_rocksdb::index_read_map_impl, we have:
That is, it thinks that both start and the end keys are '2018-10-09'. | ||||||||||||||
| Comment by Sergei Petrunia [ 2018-10-27 ] | ||||||||||||||
|
Comparing with the upstream:
| ||||||||||||||
| Comment by Sergei Petrunia [ 2018-10-27 ] | ||||||||||||||
|
The SE API doesn't have a direct equivalent of read_range_first/next for doing reverse scans. 1. Inform the SE about the other end of the range. 2. Call ha_rocksdb->ha_index_read_map(..., find_flag=HA_READ_BEFORE_KEY) Step #2 is implemented in different ways in MariaDB and in the Upstream.
min_range here has {key= SQL "NULL", flag = HA_READ_AFTER_KEY}MariaDB's QUICK_SELECT_DESC::get_next uses a different API call:
| ||||||||||||||
| Comment by Sergei Petrunia [ 2018-10-27 ] | ||||||||||||||
|
index_read_map_impl() actually has the code to flip the bounds:
added by
But it only handles closed ranges, not open ones |