diff options
author | drh <> | 2021-11-30 14:07:58 +0000 |
---|---|---|
committer | drh <> | 2021-11-30 14:07:58 +0000 |
commit | c1085ea412b5c78d58cad59273d71f44d39843c5 (patch) | |
tree | 646c526794e8e18595816348e964c7aa7fd6afc1 /src | |
parent | 78679a49505616c39366afab2c531162383c9eb8 (diff) | |
download | sqlite-c1085ea412b5c78d58cad59273d71f44d39843c5.tar.gz sqlite-c1085ea412b5c78d58cad59273d71f44d39843c5.zip |
In the automatic index generator logic, be more precise about when a
partial automatic index is allowed in order to capture more cases where it
is legal to use a partial automatic index.
FossilOrigin-Name: 664b461bb5063d98047fc2e51a3827235cd9f55ca2e23cb66e719eac53fb5437
Diffstat (limited to 'src')
-rw-r--r-- | src/where.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/where.c b/src/where.c index 7a8342675..54e4ea819 100644 --- a/src/where.c +++ b/src/where.c @@ -791,13 +791,13 @@ static void constructAutomaticIndex( idxCols = 0; for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){ Expr *pExpr = pTerm->pExpr; - assert( !ExprHasProperty(pExpr, EP_FromJoin) /* prereq always non-zero */ - || pExpr->iRightJoinTable!=pSrc->iCursor /* for the right-hand */ - || pLoop->prereq!=0 ); /* table of a LEFT JOIN */ - if( pLoop->prereq==0 - && (pTerm->wtFlags & TERM_VIRTUAL)==0 - && !ExprHasProperty(pExpr, EP_FromJoin) - && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) ){ + /* Make the automatic index a partial index if there are terms in the + ** WHERE clause (or the ON clause of a LEFT join) that constrain which + ** rows of the target table (pSrc) that can be used. */ + if( (pTerm->wtFlags & TERM_VIRTUAL)==0 + && ((pSrc->fg.jointype&JT_LEFT)==0 || ExprHasProperty(pExpr,EP_FromJoin)) + && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) + ){ pPartial = sqlite3ExprAnd(pParse, pPartial, sqlite3ExprDup(pParse->db, pExpr, 0)); } |