Commit 68432a0
committed
MDEV-29638 Crash when considering Split-Materialized plan
Variant 2: "Don't call optimize_stage2 too early"
The affected query had Split-Materialized derived table in another
derived table:
select * -- select#1
from (
select * -- select#2
from t1,
(select * from t2 ... group by t2.group_col) DT -- select#3
where t1.col=t2.group_col
) TBL;
The optimization went as follows:
JOIN::optimize() calls select_lex->handle_derived(DT_OPTIMIZE) which
calls JOIN::optimize() for all (direct and indirect) children SELECTs.
select#1->handle_derived() calls JOIN::optimize() for select#2 and #3;
select#2->handle_derived() calls JOIN::optimize() for select#3 the second
time. That call would call JOIN::optimize_stage2(), assuming the query
plan choice has been finalized for select#3.
But after that, JOIN::optimize() for select#2 would continue and consider
Split-Materialized for select#3. This would attempt to pick another join
order and cause a crash.
The fix is to have JOIN::optimize() not call optimize_stage2() ever.
Finalizing the query plan choice is now done by a separate call:
select_lex->handle_derived(thd->lex, DT_OPTIMIZE_STAGE2)
which invokes JOIN::optimize_stage2() and saves the query plan.1 parent 99a862c commit 68432a0
File tree
6 files changed
+143
-13
lines changed- mysql-test/main
- sql
6 files changed
+143
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1045 | 1045 | | |
1046 | 1046 | | |
1047 | 1047 | | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
1048 | 1070 | | |
1049 | 1071 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
664 | 664 | | |
665 | 665 | | |
666 | 666 | | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
667 | 694 | | |
668 | 695 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
| |||
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
| 63 | + | |
61 | 64 | | |
62 | 65 | | |
63 | 66 | | |
| |||
109 | 112 | | |
110 | 113 | | |
111 | 114 | | |
112 | | - | |
113 | | - | |
| 115 | + | |
| 116 | + | |
114 | 117 | | |
115 | 118 | | |
116 | 119 | | |
| |||
170 | 173 | | |
171 | 174 | | |
172 | 175 | | |
173 | | - | |
| 176 | + | |
174 | 177 | | |
175 | 178 | | |
176 | 179 | | |
| |||
1071 | 1074 | | |
1072 | 1075 | | |
1073 | 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 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
1074 | 1114 | | |
1075 | 1115 | | |
1076 | 1116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1947 | 1947 | | |
1948 | 1948 | | |
1949 | 1949 | | |
1950 | | - | |
1951 | 1950 | | |
1952 | 1951 | | |
1953 | 1952 | | |
| |||
1960 | 1959 | | |
1961 | 1960 | | |
1962 | 1961 | | |
1963 | | - | |
1964 | | - | |
1965 | 1962 | | |
1966 | 1963 | | |
1967 | | - | |
| 1964 | + | |
| 1965 | + | |
| 1966 | + | |
| 1967 | + | |
1968 | 1968 | | |
1969 | 1969 | | |
1970 | 1970 | | |
1971 | 1971 | | |
1972 | 1972 | | |
1973 | | - | |
1974 | | - | |
| 1973 | + | |
1975 | 1974 | | |
1976 | 1975 | | |
1977 | 1976 | | |
| |||
1981 | 1980 | | |
1982 | 1981 | | |
1983 | 1982 | | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
1984 | 2006 | | |
1985 | 2007 | | |
1986 | 2008 | | |
| |||
2691 | 2713 | | |
2692 | 2714 | | |
2693 | 2715 | | |
| 2716 | + | |
| 2717 | + | |
| 2718 | + | |
| 2719 | + | |
| 2720 | + | |
| 2721 | + | |
| 2722 | + | |
| 2723 | + | |
| 2724 | + | |
| 2725 | + | |
| 2726 | + | |
| 2727 | + | |
| 2728 | + | |
2694 | 2729 | | |
2695 | 2730 | | |
2696 | 2731 | | |
| |||
2711 | 2746 | | |
2712 | 2747 | | |
2713 | 2748 | | |
2714 | | - | |
| 2749 | + | |
2715 | 2750 | | |
2716 | 2751 | | |
2717 | 2752 | | |
| |||
3501 | 3536 | | |
3502 | 3537 | | |
3503 | 3538 | | |
3504 | | - | |
| 3539 | + | |
3505 | 3540 | | |
3506 | 3541 | | |
3507 | 3542 | | |
| |||
4765 | 4800 | | |
4766 | 4801 | | |
4767 | 4802 | | |
| 4803 | + | |
4768 | 4804 | | |
4769 | 4805 | | |
4770 | 4806 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1676 | 1676 | | |
1677 | 1677 | | |
1678 | 1678 | | |
| 1679 | + | |
1679 | 1680 | | |
1680 | 1681 | | |
1681 | 1682 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2031 | 2031 | | |
2032 | 2032 | | |
2033 | 2033 | | |
2034 | | - | |
| 2034 | + | |
| 2035 | + | |
| 2036 | + | |
| 2037 | + | |
| 2038 | + | |
2035 | 2039 | | |
2036 | | - | |
| 2040 | + | |
2037 | 2041 | | |
2038 | 2042 | | |
2039 | 2043 | | |
| |||
0 commit comments