diff options
author | drh <drh@noemail.net> | 2014-06-17 20:16:43 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2014-06-17 20:16:43 +0000 |
commit | dabe36d9dd98f9daea843606b22cd0af9cdcfbaa (patch) | |
tree | 1ac7ec875190875ec78765ece708ee220f6edcf1 /src | |
parent | 2daa64cd631078a0c3c01be1c857de4d2eea1b28 (diff) | |
download | sqlite-dabe36d9dd98f9daea843606b22cd0af9cdcfbaa.tar.gz sqlite-dabe36d9dd98f9daea843606b22cd0af9cdcfbaa.zip |
Prevent an automatic index from taking the place of a declared index.
FossilOrigin-Name: 4ece839d445ff578a449a339ab579a32e64c9d28
Diffstat (limited to 'src')
-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 5fd4618bb..20100662a 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; |