Index: src/btree.c
==================================================================
--- src/btree.c
+++ src/btree.c
@@ -6726,27 +6726,38 @@
** / | \
** --------- --------- ---------
** |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
** 3. All cells from Child-2 in order
** 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 {
int nCell; /* Number of cells in apCell[] */
MemPage *pRef; /* Reference page */
@@ -7656,16 +7667,19 @@
** the right of the i-th sibling page.
** usableSpace: Number of bytes of space available on each sibling.
**
*/
usableSpace = pBt->usableSize - 12 + leafCorrection;
- for(i=0; iaDataEnd;
- 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; jnOverflow; j++){
szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
}
cntNew[i] = cntOld[i];