/ Check-in [3eb08439]
Login

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

Overview
Comment:Factor the saveAllCursors() routine of btree.c into two separate routines, for a noticable performance improvement.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3eb084390382c108e9b0ff0b29dede58ebb149bc
User & Date: drh 2014-08-22 22:26:07
Context
2014-08-22
23:33
Another performance tweak: Split the sqlite3BtreeCursorHasMoved() routine into two with the second routine named sqlite3BtreeCursorRestore(). The first now only reports whether or not the cursor has moved and the second tries to restore the cursor. This allows the sqlite3VdbeCursorMoveto() routine to be refactored to avoid stack pointer movements, for a noticable performance gain. check-in: ce123b5c user: drh tags: trunk
22:26
Factor the saveAllCursors() routine of btree.c into two separate routines, for a noticable performance improvement. check-in: 3eb08439 user: drh tags: trunk
21:58
Performance enhancements in the b-tree mutex logic. check-in: 89145306 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

   625    625       pCur->eState = CURSOR_REQUIRESEEK;
   626    626     }
   627    627   
   628    628     invalidateOverflowCache(pCur);
   629    629     return rc;
   630    630   }
   631    631   
          632  +/* Forward reference */
          633  +static int SQLITE_NOINLINE saveCursorsOnList(BtCursor*,Pgno,BtCursor*);
          634  +
   632    635   /*
   633    636   ** Save the positions of all cursors (except pExcept) that are open on
   634         -** the table  with root-page iRoot. Usually, this is called just before cursor
   635         -** pExcept is used to modify the table (BtreeDelete() or BtreeInsert()).
          637  +** the table with root-page iRoot.  "Saving the cursor position" means that
          638  +** the location in the btree is remembered in such a way that it can be
          639  +** moved back to the same spot after the btree has been modified.  This
          640  +** routine is called just before cursor pExcept is used to modify the
          641  +** table, for example in BtreeDelete() or BtreeInsert().
          642  +**
          643  +** Implementation note:  This routine merely checks to see if any cursors
          644  +** need to be saved.  It calls out to saveCursorsOnList() in the (unusual)
          645  +** event that cursors are in need to being saved.
   636    646   */
   637    647   static int saveAllCursors(BtShared *pBt, Pgno iRoot, BtCursor *pExcept){
   638         -  BtCursor *p;
   639    648     assert( sqlite3_mutex_held(pBt->mutex) );
   640    649     assert( pExcept==0 || pExcept->pBt==pBt );
          650  +  BtCursor *p;
   641    651     for(p=pBt->pCursor; p; p=p->pNext){
          652  +    if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ) break;
          653  +  }
          654  +  return p ? saveCursorsOnList(p, iRoot, pExcept) : SQLITE_OK;
          655  +}
          656  +
          657  +/* This helper routine to saveAllCursors does the actual work of saving
          658  +** the cursors if and when a cursor is found that actually requires saving.
          659  +** The common case is that no cursors need to be saved, so this routine is
          660  +** broken out from its caller to avoid unnecessary stack pointer movement.
          661  +*/
          662  +static int SQLITE_NOINLINE saveCursorsOnList(
          663  +  BtCursor *p,           /* The first cursor that needs saving */
          664  +  Pgno iRoot,            /* Only save cursor with this iRoot.  Save all if zero */
          665  +  BtCursor *pExcept      /* Do not save this cursor */
          666  +){
          667  +  do{
   642    668       if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ){
   643    669         if( p->eState==CURSOR_VALID ){
   644    670           int rc = saveCursorPosition(p);
   645    671           if( SQLITE_OK!=rc ){
   646    672             return rc;
   647    673           }
   648    674         }else{
   649    675           testcase( p->iPage>0 );
   650    676           btreeReleaseAllCursorPages(p);
   651    677         }
   652    678       }
   653         -  }
          679  +    p = p->pNext;
          680  +  }while( p );
   654    681     return SQLITE_OK;
   655    682   }
   656    683   
   657    684   /*
   658    685   ** Clear the current cursor position.
   659    686   */
   660    687   void sqlite3BtreeClearCursor(BtCursor *pCur){