]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the --progress, --using, and -q options to the index_usage utility program.
authordrh <drh@noemail.net>
Wed, 30 Jan 2019 15:47:38 +0000 (15:47 +0000)
committerdrh <drh@noemail.net>
Wed, 30 Jan 2019 15:47:38 +0000 (15:47 +0000)
FossilOrigin-Name: a5e6be7cbc5d931308ddcc073c9cd6275c9711cae055d72a7c4aa71c1d15914c

manifest
manifest.uuid
tool/index_usage.c

index 22c84094971f66e2e91932b1e68fe83956e388ef..266f851814f67246d688f9567551b1521aa5e1dc 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Enhancements\sto\sthe\sindex_usage\sutility\sprogram.
-D 2019-01-30T14:01:43.193
+C Add\sthe\s--progress,\s--using,\sand\s-q\soptions\sto\sthe\sindex_usage\sutility\sprogram.
+D 2019-01-30T15:47:38.444
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F Makefile.in 178d8eb6840771149cee40b322d1b3be30d330198c522c903c1b66fb5a1bfca4
@@ -1721,7 +1721,7 @@ F tool/fuzzershell.c e1d90a03ca790d7c331c2aae08ca46ff435f1ae1faa6cb9cc48f4687c18
 F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4
 F tool/genfkey.test b6afd7b825d797a1e1274f519ab5695373552ecad5cd373530c63533638a5a4f
 F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce
-F tool/index_usage.c 28194fb8422b16adada6723d7516e404d011ffd1a7fd43ae20253001e5ddd2dc
+F tool/index_usage.c 9827f0f5252a6c0468e1addbd098ce9bbf909442d820d70b3ae91aa317e62a66
 F tool/kvtest-speed.sh 4761a9c4b3530907562314d7757995787f7aef8f
 F tool/lemon.c 900a15b9efba9890d10e7959914db94c4ad5162912127f061c4328add122d6fb
 F tool/lempar.c 61af95b8fac2bfd59c09d55330e78f3f5e352d7aa80bf37404b96ef795be3fdc
@@ -1804,7 +1804,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 760d14374d40bcd9ce3a89771c18dc236c9728553c4747c9b7452ee7b24f4140
-R f27c58459d19582c78b75fe1a98114b7
+P 19c739b4a8a43d894e37a99fa34838f3e3fa1fe0d019aefbc33f1d38d76af1a4
+R f8f216729fd1c799fb3786b449861140
 U drh
