You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check that tables participating in a FULL OUTER JOIN are not separated from
each other when trying new extenions to the query plan. Some tables t1, t2
participating in FULL OUTER JOIN should remain adjacent in the final JOIN
order, otherwise wrong results will be computed.
In this patch, tables in a FULL OUTER JOIN remember who their JOIN partner
is. When JOINs are nested, these partners are preserved and checked
when walking the nested JOIN tree during check_interleaving_in_nj.
This code accounts for the case when tables in a FULL OUTER JOIN may
themselves be nested joins, such as (t1, t2) FULL OUTER JOIN t3.
Copy file name to clipboardExpand all lines: mysql-test/main/join.result
+65-1Lines changed: 65 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -3969,6 +3969,8 @@ create table two (v int);
3969
3969
insert into two (v) values (2);
3970
3970
create table three (v int);
3971
3971
insert into three (v) values (3);
3972
+
create table four (v int);
3973
+
insert into three (v) values (4);
3972
3974
# (FULL)FULL to (INNER)INNER JOIN
3973
3975
select * from one full join two on one.v = two.v full join three on two.v = three.v where one.v is not null and two.v is not null and three.v is not null;
3974
3976
v v v
@@ -4006,9 +4008,11 @@ NULL 2 NULL
4006
4008
select * from one left join two on one.v = two.v full join three on two.v = three.v where three.v is not null;
4007
4009
v v v
4008
4010
NULL NULL 3
4011
+
NULL NULL 4
4009
4012
select * from one left join two on one.v = two.v right join three on two.v = three.v;
4010
4013
v v v
4011
4014
NULL NULL 3
4015
+
NULL NULL 4
4012
4016
# (LEFT)FULL to (LEFT)LEFT JOIN
4013
4017
insert into one (v) values (2),(3);
4014
4018
insert into two (v) values (1);
@@ -4032,5 +4036,65 @@ v v v
4032
4036
select * from three left join one on one.v = 1 left join two on two.v = 1;
4033
4037
v v v
4034
4038
1 1 1
4035
-
drop table one, two, three;
4039
+
# Interleaved JOIN checks
4040
+
explain extended select * from one full outer join (two, three) on one.v=two.v;
4041
+
id select_type table type possible_keys key key_len ref rows filtered Extra
4042
+
1 SIMPLE one UNKNOWN NULL NULL NULL NULL 0 0.00
4043
+
1 SIMPLE two UNKNOWN NULL NULL NULL NULL 0 0.00
4044
+
1 SIMPLE three UNKNOWN NULL NULL NULL NULL 0 0.00
4045
+
Warnings:
4046
+
Note 1003 select `test`.`one`.`v` AS `v`,`test`.`two`.`v` AS `v`,`test`.`three`.`v` AS `v` from `test`.`one` full join (`test`.`two` join `test`.`three`) on(multiple equal(`test`.`one`.`v`, `test`.`two`.`v`))
4047
+
# ^^^ join order must be one, two, three
4048
+
explain extended select * from (one, two) full outer join three on one.v=two.v;
4049
+
id select_type table type possible_keys key key_len ref rows filtered Extra
4050
+
1 SIMPLE one UNKNOWN NULL NULL NULL NULL 0 0.00
4051
+
1 SIMPLE two UNKNOWN NULL NULL NULL NULL 0 0.00
4052
+
1 SIMPLE three UNKNOWN NULL NULL NULL NULL 0 0.00
4053
+
Warnings:
4054
+
Note 1003 select `test`.`one`.`v` AS `v`,`test`.`two`.`v` AS `v`,`test`.`three`.`v` AS `v` from `test`.`one` join `test`.`two` full join `test`.`three` on(multiple equal(`test`.`one`.`v`, `test`.`two`.`v`))
4055
+
# ^^^ join order must be one, two, three
4056
+
explain extended select * from one full outer join (three, two) on one.v=two.v;
4057
+
id select_type table type possible_keys key key_len ref rows filtered Extra
4058
+
1 SIMPLE one UNKNOWN NULL NULL NULL NULL 0 0.00
4059
+
1 SIMPLE three UNKNOWN NULL NULL NULL NULL 0 0.00
4060
+
1 SIMPLE two UNKNOWN NULL NULL NULL NULL 0 0.00
4061
+
Warnings:
4062
+
Note 1003 select `test`.`one`.`v` AS `v`,`test`.`three`.`v` AS `v`,`test`.`two`.`v` AS `v` from `test`.`one` full join (`test`.`three` join `test`.`two`) on(multiple equal(`test`.`one`.`v`, `test`.`two`.`v`))
4063
+
# ^^^ join order must be one, three, two
4064
+
explain extended select * from (one, two t) full outer join (two v, three) on true;
4065
+
id select_type table type possible_keys key key_len ref rows filtered Extra
4066
+
1 SIMPLE one UNKNOWN NULL NULL NULL NULL 0 0.00
4067
+
1 SIMPLE t UNKNOWN NULL NULL NULL NULL 0 0.00
4068
+
1 SIMPLE v UNKNOWN NULL NULL NULL NULL 0 0.00
4069
+
1 SIMPLE three UNKNOWN NULL NULL NULL NULL 0 0.00
4070
+
Warnings:
4071
+
Note 1003 select `test`.`one`.`v` AS `v`,`test`.`t`.`v` AS `v`,`test`.`v`.`v` AS `v`,`test`.`three`.`v` AS `v` from `test`.`one` join `test`.`two` `t` full join (`test`.`two` `v` join `test`.`three`) on(1)
4072
+
# ^^^ join order must be one, t, v, three
4073
+
explain extended select * from (one full outer join two on true) full outer join (three full outer join four on true) on true;
4074
+
id select_type table type possible_keys key key_len ref rows filtered Extra
4075
+
1 SIMPLE one UNKNOWN NULL NULL NULL NULL 0 0.00
4076
+
1 SIMPLE two UNKNOWN NULL NULL NULL NULL 0 0.00
4077
+
1 SIMPLE three UNKNOWN NULL NULL NULL NULL 0 0.00
4078
+
1 SIMPLE four UNKNOWN NULL NULL NULL NULL 0 0.00
4079
+
Warnings:
4080
+
Note 1003 select `test`.`one`.`v` AS `v`,`test`.`two`.`v` AS `v`,`test`.`three`.`v` AS `v`,`test`.`four`.`v` AS `v` from `test`.`one` full join `test`.`two` on(1) full join (`test`.`three` full join `test`.`four` on(1)) on(1)
4081
+
# ^^^ join order must be one, two, three, four
4082
+
explain extended select * from (one full outer join two on true) inner join (three full outer join four on true);
4083
+
id select_type table type possible_keys key key_len ref rows filtered Extra
4084
+
1 SIMPLE one UNKNOWN NULL NULL NULL NULL 0 0.00
4085
+
1 SIMPLE two UNKNOWN NULL NULL NULL NULL 0 0.00
4086
+
1 SIMPLE three system NULL NULL NULL NULL 1 100.00
4087
+
1 SIMPLE four system NULL NULL NULL NULL 0 0.00 Const row not found
4088
+
Warnings:
4089
+
Note 1003 select `test`.`one`.`v` AS `v`,`test`.`two`.`v` AS `v`,1 AS `v`,NULL AS `v` from `test`.`one` full join `test`.`two` on(1)
4090
+
# ^^^ join order must be one, two, three, four
4091
+
explain extended select * from four full outer join (two full outer join three on true) on true;
4092
+
id select_type table type possible_keys key key_len ref rows filtered Extra
4093
+
1 SIMPLE four system NULL NULL NULL NULL 0 0.00 Const row not found
4094
+
1 SIMPLE two UNKNOWN NULL NULL NULL NULL 0 0.00
4095
+
1 SIMPLE three UNKNOWN NULL NULL NULL NULL 0 0.00
4096
+
Warnings:
4097
+
Note 1003 select NULL AS `v`,`test`.`two`.`v` AS `v`,`test`.`three`.`v` AS `v` from (`test`.`two` full join `test`.`three` on(1))
Copy file name to clipboardExpand all lines: mysql-test/main/join.test
+19-1Lines changed: 19 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2187,6 +2187,8 @@ create table two (v int);
2187
2187
insert into two (v) values (2);
2188
2188
create table three (v int);
2189
2189
insert into three (v) values (3);
2190
+
create table four (v int);
2191
+
insert into three (v) values (4);
2190
2192
2191
2193
--echo # (FULL)FULL to (INNER)INNER JOIN
2192
2194
select * from one full join two on one.v = two.v full join three on two.v = three.v where one.v is not null and two.v is not null and three.v is not null;
@@ -2223,7 +2225,23 @@ select * from three;
2223
2225
select * from one left join two on one.v = two.v full join three on two.v = three.v where three.v = 1;
2224
2226
select * from three left join one on one.v = 1 left join two on two.v = 1;
2225
2227
2226
-
drop table one, two, three;
2228
+
--echo # Interleaved JOIN checks
2229
+
explain extended select * from one full outer join (two, three) on one.v=two.v;
2230
+
--echo # ^^^ join order must be one, two, three
2231
+
explain extended select * from (one, two) full outer join three on one.v=two.v;
2232
+
--echo # ^^^ join order must be one, two, three
2233
+
explain extended select * from one full outer join (three, two) on one.v=two.v;
2234
+
--echo # ^^^ join order must be one, three, two
2235
+
explain extended select * from (one, two t) full outer join (two v, three) on true;
2236
+
--echo # ^^^ join order must be one, t, v, three
2237
+
explain extended select * from (one full outer join two on true) full outer join (three full outer join four on true) on true;
2238
+
--echo # ^^^ join order must be one, two, three, four
2239
+
explain extended select * from (one full outer join two on true) inner join (three full outer join four on true);
2240
+
--echo # ^^^ join order must be one, two, three, four
2241
+
explain extended select * from four full outer join (two full outer join three on true) on true;
2242
+
--echo # ^^^ join order must be four, two, three
2243
+
2244
+
drop table one, two, three, four;
2227
2245
2228
2246
# TODO fix PS protocol before end of FULL OUTER JOIN development
0 commit comments