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 work correctly
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
19 set ::testprefix orderby5
21 # Generate test data for a join. Verify that the join gets the
25 CREATE TABLE t1(a,b,c);
26 CREATE INDEX t1bc ON t1(b,c);
29 SELECT DISTINCT a, b, c FROM t1 WHERE a=0;
31 do_execsql_test 1.2.1 {
33 SELECT DISTINCT a, c, b FROM t1 WHERE a=0;
35 do_execsql_test 1.2.2 {
37 SELECT DISTINCT a, c, b FROM t1 WHERE a='xyz' COLLATE nocase;
39 do_execsql_test 1.2.3 {
41 SELECT DISTINCT a COLLATE nocase, c, b FROM t1 WHERE a='xyz';
43 do_execsql_test 1.2.4 {
45 SELECT DISTINCT a COLLATE nocase, c, b FROM t1 WHERE a='xyz' COLLATE nocase;
49 SELECT DISTINCT b, a, c FROM t1 WHERE a=0;
53 SELECT DISTINCT b, c, a FROM t1 WHERE a=0;
57 SELECT DISTINCT c, a, b FROM t1 WHERE a=0;
61 SELECT DISTINCT c, b, a FROM t1 WHERE a=0;
65 SELECT DISTINCT c, b, a FROM t1 WHERE +a=0;
68 # In some cases, it is faster to do repeated index lookups than it is to
69 # sort. But in other cases, it is faster to sort than to do repeated index
72 do_execsql_test 2.1a {
73 CREATE TABLE t2(a,b,c);
74 CREATE INDEX t2bc ON t2(b,c);
76 INSERT INTO sqlite_stat1 VALUES('t1','t1bc','1000000 10 9');
77 INSERT INTO sqlite_stat1 VALUES('t2','t2bc','100 10 5');
78 ANALYZE sqlite_master;
81 SELECT * FROM t2 WHERE a=0 ORDER BY a, b, c;
84 do_execsql_test 2.1b {
86 SELECT * FROM t1 WHERE likelihood(a=0, 0.05) ORDER BY a, b, c;
91 SELECT * FROM t1 WHERE +a=0 ORDER BY a, b, c;
95 SELECT * FROM t1 WHERE a=0 ORDER BY b, a, c;
99 SELECT * FROM t1 WHERE a=0 ORDER BY b, c, a;
101 do_execsql_test 2.5 {
103 SELECT * FROM t1 WHERE a=0 ORDER BY a, c, b;
105 do_execsql_test 2.6 {
107 SELECT * FROM t1 WHERE a=0 ORDER BY c, a, b;
109 do_execsql_test 2.7 {
111 SELECT * FROM t1 WHERE a=0 ORDER BY c, b, a;
115 do_execsql_test 3.0 {
116 CREATE TABLE t3(a INTEGER PRIMARY KEY, b, c, d, e, f);
117 CREATE INDEX t3bcde ON t3(b, c, d, e);
119 SELECT a FROM t3 WHERE b=2 AND c=3 ORDER BY d DESC, e DESC, b, c, a DESC;
121 do_execsql_test 3.1 {
123 CREATE TABLE t3(a INTEGER PRIMARY KEY, b, c, d, e, f) WITHOUT rowid;
124 CREATE INDEX t3bcde ON t3(b, c, d, e);
126 SELECT a FROM t3 WHERE b=2 AND c=3 ORDER BY d DESC, e DESC, b, c, a DESC;