Index: src/expr.c ================================================================== --- src/expr.c +++ src/expr.c @@ -1738,14 +1738,16 @@ testcase( pExpr->op==TK_COLUMN ); testcase( pExpr->op==TK_AGG_FUNCTION ); testcase( pExpr->op==TK_AGG_COLUMN ); if( pWalker->eCode==3 && pExpr->iTable==pWalker->u.iCur ){ return WRC_Continue; - }else{ - pWalker->eCode = 0; - return WRC_Abort; } + /* Fall through */ + case TK_IF_NULL_ROW: + testcase( pExpr->op==TK_IF_NULL_ROW ); + pWalker->eCode = 0; + return WRC_Abort; case TK_VARIABLE: if( pWalker->eCode==5 ){ /* Silently convert bound parameters that appear inside of CREATE ** statements into a NULL when parsing the CREATE statement text out ** of the sqlite_master table */ Index: src/whereexpr.c ================================================================== --- src/whereexpr.c +++ src/whereexpr.c @@ -1373,15 +1373,15 @@ */ Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){ Bitmask mask; if( p==0 ) return 0; if( p->op==TK_COLUMN ){ - mask = sqlite3WhereGetMask(pMaskSet, p->iTable); - return mask; + return sqlite3WhereGetMask(pMaskSet, p->iTable); } + mask = (p->op==TK_IF_NULL_ROW) ? sqlite3WhereGetMask(pMaskSet, p->iTable) : 0; assert( !ExprHasProperty(p, EP_TokenOnly) ); - mask = p->pRight ? sqlite3WhereExprUsage(pMaskSet, p->pRight) : 0; + if( p->pRight ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pRight); if( p->pLeft ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft); if( ExprHasProperty(p, EP_xIsSelect) ){ mask |= exprSelectUsage(pMaskSet, p->x.pSelect); }else if( p->x.pList ){ mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList); Index: test/join.test ================================================================== --- test/join.test +++ test/join.test @@ -740,7 +740,27 @@ do_execsql_test join-14.5 { DROP TABLE IF EXISTS t1; CREATE TABLE t1(c PRIMARY KEY) WITHOUT ROWID; SELECT * FROM (SELECT 111) LEFT JOIN (SELECT c+222 FROM t1) GROUP BY 1; } {111 {}} + +# Verify the fix to ticket +# https://www.sqlite.org/src/tktview/7fde638e94287d2c948cd9389 +# +db close +sqlite3 db :memory: +do_execsql_test join-14.10 { + CREATE TABLE t1(a); + INSERT INTO t1 VALUES(1),(2),(3); + CREATE VIEW v2 AS SELECT a, 1 AS b FROM t1; + CREATE TABLE t3(x); + INSERT INTO t3 VALUES(2),(4); + SELECT *, '|' FROM t3 LEFT JOIN v2 ON a=x WHERE b=1; +} {2 2 1 |} +do_execsql_test join-14.11 { + SELECT *, '|' FROM t3 LEFT JOIN v2 ON a=x WHERE b+1=x; +} {2 2 1 |} +do_execsql_test join-14.12 { + SELECT *, '|' FROM t3 LEFT JOIN v2 ON a=x ORDER BY b; +} {4 {} {} | 2 2 1 |} finish_test