[MDEV-31090] wrong query plan, seems a bug in optimizer Created: 2023-04-19 Updated: 2023-05-26 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.6.11, 10.6.12 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | firk | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Environment: |
FreeBSD 12.3 |
||
| Attachments: |
|
| Description |
|
The bug is partially intersects with MDEV-26256 Table definition (seemingly unrelated fields replaced with placeholders):
Query:
Where TTT is some value. The 'WHERE' condition never covers more than 20 rows, and, as you may see, WHERE+ORDER perfectly matches `id2_ctime` index. Usually, it handled normally via the mentioned index:
Sometimes (looks like pure random, <1% of requests), things goes wrong:
It stripped the half of useful index and bruteforced rows that matched only the first part of the index. I got optimizer traces for 'good' and 'bad' cases (attached). There is two interesting parts: 1) wrong rows estimation (more specific, longer key gets 74 rows while shorted `ctime`-only key gets 72 rows) - this looks like the same issue MDEV-26256 2) after rows_estimation, the next step "considered_execution_plans": here we see that rows_estimation results seems ignored (i don't see the plan using "better" `ctime`-only key here), but instead now we comparing the plan using `id2_ctime` key and the plan using its truncated version `id2`-only key.
For some reason, long-key version gets completely wrong resulting_rows=663.3084173, and yet more irrelevant cost=1.79769e308. Due to this, truncated-key version with it properly calculated bad cost=824471 wins. I don't think that the "1.79769e308" value may be the result of any normal calculations, it looks like the result of something completely wrong. |