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. The
12 # focus of this script is DISTINCT queries using the skip-ahead
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
19 set testprefix distinct2
22 CREATE TABLE t1(x INTEGER PRIMARY KEY);
23 INSERT INTO t1 VALUES(0),(1),(2);
25 SELECT DISTINCT a.x AS aa, b.x AS bb
27 SELECT *, '|' FROM t2 ORDER BY aa, bb;
28 } {0 0 | 0 1 | 0 2 | 1 0 | 1 1 | 1 2 | 2 0 | 2 1 | 2 2 |}
32 SELECT DISTINCT a.x AS aa, b.x AS bb
34 WHERE a.x IN t1 AND b.x IN t1;
35 SELECT *, '|' FROM t2 ORDER BY aa, bb;
36 } {0 0 | 0 1 | 0 2 | 1 0 | 1 1 | 1 2 | 2 0 | 2 1 | 2 2 |}
38 CREATE TABLE t102 (i0 TEXT UNIQUE NOT NULL);
39 INSERT INTO t102 VALUES ('0'),('1'),('2');
44 JOIN t102 AS t4 ON (t2.i0 IN t102)
45 NATURAL JOIN t102 AS t3
46 JOIN t102 AS t1 ON (t0.i0 IN t102)
47 JOIN t102 AS t2 ON (t2.i0=+t0.i0 OR (t0.i0<>500 AND t2.i0=t1.i0));
48 SELECT *, '|' FROM t2 ORDER BY 1, 2, 3, 4, 5;
49 } {0 0 0 0 | 0 0 1 0 | 0 0 1 1 | 0 0 2 0 | 0 0 2 2 | 0 1 0 0 | 0 1 1 0 | 0 1 1 1 | 0 1 2 0 | 0 1 2 2 | 0 2 0 0 | 0 2 1 0 | 0 2 1 1 | 0 2 2 0 | 0 2 2 2 | 1 0 0 0 | 1 0 0 1 | 1 0 1 1 | 1 0 2 1 | 1 0 2 2 | 1 1 0 0 | 1 1 0 1 | 1 1 1 1 | 1 1 2 1 | 1 1 2 2 | 1 2 0 0 | 1 2 0 1 | 1 2 1 1 | 1 2 2 1 | 1 2 2 2 | 2 0 0 0 | 2 0 0 2 | 2 0 1 1 | 2 0 1 2 | 2 0 2 2 | 2 1 0 0 | 2 1 0 2 | 2 1 1 1 | 2 1 1 2 | 2 1 2 2 | 2 2 0 0 | 2 2 0 2 | 2 2 1 1 | 2 2 1 2 | 2 2 2 2 |}
52 CREATE TABLE t4(a,b,c,d,e,f,g,h,i,j);
53 INSERT INTO t4 VALUES(0,1,2,3,4,5,6,7,8,9);
54 INSERT INTO t4 SELECT * FROM t4;
55 INSERT INTO t4 SELECT * FROM t4;
56 CREATE INDEX t4x ON t4(c,d,e);
57 SELECT DISTINCT a,b,c FROM t4 WHERE a=0 AND b=1;
60 SELECT DISTINCT a,b,c,d FROM t4 WHERE a=0 AND b=1;
63 SELECT DISTINCT d,a,b,c FROM t4 WHERE a=0 AND b=1;
66 SELECT DISTINCT a,b,c,d,e FROM t4 WHERE a=0 AND b=1;
69 SELECT DISTINCT a,b,c,d,e,f FROM t4 WHERE a=0 AND b=1;
73 CREATE TABLE t5(a INT, b INT);
74 CREATE UNIQUE INDEX t5x ON t5(a+b);
75 INSERT INTO t5(a,b) VALUES(0,0),(1,0),(1,1),(0,3);
76 CREATE TEMP TABLE out AS SELECT DISTINCT a+b FROM t5;
77 SELECT * FROM out ORDER BY 1;
81 CREATE TABLE t6a(x INTEGER PRIMARY KEY);
82 INSERT INTO t6a VALUES(1);
83 CREATE TABLE t6b(y INTEGER PRIMARY KEY);
84 INSERT INTO t6b VALUES(2),(3);
85 SELECT DISTINCT x, x FROM t6a, t6b;
89 CREATE TABLE t7(a, b, c);
91 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE (i+1)<200
93 INSERT INTO t7 SELECT i/100, i/50, i FROM s;
96 SELECT DISTINCT a, b FROM t7;
101 do_execsql_test 720 {
102 SELECT DISTINCT a, b+1 FROM t7;
107 do_execsql_test 730 {
108 CREATE INDEX i7 ON t7(a, b+1);
110 SELECT DISTINCT a, b+1 FROM t7;
116 do_execsql_test 800 {
117 CREATE TABLE t8(a, b, c);
119 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE (i+1)<100
121 INSERT INTO t8 SELECT i/40, i/20, i/40 FROM s;
124 do_execsql_test 820 {
125 SELECT DISTINCT a, b, c FROM t8;
132 do_execsql_test 820 {
133 SELECT DISTINCT a, b, c FROM t8 WHERE b=3;
136 do_execsql_test 830 {
137 CREATE INDEX i8 ON t8(a, c);
139 SELECT DISTINCT a, b, c FROM t8 WHERE b=3;
142 do_execsql_test 900 {
144 INSERT INTO t9 VALUES
145 ('abcd'), ('Abcd'), ('aBcd'), ('ABcd'), ('abCd'), ('AbCd'), ('aBCd'),
146 ('ABCd'), ('abcD'), ('AbcD'), ('aBcD'), ('ABcD'), ('abCD'), ('AbCD'),
148 ('wxyz'), ('Wxyz'), ('wXyz'), ('WXyz'), ('wxYz'), ('WxYz'), ('wXYz'),
149 ('WXYz'), ('wxyZ'), ('WxyZ'), ('wXyZ'), ('WXyZ'), ('wxYZ'), ('WxYZ'),
153 do_execsql_test 910 {
154 SELECT DISTINCT v COLLATE NOCASE, v FROM t9 ORDER BY +v;
156 ABCD ABCD ABCd ABCd ABcD ABcD ABcd ABcd AbCD
157 AbCD AbCd AbCd AbcD AbcD Abcd Abcd
158 WXYZ WXYZ WXYz WXYz WXyZ WXyZ WXyz WXyz WxYZ
159 WxYZ WxYz WxYz WxyZ WxyZ Wxyz Wxyz
160 aBCD aBCD aBCd aBCd aBcD aBcD aBcd aBcd abCD
161 abCD abCd abCd abcD abcD abcd abcd
162 wXYZ wXYZ wXYz wXYz wXyZ wXyZ wXyz wXyz wxYZ
163 wxYZ wxYz wxYz wxyZ wxyZ wxyz wxyz
166 do_execsql_test 920 {
167 CREATE INDEX i9 ON t9(v COLLATE NOCASE, v);
170 SELECT DISTINCT v COLLATE NOCASE, v FROM t9 ORDER BY +v;
172 ABCD ABCD ABCd ABCd ABcD ABcD ABcd ABcd AbCD
173 AbCD AbCd AbCd AbcD AbcD Abcd Abcd
174 WXYZ WXYZ WXYz WXYz WXyZ WXyZ WXyz WXyz WxYZ
175 WxYZ WxYz WxYz WxyZ WxyZ Wxyz Wxyz
176 aBCD aBCD aBCd aBCd aBcD aBcD aBcd aBcd abCD
177 abCD abCd abCd abcD abcD abcd abcd
178 wXYZ wXYZ wXYz wXYz wXyZ wXyZ wXyz wXyz wxYZ
179 wxYZ wxYz wxYz wxyZ wxyZ wxyz wxyz