diff options
author | dan <dan@noemail.net> | 2016-07-28 13:59:21 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2016-07-28 13:59:21 +0000 |
commit | 34c125747de93ecb82a0a6e10877de03ea3d80f6 (patch) | |
tree | 28838fce7721bc03a2fe5d0578876985a9f0e19c /src/expr.c | |
parent | d49fd4e89a1a9a48a14f79ba6356165b04e6e295 (diff) | |
parent | 4aff119f3a270e6b453cd32f0226a09bc1c4cd24 (diff) | |
download | sqlite-34c125747de93ecb82a0a6e10877de03ea3d80f6.tar.gz sqlite-34c125747de93ecb82a0a6e10877de03ea3d80f6.zip |
Merge latest trunk changes into this branch.
FossilOrigin-Name: 9685880f7baeb670739fdcf2d9df08e22abaa699
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/expr.c b/src/expr.c index 3c95136c5..26587309f 100644 --- a/src/expr.c +++ b/src/expr.c @@ -4314,6 +4314,61 @@ int sqlite3ExprImpliesExpr(Expr *pE1, Expr *pE2, int iTab){ /* ** An instance of the following structure is used by the tree walker +** to determine if an expression can be evaluated by reference to the +** index only, without having to do a search for the corresponding +** table entry. The IdxCover.pIdx field is the index. IdxCover.iCur +** is the cursor for the table. +*/ +struct IdxCover { + Index *pIdx; /* The index to be tested for coverage */ + int iCur; /* Cursor number for the table corresponding to the index */ +}; + +/* +** Check to see if there are references to columns in table +** pWalker->u.pIdxCover->iCur can be satisfied using the index +** pWalker->u.pIdxCover->pIdx. +*/ +static int exprIdxCover(Walker *pWalker, Expr *pExpr){ + if( pExpr->op==TK_COLUMN + && pExpr->iTable==pWalker->u.pIdxCover->iCur + && sqlite3ColumnOfIndex(pWalker->u.pIdxCover->pIdx, pExpr->iColumn)<0 + ){ + pWalker->eCode = 1; + return WRC_Abort; + } + return WRC_Continue; +} + +/* +** Determine if an index pIdx on table with cursor iCur contains will +** the expression pExpr. Return true if the index does cover the +** expression and false if the pExpr expression references table columns +** that are not found in the index pIdx. +** +** An index covering an expression means that the expression can be +** evaluated using only the index and without having to lookup the +** corresponding table entry. +*/ +int sqlite3ExprCoveredByIndex( + Expr *pExpr, /* The index to be tested */ + int iCur, /* The cursor number for the corresponding table */ + Index *pIdx /* The index that might be used for coverage */ +){ + Walker w; + struct IdxCover xcov; + memset(&w, 0, sizeof(w)); + xcov.iCur = iCur; + xcov.pIdx = pIdx; + w.xExprCallback = exprIdxCover; + w.u.pIdxCover = &xcov; + sqlite3WalkExpr(&w, pExpr); + return !w.eCode; +} + + +/* +** An instance of the following structure is used by the tree walker ** to count references to table columns in the arguments of an ** aggregate function, in order to implement the ** sqlite3FunctionThisSrc() routine. |