From 78d1d225d87af40f5bdca57fa72f00b6ffaffa21 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 17 Feb 2020 19:25:07 +0000 Subject: A better (smaller and faster) solution to ticket [4374860b29383380]. FossilOrigin-Name: abc473fb8fb999005dc79a360e34f97b3b25429decf1820dd2afa5c19577753d --- src/expr.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'src/expr.c') diff --git a/src/expr.c b/src/expr.c index be23a5bd5..8b939de24 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2244,15 +2244,6 @@ int sqlite3ExprIsInteger(Expr *p, int *pValue){ return rc; } -/* -** Return true if p is a Column node that references a virtual table. -*/ -int sqlite3ExprIsVtabRef(Expr *p){ - if( p->op!=TK_COLUMN ) return 0; - if( p->y.pTab==0 ) return 0; - return IsVirtual(p->y.pTab); -} - /* ** Return FALSE if there is no chance that the expression can be NULL. ** @@ -5481,19 +5472,25 @@ static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){ case TK_LT: case TK_LE: case TK_GT: - case TK_GE: + case TK_GE: { + Expr *pLeft = pExpr->pLeft; + Expr *pRight = pExpr->pRight; testcase( pExpr->op==TK_EQ ); testcase( pExpr->op==TK_NE ); testcase( pExpr->op==TK_LT ); testcase( pExpr->op==TK_LE ); testcase( pExpr->op==TK_GT ); testcase( pExpr->op==TK_GE ); - if( sqlite3ExprIsVtabRef(pExpr->pLeft) - || sqlite3ExprIsVtabRef(pExpr->pRight) + /* The y.pTab=0 assignment in wherecode.c always happens after the + ** impliesNotNullRow() test */ + if( (pLeft->op==TK_COLUMN && ALWAYS(pLeft->y.pTab!=0) + && IsVirtual(pLeft->y.pTab)) + || (pRight->op==TK_COLUMN && ALWAYS(pRight->y.pTab!=0) + && IsVirtual(pRight->y.pTab)) ){ - return WRC_Prune; + return WRC_Prune; } - + } default: return WRC_Continue; } -- cgit v1.2.3