18426636cSdrh# 2015-03-16 28426636cSdrh# 38426636cSdrh# The author disclaims copyright to this source code. In place of 48426636cSdrh# a legal notice, here is a blessing: 58426636cSdrh# 68426636cSdrh# May you do good and not evil. 78426636cSdrh# May you find forgiveness for yourself and forgive others. 88426636cSdrh# May you share freely, never taking more than you give. 98426636cSdrh# 108426636cSdrh#*********************************************************************** 118426636cSdrh# This file implements regression tests for SQLite library. The 128426636cSdrh# focus of this file is testing OR expressions where terms can be 138426636cSdrh# factored from either side of the OR and combined into a single new 148426636cSdrh# AND term that is beneficial to the search. Examples: 158426636cSdrh# 168426636cSdrh# (x>A OR x=A) --> ... AND (x>=A) 178426636cSdrh# (x>A OR (x=A AND y>=B) --> ... AND (x>=A) 188426636cSdrh# 198426636cSdrh 208426636cSdrh 218426636cSdrh 228426636cSdrhset testdir [file dirname $argv0] 238426636cSdrhsource $testdir/tester.tcl 2405b6048dSmistachkinset ::testprefix whereK 258426636cSdrh 268426636cSdrhdo_execsql_test 1.1 { 278426636cSdrh CREATE TABLE t1(a,b,c); 288426636cSdrh WITH RECURSIVE c(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM c WHERE x<99) 298426636cSdrh INSERT INTO t1(a,b,c) SELECT x, x/10, x%10 FROM c; 308426636cSdrh CREATE INDEX t1bc ON t1(b,c); 318426636cSdrh SELECT a FROM t1 WHERE b>9 OR b=9 ORDER BY +a; 328426636cSdrh} {90 91 92 93 94 95 96 97 98 99} 338426636cSdrhdo_execsql_test 1.1eqp { 348426636cSdrh EXPLAIN QUERY PLAN 358426636cSdrh SELECT a FROM t1 WHERE b>9 OR b=9 ORDER BY +a; 36*8210233cSdrh} {/SEARCH t1 USING INDEX t1bc/} 378426636cSdrh 388426636cSdrhdo_execsql_test 1.2 { 398426636cSdrh SELECT a FROM t1 WHERE b>8 OR (b=8 AND c>7) ORDER BY +a; 408426636cSdrh} {88 89 90 91 92 93 94 95 96 97 98 99} 418426636cSdrhdo_execsql_test 1.2eqp { 428426636cSdrh EXPLAIN QUERY PLAN 438426636cSdrh SELECT a FROM t1 WHERE b>8 OR (b=8 AND c>7) ORDER BY +a; 44*8210233cSdrh} {/SEARCH t1 USING INDEX t1bc/} 458426636cSdrh 468426636cSdrhdo_execsql_test 1.3 { 478426636cSdrh SELECT a FROM t1 WHERE (b=8 AND c>7) OR b>8 ORDER BY +a; 488426636cSdrh} {88 89 90 91 92 93 94 95 96 97 98 99} 498426636cSdrhdo_execsql_test 1.3eqp { 508426636cSdrh EXPLAIN QUERY PLAN 518426636cSdrh SELECT a FROM t1 WHERE (b=8 AND c>7) OR b>8 ORDER BY +a; 52*8210233cSdrh} {/SEARCH t1 USING INDEX t1bc/} 538426636cSdrh 548426636cSdrhdo_execsql_test 1.4 { 558426636cSdrh SELECT a FROM t1 WHERE (b=8 AND c>7) OR 8<b ORDER BY +a; 568426636cSdrh} {88 89 90 91 92 93 94 95 96 97 98 99} 578426636cSdrhdo_execsql_test 1.4eqp { 588426636cSdrh EXPLAIN QUERY PLAN 598426636cSdrh SELECT a FROM t1 WHERE (b=8 AND c>7) OR 8<b ORDER BY +a; 60*8210233cSdrh} {/SEARCH t1 USING INDEX t1bc/} 618426636cSdrh 628426636cSdrhdo_execsql_test 1.5 { 638426636cSdrh SELECT a FROM t1 WHERE (b=8 AND c>7) OR (b>8 AND c NOT IN (4,5,6)) 648426636cSdrh ORDER BY +a; 658426636cSdrh} {88 89 90 91 92 93 97 98 99} 668426636cSdrhdo_execsql_test 1.5eqp { 678426636cSdrh EXPLAIN QUERY PLAN 688426636cSdrh SELECT a FROM t1 WHERE (b=8 AND c>7) OR (b>8 AND c NOT IN (4,5,6)) 698426636cSdrh ORDER BY +a; 70*8210233cSdrh} {/SEARCH t1 USING INDEX t1bc/} 718426636cSdrh 728426636cSdrhfinish_test 73