/ Check-in [f1366bab]
Login

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

Overview
Comment:Add a new (experimental) sqlite3_stmt_status() verb that returns the number of VM steps.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | status-vm-step
Files: files | file ages | folders
SHA1: f1366bab737a3ac2ea20a0ec014cc306d7ded8a5
User & Date: drh 2013-06-25 22:01:22
Context
2013-06-26
13:22
Add the SQLITE_STMTSTATUS_VM_STEPS option for sqlite3_stmt_status(). check-in: bd4267f1 user: drh tags: trunk
2013-06-25
22:01
Add a new (experimental) sqlite3_stmt_status() verb that returns the number of VM steps. Closed-Leaf check-in: f1366bab user: drh tags: status-vm-step
2013-06-21
18:36
Remove an unused function declaration from the FTS3 source code. check-in: 096ae1d8 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.

  1105   1105     if( pArg && pArg->out && db && pArg->pStmt ){
  1106   1106       iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, bReset);
  1107   1107       fprintf(pArg->out, "Fullscan Steps:                      %d\n", iCur);
  1108   1108       iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
  1109   1109       fprintf(pArg->out, "Sort Operations:                     %d\n", iCur);
  1110   1110       iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, bReset);
  1111   1111       fprintf(pArg->out, "Autoindex Inserts:                   %d\n", iCur);
         1112  +    iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
         1113  +    fprintf(pArg->out, "Virtual Machine Steps:               %d\n", iCur);
  1112   1114     }
  1113   1115   
  1114   1116     return 0;
  1115   1117   }
  1116   1118   
  1117   1119   /*
  1118   1120   ** Execute a statement or set of statements.  Print 

Changes to src/sqlite.h.in.

  6299   6299   **
  6300   6300   ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
  6301   6301   ** <dd>^This is the number of rows inserted into transient indices that
  6302   6302   ** were created automatically in order to help joins run faster.
  6303   6303   ** A non-zero value in this counter may indicate an opportunity to
  6304   6304   ** improvement performance by adding permanent indices that do not
  6305   6305   ** need to be reinitialized each time the statement is run.</dd>
         6306  +**
         6307  +** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
         6308  +** <dd>^This is the number of virtual machine operations executed
         6309  +** by the prepared statement if that number is less than or equal
         6310  +** to 2147483647.  The number of virtual machine operations can be 
         6311  +** used as a proxy for the total work done by the prepared statement.
         6312  +** If the number of virtual machine operations exceeds 2147483647
         6313  +** then the value returned by this statement status code is undefined.
         6314  +** </dd>
  6306   6315   ** </dl>
  6307   6316   */
  6308   6317   #define SQLITE_STMTSTATUS_FULLSCAN_STEP     1
  6309   6318   #define SQLITE_STMTSTATUS_SORT              2
  6310   6319   #define SQLITE_STMTSTATUS_AUTOINDEX         3
         6320  +#define SQLITE_STMTSTATUS_VM_STEP           4
  6311   6321   
  6312   6322   /*
  6313   6323   ** CAPI3REF: Custom Page Cache Object
  6314   6324   **
  6315   6325   ** The sqlite3_pcache type is opaque.  It is implemented by
  6316   6326   ** the pluggable module.  The SQLite core has no knowledge of
  6317   6327   ** its size or internal structure and never deals with the

Changes to src/test1.c.

  2214   2214     static const struct {
  2215   2215       const char *zName;
  2216   2216       int op;
  2217   2217     } aOp[] = {
  2218   2218       { "SQLITE_STMTSTATUS_FULLSCAN_STEP",   SQLITE_STMTSTATUS_FULLSCAN_STEP   },
  2219   2219       { "SQLITE_STMTSTATUS_SORT",            SQLITE_STMTSTATUS_SORT            },
  2220   2220       { "SQLITE_STMTSTATUS_AUTOINDEX",       SQLITE_STMTSTATUS_AUTOINDEX       },
         2221  +    { "SQLITE_STMTSTATUS_VM_STEP",         SQLITE_STMTSTATUS_VM_STEP         },
  2221   2222     };
  2222   2223     if( objc!=4 ){
  2223   2224       Tcl_WrongNumArgs(interp, 1, objv, "STMT PARAMETER RESETFLAG");
  2224   2225       return TCL_ERROR;
  2225   2226     }
  2226   2227     if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
  2227   2228     zOpName = Tcl_GetString(objv[2]);

Changes to src/vdbe.c.

   552    552     sqlite3 *db = p->db;       /* The database */
   553    553     u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
   554    554     u8 encoding = ENC(db);     /* The database encoding */
   555    555   #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
   556    556     int checkProgress;         /* True if progress callbacks are enabled */
   557    557     int nProgressOps = 0;      /* Opcodes executed since progress callback. */
   558    558   #endif
          559  +  int iCompare = 0;          /* Result of last OP_Compare operation */
          560  +  unsigned nVmStep = 0;      /* Number of virtual machine steps */
   559    561     Mem *aMem = p->aMem;       /* Copy of p->aMem */
   560    562     Mem *pIn1 = 0;             /* 1st input operand */
   561    563     Mem *pIn2 = 0;             /* 2nd input operand */
   562    564     Mem *pIn3 = 0;             /* 3rd input operand */
   563    565     Mem *pOut = 0;             /* Output operand */
   564         -  int iCompare = 0;          /* Result of last OP_Compare operation */
   565    566     int *aPermute = 0;         /* Permutation of columns for OP_Compare */
   566    567     i64 lastRowid = db->lastRowid;  /* Saved value of the last insert ROWID */
   567    568   #ifdef VDBE_PROFILE
   568    569     u64 start;                 /* CPU clock count at start of opcode */
   569    570     int origPc;                /* Program counter at start of opcode */
   570    571   #endif
   571    572     /*** INSERT STACK UNION HERE ***/
