SQLite

Check-in [0ba6d709]
Login

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

Overview
Comment:Do not assume that "x IS NOT ?" implies "x NOT NULL" when considering partial indexes. Fix for ticket [8025674847].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0ba6d709b50d92db1542f2ff30535a80184b00dadf759d51e5cae7a6e37b1764
User & Date: dan 2019-05-11 13:04:33
References
2019-05-11
13:05 Closed ticket [80256748]: Incorrect use of "WHERE x NOT NULL" index for query with a "WHERE x IS NOT ?" term plus 4 other changes (artifact: 6f695f82 user: dan)
Context
2019-05-11
16:14
When considering partial indexes, do not assume that a "CASE x ..." expression implies "x IS NOT NULL". (check-in: 1b243032 user: dan tags: trunk)
13:04
Do not assume that "x IS NOT ?" implies "x NOT NULL" when considering partial indexes. Fix for ticket [8025674847]. (check-in: 0ba6d709 user: dan tags: trunk)
2019-05-10
20:44
Add tests for the RBU module. (check-in: a194e536 user: dan tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/expr.c.

4942
4943
4944
4945
4946
4947
4948

4949
4950
4951
4952
4953
4954
4955
             || sqlite3ExprImpliesExpr(pParse, pE1, pE2->pRight, iTab) )
  ){
    return 1;
  }
  if( pE2->op==TK_NOTNULL
   && pE1->op!=TK_ISNULL
   && pE1->op!=TK_IS

   && pE1->op!=TK_OR
  ){
    Expr *pX = sqlite3ExprSkipCollate(pE1->pLeft);
    testcase( pX!=pE1->pLeft );
    if( sqlite3ExprCompare(pParse, pX, pE2->pLeft, iTab)==0 ) return 1;
  }
  return 0;







>







4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
             || sqlite3ExprImpliesExpr(pParse, pE1, pE2->pRight, iTab) )
  ){
    return 1;
  }
  if( pE2->op==TK_NOTNULL
   && pE1->op!=TK_ISNULL
   && pE1->op!=TK_IS
   && pE1->op!=TK_ISNOT
   && pE1->op!=TK_OR
  ){
    Expr *pX = sqlite3ExprSkipCollate(pE1->pLeft);
    testcase( pX!=pE1->pLeft );
    if( sqlite3ExprCompare(pParse, pX, pE2->pLeft, iTab)==0 ) return 1;
  }
  return 0;

Changes to test/index6.test.

418
419
420
421
422
423
424
425










426

do_execsql_test index6-13.1 {
  DROP TABLE IF EXISTS t0;
  CREATE TABLE t0(c0);
  CREATE INDEX index_0 ON t0(c0) WHERE c0 NOT NULL;
  INSERT INTO t0(c0) VALUES (NULL);
  SELECT * FROM t0 WHERE c0 OR 1;
} {{}}











finish_test









>
>
>
>
>
>
>
>
>
>

>
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
do_execsql_test index6-13.1 {
  DROP TABLE IF EXISTS t0;
  CREATE TABLE t0(c0);
  CREATE INDEX index_0 ON t0(c0) WHERE c0 NOT NULL;
  INSERT INTO t0(c0) VALUES (NULL);
  SELECT * FROM t0 WHERE c0 OR 1;
} {{}}

# 2019-05-11
# Ticket https://sqlite.org/src/tktview/8025674847
reset_db
do_execsql_test index6-14.1 {
  CREATE TABLE IF NOT EXISTS t0 (c0, c1);
  CREATE INDEX IF NOT EXISTS i0 ON t0(c0, c1) WHERE c0 NOT NULL;
  INSERT INTO t0(c0, c1) VALUES(NULL, 'row');
  SELECT * FROM t0 WHERE t0.c0 IS NOT 1;
} {{} row}

finish_test