[MDEV-20693] ha_rocksdb::records_in_range() vastly overestimates the number of rows in certain ranges Created: 2019-09-27 Updated: 2023-06-22 |
|
| Status: | Confirmed |
| Project: | MariaDB Server |
| Component/s: | Storage Engine - RocksDB |
| Affects Version/s: | 10.2, 10.3, 10.4 |
| Fix Version/s: | 10.4 |
| Type: | Bug | Priority: | Major |
| Reporter: | Sergei Petrunia | Assignee: | Sergei Petrunia |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | upstream, upstream-fixed | ||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Description |
|
Consider this testcase (not necessarily minimal):
Ok, now table obj2 has these rows:
Reading the rows at the very end of the group with part_id=0:
Note this part:
There are 0 rows in the range, but the estimate is 100M rows! Without FORCE INDEX, index tid will not be used, and full table scan will be done, which will kill the performance. |
| Comments |
| Comment by Sergei Petrunia [ 2019-09-27 ] | ||||||||||||||||||||||||
|
The WHERE clause
Examining range bounds that are passed to ha_rocksdb::records_in_range
The lookup constants: tid is 8 bytes, converting to hex:
everything is as expected so far | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2019-09-27 ] | ||||||||||||||||||||||||
|
Following the execution in DBImpl::GetApproximateSizes(), one sees these endpoints:
| ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2019-09-27 ] | ||||||||||||||||||||||||
|
So, the problem is the upper endpoint:
The code in ha_rocksdb::records_in_range modifies it to include half of the table! | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2019-09-28 ] | ||||||||||||||||||||||||
|
On the upstream fb/mysql-5.6, the optimizer will use ref access on the first key component only:
It's not the best query plan but the issue is not directly reproducible. | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2019-09-28 ] | ||||||||||||||||||||||||
|
... but one can use a single-table DELETE and then the issue is reproducible:
...
| ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2019-09-29 ] | ||||||||||||||||||||||||
|
Filed an issue against the upstream: https://github.com/facebook/mysql-5.6/issues/1052 Filed a pull request against the upstream: https://github.com/facebook/mysql-5.6/pull/1053 | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2019-09-29 ] | ||||||||||||||||||||||||
|
Patch against MariaDB: psergey-mdev20693.diff | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2019-10-27 ] | ||||||||||||||||||||||||
|
Fixed in the upstream by:
|