................................................................................
   602    603     for(pc=p->pc; rc==SQLITE_OK; pc++){
   603    604       assert( pc>=0 && pc<p->nOp );
   604    605       if( db->mallocFailed ) goto no_mem;
   605    606   #ifdef VDBE_PROFILE
   606    607       origPc = pc;
   607    608       start = sqlite3Hwtime();
   608    609   #endif
          610  +    nVmStep++;
   609    611       pOp = &aOp[pc];
   610    612   
   611    613       /* Only allow tracing if SQLITE_DEBUG is defined.
   612    614       */
   613    615   #ifdef SQLITE_DEBUG
   614    616       if( p->trace ){
   615    617         if( pc==0 ){
................................................................................
  6196   6198     }
  6197   6199   
  6198   6200     /* This is the only way out of this procedure.  We have to
  6199   6201     ** release the mutexes on btrees that were acquired at the
  6200   6202     ** top. */
  6201   6203   vdbe_return:
  6202   6204     db->lastRowid = lastRowid;
         6205  +  p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1] += (int)nVmStep;
  6203   6206     sqlite3VdbeLeave(p);
  6204   6207     return rc;
  6205   6208   
  6206   6209     /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
  6207   6210     ** is encountered.
  6208   6211     */
  6209   6212   too_big:

Changes to src/vdbeInt.h.

   340    340     bft readOnly:1;         /* True for read-only statements */
   341    341     bft isPrepareV2:1;      /* True if prepared with prepare_v2() */
   342    342     bft doingRerun:1;       /* True if rerunning after an auto-reprepare */
   343    343     int nChange;            /* Number of db changes made since last reset */
   344    344     yDbMask btreeMask;      /* Bitmask of db->aDb[] entries referenced */
   345    345     yDbMask lockMask;       /* Subset of btreeMask that requires a lock */
   346    346     int iStatement;         /* Statement number (or 0 if has not opened stmt) */
   347         -  int aCounter[3];        /* Counters used by sqlite3_stmt_status() */
          347  +  int aCounter[4];        /* Counters used by sqlite3_stmt_status() */
   348    348   #ifndef SQLITE_OMIT_TRACE
   349    349     i64 startTime;          /* Time when query started - used for profiling */
   350    350   #endif
   351    351     i64 nFkConstraint;      /* Number of imm. FK constraints this VM */
   352    352     i64 nStmtDefCons;       /* Number of def. constraints when stmt started */
   353    353     char *zSql;             /* Text of the SQL statement that generated this */
   354    354     void *pFree;            /* Free this when deleting the vdbe */