]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Enhance the showdb tool with options to show PTRMAP usage and content.
authordrh <drh@noemail.net>
Tue, 19 Feb 2013 22:26:51 +0000 (22:26 +0000)
committerdrh <drh@noemail.net>
Tue, 19 Feb 2013 22:26:51 +0000 (22:26 +0000)
FossilOrigin-Name: 06bd91305ed6752315c5224be5f89e87cafa6687

manifest
manifest.uuid
tool/showdb.c

index dc27a853d41eb1f95ade6a2683e844b2be5162aa..eba974bac557f458a881d31a5dd9d4d5a49cae02 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sthe\sshowdb\sutility\sso\sthat\sit\sdisplays\sthe\scorrect\ssecondary\susage\sof\na\spage\swhen\sreporting\son\san\serror\sof\sa\spage\sbeing\sused\smore\sthan\sonce.
-D 2013-02-19T20:25:16.107
+C Enhance\sthe\sshowdb\stool\swith\soptions\sto\sshow\sPTRMAP\susage\sand\scontent.
+D 2013-02-19T22:26:51.195
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in a48faa9e7dd7d556d84f5456eabe5825dd8a6282
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -1014,7 +1014,7 @@ F tool/omittest.tcl 4665982e95a6e5c1bd806cf7bc3dea95be422d77
 F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
 F tool/restore_jrnl.tcl 6957a34f8f1f0f8285e07536225ec3b292a9024a
 F tool/rollback-test.c 9fc98427d1e23e84429d7e6d07d9094fbdec65a5
-F tool/showdb.c 2292b901840eb0e3390af9e8115d54dfee7613a0
+F tool/showdb.c 16960a5ce59d8b1d70dc3bdc51e2c0fe7bb91359
 F tool/showjournal.c b62cecaab86a4053d944c276bb5232e4d17ece02
 F tool/showwal.c 3f7f7da5ec0cba51b1449a75f700493377da57b5
 F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe
@@ -1034,7 +1034,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
-P d14263a719101d9c70054f2fc37e7788f73aab28
-R c7d3b3e1fb8a10f0748991954af9d6f6
+P 4507f0b3d409cd14bb2b9c29c92c76aa3ccb22b6
+R b76888af58f22e925445fcabab8c63d9
 U drh
-Z 8fc5bc0346e01701458f5c2865bfe0c3
+Z 14b66e62b1a3bf33a2d26df6fe5962d7
index 7b37219e03b4842f4dad38e582fce5189448e17d..326315ef7c4bf99eb8965a02d15235dc50d0b8e4 100644 (file)
@@ -1 +1 @@
-4507f0b3d409cd14bb2b9c29c92c76aa3ccb22b6
\ No newline at end of file
+06bd91305ed6752315c5224be5f89e87cafa6687
\ No newline at end of file
index a3358ba8bfabdde92c84641622b7510eff462ef8..4a31d9cd3e1f7b6c6cc1e3a3e3f9864da6d7857b 100644 (file)
@@ -615,6 +615,22 @@ static void page_usage_freelist(int pgno){
   }
 }
 
+/*
+** Determine pages used as PTRMAP pages
+*/
+static void page_usage_ptrmap(unsigned char *a){
+  if( a[55] ){
+    int usable = pagesize - a[20];
+    int pgno = 2;
+    int perPage = usable/5;
+    while( pgno<=mxPage ){
+      page_usage_msg(pgno, "PTRMAP page covering %d..%d",
+                           pgno+1, pgno+perPage);
+      pgno += perPage + 1;
+    }
+  }
+}
+
 /*
 ** Try to figure out how every page in the database file is being used.
 */
@@ -649,6 +665,7 @@ static void page_usage_report(const char *zDbName){
   /* Discover the usage of each page */
   a = getContent(0, 100);
   page_usage_freelist(decodeInt32(a+32));
+  page_usage_ptrmap(a);
   free(a);
   page_usage_btree(1, 0, 0, "sqlite_master");
   sqlite3_exec(db, "PRAGMA writable_schema=ON", 0, 0, 0);
@@ -679,6 +696,53 @@ static void page_usage_report(const char *zDbName){
   zPageUse = 0;
 }
 
+/*
+** Try to figure out how every page in the database file is being used.
+*/
+static void ptrmap_coverage_report(const char *zDbName){
+  unsigned int pgno;
+  unsigned char *aHdr;
+  unsigned char *a;
+  int usable;
+  int perPage;
+  unsigned int i;
+
+  /* Avoid the pathological case */
+  if( mxPage<1 ){
+    printf("empty database\n");
+    return;
+  }
+
+  /* Make sure PTRMAPs are used in this database */
+  aHdr = getContent(0, 100);
+  if( aHdr[55]==0 ){
+    printf("database does not use PTRMAP pages\n");
+    return;
+  }
+  usable = pagesize - aHdr[20];
+  perPage = usable/5;
+  free(aHdr);
+  printf("%5d: root of sqlite_master\n", 1);
+  for(pgno=2; pgno<=mxPage; pgno += perPage+1){
+    printf("%5d: PTRMAP page covering %d..%d\n", pgno,
+           pgno+1, pgno+perPage);
+    a = getContent((pgno-1)*pagesize, usable);
+    for(i=0; i+5<=usable && pgno+1+i/5<=mxPage; i+=5){
+      const char *zType = "???";
+      unsigned int iFrom = decodeInt32(&a[i+1]);
+      switch( a[i] ){
+        case 1:  zType = "b-tree root page";        break;
+        case 2:  zType = "freelist page";           break;
+        case 3:  zType = "first page of overflow";  break;
+        case 4:  zType = "later page of overflow";  break;
+        case 5:  zType = "b-tree non-root page";    break;
+      }
+      printf("%5d: %s, parent=%u\n", pgno+1+i/5, zType, iFrom);
+    }
+    free(a);
+  }
+}
+
 /*
 ** Print a usage comment
 */
@@ -688,6 +752,7 @@ static void usage(const char *argv0){
     "args:\n"
     "    dbheader        Show database header\n"
     "    pgidx           Index of how each page is used\n"
+    "    ptrmap          Show all PTRMAP page content\n"
     "    NNN..MMM        Show hex of pages NNN through MMM\n"
     "    NNN..end        Show hex of pages NNN through end of file\n"
     "    NNNb            Decode btree page NNN\n"
@@ -737,6 +802,14 @@ int main(int argc, char **argv){
         page_usage_report(argv[1]);
         continue;
       }
+      if( strcmp(argv[i], "ptrmap")==0 ){
+        ptrmap_coverage_report(argv[1]);
+        continue;
+      }
+      if( strcmp(argv[i], "help")==0 ){
+        usage(argv[0]);
+        continue;
+      }
       if( !isdigit(argv[i][0]) ){
         fprintf(stderr, "%s: unknown option: [%s]\n", argv[0], argv[i]);
         continue;