xref: /sqlite-3.40.0/test/joinF.test (revision aa03c695)
1*aa03c695Sdrh# 2022-05-31
2*aa03c695Sdrh#
3*aa03c695Sdrh# The author disclaims copyright to this source code.  In place of
4*aa03c695Sdrh# a legal notice, here is a blessing:
5*aa03c695Sdrh#
6*aa03c695Sdrh#    May you do good and not evil.
7*aa03c695Sdrh#    May you find forgiveness for yourself and forgive others.
8*aa03c695Sdrh#    May you share freely, never taking more than you give.
9*aa03c695Sdrh#
10*aa03c695Sdrh#***********************************************************************
11*aa03c695Sdrh#
12*aa03c695Sdrh# This file implements tests for JOINs
13*aa03c695Sdrh#
14*aa03c695Sdrh# The test case output is (mostly) all generated by PostgreSQL 14.  This
15*aa03c695Sdrh# test module was created as follows:
16*aa03c695Sdrh#
17*aa03c695Sdrh#   1.   Run a TCL script (included at the bottom of this file) that
18*aa03c695Sdrh#        generates an input script for "psql" that will run man
19*aa03c695Sdrh#        diverse tests on joins.
20*aa03c695Sdrh#
21*aa03c695Sdrh#   2.   Run the script from step (1) through psql and collect the
22*aa03c695Sdrh#        output.
23*aa03c695Sdrh#
24*aa03c695Sdrh#   3.   Make a few minor global search-and-replace operations to convert
25*aa03c695Sdrh#        the psql output into a form suitable for this test module.
26*aa03c695Sdrh#
27*aa03c695Sdrh#   4.   Add this header, and the script content at the footer.
28*aa03c695Sdrh#
29*aa03c695Sdrh# A few extra tests that were not generated from postgresql output are
30*aa03c695Sdrh# added at the end.
31*aa03c695Sdrh#
32*aa03c695Sdrhset testdir [file dirname $argv0]
33*aa03c695Sdrhsource $testdir/tester.tcl
34*aa03c695Sdrhdb nullvalue -
35*aa03c695Sdrhdb eval {
36*aa03c695Sdrh  CREATE TABLE t1(x INT);
37*aa03c695Sdrh  CREATE TABLE t2(y INT);
38*aa03c695Sdrh  CREATE TABLE t3(z INT);
39*aa03c695Sdrh  CREATE TABLE t4(w INT);
40*aa03c695Sdrh  INSERT INTO t1 VALUES(10);
41*aa03c695Sdrh  INSERT INTO t3 VALUES(20),(30);
42*aa03c695Sdrh  INSERT INTO t4 VALUES(50);
43*aa03c695Sdrh}
44*aa03c695Sdrhdo_execsql_test joinF-1 {
45*aa03c695Sdrh  SELECT *
46*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
47*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
48*aa03c695Sdrh  INNER JOIN t4 ON true
49*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
50*aa03c695Sdrh} {
51*aa03c695Sdrh}
52*aa03c695Sdrhdo_execsql_test joinF-2 {
53*aa03c695Sdrh  SELECT *
54*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
55*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
56*aa03c695Sdrh  INNER JOIN t4 ON true
57*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
58*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
59*aa03c695Sdrh} {
60*aa03c695Sdrh}
61*aa03c695Sdrhdo_execsql_test joinF-3 {
62*aa03c695Sdrh  SELECT *
63*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
64*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
65*aa03c695Sdrh  LEFT JOIN t4 ON true
66*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
67*aa03c695Sdrh} {
68*aa03c695Sdrh}
69*aa03c695Sdrhdo_execsql_test joinF-4 {
70*aa03c695Sdrh  SELECT *
71*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
72*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
73*aa03c695Sdrh  LEFT JOIN t4 ON true
74*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
75*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
76*aa03c695Sdrh} {
77*aa03c695Sdrh}
78*aa03c695Sdrhdo_execsql_test joinF-5 {
79*aa03c695Sdrh  SELECT *
80*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
81*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
82*aa03c695Sdrh  RIGHT JOIN t4 ON true
83*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
84*aa03c695Sdrh} {
85*aa03c695Sdrh  - - - 50
86*aa03c695Sdrh}
87*aa03c695Sdrhdo_execsql_test joinF-6 {
88*aa03c695Sdrh  SELECT *
89*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
90*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
91*aa03c695Sdrh  RIGHT JOIN t4 ON true
92*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
93*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
94*aa03c695Sdrh} {
95*aa03c695Sdrh}
96*aa03c695Sdrhdo_execsql_test joinF-7 {
97*aa03c695Sdrh  SELECT *
98*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
99*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
100*aa03c695Sdrh  INNER JOIN t4 ON true
101*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
102*aa03c695Sdrh} {
103*aa03c695Sdrh}
104*aa03c695Sdrhdo_execsql_test joinF-8 {
105*aa03c695Sdrh  SELECT *
106*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
107*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
108*aa03c695Sdrh  INNER JOIN t4 ON true
109*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
110*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
111*aa03c695Sdrh} {
112*aa03c695Sdrh}
113*aa03c695Sdrhdo_execsql_test joinF-9 {
114*aa03c695Sdrh  SELECT *
115*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
116*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
117*aa03c695Sdrh  LEFT JOIN t4 ON true
118*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
119*aa03c695Sdrh} {
120*aa03c695Sdrh}
121*aa03c695Sdrhdo_execsql_test joinF-10 {
122*aa03c695Sdrh  SELECT *
123*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
124*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
125*aa03c695Sdrh  LEFT JOIN t4 ON true
126*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
127*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
128*aa03c695Sdrh} {
129*aa03c695Sdrh}
130*aa03c695Sdrhdo_execsql_test joinF-11 {
131*aa03c695Sdrh  SELECT *
132*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
133*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
134*aa03c695Sdrh  RIGHT JOIN t4 ON true
135*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
136*aa03c695Sdrh} {
137*aa03c695Sdrh  - - - 50
138*aa03c695Sdrh}
139*aa03c695Sdrhdo_execsql_test joinF-12 {
140*aa03c695Sdrh  SELECT *
141*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
142*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
143*aa03c695Sdrh  RIGHT JOIN t4 ON true
144*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
145*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
146*aa03c695Sdrh} {
147*aa03c695Sdrh}
148*aa03c695Sdrhdo_execsql_test joinF-13 {
149*aa03c695Sdrh  SELECT *
150*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
151*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
152*aa03c695Sdrh  INNER JOIN t4 ON true
153*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
154*aa03c695Sdrh} {
155*aa03c695Sdrh  - - 20 50
156*aa03c695Sdrh  - - 30 50
157*aa03c695Sdrh}
158*aa03c695Sdrhdo_execsql_test joinF-14 {
159*aa03c695Sdrh  SELECT *
160*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
161*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
162*aa03c695Sdrh  INNER JOIN t4 ON true
163*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
164*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
165*aa03c695Sdrh} {
166*aa03c695Sdrh  - - 20 50
167*aa03c695Sdrh  - - 30 50
168*aa03c695Sdrh}
169*aa03c695Sdrhdo_execsql_test joinF-15 {
170*aa03c695Sdrh  SELECT *
171*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
172*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
173*aa03c695Sdrh  LEFT JOIN t4 ON true
174*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
175*aa03c695Sdrh} {
176*aa03c695Sdrh  - - 20 50
177*aa03c695Sdrh  - - 30 50
178*aa03c695Sdrh}
179*aa03c695Sdrhdo_execsql_test joinF-16 {
180*aa03c695Sdrh  SELECT *
181*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
182*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
183*aa03c695Sdrh  LEFT JOIN t4 ON true
184*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
185*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
186*aa03c695Sdrh} {
187*aa03c695Sdrh  - - 20 50
188*aa03c695Sdrh  - - 30 50
189*aa03c695Sdrh}
190*aa03c695Sdrhdo_execsql_test joinF-17 {
191*aa03c695Sdrh  SELECT *
192*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
193*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
194*aa03c695Sdrh  RIGHT JOIN t4 ON true
195*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
196*aa03c695Sdrh} {
197*aa03c695Sdrh  - - 20 50
198*aa03c695Sdrh  - - 30 50
199*aa03c695Sdrh}
200*aa03c695Sdrhdo_execsql_test joinF-18 {
201*aa03c695Sdrh  SELECT *
202*aa03c695Sdrh  FROM t1 INNER JOIN t2 ON true
203*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
204*aa03c695Sdrh  RIGHT JOIN t4 ON true
205*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
206*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
207*aa03c695Sdrh} {
208*aa03c695Sdrh  - - 20 50
209*aa03c695Sdrh  - - 30 50
210*aa03c695Sdrh}
211*aa03c695Sdrhdo_execsql_test joinF-19 {
212*aa03c695Sdrh  SELECT *
213*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
214*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
215*aa03c695Sdrh  INNER JOIN t4 ON true
216*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
217*aa03c695Sdrh} {
218*aa03c695Sdrh}
219*aa03c695Sdrhdo_execsql_test joinF-20 {
220*aa03c695Sdrh  SELECT *
221*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
222*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
223*aa03c695Sdrh  INNER JOIN t4 ON true
224*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
225*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
226*aa03c695Sdrh} {
227*aa03c695Sdrh}
228*aa03c695Sdrhdo_execsql_test joinF-21 {
229*aa03c695Sdrh  SELECT *
230*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
231*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
232*aa03c695Sdrh  LEFT JOIN t4 ON true
233*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
234*aa03c695Sdrh} {
235*aa03c695Sdrh}
236*aa03c695Sdrhdo_execsql_test joinF-22 {
237*aa03c695Sdrh  SELECT *
238*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
239*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
240*aa03c695Sdrh  LEFT JOIN t4 ON true
241*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
242*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
243*aa03c695Sdrh} {
244*aa03c695Sdrh}
245*aa03c695Sdrhdo_execsql_test joinF-23 {
246*aa03c695Sdrh  SELECT *
247*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
248*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
249*aa03c695Sdrh  RIGHT JOIN t4 ON true
250*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
251*aa03c695Sdrh} {
252*aa03c695Sdrh  - - - 50
253*aa03c695Sdrh}
254*aa03c695Sdrhdo_execsql_test joinF-24 {
255*aa03c695Sdrh  SELECT *
256*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
257*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
258*aa03c695Sdrh  RIGHT JOIN t4 ON true
259*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
260*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
261*aa03c695Sdrh} {
262*aa03c695Sdrh}
263*aa03c695Sdrhdo_execsql_test joinF-25 {
264*aa03c695Sdrh  SELECT *
265*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
266*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
267*aa03c695Sdrh  INNER JOIN t4 ON true
268*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
269*aa03c695Sdrh} {
270*aa03c695Sdrh  10 - - 50
271*aa03c695Sdrh}
272*aa03c695Sdrhdo_execsql_test joinF-26 {
273*aa03c695Sdrh  SELECT *
274*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
275*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
276*aa03c695Sdrh  INNER JOIN t4 ON true
277*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
278*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
279*aa03c695Sdrh} {
280*aa03c695Sdrh}
281*aa03c695Sdrhdo_execsql_test joinF-27 {
282*aa03c695Sdrh  SELECT *
283*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
284*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
285*aa03c695Sdrh  LEFT JOIN t4 ON true
286*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
287*aa03c695Sdrh} {
288*aa03c695Sdrh  10 - - 50
289*aa03c695Sdrh}
290*aa03c695Sdrhdo_execsql_test joinF-28 {
291*aa03c695Sdrh  SELECT *
292*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
293*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
294*aa03c695Sdrh  LEFT JOIN t4 ON true
295*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
296*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
297*aa03c695Sdrh} {
298*aa03c695Sdrh}
299*aa03c695Sdrhdo_execsql_test joinF-29 {
300*aa03c695Sdrh  SELECT *
301*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
302*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
303*aa03c695Sdrh  RIGHT JOIN t4 ON true
304*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
305*aa03c695Sdrh} {
306*aa03c695Sdrh  10 - - 50
307*aa03c695Sdrh}
308*aa03c695Sdrhdo_execsql_test joinF-30 {
309*aa03c695Sdrh  SELECT *
310*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
311*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
312*aa03c695Sdrh  RIGHT JOIN t4 ON true
313*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
314*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
315*aa03c695Sdrh} {
316*aa03c695Sdrh}
317*aa03c695Sdrhdo_execsql_test joinF-31 {
318*aa03c695Sdrh  SELECT *
319*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
320*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
321*aa03c695Sdrh  INNER JOIN t4 ON true
322*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
323*aa03c695Sdrh} {
324*aa03c695Sdrh  - - 20 50
325*aa03c695Sdrh  - - 30 50
326*aa03c695Sdrh}
327*aa03c695Sdrhdo_execsql_test joinF-32 {
328*aa03c695Sdrh  SELECT *
329*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
330*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
331*aa03c695Sdrh  INNER JOIN t4 ON true
332*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
333*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
334*aa03c695Sdrh} {
335*aa03c695Sdrh  - - 20 50
336*aa03c695Sdrh  - - 30 50
337*aa03c695Sdrh}
338*aa03c695Sdrhdo_execsql_test joinF-33 {
339*aa03c695Sdrh  SELECT *
340*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
341*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
342*aa03c695Sdrh  LEFT JOIN t4 ON true
343*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
344*aa03c695Sdrh} {
345*aa03c695Sdrh  - - 20 50
346*aa03c695Sdrh  - - 30 50
347*aa03c695Sdrh}
348*aa03c695Sdrhdo_execsql_test joinF-34 {
349*aa03c695Sdrh  SELECT *
350*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
351*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
352*aa03c695Sdrh  LEFT JOIN t4 ON true
353*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
354*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
355*aa03c695Sdrh} {
356*aa03c695Sdrh  - - 20 50
357*aa03c695Sdrh  - - 30 50
358*aa03c695Sdrh}
359*aa03c695Sdrhdo_execsql_test joinF-35 {
360*aa03c695Sdrh  SELECT *
361*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
362*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
363*aa03c695Sdrh  RIGHT JOIN t4 ON true
364*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
365*aa03c695Sdrh} {
366*aa03c695Sdrh  - - 20 50
367*aa03c695Sdrh  - - 30 50
368*aa03c695Sdrh}
369*aa03c695Sdrhdo_execsql_test joinF-36 {
370*aa03c695Sdrh  SELECT *
371*aa03c695Sdrh  FROM t1 LEFT JOIN t2 ON true
372*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
373*aa03c695Sdrh  RIGHT JOIN t4 ON true
374*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
375*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
376*aa03c695Sdrh} {
377*aa03c695Sdrh  - - 20 50
378*aa03c695Sdrh  - - 30 50
379*aa03c695Sdrh}
380*aa03c695Sdrhdo_execsql_test joinF-37 {
381*aa03c695Sdrh  SELECT *
382*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
383*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
384*aa03c695Sdrh  INNER JOIN t4 ON true
385*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
386*aa03c695Sdrh} {
387*aa03c695Sdrh}
388*aa03c695Sdrhdo_execsql_test joinF-38 {
389*aa03c695Sdrh  SELECT *
390*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
391*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
392*aa03c695Sdrh  INNER JOIN t4 ON true
393*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
394*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
395*aa03c695Sdrh} {
396*aa03c695Sdrh}
397*aa03c695Sdrhdo_execsql_test joinF-39 {
398*aa03c695Sdrh  SELECT *
399*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
400*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
401*aa03c695Sdrh  LEFT JOIN t4 ON true
402*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
403*aa03c695Sdrh} {
404*aa03c695Sdrh}
405*aa03c695Sdrhdo_execsql_test joinF-40 {
406*aa03c695Sdrh  SELECT *
407*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
408*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
409*aa03c695Sdrh  LEFT JOIN t4 ON true
410*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
411*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
412*aa03c695Sdrh} {
413*aa03c695Sdrh}
414*aa03c695Sdrhdo_execsql_test joinF-41 {
415*aa03c695Sdrh  SELECT *
416*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
417*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
418*aa03c695Sdrh  RIGHT JOIN t4 ON true
419*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
420*aa03c695Sdrh} {
421*aa03c695Sdrh  - - - 50
422*aa03c695Sdrh}
423*aa03c695Sdrhdo_execsql_test joinF-42 {
424*aa03c695Sdrh  SELECT *
425*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
426*aa03c695Sdrh  INNER JOIN t3 ON t2.y IS NOT NULL
427*aa03c695Sdrh  RIGHT JOIN t4 ON true
428*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
429*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
430*aa03c695Sdrh} {
431*aa03c695Sdrh}
432*aa03c695Sdrhdo_execsql_test joinF-43 {
433*aa03c695Sdrh  SELECT *
434*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
435*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
436*aa03c695Sdrh  INNER JOIN t4 ON true
437*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
438*aa03c695Sdrh} {
439*aa03c695Sdrh}
440*aa03c695Sdrhdo_execsql_test joinF-44 {
441*aa03c695Sdrh  SELECT *
442*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
443*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
444*aa03c695Sdrh  INNER JOIN t4 ON true
445*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
446*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
447*aa03c695Sdrh} {
448*aa03c695Sdrh}
449*aa03c695Sdrhdo_execsql_test joinF-45 {
450*aa03c695Sdrh  SELECT *
451*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
452*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
453*aa03c695Sdrh  LEFT JOIN t4 ON true
454*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
455*aa03c695Sdrh} {
456*aa03c695Sdrh}
457*aa03c695Sdrhdo_execsql_test joinF-46 {
458*aa03c695Sdrh  SELECT *
459*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
460*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
461*aa03c695Sdrh  LEFT JOIN t4 ON true
462*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
463*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
464*aa03c695Sdrh} {
465*aa03c695Sdrh}
466*aa03c695Sdrhdo_execsql_test joinF-47 {
467*aa03c695Sdrh  SELECT *
468*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
469*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
470*aa03c695Sdrh  RIGHT JOIN t4 ON true
471*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
472*aa03c695Sdrh} {
473*aa03c695Sdrh  - - - 50
474*aa03c695Sdrh}
475*aa03c695Sdrhdo_execsql_test joinF-48 {
476*aa03c695Sdrh  SELECT *
477*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
478*aa03c695Sdrh  LEFT JOIN t3 ON t2.y IS NOT NULL
479*aa03c695Sdrh  RIGHT JOIN t4 ON true
480*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
481*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
482*aa03c695Sdrh} {
483*aa03c695Sdrh}
484*aa03c695Sdrhdo_execsql_test joinF-49 {
485*aa03c695Sdrh  SELECT *
486*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
487*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
488*aa03c695Sdrh  INNER JOIN t4 ON true
489*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
490*aa03c695Sdrh} {
491*aa03c695Sdrh  - - 20 50
492*aa03c695Sdrh  - - 30 50
493*aa03c695Sdrh}
494*aa03c695Sdrhdo_execsql_test joinF-50 {
495*aa03c695Sdrh  SELECT *
496*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
497*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
498*aa03c695Sdrh  INNER JOIN t4 ON true
499*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
500*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
501*aa03c695Sdrh} {
502*aa03c695Sdrh  - - 20 50
503*aa03c695Sdrh  - - 30 50
504*aa03c695Sdrh}
505*aa03c695Sdrhdo_execsql_test joinF-51 {
506*aa03c695Sdrh  SELECT *
507*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
508*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
509*aa03c695Sdrh  LEFT JOIN t4 ON true
510*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
511*aa03c695Sdrh} {
512*aa03c695Sdrh  - - 20 50
513*aa03c695Sdrh  - - 30 50
514*aa03c695Sdrh}
515*aa03c695Sdrhdo_execsql_test joinF-52 {
516*aa03c695Sdrh  SELECT *
517*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
518*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
519*aa03c695Sdrh  LEFT JOIN t4 ON true
520*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
521*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
522*aa03c695Sdrh} {
523*aa03c695Sdrh  - - 20 50
524*aa03c695Sdrh  - - 30 50
525*aa03c695Sdrh}
526*aa03c695Sdrhdo_execsql_test joinF-53 {
527*aa03c695Sdrh  SELECT *
528*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
529*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
530*aa03c695Sdrh  RIGHT JOIN t4 ON true
531*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
532*aa03c695Sdrh} {
533*aa03c695Sdrh  - - 20 50
534*aa03c695Sdrh  - - 30 50
535*aa03c695Sdrh}
536*aa03c695Sdrhdo_execsql_test joinF-54 {
537*aa03c695Sdrh  SELECT *
538*aa03c695Sdrh  FROM t1 RIGHT JOIN t2 ON true
539*aa03c695Sdrh  RIGHT JOIN t3 ON t2.y IS NOT NULL
540*aa03c695Sdrh  RIGHT JOIN t4 ON true
541*aa03c695Sdrh  WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
542*aa03c695Sdrh  ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
543*aa03c695Sdrh} {
544*aa03c695Sdrh  - - 20 50
545*aa03c695Sdrh  - - 30 50
546*aa03c695Sdrh}
547*aa03c695Sdrhfinish_test
548*aa03c695Sdrh
549*aa03c695Sdrh############################################################################
550*aa03c695Sdrh# This is the TCL script used to generate the psql script that generated
551*aa03c695Sdrh# the data above.
552*aa03c695Sdrh#
553*aa03c695Sdrh# puts "
554*aa03c695Sdrh# \\pset border off
555*aa03c695Sdrh# \\pset tuples_only on
556*aa03c695Sdrh# \\pset null -
557*aa03c695Sdrh#
558*aa03c695Sdrh# DROP TABLE IF EXISTS t1;
559*aa03c695Sdrh# DROP TABLE IF EXISTS t2;
560*aa03c695Sdrh# DROP TABLE IF EXISTS t3;
561*aa03c695Sdrh# DROP TABLE IF EXISTS t4;
562*aa03c695Sdrh# CREATE TABLE t1(x INT);
563*aa03c695Sdrh# CREATE TABLE t2(y INT);
564*aa03c695Sdrh# CREATE TABLE t3(z INT);
565*aa03c695Sdrh# CREATE TABLE t4(w INT);
566*aa03c695Sdrh# INSERT INTO t1 VALUES(10);
567*aa03c695Sdrh# INSERT INTO t3 VALUES(20),(30);
568*aa03c695Sdrh# INSERT INTO t4 VALUES(50);
569*aa03c695Sdrh# "
570*aa03c695Sdrh#
571*aa03c695Sdrh# proc echo {prefix txt} {
572*aa03c695Sdrh#   regsub -all {\n} $txt \n$prefix txt
573*aa03c695Sdrh#   puts "$prefix$txt"
574*aa03c695Sdrh# }
575*aa03c695Sdrh#
576*aa03c695Sdrh# set n 0
577*aa03c695Sdrh# foreach j1 {INNER LEFT RIGHT} {
578*aa03c695Sdrh#   foreach j2 {INNER LEFT RIGHT} {
579*aa03c695Sdrh#     foreach j3 {INNER LEFT RIGHT} {
580*aa03c695Sdrh#
581*aa03c695Sdrh# incr n
582*aa03c695Sdrh# set q1 ""
583*aa03c695Sdrh# append q1 "SELECT *\n"
584*aa03c695Sdrh# append q1 "  FROM t1 $j1 JOIN t2 ON true\n"
585*aa03c695Sdrh# append q1 "          $j2 JOIN t3 ON t2.y IS NOT NULL\n"
586*aa03c695Sdrh# append q1 "          $j3 JOIN t4 ON true\n"
587*aa03c695Sdrh# append q1 " ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);"
588*aa03c695Sdrh#
589*aa03c695Sdrh# echo "\\qecho " "do_execsql_test joinF-$n \{"
590*aa03c695Sdrh# echo "\\qecho X  " $q1
591*aa03c695Sdrh# echo "\\qecho " "\} \{"
592*aa03c695Sdrh# puts $q1
593*aa03c695Sdrh# echo "\\qecho " "\}"
594*aa03c695Sdrh#
595*aa03c695Sdrh# incr n
596*aa03c695Sdrh# set q1 ""
597*aa03c695Sdrh# append q1 "SELECT *\n"
598*aa03c695Sdrh# append q1 "  FROM t1 $j1 JOIN t2 ON true\n"
599*aa03c695Sdrh# append q1 "          $j2 JOIN t3 ON t2.y IS NOT NULL\n"
600*aa03c695Sdrh# append q1 "          $j3 JOIN t4 ON true\n"
601*aa03c695Sdrh# append q1 " WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)\n"
602*aa03c695Sdrh# append q1 " ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);"
603*aa03c695Sdrh#
604*aa03c695Sdrh# echo "\\qecho " "do_execsql_test joinF-$n \{"
605*aa03c695Sdrh# echo "\\qecho X  " $q1
606*aa03c695Sdrh# echo "\\qecho " "\} \{"
607*aa03c695Sdrh# puts $q1
608*aa03c695Sdrh# echo "\\qecho " "\}"
609*aa03c695Sdrh#
610*aa03c695Sdrh#     }
611*aa03c695Sdrh#   }
612*aa03c695Sdrh# }
613*aa03c695Sdrh#
614