/ Check-in [c950d6c4]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Make sure that virtual WHERE-clause terms do not get transformed into real terms when processing set of OR-connected terms. Fix for ticket [4c86b126f22ad].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c950d6c4117d076f871518e738cdf9e8c46a19fc
User & Date: drh 2014-02-11 01:50:29
Context
2014-02-11
14:37
Fixes to the "editline" support in the command-line shell. check-in: 7989ce5f user: drh tags: trunk
04:30
Sync the latest trunk changes, and in particular the STAT4 IS NOT NULL fix. check-in: b0067926 user: drh tags: sessions
03:50
Make sure that virtual WHERE-clause terms do not get transformed into real terms when processing set of OR-connected terms. Fix for ticket [4c86b126f22ad]. check-in: de635e09 user: drh tags: branch-3.8.3
01:50
Make sure that virtual WHERE-clause terms do not get transformed into real terms when processing set of OR-connected terms. Fix for ticket [4c86b126f22ad]. check-in: c950d6c4 user: drh tags: trunk
2014-02-10
21:07
Fix a pointless conditional. Add a test case. check-in: 9367632d user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

  3311   3311       */
  3312   3312       if( pWC->nTerm>1 ){
  3313   3313         int iTerm;
  3314   3314         for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
  3315   3315           Expr *pExpr = pWC->a[iTerm].pExpr;
  3316   3316           if( &pWC->a[iTerm] == pTerm ) continue;
  3317   3317           if( ExprHasProperty(pExpr, EP_FromJoin) ) continue;
  3318         -        if( pWC->a[iTerm].wtFlags & (TERM_ORINFO) ) continue;
         3318  +        testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
         3319  +        testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL );
         3320  +        if( pWC->a[iTerm].wtFlags & (TERM_ORINFO|TERM_VIRTUAL) ) continue;
  3319   3321           if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
  3320   3322           pExpr = sqlite3ExprDup(db, pExpr, 0);
  3321   3323           pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr);
  3322   3324         }
  3323   3325         if( pAndExpr ){
  3324   3326           pAndExpr = sqlite3PExpr(pParse, TK_AND, 0, pAndExpr, 0);
  3325   3327         }

Added test/tkt-4c86b126f2.test.

            1  +# 2014-02-11
            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. Specifically,
           12  +# it tests that ticket [4c86b126f22ad548fee0125337bdc9366912d9ac].
           13  +#
           14  +# When SQLite is compiled using SQLITE_ENABLE_STAT3 or SQLITE_ENABLE_STAT4,
           15  +# it gets the wrong answer...
           16  +#
           17  +# The problem was introduced in SQLite 3.8.1.
           18  +
           19  +set testdir [file dirname $argv0]
           20  +source $testdir/tester.tcl
           21  +
           22  +do_execsql_test tkt-4c86b126f2-1.1 {
           23  +  CREATE TABLE nodes(
           24  +     local_relpath  TEXT PRIMARY KEY,
           25  +     moved_to  TEXT
           26  +  );
           27  +  INSERT INTO nodes VALUES('A',NULL);
           28  +  INSERT INTO nodes VALUES('A/B',NULL);
           29  +  INSERT INTO nodes VALUES('',NULL);
           30  +  INSERT INTO nodes VALUES('A/B/C-move',NULL);
           31  +  INSERT INTO nodes VALUES('A/B/C','A/B/C-move');
           32  +  INSERT INTO nodes VALUES('A/B-move',NULL);
           33  +  INSERT INTO nodes VALUES('A/B-move/C-move',NULL);
           34  +  INSERT INTO nodes VALUES('A/B-move/C','x');
           35  +  SELECT local_relpath, moved_to
           36  +   FROM nodes
           37  +  WHERE (local_relpath = 'A/B' OR
           38  +           ((local_relpath > 'A/B/') AND (local_relpath < 'A/B0')))
           39  +    AND moved_to IS NOT NULL;
           40  +} {A/B/C A/B/C-move}
           41  +
           42  +do_execsql_test tkt-4c86b126f2-2.1 {
           43  +  CREATE TABLE t1(x TEXT UNIQUE, y TEXT UNIQUE, z);
           44  +  INSERT INTO t1 VALUES('ghi','jkl','y');
           45  +  SELECT * FROM t1 WHERE (x='ghi' OR y='jkl') AND z IS NOT NULL;
           46  +} {ghi jkl y}
           47  +
           48  +
           49  +finish_test

Changes to test/where8.test.

   206    206     execsql_status {
   207    207       SELECT a, d FROM t1, t2 WHERE (a = 2 OR a = 3) AND d = a
   208    208     }
   209    209   } {2 2 3 3 0 0}
   210    210   
   211    211   do_test where8-3.5 {
   212    212     execsql_status {
   213         -    SELECT a, d FROM t1, t2 WHERE (a = 2 OR a = 3) AND (d = a OR e = 'sixteen')
          213  +    SELECT a, d FROM t1, t2 WHERE (a = 2 OR a = 3) AND (d = +a OR e = 'sixteen')
   214    214        ORDER BY +a, +d;
   215    215     }
   216    216   } {2 2 2 4 3 3 3 4 0 1}
   217    217   
   218    218   do_test where8-3.6 {
   219    219     # The first part of the WHERE clause in this query, (a=2 OR a=3) is
   220    220     # transformed into "a IN (2, 3)". This is why the sort is required.
   221    221     #
   222    222     execsql_status {
   223    223       SELECT a, d 
   224    224       FROM t1, t2 
   225         -    WHERE (a = 2 OR a = 3) AND (d = a OR e = 'sixteen')
          225  +    WHERE (a = 2 OR a = 3) AND (d = +a OR e = 'sixteen')
   226    226       ORDER BY t1.rowid
   227    227     }
   228    228   } {2 2 2 4 3 3 3 4 0 1}
   229    229   do_test where8-3.7 {
   230    230     execsql_status {
   231    231       SELECT a, d 
   232    232       FROM t1, t2