]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Enhance the sqlite3_analyzer tool to give reports on the sizes of individual
authordrh <drh@noemail.net>
Wed, 17 Jul 2013 18:12:15 +0000 (18:12 +0000)
committerdrh <drh@noemail.net>
Wed, 17 Jul 2013 18:12:15 +0000 (18:12 +0000)
indices.

FossilOrigin-Name: 3b4096cc8a3b4517cdf49dcfe1f33279a5eb8efb

manifest
manifest.uuid
tool/spaceanal.tcl

index ef89e7f8d04af31d1ee7bf9900f28ceeccc5a2a9..4d4e29e469acca181c3b5602cdd5ea3addda32f1 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Clear\sthe\serror\sstring\spointer\sin\ssqlite3_vtab\sobject\safter\sthe\serror\sstring\nis\stransferred\sto\sSQLite.\s\sTicket\s[78588b938a11].
-D 2013-07-17T11:54:47.775
+C Enhance\sthe\ssqlite3_analyzer\stool\sto\sgive\sreports\son\sthe\ssizes\sof\sindividual\nindices.
+D 2013-07-17T18:12:15.911
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -1087,7 +1087,7 @@ F tool/showjournal.c b62cecaab86a4053d944c276bb5232e4d17ece02
 F tool/showwal.c 3f7f7da5ec0cba51b1449a75f700493377da57b5
 F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe
 F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
-F tool/spaceanal.tcl 76f583a246a0b027f423252339e711f13198932e
+F tool/spaceanal.tcl f87fc8e459e3e42255b52987fe0dda3f8a8c513d
 F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355
 F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
@@ -1103,7 +1103,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae
 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
-P 20dba3a7fb3e7078b95af3beca948467a3af6a89
-R 013ec1a077b1a785910a41f7774e0baf
+P 64bf8148b84e0ebb45c12b629f49bc9b316aceba
+R ec17da139f6652e6c6b8090663c2b7b7
 U drh
-Z 3af7c13fd1f5fd33dd19de7f52cc0abd
+Z f519c532f4fd545ddca3699fd0c0b9a9
index 9726c5d704250de7728cb0426a6a644edcf3a0dc..509c4c91b8c8bf84902986acfbbf529dab5e76a0 100644 (file)
@@ -1 +1 @@
-64bf8148b84e0ebb45c12b629f49bc9b316aceba
\ No newline at end of file
+3b4096cc8a3b4517cdf49dcfe1f33279a5eb8efb
\ No newline at end of file
index 6988f6e8b9323e84510d919feaaca616eeabe07a..e2f23fe4bf20fdf93305bb6f6b264bad0eef70d9 100644 (file)
@@ -246,8 +246,19 @@ mem function int integerify
 # [quote {hello world's}] == {'hello world''s'}
 #
 proc quote {txt} {
-  regsub -all ' $txt '' q
-  return '$q'
+  return [string map {' ''} $txt]
+}
+
+# Output a title line
+#
+proc titleline {title} {
+  if {$title==""} {
+    puts [string repeat * 79]
+  } else {
+    set len [string length $title]
+    set stars [string repeat * [expr 79-$len-5]]
+    puts "*** $title $stars"
+  }
 }
 
 # Generate a single line of output in the statistics section of the
@@ -255,7 +266,7 @@ proc quote {txt} {
 #
 proc statline {title value {extra {}}} {
   set len [string length $title]
-  set dots [string range {......................................} $len end]
+  set dots [string repeat . [expr 50-$len]]
   set len [string length $value]
   set sp2 [string range {          } $len end]
   if {$extra ne ""} {
@@ -319,9 +330,7 @@ proc subreport {title where} {
   # Output the sub-report title, nicely decorated with * characters.
   #
   puts ""
-  set len [string length $title]
-  set stars [string repeat * [expr 65-$len]]
-  puts "*** $title $stars"
+  titleline $title
   puts ""
 
   # Calculate statistics and store the results in TCL variables, as follows:
@@ -490,9 +499,6 @@ set user_percent [percent $user_payload $file_bytes]
 # Output the summary statistics calculated above.
 #
 puts "/** Disk-Space Utilization Report For $root_filename"
-catch {
-  puts "*** As of [clock format [clock seconds] -format {%Y-%b-%d %H:%M:%S}]"
-}
 puts ""
 statline {Page size in bytes} $pageSize
 statline {Pages in the whole file (measured)} $file_pgcnt
@@ -517,16 +523,27 @@ statline {Bytes of user payload stored} $user_payload $user_percent
 # Output table rankings
 #
 puts ""
-puts "*** Page counts for all tables with their indices ********************"
+titleline "Page counts for all tables with their indices"
 puts ""
 mem eval {SELECT tblname, count(*) AS cnt, 
               int(sum(int_pages+leaf_pages+ovfl_pages)) AS size
           FROM space_used GROUP BY tblname ORDER BY size+0 DESC, tblname} {} {
   statline [string toupper $tblname] $size [percent $size $file_pgcnt]
 }
+puts ""
+titleline "Page counts for all tables and indices separately"
+puts ""
+mem eval {
+  SELECT
+       upper(name) AS nm,
+       int(int_pages+leaf_pages+ovfl_pages) AS size
+    FROM space_used
+   ORDER BY size+0 DESC, name} {} {
+  statline $nm $size [percent $size $file_pgcnt]
+}
 if {$isCompressed} {
   puts ""
-  puts "*** Bytes of disk space used after compression ***********************"
+  titleline "Bytes of disk space used after compression"
   puts ""
   set csum 0
   mem eval {SELECT tblname,
@@ -554,13 +571,22 @@ if {$nindex>0} {
 }
 foreach tbl [mem eval {SELECT name FROM space_used WHERE NOT is_index
                        ORDER BY name}] {
-  regsub ' $tbl '' qn
+  set qn [quote $tbl]
   set name [string toupper $tbl]
-  set n [mem eval "SELECT count(*) FROM space_used WHERE tblname='$qn'"]
+  set n [mem eval {SELECT count(*) FROM space_used WHERE tblname=$tbl}]
   if {$n>1} {
+    set idxlist [mem eval "SELECT name FROM space_used
+                            WHERE tblname='$qn' AND is_index
+                            ORDER BY 1"]
     subreport "Table $name and all its indices" "tblname='$qn'"
     subreport "Table $name w/o any indices" "name='$qn'"
-    subreport "Indices of table $name" "tblname='$qn' AND is_index"
+    if {[llength $idxlist]>1} {
+      subreport "Indices of table $name" "tblname='$qn' AND is_index"
+    }
+    foreach idx $idxlist {
+      set qidx [quote $idx]
+      subreport "Index [string toupper $idx] of table $name" "name='$qidx'"
+    }
   } else {
     subreport "Table $name" "name='$qn'"
   }
@@ -568,9 +594,9 @@ foreach tbl [mem eval {SELECT name FROM space_used WHERE NOT is_index
 
 # Output instructions on what the numbers above mean.
 #
+puts ""
+titleline Definitions
 puts {
-*** Definitions ******************************************************
-
 Page size in bytes
 
     The number of bytes in a single page of the database file.  
@@ -722,7 +748,7 @@ Unused bytes on all pages
 # Output a dump of the in-memory database. This can be used for more
 # complex offline analysis.
 #
-puts "**********************************************************************"
+titleline {}
 puts "The entire text of this report can be sourced into any SQL database"
 puts "engine for further analysis.  All of the text above is an SQL comment."
 puts "The data used to generate this report follows:"