[MDEV-7474] Semi-Join's DuplicateWeedout strategy skipped for some values of optimizer_search_depth Created: 2015-01-16 Updated: 2015-04-10 Resolved: 2015-03-17 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 5.5.41, 10.0.15 |
| Fix Version/s: | 5.5.43, 10.0.18 |
| Type: | Bug | Priority: | Major |
| Reporter: | Geoff Montee (Inactive) | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | optimizer | ||
| Environment: |
Linux |
||
| Attachments: |
|
| Description |
|
When "semijoin" is enabled via "optimizer_switch", data can be duplicated with certain values of "optimizer_search_depth". According to this documentation page: A DuplicateWeedout strategy is supposed to be implemented using temporary tables for semijoin queries. For some values of "optimizer_search_depth", this duplicate weedout step may not occur. Attached is the following: optimizer_search_depth_semijoin_data_setup.sql - A script that sets up a database and a few tables. optimizer_search_depth_semijoin_query_test.sql - A script that queries the tables to demonstrate the problem. optimizer_search_depth_semijoin_output.txt - Example execution of the scripts and their output. |
| Comments |
| Comment by Elena Stepanova [ 2015-01-21 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks for the report and the test case.
| ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2015-03-12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Query structure
Query structure according to EXPLAIN EXTENDED:
Debugging query optimization...
| ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2015-03-12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Removed all outer joins from the example query and it still fails. this returns 9 rows with semijoin=on and 3 rows with semijoin=off:
| ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2015-03-13 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Examining things in debugger stopped at fix_semijoin_strategies_for_picked_join_order(), I see that
but
for any i. That is, join optimization picked an invalid plan. Join optimization considers join prefixes as follows:
Debugging at table=t2_0_, idx=3 I see that we consider DuplicateElimination but choose not to use it, because its cost is higher than the cost of current plan, AND also join->cur_dups_producing_tables=0 which essentially means that there is another strategy that removed the duplicates. However, looking at join->positions[i].sj_strategy, I see nothing. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2015-03-13 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Debugging how join->cur_dups_producing_tables changes during join optimization.
then in greedy_search, we put t3_0_ back into the join prefix:
but join->cur_dups_producing_tables remains 0. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2015-03-13 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Pushed a patch into https://github.com/MariaDB/server/tree/bb-10.0-mdev7474 . I'll need testing from elenst. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2015-03-17 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Ran a set of tests, got several hundred of mismatches between the patched version and baseline 10.0 (low optimizer_search_depth values). All differences look legit, related to the bugfix, so the good news is that tests hit the right spot; but due to the sheer amount of mismatches it's unrealistic to check each one separately. On a separate note, I wonder if the commit comment is correct:
Is it not the other way round, search-depth < n_tables? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2015-03-17 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
The second run went okay. I will also try valgrind tests, but please go ahead and push (we need to decide first whether it's for 5.5 or 10.0). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2015-03-17 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Considering the nature of the fix, it should be 5.5 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2015-03-17 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Pushed into 5.5 tree |