From 3aeea463978980ad95060ad201c3ac9462555637 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 3 Apr 2012 14:59:50 +0000 Subject: [PATCH] Enhance the "showdb" utility program with the "pgidx" option. Now requires linkage with the amalgamation. FossilOrigin-Name: 4b5737014c6f1638de9dc162463508ea7dfe333d --- manifest | 12 +-- manifest.uuid | 2 +- tool/showdb.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 229 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index bebaba541e..095f368fee 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\sSQLITE_RTREE_INT_ONLY\scompile-time\soption\scauses\sthe\sRTree\sextension\s\nto\suse\sonly\sinteger\smath\sand\sstore\sonly\sinteger\scoordinates. -D 2012-04-02T21:35:42.939 +C Enhance\sthe\s"showdb"\sutility\sprogram\swith\sthe\s"pgidx"\soption.\s\sNow\srequires\nlinkage\swith\sthe\samalgamation. +D 2012-04-03T14:59:50.844 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2f37e468503dbe79d35c9f6dffcf3fae1ae9ec20 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -982,7 +982,7 @@ F tool/shell2.test 5dc76b8005b465f420fed8241621da7513060ff3 F tool/shell3.test 4fad469e8003938426355afdf34155f08c587836 F tool/shell4.test 35f9c3d452b4e76d5013c63e1fd07478a62f14ce F tool/shell5.test 0e987fb8d40638bb5c90163cb58cbe3e07dbed56 -F tool/showdb.c 43e913d954684c2f5007dcab46d1a1308852a0ad +F tool/showdb.c 9cdc45377f7512902232bdc18bd5119cc2512a1a F tool/showjournal.c b62cecaab86a4053d944c276bb5232e4d17ece02 F tool/showwal.c f09e5a80a293919290ec85a6a37c85a5ddcf37d9 F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe @@ -1000,7 +1000,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P fb121980e48af368353431fd04924e414b65c852 -R 5f487522a2da2d1baf5cda41d792b333 +P 02b7640f5118e0a635b68f65765191bb3171b7bd +R 4634bc5c716828f15113d298489e79da U drh -Z f6050a33b89113e7c2cd85615563f7a3 +Z b9b2c57600f8181cc1cad22a91aba3cd diff --git a/manifest.uuid b/manifest.uuid index 211e12f14c..fb9d6b2b22 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -02b7640f5118e0a635b68f65765191bb3171b7bd \ No newline at end of file +4b5737014c6f1638de9dc162463508ea7dfe333d \ No newline at end of file diff --git a/tool/showdb.c b/tool/showdb.c index 057abd32ba..a6e3060a14 100644 --- a/tool/showdb.c +++ b/tool/showdb.c @@ -9,6 +9,7 @@ #include #include #include +#include "sqlite3.h" static int pagesize = 1024; /* Size of a database page */ @@ -450,6 +451,222 @@ static void decode_trunk_page( } } +/* +** A short text comment on the use of each page. +*/ +static char **zPageUse; + +/* +** Add a comment on the use of a page. +*/ +static void page_usage_msg(int pgno, const char *zFormat, ...){ + va_list ap; + char *zMsg; + + va_start(ap, zFormat); + zMsg = sqlite3_vmprintf(zFormat, ap); + va_end(ap); + if( pgno<=0 || pgno>mxPage ){ + printf("ERROR: page %d out of bounds. Range=1..%d. Msg: %s\n", + pgno, mxPage, zMsg); + sqlite3_free(zMsg); + return; + } + if( zPageUse[pgno]!=0 ){ + printf("ERROR: page %d used multiple times:\n", pgno); + printf("ERROR: previous: %s\n", zPageUse[pgno]); + printf("ERROR: current: %s\n", zPageUse[pgno]); + sqlite3_free(zPageUse[pgno]); + } + zPageUse[pgno] = zMsg; +} + +/* +** Find overflow pages of a cell and describe their usage. +*/ +static void page_usage_cell( + unsigned char cType, /* Page type */ + unsigned char *a, /* Cell content */ + int pgno, /* page containing the cell */ + int cellno /* Index of the cell on the page */ +){ + int i; + int nDesc = 0; + int n = 0; + i64 nPayload; + i64 rowid; + int nLocal; + i = 0; + if( cType<=5 ){ + a += 4; + n += 4; + } + if( cType!=5 ){ + i = decodeVarint(a, &nPayload); + a += i; + n += i; + nLocal = localPayload(nPayload, cType); + }else{ + nPayload = nLocal = 0; + } + if( cType==5 || cType==13 ){ + i = decodeVarint(a, &rowid); + a += i; + n += i; + } + if( nLocalmxPage ) return; + a = getContent((pgno-1)*pagesize, pagesize); + switch( a[hdr] ){ + case 2: zType = "interior node of index"; break; + case 5: zType = "interior node of table"; break; + case 10: zType = "leaf of index"; break; + case 13: zType = "leaf of table"; break; + } + if( parent ){ + page_usage_msg(pgno, "%s [%s], child %d of page %d", + zType, zName, idx, parent); + }else{ + page_usage_msg(pgno, "root %s [%s]", zType, zName); + } + nCell = a[hdr+3]*256 + a[hdr+4]; + if( a[hdr]==2 || a[hdr]==5 ){ + int cellstart = hdr+12; + unsigned int child; + for(i=0; i0 && pgno<=mxPage && (cnt++)