1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Bias the b-tree binary search toward the high end. The common case is to

append data and this heuristic makes append run much faster because there
are fewer comparisons. (CVS 3740)

FossilOrigin-Name: a9877f616b24737152627841fcbd80cc28426f1e
This commit is contained in:
drh
2007-03-29 04:43:26 +00:00
parent b7bac72350
commit f1d68b3096
3 changed files with 14 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
C Get\sLEMON\sworking\sagain\swhen\sYYSTACKDEPTH\sis\sgreater\sthan\szero.\s(CVS\s3739)
D 2007-03-29T02:26:46
C Bias\sthe\sb-tree\sbinary\ssearch\stoward\sthe\shigh\send.\s\sThe\scommon\scase\sis\sto\nappend\sdata\sand\sthis\sheuristic\smakes\sappend\srun\smuch\sfaster\sbecause\sthere\nare\sfewer\scomparisons.\s(CVS\s3740)
D 2007-03-29T04:43:26
F Makefile.in 1fe3d0b46e40fd684e1e61f8e8056cefed16de9f
F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -58,7 +58,7 @@ F src/alter.c 2c79ec40f65e33deaf90ca493422c74586e481a3
F src/analyze.c 7d2b7ab9a9c2fd6e55700f69064dfdd3e36d7a8a
F src/attach.c a16ada4a4654a0d126b8223ec9494ebb81bc5c3c
F src/auth.c 902f4722661c796b97f007d9606bd7529c02597f
F src/btree.c 27e62fc50dba2ac0b4210402804ac12321ad8e59
F src/btree.c 434a3584766e85ca3b23d37adb9c457d83f5cf19
F src/btree.h 066444ee25bd6e6accb997bfd2cf5ace14dbcd00
F src/build.c d178bd7c8117f5f47694da9a0d5f336e85528180
F src/callback.c 31d22b4919c7645cbcbb1591ce2453e8c677c558
@@ -442,7 +442,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 06719b741ab1a2df0371f6d587563cc81eb8880a
R 611325e102e7d55f3c74217e92a2ccd7
P e72c81dbb309709462e49c4e3e90c3e16ead1265
R 2f8c0ebcc5b977db1cd11a734857a630
U drh
Z 7e0dc044f836d78b033cd61334a03256
Z f092376d9c3cfc91e80b8841598ffc58

View File

@@ -1 +1 @@
e72c81dbb309709462e49c4e3e90c3e16ead1265
a9877f616b24737152627841fcbd80cc28426f1e

View File

@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.343 2007/03/27 14:05:23 drh Exp $
** $Id: btree.c,v 1.344 2007/03/29 04:43:26 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
@@ -3305,12 +3305,10 @@ int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
*/
int sqlite3BtreeMoveto(BtCursor *pCur, const void *pKey, i64 nKey, int *pRes){
int rc;
int tryRightmost;
rc = moveToRoot(pCur);
if( rc ) return rc;
assert( pCur->pPage );
assert( pCur->pPage->isInit );
tryRightmost = pCur->pPage->intKey;
if( pCur->eState==CURSOR_INVALID ){
*pRes = -1;
assert( pCur->pPage->nCell==0 );
@@ -3326,16 +3324,13 @@ int sqlite3BtreeMoveto(BtCursor *pCur, const void *pKey, i64 nKey, int *pRes){
if( !pPage->intKey && pKey==0 ){
return SQLITE_CORRUPT_BKPT;
}
while( lwr<=upr ){
pCur->idx = upr;
if( lwr<=upr ) for(;;){
void *pCellKey;
i64 nCellKey;
pCur->idx = (lwr+upr)/2;
pCur->info.nSize = 0;
if( pPage->intKey ){
u8 *pCell;
if( tryRightmost ){
pCur->idx = upr;
}
pCell = findCell(pPage, pCur->idx) + pPage->childPtrSize;
if( pPage->hasData ){
u32 dummy;
@@ -3346,7 +3341,6 @@ int sqlite3BtreeMoveto(BtCursor *pCur, const void *pKey, i64 nKey, int *pRes){
c = -1;
}else if( nCellKey>nKey ){
c = +1;
tryRightmost = 0;
}else{
c = 0;
}
@@ -3380,6 +3374,10 @@ int sqlite3BtreeMoveto(BtCursor *pCur, const void *pKey, i64 nKey, int *pRes){
}else{
upr = pCur->idx-1;
}
if( lwr>upr ){
break;
}
pCur->idx = (lwr+upr)/2;
}
assert( lwr==upr+1 );
assert( pPage->isInit );