aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2020-02-17 19:25:07 +0000
committerdrh <drh@noemail.net>2020-02-17 19:25:07 +0000
commit78d1d225d87af40f5bdca57fa72f00b6ffaffa21 (patch)
tree4fbd90792dfbda68f8087b70821ba94540077b63 /src
parentbf48ce49f7c25e5d4524de9fdc5c0d505218d06d (diff)
downloadsqlite-78d1d225d87af40f5bdca57fa72f00b6ffaffa21.tar.gz
sqlite-78d1d225d87af40f5bdca57fa72f00b6ffaffa21.zip
A better (smaller and faster) solution to ticket [4374860b29383380].
FossilOrigin-Name: abc473fb8fb999005dc79a360e34f97b3b25429decf1820dd2afa5c19577753d
Diffstat (limited to 'src')
-rw-r--r--src/expr.c25
-rw-r--r--src/sqliteInt.h4
-rw-r--r--src/whereexpr.c12
3 files changed, 22 insertions, 19 deletions
diff --git a/src/expr.c b/src/expr.c
index be23a5bd5..8b939de24 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -2245,15 +2245,6 @@ int sqlite3ExprIsInteger(Expr *p, int *pValue){
}
/*
-** 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.
**
** If the expression might be NULL or if the expression is too complex
@@ -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;
}
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index c42a9e8c6..517bb40b8 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -2153,8 +2153,11 @@ struct Table {
*/
#ifndef SQLITE_OMIT_VIRTUALTABLE
# define IsVirtual(X) ((X)->nModuleArg)
+# define ExprIsVtab(X) \
+ ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->nModuleArg)
#else
# define IsVirtual(X) 0
+# define ExprIsVtab(X) 0
#endif
/*
@@ -4278,7 +4281,6 @@ int sqlite3ExprIsTableConstant(Expr*,int);
int sqlite3ExprContainsSubquery(Expr*);
#endif
int sqlite3ExprIsInteger(Expr*, int*);
-int sqlite3ExprIsVtabRef(Expr*);
int sqlite3ExprCanBeNull(const Expr*);
int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
int sqlite3IsRowid(const char*);
diff --git a/src/whereexpr.c b/src/whereexpr.c
index e99a44f15..3c91fc353 100644
--- a/src/whereexpr.c
+++ b/src/whereexpr.c
@@ -377,7 +377,8 @@ static int isAuxiliaryVtabOperator(
** MATCH(expression,vtab_column)
*/
pCol = pList->a[1].pExpr;
- if( sqlite3ExprIsVtabRef(pCol) ){
+ testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
+ if( ExprIsVtab(pCol) ){
for(i=0; i<ArraySize(aOp); i++){
if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
*peOp2 = aOp[i].eOp2;
@@ -399,7 +400,8 @@ static int isAuxiliaryVtabOperator(
** with function names in an arbitrary case.
*/
pCol = pList->a[0].pExpr;
- if( sqlite3ExprIsVtabRef(pCol) ){
+ testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
+ if( ExprIsVtab(pCol) ){
sqlite3_vtab *pVtab;
sqlite3_module *pMod;
void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**);
@@ -422,10 +424,12 @@ static int isAuxiliaryVtabOperator(
int res = 0;
Expr *pLeft = pExpr->pLeft;
Expr *pRight = pExpr->pRight;
- if( sqlite3ExprIsVtabRef(pLeft) ){
+ testcase( pLeft->op==TK_COLUMN && pLeft->y.pTab==0 );
+ if( ExprIsVtab(pLeft) ){
res++;
}
- if( pRight && sqlite3ExprIsVtabRef(pRight) ){
+ testcase( pRight && pRight->op==TK_COLUMN && pRight->y.pTab==0 );
+ if( pRight && ExprIsVtab(pRight) ){
res++;
SWAP(Expr*, pLeft, pRight);
}