Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
5.5.41, 10.0.15
-
Linux
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.
Thanks for the report and the test case.
Reproducible as described.
test_type
semijoin=ON, optimizer_search_depth=1
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY T3_0_ ref PRIMARY,FK_T3_T2Id PRIMARY 8 const 3 Using index
1 PRIMARY T2_1_ eq_ref PRIMARY,FK_T2_T1Id PRIMARY 8 semijoin_test.T3_0_.T2IdRef 1
1 PRIMARY T1_1_ eq_ref PRIMARY PRIMARY 8 semijoin_test.T2_1_.T1IdRef 1 Using index
1 PRIMARY T2_0_ ref FK_T2_T1Id FK_T2_T1Id 8 semijoin_test.T2_1_.T1IdRef 1 Using index
T1IdRef T2Id
200001 200011
200001 200012
200001 200013
200001 200011
200001 200012
200001 200013
200001 200011
200001 200012
200001 200013
test_type
semijoin=ON, optimizer_search_depth=3
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY T3_0_ ref PRIMARY,FK_T3_T2Id PRIMARY 8 const 3 Using index; Start temporary
1 PRIMARY T2_1_ eq_ref PRIMARY,FK_T2_T1Id PRIMARY 8 semijoin_test.T3_0_.T2IdRef 1
1 PRIMARY T1_1_ eq_ref PRIMARY PRIMARY 8 semijoin_test.T2_1_.T1IdRef 1 Using index
1 PRIMARY T2_0_ ref FK_T2_T1Id FK_T2_T1Id 8 semijoin_test.T2_1_.T1IdRef 1 Using index; End temporary
T1IdRef T2Id
200001 200011
200001 200012
200001 200013
test_type
semijoin=OFF, optimizer_search_depth=1
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY T2_0_ index NULL FK_T2_T1Id 8 NULL 27 Using where; Using index
2 MATERIALIZED T3_0_ ref PRIMARY,FK_T3_T2Id PRIMARY 8 const 3 Using index
2 MATERIALIZED T2_1_ eq_ref PRIMARY PRIMARY 8 semijoin_test.T3_0_.T2IdRef 1
2 MATERIALIZED T1_1_ eq_ref PRIMARY PRIMARY 8 semijoin_test.T2_1_.T1IdRef 1 Using index
T1IdRef T2Id
200001 200011
200001 200012
200001 200013
test_type
semijoin=OFF, optimizer_search_depth=3
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY T2_0_ index NULL FK_T2_T1Id 8 NULL 27 Using where; Using index
2 MATERIALIZED T3_0_ ref PRIMARY,FK_T3_T2Id PRIMARY 8 const 3 Using index
2 MATERIALIZED T2_1_ eq_ref PRIMARY PRIMARY 8 semijoin_test.T3_0_.T2IdRef 1
2 MATERIALIZED T1_1_ eq_ref PRIMARY PRIMARY 8 semijoin_test.T2_1_.T1IdRef 1 Using index
T1IdRef T2Id
200001 200011
200001 200012
200001 200013