Commit 46bdbf7
committed
Bug#14272788: Query with MaterializeScan and materialized subquery
returns too many rows
The fix of this bug is based on rearranging JOIN_TAB elements for
materialized semi-join nests and eliminating special optimizer and
execution code for such nests.
See separate design document for more explanation.
internal/mysql-test/suite/i_main/r/subquery.result
Added test case results for bug#14272788 and bug#14340367.
Updated test results for materialized semi-join queries.
internal/mysql-test/suite/i_main/r/subquery_mat_cost_based.result
Updated test results for materialized semi-join queries.
internal/mysql-test/suite/i_main/t/subquery.test
Added test cases for bug#14272788 and bug#14340367.
mysql-test/r/derived.result
Updated test results for materialized semi-join queries.
mysql-test/r/explain_json_all.result
Updated test results for materialized semi-join queries.
mysql-test/r/group_by.result
Updated test results for materialized semi-join queries.
mysql-test/r/subquery_mat_all.result
Updated test results for materialized semi-join queries.
mysql-test/r/subquery_sj_all.result
Updated test results for materialized semi-join queries.
mysql-test/r/subquery_sj_all_bka.result
Updated test results for materialized semi-join queries.
mysql-test/r/subquery_sj_all_bka_nixbnl.result
Updated test results for materialized semi-join queries.
mysql-test/r/subquery_sj_all_bkaunique.result
Updated test results for materialized semi-join queries.
mysql-test/r/subquery_sj_mat.result
Updated test results for materialized semi-join queries.
mysql-test/r/subquery_sj_mat_bka.result
Updated test results for materialized semi-join queries.
mysql-test/r/subquery_sj_mat_bka_nixbnl.result
Updated test results for materialized semi-join queries.
mysql-test/r/subquery_sj_mat_bkaunique.result
Updated test results for materialized semi-join queries.
sql/abstract_query_plan.cc
Uses plan_is_const()
sql/item.h
Added argument functions for Item::compile()
sql/item_cmpfunc.cc
Added Item_equal::equality_substitution_transformer() and
Item_func_eq::equality_substitution_transformer().
Updated comments in Item_equal::get_subst_item().
sql/item_cmpfunc.h
Added a couple of new function headers.
sql/item_subselect.cc
Modified to use "primary_tables" instead of "tables".
sql/opt_explain.cc
Explain_join::shallow_explain() has been updated to reflect the new
layout of JOIN_TAB elements for materialized semi-join plans.
Explain_join::explain_table_name() now tests the "derived" pointer to
check whether a table is (materialized) derived.
Explain_join::explain_select_type() has been added to set the
"MATERIALIZED" select_type.
Explain_join::explain_id() has been added to set original query block
id for a materialized semi-join table.
sql/opt_explain_json.cc
A DBUG_ASSERT was deleted.
sql/opt_range.cc
Uses plan_is_single_table() and primary_tables.
sql/sql_class.h
Class Semijoin_mat_exec:
Added members emb_sj_nest, field_count, table_index and mat_fields.
table_cols is renamed as subq_exprs.
Deleted members tab_ref, in_equality, join_cond and copy_field.
Member materialized is replaced with JOIN_TAB::materialized.
sql/sql_delete.cc
Modified to use "primary_tables" instead of "tables".
sql/sql_executor.cc
Functions join_read_key2(), join_read_record_no_init(),
rr_sequential_and_unpack() and sub_select_sjm() are deleted.
Function join_materialize_semijoin() is added.
sql/sql_executor.h
Function prototypes are removed.
sql/sql_join_buffer.cc
JOIN_CACHE::calc_record_fields() has a different way to locate first
buffered table when materializing semi-joined tables.
sql/sql_lex.cc
Added new select_type: "MATERIALIZED".
sql/sql_lex.h
Added new select_type: "MATERIALIZED".
sql/sql_optimizer.cc
eliminate_item_equal() simplified according to new design.
Function JOIN::update_keyuse() has been added.
Function JOIN::update_equalities() has been added.
Function create_keyuse_for_table() has been added.
Function make_cond_after_sjm() has been deleted.
In semijoin_types_allow_materialization(), MaterializeScan is
allowed even when selected expressions are not fields.
In make_join_select(), special handling of materialization has been
eliminated.
Using "primary_tables" several places instead of "tables".
Using new functions plan_in_const() and plan_is_single_table().
Several changes due to new layout of JOIN_TAB array.
sql/sql_optimizer.h
Added fields primary_tables and sjm_nests to class JOIN.
Deleted field outer_tables as it was redundant.
Added functions plan_is_const() and plan_is_single_table() to class JOIN.
sql/sql_planner.cc
No longer trashes the sjm member of sj_nest, as it is needed later
in optimization.
sql/sql_resolver.cc
In JOIN::prepare(), initialize field JOIN::primary_tables.
sql/sql_select.cc
Function setup_sj_materialization() is replaced with
setup_materialized_table().
In JOIN::get_best_combination(), number of JOIN_TAB elements is
calculated differently and layout is different.
setup_materialized_table() is called as materialized semi-join nests
are recognized. New adjustments to the optimized plan are made in
JOIN::update_keyuse() and JOIN::update_equalities().
In JOIN::set_semijoin_info(), TABLE::derived_select_number is updated
to original query block id for members of materialized semi-join nests.
Functions is_cond_sj_in_equality(), remove_sj_conds() and
create_subquery_equalities() are deleted.
Function JOIN_TAB::get_sj_strategy() is simplified.
Function JOIN::cleanup() has been modified for new JOIN_TAB setup.
Using "primary_tables" several places instead of "tables".
Several changes due to new layout of JOIN_TAB array.
sql/sql_select.h
Added members "position" and "materialized" in struct st_join_table.
sql/sql_test.cc
Added test for a NULL table pointer.
sql/table.cc
TABLE::init() sets derived_select_number to zero.
sql/table.h
Added field "query_block_id" to save id from original query block
when a semi-join nest is formed.1 parent 03a1bc4 commit 46bdbf7
36 files changed
Lines changed: 6530 additions & 5299 deletions
File tree
- mysql-test/r
- sql
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1629 | 1629 | | |
1630 | 1630 | | |
1631 | 1631 | | |
1632 | | - | |
1633 | | - | |
1634 | | - | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
1635 | 1636 | | |
1636 | 1637 | | |
1637 | 1638 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
806 | 806 | | |
807 | 807 | | |
808 | 808 | | |
809 | | - | |
| 809 | + | |
810 | 810 | | |
811 | 811 | | |
812 | 812 | | |
813 | 813 | | |
814 | 814 | | |
815 | 815 | | |
816 | 816 | | |
817 | | - | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
818 | 834 | | |
819 | 835 | | |
820 | 836 | | |
| |||
823 | 839 | | |
824 | 840 | | |
825 | 841 | | |
826 | | - | |
| 842 | + | |
827 | 843 | | |
828 | 844 | | |
829 | 845 | | |
830 | 846 | | |
831 | 847 | | |
832 | 848 | | |
833 | | - | |
834 | | - | |
835 | | - | |
836 | | - | |
837 | | - | |
838 | | - | |
839 | | - | |
840 | | - | |
841 | | - | |
842 | | - | |
843 | | - | |
844 | | - | |
845 | | - | |
846 | | - | |
847 | | - | |
848 | | - | |
849 | | - | |
850 | | - | |
851 | | - | |
852 | | - | |
853 | | - | |
854 | | - | |
855 | | - | |
856 | | - | |
857 | | - | |
858 | | - | |
859 | | - | |
860 | | - | |
861 | | - | |
862 | | - | |
863 | | - | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
864 | 864 | | |
865 | 865 | | |
866 | 866 | | |
867 | 867 | | |
868 | 868 | | |
869 | 869 | | |
870 | | - | |
| 870 | + | |
871 | 871 | | |
872 | 872 | | |
873 | 873 | | |
| |||
994 | 994 | | |
995 | 995 | | |
996 | 996 | | |
997 | | - | |
998 | | - | |
999 | | - | |
1000 | | - | |
1001 | | - | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
1002 | 1004 | | |
1003 | 1005 | | |
1004 | 1006 | | |
1005 | 1007 | | |
1006 | 1008 | | |
1007 | 1009 | | |
1008 | | - | |
| 1010 | + | |
1009 | 1011 | | |
1010 | 1012 | | |
1011 | 1013 | | |
1012 | 1014 | | |
1013 | 1015 | | |
1014 | 1016 | | |
1015 | | - | |
| 1017 | + | |
| 1018 | + | |
1016 | 1019 | | |
1017 | 1020 | | |
1018 | 1021 | | |
1019 | 1022 | | |
1020 | | - | |
| 1023 | + | |
1021 | 1024 | | |
1022 | | - | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
1023 | 1029 | | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
1024 | 1033 | | |
1025 | | - | |
1026 | | - | |
1027 | | - | |
1028 | | - | |
1029 | | - | |
1030 | | - | |
1031 | | - | |
1032 | | - | |
1033 | | - | |
1034 | | - | |
1035 | | - | |
1036 | | - | |
1037 | | - | |
1038 | | - | |
1039 | | - | |
1040 | | - | |
1041 | | - | |
1042 | | - | |
1043 | | - | |
1044 | | - | |
1045 | | - | |
1046 | | - | |
1047 | | - | |
1048 | | - | |
1049 | | - | |
1050 | | - | |
1051 | | - | |
1052 | | - | |
1053 | | - | |
1054 | | - | |
1055 | | - | |
| 1034 | + | |
1056 | 1035 | | |
1057 | 1036 | | |
1058 | 1037 | | |
1059 | 1038 | | |
1060 | | - | |
| 1039 | + | |
1061 | 1040 | | |
1062 | | - | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
1063 | 1045 | | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
1064 | 1049 | | |
1065 | | - | |
1066 | | - | |
1067 | | - | |
1068 | | - | |
1069 | | - | |
1070 | | - | |
1071 | | - | |
1072 | | - | |
1073 | | - | |
1074 | | - | |
1075 | | - | |
1076 | | - | |
1077 | | - | |
1078 | | - | |
1079 | | - | |
1080 | | - | |
1081 | | - | |
1082 | | - | |
1083 | | - | |
1084 | | - | |
1085 | | - | |
1086 | | - | |
1087 | | - | |
1088 | | - | |
1089 | | - | |
1090 | | - | |
1091 | | - | |
1092 | | - | |
1093 | | - | |
1094 | | - | |
1095 | | - | |
1096 | | - | |
1097 | | - | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
1098 | 1101 | | |
1099 | 1102 | | |
1100 | 1103 | | |
1101 | 1104 | | |
1102 | 1105 | | |
1103 | 1106 | | |
1104 | | - | |
| 1107 | + | |
1105 | 1108 | | |
1106 | 1109 | | |
1107 | 1110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1558 | 1558 | | |
1559 | 1559 | | |
1560 | 1560 | | |
1561 | | - | |
1562 | | - | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
1563 | 1564 | | |
1564 | 1565 | | |
1565 | 1566 | | |
| |||
1571 | 1572 | | |
1572 | 1573 | | |
1573 | 1574 | | |
1574 | | - | |
1575 | | - | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
1576 | 1578 | | |
1577 | 1579 | | |
1578 | 1580 | | |
| |||
0 commit comments