/ Check-in [b30a364a]
Login

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

Overview
Comment:The TK_IF_NULL_ROW expression node must be treated as a variable that references the table Expr.iTable. Proposed fix for ticket [7fde638e94287d2c].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | branch-3.19
Files: files | file ages | folders
SHA3-256: b30a364a12d9865242b1444984cd25ee126dc69108d5c6a2d4b35df184437fe9
User & Date: drh 2017-05-25 00:28:36
Context
2017-05-25
11:39
The SQLITE_EXTRA_IFNULLROW compile-time option causes OP_IfNullRow opcodes to be issued for references to the right-hand side table of *any* flattened join, not just LEFT JOINs. This puts extra stress on the OP_IfNUllRow opcodes for testing purposes. check-in: 1a074c8a user: drh tags: branch-3.19
00:28
The TK_IF_NULL_ROW expression node must be treated as a variable that references the table Expr.iTable. Proposed fix for ticket [7fde638e94287d2c]. check-in: b30a364a user: drh tags: branch-3.19
00:12
Increase the version number to 3.19.2 since ticket [7fde638e94287d2] is going to necessitate another patch release. check-in: c315727a user: drh tags: branch-3.19
00:08
The TK_IF_NULL_ROW expression node must be treated as a variable that references the table Expr.iTable. Proposed fix for ticket [7fde638e94287d2c]. check-in: 77fc2301 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

  1736   1736       case TK_AGG_COLUMN:
  1737   1737         testcase( pExpr->op==TK_ID );
  1738   1738         testcase( pExpr->op==TK_COLUMN );
  1739   1739         testcase( pExpr->op==TK_AGG_FUNCTION );
  1740   1740         testcase( pExpr->op==TK_AGG_COLUMN );
  1741   1741         if( pWalker->eCode==3 && pExpr->iTable==pWalker->u.iCur ){
  1742   1742           return WRC_Continue;
  1743         -      }else{
  1744         -        pWalker->eCode = 0;
  1745         -        return WRC_Abort;
  1746   1743         }
         1744  +      /* Fall through */
         1745  +    case TK_IF_NULL_ROW:
         1746  +      testcase( pExpr->op==TK_IF_NULL_ROW );
         1747  +      pWalker->eCode = 0;
         1748  +      return WRC_Abort;
  1747   1749       case TK_VARIABLE:
  1748   1750         if( pWalker->eCode==5 ){
  1749   1751           /* Silently convert bound parameters that appear inside of CREATE
  1750   1752           ** statements into a NULL when parsing the CREATE statement text out
  1751   1753           ** of the sqlite_master table */
  1752   1754           pExpr->op = TK_NULL;
  1753   1755         }else if( pWalker->eCode==4 ){

Changes to src/whereexpr.c.

  1371   1371   ** a bitmask indicating which tables are used in that expression
  1372   1372   ** tree.
  1373   1373   */
  1374   1374   Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
  1375   1375     Bitmask mask;
  1376   1376     if( p==0 ) return 0;
  1377   1377     if( p->op==TK_COLUMN ){
  1378         -    mask = sqlite3WhereGetMask(pMaskSet, p->iTable);
  1379         -    return mask;
         1378  +    return sqlite3WhereGetMask(pMaskSet, p->iTable);
  1380   1379     }
         1380  +  mask = (p->op==TK_IF_NULL_ROW) ? sqlite3WhereGetMask(pMaskSet, p->iTable) : 0;
  1381   1381     assert( !ExprHasProperty(p, EP_TokenOnly) );
  1382         -  mask = p->pRight ? sqlite3WhereExprUsage(pMaskSet, p->pRight) : 0;
         1382  +  if( p->pRight ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pRight);
  1383   1383     if( p->pLeft ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
  1384   1384     if( ExprHasProperty(p, EP_xIsSelect) ){
  1385   1385       mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
  1386   1386     }else if( p->x.pList ){
  1387   1387       mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
  1388   1388     }
  1389   1389     return mask;

Changes to test/join.test.

   738    738     SELECT * FROM (SELECT 111) LEFT JOIN (SELECT c+222 FROM t1) GROUP BY 1;
   739    739   } {111 {}}
   740    740   do_execsql_test join-14.5 {
   741    741     DROP TABLE IF EXISTS t1;
   742    742     CREATE TABLE t1(c PRIMARY KEY) WITHOUT ROWID;
   743    743     SELECT * FROM (SELECT 111) LEFT JOIN (SELECT c+222 FROM t1) GROUP BY 1;
   744    744   } {111 {}}
          745  +
          746  +# Verify the fix to ticket 
          747  +# https://www.sqlite.org/src/tktview/7fde638e94287d2c948cd9389
          748  +#
          749  +db close
          750  +sqlite3 db :memory:
          751  +do_execsql_test join-14.10 {
          752  +  CREATE TABLE t1(a);
          753  +  INSERT INTO t1 VALUES(1),(2),(3);
          754  +  CREATE VIEW v2 AS SELECT a, 1 AS b FROM t1;
          755  +  CREATE TABLE t3(x);
          756  +  INSERT INTO t3 VALUES(2),(4);
          757  +  SELECT *, '|' FROM t3 LEFT JOIN v2 ON a=x WHERE b=1;
          758  +} {2 2 1 |}
          759  +do_execsql_test join-14.11 {
          760  +  SELECT *, '|' FROM t3 LEFT JOIN v2 ON a=x WHERE b+1=x;
          761  +} {2 2 1 |}
          762  +do_execsql_test join-14.12 {
          763  +  SELECT *, '|' FROM t3 LEFT JOIN v2 ON a=x ORDER BY b;
          764  +} {4 {} {} | 2 2 1 |}
   745    765   
   746    766   finish_test