diff options
author | drh <drh@noemail.net> | 2017-01-23 16:56:18 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2017-01-23 16:56:18 +0000 |
commit | 6aabff38e95b9731fd37ca28ddad9a0d1dd036dd (patch) | |
tree | aef8b33f038315355d678293569fdcce4b2ab202 /src/btree.c | |
parent | 65c4c0b02d4c7146659185d43815d6b99fc4df7b (diff) | |
parent | 7f11afaba17fdc24ef01775613e4052a4100bbcf (diff) | |
download | sqlite-6aabff38e95b9731fd37ca28ddad9a0d1dd036dd.tar.gz sqlite-6aabff38e95b9731fd37ca28ddad9a0d1dd036dd.zip |
Optimization: Try to avoid unnecessary btree searching when repositioning
a cursor to the next row.
FossilOrigin-Name: ee793d30c1dc1f78f49e6230d17750eceedbd8ed
Diffstat (limited to 'src/btree.c')
-rw-r--r-- | src/btree.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/btree.c b/src/btree.c index fb0565591..b6bc66ea8 100644 --- a/src/btree.c +++ b/src/btree.c @@ -5091,9 +5091,26 @@ int sqlite3BtreeMovetoUnpacked( *pRes = 0; return SQLITE_OK; } - if( (pCur->curFlags & BTCF_AtLast)!=0 && pCur->info.nKey<intKey ){ - *pRes = -1; - return SQLITE_OK; + if( pCur->info.nKey<intKey ){ + if( (pCur->curFlags & BTCF_AtLast)!=0 ){ + *pRes = -1; + return SQLITE_OK; + } + /* If the requested key is one more than the previous key, then + ** try to get there using sqlite3BtreeNext() rather than a full + ** binary search. This is an optimization only. The correct answer + ** is still obtained without this ase, only a little more slowely */ + if( pCur->info.nKey+1==intKey && !pCur->skipNext ){ + *pRes = 0; + rc = sqlite3BtreeNext(pCur, pRes); + if( rc ) return rc; + if( *pRes==0 ){ + getCellInfo(pCur); + if( pCur->info.nKey==intKey ){ + return SQLITE_OK; + } + } + } } } |