]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
In the sqlite3_analyzer.exe utility, show the depth of each btree and report
authordrh <drh@noemail.net>
Tue, 4 Aug 2015 14:18:10 +0000 (14:18 +0000)
committerdrh <drh@noemail.net>
Tue, 4 Aug 2015 14:18:10 +0000 (14:18 +0000)
the average fanout of indexes and WITHOUT ROWID tables.

FossilOrigin-Name: cd997770013e923ac3fa34b1546b97681923c8b1

manifest
manifest.uuid
tool/spaceanal.tcl

index b1755902f2269ccb96dabcc0de52d7b46e165669..ed6d210969003308688f7fda75649bd10e65e4fe 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Allow\sa\sVIEW\sto\sreference\sundefined\stables\sand\sfunctions\swhen\sinitially\ncreated.\s\sThe\serror\sreport\sis\sdeferred\suntil\sthe\sVIEW\sis\sused.\s\sThis\sallows\nviews\sto\sbe\screated\sbefore\ssubviews\sand\stables\sthat\sthe\sview\sreferences.
-D 2015-08-03T13:44:45.941
+C In\sthe\ssqlite3_analyzer.exe\sutility,\sshow\sthe\sdepth\sof\seach\sbtree\sand\sreport\nthe\saverage\sfanout\sof\sindexes\sand\sWITHOUT\sROWID\stables.
+D 2015-08-04T14:18:10.060
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 4de3ef40c8b3b75c0c55ff4242a43c8ce1ad90ee
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -1350,7 +1350,7 @@ F tool/showstat4.c 9515faa8ec176599d4a8288293ba8ec61f7b728a
 F tool/showwal.c 85cb36d4fe3e93e2fbd63e786e0d1ce42d0c4fad
 F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe
 F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
-F tool/spaceanal.tcl 713c587a057334de42c41ad9566f10e255d3ad27
+F tool/spaceanal.tcl ac584838dc14782eff7c165eb70c36533fb3f1f8
 F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355
 F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
@@ -1368,7 +1368,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 3419044967258e3ed65f71528e06952ee102dcc7
-R a7ce110cce77b8da537a48fa80ac6f4f
+P 70b57dafb3216feb21091883196831fa1252e7bf
+R 13388672818fef0d2cb76a948959a6c9
 U drh
