SQLite

Check-in [1f679604]
Login

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

Overview
Comment:One of the optimizations of check-in [de9c86c9e4cdb34f] does not work for terms originating in the ON/USING clause, as demonstrated by forum post 6cf3bb457c3f4685. This check-in disables that optimization for ON/USING terms. Also improve the TreeView display for the resulting "true"/"false" nodes to show that they originate from the ON/USING clause. Add a testcase() to the other optimization to show that it can still be used for ON/USING terms.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1f6796044008e6f3a61bcf390c0c7eb31947e971f0edada74e7a3a211f8ae76a
User & Date: drh 2021-07-22 16:07:01
Context
2021-07-22
18:22
Fix ALTER TABLE DROP COLUMN so that it generates valid bytecode even when operating on a corrupt database and using PRAGMA writable_schema=ON. dbsqlfuzz 5f09e7bcc78b4954d06bf9f2400d7715f48d1fef (check-in: b65f4f76 user: drh tags: trunk)
16:07
One of the optimizations of check-in [de9c86c9e4cdb34f] does not work for terms originating in the ON/USING clause, as demonstrated by forum post 6cf3bb457c3f4685. This check-in disables that optimization for ON/USING terms. Also improve the TreeView display for the resulting "true"/"false" nodes to show that they originate from the ON/USING clause. Add a testcase() to the other optimization to show that it can still be used for ON/USING terms. (check-in: 1f679604 user: drh tags: trunk)
2021-07-21
15:42
Improved robustness of cursor renumbering in the UNION ALL flattener when operating on vector assignments of an UPDATE FROM. dbsqlfuzz 417d2b053b9b3c9edaf22dd515564f06999e029c (check-in: 60695359 user: drh tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/resolve.c.

814
815
816
817
818
819
820

821
822
823
824
825
826
827
      NameContext *p;
      int i;
      for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){ 
        anRef[i] = p->nRef;
      }
      sqlite3WalkExpr(pWalker, pExpr->pLeft);
      if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){

        if( pExpr->op==TK_NOTNULL ){
          pExpr->u.zToken = "true";
          ExprSetProperty(pExpr, EP_IsTrue);
        }else{
          pExpr->u.zToken = "false";
          ExprSetProperty(pExpr, EP_IsFalse);
        }







>







814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
      NameContext *p;
      int i;
      for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){ 
        anRef[i] = p->nRef;
      }
      sqlite3WalkExpr(pWalker, pExpr->pLeft);
      if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
        testcase( ExprHasProperty(pExpr, EP_FromJoin) );
        if( pExpr->op==TK_NOTNULL ){
          pExpr->u.zToken = "true";
          ExprSetProperty(pExpr, EP_IsTrue);
        }else{
          pExpr->u.zToken = "false";
          ExprSetProperty(pExpr, EP_IsFalse);
        }

Changes to src/treeview.c.

470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
      break;
    }
    case TK_NULL: {
      sqlite3TreeViewLine(pView,"NULL");
      break;
    }
    case TK_TRUEFALSE: {
      sqlite3TreeViewLine(pView,
         sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE");
      break;
    }
#ifndef SQLITE_OMIT_BLOB_LITERAL
    case TK_BLOB: {
      sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
      break;
    }







|
|







470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
      break;
    }
    case TK_NULL: {
      sqlite3TreeViewLine(pView,"NULL");
      break;
    }
    case TK_TRUEFALSE: {
      sqlite3TreeViewLine(pView,"%s%s",
         sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs);
      break;
    }
#ifndef SQLITE_OMIT_BLOB_LITERAL
    case TK_BLOB: {
      sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
      break;
    }

Changes to src/whereexpr.c.

1140
1141
1142
1143
1144
1145
1146



1147

1148
1149
1150
1151
1152
1153
1154
      pNew->wtFlags |= exprCommute(pParse, pDup);
      pNew->leftCursor = aiCurCol[0];
      pNew->u.x.leftColumn = aiCurCol[1];
      testcase( (prereqLeft | extraRight) != prereqLeft );
      pNew->prereqRight = prereqLeft | extraRight;
      pNew->prereqAll = prereqAll;
      pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;



    }else if( op==TK_ISNULL && 0==sqlite3ExprCanBeNull(pLeft) ){

      pExpr->op = TK_TRUEFALSE;
      pExpr->u.zToken = "false";
      ExprSetProperty(pExpr, EP_IsFalse);
      pTerm->prereqAll = 0;
      pTerm->eOperator = 0;
    }
  }







>
>
>
|
>







1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
      pNew->wtFlags |= exprCommute(pParse, pDup);
      pNew->leftCursor = aiCurCol[0];
      pNew->u.x.leftColumn = aiCurCol[1];
      testcase( (prereqLeft | extraRight) != prereqLeft );
      pNew->prereqRight = prereqLeft | extraRight;
      pNew->prereqAll = prereqAll;
      pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
    }else 
    if( op==TK_ISNULL
     && !ExprHasProperty(pExpr,EP_FromJoin)
     && 0==sqlite3ExprCanBeNull(pLeft)
    ){
      pExpr->op = TK_TRUEFALSE;
      pExpr->u.zToken = "false";
      ExprSetProperty(pExpr, EP_IsFalse);
      pTerm->prereqAll = 0;
      pTerm->eOperator = 0;
    }
  }

Changes to test/notnull2.test.

104
105
106
107
108
109
110




















111
112
do_execsql_test 3.0 {
  CREATE TABLE t0(c0 PRIMARY KEY);
  INSERT INTO t0(c0) VALUES (0);
}
do_execsql_test 3.1 {
  SELECT * FROM t0 WHERE ((c0 NOT NULL) AND 1) OR (c0 == NULL);
} {0}





















finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
do_execsql_test 3.0 {
  CREATE TABLE t0(c0 PRIMARY KEY);
  INSERT INTO t0(c0) VALUES (0);
}
do_execsql_test 3.1 {
  SELECT * FROM t0 WHERE ((c0 NOT NULL) AND 1) OR (c0 == NULL);
} {0}

# 2021-07-22 https://sqlite.org/forum/forumpost/2078b7edd2
#
reset_db
do_execsql_test 4.0 {
  SELECT *, '/'
  FROM (
      SELECT NULL val FROM (SELECT 1)
      UNION ALL
      SELECT 'missing' FROM (SELECT 1)
  ) a
  LEFT JOIN (SELECT 1)
      ON a.val IS NULL;
} {{} 1 / missing {} /}
do_execsql_test 4.1 {
  CREATE TABLE t1(a INT);
  INSERT INTO t1(a) VALUES(1);
  CREATE TABLE t2(b INT);
  SELECT * FROM (SELECT 3 AS c FROM t1) AS t3 LEFT JOIN t2 ON c IS NULL;
} {3 {}}

finish_test