xref: /sqlite-3.40.0/test/orderby3.test (revision 97a3e09f)
1*97a3e09fSdrh# 2013 January 09
2be93ca35Sdrh#
3be93ca35Sdrh# The author disclaims copyright to this source code.  In place of
4be93ca35Sdrh# a legal notice, here is a blessing:
5be93ca35Sdrh#
6be93ca35Sdrh#    May you do good and not evil.
7be93ca35Sdrh#    May you find forgiveness for yourself and forgive others.
8be93ca35Sdrh#    May you share freely, never taking more than you give.
9be93ca35Sdrh#
10be93ca35Sdrh#***********************************************************************
11be93ca35Sdrh# This file implements regression tests for SQLite library.  The
12be93ca35Sdrh# focus of this file is testing that the optimizations that disable
13be93ca35Sdrh# ORDER BY clauses work correctly on a 3-way join.  See ticket
14be93ca35Sdrh# http://www.sqlite.org/src/956e4d7f89
15be93ca35Sdrh#
16be93ca35Sdrh
17be93ca35Sdrh
18be93ca35Sdrhset testdir [file dirname $argv0]
19be93ca35Sdrhsource $testdir/tester.tcl
20be93ca35Sdrhset ::testprefix orderby3
21be93ca35Sdrh
22be93ca35Sdrh# Generate test data for a join.  Verify that the join gets the
23be93ca35Sdrh# correct answer.
24be93ca35Sdrh#
25be93ca35Sdrhdo_execsql_test 1.0 {
26be93ca35Sdrh  CREATE TABLE t1(a INTEGER PRIMARY KEY);
27be93ca35Sdrh  CREATE TABLE t2(b INTEGER PRIMARY KEY, c INTEGER);
28be93ca35Sdrh  CREATE TABLE t3(d INTEGER);
29be93ca35Sdrh
30be93ca35Sdrh  INSERT INTO t1 VALUES(1),(2),(3);
31be93ca35Sdrh
32be93ca35Sdrh  INSERT INTO t2 VALUES(3, 1);
33be93ca35Sdrh  INSERT INTO t2 VALUES(4, 2);
34be93ca35Sdrh  INSERT INTO t2 VALUES(5, 3);
35be93ca35Sdrh
36be93ca35Sdrh  INSERT INTO t3 VALUES(4),(3),(5);
37be93ca35Sdrh} {}
38be93ca35Sdrhdo_execsql_test 1.1.asc {
39be93ca35Sdrh  SELECT t1.a
40be93ca35Sdrh    FROM t1, t2, t3
41be93ca35Sdrh   WHERE t1.a=t2.c AND t2.b=t3.d
42be93ca35Sdrh   ORDER BY t1.a;
43be93ca35Sdrh} {1 2 3}
44be93ca35Sdrhdo_execsql_test 1.1.desc {
45be93ca35Sdrh  SELECT t1.a
46be93ca35Sdrh    FROM t1, t2, t3
47be93ca35Sdrh   WHERE t1.a=t2.c AND t2.b=t3.d
48be93ca35Sdrh   ORDER BY t1.a DESC;
49be93ca35Sdrh} {3 2 1}
50be93ca35Sdrhdo_execsql_test 1.123.asc {
51be93ca35Sdrh  SELECT t1.a
52be93ca35Sdrh    FROM t1 CROSS JOIN t2 CROSS JOIN t3
53be93ca35Sdrh   WHERE t1.a=t2.c AND t2.b=t3.d
54be93ca35Sdrh   ORDER BY t1.a;
55be93ca35Sdrh} {1 2 3}
56be93ca35Sdrhdo_execsql_test 1.123.desc {
57be93ca35Sdrh  SELECT t1.a
58be93ca35Sdrh    FROM t1 CROSS JOIN t2 CROSS JOIN t3
59be93ca35Sdrh   WHERE t1.a=t2.c AND t2.b=t3.d
60be93ca35Sdrh   ORDER BY t1.a DESC;
61be93ca35Sdrh} {3 2 1}
62be93ca35Sdrhdo_execsql_test 1.132.asc {
63be93ca35Sdrh  SELECT t1.a
64be93ca35Sdrh    FROM t1 CROSS JOIN t3 CROSS JOIN t2
65be93ca35Sdrh   WHERE t1.a=t2.c AND t2.b=t3.d
66be93ca35Sdrh   ORDER BY t1.a;
67be93ca35Sdrh} {1 2 3}
68be93ca35Sdrhdo_execsql_test 1.132.desc {
69be93ca35Sdrh  SELECT t1.a
70be93ca35Sdrh    FROM t1 CROSS JOIN t3 CROSS JOIN t2
71be93ca35Sdrh   WHERE t1.a=t2.c AND t2.b=t3.d
72be93ca35Sdrh   ORDER BY t1.a DESC;
73be93ca35Sdrh} {3 2 1}
74be93ca35Sdrhdo_execsql_test 1.213.asc {
75be93ca35Sdrh  SELECT t1.a
76be93ca35Sdrh    FROM t2 CROSS JOIN t1 CROSS JOIN t3
77be93ca35Sdrh   WHERE t1.a=t2.c AND t2.b=t3.d
78be93ca35Sdrh   ORDER BY t1.a;
79be93ca35Sdrh} {1 2 3}
80be93ca35Sdrhdo_execsql_test 1.213.desc {
81be93ca35Sdrh  SELECT t1.a
82be93ca35Sdrh    FROM t2 CROSS JOIN t1 CROSS JOIN t3
83be93ca35Sdrh   WHERE t1.a=t2.c AND t2.b=t3.d
84be93ca35Sdrh   ORDER BY t1.a DESC;
85be93ca35Sdrh} {3 2 1}
86be93ca35Sdrhdo_execsql_test 1.231.asc {
87be93ca35Sdrh  SELECT t1.a
88be93ca35Sdrh    FROM t2 CROSS JOIN t3 CROSS JOIN t1
89be93ca35Sdrh   WHERE t1.a=t2.c AND t2.b=t3.d
90be93ca35Sdrh   ORDER BY t1.a;
91be93ca35Sdrh} {1 2 3}
92be93ca35Sdrhdo_execsql_test 1.231.desc {
93be93ca35Sdrh  SELECT t1.a
94be93ca35Sdrh    FROM t2 CROSS JOIN t3 CROSS JOIN t1
95be93ca35Sdrh   WHERE t1.a=t2.c AND t2.b=t3.d
96be93ca35Sdrh   ORDER BY t1.a DESC;
97be93ca35Sdrh} {3 2 1}
98be93ca35Sdrhdo_execsql_test 1.312.asc {
99be93ca35Sdrh  SELECT t1.a
100be93ca35Sdrh    FROM t3 CROSS JOIN t1 CROSS JOIN t2
101be93ca35Sdrh   WHERE t1.a=t2.c AND t2.b=t3.d
102be93ca35Sdrh   ORDER BY t1.a;
103be93ca35Sdrh} {1 2 3}
104be93ca35Sdrhdo_execsql_test 1.312.desc {
105be93ca35Sdrh  SELECT t1.a
106be93ca35Sdrh    FROM t3 CROSS JOIN t1 CROSS JOIN t2
107be93ca35Sdrh   WHERE t1.a=t2.c AND t2.b=t3.d
108be93ca35Sdrh   ORDER BY t1.a DESC;
109be93ca35Sdrh} {3 2 1}
110be93ca35Sdrhdo_execsql_test 1.321.asc {
111be93ca35Sdrh  SELECT t1.a
112be93ca35Sdrh    FROM t3 CROSS JOIN t2 CROSS JOIN t1
113be93ca35Sdrh   WHERE t1.a=t2.c AND t2.b=t3.d
114be93ca35Sdrh   ORDER BY t1.a;
115be93ca35Sdrh} {1 2 3}
116be93ca35Sdrhdo_execsql_test 1.321.desc {
117be93ca35Sdrh  SELECT t1.a
118be93ca35Sdrh    FROM t3 CROSS JOIN t2 CROSS JOIN t1
119be93ca35Sdrh   WHERE t1.a=t2.c AND t2.b=t3.d
120be93ca35Sdrh   ORDER BY t1.a DESC;
121be93ca35Sdrh} {3 2 1}
122be93ca35Sdrh
123be93ca35Sdrhfinish_test
124