-C Version\s2.5.6\s(CVS\s664)
-D 2002-07-07T17:13:00
+C Make\sthe\sBTree\sbalance()\sroutine\sa\slittle\sfaster\sby\sreusing\sdatabase\r\npages\slocally\srather\sthan\sfreeing\sand\sreallocating\sthem.\s(CVS\s666)
+D 2002-07-08T02:16:38
F Makefile.in 6291a33b87d2a395aafd7646ee1ed562c6f2c28c
F Makefile.template 4e11752e0b5c7a043ca50af4296ec562857ba495
F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0
F spec.template 238f7db425a78dc1bb7682e56e3834c7270a3f5e
F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
F src/TODO af7f3cab0228e34149cf98e073aa83d45878e7e6
-F src/btree.c 73212bda34c491ce9165464c3e1ada737acf5e06
+F src/btree.c ce999ee3f5c6130aa12529ba4f510679d0a07faa
F src/btree.h 8abeabfe6e0b1a990b64fa457592a6482f6674f3
F src/build.c ea4a3bc15d6338294e68100f642edf48e4082403
F src/delete.c 215492ffcea4262a993e55f3c4a67dc9fea4da9c
F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P ee86704daf184307fe98b5631f22ceb3d701afce
-R 40fe3b9213d364dad4e1cb9b6ce3c5e4
+P 111c78e6835306fcd8b6d22b9ae68dfb9ab4febe
+R 66eadf0358149489c17da262453c92f0
U drh
-Z 0f5647bf09d0573645455993f27ff345
+Z 70877f6880980e12b35ccd8168df5635
** May you share freely, never taking more than you give.
**
*************************************************************************
-** $Id: btree.c,v 1.65 2002/07/07 16:52:47 drh Exp $
+** $Id: btree.c,v 1.66 2002/07/08 02:16:38 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
*/
for(i=0; i<nOld; i++){
copyPage(&aOld[i], apOld[i]);
- rc = freePage(pBt, apOld[i], pgnoOld[i]);
- if( rc ) goto balance_cleanup;
- sqlitepager_unref(apOld[i]);
- apOld[i] = &aOld[i];
}
/*
*/
nCell = 0;
for(i=0; i<nOld; i++){
- MemPage *pOld = apOld[i];
+ MemPage *pOld = &aOld[i];
for(j=0; j<pOld->nCell; j++){
apCell[nCell] = pOld->apCell[j];
szCell[nCell] = cellSize(apCell[nCell]);
assert( cntNew[0]>0 );
/*
- ** Allocate k new pages
+ ** Allocate k new pages. Reuse old pages where possible.
*/
for(i=0; i<k; i++){
- rc = allocatePage(pBt, &apNew[i], &pgnoNew[i]);
- if( rc ) goto balance_cleanup;
+ if( i<nOld ){
+ apNew[i] = apOld[i];
+ pgnoNew[i] = pgnoOld[i];
+ apOld[i] = 0;
+ sqlitepager_write(apNew[i]);
+ }else{
+ rc = allocatePage(pBt, &apNew[i], &pgnoNew[i]);
+ if( rc ) goto balance_cleanup;
+ }
nNew++;
zeroPage(apNew[i]);
apNew[i]->isInit = 1;
}
+ /* Free any old pages that were not reused as new pages.
+ */
+ while( i<nOld ){
+ rc = freePage(pBt, apOld[i], pgnoOld[i]);
+ if( rc ) goto balance_cleanup;
+ sqlitepager_unref(apOld[i]);
+ apOld[i] = 0;
+ i++;
+ }
+
/*
** Put the new pages in accending order. This helps to
** keep entries in the disk file in order so that a scan
}
}
assert( j==nCell );
- apNew[nNew-1]->u.hdr.rightChild = apOld[nOld-1]->u.hdr.rightChild;
+ apNew[nNew-1]->u.hdr.rightChild = aOld[nOld-1].u.hdr.rightChild;
if( nxDiv==pParent->nCell ){
pParent->u.hdr.rightChild = pgnoNew[nNew-1];
}else{
sqlitepager_unref(extraUnref);
}
for(i=0; i<nOld; i++){
- if( apOld[i]!=&aOld[i] ) sqlitepager_unref(apOld[i]);
+ if( apOld[i]!=0 && apOld[i]!=&aOld[i] ) sqlitepager_unref(apOld[i]);
}
for(i=0; i<nNew; i++){
sqlitepager_unref(apNew[i]);