From d3627afc47501b122f8615da3a98a71c6d71eb42 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 18 Dec 2006 18:34:51 +0000 Subject: [PATCH] Speed improvement: do not journal or rollback pages that are pulled out of the freelist. (CVS 3531) FossilOrigin-Name: 4dffc4c3c9c4ccc024669cec204c68e953333563 --- manifest | 14 ++++++------- manifest.uuid | 2 +- src/btree.c | 56 ++++++++++++++++++++++++++++++--------------------- src/pager.c | 6 ++++-- 4 files changed, 45 insertions(+), 33 deletions(-) diff --git a/manifest b/manifest index 662d4ac1b1..7d23bc1234 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Updates\sto\sthe\s"Distinctive\sFeatures"\sdocument.\s(CVS\s3530) -D 2006-12-18T14:12:21 +C Speed\simprovement:\sdo\snot\sjournal\sor\srollback\spages\sthat\sare\spulled\sout\sof\nthe\sfreelist.\s(CVS\s3531) +D 2006-12-18T18:34:51 F Makefile.in 8e14898d41a53033ecb687d93c9cd5d109fb9ae3 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -57,7 +57,7 @@ F src/alter.c 2c79ec40f65e33deaf90ca493422c74586e481a3 F src/analyze.c 7d2b7ab9a9c2fd6e55700f69064dfdd3e36d7a8a F src/attach.c b11eb4d5d3fb99a10a626956bccc7215f6b68b16 F src/auth.c 902f4722661c796b97f007d9606bd7529c02597f -F src/btree.c 116f748ee11ba4d3630882102e99b60ff58d2a84 +F src/btree.c e7d1694ad0844918e20b802a249533789bf811dc F src/btree.h 061c50e37de7f50b58528e352d400cf33ead7418 F src/build.c 02aedde724dc73295d6e9b8dc29afb5dd38de507 F src/callback.c fd9bb39f7ff6b52bad8365617abc61c720640429 @@ -85,7 +85,7 @@ F src/os_unix.c d3b6b66b79777c9177d76bd5c68c227978c4593c F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e F src/os_win.c cac5f9b60faacd46874aa8dfefdb7dc4d0437ff9 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b -F src/pager.c 18c9cb43b3e740c63eaa13da41c52926012e4853 +F src/pager.c 814268d5bbd69f30069867142f1d460b8b7ab778 F src/pager.h 2e6d42f4ae004ae748a037b8468112b851c447a7 F src/parse.y 9b3d1c0f8af81fe0cc909baf226865baa725bb23 F src/pragma.c d0891d3504b6291b506a5ec2226bbf79ffcef003 @@ -423,7 +423,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 7393c81b8cb9d4344ae744de9eabcb3af64f1db8 -R 90435cd6f785c0f1944fcee4b97ba9dc +P c734585e1a801bec2d393d000c323ba842c2292d +R f4b3ee85fc3b4b1abd3912c81ea3b7d4 U drh -Z 785f3b918eb47031e16bc31d88bf41e9 +Z b8975ee2a0ac067044f47c4bbda872fe diff --git a/manifest.uuid b/manifest.uuid index c9066fcb7d..5cb5c9a939 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c734585e1a801bec2d393d000c323ba842c2292d \ No newline at end of file +4dffc4c3c9c4ccc024669cec204c68e953333563 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 7324b37fd6..608f5e2543 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.331 2006/11/30 13:05:29 drh Exp $ +** $Id: btree.c,v 1.332 2006/12/18 18:34:51 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to @@ -421,7 +421,8 @@ struct BtCursor { */ #if SQLITE_TEST # define TRACE(X) if( sqlite3_btree_trace )\ - { sqlite3DebugPrintf X; fflush(stdout); } +/* { sqlite3DebugPrintf X; fflush(stdout); } */ \ +{ printf X; fflush(stdout); } int sqlite3_btree_trace=0; /* True to enable tracing */ #else # define TRACE(X) @@ -3569,14 +3570,14 @@ static int allocatePage( int rc; int n; /* Number of pages on the freelist */ int k; /* Number of leaves on the trunk of the freelist */ + MemPage *pTrunk = 0; + MemPage *pPrevTrunk = 0; pPage1 = pBt->pPage1; n = get4byte(&pPage1->aData[36]); if( n>0 ){ /* There are pages on the freelist. Reuse one of those pages. */ - MemPage *pTrunk = 0; Pgno iTrunk; - MemPage *pPrevTrunk = 0; u8 searchList = 0; /* If the free-list must be searched for 'nearby' */ /* If the 'exact' parameter was true and a query of the pointer-map @@ -3617,16 +3618,8 @@ static int allocatePage( } rc = getPage(pBt, iTrunk, &pTrunk); if( rc ){ - releasePage(pPrevTrunk); - return rc; - } - - /* TODO: This should move to after the loop? */ - rc = sqlite3pager_write(pTrunk->aData); - if( rc ){ - releasePage(pTrunk); - releasePage(pPrevTrunk); - return rc; + pTrunk = 0; + goto end_allocate_page; } k = get4byte(&pTrunk->aData[4]); @@ -3635,6 +3628,10 @@ static int allocatePage( ** So extract the trunk page itself and use it as the newly ** allocated page */ assert( pPrevTrunk==0 ); + rc = sqlite3pager_write(pTrunk->aData); + if( rc ){ + goto end_allocate_page; + } *pPgno = iTrunk; memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4); *ppPage = pTrunk; @@ -3642,7 +3639,8 @@ static int allocatePage( TRACE(("ALLOCATE: %d trunk - %d free pages left\n", *pPgno, n-1)); }else if( k>pBt->usableSize/4 - 8 ){ /* Value of k is out of range. Database corruption */ - return SQLITE_CORRUPT_BKPT; + rc = SQLITE_CORRUPT_BKPT; + goto end_allocate_page; #ifndef SQLITE_OMIT_AUTOVACUUM }else if( searchList && nearby==iTrunk ){ /* The list is being searched and this trunk page is the page @@ -3651,6 +3649,10 @@ static int allocatePage( assert( *pPgno==iTrunk ); *ppPage = pTrunk; searchList = 0; + rc = sqlite3pager_write(pTrunk->aData); + if( rc ){ + goto end_allocate_page; + } if( k==0 ){ if( !pPrevTrunk ){ memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4); @@ -3666,26 +3668,26 @@ static int allocatePage( Pgno iNewTrunk = get4byte(&pTrunk->aData[8]); rc = getPage(pBt, iNewTrunk, &pNewTrunk); if( rc!=SQLITE_OK ){ - releasePage(pTrunk); - releasePage(pPrevTrunk); - return rc; + goto end_allocate_page; } rc = sqlite3pager_write(pNewTrunk->aData); if( rc!=SQLITE_OK ){ releasePage(pNewTrunk); - releasePage(pTrunk); - releasePage(pPrevTrunk); - return rc; + goto end_allocate_page; } memcpy(&pNewTrunk->aData[0], &pTrunk->aData[0], 4); put4byte(&pNewTrunk->aData[4], k-1); memcpy(&pNewTrunk->aData[8], &pTrunk->aData[12], (k-1)*4); + releasePage(pNewTrunk); if( !pPrevTrunk ){ put4byte(&pPage1->aData[32], iNewTrunk); }else{ + rc = sqlite3pager_write(pPrevTrunk->aData); + if( rc ){ + goto end_allocate_page; + } put4byte(&pPrevTrunk->aData[0], iNewTrunk); } - releasePage(pNewTrunk); } pTrunk = 0; TRACE(("ALLOCATE: %d trunk - %d free pages left\n", *pPgno, n-1)); @@ -3695,6 +3697,10 @@ static int allocatePage( int closest; Pgno iPage; unsigned char *aData = pTrunk->aData; + rc = sqlite3pager_write(aData); + if( rc ){ + goto end_allocate_page; + } if( nearby>0 ){ int i, dist; closest = 0; @@ -3738,8 +3744,8 @@ static int allocatePage( } } releasePage(pPrevTrunk); + pPrevTrunk = 0; }while( searchList ); - releasePage(pTrunk); }else{ /* There are no pages on the freelist, so create a new page at the ** end of the file */ @@ -3768,6 +3774,10 @@ static int allocatePage( } assert( *pPgno!=PENDING_BYTE_PAGE(pBt) ); + +end_allocate_page: + releasePage(pTrunk); + releasePage(pPrevTrunk); return rc; } diff --git a/src/pager.c b/src/pager.c index 7e0293d594..ffadb59d37 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.276 2006/11/23 11:58:44 drh Exp $ +** @(#) $Id: pager.c,v 1.277 2006/12/18 18:34:51 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -31,6 +31,7 @@ ** Macros for troubleshooting. Normally turned off */ #if 0 +#define sqlite3DebugPrintf printf #define TRACE1(X) sqlite3DebugPrintf(X) #define TRACE2(X,Y) sqlite3DebugPrintf(X,Y) #define TRACE3(X,Y,Z) sqlite3DebugPrintf(X,Y,Z) @@ -3335,7 +3336,8 @@ void sqlite3pager_dont_rollback(void *pData){ PgHdr *pPg = DATA_TO_PGHDR(pData); Pager *pPager = pPg->pPager; - if( pPager->state!=PAGER_EXCLUSIVE || pPager->journalOpen==0 ) return; + assert( pPager->state>=PAGER_RESERVED ); + if( pPager->journalOpen==0 ) return; if( pPg->alwaysRollback || pPager->alwaysRollback || MEMDB ) return; if( !pPg->inJournal && (int)pPg->pgno <= pPager->origDbSize ){ assert( pPager->aInJournal!=0 ); -- 2.47.2