gitlab.com/CoiaPrant/sqlite3@v1.19.1/testdata/tcl/whereK.test (about)

     1  # 2015-03-16
     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 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:
    15  #
    16  #      (x>A OR x=A)              -->    ... AND (x>=A)
    17  #      (x>A OR (x=A AND y>=B)    -->    ... AND (x>=A)
    18  #
    19  
    20  
    21  
    22  set testdir [file dirname $argv0]
    23  source $testdir/tester.tcl
    24  set ::testprefix whereK
    25  
    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 t1 USING INDEX t1bc/}
    37  
    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 t1 USING INDEX t1bc/}
    45  
    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 t1 USING INDEX t1bc/}
    53  
    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 t1 USING INDEX t1bc/}
    61  
    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 t1 USING INDEX t1bc/}
    71  
    72  finish_test