From: drh Date: Sat, 21 Jan 2017 21:47:54 +0000 (+0000) Subject: A better implementation of the moveto-neighbor optimization that checks for X-Git-Tag: version-3.17.0~82^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7f11afaba17fdc24ef01775613e4052a4100bbcf;p=thirdparty%2Fsqlite.git A better implementation of the moveto-neighbor optimization that checks for nearby rows on adjacent pages. FossilOrigin-Name: 2c4ecb85a475b9063aa8a3bb517ac181a7ded649 --- diff --git a/manifest b/manifest index cbd159d22a..95352ee96a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C B-tree\soptimization:\s\sWhen\sseeking\son\sa\srowid\stable\sthat\shas\salready\sbeen\npositioned,\scheck\sto\ssee\sif\sthe\snew\srow\shappens\sto\sbe\sthe\snext\srow\son\sthe\nsame\sleaf\spage.\s\sThat\sis\sa\sreasonably\scommon\scase,\sand\sif\sit\sis\strue\sit\navoids\sa\sfull\sbinary\ssearch. -D 2017-01-21T16:54:19.338 +C A\sbetter\simplementation\sof\sthe\smoveto-neighbor\soptimization\sthat\schecks\sfor\nnearby\srows\son\sadjacent\spages. +D 2017-01-21T21:47:54.621 F Makefile.in 41bd4cad981487345c4a84081074bcdb876e4b2e F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da @@ -333,7 +333,7 @@ F src/auth.c 930b376a9c56998557367e6f7f8aaeac82a2a792 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 F src/btmutex.c 0e9ce2d56159b89b9bc8e197e023ee11e39ff8ca -F src/btree.c 972b7e1346eb2f4369cf8cc43117c728e2bd9cd4 +F src/btree.c f1b36bcfb1f9532ce64fe534153f11b8e2595d8b F src/btree.h e6d352808956ec163a17f832193a3e198b3fb0ac F src/btreeInt.h 10c4b77c2fb399580babbcc7cf652ac10dba796e F src/build.c 9e799f1edd910dfa8a0bc29bd390d35d310596af @@ -1547,7 +1547,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 347df3c1fd7322e7aacaf1e9f8be81830947c482 -R 3888200d85fb0a6e771ec0a3c9f2e5a8 +P 8e5cfb2039126da7689c4b1c88760f10e1234eaf +R 9f1865839aca85688e5829c506350f09 U drh -Z 4b0826cf6fb92296cc5aa9f45d953141 +Z fbf63ba541a6f5ec3e59c684016e63a0 diff --git a/manifest.uuid b/manifest.uuid index ac357ef297..478c310b27 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8e5cfb2039126da7689c4b1c88760f10e1234eaf \ No newline at end of file +2c4ecb85a475b9063aa8a3bb517ac181a7ded649 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 8b095b57b0..b6bc66ea85 100644 --- a/src/btree.c +++ b/src/btree.c @@ -5096,14 +5096,19 @@ int sqlite3BtreeMovetoUnpacked( *pRes = -1; return SQLITE_OK; } - if( pCur->aiIdx[pCur->iPage]+1apPage[pCur->iPage]->nCell ){ - pCur->aiIdx[pCur->iPage]++; - pCur->info.nSize = 0; - pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl); - getCellInfo(pCur); - if( pCur->info.nKey==intKey ){ - *pRes = 0; - 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; + } } } }