]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Display scanstatus results in neat columns.
authordrh <>
Wed, 4 Feb 2026 20:51:27 +0000 (20:51 +0000)
committerdrh <>
Wed, 4 Feb 2026 20:51:27 +0000 (20:51 +0000)
FossilOrigin-Name: c476d956d0bd3065cf894de6f9d393b999ff7d2268a35f01a6d88804789ab58f

ext/qrf/qrf.c
manifest
manifest.uuid

index 9ab593b9545d9ad360ced1a5c64d909debd24a8f..ab6b898097a210c022b65aca6437932f1f29b4d7 100644 (file)
@@ -35,7 +35,8 @@ typedef struct qrfEQPGraph qrfEQPGraph;
 struct qrfEQPGraph {
   qrfEQPGraphRow *pRow;  /* Linked list of all rows of the EQP output */
   qrfEQPGraphRow *pLast; /* Last element of the pRow list */
-  char zPrefix[100];     /* Graph prefix */
+  int nWidth;            /* Width of the graph */
+  char zPrefix[400];     /* Graph prefix */
 };
 
 /*
@@ -235,20 +236,20 @@ static void qrfEqpRenderLevel(Qrf *p, int iEqpId){
 ** pOut.
 **
 **   +  Only show the first three significant digits.
-**   +  Append suffixes K, M, G, or T for 1e3, 1e6, 1e9, 1e12
+**   +  Append suffixes K, M, G, T, P, and E for 1e3, 1e6, ... 1e18
 */
 static void qrfApproxInt64(sqlite3_str *pOut, i64 N){
-  static const char aSuffix[] = { 'K', 'M', 'G', 'T' };
+  static const char aSuffix[] = { 'K', 'M', 'G', 'T', 'P', 'E' };
   int i;
   if( N<0 ){
     N = N==INT64_MIN ? INT64_MAX : -N;
     sqlite3_str_append(pOut, "-", 1);
   }
   if( N<10000 ){
-    sqlite3_str_appendf(pOut, "%lld", N);
+    sqlite3_str_appendf(pOut, "%4lld ", N);
     return;
   }
-  for(i=1; i<=12; i++){
+  for(i=1; i<=18; i++){
     N = (N+5)/10;
     if( N<10000 ){
       int n = (int)N;
@@ -257,35 +258,16 @@ static void qrfApproxInt64(sqlite3_str *pOut, i64 N){
           sqlite3_str_appendf(pOut, "%d.%02d", n/1000, (n%1000)/10);
           break;
         case 1:
-          sqlite3_str_appendf(pOut, "%d.%d", n/100, (n%100)/10);
+          sqlite3_str_appendf(pOut, "%2d.%d", n/100, (n%100)/10);
           break;
         case 2:
-          sqlite3_str_appendf(pOut, "%d", n/10);
+          sqlite3_str_appendf(pOut, "%4d", n/10);
           break;
       }
       sqlite3_str_append(pOut, &aSuffix[i/3], 1);
-      return;
+      break;
     }
   }
-  sqlite3_str_appendf(pOut, "%lldT", N);
-}
-
-/*
-** Render a double r into pOut for use in scan-stats reporting.
-**
-** If r is greater than or equal to 1000, then render using qrfApproxInt64.
-** Otherwise render using %.1g.
-*/
-static void qrfApproxDouble(sqlite3_str *pOut, double r){
-  if( r<0.0 ){
-    sqlite3_str_append(pOut, "-", 1);
-    r = -r;
-  }
-  if( r>=1000.0 ){
-    qrfApproxInt64(pOut, (i64)r);
-  }else{
-    sqlite3_str_appendf(pOut, "%.1g", r);
-  }
 }
 
 /*
@@ -303,9 +285,26 @@ static void qrfEqpRender(Qrf *p, i64 nCycle){
       p->u.pGraph->pRow = pRow->pNext;
       sqlite3_free(pRow);
     }else if( nCycle>0 ){
-      sqlite3_str_appendf(p->pOut, "QUERY PLAN (cycles=");
+      int nSp = p->u.pGraph->nWidth - 2;
+      if( p->spec.eStyle==QRF_STYLE_StatsEst ){
+        sqlite3_str_appendchar(p->pOut, nSp, ' ');
+        sqlite3_str_appendall(p->pOut,
+                                "Cycles      Loops  (est)  Rows   (est)\n");
+        sqlite3_str_appendchar(p->pOut, nSp, ' ');
+        sqlite3_str_appendall(p->pOut,
+                                "----------  ------------  ------------\n");
+      }else{
+        sqlite3_str_appendchar(p->pOut, nSp, ' ');
+        sqlite3_str_appendall(p->pOut,
+                                "Cycles      Loops  Rows \n");
+        sqlite3_str_appendchar(p->pOut, nSp, ' ');
+        sqlite3_str_appendall(p->pOut,
+                                "----------  -----  -----\n");
+      }
+      sqlite3_str_appendall(p->pOut, "QUERY PLAN");
+      sqlite3_str_appendchar(p->pOut, nSp - 10, ' ');
       qrfApproxInt64(p->pOut, nCycle);
-      sqlite3_str_appendf(p->pOut, " [100%%])\n");
+      sqlite3_str_appendall(p->pOut, " 100%\n");
     }else{
       sqlite3_str_appendall(p->pOut, "QUERY PLAN\n");
     }
@@ -375,7 +374,7 @@ static void qrfEqpStats(Qrf *p){
     n = (int)strlen(z) + qrfStatsHeight(pS,i)*3;
     if( n>nWidth ) nWidth = n;
   }
-  nWidth += 4;
+  nWidth += 2;
 
   sqlite3_stmt_scanstatus_v2(pS,-1, SQLITE_SCANSTAT_NCYCLE, f, (void*)&nTotal);
   for(i=0; 1; i++){
@@ -405,38 +404,35 @@ static void qrfEqpStats(Qrf *p){
     sqlite3_stmt_scanstatus_v2(pS,i, SQLITE_SCANSTAT_NAME,f,(void*)&zName);
 
     if( nCycle>=0 || nLoop>=0 || nRow>=0 ){
-      const char *zSp = "";
+      int nSp = 0;
       sqlite3_str_reset(pStats);
       if( nCycle>=0 && nTotal>0 ){
-        sqlite3_str_appendf(pStats, "cycles=");
         qrfApproxInt64(pStats, nCycle);
-        sqlite3_str_appendf(pStats, " [%d%%]",
+        sqlite3_str_appendf(pStats, " %3d%%",
             ((nCycle*100)+nTotal/2) / nTotal
         );
-        zSp = " ";
+        nSp = 2;
       }
       if( nLoop>=0 ){
-        sqlite3_str_appendf(pStats, "%sloops=", zSp);
+        if( nSp ) sqlite3_str_appendchar(pStats, nSp, ' ');
         qrfApproxInt64(pStats, nLoop);
-        zSp = " ";
+        nSp = 2;
         if( p->spec.eStyle==QRF_STYLE_StatsEst ){
-          sqlite3_str_appendf(pStats, " [est ");
-          qrfApproxDouble(pStats, rEstCum/rEst);
-          sqlite3_str_appendf(pStats, "]");
+          sqlite3_str_appendf(pStats, "  ");
+          qrfApproxInt64(pStats, (i64)(rEstCum/rEst));
         }
       }
       if( nRow>=0 ){
-        sqlite3_str_appendf(pStats, "%srows=", zSp);
+        if( nSp ) sqlite3_str_appendchar(pStats, nSp, ' ');
         qrfApproxInt64(pStats, nRow);
-        zSp = " ";
+        nSp = 2;
         if( p->spec.eStyle==QRF_STYLE_StatsEst ){
-          sqlite3_str_appendf(pStats, " [est ");
-          qrfApproxDouble(pStats, rEstCum);
-          sqlite3_str_appendf(pStats, "]");
+          sqlite3_str_appendf(pStats, "  ");
+          qrfApproxInt64(pStats, (i64)rEstCum);
         }
       }
       sqlite3_str_appendf(pLine,
-          "% *s (%s)", -1*(nWidth-qrfStatsHeight(pS,i)*3), zo,
+          "% *s %s", -1*(nWidth-qrfStatsHeight(pS,i)*3), zo,
           sqlite3_str_value(pStats)
       );
       sqlite3_str_reset(pStats);
@@ -446,6 +442,7 @@ static void qrfEqpStats(Qrf *p){
       qrfEqpAppend(p, iId, iPid, zo);
     }
   }
+  if( p->u.pGraph ) p->u.pGraph->nWidth = nWidth;
   qrfStrErr(p, pLine);
   sqlite3_free(sqlite3_str_finish(pLine));
   qrfStrErr(p, pStats);
index f23749e71d302ac32b1d8037ce2b11f86fd62105..0cee9e9621ad70c7d29891ae1753f7341cf58e48 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Improved\soutput\sfor\s".scanstatus\sest"\sin\sthe\sCLI.
-D 2026-02-04T18:10:49.143
+C Display\sscanstatus\sresults\sin\sneat\scolumns.
+D 2026-02-04T20:51:27.822
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -420,7 +420,7 @@ F ext/misc/zipfile.c 837591f0505d21f7f7937ea046c9b0fc594f7fa3ca00c2bd54ffa1c94bf
 F ext/misc/zorder.c bddff2e1b9661a90c95c2a9a9c7ecd8908afab5763256294dd12d609d4664eee
 F ext/qrf/README.md e6e0ce2700acf6fd06312b42726a8f08ca240f30e1b122bff87c71c602046352
 F ext/qrf/dev-notes.md e68a6d91ce4c7eb296ef2daadc2bb79c95c317ad15b9fafe40850c67b29c2430
-F ext/qrf/qrf.c fd014c041a2fd54c900800c69a4ef1a7611201a15a46b60b967f07abb2f7d21d
+F ext/qrf/qrf.c 9216879683752773fa612849b8bc6a26b74f2a7cb9253bcbdd168092d8bfbbe2
 F ext/qrf/qrf.h 2ac14b0aaacf44636d8c81051bfeab4afae50a98fbb2e10ff5aed0c28a87b2b2
 F ext/rbu/rbu.c 801450b24eaf14440d8fd20385aacc751d5c9d6123398df41b1b5aa804bf4ce8
 F ext/rbu/rbu1.test 25870dd7db7eb5597e2b4d6e29e7a7e095abf332660f67d89959552ce8f8f255
@@ -2194,9 +2194,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee
 F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
 F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c
-P 6852843e6aa23051de0884593ce64b96a16f16c4d63b222bd324297581f7cf75 70ef095740c62081090147bb1900c843cb31864e93a8af518ff48855f1175717
-R 71c5e12c89ae4ea6f7261fec39f95a65
-T +closed 70ef095740c62081090147bb1900c843cb31864e93a8af518ff48855f1175717
+P e6902937ecdbeb449986469859b46631272fb0a9e7e1c31adea14cff072b6d67
+R 43daeeac5ff8274b48ad77362f50e842
 U drh
-Z 5039988e5fe2a9bbc455ceb4ad4f9ba6
+Z d676c59d86c6fefd831836dd5b0f9b5c
 # Remove this line to create a well-formed Fossil manifest.
index aa08672721c6b4f612b1241151d6bd12a043cc8b..fe635c9ee8c7998d3a7ed6854c4a457f3db5486d 100644 (file)
@@ -1 +1 @@
-e6902937ecdbeb449986469859b46631272fb0a9e7e1c31adea14cff072b6d67
+c476d956d0bd3065cf894de6f9d393b999ff7d2268a35f01a6d88804789ab58f