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

Factor the saveAllCursors() routine of btree.c into two separate routines,

for a noticable performance improvement.

FossilOrigin-Name: 3eb084390382c108e9b0ff0b29dede58ebb149bc
This commit is contained in:
drh
2014-08-22 22:26:07 +00:00
parent 75e2a2d362
commit 637f3d83b9
3 changed files with 38 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
C Performance\senhancements\sin\sthe\sb-tree\smutex\slogic. C Factor\sthe\ssaveAllCursors()\sroutine\sof\sbtree.c\sinto\stwo\sseparate\sroutines,\nfor\sa\snoticable\sperformance\simprovement.
D 2014-08-22T21:58:10.354 D 2014-08-22T22:26:07.834
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -168,7 +168,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
F src/backup.c a31809c65623cc41849b94d368917f8bb66e6a7e F src/backup.c a31809c65623cc41849b94d368917f8bb66e6a7e
F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb
F src/btmutex.c ec9d3f1295dafeb278c3830211cc5584132468f4 F src/btmutex.c ec9d3f1295dafeb278c3830211cc5584132468f4
F src/btree.c 4195fed5741b4dbcc9831b623aec487258f3e62d F src/btree.c 776885dfef3033af7e8eabbf004481f219870a1d
F src/btree.h 4245a349bfe09611d7ff887dbc3a80cee8b7955a F src/btree.h 4245a349bfe09611d7ff887dbc3a80cee8b7955a
F src/btreeInt.h cf180d86b2e9e418f638d65baa425c4c69c0e0e3 F src/btreeInt.h cf180d86b2e9e418f638d65baa425c4c69c0e0e3
F src/build.c 058e3aadb1376521ff291735237edf4c10f438fb F src/build.c 058e3aadb1376521ff291735237edf4c10f438fb
@@ -1188,7 +1188,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 6bcf1af6a48dbda5ac6f6b3b02810bdfc4730000 P 8914530644f938a7a98e25ea1fb0bca1f9d79101
R 24d5ffe2f1d9679a613707454c70f45a R 036983fb95199f1ba06f1397f389a453
U drh U drh
Z 6801ae93f83fb9ed7a247305de8bd03a Z 9ea20fed62648c22294e9e322338cabb

View File

@@ -1 +1 @@
8914530644f938a7a98e25ea1fb0bca1f9d79101 3eb084390382c108e9b0ff0b29dede58ebb149bc

View File

@@ -629,16 +629,42 @@ static int saveCursorPosition(BtCursor *pCur){
return rc; return rc;
} }
/* Forward reference */
static int SQLITE_NOINLINE saveCursorsOnList(BtCursor*,Pgno,BtCursor*);
/* /*
** Save the positions of all cursors (except pExcept) that are open on ** Save the positions of all cursors (except pExcept) that are open on
** the table with root-page iRoot. Usually, this is called just before cursor ** the table with root-page iRoot. "Saving the cursor position" means that
** pExcept is used to modify the table (BtreeDelete() or BtreeInsert()). ** the location in the btree is remembered in such a way that it can be
** moved back to the same spot after the btree has been modified. This
** routine is called just before cursor pExcept is used to modify the
** table, for example in BtreeDelete() or BtreeInsert().
**
** Implementation note: This routine merely checks to see if any cursors
** need to be saved. It calls out to saveCursorsOnList() in the (unusual)
** event that cursors are in need to being saved.
*/ */
static int saveAllCursors(BtShared *pBt, Pgno iRoot, BtCursor *pExcept){ static int saveAllCursors(BtShared *pBt, Pgno iRoot, BtCursor *pExcept){
BtCursor *p;
assert( sqlite3_mutex_held(pBt->mutex) ); assert( sqlite3_mutex_held(pBt->mutex) );
assert( pExcept==0 || pExcept->pBt==pBt ); assert( pExcept==0 || pExcept->pBt==pBt );
BtCursor *p;
for(p=pBt->pCursor; p; p=p->pNext){ for(p=pBt->pCursor; p; p=p->pNext){
if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ) break;
}
return p ? saveCursorsOnList(p, iRoot, pExcept) : SQLITE_OK;
}
/* This helper routine to saveAllCursors does the actual work of saving
** the cursors if and when a cursor is found that actually requires saving.
** The common case is that no cursors need to be saved, so this routine is
** broken out from its caller to avoid unnecessary stack pointer movement.
*/
static int SQLITE_NOINLINE saveCursorsOnList(
BtCursor *p, /* The first cursor that needs saving */
Pgno iRoot, /* Only save cursor with this iRoot. Save all if zero */
BtCursor *pExcept /* Do not save this cursor */
){
do{
if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ){ if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ){
if( p->eState==CURSOR_VALID ){ if( p->eState==CURSOR_VALID ){
int rc = saveCursorPosition(p); int rc = saveCursorPosition(p);
@@ -650,7 +676,8 @@ static int saveAllCursors(BtShared *pBt, Pgno iRoot, BtCursor *pExcept){
btreeReleaseAllCursorPages(p); btreeReleaseAllCursorPages(p);
} }
} }
} p = p->pNext;
}while( p );
return SQLITE_OK; return SQLITE_OK;
} }