/ Check-in [0c8b74e668]
Login

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

Overview
Comment:In function moveToRoot(), use the MemPage.pParent pointers to find the root page if they are valid. This is slightly faster than requesting a new reference to the root page from the pager layer. (CVS 5725)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0c8b74e668b7462c5439c04993d1d7cd74210075
User & Date: danielk1977 2008-09-19 16:39:38
Context
2008-09-19
18:32
Speed up releaseMemArray() a bit by handling the most common types of memory cells inline. (CVS 5726) check-in: ce07508550 user: danielk1977 tags: trunk
16:39
In function moveToRoot(), use the MemPage.pParent pointers to find the root page if they are valid. This is slightly faster than requesting a new reference to the root page from the pager layer. (CVS 5725) check-in: 0c8b74e668 user: danielk1977 tags: trunk
15:10
In sqlite3BtreeGetMeta(), if BtShared.pPage1 is available use it instead of requesting a new reference from the pager layer. (CVS 5724) check-in: 59be34cfa4 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.515 2008/09/19 15:10:58 danielk1977 Exp $
           12  +** $Id: btree.c,v 1.516 2008/09/19 16:39:38 danielk1977 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   
................................................................................
  3560   3560     if( pCur->eState>=CURSOR_REQUIRESEEK ){
  3561   3561       if( pCur->eState==CURSOR_FAULT ){
  3562   3562         return pCur->skip;
  3563   3563       }
  3564   3564       clearCursorPosition(pCur);
  3565   3565     }
  3566   3566     pRoot = pCur->pPage;
  3567         -  if( pRoot && pRoot->pgno==pCur->pgnoRoot ){
         3567  +  if( pRoot && pRoot->isInit ){
         3568  +    /* If the page the cursor is currently pointing to is fully initialized,
         3569  +    ** then the root page can be found by following the MemPage.pParent
         3570  +    ** pointers. This is faster than requesting a reference to the root
         3571  +    ** page from the pager layer.
         3572  +    */
         3573  +    while( pRoot->pParent ){
         3574  +      assert( pRoot->isInit==PAGE_ISINIT_FULL );
         3575  +      pRoot = pRoot->pParent;
         3576  +    }
  3568   3577       assert( pRoot->isInit==PAGE_ISINIT_FULL );
         3578  +    if( pRoot!=pCur->pPage ){
         3579  +      sqlite3PagerRef(pRoot->pDbPage);
         3580  +      releasePage(pCur->pPage);
         3581  +      pCur->pPage = pRoot;
         3582  +    }
  3569   3583     }else{
  3570   3584       if( 
  3571   3585         SQLITE_OK!=(rc = getAndInitPage(pBt, pCur->pgnoRoot, &pRoot, 0))
  3572   3586       ){
  3573   3587         pCur->eState = CURSOR_INVALID;
  3574   3588         return rc;
  3575   3589       }
  3576   3590       releasePage(pCur->pPage);
  3577   3591       pCur->pPage = pRoot;
  3578   3592     }
         3593  +  assert( pCur->pPage->pgno==pCur->pgnoRoot );
  3579   3594     pCur->idx = 0;
  3580   3595     pCur->info.nSize = 0;
  3581   3596     pCur->atLast = 0;
  3582   3597     pCur->validNKey = 0;
  3583   3598     if( pRoot->nCell==0 && !pRoot->leaf ){
  3584   3599       Pgno subpage;
  3585   3600       assert( pRoot->pgno==1 );
................................................................................
  3740   3755         return SQLITE_OK;
  3741   3756       }
  3742   3757       if( pCur->atLast && pCur->info.nKey<intKey ){
  3743   3758         *pRes = -1;
  3744   3759         return SQLITE_OK;
  3745   3760       }
  3746   3761     }
  3747         -
  3748   3762   
  3749   3763     rc = moveToRoot(pCur);
  3750   3764     if( rc ){
  3751   3765       return rc;
  3752   3766     }
  3753   3767     assert( pCur->pPage );
  3754   3768     assert( pCur->pPage->isInit==PAGE_ISINIT_FULL );
................................................................................
  6468   6482     rc = queryTableLock(p, 1, READ_LOCK);
  6469   6483     if( rc!=SQLITE_OK ){
  6470   6484       sqlite3BtreeLeave(p);
  6471   6485       return rc;
  6472   6486     }
  6473   6487   
  6474   6488     assert( idx>=0 && idx<=15 );
  6475         -  if( !pBt->pPage1 ){
         6489  +  if( pBt->pPage1 ){
         6490  +    /* The b-tree is already holding a reference to page 1 of the database
         6491  +    ** file. In this case the required meta-data value can be read directly
         6492  +    ** from the page data of this reference. This is slightly faster than
         6493  +    ** requesting a new reference from the pager layer.
         6494  +    */
         6495  +    pP1 = (unsigned char *)pBt->pPage1->aData;
         6496  +  }else{
         6497  +    /* The b-tree does not have a reference to page 1 of the database file.
         6498  +    ** Obtain one from the pager layer.
         6499  +    */
  6476   6500       rc = sqlite3PagerGet(pBt->pPager, 1, &pDbPage);
  6477   6501       if( rc ){
  6478   6502         sqlite3BtreeLeave(p);
  6479   6503         return rc;
  6480   6504       }
  6481   6505       pP1 = (unsigned char *)sqlite3PagerGetData(pDbPage);
  6482         -  }else{
  6483         -    pP1 = (unsigned char *)pBt->pPage1->aData;
  6484   6506     }
  6485   6507     *pMeta = get4byte(&pP1[36 + idx*4]);
  6486   6508   
         6509  +  /* If the b-tree is not holding a reference to page 1, then one was 
         6510  +  ** requested from the pager layer in the above block. Release it now.
         6511  +  */
  6487   6512     if( !pBt->pPage1 ){
  6488   6513       sqlite3PagerUnref(pDbPage);
  6489   6514     }
  6490   6515   
  6491   6516     /* If autovacuumed is disabled in this build but we are trying to 
  6492   6517     ** access an autovacuumed database, then make the database readonly. 
  6493   6518     */