[MDEV-30603] Wrong result with non-default JOIN_CACHE_LEVEL=[4|5] and USE_STAT_TABLES=[NEVER|COMPLEMENTARY] Created: 2023-02-07 Updated: 2023-12-05 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | N/A |
| Fix Version/s: | 11.0 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Elena Stepanova | Assignee: | Igor Babaev |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Attachments: |
|
||||||||||||||||||||
| Issue Links: |
|
||||||||||||||||||||
| Description |
|
I could only reproduce it on bb-11.0, but it is of course not a guarantee that it's feature-specific. The dataset in the test case is dbt3 0.0001, i.e. ~1/10 of the dbt3 dataset which comes with MTR (lineitem ~600 rows).
6183 is apparently the expected result.
|
| Comments |
| Comment by Sergei Petrunia [ 2023-02-08 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
One can get almost the same query plan on 11.0 vanilla. (there is difference in the access to the last table but I think it's not relevant). Diff'ing EXPLAIN outputs:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-02-08 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The
part is the first thing one needs to check. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-02-08 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Ok the negative join buffer size comes from this logic: Consider a join order:
execution reaches JOIN_CACHE::alloc_buffer() for table region:
It computes the total buffer size by adding up join buffer sizes In our case Buffer sizes are
The sum is 110437 which is 1 over the join_buff_space_limit=108544. So, this if is taken:
and it calls shrink_join_buffers() to shrink buffers by 2%.
We have:
so it goes there shrinking the buffer by 1% and subtracting it from
shrinking buffers by 1% doesn't let them fit into the needed_space. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-02-08 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Adding a trivial "cop-out" logic to avoid negative buffer sizes:
Changes EXPLAIN not to use linked join buffers but the query output is still wrong. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-02-08 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
But the above patch makes the query produce a nonsensical EXPLAIN: https://gist.github.com/spetrunia/bef22d46dd95b0da4f0885fa86706b60 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-02-08 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Fixing JOIN_CACHE::alloc_buffer() instead fixes the issue. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-02-10 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Fixed in bb-11.0 tree. I think , the fix should be backported to earlier versions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Julien Fritsch [ 2023-12-05 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Automated message: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by JiraAutomate [ 2023-12-05 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Automated message: |