diff options
author | drh <drh@noemail.net> | 2016-06-08 18:07:21 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2016-06-08 18:07:21 +0000 |
commit | 8dc570b6afac593f029a67640ab916278af1ca65 (patch) | |
tree | 4d6a195a8041206b248fd273ca16ce8ae82b72f9 /src | |
parent | b9f3f6b672b4dbf11617e0d9872e36773f72e9a6 (diff) | |
download | sqlite-8dc570b6afac593f029a67640ab916278af1ca65.tar.gz sqlite-8dc570b6afac593f029a67640ab916278af1ca65.zip |
Prefer to use partial indexes for full table scans when that is possible.
FossilOrigin-Name: fe1874321ba31cec9ae65387920c33d8d0178ed8
Diffstat (limited to 'src')
-rw-r--r-- | src/build.c | 7 | ||||
-rw-r--r-- | src/where.c | 1 |
2 files changed, 5 insertions, 3 deletions
diff --git a/src/build.c b/src/build.c index a5931954a..c32195f65 100644 --- a/src/build.c +++ b/src/build.c @@ -3434,10 +3434,11 @@ void sqlite3DefaultRowEst(Index *pIdx){ int i; /* Set the first entry (number of rows in the index) to the estimated - ** number of rows in the table. Or 10, if the estimated number of rows - ** in the table is less than that. */ + ** number of rows in the table, or half the number of rows in the table + ** for a partial index. But do not let the estimate drop below 10. */ a[0] = pIdx->pTable->nRowLogEst; - if( a[0]<33 ) a[0] = 33; assert( 33==sqlite3LogEst(10) ); + if( pIdx->pPartIdxWhere!=0 ) a[0] -= 10; assert( 10==sqlite3LogEst(2) ); + if( a[0]<33 ) a[0] = 33; assert( 33==sqlite3LogEst(10) ); /* Estimate that a[1] is 10, a[2] is 9, a[3] is 8, a[4] is 7, a[5] is ** 6 and each subsequent value (if any) is 5. */ diff --git a/src/where.c b/src/where.c index 04d0b0190..e5a476c00 100644 --- a/src/where.c +++ b/src/where.c @@ -2761,6 +2761,7 @@ static int whereLoopAddBtree( /* Full scan via index */ if( b || !HasRowid(pTab) + || pProbe->pPartIdxWhere!=0 || ( m==0 && pProbe->bUnordered==0 && (pProbe->szIdxRow<pTab->szTabRow) |