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 name resolution in SELECT
12 # statements that have parenthesized FROM clauses.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
19 for {set i 1} {$i<=2} {incr i} {
24 optimization_control db query-flattener off
26 do_test selectD-$i.0 {
28 ATTACH ':memory:' AS aux1;
29 CREATE TABLE t1(a,b); INSERT INTO t1 VALUES(111,'x1');
30 CREATE TABLE t2(a,b); INSERT INTO t2 VALUES(222,'x2');
31 CREATE TEMP TABLE t3(a,b); INSERT INTO t3 VALUES(333,'x3');
32 CREATE TABLE main.t4(a,b); INSERT INTO main.t4 VALUES(444,'x4');
33 CREATE TABLE aux1.t4(a,b); INSERT INTO aux1.t4 VALUES(555,'x5');
36 do_test selectD-$i.1 {
39 FROM (t1), (t2), (t3), (t4)
44 } {111 x1 222 x2 333 x3 444 x4}
45 do_test selectD-$i.2.1 {
48 FROM t1 JOIN (t2 JOIN (t3 JOIN t4 ON t4.a=t3.a+111)
52 } {111 x1 222 x2 333 x3 444 x4}
53 do_test selectD-$i.2.2 {
56 FROM t1 JOIN (t2 JOIN (t3 JOIN t4 ON t4.a=t3.a+111)
61 do_test selectD-$i.2.3 {
64 FROM t1 JOIN (t2 JOIN (t3 JOIN t4 ON t4.a=t3.a+111)
69 do_test selectD-$i.2.3 {
72 FROM t1 JOIN (t2 JOIN (t3 JOIN t4 ON t4.a=t3.a+111)
77 do_test selectD-$i.2.4 {
80 FROM t1 JOIN (t2 JOIN (main.t4 JOIN aux1.t4 ON aux1.t4.a=main.t4.a+111)
81 ON main.t4.a=t2.a+222)
84 } {111 x1 222 x2 444 x4 555 x5}
85 do_test selectD-$i.2.5 {
88 FROM t1 JOIN (t2 JOIN (main.t4 AS x JOIN aux1.t4 ON aux1.t4.a=x.a+111)
92 } {111 x1 222 x2 444 x4 555 x5}
93 do_test selectD-$i.2.6 {
96 FROM t1 JOIN (t2 JOIN (main.t4 JOIN aux.t4 ON aux.t4.a=main.t4.a+111)
97 ON main.t4.a=t2.a+222)
100 } {1 {no such table: aux.t4}}
101 do_test selectD-$i.2.7 {
104 FROM t1 JOIN (t2 JOIN (main.t4 x JOIN aux1.t4 y ON y.a=x.a+111)
109 do_test selectD-$i.3 {
115 FROM t1 JOIN (t2 JOIN (t3 JOIN t4 USING(a)) USING (a)) USING (a);
118 do_test selectD-$i.4 {
124 FROM t1 LEFT JOIN (t2 LEFT JOIN (t3 LEFT JOIN t4 USING(a))
129 do_test selectD-$i.5 {
134 FROM (t1 LEFT JOIN t2 USING(a)) JOIN (t3 LEFT JOIN t4 USING(a))
137 } {111 x1 x2 222 x3 x4}
138 do_test selectD-$i.6 {
142 FROM (t1 LEFT JOIN t2 USING(a)) JOIN (t3 LEFT JOIN t4 USING(a))
145 } {111 x1 x2 222 x3 {}}
146 do_test selectD-$i.7 {
148 SELECT t1.*, t2.*, t3.*, t4.b
149 FROM (t1 LEFT JOIN t2 USING(a)) JOIN (t3 LEFT JOIN t4 USING(a))
152 } {111 x1 111 x2 222 x3 {}}
155 # The following test was added on 2013-04-24 in order to verify that
156 # the datatypes and affinities of sub-sub-queries are set prior to computing
157 # the datatypes and affinities of the parent sub-queries because the
158 # latter computation depends on the former.
160 do_execsql_test selectD-4.1 {
161 CREATE TABLE t41(a INTEGER PRIMARY KEY, b INTEGER);
162 CREATE TABLE t42(d INTEGER PRIMARY KEY, e INTEGER);
163 CREATE TABLE t43(f INTEGER PRIMARY KEY, g INTEGER);
167 LEFT JOIN (SELECT count(*) AS cnt, x1.d
168 FROM (t42 INNER JOIN t43 ON d=g) AS x1
172 } {/.*SEARCH SUBQUERY 1 AS x2 USING AUTOMATIC.*/}