146 lines
4.4 KiB
Diff
146 lines
4.4 KiB
Diff
Index: src/expr.c
|
|
==================================================================
|
|
--- src/expr.c
|
|
+++ src/expr.c
|
|
@@ -2242,19 +2242,10 @@
|
|
default: break;
|
|
}
|
|
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.
|
|
**
|
|
** If the expression might be NULL or if the expression is too complex
|
|
** to tell return TRUE.
|
|
@@ -5479,23 +5470,29 @@
|
|
case TK_EQ:
|
|
case TK_NE:
|
|
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;
|
|
}
|
|
}
|
|
|
|
|
|
Index: src/sqliteInt.h
|
|
==================================================================
|
|
--- src/sqliteInt.h
|
|
+++ src/sqliteInt.h
|
|
@@ -2151,12 +2151,15 @@
|
|
** done as a macro so that it will be optimized out when virtual
|
|
** table support is omitted from the build.
|
|
*/
|
|
#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
|
|
|
|
/*
|
|
** Macros to determine if a column is hidden. IsOrdinaryHiddenColumn()
|
|
** only works for non-virtual tables (ordinary tables and views) and is
|
|
@@ -4276,11 +4279,10 @@
|
|
int sqlite3ExprIsTableConstant(Expr*,int);
|
|
#ifdef SQLITE_ENABLE_CURSOR_HINTS
|
|
int sqlite3ExprContainsSubquery(Expr*);
|
|
#endif
|
|
int sqlite3ExprIsInteger(Expr*, int*);
|
|
-int sqlite3ExprIsVtabRef(Expr*);
|
|
int sqlite3ExprCanBeNull(const Expr*);
|
|
int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
|
|
int sqlite3IsRowid(const char*);
|
|
void sqlite3GenerateRowDelete(
|
|
Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8,int);
|
|
|
|
Index: src/whereexpr.c
|
|
==================================================================
|
|
--- src/whereexpr.c
|
|
+++ src/whereexpr.c
|
|
@@ -375,11 +375,12 @@
|
|
**
|
|
** vtab_column MATCH expression
|
|
** 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;
|
|
*ppRight = pList->a[0].pExpr;
|
|
*ppLeft = pCol;
|
|
@@ -397,11 +398,12 @@
|
|
** Historically, xFindFunction expected to see lower-case function
|
|
** names. But for this use case, xFindFunction is expected to deal
|
|
** 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**);
|
|
void *pNotUsed;
|
|
pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab;
|
|
@@ -420,14 +422,16 @@
|
|
}
|
|
}else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){
|
|
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);
|
|
}
|
|
*ppLeft = pLeft;
|
|
*ppRight = pRight;
|
|
|