]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Reduce the overhead of SQLITE_ENABLE_STMT_SCANSTATUS some.
authordan <Dan Kennedy>
Wed, 7 Dec 2022 20:09:54 +0000 (20:09 +0000)
committerdan <Dan Kennedy>
Wed, 7 Dec 2022 20:09:54 +0000 (20:09 +0000)
FossilOrigin-Name: 212927e97e7be7d237de08359dce0dfb9211ac406b32009a6e15afd79c006475

manifest
manifest.uuid
src/vdbe.c
src/vdbe.h
src/vdbeInt.h
src/vdbeapi.c
src/vdbeaux.c

index e1ead94721de0732fd14eaebf67d2f5c1c45b230..bf71b14d9719aa0b16e1757a8dee5339d8cbd5d5 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sharmless\scompiler\swarning\sin\sthe\sdynamic\scontinuation\sprompt\sof\sthe\sCLI.
-D 2022-12-07T19:51:48.626
+C Reduce\sthe\soverhead\sof\sSQLITE_ENABLE_STMT_SCANSTATUS\ssome.
+D 2022-12-07T20:09:54.641
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -717,11 +717,11 @@ F src/upsert.c 5303dc6c518fa7d4b280ec65170f465c7a70b7ac2b22491598f6d0b4875b3145
 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0
 F src/util.c 313f3154e2b85a447326f5dd15de8d31a4df6ab0c3579bd58f426ff634ec9050
 F src/vacuum.c 84ce7f01f8a7a08748e107a441db83bcec13970190ddcb0c9ff522adbc1c23fd
-F src/vdbe.c 8fdef91d3c9bfa363e8eb381d362e2f0cadec456975ec5595c0bfdf65da84e53
-F src/vdbe.h 6d921884cf8ec6a53efba99f8b68e32e955367631743e29039840e781aaf547c
-F src/vdbeInt.h e83be1eea422758d42302941e96e59d93193c373da655a87befdc03a851e0f95
-F src/vdbeapi.c 5e265ab5165b0dfeac55e6a2ad3929d64584c4e7ca106b438137d7596da91348
-F src/vdbeaux.c 0b81f317c86ed9f4ba822af66a52777fed6e8180edc79d4fc62ffe75c8e52d80
+F src/vdbe.c df9ff3fcaa3c60fa9b0bca340c3f3cfc63a51361901ca06fe18bdeadeb2a1a24
+F src/vdbe.h 73b904a6b3bb27f308c6cc287a5751ebc7f1f89456be0ed068a12b92844c6e8c
+F src/vdbeInt.h 8651e4c4e04d1860d0bdcf330cb8294e3778a9d4222be30ce4c490d9220af783
+F src/vdbeapi.c df3f73a4d0a487f2068e3c84776cd6e3fba5ae80ff612659dcfda4307686420b
+F src/vdbeaux.c 25691b395bf57ae0a754570fc3ba2d6f8bd2f0a8944f1d2589b9e68114e01c2b
 F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd
 F src/vdbemem.c 6cfed43758d57b6e3b99d9cdedfeccd86e45a07e427b22d8487cbdbebb6c522a
 F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35
@@ -2067,8 +2067,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 976c23520fa64b39aa54047f2fd12445e65940206768ce51c0d690d0d0d570ab
-R b08d7359f3a0adfc8758cdabe6250a50
-U drh
-Z 38d73aa067c1a85ec056e9ed86a84d61
+P 68947b0a1147365a29e335d5e4dc55fe5d9afe3562a0709b111067d6017c5a42
+R 4a013de93da29e8129599899cb5c1b54
+U dan
+Z 4aecefd86ed6f42fbe2469d178e09d33
 # Remove this line to create a well-formed Fossil manifest.
