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

Reduce the number of "#ifndef SQLITE_OMIT_AUTOVACUUM" conditions in btree.c by using the ISAUTOVACUUM macro instead. (CVS 5444)

FossilOrigin-Name: a560c61849cb669ab03ba4a63b23369db234f329
This commit is contained in:
danielk1977
2008-07-19 14:25:15 +00:00
parent b27475ba75
commit 85d90ca7a7
3 changed files with 28 additions and 51 deletions

View File

@@ -1,5 +1,5 @@
C To\sensure\sSQLITE_THREADSAFE\sis\salways\sdefined,\shave\stest_mutex.c\sinclude\ssqliteInt.h.\s(CVS\s5443) C Reduce\sthe\snumber\sof\s"#ifndef\sSQLITE_OMIT_AUTOVACUUM"\sconditions\sin\sbtree.c\sby\susing\sthe\sISAUTOVACUUM\smacro\sinstead.\s(CVS\s5444)
D 2008-07-19T13:43:24 D 2008-07-19T14:25:16
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in a03f7cb4f7ad50bc53a788c6c544430e81f95de4 F Makefile.in a03f7cb4f7ad50bc53a788c6c544430e81f95de4
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -96,7 +96,7 @@ F src/attach.c b18ba42c77f7d3941f5d23d2ca20fa1d841a4e91
F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627 F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
F src/bitvec.c 95c86bd18d8fedf0533f5af196192546e10a7e7d F src/bitvec.c 95c86bd18d8fedf0533f5af196192546e10a7e7d
F src/btmutex.c 709cad2cdca0afd013f0f612363810e53f59ec53 F src/btmutex.c 709cad2cdca0afd013f0f612363810e53f59ec53
F src/btree.c 7303414d1afc4c56c8e16eb530fbd902c1243fbc F src/btree.c 1318ab0eaad158aad791d73611c1c63c9b5e981f
F src/btree.h 03256ed7ee42b5ecacbe887070b0f8249e7d069d F src/btree.h 03256ed7ee42b5ecacbe887070b0f8249e7d069d
F src/btreeInt.h 6e4cb69a9192a8d609c27034ae5f921cf0ecdde1 F src/btreeInt.h 6e4cb69a9192a8d609c27034ae5f921cf0ecdde1
F src/build.c bac7233d984be3805aaa41cf500f7ee12dc97249 F src/build.c bac7233d984be3805aaa41cf500f7ee12dc97249
@@ -608,7 +608,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P 9992b1aecdbbc7a260f00cb6ef78b500aeab22df P d8be91e2d2737dcb0e82e6c8a6a3f4827bc98d63
R 615c9acc5406836f8f320d7701ad2533 R 62e45d7b8ed334b4b86371bb551b8bcf
U danielk1977 U danielk1977
Z 549920f4a7d84d25c74c12bb9c25624e Z 4b754cdd81d101220a03014dfb941ae8

View File

@@ -1 +1 @@
d8be91e2d2737dcb0e82e6c8a6a3f4827bc98d63 a560c61849cb669ab03ba4a63b23369db234f329

View File

