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
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 {
35 SELECT a FROM t1 WHERE b>9 OR b=9 ORDER BY +a;
36 } {/SEARCH t1 USING INDEX t1bc/}
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 {
43 SELECT a FROM t1 WHERE b>8 OR (b=8 AND c>7) ORDER BY +a;
44 } {/SEARCH t1 USING INDEX t1bc/}
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 {
51 SELECT a FROM t1 WHERE (b=8 AND c>7) OR b>8 ORDER BY +a;
52 } {/SEARCH t1 USING INDEX t1bc/}
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 {
59 SELECT a FROM t1 WHERE (b=8 AND c>7) OR 8<b ORDER BY +a;
60 } {/SEARCH t1 USING INDEX t1bc/}
63 SELECT a FROM t1 WHERE (b=8 AND c>7) OR (b>8 AND c NOT IN (4,5,6))
65 } {88 89 90 91 92 93 97 98 99}
66 do_execsql_test 1.5eqp {
68 SELECT a FROM t1 WHERE (b=8 AND c>7) OR (b>8 AND c NOT IN (4,5,6))
70 } {/SEARCH t1 USING INDEX t1bc/}