index 070399b39f9510220a10a47bd731ffcb9bd93daf..01cc2da2affc7704440962fa79e8e42195c2d009 100644 (file)
@@ -1 +1 @@
-68947b0a1147365a29e335d5e4dc55fe5d9afe3562a0709b111067d6017c5a42
\ No newline at end of file
+212927e97e7be7d237de08359dce0dfb9211ac406b32009a6e15afd79c006475
\ No newline at end of file
index cd27aff44f6e3c86371ffda3c7399629f5f27949..12b22992b9499a8a433409cbacf59ab50becb807 100644 (file)
@@ -790,15 +790,12 @@ int sqlite3VdbeExec(
     assert( pOp>=aOp && pOp<&aOp[p->nOp]);
     nVmStep++;
 #if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
-    if( p->anExec ){
-      assert( p->anExec && p->anCycle );
-      p->anExec[(int)(pOp-aOp)]++;
-      pnCycle = &p->anCycle[pOp-aOp];
+    pOp->nExec++;
+    pnCycle = &pOp->nCycle;
 # ifdef VDBE_PROFILE
-      if( sqlite3NProfileCnt==0 )
+    if( sqlite3NProfileCnt==0 )
 # endif
-        *pnCycle -= sqlite3Hwtime();
-    }
+      *pnCycle -= sqlite3Hwtime();
 #endif
 
     /* Only allow tracing if SQLITE_DEBUG is defined.
@@ -7152,10 +7149,6 @@ case OP_Program: {        /* jump */
     pFrame->aOp = p->aOp;
     pFrame->nOp = p->nOp;
     pFrame->token = pProgram->token;
-#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
-    pFrame->anExec = p->anExec;
-    pFrame->anCycle = p->anCycle;
-#endif
 #ifdef SQLITE_DEBUG
     pFrame->iFrameMagic = SQLITE_FRAME_MAGIC;
 #endif
@@ -7192,10 +7185,6 @@ case OP_Program: {        /* jump */
   memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8);
   p->aOp = aOp = pProgram->aOp;
   p->nOp = pProgram->nOp;
-#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
-  p->anExec = 0;
-  p->anCycle = 0;
-#endif
 #ifdef SQLITE_DEBUG
   /* Verify that second and subsequent executions of the same trigger do not
   ** try to reuse register values from the first use. */
@@ -8732,17 +8721,11 @@ default: {          /* This is really OP_Noop, OP_Explain */
     }
 
 #if defined(VDBE_PROFILE)
-    assert( pnCycle );
-    if( pnCycle ){
-      *pnCycle += sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
-      assert( *pnCycle < (((u64)1) << 48) );
-      pnCycle = 0;
-    }
+    *pnCycle += sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
+    pnCycle = 0;
 #elif defined(SQLITE_ENABLE_STMT_SCANSTATUS)
-    if( pnCycle ){
-      *pnCycle += sqlite3Hwtime();
-      pnCycle = 0;
-    }
+    *pnCycle += sqlite3Hwtime();
+    pnCycle = 0;
 #endif
 
     /* The following code adds nothing to the actual functionality
@@ -8819,11 +8802,10 @@ abort_due_to_error:
   ** top. */
 vdbe_return:
 #if defined(VDBE_PROFILE)
-    if( pnCycle ){
-      *pnCycle += sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
-      assert( *pnCycle < (((u64)1) << 48) );
-      pnCycle = 0;
-    }
+  if( pnCycle ){
+    *pnCycle += sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
+    pnCycle = 0;
+  }
 #elif defined(SQLITE_ENABLE_STMT_SCANSTATUS)
   if( pnCycle ){
     *pnCycle += sqlite3Hwtime();
index a199247434e95df90353a7261fdee7ba6725e076..3caf1f787209e13ba28e9c25164f88463e6b4513 100644 (file)
@@ -71,6 +71,10 @@ struct VdbeOp {
   u32 iSrcLine;            /* Source-code line that generated this opcode
                            ** with flags in the upper 8 bits */
 #endif
+#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
+  u64 nExec;
+  u64 nCycle;
+#endif
 };
 typedef struct VdbeOp VdbeOp;
 
index df47e054481be9f306d88079903e61cf68025e0e..cd112e9c4826ba0e1f465157d033fe9186389705 100644 (file)
@@ -171,8 +171,6 @@ struct VdbeFrame {
   Vdbe *v;                /* VM this frame belongs to */
   VdbeFrame *pParent;     /* Parent of this frame, or NULL if parent is main */
   Op *aOp;                /* Program instructions for parent frame */
-  i64 *anExec;            /* Event counters from parent frame */
-  u64 *anCycle;           /* Cycle counters from parent frame */
   Mem *aMem;              /* Array of memory cells for parent frame */
   VdbeCursor **apCsr;     /* Array of Vdbe cursors for parent frame */
   u8 *aOnce;              /* Bitmask used by OP_Once */
@@ -492,10 +490,6 @@ struct Vdbe {
   u32 expmask;            /* Binding to these vars invalidates VM */
   SubProgram *pProgram;   /* Linked list of all sub-programs used by VM */
   AuxData *pAuxData;      /* Linked list of auxdata allocations */
-#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
-  i64 *anExec;            /* Number of times each op has been executed */
-  u64 *anCycle;           /* Sum of sqlite3HwTime() spent in each opcode */
-#endif
 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
   int nScan;              /* Entries in aScan[] */
   ScanStatus *aScan;      /* Scan definitions for sqlite3_stmt_scanstatus() */
index 028eb7fe649f0cca204fe4f7ffd9893a2ba2febe..414745e8ba13e8c7353c3fa2c1417476dec16a8a 100644 (file)
@@ -2123,14 +2123,12 @@ int sqlite3_stmt_scanstatus_v2(
   ScanStatus *pScan;
   int idx;
 
-  /* If the v2 flag is clear, then this function must ignore any ScanStatus
-  ** structures with ScanStatus.addrLoop set to 0. */
   if( iScan<0 ){
     int ii;
     if( iScanStatusOp==SQLITE_SCANSTAT_NCYCLE ){
       i64 res = 0;
       for(ii=0; ii<p->nOp; ii++){
-        res += p->anCycle[ii];
+        res += p->aOp[ii].nCycle;
       }
       *(i64*)pOut = res;
       return 0;
@@ -2141,6 +2139,8 @@ int sqlite3_stmt_scanstatus_v2(
     idx = iScan;
     pScan = &p->aScan[idx];
   }else{
+    /* If the COMPLEX flag is clear, then this function must ignore any 
+    ** ScanStatus structures with ScanStatus.addrLoop set to 0. */
     for(idx=0; idx<p->nScan; idx++){
       pScan = &p->aScan[idx];
       if( pScan->zName ){
@@ -2154,7 +2154,7 @@ int sqlite3_stmt_scanstatus_v2(
   switch( iScanStatusOp ){
     case SQLITE_SCANSTAT_NLOOP: {
       if( pScan->addrLoop>0 ){
-        *(sqlite3_int64*)pOut = p->anExec[pScan->addrLoop];
+        *(sqlite3_int64*)pOut = p->aOp[pScan->addrLoop].nExec;
       }else{
         *(sqlite3_int64*)pOut = -1;
       }
@@ -2162,7 +2162,7 @@ int sqlite3_stmt_scanstatus_v2(
     }
     case SQLITE_SCANSTAT_NVISIT: {
       if( pScan->addrVisit>0 ){
-        *(sqlite3_int64*)pOut = p->anExec[pScan->addrVisit];
+        *(sqlite3_int64*)pOut = p->aOp[pScan->addrVisit].nExec;
       }else{
         *(sqlite3_int64*)pOut = -1;
       }
@@ -2218,7 +2218,7 @@ int sqlite3_stmt_scanstatus_v2(
           if( iIns==0 ) break;
           if( iIns>0 ){
             while( iIns<=iEnd ){
-              res += p->anCycle[iIns];
+              res += p->aOp[iIns].nCycle;
               iIns++;
             }
           }else{
@@ -2229,7 +2229,7 @@ int sqlite3_stmt_scanstatus_v2(
               if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_NCYCLE)==0 ){
                 continue;
               }
-              res += p->anCycle[iOp];
+              res += p->aOp[iOp].nCycle;
             }
           }
         }
@@ -2261,7 +2261,11 @@ int sqlite3_stmt_scanstatus(
 */
 void sqlite3_stmt_scanstatus_reset(sqlite3_stmt *pStmt){
   Vdbe *p = (Vdbe*)pStmt;
-  memset(p->anExec, 0, p->nOp * sizeof(i64));
-  memset(p->anCycle, 0, p->nOp * sizeof(u64));
+  int ii;
+  for(ii=0; ii<p->nOp; ii++){
+    Op *pOp = &p->aOp[ii];
+    pOp->nExec = 0;
+    pOp->nCycle = 0;
+  }
 }
 #endif /* SQLITE_ENABLE_STMT_SCANSTATUS */
index e22b741196678992a41405dbf32b14cbe9dbf0f0..8d284746f13351db451623ff9d98a1742789e0bb 100644 (file)
@@ -262,6 +262,10 @@ int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
   pOp->zComment = 0;
 #endif
+#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
+  pOp->nExec = 0;
+  pOp->nCycle = 0;
+#endif
 #ifdef SQLITE_DEBUG
   if( p->db->flags & SQLITE_VdbeAddopTrace ){
     sqlite3VdbePrintOp(0, i, &p->aOp[i]);
@@ -2508,8 +2512,10 @@ void sqlite3VdbeRewind(Vdbe *p){
   p->iStatement = 0;
   p->nFkConstraint = 0;
 #ifdef VDBE_PROFILE
-  memset(p->anExec, 0, sizeof(i64)*p->nOp);
-  memset(p->anCycle, 0, sizeof(u64)*p->nOp);
+  for(i=0; i<p->nOp; i++){
+    p->aOp[i].nExec = 0;
+    p->aOp[i].nCycle = 0;
+  }
 #endif
 }
 
@@ -2617,10 +2623,6 @@ void sqlite3VdbeMakeReady(
   p->aVar = allocSpace(&x, 0, nVar*sizeof(Mem));
   p->apArg = allocSpace(&x, 0, nArg*sizeof(Mem*));
   p->apCsr = allocSpace(&x, 0, nCursor*sizeof(VdbeCursor*));
-#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
-  p->anExec = allocSpace(&x, 0, p->nOp*sizeof(i64));
-  p->anCycle = allocSpace(&x, 0, p->nOp*sizeof(u64));
-#endif
   if( x.nNeeded ){
     x.pSpace = p->pFree = sqlite3DbMallocRawNN(db, x.nNeeded);
     x.nFree = x.nNeeded;
@@ -2629,10 +2631,6 @@ void sqlite3VdbeMakeReady(
       p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
       p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
       p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
-#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
-      p->anExec = allocSpace(&x, p->anExec, p->nOp*sizeof(i64));
-      p->anCycle = allocSpace(&x, p->anCycle, p->nOp*sizeof(u64));
-#endif
     }
   }
 
@@ -2647,10 +2645,6 @@ void sqlite3VdbeMakeReady(
     p->nMem = nMem;
     initMemArray(p->aMem, nMem, db, MEM_Undefined);
     memset(p->apCsr, 0, nCursor*sizeof(VdbeCursor*));
-#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
-    memset(p->anExec, 0, p->nOp*sizeof(i64));
-    memset(p->anCycle, 0, p->nOp*sizeof(u64));
-#endif
   }
   sqlite3VdbeRewind(p);
 }
@@ -2708,10 +2702,6 @@ static void closeCursorsInFrame(Vdbe *p){
 int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
   Vdbe *v = pFrame->v;
   closeCursorsInFrame(v);
-#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
-  v->anExec = pFrame->anExec;
-  v->anCycle = pFrame->anCycle;
-#endif
   v->aOp = pFrame->aOp;
   v->nOp = pFrame->nOp;
   v->aMem = pFrame->aMem;
@@ -3543,8 +3533,8 @@ int sqlite3VdbeReset(Vdbe *p){
       }
       for(i=0; i<p->nOp; i++){
         char zHdr[100];
-        i64 cnt = p->anExec[i];
-        i64 cycles = p->anCycle[i];
+        i64 cnt = p->aOp[i].nExec;
+        i64 cycles = p->aOp[i].nCycle;
         sqlite3_snprintf(sizeof(zHdr), zHdr, "%6u %12llu %8llu ",
            cnt,
            cycles,