@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give. ** May you share freely, never taking more than you give.
** **
************************************************************************* *************************************************************************
** $Id: btree.c,v 1.490 2008/07/19 11:49:07 danielk1977 Exp $ ** $Id: btree.c,v 1.491 2008/07/19 14:25:16 danielk1977 Exp $
** **
** This file implements a external (disk-based) database using BTrees. ** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information. ** See the header comment on "btreeInt.h" for additional information.
@@ -507,7 +507,11 @@ static int ptrmapGet(BtShared *pBt, Pgno key, u8 *pEType, Pgno *pPgno){
return SQLITE_OK; return SQLITE_OK;
} }
#endif /* SQLITE_OMIT_AUTOVACUUM */ #else /* if defined SQLITE_OMIT_AUTOVACUUM */
#define ptrmapPut(w,x,y,z) SQLITE_OK
#define ptrmapGet(w,x,y,z) SQLITE_OK
#define ptrmapPutOvfl(y,z) SQLITE_OK
#endif
/* /*
** Given a btree page and a cell index (0 means the first cell on ** Given a btree page and a cell index (0 means the first cell on
@@ -4283,15 +4287,13 @@ static int freePage(MemPage *pPage){
memset(pPage->aData, 0, pPage->pBt->pageSize); memset(pPage->aData, 0, pPage->pBt->pageSize);
#endif #endif
#ifndef SQLITE_OMIT_AUTOVACUUM
/* If the database supports auto-vacuum, write an entry in the pointer-map /* If the database supports auto-vacuum, write an entry in the pointer-map
** to indicate that the page is free. ** to indicate that the page is free.
*/ */
if( pBt->autoVacuum ){ if( ISAUTOVACUUM ){
rc = ptrmapPut(pBt, pPage->pgno, PTRMAP_FREEPAGE, 0); rc = ptrmapPut(pBt, pPage->pgno, PTRMAP_FREEPAGE, 0);
if( rc ) return rc; if( rc ) return rc;
} }
#endif
if( n==0 ){ if( n==0 ){
/* This is the first free page */ /* This is the first free page */
@@ -4560,8 +4562,7 @@ static int reparentPage(
sqlite3PagerUnref(pDbPage); sqlite3PagerUnref(pDbPage);
} }
#ifndef SQLITE_OMIT_AUTOVACUUM if( ISAUTOVACUUM && updatePtrmap ){
if( pBt->autoVacuum && updatePtrmap ){
return ptrmapPut(pBt, pgno, PTRMAP_BTREE, pNewParent->pgno); return ptrmapPut(pBt, pgno, PTRMAP_BTREE, pNewParent->pgno);
} }
@@ -4569,7 +4570,7 @@ static int reparentPage(
/* If the updatePtrmap flag was clear, assert that the entry in the /* If the updatePtrmap flag was clear, assert that the entry in the
** pointer-map is already correct. ** pointer-map is already correct.
*/ */
if( pBt->autoVacuum ){ if( ISAUTOVACUUM ){
u8 eType; u8 eType;
Pgno ii; Pgno ii;
ptrmapGet(pBt, pgno, &eType, &ii); ptrmapGet(pBt, pgno, &eType, &ii);
@@ -4577,7 +4578,6 @@ static int reparentPage(
} }
#endif #endif
#endif
return SQLITE_OK; return SQLITE_OK;
} }
@@ -4882,12 +4882,11 @@ static int balance_quick(MemPage *pPage, MemPage *pParent){
put4byte(findOverflowCell(pParent,parentIdx), pPage->pgno); put4byte(findOverflowCell(pParent,parentIdx), pPage->pgno);
put4byte(&pParent->aData[pParent->hdrOffset+8], pgnoNew); put4byte(&pParent->aData[pParent->hdrOffset+8], pgnoNew);
#ifndef SQLITE_OMIT_AUTOVACUUM
/* If this is an auto-vacuum database, update the pointer map /* If this is an auto-vacuum database, update the pointer map
** with entries for the new page, and any pointer from the ** with entries for the new page, and any pointer from the
** cell on the page to an overflow page. ** cell on the page to an overflow page.
*/ */
if( pBt->autoVacuum ){ if( ISAUTOVACUUM ){
rc = ptrmapPut(pBt, pgnoNew, PTRMAP_BTREE, pParent->pgno); rc = ptrmapPut(pBt, pgnoNew, PTRMAP_BTREE, pParent->pgno);
if( rc==SQLITE_OK ){ if( rc==SQLITE_OK ){
rc = ptrmapPutOvfl(pNew, 0); rc = ptrmapPutOvfl(pNew, 0);
@@ -4897,7 +4896,6 @@ static int balance_quick(MemPage *pPage, MemPage *pParent){
return rc; return rc;
} }
} }
#endif
/* Release the reference to the new page and balance the parent page, /* Release the reference to the new page and balance the parent page,
** in case the divider cell inserted caused it to become overfull. ** in case the divider cell inserted caused it to become overfull.
@@ -4969,9 +4967,7 @@ static int balance_nonroot(MemPage *pPage){
u8 *aCopy[NB]; /* Space for holding data of apCopy[] */ u8 *aCopy[NB]; /* Space for holding data of apCopy[] */
u8 *aSpace1; /* Space for copies of dividers cells before balance */ u8 *aSpace1; /* Space for copies of dividers cells before balance */
u8 *aSpace2 = 0; /* Space for overflow dividers cells after balance */ u8 *aSpace2 = 0; /* Space for overflow dividers cells after balance */
#ifndef SQLITE_OMIT_AUTOVACUUM
u8 *aFrom = 0; u8 *aFrom = 0;
#endif
assert( sqlite3_mutex_held(pPage->pBt->mutex) ); assert( sqlite3_mutex_held(pPage->pBt->mutex) );
@@ -5107,11 +5103,9 @@ static int balance_nonroot(MemPage *pPage){
} }
aSpace1 = &aCopy[NB-1][pBt->pageSize+ROUND8(sizeof(MemPage))]; aSpace1 = &aCopy[NB-1][pBt->pageSize+ROUND8(sizeof(MemPage))];
assert( ((aSpace1 - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */ assert( ((aSpace1 - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */
#ifndef SQLITE_OMIT_AUTOVACUUM if( ISAUTOVACUUM ){
if( pBt->autoVacuum ){
aFrom = &aSpace1[pBt->pageSize]; aFrom = &aSpace1[pBt->pageSize];
} }
#endif
aSpace2 = sqlite3PageMalloc(pBt->pageSize); aSpace2 = sqlite3PageMalloc(pBt->pageSize);
if( aSpace2==0 ){ if( aSpace2==0 ){
rc = SQLITE_NOMEM; rc = SQLITE_NOMEM;
@@ -5157,8 +5151,7 @@ static int balance_nonroot(MemPage *pPage){
assert( nCell<nMaxCells ); assert( nCell<nMaxCells );
apCell[nCell] = findOverflowCell(pOld, j); apCell[nCell] = findOverflowCell(pOld, j);
szCell[nCell] = cellSizePtr(pOld, apCell[nCell]); szCell[nCell] = cellSizePtr(pOld, apCell[nCell]);
#ifndef SQLITE_OMIT_AUTOVACUUM if( ISAUTOVACUUM ){
if( pBt->autoVacuum ){
int a; int a;
aFrom[nCell] = i; aFrom[nCell] = i;
for(a=0; a<pOld->nOverflow; a++){ for(a=0; a<pOld->nOverflow; a++){
@@ -5168,7 +5161,6 @@ static int balance_nonroot(MemPage *pPage){
} }
} }
} }
#endif
nCell++; nCell++;
} }
if( i<nOld-1 ){ if( i<nOld-1 ){
@@ -5190,11 +5182,9 @@ static int balance_nonroot(MemPage *pPage){
assert( iSpace1<=pBt->pageSize ); assert( iSpace1<=pBt->pageSize );
memcpy(pTemp, apDiv[i], sz); memcpy(pTemp, apDiv[i], sz);
apCell[nCell] = pTemp+leafCorrection; apCell[nCell] = pTemp+leafCorrection;
#ifndef SQLITE_OMIT_AUTOVACUUM if( ISAUTOVACUUM ){
if( pBt->autoVacuum ){
aFrom[nCell] = 0xFF; aFrom[nCell] = 0xFF;
} }
#endif
dropCell(pParent, nxDiv, sz); dropCell(pParent, nxDiv, sz);
szCell[nCell] -= leafCorrection; szCell[nCell] -= leafCorrection;
assert( get4byte(pTemp)==pgnoOld[i] ); assert( get4byte(pTemp)==pgnoOld[i] );
@@ -5381,8 +5371,7 @@ static int balance_nonroot(MemPage *pPage){
** children of cells, the right-child of the page, or overflow pages ** children of cells, the right-child of the page, or overflow pages
** pointed to by cells. ** pointed to by cells.
*/ */
#ifndef SQLITE_OMIT_AUTOVACUUM if( ISAUTOVACUUM ){
if( pBt->autoVacuum ){
for(k=j; k<cntNew[i]; k++){ for(k=j; k<cntNew[i]; k++){
assert( k<nMaxCells ); assert( k<nMaxCells );
if( aFrom[k]==0xFF || apCopy[aFrom[k]]->pgno!=pNew->pgno ){ if( aFrom[k]==0xFF || apCopy[aFrom[k]]->pgno!=pNew->pgno ){
@@ -5396,7 +5385,6 @@ static int balance_nonroot(MemPage *pPage){
} }
} }
} }
#endif
j = cntNew[i]; j = cntNew[i];
@@ -5414,8 +5402,7 @@ static int balance_nonroot(MemPage *pPage){
pTemp = &aSpace2[iSpace2]; pTemp = &aSpace2[iSpace2];
if( !pNew->leaf ){ if( !pNew->leaf ){
memcpy(&pNew->aData[8], pCell, 4); memcpy(&pNew->aData[8], pCell, 4);
#ifndef SQLITE_OMIT_AUTOVACUUM if( ISAUTOVACUUM
if( pBt->autoVacuum
&& (aFrom[j]==0xFF || apCopy[aFrom[j]]->pgno!=pNew->pgno) && (aFrom[j]==0xFF || apCopy[aFrom[j]]->pgno!=pNew->pgno)
){ ){
rc = ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno); rc = ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno);
@@ -5423,7 +5410,6 @@ static int balance_nonroot(MemPage *pPage){
goto balance_cleanup; goto balance_cleanup;
} }
} }
#endif
}else if( leafData ){ }else if( leafData ){
/* If the tree is a leaf-data tree, and the siblings are leaves, /* If the tree is a leaf-data tree, and the siblings are leaves,
** then there is no divider cell in apCell[]. Instead, the divider ** then there is no divider cell in apCell[]. Instead, the divider
@@ -5460,31 +5446,28 @@ static int balance_nonroot(MemPage *pPage){
rc = insertCell(pParent, nxDiv, pCell, sz, pTemp, 4); rc = insertCell(pParent, nxDiv, pCell, sz, pTemp, 4);
if( rc!=SQLITE_OK ) goto balance_cleanup; if( rc!=SQLITE_OK ) goto balance_cleanup;
put4byte(findOverflowCell(pParent,nxDiv), pNew->pgno); put4byte(findOverflowCell(pParent,nxDiv), pNew->pgno);
#ifndef SQLITE_OMIT_AUTOVACUUM
/* If this is an auto-vacuum database, and not a leaf-data tree, /* If this is an auto-vacuum database, and not a leaf-data tree,
** then update the pointer map with an entry for the overflow page ** then update the pointer map with an entry for the overflow page
** that the cell just inserted points to (if any). ** that the cell just inserted points to (if any).
*/ */
if( pBt->autoVacuum && !leafData ){ if( ISAUTOVACUUM && !leafData ){
rc = ptrmapPutOvfl(pParent, nxDiv); rc = ptrmapPutOvfl(pParent, nxDiv);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
goto balance_cleanup; goto balance_cleanup;
} }
} }
#endif
j++; j++;
nxDiv++; nxDiv++;
} }
#ifndef SQLITE_OMIT_AUTOVACUUM
/* Set the pointer-map entry for the new sibling page. */ /* Set the pointer-map entry for the new sibling page. */
if( pBt->autoVacuum ){ if( ISAUTOVACUUM ){
rc = ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno); rc = ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
goto balance_cleanup; goto balance_cleanup;
} }
} }
#endif
} }
assert( j==nCell ); assert( j==nCell );
assert( nOld>0 ); assert( nOld>0 );
@@ -5492,14 +5475,12 @@ static int balance_nonroot(MemPage *pPage){
if( (pageFlags & PTF_LEAF)==0 ){ if( (pageFlags & PTF_LEAF)==0 ){
u8 *zChild = &apCopy[nOld-1]->aData[8]; u8 *zChild = &apCopy[nOld-1]->aData[8];
memcpy(&apNew[nNew-1]->aData[8], zChild, 4); memcpy(&apNew[nNew-1]->aData[8], zChild, 4);
#ifndef SQLITE_OMIT_AUTOVACUUM if( ISAUTOVACUUM ){
if( pBt->autoVacuum ){
rc = ptrmapPut(pBt, get4byte(zChild), PTRMAP_BTREE, apNew[nNew-1]->pgno); rc = ptrmapPut(pBt, get4byte(zChild), PTRMAP_BTREE, apNew[nNew-1]->pgno);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
goto balance_cleanup; goto balance_cleanup;
} }
} }
#endif
} }
if( nxDiv==pParent->nCell+pParent->nOverflow ){ if( nxDiv==pParent->nCell+pParent->nOverflow ){
/* Right-most sibling is the right-most child of pParent */ /* Right-most sibling is the right-most child of pParent */
@@ -5627,8 +5608,7 @@ static int balance_shallower(MemPage *pPage){
} }
rc = reparentChildPages(pPage, 1); rc = reparentChildPages(pPage, 1);
assert( pPage->nOverflow==0 ); assert( pPage->nOverflow==0 );
#ifndef SQLITE_OMIT_AUTOVACUUM if( ISAUTOVACUUM ){
if( pBt->autoVacuum ){
int i; int i;
for(i=0; i<pPage->nCell; i++){ for(i=0; i<pPage->nCell; i++){
rc = ptrmapPutOvfl(pPage, i); rc = ptrmapPutOvfl(pPage, i);
@@ -5637,7 +5617,6 @@ static int balance_shallower(MemPage *pPage){
} }
} }
} }
#endif
releasePage(pChild); releasePage(pChild);
} }
end_shallow_balance: end_shallow_balance:
@@ -5692,8 +5671,7 @@ static int balance_deeper(MemPage *pPage){
zeroPage(pPage, pChild->aData[0] & ~PTF_LEAF); zeroPage(pPage, pChild->aData[0] & ~PTF_LEAF);
put4byte(&pPage->aData[pPage->hdrOffset+8], pgnoChild); put4byte(&pPage->aData[pPage->hdrOffset+8], pgnoChild);
TRACE(("BALANCE: copy root %d into %d\n", pPage->pgno, pChild->pgno)); TRACE(("BALANCE: copy root %d into %d\n", pPage->pgno, pChild->pgno));
#ifndef SQLITE_OMIT_AUTOVACUUM if( ISAUTOVACUUM ){
if( pBt->autoVacuum ){
int i; int i;
rc = ptrmapPut(pBt, pChild->pgno, PTRMAP_BTREE, pPage->pgno); rc = ptrmapPut(pBt, pChild->pgno, PTRMAP_BTREE, pPage->pgno);
if( rc ) goto balancedeeper_out; if( rc ) goto balancedeeper_out;
@@ -5705,7 +5683,6 @@ static int balance_deeper(MemPage *pPage){
} }
rc = reparentChildPages(pChild, 1); rc = reparentChildPages(pChild, 1);
} }
#endif
if( rc==SQLITE_OK ){ if( rc==SQLITE_OK ){
rc = balance_nonroot(pChild); rc = balance_nonroot(pChild);
} }