[MDEV-31380] Assertion `s->table->opt_range_condition_rows <= s->found_records' failed with optimizer_use_condition_selectivity=1 Created: 2023-06-01 Updated: 2023-06-21 Resolved: 2023-06-07 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.6.13, 10.5, 10.8, 10.9, 10.10, 10.11 |
| Fix Version/s: | 10.5.22, 10.6.15, 10.9.8, 10.10.6, 10.11.5, 11.0.3, 11.1.2 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Elena Stepanova | Assignee: | Michael Widenius |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
The failure started happening on 10.6-10.11 after this commit in 10.6.13:
Not reproducible with the provided test case on 11.0. |
| Comments |
| Comment by Sergei Petrunia [ 2023-06-01 ] | |||||||||||||||
|
The assertion is caused by the following sequence of events:
We hit this (wrong) code in opt_range.cc:
Note the
We had opt_range_condition_rows=2 (due to the quick select), but MY_MIN(...) ignored it
This is how we end up with
which hits an assert. | |||||||||||||||
| Comment by Sergei Petrunia [ 2023-06-01 ] | |||||||||||||||
|
Does this have anything to do with the code added by patch for That patch added the assert that is firing:
... but that's it. | |||||||||||||||
| Comment by Sergei Petrunia [ 2023-06-01 ] | |||||||||||||||
|
The problem code itself:
is rather old, last meaningful ( not rename/typecast cleanup) change was in 2013 or before... | |||||||||||||||
| Comment by Sergei Petrunia [ 2023-06-01 ] | |||||||||||||||
|
bb-10.6- Note to the reviewer: the crash can be observed starting from 10.6, because we have the patch for | |||||||||||||||
| Comment by Sergei Petrunia [ 2023-06-02 ] | |||||||||||||||
|
The problem doesn't exist in 10.4 as there the range optimizer first considers the loose scan plan, and after that the range plans. This way, the lines
are correct. But 10.5 already checks the range access first and then checks loose scan. For the testcase for this MDEV, having opt_range_condition_rows > quick->rows causes best_access_path to use DBL_MAX as the cost of range scan:
This doesn't make any difference for this MDEV's testcase (the best quick select, range(PK) is used regardless of what best_access_path thinks about its cost). What if there is a:
Then
It looks like 10.5 could potentially make poor query plan choices. | |||||||||||||||
| Comment by Sergei Petrunia [ 2023-06-02 ] | |||||||||||||||
|
bb-10.5- | |||||||||||||||
| Comment by Sergei Petrunia [ 2023-06-07 ] | |||||||||||||||
|
The problem was introduced by this commit:
which was pushed into 10.5.
as the only quick select we had considered was the one in group_trp. Starting from 10.5, the above code was executed after quick range select has set opt_range_condition_rows to a value that was lower than group_trp->records. | |||||||||||||||
| Comment by Sergei Petrunia [ 2023-06-21 ] | |||||||||||||||
|
The testcase fails in --emb runs. The testcase uses optimizer trace which is not available in embedded. The fix for this is already pushed. |