mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-10 01:02:56 +03:00
Make the BTree balance() routine a little faster by reusing database
pages locally rather than freeing and reallocating them. (CVS 666) FossilOrigin-Name: 3c2dea4310af491d6cb09856d4bc5236d6dc44ac
This commit is contained in:
12
manifest
12
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Version\s2.5.6\s(CVS\s664)
|
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-07T17:13:00
|
D 2002-07-08T02:16:38
|
||||||
F Makefile.in 6291a33b87d2a395aafd7646ee1ed562c6f2c28c
|
F Makefile.in 6291a33b87d2a395aafd7646ee1ed562c6f2c28c
|
||||||
F Makefile.template 4e11752e0b5c7a043ca50af4296ec562857ba495
|
F Makefile.template 4e11752e0b5c7a043ca50af4296ec562857ba495
|
||||||
F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0
|
F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0
|
||||||
@@ -18,7 +18,7 @@ F publish.sh 1a04b9aa0d9c9661e338268343476ed0851c5778
|
|||||||
F spec.template 238f7db425a78dc1bb7682e56e3834c7270a3f5e
|
F spec.template 238f7db425a78dc1bb7682e56e3834c7270a3f5e
|
||||||
F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
|
F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
|
||||||
F src/TODO af7f3cab0228e34149cf98e073aa83d45878e7e6
|
F src/TODO af7f3cab0228e34149cf98e073aa83d45878e7e6
|
||||||
F src/btree.c 73212bda34c491ce9165464c3e1ada737acf5e06
|
F src/btree.c ce999ee3f5c6130aa12529ba4f510679d0a07faa
|
||||||
F src/btree.h 8abeabfe6e0b1a990b64fa457592a6482f6674f3
|
F src/btree.h 8abeabfe6e0b1a990b64fa457592a6482f6674f3
|
||||||
F src/build.c ea4a3bc15d6338294e68100f642edf48e4082403
|
F src/build.c ea4a3bc15d6338294e68100f642edf48e4082403
|
||||||
F src/delete.c 215492ffcea4262a993e55f3c4a67dc9fea4da9c
|
F src/delete.c 215492ffcea4262a993e55f3c4a67dc9fea4da9c
|
||||||
@@ -140,7 +140,7 @@ F www/speed.tcl da8afcc1d3ccc5696cfb388a68982bc3d9f7f00f
|
|||||||
F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
|
F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
|
||||||
F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
|
F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
|
||||||
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
|
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
|
||||||
P ee86704daf184307fe98b5631f22ceb3d701afce
|
P 111c78e6835306fcd8b6d22b9ae68dfb9ab4febe
|
||||||
R 40fe3b9213d364dad4e1cb9b6ce3c5e4
|
R 66eadf0358149489c17da262453c92f0
|
||||||
U drh
|
U drh
|
||||||
Z 0f5647bf09d0573645455993f27ff345
|
Z 70877f6880980e12b35ccd8168df5635
|
||||||
|
@@ -1 +1 @@
|
|||||||
111c78e6835306fcd8b6d22b9ae68dfb9ab4febe
|
3c2dea4310af491d6cb09856d4bc5236d6dc44ac
|
35
src/btree.c
35
src/btree.c
@@ -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.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.
|
** This file implements a external (disk-based) database using BTrees.
|
||||||
** For a detailed discussion of BTrees, refer to
|
** For a detailed discussion of BTrees, refer to
|
||||||
@@ -2099,10 +2099,6 @@ static int balance(Btree *pBt, MemPage *pPage, BtCursor *pCur){
|
|||||||
*/
|
*/
|
||||||
for(i=0; i<nOld; i++){
|
for(i=0; i<nOld; i++){
|
||||||
copyPage(&aOld[i], apOld[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];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -2112,7 +2108,7 @@ static int balance(Btree *pBt, MemPage *pPage, BtCursor *pCur){
|
|||||||
*/
|
*/
|
||||||
nCell = 0;
|
nCell = 0;
|
||||||
for(i=0; i<nOld; i++){
|
for(i=0; i<nOld; i++){
|
||||||
MemPage *pOld = apOld[i];
|
MemPage *pOld = &aOld[i];
|
||||||
for(j=0; j<pOld->nCell; j++){
|
for(j=0; j<pOld->nCell; j++){
|
||||||
apCell[nCell] = pOld->apCell[j];
|
apCell[nCell] = pOld->apCell[j];
|
||||||
szCell[nCell] = cellSize(apCell[nCell]);
|
szCell[nCell] = cellSize(apCell[nCell]);
|
||||||
@@ -2166,16 +2162,33 @@ static int balance(Btree *pBt, MemPage *pPage, BtCursor *pCur){
|
|||||||
assert( cntNew[0]>0 );
|
assert( cntNew[0]>0 );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Allocate k new pages
|
** Allocate k new pages. Reuse old pages where possible.
|
||||||
*/
|
*/
|
||||||
for(i=0; i<k; i++){
|
for(i=0; i<k; i++){
|
||||||
rc = allocatePage(pBt, &apNew[i], &pgnoNew[i]);
|
if( i<nOld ){
|
||||||
if( rc ) goto balance_cleanup;
|
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++;
|
nNew++;
|
||||||
zeroPage(apNew[i]);
|
zeroPage(apNew[i]);
|
||||||
apNew[i]->isInit = 1;
|
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
|
** Put the new pages in accending order. This helps to
|
||||||
** keep entries in the disk file in order so that a scan
|
** keep entries in the disk file in order so that a scan
|
||||||
@@ -2236,7 +2249,7 @@ static int balance(Btree *pBt, MemPage *pPage, BtCursor *pCur){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert( j==nCell );
|
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 ){
|
if( nxDiv==pParent->nCell ){
|
||||||
pParent->u.hdr.rightChild = pgnoNew[nNew-1];
|
pParent->u.hdr.rightChild = pgnoNew[nNew-1];
|
||||||
}else{
|
}else{
|
||||||
@@ -2274,7 +2287,7 @@ balance_cleanup:
|
|||||||
sqlitepager_unref(extraUnref);
|
sqlitepager_unref(extraUnref);
|
||||||
}
|
}
|
||||||
for(i=0; i<nOld; i++){
|
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++){
|
for(i=0; i<nNew; i++){
|
||||||
sqlitepager_unref(apNew[i]);
|
sqlitepager_unref(apNew[i]);
|
||||||
|
Reference in New Issue
Block a user