xref: /sqlite-3.40.0/test/whereE.test (revision 962f9669)
1# 2012 November 9
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 the query planner to make sure it
13# is making good planning decisions.
14#
15
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19set ::testprefix whereE
20
21do_execsql_test 1.1 {
22  CREATE TABLE t1(a,b);
23  INSERT INTO t1 VALUES(1,10), (2,20), (3,30), (2,22), (3, 33);
24  INSERT INTO t1 SELECT * FROM t1;
25  INSERT INTO t1 SELECT * FROM t1;
26  INSERT INTO t1 SELECT * FROM t1;
27  INSERT INTO t1 SELECT * FROM t1;
28  INSERT INTO t1 SELECT * FROM t1;
29  INSERT INTO t1 SELECT * FROM t1;
30  INSERT INTO t1 SELECT * FROM t1;
31  INSERT INTO t1 SELECT * FROM t1;
32  INSERT INTO t1 SELECT * FROM t1;
33  INSERT INTO t1 SELECT * FROM t1;
34  ALTER TABLE t1 ADD COLUMN c;
35  UPDATE t1 SET c=a*rowid+10000;
36  CREATE INDEX t1ab ON t1(a,b);
37
38  CREATE TABLE t2(x,y);
39  INSERT INTO t2 VALUES(4,44),(5,55),(6,66),(7,77);
40  INSERT INTO t2 SELECT x+4, (x+4)*11 FROM t2;
41  INSERT INTO t2 SELECT x+8, (x+8)*11 FROM t2;
42  INSERT INTO t2 SELECT x+16, (x+16)*11 FROM t2;
43  INSERT INTO t2 SELECT x+32, (x+32)*11 FROM t2;
44  INSERT INTO t2 SELECT x+64, (x+32)*11 FROM t2;
45  ALTER TABLE t2 ADD COLUMN z;
46  UPDATE t2 SET z=2;
47  CREATE UNIQUE INDEX t2zx ON t2(z,x);
48
49  EXPLAIN QUERY PLAN SELECT x FROM t1, t2 WHERE a=z AND c=x;
50} {/.*SCAN TABLE t1.*SEARCH TABLE t2.*/}
51do_execsql_test 1.2 {
52  EXPLAIN QUERY PLAN SELECT x FROM t2, t1 WHERE a=z AND c=x;
53} {/.*SCAN TABLE t1.*SEARCH TABLE t2.*/}
54do_execsql_test 1.3 {
55  ANALYZE;
56  EXPLAIN QUERY PLAN SELECT x FROM t1, t2 WHERE a=z AND c=x;
57} {/.*SCAN TABLE t1.*SEARCH TABLE t2.*/}
58do_execsql_test 1.4 {
59  EXPLAIN QUERY PLAN SELECT x FROM t2, t1 WHERE a=z AND c=x;
60} {/.*SCAN TABLE t1.*SEARCH TABLE t2.*/}
61
62finish_test
63