[MDEV-17752] Plan changes from hash_index_merge to index_merge with new optimizer defaults Created: 2018-11-16 Updated: 2019-05-21 Resolved: 2019-05-21 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.0, 10.1, 10.2, 10.3, 10.4 |
| Fix Version/s: | 10.2.25, 10.1.41, 10.3.16, 10.4.6 |
| Type: | Bug | Priority: | Major |
| Reporter: | Varun Gupta (Inactive) | Assignee: | Varun Gupta (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
The mtr test case
|
| Comments |
| Comment by Varun Gupta (Inactive) [ 2018-11-16 ] | ||||||||||||||||||||||||||||||||
|
If I just run the explain without the other query
| ||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2018-11-16 ] | ||||||||||||||||||||||||||||||||
|
Patch | ||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2018-11-24 ] | ||||||||||||||||||||||||||||||||
|
Debugging the original query plan (with hash_index_merge)
Re-running the above query under debugger, in best_access_path(idx=1, table=City) : The first line of the condition computes to true:
Then
So, the first line computes to true:
and we are about to compute s->table->quick_key_parts[best_key->key]. This will read beyond the end of the quick_key_parts array:
There's no crash potential because of the next array, but this is still bad. ... and this is why Varun observes that the query plan changes depending on whether there was another query ran before it. best_max_key_part >= s->table->quick_key_parts[best_key->key] evaluates to true when there was no previous query (and we get hash_index_merge). When there was a previous query, it evaluates to false. | ||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2018-11-24 ] | ||||||||||||||||||||||||||||||||
|
Now, looking at the patch. It disables taking the if-branch if hash join is being used:
This was not my intent. My intent was as follows:
But maybe what the patch does would be better? Perhaps, but in that case the code inside the if-branch should not check "best_key->is_for_hash_join()" like it currently does. I would like to check with Igor, does the execution need to enter the if-branch if hash join is used. | ||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2018-11-24 ] | ||||||||||||||||||||||||||||||||
|
... varun, on the question of loading the "world" database again - why is it not possible to add the test into the join_cache.test where this database is loaded already? | ||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2019-05-20 ] | ||||||||||||||||||||||||||||||||
|
Patch | ||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2019-05-21 ] | ||||||||||||||||||||||||||||||||
|
Ok to push into 10.1 |