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 # The focus of this file is testing the compound-SELECT merge
14 # optimization. Or, in other words, making sure that all
15 # possible combinations of UNION, UNION ALL, EXCEPT, and
16 # INTERSECT work together with an ORDER BY clause (with or w/o
17 # explicit sort order and explicit collating secquites) and
18 # with and without optional LIMIT and OFFSET clauses.
20 # $Id: selectA.test,v 1.6 2008/08/21 14:24:29 drh Exp $
22 set testdir [file dirname $argv0]
23 source $testdir/tester.tcl
24 set testprefix selectA
33 CREATE TABLE t1(a,b,c COLLATE NOCASE);
34 INSERT INTO t1 VALUES(1,'a','a');
35 INSERT INTO t1 VALUES(9.9, 'b', 'B');
36 INSERT INTO t1 VALUES(NULL, 'C', 'c');
37 INSERT INTO t1 VALUES('hello', 'd', 'D');
38 INSERT INTO t1 VALUES(x'616263', 'e', 'e');
41 } {1 a a 9.9 b B {} C c hello d D abc e e}
44 CREATE TABLE t2(x,y,z COLLATE NOCASE);
45 INSERT INTO t2 VALUES(NULL,'U','u');
46 INSERT INTO t2 VALUES('mad', 'Z', 'z');
47 INSERT INTO t2 VALUES(x'68617265', 'm', 'M');
48 INSERT INTO t2 VALUES(5.2e6, 'X', 'x');
49 INSERT INTO t2 VALUES(-23, 'Y', 'y');
52 } {{} U u mad Z z hare m M 5200000.0 X x -23 Y y}
55 CREATE TABLE t3(a,b,c COLLATE NOCASE);
56 INSERT INTO t3 SELECT * FROM t1;
57 INSERT INTO t3 SELECT * FROM t2;
58 INSERT INTO t3 SELECT * FROM t1;
59 INSERT INTO t3 SELECT * FROM t2;
60 INSERT INTO t3 SELECT * FROM t1;
61 INSERT INTO t3 SELECT * FROM t2;
62 SELECT count(*) FROM t3;
68 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
71 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
72 do_test selectA-2.1.1 { # Ticket #3314
74 SELECT t1.a, t1.b, t1.c FROM t1 UNION ALL SELECT x,y,z FROM t2
77 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
78 do_test selectA-2.1.2 { # Ticket #3314
80 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
81 ORDER BY t1.a, t1.b, t1.c
83 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
86 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
89 } {hare m M abc e e mad Z z hello d D 5200000.0 X x 9.9 b B 1 a a -23 Y y {} C c {} U u}
92 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
95 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
98 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
101 } {{} C c {} U u 5200000.0 X x -23 Y y mad Z z 1 a a 9.9 b B hello d D abc e e hare m M}
102 do_test selectA-2.5 {
104 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
105 ORDER BY b COLLATE NOCASE,a,c
107 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
108 do_test selectA-2.6 {
110 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
111 ORDER BY b COLLATE NOCASE DESC,a,c
113 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
114 do_test selectA-2.7 {
116 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
119 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
120 do_test selectA-2.8 {
122 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
125 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
126 do_test selectA-2.9 {
128 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
131 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
132 do_test selectA-2.10 {
134 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
135 ORDER BY c COLLATE BINARY DESC,a,b
137 } {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
138 do_test selectA-2.11 {
140 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
143 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
144 do_test selectA-2.12 {
146 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
149 } {hare m M abc e e mad Z z hello d D 5200000.0 X x 9.9 b B 1 a a -23 Y y {} C c {} U u}
150 do_test selectA-2.13 {
152 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
155 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
156 do_test selectA-2.14 {
158 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
161 } {{} C c {} U u 5200000.0 X x -23 Y y mad Z z 1 a a 9.9 b B hello d D abc e e hare m M}
162 do_test selectA-2.15 {
164 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
165 ORDER BY b COLLATE NOCASE,a,c
167 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
168 do_test selectA-2.16 {
170 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
171 ORDER BY b COLLATE NOCASE DESC,a,c
173 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
174 do_test selectA-2.17 {
176 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
179 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
180 do_test selectA-2.18 {
182 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
185 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
186 do_test selectA-2.19 {
188 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
191 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
192 do_test selectA-2.20 {
194 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
195 ORDER BY c COLLATE BINARY DESC,a,b
197 } {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
198 do_test selectA-2.21 {
200 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
203 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
204 do_test selectA-2.22 {
206 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
209 } {hare m M abc e e mad Z z hello d D 5200000.0 X x 9.9 b B 1 a a -23 Y y {} C c {} U u}
210 do_test selectA-2.23 {
212 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
215 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
216 do_test selectA-2.24 {
218 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
221 } {{} C c {} U u 5200000.0 X x -23 Y y mad Z z 1 a a 9.9 b B hello d D abc e e hare m M}
222 do_test selectA-2.25 {
224 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
225 ORDER BY b COLLATE NOCASE,a,c
227 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
228 do_test selectA-2.26 {
230 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
231 ORDER BY b COLLATE NOCASE DESC,a,c
233 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
234 do_test selectA-2.27 {
236 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
239 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
240 do_test selectA-2.28 {
242 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
245 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
246 do_test selectA-2.29 {
248 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
251 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
252 do_test selectA-2.30 {
254 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
255 ORDER BY c COLLATE BINARY DESC,a,b
257 } {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
258 do_test selectA-2.31 {
260 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
263 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
264 do_test selectA-2.32 {
266 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
269 } {hare m M abc e e mad Z z hello d D 5200000.0 X x 9.9 b B 1 a a -23 Y y {} C c {} U u}
270 do_test selectA-2.33 {
272 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
275 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
276 do_test selectA-2.34 {
278 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
281 } {{} C c {} U u 5200000.0 X x -23 Y y mad Z z 1 a a 9.9 b B hello d D abc e e hare m M}
282 do_test selectA-2.35 {
284 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
285 ORDER BY y COLLATE NOCASE,x,z
287 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
288 do_test selectA-2.36 {
290 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
291 ORDER BY y COLLATE NOCASE DESC,x,z
293 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
294 do_test selectA-2.37 {
296 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
299 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
300 do_test selectA-2.38 {
302 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
305 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
306 do_test selectA-2.39 {
308 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
311 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
312 do_test selectA-2.40 {
314 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
315 ORDER BY z COLLATE BINARY DESC,x,y
317 } {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
318 do_test selectA-2.41 {
320 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b>='d'
323 } {{} C c 1 a a 9.9 b B}
324 do_test selectA-2.42 {
326 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b>='d'
329 } {hello d D abc e e}
330 do_test selectA-2.43 {
332 SELECT a,b,c FROM t1 WHERE b>='d' INTERSECT SELECT a,b,c FROM t1
335 } {hello d D abc e e}
336 do_test selectA-2.44 {
338 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b<'d'
341 } {hello d D abc e e}
342 do_test selectA-2.45 {
344 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b<'d'
347 } {{} C c 1 a a 9.9 b B}
348 do_test selectA-2.46 {
350 SELECT a,b,c FROM t1 WHERE b<'d' INTERSECT SELECT a,b,c FROM t1
353 } {{} C c 1 a a 9.9 b B}
354 do_test selectA-2.47 {
356 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b>='d'
359 } {9.9 b B 1 a a {} C c}
360 do_test selectA-2.48 {
362 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b>='d'
365 } {abc e e hello d D}
366 do_test selectA-2.49 {
368 SELECT a,b,c FROM t1 WHERE b>='d' INTERSECT SELECT a,b,c FROM t1
371 } {abc e e hello d D}
372 do_test selectA-2.50 {
374 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b<'d'
377 } {abc e e hello d D}
378 do_test selectA-2.51 {
380 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b<'d'
383 } {9.9 b B 1 a a {} C c}
384 do_test selectA-2.52 {
386 SELECT a,b,c FROM t1 WHERE b<'d' INTERSECT SELECT a,b,c FROM t1
389 } {9.9 b B 1 a a {} C c}
390 do_test selectA-2.53 {
392 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b>='d'
395 } {{} C c 1 a a 9.9 b B}
396 do_test selectA-2.54 {
398 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b>='d'
401 } {hello d D abc e e}
402 do_test selectA-2.55 {
404 SELECT a,b,c FROM t1 WHERE b>='d' INTERSECT SELECT a,b,c FROM t1
407 } {abc e e hello d D}
408 do_test selectA-2.56 {
410 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b<'d'
411 ORDER BY b, c DESC, a
413 } {hello d D abc e e}
414 do_test selectA-2.57 {
416 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b<'d'
417 ORDER BY b COLLATE NOCASE
419 } {1 a a 9.9 b B {} C c}
420 do_test selectA-2.58 {
422 SELECT a,b,c FROM t1 WHERE b<'d' INTERSECT SELECT a,b,c FROM t1
425 } {{} C c 1 a a 9.9 b B}
426 do_test selectA-2.59 {
428 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b>='d'
431 } {1 a a 9.9 b B {} C c}
432 do_test selectA-2.60 {
434 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b>='d'
437 } {hello d D abc e e}
438 do_test selectA-2.61 {
440 SELECT a,b,c FROM t1 WHERE b>='d' INTERSECT SELECT a,b,c FROM t1
441 ORDER BY c COLLATE BINARY, b DESC, c, a, b, c, a, b, c
443 } {hello d D abc e e}
444 do_test selectA-2.62 {
446 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b<'d'
449 } {abc e e hello d D}
450 do_test selectA-2.63 {
452 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b<'d'
453 ORDER BY c COLLATE NOCASE
455 } {1 a a 9.9 b B {} C c}
456 do_test selectA-2.64 {
458 SELECT a,b,c FROM t1 WHERE b<'d' INTERSECT SELECT a,b,c FROM t1
461 } {1 a a 9.9 b B {} C c}
462 do_test selectA-2.65 {
464 SELECT a,b,c FROM t3 INTERSECT SELECT a,b,c FROM t1 WHERE b<'d'
465 ORDER BY c COLLATE NOCASE
467 } {1 a a 9.9 b B {} C c}
468 do_test selectA-2.66 {
470 SELECT a,b,c FROM t1 WHERE b<'d' INTERSECT SELECT a,b,c FROM t3
473 } {1 a a 9.9 b B {} C c}
474 do_test selectA-2.67 {
476 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t3 WHERE b<'d'
479 } {abc e e hello d D}
480 do_test selectA-2.68 {
482 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b<'d'
483 INTERSECT SELECT a,b,c FROM t3
484 EXCEPT SELECT b,c,a FROM t3
487 } {abc e e hello d D}
488 do_test selectA-2.69 {
490 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b<'d'
491 INTERSECT SELECT a,b,c FROM t3
492 EXCEPT SELECT b,c,a FROM t3
493 ORDER BY c COLLATE NOCASE
495 } {1 a a 9.9 b B {} C c}
496 do_test selectA-2.70 {
498 SELECT a,b,c FROM t1 WHERE b<'d' INTERSECT SELECT a,b,c FROM t1
499 INTERSECT SELECT a,b,c FROM t3
500 EXCEPT SELECT b,c,a FROM t3
503 } {1 a a 9.9 b B {} C c}
504 do_test selectA-2.71 {
506 SELECT a,b,c FROM t1 WHERE b<'d'
507 INTERSECT SELECT a,b,c FROM t1
508 INTERSECT SELECT a,b,c FROM t3
509 EXCEPT SELECT b,c,a FROM t3
510 INTERSECT SELECT a,b,c FROM t1
511 EXCEPT SELECT x,y,z FROM t2
512 INTERSECT SELECT a,b,c FROM t3
513 EXCEPT SELECT y,x,z FROM t2
514 INTERSECT SELECT a,b,c FROM t1
515 EXCEPT SELECT c,b,a FROM t3
518 } {1 a a 9.9 b B {} C c}
519 do_test selectA-2.72 {
521 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
524 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
525 do_test selectA-2.73 {
527 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
530 } {hare m M abc e e mad Z z hello d D 5200000.0 X x 9.9 b B 1 a a -23 Y y {} C c {} U u}
531 do_test selectA-2.74 {
533 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
536 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
537 do_test selectA-2.75 {
539 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
542 } {{} C c {} U u 5200000.0 X x -23 Y y mad Z z 1 a a 9.9 b B hello d D abc e e hare m M}
543 do_test selectA-2.76 {
545 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
546 ORDER BY b COLLATE NOCASE,a,c
548 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
549 do_test selectA-2.77 {
551 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
552 ORDER BY b COLLATE NOCASE DESC,a,c
554 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
555 do_test selectA-2.78 {
557 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
560 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
561 do_test selectA-2.79 {
563 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
566 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
567 do_test selectA-2.80 {
569 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
572 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
573 do_test selectA-2.81 {
575 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
576 ORDER BY c COLLATE BINARY DESC,a,b
578 } {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
579 do_test selectA-2.82 {
581 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
584 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
585 do_test selectA-2.83 {
587 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
590 } {hare m M abc e e mad Z z hello d D 5200000.0 X x 9.9 b B 1 a a -23 Y y {} C c {} U u}
591 do_test selectA-2.84 {
593 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
596 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
597 do_test selectA-2.85 {
599 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
602 } {{} C c {} U u 5200000.0 X x -23 Y y mad Z z 1 a a 9.9 b B hello d D abc e e hare m M}
603 do_test selectA-2.86 {
605 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
606 ORDER BY y COLLATE NOCASE,x,z
608 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
609 do_test selectA-2.87 {
611 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
612 ORDER BY y COLLATE NOCASE DESC,x,z
614 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
615 do_test selectA-2.88 {
617 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
620 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
621 do_test selectA-2.89 {
623 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
626 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
627 do_test selectA-2.90 {
629 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
632 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
633 do_test selectA-2.91 {
635 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
636 ORDER BY z COLLATE BINARY DESC,x,y
638 } {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
639 do_test selectA-2.92 {
642 INTERSECT SELECT a,b,c FROM t3
643 EXCEPT SELECT c,b,a FROM t1
644 UNION SELECT a,b,c FROM t3
645 INTERSECT SELECT a,b,c FROM t3
646 EXCEPT SELECT c,b,a FROM t1
647 UNION SELECT a,b,c FROM t3
648 ORDER BY y COLLATE NOCASE DESC,x,z
650 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
651 do_test selectA-2.93 {
653 SELECT upper((SELECT c FROM t1 UNION SELECT z FROM t2 ORDER BY 1));
656 do_test selectA-2.94 {
658 SELECT lower((SELECT c FROM t1 UNION ALL SELECT z FROM t2 ORDER BY 1));
661 do_test selectA-2.95 {
663 SELECT lower((SELECT c FROM t1 INTERSECT SELECT z FROM t2 ORDER BY 1));
666 do_test selectA-2.96 {
668 SELECT lower((SELECT z FROM t2 EXCEPT SELECT c FROM t1 ORDER BY 1));
673 do_test selectA-3.0 {
675 CREATE UNIQUE INDEX t1a ON t1(a);
676 CREATE UNIQUE INDEX t1b ON t1(b);
677 CREATE UNIQUE INDEX t1c ON t1(c);
678 CREATE UNIQUE INDEX t2x ON t2(x);
679 CREATE UNIQUE INDEX t2y ON t2(y);
680 CREATE UNIQUE INDEX t2z ON t2(z);
681 SELECT name FROM sqlite_master WHERE type='index'
683 } {t1a t1b t1c t2x t2y t2z}
684 do_test selectA-3.1 {
686 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
689 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
690 do_test selectA-3.1.1 { # Ticket #3314
692 SELECT t1.a,b,t1.c FROM t1 UNION ALL SELECT x,y,z FROM t2
695 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
696 do_test selectA-3.2 {
698 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
701 } {hare m M abc e e mad Z z hello d D 5200000.0 X x 9.9 b B 1 a a -23 Y y {} C c {} U u}
702 do_test selectA-3.3 {
704 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
707 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
708 do_test selectA-3.4 {
710 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
713 } {{} C c {} U u 5200000.0 X x -23 Y y mad Z z 1 a a 9.9 b B hello d D abc e e hare m M}
714 do_test selectA-3.5 {
716 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
717 ORDER BY b COLLATE NOCASE,a,c
719 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
720 do_test selectA-3.6 {
722 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
723 ORDER BY b COLLATE NOCASE DESC,a,c
725 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
726 do_test selectA-3.7 {
728 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
731 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
732 do_test selectA-3.8 {
734 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
737 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
738 do_test selectA-3.9 {
740 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
743 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
744 do_test selectA-3.10 {
746 SELECT a,b,c FROM t1 UNION ALL SELECT x,y,z FROM t2
747 ORDER BY c COLLATE BINARY DESC,a,b
749 } {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
750 do_test selectA-3.11 {
752 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
755 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
756 do_test selectA-3.12 {
758 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
761 } {hare m M abc e e mad Z z hello d D 5200000.0 X x 9.9 b B 1 a a -23 Y y {} C c {} U u}
762 do_test selectA-3.13 {
764 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
767 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
768 do_test selectA-3.14 {
770 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
773 } {{} C c {} U u 5200000.0 X x -23 Y y mad Z z 1 a a 9.9 b B hello d D abc e e hare m M}
774 do_test selectA-3.15 {
776 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
777 ORDER BY b COLLATE NOCASE,a,c
779 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
780 do_test selectA-3.16 {
782 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
783 ORDER BY b COLLATE NOCASE DESC,a,c
785 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
786 do_test selectA-3.17 {
788 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
791 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
792 do_test selectA-3.18 {
794 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
797 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
798 do_test selectA-3.19 {
800 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
803 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
804 do_test selectA-3.20 {
806 SELECT x,y,z FROM t2 UNION ALL SELECT a,b,c FROM t1
807 ORDER BY c COLLATE BINARY DESC,a,b
809 } {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
810 do_test selectA-3.21 {
812 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
815 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
816 do_test selectA-3.22 {
818 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
821 } {hare m M abc e e mad Z z hello d D 5200000.0 X x 9.9 b B 1 a a -23 Y y {} C c {} U u}
822 do_test selectA-3.23 {
824 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
827 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
828 do_test selectA-3.24 {
830 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
833 } {{} C c {} U u 5200000.0 X x -23 Y y mad Z z 1 a a 9.9 b B hello d D abc e e hare m M}
834 do_test selectA-3.25 {
836 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
837 ORDER BY b COLLATE NOCASE,a,c
839 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
840 do_test selectA-3.26 {
842 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
843 ORDER BY b COLLATE NOCASE DESC,a,c
845 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
846 do_test selectA-3.27 {
848 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
851 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
852 do_test selectA-3.28 {
854 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
857 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
858 do_test selectA-3.29 {
860 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
863 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
864 do_test selectA-3.30 {
866 SELECT a,b,c FROM t1 UNION SELECT x,y,z FROM t2
867 ORDER BY c COLLATE BINARY DESC,a,b
869 } {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
870 do_test selectA-3.31 {
872 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
875 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
876 do_test selectA-3.32 {
878 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
881 } {hare m M abc e e mad Z z hello d D 5200000.0 X x 9.9 b B 1 a a -23 Y y {} C c {} U u}
882 do_test selectA-3.33 {
884 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
887 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
888 do_test selectA-3.34 {
890 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
893 } {{} C c {} U u 5200000.0 X x -23 Y y mad Z z 1 a a 9.9 b B hello d D abc e e hare m M}
894 do_test selectA-3.35 {
896 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
897 ORDER BY y COLLATE NOCASE,x,z
899 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
900 do_test selectA-3.36 {
902 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
903 ORDER BY y COLLATE NOCASE DESC,x,z
905 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
906 do_test selectA-3.37 {
908 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
911 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
912 do_test selectA-3.38 {
914 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
917 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
918 do_test selectA-3.39 {
920 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
923 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
924 do_test selectA-3.40 {
926 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
927 ORDER BY z COLLATE BINARY DESC,x,y
929 } {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
930 do_test selectA-3.41 {
932 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b>='d'
935 } {{} C c 1 a a 9.9 b B}
936 do_test selectA-3.42 {
938 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b>='d'
941 } {hello d D abc e e}
942 do_test selectA-3.43 {
944 SELECT a,b,c FROM t1 WHERE b>='d' INTERSECT SELECT a,b,c FROM t1
947 } {hello d D abc e e}
948 do_test selectA-3.44 {
950 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b<'d'
953 } {hello d D abc e e}
954 do_test selectA-3.45 {
956 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b<'d'
959 } {{} C c 1 a a 9.9 b B}
960 do_test selectA-3.46 {
962 SELECT a,b,c FROM t1 WHERE b<'d' INTERSECT SELECT a,b,c FROM t1
965 } {{} C c 1 a a 9.9 b B}
966 do_test selectA-3.47 {
968 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b>='d'
971 } {9.9 b B 1 a a {} C c}
972 do_test selectA-3.48 {
974 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b>='d'
977 } {abc e e hello d D}
978 do_test selectA-3.49 {
980 SELECT a,b,c FROM t1 WHERE b>='d' INTERSECT SELECT a,b,c FROM t1
983 } {abc e e hello d D}
984 do_test selectA-3.50 {
986 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b<'d'
989 } {abc e e hello d D}
990 do_test selectA-3.51 {
992 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b<'d'
995 } {9.9 b B 1 a a {} C c}
996 do_test selectA-3.52 {
998 SELECT a,b,c FROM t1 WHERE b<'d' INTERSECT SELECT a,b,c FROM t1
1001 } {9.9 b B 1 a a {} C c}
1002 do_test selectA-3.53 {
1004 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b>='d'
1007 } {{} C c 1 a a 9.9 b B}
1008 do_test selectA-3.54 {
1010 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b>='d'
1013 } {hello d D abc e e}
1014 do_test selectA-3.55 {
1016 SELECT a,b,c FROM t1 WHERE b>='d' INTERSECT SELECT a,b,c FROM t1
1019 } {abc e e hello d D}
1020 do_test selectA-3.56 {
1022 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b<'d'
1023 ORDER BY b, c DESC, a
1025 } {hello d D abc e e}
1026 do_test selectA-3.57 {
1028 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b<'d'
1029 ORDER BY b COLLATE NOCASE
1031 } {1 a a 9.9 b B {} C c}
1032 do_test selectA-3.58 {
1034 SELECT a,b,c FROM t1 WHERE b<'d' INTERSECT SELECT a,b,c FROM t1
1037 } {{} C c 1 a a 9.9 b B}
1038 do_test selectA-3.59 {
1040 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b>='d'
1043 } {1 a a 9.9 b B {} C c}
1044 do_test selectA-3.60 {
1046 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b>='d'
1049 } {hello d D abc e e}
1050 do_test selectA-3.61 {
1052 SELECT a,b,c FROM t1 WHERE b>='d' INTERSECT SELECT a,b,c FROM t1
1053 ORDER BY c COLLATE BINARY, b DESC, c, a, b, c, a, b, c
1055 } {hello d D abc e e}
1056 do_test selectA-3.62 {
1058 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b<'d'
1061 } {abc e e hello d D}
1062 do_test selectA-3.63 {
1064 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b<'d'
1065 ORDER BY c COLLATE NOCASE
1067 } {1 a a 9.9 b B {} C c}
1068 do_test selectA-3.64 {
1070 SELECT a,b,c FROM t1 WHERE b<'d' INTERSECT SELECT a,b,c FROM t1
1073 } {1 a a 9.9 b B {} C c}
1074 do_test selectA-3.65 {
1076 SELECT a,b,c FROM t3 INTERSECT SELECT a,b,c FROM t1 WHERE b<'d'
1077 ORDER BY c COLLATE NOCASE
1079 } {1 a a 9.9 b B {} C c}
1080 do_test selectA-3.66 {
1082 SELECT a,b,c FROM t1 WHERE b<'d' INTERSECT SELECT a,b,c FROM t3
1085 } {1 a a 9.9 b B {} C c}
1086 do_test selectA-3.67 {
1088 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t3 WHERE b<'d'
1091 } {abc e e hello d D}
1092 do_test selectA-3.68 {
1094 SELECT a,b,c FROM t1 EXCEPT SELECT a,b,c FROM t1 WHERE b<'d'
1095 INTERSECT SELECT a,b,c FROM t3
1096 EXCEPT SELECT b,c,a FROM t3
1099 } {abc e e hello d D}
1100 do_test selectA-3.69 {
1102 SELECT a,b,c FROM t1 INTERSECT SELECT a,b,c FROM t1 WHERE b<'d'
1103 INTERSECT SELECT a,b,c FROM t3
1104 EXCEPT SELECT b,c,a FROM t3
1105 ORDER BY c COLLATE NOCASE
1107 } {1 a a 9.9 b B {} C c}
1108 do_test selectA-3.70 {
1110 SELECT a,b,c FROM t1 WHERE b<'d' INTERSECT SELECT a,b,c FROM t1
1111 INTERSECT SELECT a,b,c FROM t3
1112 EXCEPT SELECT b,c,a FROM t3
1115 } {1 a a 9.9 b B {} C c}
1116 do_test selectA-3.71 {
1118 SELECT a,b,c FROM t1 WHERE b<'d'
1119 INTERSECT SELECT a,b,c FROM t1
1120 INTERSECT SELECT a,b,c FROM t3
1121 EXCEPT SELECT b,c,a FROM t3
1122 INTERSECT SELECT a,b,c FROM t1
1123 EXCEPT SELECT x,y,z FROM t2
1124 INTERSECT SELECT a,b,c FROM t3
1125 EXCEPT SELECT y,x,z FROM t2
1126 INTERSECT SELECT a,b,c FROM t1
1127 EXCEPT SELECT c,b,a FROM t3
1130 } {1 a a 9.9 b B {} C c}
1131 do_test selectA-3.72 {
1133 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
1136 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
1137 do_test selectA-3.73 {
1139 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
1142 } {hare m M abc e e mad Z z hello d D 5200000.0 X x 9.9 b B 1 a a -23 Y y {} C c {} U u}
1143 do_test selectA-3.74 {
1145 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
1148 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
1149 do_test selectA-3.75 {
1151 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
1154 } {{} C c {} U u 5200000.0 X x -23 Y y mad Z z 1 a a 9.9 b B hello d D abc e e hare m M}
1155 do_test selectA-3.76 {
1157 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
1158 ORDER BY b COLLATE NOCASE,a,c
1160 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
1161 do_test selectA-3.77 {
1163 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
1164 ORDER BY b COLLATE NOCASE DESC,a,c
1166 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
1167 do_test selectA-3.78 {
1169 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
1172 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
1173 do_test selectA-3.79 {
1175 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
1178 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
1179 do_test selectA-3.80 {
1181 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
1184 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
1185 do_test selectA-3.81 {
1187 SELECT a,b,c FROM t3 UNION SELECT x,y,z FROM t2
1188 ORDER BY c COLLATE BINARY DESC,a,b
1190 } {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
1191 do_test selectA-3.82 {
1193 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
1196 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
1197 do_test selectA-3.83 {
1199 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
1202 } {hare m M abc e e mad Z z hello d D 5200000.0 X x 9.9 b B 1 a a -23 Y y {} C c {} U u}
1203 do_test selectA-3.84 {
1205 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
1208 } {{} C c {} U u -23 Y y 1 a a 9.9 b B 5200000.0 X x hello d D mad Z z abc e e hare m M}
1209 do_test selectA-3.85 {
1211 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
1214 } {{} C c {} U u 5200000.0 X x -23 Y y mad Z z 1 a a 9.9 b B hello d D abc e e hare m M}
1215 do_test selectA-3.86 {
1217 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
1218 ORDER BY y COLLATE NOCASE,x,z
1220 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
1221 do_test selectA-3.87 {
1223 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
1224 ORDER BY y COLLATE NOCASE DESC,x,z
1226 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
1227 do_test selectA-3.88 {
1229 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
1232 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
1233 do_test selectA-3.89 {
1235 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
1238 } {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
1239 do_test selectA-3.90 {
1241 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
1244 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
1245 do_test selectA-3.91 {
1247 SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
1248 ORDER BY z COLLATE BINARY DESC,x,y
1250 } {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
1251 do_test selectA-3.92 {
1253 SELECT x,y,z FROM t2
1254 INTERSECT SELECT a,b,c FROM t3
1255 EXCEPT SELECT c,b,a FROM t1
1256 UNION SELECT a,b,c FROM t3
1257 INTERSECT SELECT a,b,c FROM t3
1258 EXCEPT SELECT c,b,a FROM t1
1259 UNION SELECT a,b,c FROM t3
1260 ORDER BY y COLLATE NOCASE DESC,x,z
1262 } {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
1263 do_test selectA-3.93 {
1265 SELECT upper((SELECT c FROM t1 UNION SELECT z FROM t2 ORDER BY 1));
1268 do_test selectA-3.94 {
1270 SELECT lower((SELECT c FROM t1 UNION ALL SELECT z FROM t2 ORDER BY 1));
1273 do_test selectA-3.95 {
1275 SELECT lower((SELECT c FROM t1 INTERSECT SELECT z FROM t2 ORDER BY 1));
1278 do_test selectA-3.96 {
1280 SELECT lower((SELECT z FROM t2 EXCEPT SELECT c FROM t1 ORDER BY 1));
1283 do_test selectA-3.97 {
1285 SELECT upper((SELECT x FROM (
1286 SELECT x,y,z FROM t2
1287 INTERSECT SELECT a,b,c FROM t3
1288 EXCEPT SELECT c,b,a FROM t1
1289 UNION SELECT a,b,c FROM t3
1290 INTERSECT SELECT a,b,c FROM t3
1291 EXCEPT SELECT c,b,a FROM t1
1292 UNION SELECT a,b,c FROM t3
1293 ORDER BY y COLLATE NOCASE DESC,x,z)))
1296 do_execsql_test selectA-3.98 {
1299 SELECT upper((SELECT x FROM (
1300 SELECT x,y,z FROM t2
1301 INTERSECT SELECT a,b,c FROM t3
1302 EXCEPT SELECT c,b,a FROM t1
1303 UNION SELECT a,b,c FROM t3
1304 INTERSECT SELECT a,b,c FROM t3
1305 EXCEPT SELECT c,b,a FROM t1
1306 UNION SELECT a,b,c FROM t3
1307 ORDER BY y COLLATE NOCASE DESC,x,z)))
1309 SELECT n || '+' FROM xyz WHERE length(n)<5
1311 SELECT n FROM xyz ORDER BY +n;
1314 #-------------------------------------------------------------------------
1315 # At one point the following code exposed a temp register reuse problem.
1317 proc f {args} { return 1 }
1320 do_execsql_test 4.1.1 {
1321 CREATE TABLE t4(a, b);
1322 CREATE TABLE t5(c, d);
1324 INSERT INTO t5 VALUES(1, 'x');
1325 INSERT INTO t5 VALUES(2, 'x');
1326 INSERT INTO t4 VALUES(3, 'x');
1327 INSERT INTO t4 VALUES(4, 'x');
1329 CREATE INDEX i1 ON t4(a);
1330 CREATE INDEX i2 ON t5(c);
1336 SELECT a, b FROM t4 WHERE f()==f()
1340 `--MERGE (UNION ALL)
1342 | |--SCAN t5 USING INDEX i2
1343 | `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY
1345 |--SCAN t4 USING INDEX i1
1346 `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY
1349 do_execsql_test 4.1.3 {
1352 SELECT a, b FROM t4 WHERE f()==f()
1358 do_execsql_test 4.2.1 {
1359 CREATE TABLE t6(a, b);
1360 CREATE TABLE t7(c, d);
1362 INSERT INTO t7 VALUES(2, 9);
1363 INSERT INTO t6 VALUES(3, 0);
1364 INSERT INTO t6 VALUES(4, 1);
1365 INSERT INTO t7 VALUES(5, 6);
1366 INSERT INTO t6 VALUES(6, 0);
1367 INSERT INTO t7 VALUES(7, 6);
1369 CREATE INDEX i6 ON t6(a);
1370 CREATE INDEX i7 ON t7(c);
1373 do_execsql_test 4.2.2 {
1374 SELECT c, f(d,c,d,c,d) FROM t7
1378 } {/2 . 3 . 4 . 5 . 6 . 7 ./}
1381 proc strip_rnd {explain} {
1382 regexp -all {sqlite_sq_[0123456789ABCDEF]*} $explain sqlite_sq
1385 proc do_same_test {tn q1 args} {
1386 set r2 [strip_rnd [db eval "EXPLAIN $q1"]]
1389 set tst [subst -nocommands {strip_rnd [db eval "EXPLAIN $q"]}]
1390 uplevel do_test $tn.$i [list $tst] [list $r2]
1395 do_execsql_test 5.0 {
1396 CREATE TABLE t8(a, b);
1397 CREATE TABLE t9(c, d);
1401 SELECT a, b FROM t8 INTERSECT SELECT c, d FROM t9 ORDER BY a;
1403 SELECT a, b FROM t8 INTERSECT SELECT c, d FROM t9 ORDER BY t8.a;
1405 SELECT a, b FROM t8 INTERSECT SELECT c, d FROM t9 ORDER BY 1;
1407 SELECT a, b FROM t8 INTERSECT SELECT c, d FROM t9 ORDER BY c;
1409 SELECT a, b FROM t8 INTERSECT SELECT c, d FROM t9 ORDER BY t9.c;
1413 SELECT a, b FROM t8 UNION SELECT c, d FROM t9 ORDER BY a COLLATE NOCASE
1415 SELECT a, b FROM t8 UNION SELECT c, d FROM t9 ORDER BY t8.a COLLATE NOCASE
1417 SELECT a, b FROM t8 UNION SELECT c, d FROM t9 ORDER BY 1 COLLATE NOCASE
1419 SELECT a, b FROM t8 UNION SELECT c, d FROM t9 ORDER BY c COLLATE NOCASE
1421 SELECT a, b FROM t8 UNION SELECT c, d FROM t9 ORDER BY t9.c COLLATE NOCASE
1425 SELECT a, b FROM t8 EXCEPT SELECT c, d FROM t9 ORDER BY b, c COLLATE NOCASE
1427 SELECT a, b FROM t8 EXCEPT SELECT c, d FROM t9 ORDER BY 2, 1 COLLATE NOCASE
1429 SELECT a, b FROM t8 EXCEPT SELECT c, d FROM t9 ORDER BY d, a COLLATE NOCASE
1431 SELECT a, b FROM t8 EXCEPT SELECT * FROM t9 ORDER BY t9.d, c COLLATE NOCASE
1433 SELECT * FROM t8 EXCEPT SELECT c, d FROM t9 ORDER BY d, t8.a COLLATE NOCASE
1436 do_catchsql_test 5.4 {
1437 SELECT * FROM t8 UNION SELECT * FROM t9 ORDER BY a+b COLLATE NOCASE
1438 } {1 {1st ORDER BY term does not match any column in the result set}}
1440 do_execsql_test 6.1 {
1441 DROP TABLE IF EXISTS t1;
1442 DROP TABLE IF EXISTS t2;
1443 CREATE TABLE t1(a INTEGER);
1444 CREATE TABLE t2(b TEXT);
1445 INSERT INTO t2(b) VALUES('12345');
1446 SELECT * FROM (SELECT a FROM t1 UNION SELECT b FROM t2) WHERE a=a;
1449 # 2020-06-15 ticket 8f157e8010b22af0
1452 do_execsql_test 7.1 {
1453 CREATE TABLE t1(c1); INSERT INTO t1 VALUES(12),(123),(1234),(NULL),('abc');
1454 CREATE TABLE t2(c2); INSERT INTO t2 VALUES(44),(55),(123);
1455 CREATE TABLE t3(c3,c4); INSERT INTO t3 VALUES(66,1),(123,2),(77,3);
1456 CREATE VIEW t4 AS SELECT c3 FROM t3;
1457 CREATE VIEW t5 AS SELECT c3 FROM t3 ORDER BY c4;
1459 do_execsql_test 7.2 {
1460 SELECT * FROM t1, t2 WHERE c1=(SELECT 123 INTERSECT SELECT c2 FROM t4) AND c1=123;
1462 do_execsql_test 7.3 {
1463 SELECT * FROM t1, t2 WHERE c1=(SELECT 123 INTERSECT SELECT c2 FROM t5) AND c1=123;
1465 do_execsql_test 7.4 {
1467 CREATE VIEW c(d) AS SELECT b FROM a ORDER BY b;
1468 SELECT sum(d) OVER( PARTITION BY(SELECT 0 FROM c JOIN a WHERE b =(SELECT b INTERSECT SELECT d FROM c) AND b = 123)) FROM c;
1471 #-------------------------------------------------------------------------
1473 do_execsql_test 8.0 {
1475 CREATE TABLE t1(a, b, c, d);
1476 CREATE INDEX t1a ON t1(a);
1477 CREATE INDEX t1b ON t1(b);
1480 do_execsql_test 8.1 {
1481 SELECT 'ABCD' FROM t1
1483 AND (0 OR (SELECT 'xyz' INTERSECT SELECT a ORDER BY 1))