[MDEV-31479] Inconsistency between MRR and SQL layer costs can cause poor query plan Created: 2023-06-14 Updated: 2023-07-31 Resolved: 2023-06-14 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.5, 10.6, 10.7, 10.8, 10.9, 10.11, 11.0, 11.1 |
| 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: | Major |
| Reporter: | Sergei Petrunia | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
This is based on a customer case. Based on DDL+optimizer trace, I've created a syntethic testcase. The SQL script is attached to the linked issue. Failure scenario is as follows:
Can also optionally have mrr_cost_based=on.
and a query
Then optimization runs like this
Then in best_access_path we will have this:
Because the cost is negative, the optimizer will use ref(idx1) instead of range(idx2) which was much cheaper. |
| Comments |
| Comment by Sergei Petrunia [ 2023-06-14 ] |
|
The commit that has introduced the issue: That is, the problem has appeared in 10.5 |