/ Check-in [f21d2175]
Login

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

Overview
Comment:Have the clearCell() routine return the cell size to the caller, rather than have the caller make a separate call to cellSizePtr().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f21d217583c205dc17f98bb4877fd4ed98cefcb1
User & Date: drh 2014-09-24 02:05:41
Context
2014-09-24
13:20
Do not allow parameters in a DEFAULT clause of a CREATE TABLE statement. Ticket [78c0c8c3c9f7c1]. check-in: 1ad2bc1e user: drh tags: trunk
04:38
Experiment using linear interpolation, instead of a strict binary search, when looking for integer-keyed rows on a single b-tree page. The experiment was not successful. The number of key comparisons is reduced by about 15%, but the added complexity of the search logic causes an overall reduction in performance. The patch is saved for historical reference only. Closed-Leaf check-in: c705cf85 user: drh tags: linear-interpolation
02:05
Have the clearCell() routine return the cell size to the caller, rather than have the caller make a separate call to cellSizePtr(). check-in: f21d2175 user: drh tags: trunk
01:23
Shorten all lines of source code in btree.c to at most 80 characters. No logical changes. check-in: 5dd41cdb user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  5515   5515   static void freePage(MemPage *pPage, int *pRC){
  5516   5516     if( (*pRC)==SQLITE_OK ){
  5517   5517       *pRC = freePage2(pPage->pBt, pPage, pPage->pgno);
  5518   5518     }
  5519   5519   }
  5520   5520   
  5521   5521   /*
  5522         -** Free any overflow pages associated with the given Cell.
         5522  +** Free any overflow pages associated with the given Cell.  Write the
         5523  +** local Cell size (the number of bytes on the original page, omitting
         5524  +** overflow) into *pnSize.
  5523   5525   */
  5524         -static int clearCell(MemPage *pPage, unsigned char *pCell){
         5526  +static int clearCell(
         5527  +  MemPage *pPage,          /* The page that contains the Cell */
         5528  +  unsigned char *pCell,    /* First byte of the Cell */
         5529  +  u16 *pnSize              /* Write the size of the Cell here */
         5530  +){
  5525   5531     BtShared *pBt = pPage->pBt;
  5526   5532     CellInfo info;
  5527   5533     Pgno ovflPgno;
  5528   5534     int rc;
  5529   5535     int nOvfl;
  5530   5536     u32 ovflPageSize;
  5531   5537   
  5532   5538     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  5533   5539     btreeParseCellPtr(pPage, pCell, &info);
         5540  +  *pnSize = info.nSize;
  5534   5541     if( info.iOverflow==0 ){
  5535   5542       return SQLITE_OK;  /* No overflow pages. Return without doing anything */
  5536   5543     }
  5537   5544     if( pCell+info.iOverflow+3 > pPage->aData+pPage->maskPage ){
  5538   5545       return SQLITE_CORRUPT_BKPT;  /* Cell extends past end of page */
  5539   5546     }
  5540   5547     ovflPgno = get4byte(&pCell[info.iOverflow]);
................................................................................
  7162   7169       if( rc ){
  7163   7170         goto end_insert;
  7164   7171       }
  7165   7172       oldCell = findCell(pPage, idx);
  7166   7173       if( !pPage->leaf ){
  7167   7174         memcpy(newCell, oldCell, 4);
  7168   7175       }
  7169         -    szOld = cellSizePtr(pPage, oldCell);
  7170         -    rc = clearCell(pPage, oldCell);
         7176  +    rc = clearCell(pPage, oldCell, &szOld);
  7171   7177       dropCell(pPage, idx, szOld, &rc);
  7172   7178       if( rc ) goto end_insert;
  7173   7179     }else if( loc<0 && pPage->nCell>0 ){
  7174   7180       assert( pPage->leaf );
  7175   7181       idx = ++pCur->aiIdx[pCur->iPage];
  7176   7182     }else{
  7177   7183       assert( pPage->leaf );
................................................................................
  7225   7231     Btree *p = pCur->pBtree;
  7226   7232     BtShared *pBt = p->pBt;              
  7227   7233     int rc;                              /* Return code */
  7228   7234     MemPage *pPage;                      /* Page to delete cell from */
  7229   7235     unsigned char *pCell;                /* Pointer to cell to delete */
  7230   7236     int iCellIdx;                        /* Index of cell to delete */
  7231   7237     int iCellDepth;                      /* Depth of node containing pCell */ 
         7238  +  u16 szCell;                          /* Size of the cell being deleted */
  7232   7239   
  7233   7240     assert( cursorHoldsMutex(pCur) );
  7234   7241     assert( pBt->inTransaction==TRANS_WRITE );
  7235   7242     assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
  7236   7243     assert( pCur->curFlags & BTCF_WriteFlag );
  7237   7244     assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
  7238   7245     assert( !hasReadConflicts(p, pCur->pgnoRoot) );
................................................................................
  7273   7280     ** invalidate any incrblob cursors open on the row being deleted.  */
  7274   7281     if( pCur->pKeyInfo==0 ){
  7275   7282       invalidateIncrblobCursors(p, pCur->info.nKey, 0);
  7276   7283     }
  7277   7284   
  7278   7285     rc = sqlite3PagerWrite(pPage->pDbPage);
  7279   7286     if( rc ) return rc;
  7280         -  rc = clearCell(pPage, pCell);
  7281         -  dropCell(pPage, iCellIdx, cellSizePtr(pPage, pCell), &rc);
         7287  +  rc = clearCell(pPage, pCell, &szCell);
         7288  +  dropCell(pPage, iCellIdx, szCell, &rc);
  7282   7289     if( rc ) return rc;
  7283   7290   
  7284   7291     /* If the cell deleted was not located on a leaf page, then the cursor
  7285   7292     ** is currently pointing to the largest entry in the sub-tree headed
  7286   7293     ** by the child-page of the cell that was just deleted from an internal
  7287   7294     ** node. The cell from the leaf node needs to be moved to the internal
  7288   7295     ** node to replace the deleted cell.  */
................................................................................
  7506   7513     int *pnChange            /* Add number of Cells freed to this counter */
  7507   7514   ){
  7508   7515     MemPage *pPage;
  7509   7516     int rc;
  7510   7517     unsigned char *pCell;
  7511   7518     int i;
  7512   7519     int hdr;
         7520  +  u16 szCell;
  7513   7521   
  7514   7522     assert( sqlite3_mutex_held(pBt->mutex) );
  7515   7523     if( pgno>btreePagecount(pBt) ){
  7516   7524       return SQLITE_CORRUPT_BKPT;
  7517   7525     }
  7518   7526   
  7519   7527     rc = getAndInitPage(pBt, pgno, &pPage, 0);
................................................................................
  7521   7529     hdr = pPage->hdrOffset;
  7522   7530     for(i=0; i<pPage->nCell; i++){
  7523   7531       pCell = findCell(pPage, i);
  7524   7532       if( !pPage->leaf ){
  7525   7533         rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
  7526   7534         if( rc ) goto cleardatabasepage_out;
  7527   7535       }
  7528         -    rc = clearCell(pPage, pCell);
         7536  +    rc = clearCell(pPage, pCell, &szCell);
  7529   7537       if( rc ) goto cleardatabasepage_out;
  7530   7538     }
  7531   7539     if( !pPage->leaf ){
  7532   7540       rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange);
  7533   7541       if( rc ) goto cleardatabasepage_out;
  7534   7542     }else if( pnChange ){
  7535   7543       assert( pPage->intKey );