]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Parameterize the number of adjacent pages that participate in the balancing
authordrh <drh@noemail.net>
Sat, 4 Jan 2003 19:44:07 +0000 (19:44 +0000)
committerdrh <drh@noemail.net>
Sat, 4 Jan 2003 19:44:07 +0000 (19:44 +0000)
algorithm in the BTree.  But leave the setting at the current value of 3. (CVS 812)

FossilOrigin-Name: 6c304024bbd21a1886a57ada795531349aa627d7

manifest
manifest.uuid
src/btree.c

index e9d4159063270bd3a7e7d6e278e492d98b26935a..eba8e18f55e7410a70370a226ed2e2c66cfa213e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Another\soptimization\sto\sthe\sbtree\slogic.\s(CVS\s811)
-D 2003-01-04T18:53:28
+C Parameterize\sthe\snumber\sof\sadjacent\spages\sthat\sparticipate\sin\sthe\sbalancing\nalgorithm\sin\sthe\sBTree.\s\sBut\sleave\sthe\ssetting\sat\sthe\scurrent\svalue\sof\s3.\s(CVS\s812)
+D 2003-01-04T19:44:08
 F Makefile.in 868c17a1ae1c07603d491274cc8f86c04acf2a1e
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -18,7 +18,7 @@ F main.mk 9d13839b9697af332d788fe6e801e68da027cc5c
 F publish.sh e5b83867d14708ed58cec8cba0a4f201e969474d
 F spec.template 238f7db425a78dc1bb7682e56e3834c7270a3f5e
 F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
-F src/btree.c 9ae3232125d54e0f4c73ae88af1f4556e15440e9
+F src/btree.c 65dfa86fc2a9eded02fc011c368d20174fba10d1
 F src/btree.h 17710339f7a8f46e3c7d6d0d4648ef19c584ffda
 F src/build.c 8569ac014609add4b796260d3567a5090b90056d
 F src/delete.c aad9d4051ab46e6f6391ea5f7b8994a7c05bdd15
@@ -152,7 +152,7 @@ F www/speed.tcl a20a792738475b68756ea7a19321600f23d1d803
 F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P 39902a70417475225956704a037493515e9b08b9
-R 5307d3e389db7bcbbe208e92a667a5a5
+P 03d20673616cae0dca524fd04557798a98fb7069
+R 131375a6bd5b4a8f3f85a8c7c672f995
 U drh
-Z 5237255ce20b25abc6c29c72daee1d77
+Z c7e9682e375704261f3906f005af16af
index 5a343221c7d25f56d21fdd370e32bceb8fe26181..a62d5457b8161257e225e50b7201e881936c189a 100644 (file)
@@ -1 +1 @@
-03d20673616cae0dca524fd04557798a98fb7069
\ No newline at end of file
+6c304024bbd21a1886a57ada795531349aa627d7
\ No newline at end of file
index a99f86729dc2409a4fe7b419eb81befa2fa2f698..0b85a933fcf73fb5a7faf28be4c5975fd9367c45 100644 (file)
@@ -9,7 +9,7 @@
 **    May you share freely, never taking more than you give.
 **
 *************************************************************************
-** $Id: btree.c,v 1.78 2003/01/04 18:53:28 drh Exp $
+** $Id: btree.c,v 1.79 2003/01/04 19:44:08 drh Exp $
 **
 ** This file implements a external (disk-based) database using BTrees.
 ** For a detailed discussion of BTrees, refer to
@@ -2061,6 +2061,21 @@ static void copyPage(MemPage *pTo, MemPage *pFrom){
   }
 }
 
