diff options
author | drh <drh@noemail.net> | 2014-10-25 12:28:25 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2014-10-25 12:28:25 +0000 |
commit | 051575cbf4c47fc472f53146e30d6ddddc9054b3 (patch) | |
tree | 718ef5e21e91755c980d94a58dec8e84e677683a /src | |
parent | 059b2d50e1c6a57ca301f3c9639f92f7e16ff96e (diff) | |
download | sqlite-051575cbf4c47fc472f53146e30d6ddddc9054b3.tar.gz sqlite-051575cbf4c47fc472f53146e30d6ddddc9054b3.zip |
Do not use virtual (and hence redundant) WHERE-clause terms to restrict the
content of a automatic partial index. Show when an automatic partial index
is used in the EXPLAIN QUERY PLAN output.
FossilOrigin-Name: b9ad601eab1d7298d369267eb697c7fa1bc16985
Diffstat (limited to 'src')
-rw-r--r-- | src/where.c | 4 | ||||
-rw-r--r-- | src/whereInt.h | 1 |
2 files changed, 5 insertions, 0 deletions
diff --git a/src/where.c b/src/where.c index 8d2a89187..2e42b8fc3 100644 --- a/src/where.c +++ b/src/where.c @@ -1612,6 +1612,7 @@ static void constructAutomaticIndex( idxCols = 0; for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){ if( pLoop->prereq==0 + && (pTerm->wtFlags & TERM_VIRTUAL)==0 && sqlite3ExprIsTableConstant(pTerm->pExpr, pSrc->iCursor) ){ pPartial = sqlite3ExprAnd(pParse->db, pPartial, sqlite3ExprDup(pParse->db, pTerm->pExpr, 0)); @@ -1720,6 +1721,7 @@ static void constructAutomaticIndex( if( pPartial ){ iContinue = sqlite3VdbeMakeLabel(v); sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL); + pLoop->wsFlags |= WHERE_PARTIALIDX; } regRecord = sqlite3GetTempReg(pParse); sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0); @@ -2865,6 +2867,8 @@ static void explainOneScan( if( isSearch ){ zFmt = "PRIMARY KEY"; } + }else if( flags & WHERE_PARTIALIDX ){ + zFmt = "AUTOMATIC PARTIAL COVERING INDEX"; }else if( flags & WHERE_AUTO_INDEX ){ zFmt = "AUTOMATIC COVERING INDEX"; }else if( flags & WHERE_IDX_ONLY ){ diff --git a/src/whereInt.h b/src/whereInt.h index e9eb8b7dd..fd4cfdf88 100644 --- a/src/whereInt.h +++ b/src/whereInt.h @@ -459,3 +459,4 @@ struct WhereInfo { #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */ #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */ #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/ +#define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */ |