/ Check-in [f80497be]
Login

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

Overview
Comment:More optimizations to sqlite3BtreeMovetoUnpacked(). But there are failures in TH3. Committing this intermediate state to facilitate bisecting.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | btree-optimization
Files: files | file ages | folders
SHA1:f80497be446f84d2000e454e32d717887a7d0cee
User & Date: drh 2013-11-25 15:01:38
Context
2013-11-25
16:23
Arrange for sqlite3BtreeMovetoUnpacked() to always leave the cursor cell parse cache invalidated. This fixes issues with previous check-ins on this branch and also runs faster. check-in: a7467560 user: drh tags: btree-optimization
15:01
More optimizations to sqlite3BtreeMovetoUnpacked(). But there are failures in TH3. Committing this intermediate state to facilitate bisecting. check-in: f80497be user: drh tags: btree-optimization
14:10
More improvements to sqlite3BtreeMovetoUnpacked() performance. check-in: 88680698 user: drh tags: btree-optimization
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  4658   4658       ** would have already detected db corruption. Similarly, pPage must
  4659   4659       ** be the right kind (index or table) of b-tree page. Otherwise
  4660   4660       ** a moveToChild() or moveToRoot() call would have detected corruption.  */
  4661   4661       assert( pPage->nCell>0 );
  4662   4662       assert( pPage->intKey==(pIdxKey==0) );
  4663   4663       lwr = 0;
  4664   4664       upr = pPage->nCell-1;
  4665         -    idx = biasRight ? upr : (upr+lwr)/2;
         4665  +    idx = biasRight ? upr : upr/2;
  4666   4666       pCur->aiIdx[pCur->iPage] = (u16)idx;
  4667   4667       pCur->info.nSize = 0;
  4668   4668       if( pPage->intKey ){
  4669   4669         for(;;){
  4670   4670           i64 nCellKey;
  4671   4671           pCell = findCell(pPage, idx) + pPage->childPtrSize;
  4672   4672           if( pPage->hasData ){
  4673   4673             u32 dummy;
  4674   4674             pCell += getVarint32(pCell, dummy);
  4675   4675           }
  4676   4676           getVarint(pCell, (u64*)&nCellKey);
  4677         -        if( nCellKey==intKey ){
         4677  +        if( nCellKey<intKey ){
         4678  +          lwr = idx+1;
         4679  +          if( lwr>upr ){ c = -1; break; }
         4680  +        }else if( nCellKey>intKey ){
         4681  +          upr = idx-1;
         4682  +          if( lwr>upr ){ c = +1; break; }
         4683  +        }else{
         4684  +          assert( nCellKey==intKey );
  4678   4685             pCur->validNKey = 1;
  4679   4686             pCur->info.nKey = nCellKey;
  4680   4687             pCur->aiIdx[pCur->iPage] = (u16)idx;
  4681   4688             if( !pPage->leaf ){
  4682   4689               lwr = idx;
         4690  +            c = 0;
  4683   4691               break;
  4684   4692             }else{
  4685   4693               *pRes = 0;
  4686   4694               rc = SQLITE_OK;
  4687   4695               goto moveto_finish;
  4688   4696             }
  4689         -        }else if( nCellKey<intKey ){
  4690         -          lwr = idx+1;
  4691         -        }else{
  4692         -          assert( nCellKey>intKey );
  4693         -          upr = idx-1;
  4694         -        }
  4695         -        if( lwr>upr ){
  4696         -          c = nCellKey<intKey ? -1 : +1;
  4697         -          pCur->aiIdx[pCur->iPage] = (u16)idx;
  4698         -          break;
  4699   4697           }
  4700   4698           idx = (lwr+upr)/2;
  4701   4699         }
  4702   4700       }else{
  4703   4701         for(;;){
  4704   4702           int nCell;
  4705   4703           pCell = findCell(pPage, idx) + pPage->childPtrSize;
................................................................................
  4748   4746             if( rc ){
  4749   4747               sqlite3_free(pCellKey);
  4750   4748               goto moveto_finish;
  4751   4749             }
  4752   4750             c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
  4753   4751             sqlite3_free(pCellKey);
  4754   4752           }
  4755         -        if( c==0 ){
         4753  +        if( c<0 ){
         4754  +          lwr = idx+1;
         4755  +        }else if( c>0 ){
         4756  +          upr = idx-1;
         4757  +        }else{
         4758  +          assert( c==0 );
  4756   4759             *pRes = 0;
  4757   4760             rc = SQLITE_OK;
  4758   4761             pCur->aiIdx[pCur->iPage] = (u16)idx;
  4759   4762             goto moveto_finish;
  4760   4763           }
  4761         -        if( c<0 ){
  4762         -          lwr = idx+1;
  4763         -        }else{
  4764         -          upr = idx-1;
  4765         -        }
  4766   4764           if( lwr>upr ){
  4767         -          pCur->aiIdx[pCur->iPage] = (u16)idx;
  4768   4765             break;
  4769   4766           }
  4770   4767           idx = (lwr+upr)/2;
  4771   4768         }
  4772   4769       }
  4773   4770       assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
  4774   4771       assert( pPage->isInit );
  4775   4772       if( pPage->leaf ){
  4776   4773         assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
         4774  +      pCur->aiIdx[pCur->iPage] = (u16)idx;
  4777   4775         *pRes = c;
  4778   4776         rc = SQLITE_OK;
  4779   4777         goto moveto_finish;
  4780   4778       }else if( lwr>=pPage->nCell ){
  4781   4779         chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
  4782   4780       }else{
  4783   4781         chldPg = get4byte(findCell(pPage, lwr));