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 file is testing that the optimizations that disable
13 # ORDER BY clauses when the natural order of a query is correct.
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
19 set ::testprefix orderby2
21 # Generate test data for a join. Verify that the join gets the
26 CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
27 INSERT INTO t1 VALUES(1,11), (2,22);
28 CREATE TABLE t2(d, e, UNIQUE(d,e));
29 INSERT INTO t2 VALUES(10, 'ten'), (11,'eleven'), (12,'twelve'),
36 SELECT e FROM t1, t2 WHERE a=1 AND d=b ORDER BY d, e;
42 SELECT e FROM t1, t2 WHERE a=1 AND d=b ORDER BY d, e;
48 SELECT e FROM t1, t2 WHERE a=1 AND d=b ORDER BY e;
54 SELECT e FROM t1, t2 WHERE a=1 AND d=b ORDER BY e;
60 SELECT e, b FROM t1, t2 WHERE a=1 ORDER BY d, e;
62 } {ten 11 eleven 11 oneteen 11 twelve 11}
66 SELECT e, b FROM t1, t2 WHERE a=1 ORDER BY d, e;
70 # The following tests derived from TH3 test module cov1/where34.test
74 CREATE TABLE t31(a,b); CREATE INDEX t31ab ON t31(a,b);
75 CREATE TABLE t32(c,d); CREATE INDEX t32cd ON t32(c,d);
76 CREATE TABLE t33(e,f); CREATE INDEX t33ef ON t33(e,f);
77 CREATE TABLE t34(g,h); CREATE INDEX t34gh ON t34(g,h);
79 INSERT INTO t31 VALUES(1,4), (2,3), (1,3);
80 INSERT INTO t32 VALUES(4,5), (3,6), (3,7), (4,8);
81 INSERT INTO t33 VALUES(5,9), (7,10), (6,11), (8,12), (8,13), (7,14);
82 INSERT INTO t34 VALUES(11,20), (10,21), (12,22), (9,23), (13,24),
84 SELECT a||','||c||','||e||','||g FROM t31, t32, t33, t34
85 WHERE c=b AND e=d AND g=f
86 ORDER BY a ASC, c ASC, e DESC, g ASC;
88 } {1,3,7,10 1,3,7,14 1,3,6,11 1,4,8,12 1,4,8,12 1,4,8,13 1,4,5,9 2,3,7,10 2,3,7,14 2,3,6,11}
91 SELECT a||','||c||','||e||','||g FROM t31, t32, t33, t34
92 WHERE c=b AND e=d AND g=f
93 ORDER BY +a ASC, +c ASC, +e DESC, +g ASC;
95 } {1,3,7,10 1,3,7,14 1,3,6,11 1,4,8,12 1,4,8,12 1,4,8,13 1,4,5,9 2,3,7,10 2,3,7,14 2,3,6,11}
98 SELECT a||','||c||','||e||','||g FROM t31, t32, t33, t34
99 WHERE c=b AND e=d AND g=f
100 ORDER BY a ASC, c ASC, e ASC, g ASC;
102 } {1,3,6,11 1,3,7,10 1,3,7,14 1,4,5,9 1,4,8,12 1,4,8,12 1,4,8,13 2,3,6,11 2,3,7,10 2,3,7,14}
104 optimization_control db cover-idx-scan off
107 SELECT a||','||c||','||e||','||g FROM t31, t32, t33, t34
108 WHERE c=b AND e=d AND g=f
109 ORDER BY a ASC, c ASC, e ASC, g ASC;
111 } {1,3,6,11 1,3,7,10 1,3,7,14 1,4,5,9 1,4,8,12 1,4,8,12 1,4,8,13 2,3,6,11 2,3,7,10 2,3,7,14}
112 optimization_control db all on