1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Progress toward using the iScanRatio information on indices. Many tests

are still failing.

FossilOrigin-Name: 6c352edbba85a15ca356b5e131f4b3b2723d1774
This commit is contained in:
drh
2013-10-04 02:36:19 +00:00
parent c28c4e5009
commit d9e3cad2f8
7 changed files with 52 additions and 57 deletions

View File

@@ -4597,13 +4597,7 @@ int sqlite3Select(
sqlite3CodeVerifySchema(pParse, iDb);
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
/* Search for the index that has the least amount of columns. If
** there is such an index, and it has less columns than the table
** does, then we can assume that it consumes less space on disk and
** will therefore be cheaper to scan to determine the query result.
** In this case set iRoot to the root page number of the index b-tree
** and pKeyInfo to the KeyInfo structure required to navigate the
** index.
/* Search for the index that has the lowest scan cost.
**
** (2011-04-15) Do not do a full scan of an unordered index.
**
@@ -4611,11 +4605,14 @@ int sqlite3Select(
** passed to keep OP_OpenRead happy.
*/
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
if( pIdx->bUnordered==0 && (!pBest || pIdx->nColumn<pBest->nColumn) ){
if( pIdx->bUnordered==0
&& pIdx->iScanRatio<128
&& (!pBest || pIdx->iScanRatio<pBest->iScanRatio)
){
pBest = pIdx;
}
}
if( pBest && pBest->nColumn<pTab->nCol ){
if( pBest ){
iRoot = pBest->tnum;
pKeyInfo = sqlite3IndexKeyinfo(pParse, pBest);
}