Skip to content

Commit 420dd25

Browse files
committed
Add a few more tests testing JOIN scenarios.
It adds test-cases covering scenarios involving sub-select, LEFT JOIN LATERAL, NATURAL JOIN, IS NULL and LIKE filters, etc. FDW-157, FDW-206, FDW-207, FDW-208, Rajkumar Raghuwanshi.
1 parent e35c1dc commit 420dd25

File tree

2 files changed

+172
-2
lines changed

2 files changed

+172
-2
lines changed

expected/select.out

Lines changed: 132 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ SELECT d.c1, d.c2, e.c1, e.c2, e.c6, e.c8
898898
40 | HR | | | |
899899
(15 rows)
900900

901-
-- FDW-206; LEFT JOIN LATERAL case should not crash
901+
-- FDW-206: LEFT JOIN LATERAL case should not crash
902902
EXPLAIN (VERBOSE, COSTS OFF)
903903
SELECT * FROM f_mysql_test t1 LEFT JOIN LATERAL (
904904
SELECT t2.a, t1.a AS t1_a FROM f_mysql_test t2) t3 ON t1.a = t3.a ORDER BY 1;
@@ -926,6 +926,113 @@ SELECT * FROM f_mysql_test t1 LEFT JOIN LATERAL (
926926
1 | 1 | 1 | 1
927927
(1 row)
928928

929+
SELECT t1.c1, t3.c1, t3.t1_c8 FROM f_test_tbl1 t1 INNER JOIN LATERAL (
930+
SELECT t2.c1, t1.c8 AS t1_c8 FROM f_test_tbl2 t2) t3 ON t3.c1 = t3.t1_c8
931+
ORDER BY 1, 2, 3;
932+
c1 | c1 | t1_c8
933+
------+----+-------
934+
100 | 20 | 20
935+
200 | 30 | 30
936+
300 | 30 | 30
937+
400 | 20 | 20
938+
500 | 30 | 30
939+
600 | 30 | 30
940+
700 | 10 | 10
941+
800 | 20 | 20
942+
900 | 10 | 10
943+
1000 | 30 | 30
944+
1100 | 20 | 20
945+
1200 | 30 | 30
946+
1300 | 20 | 20
947+
1400 | 10 | 10
948+
(14 rows)
949+
950+
SELECT t1.c1, t3.c1, t3.t1_c8 FROM l_test_tbl1 t1 LEFT JOIN LATERAL (
951+
SELECT t2.c1, t1.c8 AS t1_c8 FROM f_test_tbl2 t2) t3 ON t3.c1 = t3.t1_c8
952+
ORDER BY 1, 2, 3;
953+
c1 | c1 | t1_c8
954+
------+----+-------
955+
100 | 20 | 20
956+
200 | 30 | 30
957+
300 | 30 | 30
958+
400 | 20 | 20
959+
500 | 30 | 30
960+
600 | 30 | 30
961+
700 | 10 | 10
962+
800 | 20 | 20
963+
900 | 10 | 10
964+
1000 | 30 | 30
965+
1100 | 20 | 20
966+
1200 | 30 | 30
967+
1300 | 20 | 20
968+
1400 | 10 | 10
969+
(14 rows)
970+
971+
SELECT *, (SELECT r FROM (SELECT c1 AS c1) x, LATERAL (SELECT c1 AS r) y)
972+
FROM f_test_tbl1 ORDER BY 1, 2, 3;
973+
c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | r
974+
------+-------+----------+------+------------+------------+------+----+------
975+
100 | EMP1 | ADMIN | 1300 | 1980-12-17 | 800.23000 | | 20 | 100
976+
200 | EMP2 | SALESMAN | 600 | 1981-02-20 | 1600.00000 | 300 | 30 | 200
977+
300 | EMP3 | SALESMAN | 600 | 1981-02-22 | 1250.00000 | 500 | 30 | 300
978+
400 | EMP4 | MANAGER | 900 | 1981-04-02 | 2975.12000 | | 20 | 400
979+
500 | EMP5 | SALESMAN | 600 | 1981-09-28 | 1250.00000 | 1400 | 30 | 500
980+
600 | EMP6 | MANAGER | 900 | 1981-05-01 | 2850.00000 | | 30 | 600
981+
700 | EMP7 | MANAGER | 900 | 1981-06-09 | 2450.45000 | | 10 | 700
982+
800 | EMP8 | FINANCE | 400 | 1987-04-19 | 3000.00000 | | 20 | 800
983+
900 | EMP9 | HEAD | | 1981-11-17 | 5000.00000 | | 10 | 900
984+
1000 | EMP10 | SALESMAN | 600 | 1980-09-08 | 1500.00000 | 0 | 30 | 1000
985+
1100 | EMP11 | ADMIN | 800 | 1987-05-23 | 1100.00000 | | 20 | 1100
986+
1200 | EMP12 | ADMIN | 600 | 1981-12-03 | 950.00000 | | 30 | 1200
987+
1300 | EMP13 | FINANCE | 400 | 1981-12-03 | 3000.00000 | | 20 | 1300
988+
1400 | EMP14 | ADMIN | 700 | 1982-01-23 | 1300.00000 | | 10 | 1400
989+
(14 rows)
990+
991+
-- LATERAL JOIN with RIGHT should throw error
992+
SELECT t1.c1, t3.c1, t3.t1_c8 FROM f_test_tbl1 t1 RIGHT JOIN LATERAL (
993+
SELECT t2.c1, t1.c8 AS t1_c8 FROM f_test_tbl2 t2) t3 ON t3.c1 = t3.t1_c8
994+
ORDER BY 1, 2, 3;
995+
ERROR: invalid reference to FROM-clause entry for table "t1"
996+
LINE 2: SELECT t2.c1, t1.c8 AS t1_c8 FROM f_test_tbl2 t2) t3 ON t3...
997+
^
998+
DETAIL: The combining JOIN type must be INNER or LEFT for a LATERAL reference.
999+
-- FDW-207: NATURAL JOIN should give correct output
1000+
SELECT t1.c1, t2.c1, t3.c1
1001+
FROM f_test_tbl1 t1 NATURAL JOIN f_test_tbl1 t2 NATURAL JOIN f_test_tbl1 t3
1002+
ORDER BY 1, 2, 3;
1003+
c1 | c1 | c1
1004+
------+------+------
1005+
200 | 200 | 200
1006+
300 | 300 | 300
1007+
500 | 500 | 500
1008+
1000 | 1000 | 1000
1009+
(4 rows)
1010+
1011+
-- FDW-208: IS NULL and LIKE should give the correct output with
1012+
-- use_remote_estimate set to true.
1013+
INSERT INTO f_test_tbl2 VALUES (50, 'TEMP1', NULL);
1014+
INSERT INTO f_test_tbl2 VALUES (60, 'TEMP2', NULL);
1015+
ALTER SERVER mysql_svr OPTIONS (use_remote_estimate 'true');
1016+
SELECT t1.c1, t2.c1
1017+
FROM f_test_tbl2 t1 INNER JOIN f_test_tbl2 t2 ON t1.c1 = t2.c1
1018+
WHERE t1.c3 IS NULL ORDER BY 1, 2;
1019+
c1 | c1
1020+
----+----
1021+
50 | 50
1022+
60 | 60
1023+
(2 rows)
1024+
1025+
SELECT t1.c1, t2.c1
1026+
FROM f_test_tbl2 t1 INNER JOIN f_test_tbl2 t2 ON t1.c1 = t2.c1 AND t1.c2 LIKE 'TEMP%'
1027+
ORDER BY 1, 2;
1028+
c1 | c1
1029+
----+----
1030+
50 | 50
1031+
60 | 60
1032+
(2 rows)
1033+
1034+
DELETE FROM f_test_tbl2 WHERE c1 IN (50, 60);
1035+
ALTER SERVER mysql_svr OPTIONS (SET use_remote_estimate 'false');
9291036
-- FDW-155: Enum data type can be handled correctly in select statements on
9301037
-- foreign table.
9311038
SELECT * FROM f_enum_t1 WHERE size = 'medium' ORDER BY id;
@@ -1109,6 +1216,30 @@ SELECT c1, c2 FROM f_test_tbl1 WHERE c8 = (
11091216
----+----
11101217
(0 rows)
11111218

1219+
SELECT * FROM f_test_tbl1 WHERE c1 = (SELECT 500) AND c2 = (
1220+
SELECT max(c2) FROM f_test_tbl1 WHERE c4 = (SELECT 600))
1221+
ORDER BY 1, 2;
1222+
c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
1223+
-----+------+----------+-----+------------+------------+------+----
1224+
500 | EMP5 | SALESMAN | 600 | 1981-09-28 | 1250.00000 | 1400 | 30
1225+
(1 row)
1226+
1227+
SELECT t1.c1, (SELECT c2 FROM f_test_tbl1 WHERE c1 =(SELECT 500))
1228+
FROM f_test_tbl2 t1, (
1229+
SELECT c1, c2 FROM f_test_tbl2 WHERE c1 > ANY (SELECT 20)) t2
1230+
ORDER BY 1, 2;
1231+
c1 | c2
1232+
----+------
1233+
10 | EMP5
1234+
10 | EMP5
1235+
20 | EMP5
1236+
20 | EMP5
1237+
30 | EMP5
1238+
30 | EMP5
1239+
40 | EMP5
1240+
40 | EMP5
1241+
(8 rows)
1242+
11121243
-- Cleanup
11131244
DROP TABLE l_test_tbl1;
11141245
DROP TABLE l_test_tbl2;

sql/select.sql

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,43 @@ SELECT d.c1, d.c2, e.c1, e.c2, e.c6, e.c8
222222
SELECT d.c1, d.c2, e.c1, e.c2, e.c6, e.c8
223223
FROM f_test_tbl2 d FULL OUTER JOIN l_test_tbl1 e ON d.c1 = e.c8 ORDER BY 1, 3;
224224

225-
-- FDW-206; LEFT JOIN LATERAL case should not crash
225+
-- FDW-206: LEFT JOIN LATERAL case should not crash
226226
EXPLAIN (VERBOSE, COSTS OFF)
227227
SELECT * FROM f_mysql_test t1 LEFT JOIN LATERAL (
228228
SELECT t2.a, t1.a AS t1_a FROM f_mysql_test t2) t3 ON t1.a = t3.a ORDER BY 1;
229229
SELECT * FROM f_mysql_test t1 LEFT JOIN LATERAL (
230230
SELECT t2.a, t1.a AS t1_a FROM f_mysql_test t2) t3 ON t1.a = t3.a ORDER BY 1;
231+
SELECT t1.c1, t3.c1, t3.t1_c8 FROM f_test_tbl1 t1 INNER JOIN LATERAL (
232+
SELECT t2.c1, t1.c8 AS t1_c8 FROM f_test_tbl2 t2) t3 ON t3.c1 = t3.t1_c8
233+
ORDER BY 1, 2, 3;
234+
SELECT t1.c1, t3.c1, t3.t1_c8 FROM l_test_tbl1 t1 LEFT JOIN LATERAL (
235+
SELECT t2.c1, t1.c8 AS t1_c8 FROM f_test_tbl2 t2) t3 ON t3.c1 = t3.t1_c8
236+
ORDER BY 1, 2, 3;
237+
SELECT *, (SELECT r FROM (SELECT c1 AS c1) x, LATERAL (SELECT c1 AS r) y)
238+
FROM f_test_tbl1 ORDER BY 1, 2, 3;
239+
-- LATERAL JOIN with RIGHT should throw error
240+
SELECT t1.c1, t3.c1, t3.t1_c8 FROM f_test_tbl1 t1 RIGHT JOIN LATERAL (
241+
SELECT t2.c1, t1.c8 AS t1_c8 FROM f_test_tbl2 t2) t3 ON t3.c1 = t3.t1_c8
242+
ORDER BY 1, 2, 3;
243+
244+
-- FDW-207: NATURAL JOIN should give correct output
245+
SELECT t1.c1, t2.c1, t3.c1
246+
FROM f_test_tbl1 t1 NATURAL JOIN f_test_tbl1 t2 NATURAL JOIN f_test_tbl1 t3
247+
ORDER BY 1, 2, 3;
248+
249+
-- FDW-208: IS NULL and LIKE should give the correct output with
250+
-- use_remote_estimate set to true.
251+
INSERT INTO f_test_tbl2 VALUES (50, 'TEMP1', NULL);
252+
INSERT INTO f_test_tbl2 VALUES (60, 'TEMP2', NULL);
253+
ALTER SERVER mysql_svr OPTIONS (use_remote_estimate 'true');
254+
SELECT t1.c1, t2.c1
255+
FROM f_test_tbl2 t1 INNER JOIN f_test_tbl2 t2 ON t1.c1 = t2.c1
256+
WHERE t1.c3 IS NULL ORDER BY 1, 2;
257+
SELECT t1.c1, t2.c1
258+
FROM f_test_tbl2 t1 INNER JOIN f_test_tbl2 t2 ON t1.c1 = t2.c1 AND t1.c2 LIKE 'TEMP%'
259+
ORDER BY 1, 2;
260+
DELETE FROM f_test_tbl2 WHERE c1 IN (50, 60);
261+
ALTER SERVER mysql_svr OPTIONS (SET use_remote_estimate 'false');
231262

232263
-- FDW-155: Enum data type can be handled correctly in select statements on
233264
-- foreign table.
@@ -287,6 +318,14 @@ SELECT c1, c2 FROM f_test_tbl1 WHERE c8 = (
287318
SELECT c1 FROM f_test_tbl2 WHERE c1 = (
288319
SELECT min(c1) + 1 FROM f_test_tbl2)) ORDER BY c1;
289320

321+
SELECT * FROM f_test_tbl1 WHERE c1 = (SELECT 500) AND c2 = (
322+
SELECT max(c2) FROM f_test_tbl1 WHERE c4 = (SELECT 600))
323+
ORDER BY 1, 2;
324+
SELECT t1.c1, (SELECT c2 FROM f_test_tbl1 WHERE c1 =(SELECT 500))
325+
FROM f_test_tbl2 t1, (
326+
SELECT c1, c2 FROM f_test_tbl2 WHERE c1 > ANY (SELECT 20)) t2
327+
ORDER BY 1, 2;
328+
290329
-- Cleanup
291330
DROP TABLE l_test_tbl1;
292331
DROP TABLE l_test_tbl2;

0 commit comments

Comments
 (0)