aboutsummaryrefslogtreecommitdiff
path: root/src/btree.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2017-01-23 16:56:18 +0000
committerdrh <drh@noemail.net>2017-01-23 16:56:18 +0000
commit6aabff38e95b9731fd37ca28ddad9a0d1dd036dd (patch)
treeaef8b33f038315355d678293569fdcce4b2ab202 /src/btree.c
parent65c4c0b02d4c7146659185d43815d6b99fc4df7b (diff)
parent7f11afaba17fdc24ef01775613e4052a4100bbcf (diff)
downloadsqlite-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.c23
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;
+ }
+ }
+ }
}
}