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. Specifically,
12 # it tests that ticket [38cb5df375078d3f9711482d2a1615d09f6b3f33] has
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
24 do_test tkt-38cb5df375.0 {
27 INSERT INTO t1 VALUES(1);
28 INSERT INTO t1 VALUES(2);
29 INSERT INTO t1 SELECT a+2 FROM t1;
30 INSERT INTO t1 SELECT a+4 FROM t1;
34 foreach ii {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16} {
35 do_test tkt-38cb5df375.1.$ii {
37 SELECT * FROM (SELECT * FROM t1 ORDER BY a)
38 UNION ALL SELECT 9 FROM (SELECT a FROM t1)
41 } [lrange {1 2 3 4 5 6 7 8 9 9 9 9 9 9 9 9} 0 [expr {$ii-1}]]
43 foreach ii {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16} {
44 do_test tkt-38cb5df375.2.$ii {
46 SELECT 9 FROM (SELECT * FROM t1)
47 UNION ALL SELECT a FROM (SELECT a FROM t1 ORDER BY a)
50 } [lrange {9 9 9 9 9 9 9 9 1 2 3 4 5 6 7 8} 0 [expr {$ii-1}]]
52 foreach ii {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16} {
53 do_test tkt-38cb5df375.3.$ii {
55 SELECT a FROM (SELECT * FROM t1 ORDER BY a)
56 UNION ALL SELECT a FROM (SELECT a FROM t1 ORDER BY a)
59 } [lrange {1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8} 0 [expr {$ii-1}]]
61 foreach ii {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16} {
62 do_test tkt-38cb5df375.4.$ii {
64 SELECT 0 FROM (SELECT * FROM t1)
65 UNION ALL SELECT 9 FROM (SELECT a FROM t1)
68 } [lrange {0 0 0 0 0 0 0 0 9 9 9 9 9 9 9 9} 0 [expr {$ii-1}]]
70 foreach ii {1 2 3 4} {
71 do_test tkt-38cb5df375.5.$ii {
73 SELECT 0 FROM (SELECT * FROM t1)
74 UNION SELECT 9 FROM (SELECT a FROM t1)
77 } [lrange {0 9} 0 [expr {$ii-1}]]
80 foreach ii {1 2 3 4 5 6 7 8 9 10 11} {
81 do_test tkt-38cb5df375.11.$ii {
83 SELECT * FROM (SELECT * FROM t1 ORDER BY a LIMIT 3)
84 UNION ALL SELECT 9 FROM (SELECT a FROM t1)
87 } [lrange {1 2 3 9 9 9 9 9 9 9 9} 0 [expr {$ii-1}]]
89 foreach ii {1 2 3 4 5 6 7 8 9 10 11} {
90 do_test tkt-38cb5df375.12.$ii {
92 SELECT 9 FROM (SELECT * FROM t1)
93 UNION ALL SELECT a FROM (SELECT a FROM t1 ORDER BY a LIMIT 3)
96 } [lrange {9 9 9 9 9 9 9 9 1 2 3} 0 [expr {$ii-1}]]
98 foreach ii {1 2 3 4 5 6} {
99 do_test tkt-38cb5df375.13.$ii {
101 SELECT a FROM (SELECT * FROM t1 ORDER BY a LIMIT 3)
102 UNION ALL SELECT a FROM (SELECT a FROM t1 ORDER BY a LIMIT 3)
105 } [lrange {1 2 3 1 2 3} 0 [expr {$ii-1}]]
107 foreach ii {1 2 3 4 5 6} {
108 do_test tkt-38cb5df375.14.$ii {
110 SELECT 0 FROM (SELECT * FROM t1 LIMIT 3)
111 UNION ALL SELECT 9 FROM (SELECT a FROM t1 LIMIT 3)
114 } [lrange {0 0 0 9 9 9} 0 [expr {$ii-1}]]
117 foreach ii {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16} {
118 do_test tkt-38cb5df375.21.$ii {
120 SELECT * FROM (SELECT * FROM t1 ORDER BY a)
121 UNION ALL SELECT 9 FROM (SELECT a FROM t1)
125 } [lrange {1 2 3 4 5 6 7 8 9 9 9 9 9 9 9 9} 0 [expr {$ii-1}]]
127 foreach ii {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16} {
128 do_test tkt-38cb5df375.22.$ii {
130 SELECT 9 FROM (SELECT * FROM t1)
131 UNION ALL SELECT a FROM (SELECT a FROM t1 ORDER BY a)
135 } [lrange {1 2 3 4 5 6 7 8 9 9 9 9 9 9 9 9} 0 [expr {$ii-1}]]
137 foreach ii {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16} {
138 do_test tkt-38cb5df375.23.$ii {
140 SELECT a FROM (SELECT * FROM t1 ORDER BY a)
141 UNION ALL SELECT a FROM (SELECT a FROM t1 ORDER BY a)
145 } [lrange {8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1} 0 [expr {$ii-1}]]
147 foreach ii {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16} {
148 do_test tkt-38cb5df375.24.$ii {
150 SELECT 0 FROM (SELECT * FROM t1)
151 UNION ALL SELECT 9 FROM (SELECT a FROM t1)
155 } [lrange {0 0 0 0 0 0 0 0 9 9 9 9 9 9 9 9} 0 [expr {$ii-1}]]
158 foreach ii {1 2 3 4 5 6 7 8 9 10 11} {
159 do_test tkt-38cb5df375.31.$ii {
161 SELECT * FROM (SELECT * FROM t1 ORDER BY a LIMIT 3)
162 UNION ALL SELECT 9 FROM (SELECT a FROM t1)
166 } [lrange {1 2 3 9 9 9 9 9 9 9 9} 0 [expr {$ii-1}]]
168 foreach ii {1 2 3 4 5 6 7 8 9 10 11} {
169 do_test tkt-38cb5df375.32.$ii {
171 SELECT 9 FROM (SELECT * FROM t1)
172 UNION ALL SELECT a FROM (SELECT a FROM t1 ORDER BY a LIMIT 3)
176 } [lrange {1 2 3 9 9 9 9 9 9 9 9} 0 [expr {$ii-1}]]
178 foreach ii {1 2 3 4 5 6 7} {
179 do_test tkt-38cb5df375.33.$ii {
181 SELECT a FROM (SELECT * FROM t1 ORDER BY a LIMIT 4)
182 UNION ALL SELECT 90+a FROM (SELECT a FROM t1 ORDER BY a LIMIT 3)
186 } [lrange {1 2 3 4 91 92 93} 0 [expr {$ii-1}]]
188 foreach ii {1 2 3 4 5 6 7} {
189 do_test tkt-38cb5df375.34.$ii {
191 SELECT a FROM (SELECT * FROM t1 ORDER BY a LIMIT 2)
192 UNION ALL SELECT a FROM (SELECT a FROM t1 ORDER BY a LIMIT 5)
196 } [lrange {1 1 2 2 3 4 5} 0 [expr {$ii-1}]]
198 foreach ii {1 2 3 4 5 6 7} {
199 do_test tkt-38cb5df375.35.$ii {
201 SELECT a FROM (SELECT * FROM t1 ORDER BY a LIMIT 5)
202 UNION ALL SELECT a FROM (SELECT a FROM t1 ORDER BY a LIMIT 2)
206 } [lrange {1 1 2 2 3 4 5} 0 [expr {$ii-1}]]
208 foreach ii {1 2 3 4 5 6 7} {
209 do_test tkt-38cb5df375.35b.$ii {
211 SELECT a FROM (SELECT * FROM t1 ORDER BY a LIMIT 5)
212 UNION ALL SELECT a+10 FROM (SELECT a FROM t1 ORDER BY a LIMIT 2)
216 } [lrange {1 2 3 4 5 11 12} 0 [expr {$ii-1}]]
218 foreach ii {1 2 3 4 5 6 7} {
219 do_test tkt-38cb5df375.35c.$ii {
221 SELECT a FROM (SELECT * FROM t1 ORDER BY a LIMIT 5)
222 UNION SELECT a+10 FROM (SELECT a FROM t1 ORDER BY a LIMIT 2)
226 } [lrange {1 2 3 4 5 11 12} 0 [expr {$ii-1}]]
228 foreach ii {1 2 3 4 5 6 7} {
229 do_test tkt-38cb5df375.35d.$ii {
231 SELECT a FROM (SELECT * FROM t1 ORDER BY a LIMIT 5)
232 INTERSECT SELECT a FROM (SELECT a FROM t1 ORDER BY a LIMIT 2)
236 } [lrange {1 2} 0 [expr {$ii-1}]]
238 foreach ii {1 2 3 4 5 6 7} {
239 do_test tkt-38cb5df375.35e.$ii {
241 SELECT a FROM (SELECT * FROM t1 ORDER BY a LIMIT 5)
242 EXCEPT SELECT a FROM (SELECT a FROM t1 ORDER BY a LIMIT 2)
246 } [lrange {3 4 5} 0 [expr {$ii-1}]]
248 foreach ii {1 2 3 4 5 6 7} {
249 do_test tkt-38cb5df375.36.$ii {
251 SELECT 0 FROM (SELECT * FROM t1 LIMIT 3)
252 UNION ALL SELECT 9 FROM (SELECT a FROM t1 LIMIT 4)
256 } [lrange {0 0 0 9 9 9 9} 0 [expr {$ii-1}]]
258 foreach ii {1 2 3 4 5 6 7} {
259 do_test tkt-38cb5df375.37.$ii {
261 SELECT 0 FROM (SELECT * FROM t1 LIMIT 3)
262 UNION SELECT 9 FROM (SELECT a FROM t1 LIMIT 4)
266 } [lrange {0 9} 0 [expr {$ii-1}]]
268 foreach ii {1 2 3 4 5 6 7} {
269 do_test tkt-38cb5df375.38.$ii {
271 SELECT 0 FROM (SELECT * FROM t1 LIMIT 3)
272 EXCEPT SELECT 9 FROM (SELECT a FROM t1 LIMIT 4)
276 } [lrange {0} 0 [expr {$ii-1}]]
279 foreach ii {1 2 3 4 5 6 7 8 9} {
280 do_test tkt-38cb5df375.41.$ii {
282 SELECT 0 FROM (SELECT * FROM t1 LIMIT 3)
283 UNION ALL SELECT 9 FROM (SELECT a FROM t1 LIMIT 4)
284 UNION ALL SELECT 88 FROM (SELECT a FROM t1 LIMIT 2)
288 } [lrange {0 0 0 9 9 9 9 88 88} 0 [expr {$ii-1}]]
290 foreach ii {1 2 3 4 5 6 7 8 9} {
291 do_test tkt-38cb5df375.42.$ii {
293 SELECT a FROM (SELECT * FROM t1 ORDER BY a LIMIT 3)
294 UNION ALL SELECT a+10 FROM (SELECT a FROM t1 ORDER BY a LIMIT 4)
295 UNION ALL SELECT a+20 FROM (SELECT a FROM t1 ORDER BY a LIMIT 2)
299 } [lrange {1 2 3 11 12 13 14 21 22} 0 [expr {$ii-1}]]
301 foreach ii {1 2 3 4 5 6 7 8 9} {
302 do_test tkt-38cb5df375.43.$ii {
304 SELECT a FROM (SELECT * FROM t1 ORDER BY a LIMIT 3)
305 UNION SELECT a+10 FROM (SELECT a FROM t1 ORDER BY a LIMIT 4)
306 UNION SELECT a+20 FROM (SELECT a FROM t1 ORDER BY a LIMIT 2)
310 } [lrange {1 2 3 11 12 13 14 21 22} 0 [expr {$ii-1}]]
313 foreach ii {1 2 3 4 5 6 7} {
314 set jj [expr {7-$ii}]
315 do_test tkt-38cb5df375.51.$ii {
317 SELECT a FROM (SELECT * FROM t1 ORDER BY a)
318 EXCEPT SELECT a FROM (SELECT a FROM t1 ORDER BY a LIMIT $::ii)
322 } [lrange {8 7 6 5 4 3 2 1} 0 [expr {$jj-1}]]