/ Check-in [d99bde9c]
Login

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

Overview
Comment:Unwind some complex conditions in sqlite3BtreeDelete() into separate "if" statements. (CVS 6879)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d99bde9ca61eeccfe6363ff0882fd4bcdb9a34dc
User & Date: drh 2009-07-11 13:13:12
Context
2009-07-11
17:04
Bug fix in the computation of the number of pages to autovacuum when nReserve is greater than zero. (CVS 6880) check-in: 618a83d6 user: drh tags: trunk
13:13
Unwind some complex conditions in sqlite3BtreeDelete() into separate "if" statements. (CVS 6879) check-in: d99bde9c user: drh tags: trunk
11:45
Remove another unreachable branch from btree.c. (CVS 6878) check-in: b0853100 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12         -** $Id: btree.c,v 1.677 2009/07/11 11:45:23 danielk1977 Exp $
           12  +** $Id: btree.c,v 1.678 2009/07/11 13:13:12 drh Exp $
    13     13   **
    14     14   ** This file implements a external (disk-based) database using BTrees.
    15     15   ** See the header comment on "btreeInt.h" for additional information.
    16     16   ** Including a description of file format and an overview of operation.
    17     17   */
    18     18   #include "btreeInt.h"
    19     19   
................................................................................
  6547   6547         return rc;
  6548   6548       }
  6549   6549     }
  6550   6550   
  6551   6551     /* Save the positions of any other cursors open on this table before
  6552   6552     ** making any modifications. Make the page containing the entry to be 
  6553   6553     ** deleted writable. Then free any overflow pages associated with the 
  6554         -  ** entry and finally remove the cell itself from within the page.  */
  6555         -  if( SQLITE_OK!=(rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur))
  6556         -   || SQLITE_OK!=(rc = sqlite3PagerWrite(pPage->pDbPage))
  6557         -   || SQLITE_OK!=(rc = clearCell(pPage, pCell))
  6558         -   || SQLITE_OK!=(rc = dropCell(pPage, iCellIdx, cellSizePtr(pPage, pCell)))
  6559         -  ){
  6560         -    return rc;
  6561         -  }
         6554  +  ** entry and finally remove the cell itself from within the page.  
         6555  +  */
         6556  +  rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
         6557  +  if( rc ) return rc;
         6558  +  rc = sqlite3PagerWrite(pPage->pDbPage);
         6559  +  if( rc ) return rc;
         6560  +  rc = clearCell(pPage, pCell);
         6561  +  if( rc ) return rc;
         6562  +  rc = dropCell(pPage, iCellIdx, cellSizePtr(pPage, pCell));
         6563  +  if( rc ) return rc;
  6562   6564   
  6563   6565     /* If the cell deleted was not located on a leaf page, then the cursor
  6564   6566     ** is currently pointing to the largest entry in the sub-tree headed
  6565   6567     ** by the child-page of the cell that was just deleted from an internal
  6566   6568     ** node. The cell from the leaf node needs to be moved to the internal
  6567   6569     ** node to replace the deleted cell.  */
  6568   6570     if( !pPage->leaf ){
................................................................................
  6574   6576       pCell = findCell(pLeaf, pLeaf->nCell-1);
  6575   6577       nCell = cellSizePtr(pLeaf, pCell);
  6576   6578       assert( MX_CELL_SIZE(pBt)>=nCell );
  6577   6579   
  6578   6580       allocateTempSpace(pBt);
  6579   6581       pTmp = pBt->pTmpSpace;
  6580   6582   
  6581         -    if( SQLITE_OK!=(rc = sqlite3PagerWrite(pLeaf->pDbPage)) 
  6582         -     || SQLITE_OK!=(rc = insertCell(pPage, iCellIdx, pCell-4, nCell+4, pTmp, n))
  6583         -     || SQLITE_OK!=(rc = dropCell(pLeaf, pLeaf->nCell-1, nCell))
  6584         -    ){
  6585         -      return rc;
  6586         -    }
         6583  +    rc = sqlite3PagerWrite(pLeaf->pDbPage);
         6584  +    if( rc ) return rc;
         6585  +    rc = insertCell(pPage, iCellIdx, pCell-4, nCell+4, pTmp, n);
         6586  +    if( rc ) return rc;
         6587  +    rc = dropCell(pLeaf, pLeaf->nCell-1, nCell);
         6588  +    if( rc ) return rc;
  6587   6589     }
  6588   6590   
  6589   6591     /* Balance the tree. If the entry deleted was located on a leaf page,
  6590   6592     ** then the cursor still points to that page. In this case the first
  6591   6593     ** call to balance() repairs the tree, and the if(...) condition is
  6592   6594     ** never true.
  6593   6595     **