diff options
author | drh <drh@noemail.net> | 2019-02-01 14:50:43 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2019-02-01 14:50:43 +0000 |
commit | 26b7ec8b244cf937cdca47b45f57121f27367a54 (patch) | |
tree | 2b6388ae5329fba211c4ff228d4d29ec8dac5aff /src/btree.c | |
parent | 1c7d389a2304cb6d02561b9028488346b3c6f04a (diff) | |
download | sqlite-26b7ec8b244cf937cdca47b45f57121f27367a54.tar.gz sqlite-26b7ec8b244cf937cdca47b45f57121f27367a54.zip |
Improve the strict enforcement of cell sizes in balancing from
check-in [12713f320b2c1def] so that it also works with table-btrees
in addition to index-btrees.
FossilOrigin-Name: ef27e7a08728aa7447ae19812803ac5c4a9d80c97541014bd292485792005a3e
Diffstat (limited to 'src/btree.c')
-rw-r--r-- | src/btree.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/src/btree.c b/src/btree.c index 5c455f7d2..1fd7dcac4 100644 --- a/src/btree.c +++ b/src/btree.c @@ -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]); |