-Z 0cbd7829b00ada6a24c23b51a4093668
+Z 06142420513d4bba3f9f1464c1f7a39e
index d5b4bd14a8cc1e18e0c89d8801fda471fb22fe81..191c9d8ba5aad8e87fa27899aac5a3a001e91e33 100644 (file)
@@ -1 +1 @@
-70b57dafb3216feb21091883196831fa1252e7bf
\ No newline at end of file
+cd997770013e923ac3fa34b1546b97681923c8b1
\ No newline at end of file
index cd3785bd7d195973aec52da10b03152d2d1ca68f..2271e21b817e553b2deceb182534d7d27d317728 100644 (file)
@@ -142,6 +142,7 @@ set tabledef {CREATE TABLE space_used(
    is_index boolean, -- TRUE if it is an index, false for a table
    nentry int,       -- Number of entries in the BTree
    leaf_entries int, -- Number of leaf entries
+   depth int,        -- Depth of the b-tree
    payload int,      -- Total amount of data stored in this table or index
    ovfl_payload int, -- Total amount of data stored on overflow pages
    ovfl_cnt int,     -- Number of entries that use overflow
@@ -164,22 +165,9 @@ db eval {CREATE TEMP TABLE dbstat AS SELECT * FROM temp.stat
          ORDER BY name, path}
 db eval {DROP TABLE temp.stat}
 
-proc isleaf {pagetype is_index} {
-  return [expr {$pagetype == "leaf" || ($pagetype == "internal" && $is_index)}]
-}
-proc isoverflow {pagetype is_index} {
-  return [expr {$pagetype == "overflow"}]
-}
-proc isinternal {pagetype is_index} {
-  return [expr {$pagetype == "internal" && $is_index==0}]
-}
-
-db func isleaf isleaf
-db func isinternal isinternal
-db func isoverflow isoverflow
-
 set isCompressed 0
 set compressOverhead 0
+set depth 0
 set sql { SELECT name, tbl_name FROM sqlite_master WHERE rootpage>0 }
 foreach {name tblname} [concat sqlite_master sqlite_master [db eval $sql]] {
 
@@ -188,18 +176,20 @@ foreach {name tblname} [concat sqlite_master sqlite_master [db eval $sql]] {
   db eval {
     SELECT 
       sum(ncell) AS nentry,
-      sum(isleaf(pagetype, $idx_btree) * ncell) AS leaf_entries,
+      sum((pagetype=='leaf')*ncell) AS leaf_entries,
       sum(payload) AS payload,
-      sum(isoverflow(pagetype, $idx_btree) * payload) AS ovfl_payload,
+      sum((pagetype=='overflow') * payload) AS ovfl_payload,
       sum(path LIKE '%+000000') AS ovfl_cnt,
       max(mx_payload) AS mx_payload,
-      sum(isinternal(pagetype, $idx_btree)) AS int_pages,
-      sum(isleaf(pagetype, $idx_btree)) AS leaf_pages,
-      sum(isoverflow(pagetype, $idx_btree)) AS ovfl_pages,
-      sum(isinternal(pagetype, $idx_btree) * unused) AS int_unused,
-      sum(isleaf(pagetype, $idx_btree) * unused) AS leaf_unused,
-      sum(isoverflow(pagetype, $idx_btree) * unused) AS ovfl_unused,
-      sum(pgsize) AS compressed_size
+      sum(pagetype=='internal') AS int_pages,
+      sum(pagetype=='leaf') AS leaf_pages,
+      sum(pagetype=='overflow') AS ovfl_pages,
+      sum((pagetype=='internal') * unused) AS int_unused,
+      sum((pagetype=='leaf') * unused) AS leaf_unused,
+      sum((pagetype=='overflow') * unused) AS ovfl_unused,
+      sum(pgsize) AS compressed_size,
+      max((length(CASE WHEN path LIKE '%+%' THEN '' ELSE path END)+3)/4)
+        AS depth
     FROM temp.dbstat WHERE name = $name
   } break
 
@@ -235,6 +225,7 @@ foreach {name tblname} [concat sqlite_master sqlite_master [db eval $sql]] {
       $is_index,
       $nentry,
       $leaf_entries,
+      $depth,
       $payload,     
       $ovfl_payload,
       $ovfl_cnt,   
@@ -344,7 +335,9 @@ proc subreport {title where showFrag} {
       int(sum(int_unused)) AS int_unused,
       int(sum(ovfl_unused)) AS ovfl_unused,
       int(sum(gap_cnt)) AS gap_cnt,
-      int(sum(compressed_size)) AS compressed_size
+      int(sum(compressed_size)) AS compressed_size,
+      int(max(depth)) AS depth,
+      count(*) AS cnt
     FROM space_used WHERE $where" {} {}
 
   # Output the sub-report title, nicely decorated with * characters.
@@ -381,7 +374,7 @@ proc subreport {title where showFrag} {
     "]
     set avg_fanout [mem eval "
       SELECT (sum(leaf_pages+int_pages)-$nTab)/sum(int_pages) FROM space_used
-          WHERE $where AND is_index = 0
+          WHERE $where
     "]
     set avg_fanout [format %.2f $avg_fanout]
   }
@@ -399,6 +392,7 @@ proc subreport {title where showFrag} {
     statline {Bytes used after compression} $compressed_size $pct
   }
   statline {Bytes of payload} $payload $payload_percent
+  if {$cnt==1} {statline {B-tree depth} $depth}
   statline {Average payload per entry} $avg_payload
   statline {Average unused bytes per entry} $avg_unused
   if {[info exists avg_fanout]} {