/ Check-in [65db822f]
Login

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

Overview
Comment:Performance improvement to the btree search routine.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 65db822f200bafe9abe59b33b17b2c643c17c5e8
User & Date: drh 2011-06-04 01:43:53
Context
2011-06-06
13:38
Add assert() statements to verify that u16 pointers associated with the enhancement in [897f56a158] are always 2-byte aligned. check-in: 98ccfa93 user: drh tags: trunk
2011-06-04
01:43
Performance improvement to the btree search routine. check-in: 65db822f user: drh tags: trunk
2011-06-03
23:28
Performance improvements on memory copies inside of btree by moving 2 bytes at a time instead of just 1 byte at a time. check-in: 897f56a1 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  4449   4449     if( pCur->eState==CURSOR_INVALID ){
  4450   4450       *pRes = -1;
  4451   4451       assert( pCur->apPage[pCur->iPage]->nCell==0 );
  4452   4452       return SQLITE_OK;
  4453   4453     }
  4454   4454     assert( pCur->apPage[0]->intKey || pIdxKey );
  4455   4455     for(;;){
  4456         -    int lwr, upr;
         4456  +    int lwr, upr, idx;
  4457   4457       Pgno chldPg;
  4458   4458       MemPage *pPage = pCur->apPage[pCur->iPage];
  4459   4459       int c;
  4460   4460   
  4461   4461       /* pPage->nCell must be greater than zero. If this is the root-page
  4462   4462       ** the cursor would have been INVALID above and this for(;;) loop
  4463   4463       ** not run. If this is not the root-page, then the moveToChild() routine
................................................................................
  4465   4465       ** be the right kind (index or table) of b-tree page. Otherwise
  4466   4466       ** a moveToChild() or moveToRoot() call would have detected corruption.  */
  4467   4467       assert( pPage->nCell>0 );
  4468   4468       assert( pPage->intKey==(pIdxKey==0) );
  4469   4469       lwr = 0;
  4470   4470       upr = pPage->nCell-1;
  4471   4471       if( biasRight ){
  4472         -      pCur->aiIdx[pCur->iPage] = (u16)upr;
         4472  +      pCur->aiIdx[pCur->iPage] = (u16)(idx = upr);
  4473   4473       }else{
  4474         -      pCur->aiIdx[pCur->iPage] = (u16)((upr+lwr)/2);
         4474  +      pCur->aiIdx[pCur->iPage] = (u16)(idx = (upr+lwr)/2);
  4475   4475       }
  4476   4476       for(;;){
  4477         -      int idx = pCur->aiIdx[pCur->iPage]; /* Index of current cell in pPage */
  4478   4477         u8 *pCell;                          /* Pointer to current cell in pPage */
  4479   4478   
         4479  +      assert( idx==pCur->aiIdx[pCur->iPage] );
  4480   4480         pCur->info.nSize = 0;
  4481   4481         pCell = findCell(pPage, idx) + pPage->childPtrSize;
  4482   4482         if( pPage->intKey ){
  4483   4483           i64 nCellKey;
  4484   4484           if( pPage->hasData ){
  4485   4485             u32 dummy;
  4486   4486             pCell += getVarint32(pCell, dummy);
................................................................................
  4555   4555           lwr = idx+1;
  4556   4556         }else{
  4557   4557           upr = idx-1;
  4558   4558         }
  4559   4559         if( lwr>upr ){
  4560   4560           break;
  4561   4561         }
  4562         -      pCur->aiIdx[pCur->iPage] = (u16)((lwr+upr)/2);
         4562  +      pCur->aiIdx[pCur->iPage] = (u16)(idx = (lwr+upr)/2);
  4563   4563       }
  4564   4564       assert( lwr==upr+1 );
  4565   4565       assert( pPage->isInit );
  4566   4566       if( pPage->leaf ){
  4567   4567         chldPg = 0;
  4568   4568       }else if( lwr>=pPage->nCell ){
  4569   4569         chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);