/ Check-in [ef27e7a0]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ef27e7a08728aa7447ae19812803ac5c4a9d80c97541014bd292485792005a3e
User & Date: drh 2019-02-01 14:50:43
Context
2019-02-01
14:54
New test cases added to test/fuzzdata8.db. check-in: e5924939 user: drh tags: trunk
14:50
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. check-in: ef27e7a0 user: drh tags: trunk
14:40
Fix an assert() in fts5 that could fail if the database is corrupt. check-in: 55f06aa3 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  6724   6724   **             -----------
  6725   6725   **            /     |     \
  6726   6726   **           /      |      \
  6727   6727   **  ---------   ---------   ---------
  6728   6728   **  |Child-1|   |Child-2|   |Child-3|
  6729   6729   **  ---------   ---------   ---------
  6730   6730   **
  6731         -** The order of cells is in the array is:
         6731  +** The order of cells is in the array is for an index btree is:
  6732   6732   **
  6733   6733   **       1.  All cells from Child-1 in order
  6734   6734   **       2.  The first divider cell from Parent
  6735   6735   **       3.  All cells from Child-2 in order
  6736   6736   **       4.  The second divider cell from Parent
  6737   6737   **       5.  All cells from Child-3 in order
  6738   6738   **
  6739         -** The apEnd[] array holds pointer to the end of page for Child-1, the
  6740         -** Parent, Child-2, the Parent (again), and Child-3.  The ixNx[] array
  6741         -** holds the number of cells contained in each of these 5 stages, and
  6742         -** all stages to the left.  Hence:
         6739  +** For a table-btree (with rowids) the items 2 and 4 are empty because
         6740  +** content exists only in leaves and there are no divider cells.
         6741  +**
         6742  +** For an index btree, the apEnd[] array holds pointer to the end of page
         6743  +** for Child-1, the Parent, Child-2, the Parent (again), and Child-3,
         6744  +** respectively. The ixNx[] array holds the number of cells contained in
         6745  +** each of these 5 stages, and all stages to the left.  Hence:
         6746  +**
  6743   6747   **    ixNx[0] = Number of cells in Child-1.
  6744   6748   **    ixNx[1] = Number of cells in Child-1 plus 1 for first divider.
  6745   6749   **    ixNx[2] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
  6746   6750   **    ixNx[3] = Number of cells in Child-1 and Child-2 + both divider cells
  6747   6751   **    ixNx[4] = Total number of cells.
         6752  +**
         6753  +** For a table-btree, the concept is similar, except only apEnd[0]..apEnd[2]
         6754  +** are used and they point to the leaf pages only, and the ixNx value are:
         6755  +**
         6756  +**    ixNx[0] = Number of cells in Child-1.
         6757  +**    ixNx[1] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
         6758  +**    ixNx[2] = Number of cells in Child-1 and Child-2 + both divider cells
  6748   6759   */
  6749   6760   typedef struct CellArray CellArray;
  6750   6761   struct CellArray {
  6751   6762     int nCell;              /* Number of cells in apCell[] */
  6752   6763     MemPage *pRef;          /* Reference page */
  6753   6764     u8 **apCell;            /* All cells begin balanced */
  6754   6765     u16 *szCell;            /* Local size of all cells in apCell[] */
................................................................................
  7654   7665     **    szNew[i]: Spaced used on the i-th sibling page.
  7655   7666     **   cntNew[i]: Index in b.apCell[] and b.szCell[] for the first cell to
  7656   7667     **              the right of the i-th sibling page.
  7657   7668     ** usableSpace: Number of bytes of space available on each sibling.
  7658   7669     ** 
  7659   7670     */
  7660   7671     usableSpace = pBt->usableSize - 12 + leafCorrection;
  7661         -  for(i=0; i<nOld; i++){
         7672  +  for(i=k=0; i<nOld; i++, k++){
  7662   7673       MemPage *p = apOld[i];
  7663         -    b.apEnd[i*2] = p->aDataEnd;
  7664         -    b.apEnd[i*2+1] = pParent->aDataEnd;
  7665         -    b.ixNx[i*2] = cntOld[i];
  7666         -    b.ixNx[i*2+1] = cntOld[i]+1;
         7674  +    b.apEnd[k] = p->aDataEnd;
         7675  +    b.ixNx[k] = cntOld[i];
         7676  +    if( !leafData ){
         7677  +      k++;
         7678  +      b.apEnd[k] = pParent->aDataEnd;
         7679  +      b.ixNx[k] = cntOld[i]+1;
         7680  +    }
  7667   7681       szNew[i] = usableSpace - p->nFree;
  7668   7682       for(j=0; j<p->nOverflow; j++){
  7669   7683         szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
  7670   7684       }
  7671   7685       cntNew[i] = cntOld[i];
  7672   7686     }
  7673   7687     k = nOld;