/ Check-in [e2ad30c8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix a problem with vector range constraints and mixed ASC/DESC indexes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | rowvalue
Files: files | file ages | folders
SHA1: e2ad30c8b5366fd8e50f36c62345ed03ec613c47
User & Date: dan 2016-08-02 17:07:51
Context
2016-08-02
17:45
Fix SQLITE_OMIT_SUBQUERY builds. check-in: 339f85f4 user: dan tags: rowvalue
17:07
Fix a problem with vector range constraints and mixed ASC/DESC indexes. check-in: e2ad30c8 user: dan tags: rowvalue
16:24
Merge latest trunk changes into this branch. check-in: d468101b user: dan tags: rowvalue
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

  2222   2222       if( pRhs->flags & EP_xIsSelect ){
  2223   2223         pRhs = pRhs->x.pSelect->pEList->a[i].pExpr;
  2224   2224       }else{
  2225   2225         pRhs = pRhs->x.pList->a[i].pExpr;
  2226   2226       }
  2227   2227   
  2228   2228       /* Check that the LHS of the comparison is a column reference to
  2229         -    ** the right column of the right source table. 
  2230         -    */
         2229  +    ** the right column of the right source table. And that the sort
         2230  +    ** order of the index column is the same as the sort order of the
         2231  +    ** leftmost index column.  */
  2231   2232       if( pLhs->op!=TK_COLUMN 
  2232   2233        || pLhs->iTable!=iCur 
  2233   2234        || pLhs->iColumn!=pIdx->aiColumn[i+nEq] 
         2235  +     || pIdx->aSortOrder[i]!=pIdx->aSortOrder[0]
  2234   2236       ){
  2235   2237         break;
  2236   2238       }
  2237   2239   
  2238   2240       aff = sqlite3CompareAffinity(pRhs, sqlite3ExprAffinity(pLhs));
  2239   2241       idxaff = pIdx->pTable->aCol[pLhs->iColumn].affinity;
  2240   2242       if( aff!=idxaff ) break;

Changes to test/rowvalue3.test.

    13     13   # where the SELECT statement returns more than one column.
    14     14   #
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   set ::testprefix rowvalue3
    19     19   
    20         -# Drop all auxiliary indexes from the main database opened by handle [db].
    21         -#
    22         -proc drop_all_indexes {} {
    23         -  set L [db eval {
    24         -    SELECT name FROM sqlite_master WHERE type='index' AND sql LIKE 'create%'
    25         -  }]
    26         -  foreach idx $L { db eval "DROP INDEX $idx" }
    27         -}
    28         -
    29     20   do_execsql_test 1.0 {
    30     21     CREATE TABLE t1(a, b, c);
    31     22     CREATE INDEX i1 ON t1(a, b);
    32     23     INSERT INTO t1 VALUES(1, 2, 3);
    33     24     INSERT INTO t1 VALUES(4, 5, 6);
    34     25     INSERT INTO t1 VALUES(7, 8, 9);
    35     26   }

Changes to test/rowvalue4.test.

    13     13   # and sub-selects that return multiple arguments.
    14     14   #
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   set ::testprefix rowvalue4
    19     19   
    20         -do_execsql_test 0 {
           20  +#-------------------------------------------------------------------------
           21  +# Test some error conditions:
           22  +# 
           23  +#   * row values used where they are not supported,
           24  +#   * row values or sub-selects that contain/return the wrong number
           25  +#     of elements.
           26  +#
           27  +do_execsql_test 1.0 {
    21     28     CREATE TABLE t1(a, b, c);
    22     29     CREATE INDEX t1bac ON t1(b, a, c);
    23     30   }
    24     31   
    25     32   foreach {tn e} {
    26     33     1 "(1, 2, 3)"
    27     34     2 "1 + (1, 2)"
................................................................................
    40     47   
    41     48     6 "SELECT * FROM t1 WHERE (a, b) IN (SELECT * FROM t1)" 
    42     49                                {sub-select returns 3 columns - expected 2}
    43     50   } {
    44     51     do_catchsql_test 2.$tn "$s" [list 1 $error]
    45     52   }
    46     53   
           54  +#-------------------------------------------------------------------------
           55  +do_execsql_test 2.0 {
           56  +  CREATE TABLE t2(a, b, c, d);
           57  +  INSERT INTO t2 VALUES(1, 1, 1,   1);
           58  +  INSERT INTO t2 VALUES(1, 1, 2,   2);
           59  +  INSERT INTO t2 VALUES(1, 1, 3,   3);
           60  +  INSERT INTO t2 VALUES(1, 2, 1,   4);
           61  +  INSERT INTO t2 VALUES(1, 2, 2,   5);
           62  +  INSERT INTO t2 VALUES(1, 2, 3,   6);
           63  +  INSERT INTO t2 VALUES(1, 3, 1,   7);
           64  +  INSERT INTO t2 VALUES(1, 3, 2,   8);
           65  +  INSERT INTO t2 VALUES(1, 3, 3,   9);
           66  +
           67  +  INSERT INTO t2 VALUES(2, 1, 1,   10);
           68  +  INSERT INTO t2 VALUES(2, 1, 2,   11);
           69  +  INSERT INTO t2 VALUES(2, 1, 3,   12);
           70  +  INSERT INTO t2 VALUES(2, 2, 1,   13);
           71  +  INSERT INTO t2 VALUES(2, 2, 2,   14);
           72  +  INSERT INTO t2 VALUES(2, 2, 3,   15);
           73  +  INSERT INTO t2 VALUES(2, 3, 1,   16);
           74  +  INSERT INTO t2 VALUES(2, 3, 2,   17);
           75  +  INSERT INTO t2 VALUES(2, 3, 3,   18);
           76  +
           77  +  INSERT INTO t2 VALUES(3, 1, 1,   19);
           78  +  INSERT INTO t2 VALUES(3, 1, 2,   20);
           79  +  INSERT INTO t2 VALUES(3, 1, 3,   21);
           80  +  INSERT INTO t2 VALUES(3, 2, 1,   22);
           81  +  INSERT INTO t2 VALUES(3, 2, 2,   23);
           82  +  INSERT INTO t2 VALUES(3, 2, 3,   24);
           83  +  INSERT INTO t2 VALUES(3, 3, 1,   25);
           84  +  INSERT INTO t2 VALUES(3, 3, 2,   26);
           85  +  INSERT INTO t2 VALUES(3, 3, 3,   27);
           86  +}
           87  +
           88  +foreach {nm idx} {
           89  +  idx1 {}
           90  +  idx2 { CREATE INDEX t2abc ON t2(a, b, c); }
           91  +  idx3 { CREATE INDEX t2abc ON t2(a, b DESC, c); }
           92  +  idx4 { CREATE INDEX t2abc ON t2(a DESC, b DESC, c DESC); }
           93  +  idx5 { CREATE INDEX t2abc ON t2(a ASC, b ASC, c ASC); }
           94  +  idx6 { CREATE INDEX t2abc ON t2(a DESC, b, c); }
           95  +} {
           96  +  drop_all_indexes
           97  +  execsql $idx
           98  +
           99  +  foreach {tn where res} {
          100  +    1 "(a, b, c) < (2, 2, 2)"  {1 2 3 4 5 6 7 8 9 10 11 12 13}
          101  +    2 "(a, b, c) <= (2, 2, 2)" {1 2 3 4 5 6 7 8 9 10 11 12 13 14}
          102  +    3 "(a, b, c) > (2, 2, 2)"  {15 16 17 18 19 20 21 22 23 24 25 26 27}
          103  +    4 "(a, b, c) >= (2, 2, 2)" {14 15 16 17 18 19 20 21 22 23 24 25 26 27}
          104  +  } {
          105  +    set result [db eval "SELECT d FROM t2 WHERE $where"]
          106  +    do_test 2.$nm.$tn { lsort -integer $result } $res
          107  +  }
          108  +}
    47    109   finish_test
    48    110   

Changes to test/tester.tcl.

    21     21   #
    22     22   #      is_relative_file
    23     23   #      test_pwd
    24     24   #      get_pwd
    25     25   #      copy_file              FROM TO
    26     26   #      delete_file            FILENAME
    27     27   #      drop_all_tables        ?DB?
           28  +#      drop_all_indexes       ?DB?
    28     29   #      forcecopy              FROM TO
    29     30   #      forcedelete            FILENAME
    30     31   #
    31     32   # Test the capability of the SQLite version built into the interpreter to
    32     33   # determine if a specific test can be run:
    33     34   #
    34     35   #      capable                EXPR
................................................................................
  1946   1947         $db eval "DROP $type \"$t\""
  1947   1948       }
  1948   1949     }
  1949   1950     ifcapable trigger&&foreignkey {
  1950   1951       $db eval "PRAGMA foreign_keys = $pk"
  1951   1952     }
  1952   1953   }
         1954  +
         1955  +# Drop all auxiliary indexes from the main database opened by handle [db].
         1956  +#
         1957  +proc drop_all_indexes {{db db}} {
         1958  +  set L [$db eval {
         1959  +    SELECT name FROM sqlite_master WHERE type='index' AND sql LIKE 'create%'
         1960  +  }]
         1961  +  foreach idx $L { $db eval "DROP INDEX $idx" }
         1962  +}
         1963  +
  1953   1964   
  1954   1965   #-------------------------------------------------------------------------
  1955   1966   # If a test script is executed with global variable $::G(perm:name) set to
  1956   1967   # "wal", then the tests are run in WAL mode. Otherwise, they should be run
  1957   1968   # in rollback mode. The following Tcl procs are used to make this less
  1958   1969   # intrusive:
  1959   1970   #