xref: /sqlite-3.40.0/test/orderby5.test (revision 962f9669)
1# 2013-06-14
2#
3# The author disclaims copyright to this source code.  In place of
4# a legal notice, here is a blessing:
5#
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.
9#
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
14#
15
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19set ::testprefix orderby5
20
21# Generate test data for a join.  Verify that the join gets the
22# correct answer.
23#
24do_execsql_test 1.1 {
25  CREATE TABLE t1(a,b,c);
26  CREATE INDEX t1bc ON t1(b,c);
27
28  EXPLAIN QUERY PLAN
29  SELECT DISTINCT a, b, c FROM t1 WHERE a=0;
30} {~/B-TREE/}
31do_execsql_test 1.2.1 {
32  EXPLAIN QUERY PLAN
33  SELECT DISTINCT a, c, b FROM t1 WHERE a=0;
34} {~/B-TREE/}
35do_execsql_test 1.2.2 {
36  EXPLAIN QUERY PLAN
37  SELECT DISTINCT a, c, b FROM t1 WHERE a='xyz' COLLATE nocase;
38} {/B-TREE/}
39do_execsql_test 1.2.3 {
40  EXPLAIN QUERY PLAN
41  SELECT DISTINCT a COLLATE nocase, c, b FROM t1 WHERE a='xyz';
42} {/B-TREE/}
43do_execsql_test 1.2.4 {
44  EXPLAIN QUERY PLAN
45  SELECT DISTINCT a COLLATE nocase, c, b FROM t1 WHERE a='xyz' COLLATE nocase;
46} {~/B-TREE/}
47do_execsql_test 1.3 {
48  EXPLAIN QUERY PLAN
49  SELECT DISTINCT b, a, c FROM t1 WHERE a=0;
50} {~/B-TREE/}
51do_execsql_test 1.4 {
52  EXPLAIN QUERY PLAN
53  SELECT DISTINCT b, c, a FROM t1 WHERE a=0;
54} {~/B-TREE/}
55do_execsql_test 1.5 {
56  EXPLAIN QUERY PLAN
57  SELECT DISTINCT c, a, b FROM t1 WHERE a=0;
58} {~/B-TREE/}
59do_execsql_test 1.6 {
60  EXPLAIN QUERY PLAN
61  SELECT DISTINCT c, b, a FROM t1 WHERE a=0;
62} {~/B-TREE/}
63do_execsql_test 1.7 {
64  EXPLAIN QUERY PLAN
65  SELECT DISTINCT c, b, a FROM t1 WHERE +a=0;
66} {/B-TREE/}
67do_execsql_test 2.1 {
68  EXPLAIN QUERY PLAN
69  SELECT * FROM t1 WHERE a=0 ORDER BY a, b, c;
70} {~/B-TREE/}
71do_execsql_test 2.2 {
72  EXPLAIN QUERY PLAN
73  SELECT * FROM t1 WHERE +a=0 ORDER BY a, b, c;
74} {/B-TREE/}
75do_execsql_test 2.3 {
76  EXPLAIN QUERY PLAN
77  SELECT * FROM t1 WHERE a=0 ORDER BY b, a, c;
78} {~/B-TREE/}
79do_execsql_test 2.4 {
80  EXPLAIN QUERY PLAN
81  SELECT * FROM t1 WHERE a=0 ORDER BY b, c, a;
82} {~/B-TREE/}
83do_execsql_test 2.5 {
84  EXPLAIN QUERY PLAN
85  SELECT * FROM t1 WHERE a=0 ORDER BY a, c, b;
86} {/B-TREE/}
87do_execsql_test 2.6 {
88  EXPLAIN QUERY PLAN
89  SELECT * FROM t1 WHERE a=0 ORDER BY c, a, b;
90} {/B-TREE/}
91do_execsql_test 2.7 {
92  EXPLAIN QUERY PLAN
93  SELECT * FROM t1 WHERE a=0 ORDER BY c, b, a;
94} {/B-TREE/}
95
96
97do_execsql_test 3.0 {
98  CREATE TABLE t3(a INTEGER PRIMARY KEY, b, c, d, e, f);
99  CREATE INDEX t3bcde ON t3(b, c, d, e);
100  EXPLAIN QUERY PLAN
101  SELECT a FROM t3 WHERE b=2 AND c=3 ORDER BY d DESC, e DESC, b, c, a DESC;
102} {~/B-TREE/}
103do_execsql_test 3.1 {
104  DROP TABLE t3;
105  CREATE TABLE t3(a INTEGER PRIMARY KEY, b, c, d, e, f) WITHOUT rowid;
106  CREATE INDEX t3bcde ON t3(b, c, d, e);
107  EXPLAIN QUERY PLAN
108  SELECT a FROM t3 WHERE b=2 AND c=3 ORDER BY d DESC, e DESC, b, c, a DESC;
109} {~/B-TREE/}
110
111
112finish_test
113