+/*
+** The following parameters determine how many adjacent pages get involved
+** in a balancing operation.  NN is the number of neighbors on either side
+** of the page that participate in the balancing operation.  NB is the
+** total number of pages that participate, including the target page and
+** NN neighbors on either side.
+**
+** The minimum value of NN is 1 (of course).  Increasing NN above 1
+** (to 2 or 3) gives a modest improvement in SELECT and DELETE performance
+** in exchange for a larger degradation in INSERT and UPDATE performance.
+** The value of NN appears to give the best results overall.
+*/
+#define NN 1             /* Number of neighbors on either side of pPage */
+#define NB (NN*2+1)      /* Total pages involved in the balance */
+
 /*
 ** This routine redistributes Cells on pPage and up to two siblings
 ** of pPage so that all pages have about the same amount of free space.
@@ -2103,12 +2118,6 @@ static void copyPage(MemPage *pTo, MemPage *pFrom){
 */
 static int balance(Btree *pBt, MemPage *pPage, BtCursor *pCur){
   MemPage *pParent;            /* The parent of pPage */
-  MemPage *apOld[3];           /* pPage and up to two siblings */
-  Pgno pgnoOld[3];             /* Page numbers for each page in apOld[] */
-  MemPage *apNew[4];           /* pPage and up to 3 siblings after balancing */
-  Pgno pgnoNew[4];             /* Page numbers for each page in apNew[] */
-  int idxDiv[3];               /* Indices of divider cells in pParent */
-  Cell *apDiv[3];              /* Divider cells in pParent */
   int nCell;                   /* Number of cells in apCell[] */
   int nOld;                    /* Number of pages in apOld[] */
   int nNew;                    /* Number of pages in apNew[] */
@@ -2120,13 +2129,19 @@ static int balance(Btree *pBt, MemPage *pPage, BtCursor *pCur){
   int iCur;                    /* apCell[iCur] is the cell of the cursor */
   MemPage *pOldCurPage;        /* The cursor originally points to this page */
   int subtotal;                /* Subtotal of bytes in cells on one page */
-  int cntNew[4];               /* Index in apCell[] of cell after i-th page */
-  int szNew[4];                /* Combined size of cells place on i-th page */
   MemPage *extraUnref = 0;     /* A page that needs to be unref-ed */
-  Cell *apCell[MX_CELL*3+5];   /* All cells from pages being balanceed */
-  int szCell[MX_CELL*3+5];     /* Local size of all cells */
-  Cell aTemp[2];               /* Temporary holding area for apDiv[] */
-  MemPage aOld[3];             /* Temporary copies of pPage and its siblings */
+  MemPage *apOld[NB];          /* pPage and up to two siblings */
+  Pgno pgnoOld[NB];            /* Page numbers for each page in apOld[] */
+  MemPage *apNew[NB+1];        /* pPage and up to NB siblings after balancing */
+  Pgno pgnoNew[NB+1];          /* Page numbers for each page in apNew[] */
+  int idxDiv[NB];              /* Indices of divider cells in pParent */
+  Cell *apDiv[NB];             /* Divider cells in pParent */
+  Cell aTemp[NB];              /* Temporary holding area for apDiv[] */
+  int cntNew[NB+1];            /* Index in apCell[] of cell after i-th page */
+  int szNew[NB+1];             /* Combined size of cells place on i-th page */
+  MemPage aOld[NB];            /* Temporary copies of pPage and its siblings */
+  Cell *apCell[(MX_CELL+2)*NB]; /* All cells from pages being balanced */
+  int szCell[(MX_CELL+2)*NB];  /* Local size of all cells */
 
   /* 
   ** Return without doing any work if pPage is neither overfull nor
@@ -2243,19 +2258,20 @@ static int balance(Btree *pBt, MemPage *pPage, BtCursor *pCur){
 
   /*
   ** Find sibling pages to pPage and the Cells in pParent that divide
-  ** the siblings.  An attempt is made to find one sibling on either
-  ** side of pPage.  Both siblings are taken from one side, however, if
-  ** pPage is either the first or last child of its parent.  If pParent
-  ** has 3 or fewer children then all children of pParent are taken.
+  ** the siblings.  An attempt is made to find NN siblings on either
+  ** side of pPage.  More siblings are taken from one side, however, if
+  ** pPage there are fewer than NN siblings on the other side.  If pParent
+  ** has NB or fewer children then all children of pParent are taken.
   */
-  if( idx==pParent->nCell ){
-    nxDiv = idx - 2;
-  }else{
-    nxDiv = idx - 1;
+  nxDiv = idx - NN;
+  if( nxDiv + NB > pParent->nCell ){
+    nxDiv = pParent->nCell - NB + 1;
+  }
+  if( nxDiv<0 ){
+    nxDiv = 0;
   }
-  if( nxDiv<0 ) nxDiv = 0;
   nDiv = 0;
-  for(i=0, k=nxDiv; i<3; i++, k++){
+  for(i=0, k=nxDiv; i<NB; i++, k++){
     if( k<pParent->nCell ){
       idxDiv[i] = k;
       apDiv[i] = pParent->apCell[k];
@@ -2400,10 +2416,11 @@ static int balance(Btree *pBt, MemPage *pPage, BtCursor *pCur){
   ** from the disk more rapidly.
   **
   ** An O(n^2) insertion sort algorithm is used, but since
-  ** n is never more than 3, that should not be a problem.
+  ** n is never more than NB (a small constant), that should
+  ** not be a problem.
   **
-  ** This one optimization makes the database about 25%
-  ** faster for large insertions and deletions.
+  ** When NB==3, this one optimization makes the database
+  ** about 25% faster for large insertions and deletions.
   */
   for(i=0; i<k-1; i++){
     int minV = pgnoNew[i];