/ Check-in [1e96e5ec]
Login

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

Overview
Comment:Performance optimization in sqlite3VdbeCloseStatement().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1e96e5ec1ee617cb5b5cbdc5a2ee79c8cc35821d
User & Date: drh 2017-01-26 17:11:18
Context
2017-01-26
17:26
Remove the obsolete lastRowid cache from the sqlite3VdbeExec() for a size reduction and performance improvement. check-in: b4803184 user: drh tags: trunk
17:11
Performance optimization in sqlite3VdbeCloseStatement(). check-in: 1e96e5ec user: drh tags: trunk
16:54
Performance optimization to sqlite3_blob_read(). check-in: 7459f4b7 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbeaux.c.

  2493   2493   ** SAVEPOINT_RELEASE. If it is SAVEPOINT_ROLLBACK, then the statement
  2494   2494   ** transaction is rolled back. If eOp is SAVEPOINT_RELEASE, then the 
  2495   2495   ** statement transaction is committed.
  2496   2496   **
  2497   2497   ** If an IO error occurs, an SQLITE_IOERR_XXX error code is returned. 
  2498   2498   ** Otherwise SQLITE_OK.
  2499   2499   */
  2500         -int sqlite3VdbeCloseStatement(Vdbe *p, int eOp){
         2500  +static SQLITE_NOINLINE int vdbeCloseStatement(Vdbe *p, int eOp){
  2501   2501     sqlite3 *const db = p->db;
  2502   2502     int rc = SQLITE_OK;
         2503  +  int i;
         2504  +  const int iSavepoint = p->iStatement-1;
  2503   2505   
  2504         -  /* If p->iStatement is greater than zero, then this Vdbe opened a 
  2505         -  ** statement transaction that should be closed here. The only exception
  2506         -  ** is that an IO error may have occurred, causing an emergency rollback.
  2507         -  ** In this case (db->nStatement==0), and there is nothing to do.
  2508         -  */
  2509         -  if( db->nStatement && p->iStatement ){
  2510         -    int i;
  2511         -    const int iSavepoint = p->iStatement-1;
         2506  +  assert( eOp==SAVEPOINT_ROLLBACK || eOp==SAVEPOINT_RELEASE);
         2507  +  assert( db->nStatement>0 );
         2508  +  assert( p->iStatement==(db->nStatement+db->nSavepoint) );
  2512   2509   
  2513         -    assert( eOp==SAVEPOINT_ROLLBACK || eOp==SAVEPOINT_RELEASE);
  2514         -    assert( db->nStatement>0 );
  2515         -    assert( p->iStatement==(db->nStatement+db->nSavepoint) );
  2516         -
  2517         -    for(i=0; i<db->nDb; i++){ 
  2518         -      int rc2 = SQLITE_OK;
  2519         -      Btree *pBt = db->aDb[i].pBt;
  2520         -      if( pBt ){
  2521         -        if( eOp==SAVEPOINT_ROLLBACK ){
  2522         -          rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_ROLLBACK, iSavepoint);
  2523         -        }
  2524         -        if( rc2==SQLITE_OK ){
  2525         -          rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_RELEASE, iSavepoint);
  2526         -        }
  2527         -        if( rc==SQLITE_OK ){
  2528         -          rc = rc2;
  2529         -        }
  2530         -      }
  2531         -    }
  2532         -    db->nStatement--;
  2533         -    p->iStatement = 0;
  2534         -
  2535         -    if( rc==SQLITE_OK ){
         2510  +  for(i=0; i<db->nDb; i++){ 
         2511  +    int rc2 = SQLITE_OK;
         2512  +    Btree *pBt = db->aDb[i].pBt;
         2513  +    if( pBt ){
  2536   2514         if( eOp==SAVEPOINT_ROLLBACK ){
  2537         -        rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint);
         2515  +        rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_ROLLBACK, iSavepoint);
         2516  +      }
         2517  +      if( rc2==SQLITE_OK ){
         2518  +        rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_RELEASE, iSavepoint);
  2538   2519         }
  2539   2520         if( rc==SQLITE_OK ){
  2540         -        rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint);
         2521  +        rc = rc2;
  2541   2522         }
  2542   2523       }
         2524  +  }
         2525  +  db->nStatement--;
         2526  +  p->iStatement = 0;
  2543   2527   
  2544         -    /* If the statement transaction is being rolled back, also restore the 
  2545         -    ** database handles deferred constraint counter to the value it had when 
  2546         -    ** the statement transaction was opened.  */
         2528  +  if( rc==SQLITE_OK ){
  2547   2529       if( eOp==SAVEPOINT_ROLLBACK ){
  2548         -      db->nDeferredCons = p->nStmtDefCons;
  2549         -      db->nDeferredImmCons = p->nStmtDefImmCons;
         2530  +      rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint);
  2550   2531       }
         2532  +    if( rc==SQLITE_OK ){
         2533  +      rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint);
         2534  +    }
         2535  +  }
         2536  +
         2537  +  /* If the statement transaction is being rolled back, also restore the 
         2538  +  ** database handles deferred constraint counter to the value it had when 
         2539  +  ** the statement transaction was opened.  */
         2540  +  if( eOp==SAVEPOINT_ROLLBACK ){
         2541  +    db->nDeferredCons = p->nStmtDefCons;
         2542  +    db->nDeferredImmCons = p->nStmtDefImmCons;
  2551   2543     }
  2552   2544     return rc;
  2553   2545   }
         2546  +int sqlite3VdbeCloseStatement(Vdbe *p, int eOp){
         2547  +  if( p->db->nStatement && p->iStatement ){
         2548  +    return vdbeCloseStatement(p, eOp);
         2549  +  }
         2550  +  return SQLITE_OK;
         2551  +}
         2552  +
  2554   2553   
  2555   2554   /*
  2556   2555   ** This function is called when a transaction opened by the database 
  2557   2556   ** handle associated with the VM passed as an argument is about to be 
  2558   2557   ** committed. If there are outstanding deferred foreign key constraint
  2559   2558   ** violations, return SQLITE_ERROR. Otherwise, SQLITE_OK.
  2560   2559   **