From: drh Date: Sat, 21 Jan 2017 16:54:19 +0000 (+0000) Subject: B-tree optimization: When seeking on a rowid table that has already been X-Git-Tag: version-3.17.0~82^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=451e76d5b594d48d3450057ac542c7635b74b021;p=thirdparty%2Fsqlite.git B-tree optimization: When seeking on a rowid table that has already been positioned, check to see if the new row happens to be the next row on the same leaf page. That is a reasonably common case, and if it is true it avoids a full binary search. FossilOrigin-Name: 8e5cfb2039126da7689c4b1c88760f10e1234eaf --- diff --git a/manifest b/manifest index 334c7a3604..cbd159d22a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\ssqlite3_blob_reopen()\sto\scall\ssqlite3VdbeExec()\sdirectly\srather\sthan\ngoing\sthrough\ssqlite3_step().\s\sPerformance\senhancement. -D 2017-01-21T16:27:56.517 +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 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 e6b8f39d7dd1ad65f1747956de36f2595172a23d +F src/btree.c 972b7e1346eb2f4369cf8cc43117c728e2bd9cd4 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 0d1ad13a296b22d6fe36879b56f99bd6af1acd3a -R 6bebf342d641742884692400aca75850 +P 347df3c1fd7322e7aacaf1e9f8be81830947c482 +R 3888200d85fb0a6e771ec0a3c9f2e5a8 U drh -Z fb104ae24cf906c93b7fa008d273f235 +Z 4b0826cf6fb92296cc5aa9f45d953141 diff --git a/manifest.uuid b/manifest.uuid index 56e58c0ea3..ac357ef297 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -347df3c1fd7322e7aacaf1e9f8be81830947c482 \ No newline at end of file +8e5cfb2039126da7689c4b1c88760f10e1234eaf \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index fb05655912..8b095b57b0 100644 --- a/src/btree.c +++ b/src/btree.c @@ -5091,9 +5091,21 @@ int sqlite3BtreeMovetoUnpacked( *pRes = 0; return SQLITE_OK; } - if( (pCur->curFlags & BTCF_AtLast)!=0 && pCur->info.nKeyinfo.nKeycurFlags & BTCF_AtLast)!=0 ){ + *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; + } + } } }