/ Check-in [bfde3dae]
Login

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

Overview
Comment:Make sure the nOverflow flag in MemPage is reset to zero after every insert. (CVS 5983)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: bfde3dae0c7b97308344519ca06cd4b290e8cf47
User & Date: drh 2008-12-05 20:01:43
Context
2008-12-05
22:40
Fix integrity check so that it always reports memory allocation errors that it encounters. (CVS 5984) check-in: 2a3f5ce1 user: drh tags: trunk
20:01
Make sure the nOverflow flag in MemPage is reset to zero after every insert. (CVS 5983) check-in: bfde3dae user: drh tags: trunk
17:17
Fix harmless compiler warnings. Improved comments in the query optimizer. (CVS 5982) check-in: adedd697 user: drh 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.543 2008/11/27 02:22:11 drh Exp $
           12  +** $Id: btree.c,v 1.544 2008/12/05 20:01:43 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   
................................................................................
  5533   5533     sqlite3ScratchFree(apCell);
  5534   5534     for(i=0; i<nOld; i++){
  5535   5535       releasePage(apOld[i]);
  5536   5536     }
  5537   5537     for(i=0; i<nNew; i++){
  5538   5538       releasePage(apNew[i]);
  5539   5539     }
         5540  +  pPage->nOverflow = 0;
  5540   5541   
  5541   5542     /* releasePage(pParent); */
  5542   5543     TRACE(("BALANCE: finished with %d: old=%d new=%d cells=%d\n",
  5543   5544             pPage->pgno, nOld, nNew, nCell));
  5544   5545   
  5545   5546     return rc;
  5546   5547   }
................................................................................
  5606   5607             szCell[i] = cellSizePtr(pChild, apCell[i]);
  5607   5608           }
  5608   5609           assemblePage(pPage, pChild->nCell, apCell, szCell);
  5609   5610           /* Copy the right-pointer of the child to the parent. */
  5610   5611           assert( sqlite3PagerIswriteable(pPage->pDbPage) );
  5611   5612           put4byte(&pPage->aData[pPage->hdrOffset+8], 
  5612   5613               get4byte(&pChild->aData[pChild->hdrOffset+8]));
  5613         -        freePage(pChild);
         5614  +        rc = freePage(pChild);
  5614   5615           TRACE(("BALANCE: child %d transfer to page 1\n", pChild->pgno));
  5615   5616         }else{
  5616   5617           /* The child has more information that will fit on the root.
  5617   5618           ** The tree is already balanced.  Do nothing. */
  5618   5619           TRACE(("BALANCE: child %d will not fit on page 1\n", pChild->pgno));
  5619   5620         }
  5620   5621       }else{
................................................................................
  5624   5625         assert( rc==SQLITE_OK );
  5625   5626         freePage(pChild);
  5626   5627         TRACE(("BALANCE: transfer child %d into root %d\n",
  5627   5628                 pChild->pgno, pPage->pgno));
  5628   5629       }
  5629   5630       assert( pPage->nOverflow==0 );
  5630   5631   #ifndef SQLITE_OMIT_AUTOVACUUM
  5631         -    if( ISAUTOVACUUM ){
         5632  +    if( ISAUTOVACUUM && rc==SQLITE_OK ){
  5632   5633         rc = setChildPtrmaps(pPage);
  5633   5634       }
  5634   5635   #endif
  5635   5636       releasePage(pChild);
  5636   5637     }
  5637   5638   end_shallow_balance:
  5638   5639     sqlite3_free(apCell);
................................................................................
  5730   5731     MemPage *pPage = pCur->apPage[pCur->iPage];
  5731   5732   
  5732   5733     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  5733   5734     if( pCur->iPage==0 ){
  5734   5735       rc = sqlite3PagerWrite(pPage->pDbPage);
  5735   5736       if( rc==SQLITE_OK && pPage->nOverflow>0 ){
  5736   5737         rc = balance_deeper(pCur);
         5738  +      assert( pPage->nOverflow==0 || rc!=SQLITE_OK );
  5737   5739       }
  5738   5740       if( rc==SQLITE_OK && pPage->nCell==0 ){
  5739   5741         rc = balance_shallower(pCur);
         5742  +      assert( pPage->nOverflow==0 || rc!=SQLITE_OK );
  5740   5743       }
  5741   5744     }else{
  5742   5745       if( pPage->nOverflow>0 || 
  5743   5746           (!isInsert && pPage->nFree>pPage->pBt->usableSize*2/3) ){
  5744   5747         rc = balance_nonroot(pCur);
         5748  +      assert( pPage->nOverflow==0 || rc!=SQLITE_OK );
  5745   5749       }
  5746   5750     }
  5747   5751     return rc;
  5748   5752   }
  5749   5753   
  5750   5754   /*
  5751   5755   ** This routine checks all cursors that point to table pgnoRoot.
................................................................................
  5906   5910       idx = ++pCur->aiIdx[pCur->iPage];
  5907   5911       pCur->info.nSize = 0;
  5908   5912       pCur->validNKey = 0;
  5909   5913     }else{
  5910   5914       assert( pPage->leaf );
  5911   5915     }
  5912   5916     rc = insertCell(pPage, idx, newCell, szNew, 0, 0);
  5913         -  if( rc!=SQLITE_OK ) goto end_insert;
  5914         -  rc = balance(pCur, 1);
         5917  +  if( rc==SQLITE_OK ){
         5918  +    rc = balance(pCur, 1);
         5919  +  }
         5920  +
         5921  +  /* Must make sure nOverflow is reset to zero even if the balance()
         5922  +  ** fails.  Internal data structure corruption will result otherwise. */
         5923  +  assert( pPage->nOverflow==0 || rc!=SQLITE_OK );
         5924  +  pPage->nOverflow = 0;
         5925  +
  5915   5926     if( rc==SQLITE_OK ){
  5916   5927       moveToRoot(pCur);
  5917   5928     }
  5918   5929   end_insert:
  5919   5930     return rc;
  5920   5931   }
  5921   5932