[MDEV-30333] Wrong result with not_null_range_scan and LEFT JOIN with empty table Created: 2023-01-03 Updated: 2023-05-24 Resolved: 2023-02-15 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11 |
| Fix Version/s: | 10.11.3, 11.0.0, 10.5.20, 10.6.13, 10.7.8, 10.8.8, 10.9.6, 10.10.4 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Elena Stepanova | Assignee: | Michael Widenius |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | 11.0-sel | ||
| Description |
|
The expected result is 2 rows. When the test case is executed exactly this way (nothing else is done), it produces the wrong result as above, and the execution plan for the 2nd SELECT is
However, important!
Please be aware of this, as it may affect reproducibility and cause confusion (especially if you are running the test case in the client, not in MTR which does everything from scratch every time). Also, since I don't know the reasons of the non-determinism, it may show up in other forms, e.g. depending on the environment, settings or whatever. |
| Comments |
| Comment by Elena Stepanova [ 2023-01-08 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Another test case which seems to be less volatile (or maybe I'm being more lucky with it) and somewhat different in the plan, but otherwise similar in characteristics
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Hartmut Holzgraefe [ 2023-01-20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Another apparently related case, here a query returns the correct result first, but after another query has been run it returns empty result until FLUSH TABLES, or a specific other query, resets the situation. Just running EXPLAIN is actually already enough to reproduce this, actually executing the queries is not necessary:
Before running the EXPLAIN on the 2nd query the plan for the first one is:
after the EXPLAIN on the 2nd query re-running EXPLAIN for the first one gives:
After running FLUSH TABLES the original query plan is restored. The actual result set of the query contains exactly one row, so "Impossible WHERE condition" is obviously not correct. A specific query resetting to the correct plan here is:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Widenius [ 2023-02-15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a bug in JOIN::make_notnull_conds_for_range_scans() when clearing TABLE->tmp_set, which was used to mark fields that could not be null. The effect was that tmp_set had a 'random value' and this caused the optimizer to think that some fields that could be null could not. Fixed by clearing the tmp_set properly. |