From: dan Date: Fri, 6 May 2016 15:16:02 +0000 (+0000) Subject: Fix a bug in sqlite_analyzer causing it report (slightly) incorrect values for the... X-Git-Tag: version-3.13.0~33 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d49c6930b16bae906c8017c9bf498869bce4ca39;p=thirdparty%2Fsqlite.git Fix a bug in sqlite_analyzer causing it report (slightly) incorrect values for the number of entries in indexes or WITHOUT ROWID tables. FossilOrigin-Name: dc37750d4e87d0c529785adceeebd838b8f8591d --- diff --git a/manifest b/manifest index 8e5f6ffbdc..7c1f55f984 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Renumber\sinternal\sconstants\sin\sthe\sprintf()\simplemention\sfor\sa\ssmall\nperformance\simprovement. -D 2016-05-05T11:53:12.439 +C Fix\sa\sbug\sin\ssqlite_analyzer\scausing\sit\sreport\s(slightly)\sincorrect\svalues\sfor\sthe\snumber\sof\sentries\sin\sindexes\sor\sWITHOUT\sROWID\stables. +D 2016-05-06T15:16:02.765 F Makefile.in 9eda6e1c90d05c199c3ec8a7069b0682ad307657 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc db82b35aef27f412fef14d8534afc022138bcdfd @@ -1447,7 +1447,7 @@ F tool/showlocks.c 9920bcc64f58378ff1118caead34147201f48c68 F tool/showstat4.c bda40d6e395df7edb6e9ea630784d3d762c35b4b F tool/showwal.c ec79959834f7b21f1e0a2aa52bb7c056d2203977 F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe -F tool/spaceanal.tcl 93c1fdc9733c525b17a2024c7df193daa002e037 +F tool/spaceanal.tcl 85d90e6674d8298e3eaf82dbcef3abc2d5317f3e F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355 F tool/speedtest16.c ecb6542862151c3e6509bbc00509b234562ae81e F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff @@ -1487,7 +1487,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 71af9ac165ac02272f4886f69bd9ab4770fd7bb6 -R 89655379113728f544ce9a18ad294b0b -U drh -Z f65addcdc03169dedb02067b28293d6c +P 69d11447f4b1a8c536c3b6573d2a3419da870412 +R 56e7e963139ae94efddd96a9288ff8e5 +U dan +Z 82199c527d2c64b9169490d91c3a80bb diff --git a/manifest.uuid b/manifest.uuid index 4a4e62d8ed..aa435a5204 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -69d11447f4b1a8c536c3b6573d2a3419da870412 \ No newline at end of file +dc37750d4e87d0c529785adceeebd838b8f8591d \ No newline at end of file diff --git a/tool/spaceanal.tcl b/tool/spaceanal.tcl index 38d954162e..eef1192a1d 100644 --- a/tool/spaceanal.tcl +++ b/tool/spaceanal.tcl @@ -152,6 +152,7 @@ set tabledef {CREATE TABLE space_used( name clob, -- Name of a table or index in the database file tblname clob, -- Name of associated table is_index boolean, -- TRUE if it is an index, false for a table + is_without_rowid boolean, -- TRUE if WITHOUT ROWID table nentry int, -- Number of entries in the BTree leaf_entries int, -- Number of leaf entries depth int, -- Depth of the b-tree @@ -184,7 +185,7 @@ set sql { SELECT name, tbl_name FROM sqlite_master WHERE rootpage>0 } foreach {name tblname} [concat sqlite_master sqlite_master [db eval $sql]] { set is_index [expr {$name!=$tblname}] - set idx_btree [expr {$is_index || [is_without_rowid $name]}] + set is_without_rowid [is_without_rowid $name] db eval { SELECT sum(ncell) AS nentry, @@ -235,6 +236,7 @@ foreach {name tblname} [concat sqlite_master sqlite_master [db eval $sql]] { $name, $tblname, $is_index, + $is_without_rowid, $nentry, $leaf_entries, $depth, @@ -330,12 +332,15 @@ proc subreport {title where showFrag} { # following query returns exactly one row (because it is an aggregate). # # The results of the query are stored directly by SQLite into local - # variables (i.e. $nentry, $nleaf etc.). + # variables (i.e. $nentry, $payload etc.). # mem eval " SELECT - int(sum(nentry)) AS nentry, - int(sum(leaf_entries)) AS nleaf, + int(sum( + CASE WHEN (is_without_rowid OR is_index) THEN nentry + ELSE leaf_entries + END + )) AS nentry, int(sum(payload)) AS payload, int(sum(ovfl_payload)) AS ovfl_payload, max(mx_payload) AS mx_payload, @@ -375,8 +380,8 @@ proc subreport {title where showFrag} { set storage [expr {$total_pages*$pageSize}] set payload_percent [percent $payload $storage {of storage consumed}] set total_unused [expr {$ovfl_unused+$int_unused+$leaf_unused}] - set avg_payload [divide $payload $nleaf] - set avg_unused [divide $total_unused $nleaf] + set avg_payload [divide $payload $nentry] + set avg_unused [divide $total_unused $nentry] if {$int_pages>0} { # TODO: Is this formula correct? set nTab [mem eval " @@ -390,12 +395,12 @@ proc subreport {title where showFrag} { "] set avg_fanout [format %.2f $avg_fanout] } - set ovfl_cnt_percent [percent $ovfl_cnt $nleaf {of all entries}] + set ovfl_cnt_percent [percent $ovfl_cnt $nentry {of all entries}] # Print out the sub-report statistics. # statline {Percentage of total database} $total_pages_percent - statline {Number of entries} $nleaf + statline {Number of entries} $nentry statline {Bytes of storage consumed} $storage if {$compressed_size!=$storage} { set compressed_size [expr {$compressed_size+$compressOverhead*$total_pages}]