-Z eaaf90eb816c0def68c7e8f9deaf5b3d
+Z 016d67606384203f33b230415c37c583
index f992e8a90af7394c38dccaab664918e54f14c1f9..1b5403c8f16b615e0b8bf36518058afe1e4bafe3 100644 (file)
@@ -1 +1 @@
-19c739b4a8a43d894e37a99fa34838f3e3fa1fe0d019aefbc33f1d38d76af1a4
\ No newline at end of file
+a5e6be7cbc5d931308ddcc073c9cd6275c9711cae055d72a7c4aa71c1d15914c
\ No newline at end of file
index 9d97c73183135b0e1fc0878dbaaf6865e7ba0479..abe9ae42d7dacfb3e33b839d5e92ae0b35e41970 100644 (file)
@@ -21,7 +21,7 @@
 #include <string.h>
 
 static void usage(const char *argv0){
-  printf("Usage: %s DATABASE LOG\n\n", argv0);
+  printf("Usage: %s [OPTIONS] DATABASE LOG\n\n", argv0);
   printf(
     "DATABASE is an SQLite database against which various statements\n"
     "have been run.  The SQL text is stored in LOG.  LOG is an SQLite\n"
@@ -36,6 +36,12 @@ static void usage(const char *argv0){
     "DATABASE only needs to contain the schema used by the statements in\n"
     "LOG. The content can be removed from DATABASE.\n"
   );
+  printf(
+    "\nOPTIONS:\n\n"
+    "    --progress N   Show a progress message after every N input rows\n"
+    "    -q             Omit error message when parsing log entries\n"
+    "    --using NAME   Print SQL statements that use index NAME\n"
+  );
   printf("\nAnalysis will be done by SQLite version %s dated %.20s\n"
          "checkin number %.40s. Different versions\n"
          "of SQLite might use different indexes.\n",
@@ -49,6 +55,48 @@ int main(int argc, char **argv){
   char *zSql;
   int nErr = 0;
   int rc;
+  int bQuiet = 0;
+  int i, j;
+  const char *zUsing = 0;
+  sqlite3_stmt *pIncrCnt = 0;
+  int nRow = 0;
+  int iProgress = 0;
+
+  for(i=j=1; i<argc; i++){
+    const char *z = argv[i];
+    if( z[0]=='-' ){
+      z++;
+      if( z[0]=='-' ) z++;
+      if( strcmp(z,"progress")==0 ){
+        if( i+1<argc ){
+          iProgress = strtol(argv[++i],0,0);
+          continue;
+        }
+        printf("The --progress option requires an argument\n");
+        exit(0);
+      }
+      if( strcmp(z,"q")==0 ){
+        bQuiet = 1;
+        continue;
+      }
+      if( strcmp(z,"using")==0 ){
+        if( i+1<argc ){
+          zUsing = argv[++i];
+          continue;
+        }
+        printf("The --using option requires an argument\n");
+        exit(0);
+      }
+      if( strcmp(z, "help")==0 || strcmp(z, "?")==0 ){
+        usage(argv[0]);
+      }
+      printf("Unknown command-line option: \"%s\"\n", argv[i]);
+      exit(0);
+    }else{
+      if( j<i ) argv[j++] = argv[i];
+    }
+  }
+  argc = j;
 
   if( argc!=3 ) usage(argv[0]);
   rc = sqlite3_open_v2(argv[1], &db, SQLITE_OPEN_READONLY, 0);
@@ -66,8 +114,8 @@ int main(int argc, char **argv){
   pStmt = 0;
   rc = sqlite3_exec(db, 
      "CREATE TABLE temp.idxu(\n"
-     "  tbl TEXT,\n"
-     "  idx TEXT,\n"
+     "  tbl TEXT COLLATE nocase,\n"
+     "  idx TEXT COLLATE nocase,\n"
      "  cnt INT,\n"
      "  PRIMARY KEY(idx)\n"
      ") WITHOUT ROWID;", 0, 0, 0);
@@ -100,6 +148,15 @@ int main(int argc, char **argv){
     goto errorOut;
   }
 
+  rc = sqlite3_prepare_v2(db,
+    "UPDATE temp.idxu SET cnt=cnt+1 WHERE idx=?1",
+    -1, &pIncrCnt, 0);
+  if( rc ){
+    printf("Cannot prepare a statement to increment a counter for "
+           "indexes used\n");
+    goto errorOut;
+  }
+
   /* Update the counts based on LOG */
   while( sqlite3_step(pStmt)==SQLITE_ROW ){
     const char *zLog = (const char*)sqlite3_column_text(pStmt, 0);
@@ -109,10 +166,18 @@ int main(int argc, char **argv){
     rc = sqlite3_prepare_v2(db, zSql, -1, &pS2, 0);
     sqlite3_free(zSql);
     if( rc ){
-      printf("Cannot compile LOG entry %d (%s): %s\n",
+      if( !bQuiet ){
+        printf("Cannot compile LOG entry %d (%s): %s\n",
              sqlite3_column_int(pStmt, 1), zLog, sqlite3_errmsg(db));
+        fflush(stdout);
+      }
       nErr++;
     }else{
+      nRow++;
+      if( iProgress>0 && (nRow%iProgress)==0 ){
+        printf("%d...\n", nRow);
+        fflush(stdout);
+      }
       while( sqlite3_step(pS2)==SQLITE_ROW ){
         const char *zExplain = (const char*)sqlite3_column_text(pS2,3);
         const char *z1, *z2;
@@ -123,12 +188,13 @@ int main(int argc, char **argv){
         z1 += 13;
         for(z2=z1+1; z2[1] && z2[1]!='('; z2++){}
         n = z2 - z1;
-        zSql = sqlite3_mprintf(
-          "UPDATE temp.idxu SET cnt=cnt+1 WHERE idx='%.*q'", n, z1
-        );
-        /* printf("sql: %s\n", zSql); */
-        sqlite3_exec(db, zSql, 0, 0, 0);
-        sqlite3_free(zSql);
+        if( zUsing && sqlite3_strnicmp(zUsing, z1, n)==0 ){
+          printf("Using %s:\n%s\n", zUsing, zLog);
+          fflush(stdout);
+        }
+        sqlite3_bind_text(pIncrCnt,1,z1,n,SQLITE_STATIC);
+        sqlite3_step(pIncrCnt);
+        sqlite3_reset(pIncrCnt);
       }
     }
     sqlite3_finalize(pS2);
@@ -160,6 +226,7 @@ int main(int argc, char **argv){
   pStmt = 0;
 
 errorOut:
+  sqlite3_finalize(pIncrCnt);
   sqlite3_finalize(pStmt);
   sqlite3_close(db);
   return nErr;