diff options
author | drh <drh@noemail.net> | 2014-06-18 15:11:54 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2014-06-18 15:11:54 +0000 |
commit | f9944b5053632fd64457f87a49d500c8114082a1 (patch) | |
tree | 97902ad157a23f30606b87d33adeb6b35c6eb008 /src/where.c | |
parent | ef3ad02d90eb16c51c3f0baa81b3976b6b60f1d2 (diff) | |
parent | dabe36d9dd98f9daea843606b22cd0af9cdcfbaa (diff) | |
download | sqlite-f9944b5053632fd64457f87a49d500c8114082a1.tar.gz sqlite-f9944b5053632fd64457f87a49d500c8114082a1.zip |
Prevent an automatic index from taking the place of a declared index.
FossilOrigin-Name: 0a52bddd9db49b2b79fc24888b50023d0fe74f7b
Diffstat (limited to 'src/where.c')
-rw-r--r-- | src/where.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/where.c b/src/where.c index 1865871ed..fd5831872 100644 --- a/src/where.c +++ b/src/where.c @@ -3923,6 +3923,17 @@ static WhereLoop **whereLoopFindLesser( ** rSetup. Call this SETUP-INVARIANT */ assert( p->rSetup>=pTemplate->rSetup ); + /* Any loop using an appliation-defined index (or PRIMARY KEY or + ** UNIQUE constraint) with one or more == constraints is better + ** than an automatic index. */ + if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 + && (pTemplate->wsFlags & WHERE_INDEXED)!=0 + && (pTemplate->wsFlags & WHERE_COLUMN_EQ)!=0 + && (p->prereq & pTemplate->prereq)==pTemplate->prereq + ){ + break; + } + /* If existing WhereLoop p is better than pTemplate, pTemplate can be ** discarded. WhereLoop p is better if: ** (1) p has no more dependencies than pTemplate, and @@ -4047,7 +4058,7 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){ WhereLoop *pToDel; while( *ppTail ){ ppTail = whereLoopFindLesser(ppTail, pTemplate); - if( NEVER(ppTail==0) ) break; + if( ppTail==0 ) break; pToDel = *ppTail; if( pToDel==0 ) break; *ppTail = pToDel->pNextLoop; |