[MDEV-18073] get_range_limit_read_cost() doesnt adjust LIMIT for the range access Created: 2018-12-24 Updated: 2019-01-23 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.1, 10.2, 10.3, 10.4 |
| Fix Version/s: | 10.4 |
| Type: | Bug | Priority: | Major |
| Reporter: | Sergei Petrunia | Assignee: | Sergei Petrunia |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | order-by-optimization | ||
| Issue Links: |
|
||||||||||||
| Description |
|
Basically, it ignores the selectivity of the range access being considered. Consider an example
Let's debug this query:
Put a breakpoint in test_if_cheaper_ordering.
The selectivity WHERE condition would be about 2%:
This code is executed:
and adjusts select_limit to be: 10 / 0.021 = 476.
Good so far. Then, we enter get_range_limit_read_cost(... rows_limit=476, ...). and arrive here:
Look at the if-condition. This seems wrong. Instead of rows_limit, we should use "the number of rows to read from quick select, before we find #LIMIT matches". |
| Comments |
| Comment by Sergei Petrunia [ 2018-12-24 ] | ||||||||||||||||||||||||||||||||||||
|
A patch: http://lists.askmonty.org/pipermail/commits/2018-December/013230.html | ||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2018-12-24 ] | ||||||||||||||||||||||||||||||||||||
|
Playing with the patch and the provided example dataset
After the patch:
| ||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2018-12-24 ] | ||||||||||||||||||||||||||||||||||||
|
The dataset I created CREATE TABLE t1 ( insert into t1 select A.a , B.a, C.a from t0 A, t0 B, t0 C, t0 D;
So with limit=1 we change from ref -> index access. But I feel it is strange that we use b_2 instead of b_3. The logic here is that b_3 uses more keyparts than b_2. | ||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2018-12-24 ] | ||||||||||||||||||||||||||||||||||||
|
Lets use the optimizer trace to trace test_if_cheaper_ordering
| ||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2019-01-23 ] | ||||||||||||||||||||||||||||||||||||
|
Pushed the patch that fixes the computation into 10.4 |