3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests for joins, including outer joins.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
21 CREATE TABLE t1(a,b,c);
22 INSERT INTO t1 VALUES(1,2,3);
23 INSERT INTO t1 VALUES(2,3,4);
24 INSERT INTO t1 VALUES(3,4,5);
30 CREATE TABLE t2(b,c,d);
31 INSERT INTO t2 VALUES(1,2,3);
32 INSERT INTO t2 VALUES(2,3,4);
33 INSERT INTO t2 VALUES(3,4,5);
38 # A FROM clause of the form: "<table>, <table> ON <expr>" is not
39 # allowed by the SQLite syntax diagram, nor by any other SQL database
40 # engine that we are aware of. Nevertheless, historic versions of
41 # SQLite have allowed it. We need to continue to support it moving
42 # forward to prevent breakage of legacy applications. Though, we will
43 # not advertise it as being supported.
45 do_execsql_test join-1.2.1 {
46 SELECT t1.rowid, t2.rowid, '|' FROM t1, t2 ON t1.a=t2.b;
51 SELECT * FROM t1 NATURAL JOIN t2;
53 } {a 1 b 2 c 3 d 4 a 2 b 3 c 4 d 5}
56 SELECT * FROM t2 NATURAL JOIN t1;
58 } {b 2 c 3 d 4 a 1 b 3 c 4 d 5 a 2}
61 SELECT * FROM t2 AS x NATURAL JOIN t1;
63 } {b 2 c 3 d 4 a 1 b 3 c 4 d 5 a 2}
66 SELECT * FROM t2 NATURAL JOIN t1 AS y;
68 } {b 2 c 3 d 4 a 1 b 3 c 4 d 5 a 2}
71 SELECT b FROM t1 NATURAL JOIN t2;
78 SELECT t2.* FROM t2 NATURAL JOIN t1
80 } {b 2 c 3 d 4 b 3 c 4 d 5}
83 SELECT xyzzy.* FROM t2 AS xyzzy NATURAL JOIN t1
85 } {b 2 c 3 d 4 b 3 c 4 d 5}
88 SELECT t1.* FROM t2 NATURAL JOIN t1
90 } {a 1 b 2 c 3 a 2 b 3 c 4}
93 SELECT xyzzy.* FROM t2 NATURAL JOIN t1 AS xyzzy
95 } {a 1 b 2 c 3 a 2 b 3 c 4}
98 SELECT aaa.*, bbb.* FROM t2 AS aaa NATURAL JOIN t1 AS bbb
100 } {b 2 c 3 d 4 a 1 b 2 c 3 b 3 c 4 d 5 a 2 b 3 c 4}
101 do_test join-1.3.10 {
103 SELECT t1.*, t2.* FROM t2 NATURAL JOIN t1
105 } {a 1 b 2 c 3 b 2 c 3 d 4 a 2 b 3 c 4 b 3 c 4 d 5}
110 SELECT * FROM t1 INNER JOIN t2 USING(b,c);
112 } {a 1 b 2 c 3 d 4 a 2 b 3 c 4 d 5}
115 SELECT * FROM t1 AS x INNER JOIN t2 USING(b,c);
117 } {a 1 b 2 c 3 d 4 a 2 b 3 c 4 d 5}
120 SELECT * FROM t1 INNER JOIN t2 AS y USING(b,c);
122 } {a 1 b 2 c 3 d 4 a 2 b 3 c 4 d 5}
125 SELECT * FROM t1 AS x INNER JOIN t2 AS y USING(b,c);
127 } {a 1 b 2 c 3 d 4 a 2 b 3 c 4 d 5}
130 SELECT b FROM t1 JOIN t2 USING(b);
137 SELECT t1.* FROM t1 JOIN t2 USING(b);
139 } {a 1 b 2 c 3 a 2 b 3 c 4}
142 SELECT t2.* FROM t1 JOIN t2 USING(b);
144 } {b 2 c 3 d 4 b 3 c 4 d 5}
148 SELECT * FROM t1 INNER JOIN t2 USING(b);
150 } {a 1 b 2 c 3 c 3 d 4 a 2 b 3 c 4 c 4 d 5}
153 SELECT * FROM t1 INNER JOIN t2 USING(c);
155 } {a 1 b 2 c 3 b 2 d 4 a 2 b 3 c 4 b 3 d 5}
158 SELECT * FROM t1 INNER JOIN t2 USING(c,b);
160 } {a 1 b 2 c 3 d 4 a 2 b 3 c 4 d 5}
164 SELECT * FROM t1 NATURAL CROSS JOIN t2;
169 SELECT * FROM t1 CROSS JOIN t2 USING(b,c);
174 SELECT * FROM t1 NATURAL INNER JOIN t2;
179 SELECT * FROM t1 INNER JOIN t2 USING(b,c);
184 SELECT * FROM t1 natural inner join t2;
191 SELECT * FROM t1 NATURAL JOIN
192 (SELECT b as 'c', c as 'd', d as 'e' FROM t2) as t3
194 } {a 1 b 2 c 3 d 4 e 5}
197 SELECT * FROM (SELECT b as 'c', c as 'd', d as 'e' FROM t2) as 'tx'
200 } {c 3 d 4 e 5 a 1 b 2}
205 CREATE TABLE t3(c,d,e);
206 INSERT INTO t3 VALUES(2,3,4);
207 INSERT INTO t3 VALUES(3,4,5);
208 INSERT INTO t3 VALUES(4,5,6);
211 } {2 3 4 3 4 5 4 5 6}
214 SELECT * FROM t1 natural join t2 natural join t3;
216 } {1 2 3 4 5 2 3 4 5 6}
219 SELECT * FROM t1 natural join t2 natural join t3;
221 } {a 1 b 2 c 3 d 4 e 5 a 2 b 3 c 4 d 5 e 6}
224 CREATE TABLE t4(d,e,f);
225 INSERT INTO t4 VALUES(2,3,4);
226 INSERT INTO t4 VALUES(3,4,5);
227 INSERT INTO t4 VALUES(4,5,6);
230 } {2 3 4 3 4 5 4 5 6}
231 do_test join-1.19.1 {
233 SELECT * FROM t1 natural join t2 natural join t4;
236 do_test join-1.19.2 {
238 SELECT * FROM t1 natural join t2 natural join t4;
240 } {a 1 b 2 c 3 d 4 e 5 f 6}
243 SELECT * FROM t1 natural join t2 natural join t3 WHERE t1.a=1
249 SELECT * FROM t1 NATURAL LEFT JOIN t2;
251 } {1 2 3 4 2 3 4 5 3 4 5 {}}
256 SELECT * FROM t1 NATURAL LEFT JOIN t2;
258 } {a 1 b 2 c 3 d 4 a 2 b 3 c 4 d 5 a 3 b 4 c 5 d {}}
261 SELECT t1.* FROM t1 NATURAL LEFT JOIN t2;
263 } {a 1 b 2 c 3 a 2 b 3 c 4 a 3 b 4 c 5}
266 SELECT t2.* FROM t1 NATURAL LEFT JOIN t2;
268 } {b 2 c 3 d 4 b 3 c 4 d 5 b {} c {} d {}}
272 SELECT * FROM t2 NATURAL LEFT OUTER JOIN t1;
274 } {1 2 3 {} 2 3 4 1 3 4 5 2}
277 SELECT * FROM t1 NATURAL RIGHT OUTER JOIN t2;
279 } {1 {RIGHT and FULL OUTER JOINs are not currently supported}}
282 SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.d
284 } {1 2 3 {} {} {} 2 3 4 {} {} {} 3 4 5 1 2 3}
287 SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.d WHERE t1.a>1
289 } {2 3 4 {} {} {} 3 4 5 1 2 3}
292 SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.d WHERE t2.b IS NULL OR t2.b>1
294 } {1 2 3 {} {} {} 2 3 4 {} {} {}}
298 SELECT * FROM t1 NATURAL JOIN t2 ON t1.a=t2.b;
300 } {1 {a NATURAL join may not have an ON or USING clause}}
303 SELECT * FROM t1 NATURAL JOIN t2 USING(b);
305 } {1 {a NATURAL join may not have an ON or USING clause}}
308 SELECT * FROM t1 JOIN t2 ON t1.a=t2.b USING(b);
310 } {1 {cannot have both ON and USING clauses in the same join}}
313 SELECT * FROM t1 JOIN t2 USING(a);
315 } {1 {cannot join using column a - column not present in both tables}}
318 SELECT * FROM t1 JOIN t2 USING(d);
320 } {1 {cannot join using column d - column not present in both tables}}
322 catchsql { SELECT * FROM t1 USING(a) }
323 } {1 {a JOIN clause is required before USING}}
326 SELECT * FROM t1 JOIN t2 ON t3.a=t2.b;
328 } {1 {no such column: t3.a}}
331 SELECT * FROM t1 INNER OUTER JOIN t2;
333 } {1 {unknown or unsupported join type: INNER OUTER}}
336 SELECT * FROM t1 INNER OUTER CROSS JOIN t2;
338 } {1 {unknown or unsupported join type: INNER OUTER CROSS}}
341 SELECT * FROM t1 OUTER NATURAL INNER JOIN t2;
343 } {1 {unknown or unsupported join type: OUTER NATURAL INNER}}
346 SELECT * FROM t1 LEFT BOGUS JOIN t2;
348 } {1 {unknown or unsupported join type: LEFT BOGUS}}
351 SELECT * FROM t1 INNER BOGUS CROSS JOIN t2;
353 } {1 {unknown or unsupported join type: INNER BOGUS CROSS}}
356 SELECT * FROM t1 NATURAL AWK SED JOIN t2;
358 } {1 {unknown or unsupported join type: NATURAL AWK SED}}
363 CREATE TABLE t5(a INTEGER PRIMARY KEY);
364 CREATE TABLE t6(a INTEGER);
365 INSERT INTO t6 VALUES(NULL);
366 INSERT INTO t6 VALUES(NULL);
367 INSERT INTO t6 SELECT * FROM t6;
368 INSERT INTO t6 SELECT * FROM t6;
369 INSERT INTO t6 SELECT * FROM t6;
370 INSERT INTO t6 SELECT * FROM t6;
371 INSERT INTO t6 SELECT * FROM t6;
372 INSERT INTO t6 SELECT * FROM t6;
376 SELECT * FROM t6 NATURAL JOIN t5;
381 SELECT * FROM t6, t5 WHERE t6.a<t5.a;
386 SELECT * FROM t6, t5 WHERE t6.a>t5.a;
391 UPDATE t6 SET a='xyz';
392 SELECT * FROM t6 NATURAL JOIN t5;
397 SELECT * FROM t6, t5 WHERE t6.a<t5.a;
402 SELECT * FROM t6, t5 WHERE t6.a>t5.a;
408 SELECT * FROM t6 NATURAL JOIN t5;
413 SELECT * FROM t6, t5 WHERE t6.a<t5.a;
418 SELECT * FROM t6, t5 WHERE t6.a>t5.a;
425 create table centros (id integer primary key, centro);
426 INSERT INTO centros VALUES(1,'xxx');
427 create table usuarios (id integer primary key, nombre, apellidos,
429 INSERT INTO usuarios VALUES(1,'a','aa',1);
430 INSERT INTO usuarios VALUES(2,'b','bb',1);
431 INSERT INTO usuarios VALUES(3,'c','cc',NULL);
432 create index idcentro on usuarios (idcentro);
434 select usuarios.id, usuarios.nombre, centros.centro from
435 usuarios left outer join centros on usuarios.idcentro = centros.id;
437 } {1 a xxx 2 b xxx 3 c {}}
439 # A test for ticket #247.
443 CREATE TABLE t7 (x, y);
444 INSERT INTO t7 VALUES ("pa1", 1);
445 INSERT INTO t7 VALUES ("pa2", NULL);
446 INSERT INTO t7 VALUES ("pa3", NULL);
447 INSERT INTO t7 VALUES ("pa4", 2);
448 INSERT INTO t7 VALUES ("pa30", 131);
449 INSERT INTO t7 VALUES ("pa31", 130);
450 INSERT INTO t7 VALUES ("pa28", NULL);
452 CREATE TABLE t8 (a integer primary key, b);
453 INSERT INTO t8 VALUES (1, "pa1");
454 INSERT INTO t8 VALUES (2, "pa4");
455 INSERT INTO t8 VALUES (3, NULL);
456 INSERT INTO t8 VALUES (4, NULL);
457 INSERT INTO t8 VALUES (130, "pa31");
458 INSERT INTO t8 VALUES (131, "pa30");
460 SELECT coalesce(t8.a,999) from t7 LEFT JOIN t8 on y=a;
462 } {1 999 999 2 131 130 999}
464 # Make sure a left join where the right table is really a view that
465 # is itself a join works right. Ticket #306.
471 CREATE TABLE t9(a INTEGER PRIMARY KEY, b);
472 INSERT INTO t9 VALUES(1,11);
473 INSERT INTO t9 VALUES(2,22);
474 CREATE TABLE t10(x INTEGER PRIMARY KEY, y);
475 INSERT INTO t10 VALUES(1,2);
476 INSERT INTO t10 VALUES(3,3);
477 CREATE TABLE t11(p INTEGER PRIMARY KEY, q);
478 INSERT INTO t11 VALUES(2,111);
479 INSERT INTO t11 VALUES(3,333);
480 CREATE VIEW v10_11 AS SELECT x, q FROM t10, t11 WHERE t10.y=t11.p;
482 SELECT * FROM t9 LEFT JOIN v10_11 ON( a=x );
484 } {1 11 1 111 2 22 {} {}}
488 SELECT * FROM t9 LEFT JOIN (SELECT x, q FROM t10, t11 WHERE t10.y=t11.p)
491 } {1 11 1 111 2 22 {} {}}
495 SELECT * FROM v10_11 LEFT JOIN t9 ON( a=x );
497 } {1 111 1 11 3 333 {} {}}
499 # Constant expressions in a subquery that is the right element of a
500 # LEFT JOIN evaluate to NULL for rows where the LEFT JOIN does not
501 # match. Ticket #3300
504 SELECT * FROM t9 LEFT JOIN (SELECT 44, p, q FROM t11) AS sub1 ON p=a
506 } {1 11 {} {} {} 2 22 44 2 111}
510 # Ticket #350 describes a scenario where LEFT OUTER JOIN does not
511 # function correctly if the right table in the join is really
514 # To test the problem, we generate the same LEFT OUTER JOIN in two
515 # separate selects but with on using a subquery and the other calling
516 # the table directly. Then connect the two SELECTs using an EXCEPT.
517 # Both queries should generate the same results so the answer should
524 CREATE TABLE t12(a,b);
525 INSERT INTO t12 VALUES(1,11);
526 INSERT INTO t12 VALUES(2,22);
527 CREATE TABLE t13(b,c);
528 INSERT INTO t13 VALUES(22,222);
536 SELECT * FROM t12 NATURAL LEFT JOIN t13
538 SELECT * FROM t12 NATURAL LEFT JOIN (SELECT * FROM t13 WHERE b>0);
545 CREATE VIEW v13 AS SELECT * FROM t13 WHERE b>0;
546 SELECT * FROM t12 NATURAL LEFT JOIN t13
548 SELECT * FROM t12 NATURAL LEFT JOIN v13;
552 } ;# ifcapable compound
555 # Ticket #1697: Left Join WHERE clause terms that contain an
556 # aggregate subquery.
560 CREATE TABLE t21(a,b,c);
561 CREATE TABLE t22(p,q);
562 CREATE INDEX i22 ON t22(q);
563 SELECT a FROM t21 LEFT JOIN t22 ON b=p WHERE q=
564 (SELECT max(m.q) FROM t22 m JOIN t21 n ON n.b=m.p WHERE n.c=1);
568 # Test a LEFT JOIN when the right-hand side of hte join is an empty
569 # sub-query. Seems fine.
573 CREATE TABLE t23(a, b, c);
574 CREATE TABLE t24(a, b, c);
575 INSERT INTO t23 VALUES(1, 2, 3);
578 SELECT * FROM t23 LEFT JOIN t24;
583 SELECT * FROM t23 LEFT JOIN (SELECT * FROM t24);
587 } ;# ifcapable subquery
589 #-------------------------------------------------------------------------
590 # The following tests are to ensure that bug b73fb0bd64 is fixed.
595 CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT);
596 CREATE TABLE t2(a INTEGER PRIMARY KEY, b TEXT);
597 INSERT INTO t1 VALUES(1,'abc');
598 INSERT INTO t1 VALUES(2,'def');
599 INSERT INTO t2 VALUES(1,'abc');
600 INSERT INTO t2 VALUES(2,'def');
601 SELECT * FROM t1 NATURAL JOIN t2;
606 execsql { SELECT a FROM t1 JOIN t1 USING (a)}
609 execsql { SELECT a FROM t1 JOIN t1 AS t2 USING (a)}
612 execsql { SELECT * FROM t1 NATURAL JOIN t1 AS t2}
615 execsql { SELECT * FROM t1 NATURAL JOIN t1 }
621 CREATE TABLE t1(a COLLATE nocase, b);
622 CREATE TABLE t2(a, b);
623 INSERT INTO t1 VALUES('ONE', 1);
624 INSERT INTO t1 VALUES('two', 2);
625 INSERT INTO t2 VALUES('one', 1);
626 INSERT INTO t2 VALUES('two', 2);
630 execsql { SELECT * FROM t1 NATURAL JOIN t2 }
633 execsql { SELECT * FROM t2 NATURAL JOIN t1 }
639 CREATE TABLE t1(a, b TEXT);
640 CREATE TABLE t2(b INTEGER, a);
641 INSERT INTO t1 VALUES('one', '1.0');
642 INSERT INTO t1 VALUES('two', '2');
643 INSERT INTO t2 VALUES(1, 'one');
644 INSERT INTO t2 VALUES(2, 'two');
648 execsql { SELECT * FROM t1 NATURAL JOIN t2 }
651 execsql { SELECT * FROM t2 NATURAL JOIN t1 }
654 #-------------------------------------------------------------------------
655 # Test that at most 64 tables are allowed in a join.
657 do_execsql_test join-12.1 {
659 INSERT INTO t14 VALUES('abcdefghij');
662 proc jointest {tn nTbl res} {
663 set sql "SELECT 1 FROM [string repeat t14, [expr $nTbl-1]] t14;"
664 uplevel [list do_catchsql_test $tn $sql $res]
667 jointest join-12.2 30 {0 1}
668 jointest join-12.3 63 {0 1}
669 jointest join-12.4 64 {0 1}
670 jointest join-12.5 65 {1 {at most 64 tables in a join}}
671 jointest join-12.6 66 {1 {at most 64 tables in a join}}
672 jointest join-12.7 127 {1 {at most 64 tables in a join}}
673 jointest join-12.8 128 {1 {at most 64 tables in a join}}
674 jointest join-12.9 1000 {1 {at most 64 tables in a join}}
676 # If SQLite is built with SQLITE_MEMDEBUG, then the huge number of realloc()
677 # calls made by the following test cases are too time consuming to run.
678 # Without SQLITE_MEMDEBUG, realloc() is fast enough that these are not
680 ifcapable pragma&&compileoption_diags {
681 if {[lsearch [db eval {PRAGMA compile_options}] MEMDEBUG]<0} {
682 jointest join-12.10 65534 {1 {at most 64 tables in a join}}
683 jointest join-12.11 65535 {1 {too many references to "t14": max 65535}}
684 jointest join-12.12 65536 {1 {too many references to "t14": max 65535}}
685 jointest join-12.13 65537 {1 {too many references to "t14": max 65535}}
690 #-------------------------------------------------------------------------
691 # Test a problem with reordering tables following a LEFT JOIN.
693 do_execsql_test join-13.0 {
698 INSERT INTO aa VALUES(45);
699 INSERT INTO cc VALUES(45);
700 INSERT INTO cc VALUES(45);
703 do_execsql_test join-13.1 {
704 SELECT * FROM aa LEFT JOIN bb, cc WHERE cc.c=aa.a;
705 } {45 {} 45 45 {} 45}
707 # In the following, the order of [cc] and [bb] must not be exchanged, even
708 # though this would be helpful if the query used an inner join.
709 do_execsql_test join-13.2 {
710 CREATE INDEX ccc ON cc(c);
711 SELECT * FROM aa LEFT JOIN bb, cc WHERE cc.c=aa.a;
712 } {45 {} 45 45 {} 45}
714 # Verify that that iTable attributes the TK_IF_NULL_ROW operators in the
715 # expression tree are correctly updated by the query flattener. This was
716 # a bug discovered on 2017-05-22 by Mark Brand.
718 do_execsql_test join-14.1 {
720 FROM (SELECT 1 a) AS x
721 LEFT JOIN (SELECT 1, * FROM (SELECT * FROM (SELECT 1)));
723 do_execsql_test join-14.2 {
725 FROM (SELECT 1 a) AS x
726 LEFT JOIN (SELECT 1, * FROM (SELECT * FROM (SELECT * FROM (SELECT 1)))) AS y
727 JOIN (SELECT * FROM (SELECT 9)) AS z;
729 do_execsql_test join-14.3 {
732 LEFT JOIN (SELECT cc+222, * FROM (SELECT * FROM (SELECT 333 cc)));
735 do_execsql_test join-14.4 {
736 DROP TABLE IF EXISTS t1;
737 CREATE TABLE t1(c PRIMARY KEY, a TEXT(10000), b TEXT(10000));
738 SELECT * FROM (SELECT 111) LEFT JOIN (SELECT c+222 FROM t1) GROUP BY 1;
740 do_execsql_test join-14.5 {
741 DROP TABLE IF EXISTS t1;
742 CREATE TABLE t1(c PRIMARY KEY) WITHOUT ROWID;
743 SELECT * FROM (SELECT 111) LEFT JOIN (SELECT c+222 FROM t1) GROUP BY 1;
746 # Verify the fix to ticket
747 # https://www.sqlite.org/src/tktview/7fde638e94287d2c948cd9389
751 do_execsql_test join-14.10 {
753 INSERT INTO t1 VALUES(1),(2),(3);
754 CREATE VIEW v2 AS SELECT a, 1 AS b FROM t1;
756 INSERT INTO t3 VALUES(2),(4);
757 SELECT *, '|' FROM t3 LEFT JOIN v2 ON a=x WHERE b=1;
759 do_execsql_test join-14.11 {
760 SELECT *, '|' FROM t3 LEFT JOIN v2 ON a=x WHERE b+1=x;
762 do_execsql_test join-14.12 {
763 SELECT *, '|' FROM t3 LEFT JOIN v2 ON a=x ORDER BY b;
764 } {4 {} {} | 2 2 1 |}
766 # Verify the fix for ticket
767 # https://www.sqlite.org/src/info/892fc34f173e99d8
771 do_execsql_test join-14.20 {
772 CREATE TABLE t1(id INTEGER PRIMARY KEY);
773 CREATE TABLE t2(id INTEGER PRIMARY KEY, c2 INTEGER);
774 CREATE TABLE t3(id INTEGER PRIMARY KEY, c3 INTEGER);
775 INSERT INTO t1(id) VALUES(456);
776 INSERT INTO t3(id) VALUES(1),(2);
777 SELECT t1.id, x2.id, x3.id
779 LEFT JOIN (SELECT * FROM t2) AS x2 ON t1.id=x2.c2
780 LEFT JOIN t3 AS x3 ON x2.id=x3.c3;
784 # E.Pasma discovered that the LEFT JOIN strength reduction optimization
785 # was misbehaving. The problem turned out to be that the
786 # sqlite3ExprImpliesNotNull() routine was saying that CASE expressions
789 # CASE WHEN true THEN true ELSE x=0 END
791 # could never be true if x is NULL. The following test cases verify
792 # that this error has been resolved.
796 do_execsql_test join-15.100 {
797 CREATE TABLE t1(a INT, b INT);
798 INSERT INTO t1 VALUES(1,2),(3,4);
799 CREATE TABLE t2(x INT, y INT);
802 WHERE CASE WHEN FALSE THEN a=x ELSE 1 END;
803 } {1 2 {} {} x 3 4 {} {} x}
804 do_execsql_test join-15.105 {
807 WHERE a IN (1,3,x,y);
808 } {1 2 {} {} x 3 4 {} {} x}
809 do_execsql_test join-15.106 {
812 WHERE NOT ( 'x'='y' AND t2.y=1 );
813 } {1 2 {} {} x 3 4 {} {} x}
814 do_execsql_test join-15.107 {
817 WHERE t2.y IS NOT 'abc'
818 } {1 2 {} {} x 3 4 {} {} x}
819 do_execsql_test join-15.110 {
822 CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER);
823 INSERT INTO t1(a,b) VALUES(1,0),(11,1),(12,1),(13,1),(121,12);
824 CREATE INDEX t1b ON t1(b);
825 CREATE TABLE t2(x INTEGER PRIMARY KEY);
826 INSERT INTO t2(x) VALUES(0),(1);
827 SELECT a1, a2, a3, a4, a5
828 FROM (SELECT a AS a1 FROM t1 WHERE b=0)
829 JOIN (SELECT x AS x1 FROM t2)
830 LEFT JOIN (SELECT a AS a2, b AS b2 FROM t1)
831 ON x1 IS TRUE AND b2=a1
832 JOIN (SELECT x AS x2 FROM t2)
833 ON x2<=CASE WHEN x1 THEN CASE WHEN a2 THEN 1 ELSE -1 END ELSE 0 END
834 LEFT JOIN (SELECT a AS a3, b AS b3 FROM t1)
835 ON x2 IS TRUE AND b3=a2
836 JOIN (SELECT x AS x3 FROM t2)
837 ON x3<=CASE WHEN x2 THEN CASE WHEN a3 THEN 1 ELSE -1 END ELSE 0 END
838 LEFT JOIN (SELECT a AS a4, b AS b4 FROM t1)
839 ON x3 IS TRUE AND b4=a3
840 JOIN (SELECT x AS x4 FROM t2)
841 ON x4<=CASE WHEN x3 THEN CASE WHEN a4 THEN 1 ELSE -1 END ELSE 0 END
842 LEFT JOIN (SELECT a AS a5, b AS b5 FROM t1)
843 ON x4 IS TRUE AND b5=a4
844 ORDER BY a1, a2, a3, a4, a5;
845 } {1 {} {} {} {} 1 11 {} {} {} 1 12 {} {} {} 1 12 121 {} {} 1 13 {} {} {}}