/ Check-in [c7920f55]
Login

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

Overview
Comment:Trivial performance improvement for balance().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | filter-clause
Files: files | file ages | folders
SHA3-256: c7920f5569022f645ec4dbfce8c228880263785c708c2c0ac065e770c438b1d9
User & Date: dan 2019-07-13 09:55:33
Context
2019-07-13
09:56
Merge latest trunk changes into this branch. check-in: 86ab963c user: dan tags: filter-clause
09:55
Trivial performance improvement for balance(). check-in: c7920f55 user: dan tags: filter-clause
2019-07-12
15:15
Minor performance improvement in vdbeRecordCompareString(). check-in: 777fec84 user: dan tags: filter-clause
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  8303   8303     u8 aBalanceQuickSpace[13];
  8304   8304     u8 *pFree = 0;
  8305   8305   
  8306   8306     VVA_ONLY( int balance_quick_called = 0 );
  8307   8307     VVA_ONLY( int balance_deeper_called = 0 );
  8308   8308   
  8309   8309     do {
  8310         -    int iPage = pCur->iPage;
         8310  +    int iPage;
  8311   8311       MemPage *pPage = pCur->pPage;
  8312   8312   
  8313   8313       if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
  8314         -    if( iPage==0 ){
         8314  +    if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
         8315  +      break;
         8316  +    }else if( (iPage = pCur->iPage)==0 ){
  8315   8317         if( pPage->nOverflow ){
  8316   8318           /* The root page of the b-tree is overfull. In this case call the
  8317   8319           ** balance_deeper() function to create a new child for the root-page
  8318   8320           ** and copy the current contents of the root-page to it. The
  8319   8321           ** next iteration of the do-loop will balance the child page.
  8320   8322           */ 
  8321   8323           assert( balance_deeper_called==0 );
................................................................................
  8328   8330             pCur->apPage[0] = pPage;
  8329   8331             pCur->pPage = pCur->apPage[1];
  8330   8332             assert( pCur->pPage->nOverflow );
  8331   8333           }
  8332   8334         }else{
  8333   8335           break;
  8334   8336         }
  8335         -    }else if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
  8336         -      break;
  8337   8337       }else{
  8338   8338         MemPage * const pParent = pCur->apPage[iPage-1];
  8339   8339         int const iIdx = pCur->aiIdx[iPage-1];
  8340   8340   
  8341   8341         rc = sqlite3PagerWrite(pParent->pDbPage);
  8342   8342         if( rc==SQLITE_OK && pParent->nFree<0 ){
  8343   8343           rc = btreeComputeFreeSpace(pParent);