Enhance the command-line completion extension to return the names of
[sqlite.git] / test / whereK.test
blob13c86508f906ed902d839469aeaf94d4f49a23ae
1 # 2015-03-16
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 OR expressions where terms can be
13 # factored from either side of the OR and combined into a single new
14 # AND term that is beneficial to the search.  Examples:
16 #      (x>A OR x=A)              -->    ... AND (x>=A)
17 #      (x>A OR (x=A AND y>=B)    -->    ... AND (x>=A)
22 set testdir [file dirname $argv0]
23 source $testdir/tester.tcl
24 set ::testprefix whereK
26 do_execsql_test 1.1 {
27   CREATE TABLE t1(a,b,c);
28   WITH RECURSIVE c(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM c WHERE x<99)
29     INSERT INTO t1(a,b,c) SELECT x, x/10, x%10 FROM c;
30   CREATE INDEX t1bc ON t1(b,c);
31   SELECT a FROM t1 WHERE b>9 OR b=9 ORDER BY +a;
32 } {90 91 92 93 94 95 96 97 98 99}
33 do_execsql_test 1.1eqp {
34   EXPLAIN QUERY PLAN
35   SELECT a FROM t1 WHERE b>9 OR b=9 ORDER BY +a;
36 } {/SEARCH TABLE t1 USING INDEX t1bc/}
38 do_execsql_test 1.2 {
39   SELECT a FROM t1 WHERE b>8 OR (b=8 AND c>7) ORDER BY +a;
40 } {88 89 90 91 92 93 94 95 96 97 98 99}
41 do_execsql_test 1.2eqp {
42   EXPLAIN QUERY PLAN
43   SELECT a FROM t1 WHERE b>8 OR (b=8 AND c>7) ORDER BY +a;
44 } {/SEARCH TABLE t1 USING INDEX t1bc/}
46 do_execsql_test 1.3 {
47   SELECT a FROM t1 WHERE (b=8 AND c>7) OR b>8 ORDER BY +a;
48 } {88 89 90 91 92 93 94 95 96 97 98 99}
49 do_execsql_test 1.3eqp {
50   EXPLAIN QUERY PLAN
51   SELECT a FROM t1 WHERE (b=8 AND c>7) OR b>8 ORDER BY +a;
52 } {/SEARCH TABLE t1 USING INDEX t1bc/}
54 do_execsql_test 1.4 {
55   SELECT a FROM t1 WHERE (b=8 AND c>7) OR 8<b ORDER BY +a;
56 } {88 89 90 91 92 93 94 95 96 97 98 99}
57 do_execsql_test 1.4eqp {
58   EXPLAIN QUERY PLAN
59   SELECT a FROM t1 WHERE (b=8 AND c>7) OR 8<b ORDER BY +a;
60 } {/SEARCH TABLE t1 USING INDEX t1bc/}
62 do_execsql_test 1.5 {
63   SELECT a FROM t1 WHERE (b=8 AND c>7) OR (b>8 AND c NOT IN (4,5,6))
64    ORDER BY +a;
65 } {88 89 90 91 92 93 97 98 99}
66 do_execsql_test 1.5eqp {
67   EXPLAIN QUERY PLAN
68   SELECT a FROM t1 WHERE (b=8 AND c>7) OR (b>8 AND c NOT IN (4,5,6))
69    ORDER BY +a;
70 } {/SEARCH TABLE t1 USING INDEX t1bc/}
72 finish_test