/ Check-in [b5842a70]
Login

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

Overview
Comment:Performance optimization to the moveToRoot() subroutine in btree.c.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:b5842a70f8e26456a8f0d39539bc266f097480a4
User & Date: drh 2013-12-06 23:25:27
Context
2013-12-07
16:56
At the start of each journaled write transaction, check to see if the database file has been moved, and if it has refuse to start the transaction, returning an SQLITE_READONLY_DBMOVED error code. Writing to a moved or renamed database is still allowed when journal_mode is OFF or MEMORY. check-in: 369a23e0 user: drh tags: trunk
2013-12-06
23:25
Performance optimization to the moveToRoot() subroutine in btree.c. check-in: b5842a70 user: drh tags: trunk
22:45
Use memcmp() instead of the BINARY collating function where possible, for a performance boost. check-in: c5a3a1af user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  4391   4391   ** indicating a table b-tree, or if the caller did specify a KeyInfo 
  4392   4392   ** structure the flags byte is set to 0x02 or 0x0A, indicating an index
  4393   4393   ** b-tree).
  4394   4394   */
  4395   4395   static int moveToRoot(BtCursor *pCur){
  4396   4396     MemPage *pRoot;
  4397   4397     int rc = SQLITE_OK;
  4398         -  Btree *p = pCur->pBtree;
  4399         -  BtShared *pBt = p->pBt;
  4400   4398   
  4401   4399     assert( cursorHoldsMutex(pCur) );
  4402   4400     assert( CURSOR_INVALID < CURSOR_REQUIRESEEK );
  4403   4401     assert( CURSOR_VALID   < CURSOR_REQUIRESEEK );
  4404   4402     assert( CURSOR_FAULT   > CURSOR_REQUIRESEEK );
  4405   4403     if( pCur->eState>=CURSOR_REQUIRESEEK ){
  4406   4404       if( pCur->eState==CURSOR_FAULT ){
................................................................................
  4407   4405         assert( pCur->skipNext!=SQLITE_OK );
  4408   4406         return pCur->skipNext;
  4409   4407       }
  4410   4408       sqlite3BtreeClearCursor(pCur);
  4411   4409     }
  4412   4410   
  4413   4411     if( pCur->iPage>=0 ){
  4414         -    int i;
  4415         -    for(i=1; i<=pCur->iPage; i++){
  4416         -      releasePage(pCur->apPage[i]);
  4417         -    }
  4418         -    pCur->iPage = 0;
         4412  +    while( pCur->iPage ) releasePage(pCur->apPage[pCur->iPage--]);
  4419   4413     }else if( pCur->pgnoRoot==0 ){
  4420   4414       pCur->eState = CURSOR_INVALID;
  4421   4415       return SQLITE_OK;
  4422   4416     }else{
  4423         -    rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0],
         4417  +    rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0],
  4424   4418                           pCur->wrFlag==0 ? PAGER_GET_READONLY : 0);
  4425   4419       if( rc!=SQLITE_OK ){
  4426   4420         pCur->eState = CURSOR_INVALID;
  4427   4421         return rc;
  4428   4422       }
  4429   4423       pCur->iPage = 0;
  4430   4424   
................................................................................
  4449   4443     assert( pRoot->isInit && (pCur->pKeyInfo==0)==pRoot->intKey );
  4450   4444   
  4451   4445     pCur->aiIdx[0] = 0;
  4452   4446     pCur->info.nSize = 0;
  4453   4447     pCur->atLast = 0;
  4454   4448     pCur->validNKey = 0;
  4455   4449   
  4456         -  if( pRoot->nCell==0 && !pRoot->leaf ){
         4450  +  if( pRoot->nCell>0 ){
         4451  +    pCur->eState = CURSOR_VALID;
         4452  +  }else if( !pRoot->leaf ){
  4457   4453       Pgno subpage;
  4458   4454       if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT;
  4459   4455       subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]);
  4460   4456       pCur->eState = CURSOR_VALID;
  4461   4457       rc = moveToChild(pCur, subpage);
  4462   4458     }else{
  4463         -    pCur->eState = ((pRoot->nCell>0)?CURSOR_VALID:CURSOR_INVALID);
         4459  +    pCur->eState = CURSOR_INVALID;
  4464   4460     }
  4465   4461     return rc;
  4466   4462   }
  4467   4463   
  4468   4464   /*
  4469   4465   ** Move the cursor down to the left-most leaf entry beneath the
  4470   4466   ** entry to which it is currently pointing.