From: drh Date: Tue, 4 Aug 2015 14:18:10 +0000 (+0000) Subject: In the sqlite3_analyzer.exe utility, show the depth of each btree and report X-Git-Tag: version-3.9.0~241 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8fb6c4389dd7718f7eb552467fda4a1a36913cfb;p=thirdparty%2Fsqlite.git In the sqlite3_analyzer.exe utility, show the depth of each btree and report the average fanout of indexes and WITHOUT ROWID tables. FossilOrigin-Name: cd997770013e923ac3fa34b1546b97681923c8b1 --- diff --git a/manifest b/manifest index b1755902f2..ed6d210969 100644 --- 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 diff --git a/manifest.uuid b/manifest.uuid index d5b4bd14a8..191c9d8ba5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -70b57dafb3216feb21091883196831fa1252e7bf \ No newline at end of file +cd997770013e923ac3fa34b1546b97681923c8b1 \ No newline at end of file diff --git a/tool/spaceanal.tcl b/tool/spaceanal.tcl index cd3785bd7d..2271e21b81 100644 --- a/tool/spaceanal.tcl +++ b/tool/spaceanal.tcl @@ -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]} {