mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Add the "space_used.tcl" script to the tools directory. This script is used
to measure how much disk space is used by each table and index of a database. (CVS 789) FossilOrigin-Name: 83b2c27a568cd67cd5162d513766b23ff9fc2227
This commit is contained in:
1
main.mk
1
main.mk
@@ -212,7 +212,6 @@ config.h:
|
|||||||
rm -f temp.c temp
|
rm -f temp.c temp
|
||||||
|
|
||||||
sqlite.h: $(TOP)/src/sqlite.h.in
|
sqlite.h: $(TOP)/src/sqlite.h.in
|
||||||
$(BCC) -o temp temp.c
|
|
||||||
sed -e s/--VERS--/`cat ${TOP}/VERSION`/ \
|
sed -e s/--VERS--/`cat ${TOP}/VERSION`/ \
|
||||||
-e s/--ENCODING--/$(ENCODING)/ \
|
-e s/--ENCODING--/$(ENCODING)/ \
|
||||||
$(TOP)/src/sqlite.h.in >sqlite.h
|
$(TOP)/src/sqlite.h.in >sqlite.h
|
||||||
|
15
manifest
15
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Automatically\sdetermine\sif\spointers\sare\s4\sor\s8\sbytes\sin\ssize\sduring\sthe\ncompilation\sprocess.\s\sTicket\s#190.\s(CVS\s788)
|
C Add\sthe\s"space_used.tcl"\sscript\sto\sthe\stools\sdirectory.\s\sThis\sscript\sis\sused\nto\smeasure\show\smuch\sdisk\sspace\sis\sused\sby\seach\stable\sand\sindex\sof\sa\sdatabase.\s(CVS\s789)
|
||||||
D 2002-11-20T11:55:19
|
D 2002-11-24T14:52:27
|
||||||
F Makefile.in 868c17a1ae1c07603d491274cc8f86c04acf2a1e
|
F Makefile.in 868c17a1ae1c07603d491274cc8f86c04acf2a1e
|
||||||
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
|
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
|
||||||
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
|
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
|
||||||
@@ -14,7 +14,7 @@ F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
|
|||||||
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
|
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
|
||||||
F libtool c56e618713c9510a103bda6b95f3ea3900dcacd6
|
F libtool c56e618713c9510a103bda6b95f3ea3900dcacd6
|
||||||
F ltmain.sh e9ed72eb1d690f447c13945eaf69e28af531eda1
|
F ltmain.sh e9ed72eb1d690f447c13945eaf69e28af531eda1
|
||||||
F main.mk e0f1f0b2fe39593b5d1c41e467d409210656d3be
|
F main.mk 9d13839b9697af332d788fe6e801e68da027cc5c
|
||||||
F publish.sh e5b83867d14708ed58cec8cba0a4f201e969474d
|
F publish.sh e5b83867d14708ed58cec8cba0a4f201e969474d
|
||||||
F spec.template 238f7db425a78dc1bb7682e56e3834c7270a3f5e
|
F spec.template 238f7db425a78dc1bb7682e56e3834c7270a3f5e
|
||||||
F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
|
F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
|
||||||
@@ -46,7 +46,7 @@ F src/table.c eed2098c9b577aa17f8abe89313a9c4413f57d63
|
|||||||
F src/tclsqlite.c 9f2c00a92338c51171ded8943bd42d77f7e69e64
|
F src/tclsqlite.c 9f2c00a92338c51171ded8943bd42d77f7e69e64
|
||||||
F src/test1.c a46e9f61915b32787c5d5a05a4b92e4dacc437d9
|
F src/test1.c a46e9f61915b32787c5d5a05a4b92e4dacc437d9
|
||||||
F src/test2.c 8f7d88895a49b3eed111469f2ab1071cb780ed12
|
F src/test2.c 8f7d88895a49b3eed111469f2ab1071cb780ed12
|
||||||
F src/test3.c 540fa7fc3cb3732517b779b5f90ad9cc4303d0ab
|
F src/test3.c 03d4f962f482599df9027a5814490c441a58cd99
|
||||||
F src/threadtest.c d641a5219e718e18a1a80a50eb9bb549f451f42e
|
F src/threadtest.c d641a5219e718e18a1a80a50eb9bb549f451f42e
|
||||||
F src/tokenize.c 75e3bb37305b64e118e709752066f494c4f93c30
|
F src/tokenize.c 75e3bb37305b64e118e709752066f494c4f93c30
|
||||||
F src/trigger.c 5ba917fc226b96065108da28186c2efaec53e481
|
F src/trigger.c 5ba917fc226b96065108da28186c2efaec53e481
|
||||||
@@ -122,6 +122,7 @@ F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
|
|||||||
F tool/report1.txt 9eae07f26a8fc53889b45fc833a66a33daa22816
|
F tool/report1.txt 9eae07f26a8fc53889b45fc833a66a33daa22816
|
||||||
F tool/showdb.c 3559eac5a3b46e9b558d50856946b25e77633236
|
F tool/showdb.c 3559eac5a3b46e9b558d50856946b25e77633236
|
||||||
F tool/showjournal.c 9a37d7b05de0591e3102aaf774d01fbc0d053a8b
|
F tool/showjournal.c 9a37d7b05de0591e3102aaf774d01fbc0d053a8b
|
||||||
|
F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
|
||||||
F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355
|
F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355
|
||||||
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||||
F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf
|
F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf
|
||||||
@@ -149,7 +150,7 @@ F www/speed.tcl a20a792738475b68756ea7a19321600f23d1d803
|
|||||||
F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
|
F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
|
||||||
F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
|
F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
|
||||||
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
|
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
|
||||||
P da4a79e2891aa81e2e6d96689f99b3924f940dd5
|
P dd5396a73a782b6abe9da3de43a5ee11e0dddbb2
|
||||||
R e6e632d6bef956a28043c04d8612ec4c
|
R f02620fdf50f08e680c6e4c887b23004
|
||||||
U drh
|
U drh
|
||||||
Z 48fdd2120a0a70b5abec7fb92ba361ca
|
Z d6b1541e76d56cb79d446daffe01fa52
|
||||||
|
@@ -1 +1 @@
|
|||||||
dd5396a73a782b6abe9da3de43a5ee11e0dddbb2
|
83b2c27a568cd67cd5162d513766b23ff9fc2227
|
@@ -13,7 +13,7 @@
|
|||||||
** is not included in the SQLite library. It is used for automated
|
** is not included in the SQLite library. It is used for automated
|
||||||
** testing of the SQLite library.
|
** testing of the SQLite library.
|
||||||
**
|
**
|
||||||
** $Id: test3.c,v 1.19 2002/08/31 18:53:08 drh Exp $
|
** $Id: test3.c,v 1.20 2002/11/24 14:52:27 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
#include "pager.h"
|
#include "pager.h"
|
||||||
@@ -822,7 +822,6 @@ static int btree_payload_size(
|
|||||||
sqliteBtreeDataSize(pCur, &n2);
|
sqliteBtreeDataSize(pCur, &n2);
|
||||||
sprintf(zBuf, "%d", n1+n2);
|
sprintf(zBuf, "%d", n1+n2);
|
||||||
Tcl_AppendResult(interp, zBuf, 0);
|
Tcl_AppendResult(interp, zBuf, 0);
|
||||||
free(zBuf);
|
|
||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
111
tool/space_used.tcl
Normal file
111
tool/space_used.tcl
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
# Run this TCL script using "testfixture" in order get a report that shows
|
||||||
|
# how much disk space is used by a particular data to actually store data
|
||||||
|
# versus how much space is unused.
|
||||||
|
#
|
||||||
|
|
||||||
|
# Get the name of the database to analyze
|
||||||
|
#
|
||||||
|
if {[llength $argv]!=1} {
|
||||||
|
puts stderr "Usage: $argv0 database-name"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
set file_to_analyze [lindex $argv 0]
|
||||||
|
|
||||||
|
# Open the database
|
||||||
|
#
|
||||||
|
sqlite db [lindex $argv 0]
|
||||||
|
set DB [btree_open [lindex $argv 0]]
|
||||||
|
|
||||||
|
# Output the schema for the generated report
|
||||||
|
#
|
||||||
|
puts \
|
||||||
|
{BEGIN;
|
||||||
|
CREATE TABLE space_used(
|
||||||
|
name clob, -- Name of a table or index in the database file
|
||||||
|
is_index boolean, -- TRUE if it is an index, false for a table
|
||||||
|
payload int, -- Total amount of data stored in this table or index
|
||||||
|
pri_pages int, -- Number of primary pages used
|
||||||
|
ovfl_pages int, -- Number of overflow pages used
|
||||||
|
pri_unused int, -- Number of unused bytes on primary pages
|
||||||
|
ovfl_unused int -- Number of unused bytes on overflow pages
|
||||||
|
);}
|
||||||
|
|
||||||
|
# This query will be used to find the root page number for every index and
|
||||||
|
# table in the database.
|
||||||
|
#
|
||||||
|
set sql {
|
||||||
|
SELECT name, type, rootpage FROM sqlite_master
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'sqlite_master', 'table', 2
|
||||||
|
ORDER BY 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initialize variables used for summary statistics.
|
||||||
|
#
|
||||||
|
set total_size 0
|
||||||
|
set total_primary 0
|
||||||
|
set total_overflow 0
|
||||||
|
set total_unused_primary 0
|
||||||
|
set total_unused_ovfl 0
|
||||||
|
|
||||||
|
# Analyze every table in the database, one at a time.
|
||||||
|
#
|
||||||
|
foreach {name type rootpage} [db eval $sql] {
|
||||||
|
set cursor [btree_cursor $DB $rootpage 0]
|
||||||
|
set go [btree_first $cursor]
|
||||||
|
set size 0
|
||||||
|
catch {unset pg_used}
|
||||||
|
set unused_ovfl 0
|
||||||
|
set n_overflow 0
|
||||||
|
while {$go==0} {
|
||||||
|
set payload [btree_payload_size $cursor]
|
||||||
|
incr size $payload
|
||||||
|
set stat [btree_cursor_dump $cursor]
|
||||||
|
set pgno [lindex $stat 0]
|
||||||
|
set freebytes [lindex $stat 4]
|
||||||
|
set pg_used($pgno) $freebytes
|
||||||
|
if {$payload>238} {
|
||||||
|
set n [expr {($payload-238+1019)/1020}]
|
||||||
|
incr n_overflow $n
|
||||||
|
incr unused_ovfl [expr {$n*1020+238-$payload}]
|
||||||
|
}
|
||||||
|
set go [btree_next $cursor]
|
||||||
|
}
|
||||||
|
btree_close_cursor $cursor
|
||||||
|
set n_primary [llength [array names pg_used]]
|
||||||
|
set unused_primary 0
|
||||||
|
foreach x [array names pg_used] {incr unused_primary $pg_used($x)}
|
||||||
|
regsub -all ' $name '' name
|
||||||
|
puts -nonewline "INSERT INTO space_used VALUES('$name'"
|
||||||
|
puts -nonewline ",[expr {$type=="index"}]"
|
||||||
|
puts ",$size,$n_primary,$n_overflow,$unused_primary,$unused_ovfl);"
|
||||||
|
incr total_size $size
|
||||||
|
incr total_primary $n_primary
|
||||||
|
incr total_overflow $n_overflow
|
||||||
|
incr total_unused_primary $unused_primary
|
||||||
|
incr total_unused_ovfl $unused_ovfl
|
||||||
|
}
|
||||||
|
|
||||||
|
# Output summary statistics:
|
||||||
|
#
|
||||||
|
puts "-- Total payload size: $total_size"
|
||||||
|
puts "-- Total pages used: $total_primary primary and $total_overflow overflow"
|
||||||
|
set file_pgcnt [expr {[file size [lindex $argv 0]]/1024}]
|
||||||
|
puts -nonewline "-- Total unused bytes on primary pages: $total_unused_primary"
|
||||||
|
if {$total_primary>0} {
|
||||||
|
set upp [expr {$total_unused_primary/$total_primary}]
|
||||||
|
puts " (avg $upp bytes/page)"
|
||||||
|
} else {
|
||||||
|
puts ""
|
||||||
|
}
|
||||||
|
puts -nonewline "-- Total unused bytes on overflow pages: $total_unused_ovfl"
|
||||||
|
if {$total_overflow>0} {
|
||||||
|
set upp [expr {$total_unused_ovfl/$total_overflow}]
|
||||||
|
puts " (avg $upp bytes/page)"
|
||||||
|
} else {
|
||||||
|
puts ""
|
||||||
|
}
|
||||||
|
set n_free [expr {$file_pgcnt-$total_primary-$total_overflow}]
|
||||||
|
if {$n_free>0} {incr n_free -1}
|
||||||
|
puts "-- Total pages on freelist: $n_free"
|
||||||
|
puts "COMMIT;"
|
Reference in New Issue
Block a user