]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Improve the strict enforcement of cell sizes in balancing from
authordrh <drh@noemail.net>
Fri, 1 Feb 2019 14:50:43 +0000 (14:50 +0000)
committerdrh <drh@noemail.net>
Fri, 1 Feb 2019 14:50:43 +0000 (14:50 +0000)
check-in [12713f320b2c1def] so that it also works with table-btrees
in addition to index-btrees.

FossilOrigin-Name: ef27e7a08728aa7447ae19812803ac5c4a9d80c97541014bd292485792005a3e

manifest
manifest.uuid
src/btree.c

index dcadb8969f74a7b1f8b3b983df4c90d781683a4c..6d708aeb8508344b6eb22909a78b34526f6b0adc 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\san\sassert()\sin\sfts5\sthat\scould\sfail\sif\sthe\sdatabase\sis\scorrupt.
-D 2019-02-01T14:40:44.768
+C Improve\sthe\sstrict\senforcement\sof\scell\ssizes\sin\sbalancing\sfrom\ncheck-in\s[12713f320b2c1def]\sso\sthat\sit\salso\sworks\swith\stable-btrees\nin\saddition\sto\sindex-btrees.
+D 2019-02-01T14:50:43.745
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F Makefile.in 178d8eb6840771149cee40b322d1b3be30d330198c522c903c1b66fb5a1bfca4
@@ -455,7 +455,7 @@ F src/auth.c 0fac71038875693a937e506bceb492c5f136dd7b1249fbd4ae70b4e8da14f9df
 F src/backup.c 78d3cecfbe28230a3a9a1793e2ead609f469be43e8f486ca996006be551857ab
 F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33
 F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6
-F src/btree.c 79464668601b6d278954cf822ef484893e1434f85addda2bd9a323796b91b328
+F src/btree.c 9649c95a846deddf256525125ae257ef1ce0cf29409031df8378330a45d513a6
 F src/btree.h febb2e817be499570b7a2e32a9bbb4b607a9234f6b84bb9ae84916d4806e96f2
 F src/btreeInt.h cd82f0f08886078bf99b29e1a7045960b1ca5d9d5829c38607e1299c508eaf00
 F src/build.c fe6e3753c4cfc76f9c621a24ef5f6fd62aac5aa6c843710b542509f493274eca
@@ -1804,7 +1804,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 9876ae1b802a449aacbbdd42778653edc19e29315dc627c23ab7493d6492c800
-R 37889ca5f23631d6a97887212bc95ece
-U dan
-Z f38e72163280904b28dc1d9373c8a5e6
+P 55f06aa3f890dc1dc5c2ed0e6777e46d609a6f9d223d1d4b5813097ce4f4e797
+R 20b34459b8ccf247d9f81319ceb019f1
+U drh
+Z b1e6b3262e06a43d75a1c54043cfe677
index aa2807cb2810d2fb65af4bd928aeecb2f32ad2ac..6d38cb6ecb3d0abafc9d1c9ebe4efa724fa16f04 100644 (file)
@@ -1 +1 @@
-55f06aa3f890dc1dc5c2ed0e6777e46d609a6f9d223d1d4b5813097ce4f4e797
\ No newline at end of file
+ef27e7a08728aa7447ae19812803ac5c4a9d80c97541014bd292485792005a3e
\ No newline at end of file
index 5c455f7d22c80138b38fd123129793366aa750e6..1fd7dcac4a01ef25f6161304696608ed9714839f 100644 (file)
@@ -6728,7 +6728,7 @@ static void insertCell(
 **  |Child-1|   |Child-2|   |Child-3|
 **  ---------   ---------   ---------
 **
-** The order of cells is in the array is:
+** The order of cells is in the array is for an index btree is:
 **
 **       1.  All cells from Child-1 in order
 **       2.  The first divider cell from Parent
@@ -6736,15 +6736,26 @@ static void insertCell(
 **       4.  The second divider cell from Parent
 **       5.  All cells from Child-3 in order
 **
-** The apEnd[] array holds pointer to the end of page for Child-1, the
-** Parent, Child-2, the Parent (again), and Child-3.  The ixNx[] array
-** holds the number of cells contained in each of these 5 stages, and
-** all stages to the left.  Hence:
+** For a table-btree (with rowids) the items 2 and 4 are empty because
+** content exists only in leaves and there are no divider cells.
+**
+** For an index btree, the apEnd[] array holds pointer to the end of page
+** for Child-1, the Parent, Child-2, the Parent (again), and Child-3,
+** respectively. The ixNx[] array holds the number of cells contained in
+** each of these 5 stages, and all stages to the left.  Hence:
+**
 **    ixNx[0] = Number of cells in Child-1.
 **    ixNx[1] = Number of cells in Child-1 plus 1 for first divider.
 **    ixNx[2] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
 **    ixNx[3] = Number of cells in Child-1 and Child-2 + both divider cells
 **    ixNx[4] = Total number of cells.
+**
+** For a table-btree, the concept is similar, except only apEnd[0]..apEnd[2]
+** are used and they point to the leaf pages only, and the ixNx value are:
+**
+**    ixNx[0] = Number of cells in Child-1.
+**    ixNx[1] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
+**    ixNx[2] = Number of cells in Child-1 and Child-2 + both divider cells
 */
 typedef struct CellArray CellArray;
 struct CellArray {
@@ -7658,12 +7669,15 @@ static int balance_nonroot(
   ** 
   */
   usableSpace = pBt->usableSize - 12 + leafCorrection;
-  for(i=0; i<nOld; i++){
+  for(i=k=0; i<nOld; i++, k++){
     MemPage *p = apOld[i];
-    b.apEnd[i*2] = p->aDataEnd;
-    b.apEnd[i*2+1] = pParent->aDataEnd;
-    b.ixNx[i*2] = cntOld[i];
-    b.ixNx[i*2+1] = cntOld[i]+1;
+    b.apEnd[k] = p->aDataEnd;
+    b.ixNx[k] = cntOld[i];
+    if( !leafData ){
+      k++;
+      b.apEnd[k] = pParent->aDataEnd;
+      b.ixNx[k] = cntOld[i]+1;
+    }
     szNew[i] = usableSpace - p->nFree;
     for(j=0; j<p->nOverflow; j++){
       szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);