Ah, this tool seems very handy. For those curious, I'll paste the results
below. The index approximately doubles the storage size, but I am
intentionally making that tradeoff to avoid the slow down when enforcing a
unique/primary key on the Reference table while inserting.

-AJ

/** Disk-Space Utilization Report For F:/mytestdb2.db

Page size in bytes................................ 4096      
Pages in the whole file (measured)................ 104071490 
Pages in the whole file (calculated).............. 104071489 
Pages that store data............................. 104071489  100.000% 
Pages on the freelist (per header)................ 0            0.0% 
Pages on the freelist (calculated)................ 1            0.0% 
Pages of auto-vacuum overhead..................... 0            0.0% 
Number of tables in the database.................. 3         
Number of indices................................. 1         
Number of defined indices......................... 1         
Number of implied indices......................... 0         
Size of the file in bytes......................... 426276823040
Bytes of user payload stored...................... 174138410641  40.9% 

*** Page counts for all tables with their indices
*****************************

REFERENCE......................................... 93008188    89.4% 
MAINDATA.......................................... 11063300    10.6% 
SQLITE_MASTER..................................... 1            0.0% 

*** Page counts for all tables and indices separately
*************************

REFERENCE......................................... 50304534    48.3% 
HASHINDEX......................................... 42703654    41.0% 
MAINDATA.......................................... 11063300    10.6% 
SQLITE_MASTER..................................... 1            0.0% 

*** All tables and indices
****************************************************

Percentage of total database...................... 100.000%  
Number of entries................................. 17948049998
Bytes of storage consumed......................... 426276818944
Bytes of payload.................................. 321412979244  75.4% 
Bytes of metadata................................. 100378462716  23.5% 
Average payload per entry......................... 17.91     
Average unused bytes per entry.................... 0.25      
Average metadata per entry........................ 5.59      
Average fanout.................................... 241.00    
Maximum payload per entry......................... 37003     
Entries that use overflow......................... 53547        0.0% 
Index pages used.................................. 430147    
Primary pages used................................ 103581347 
Overflow pages used............................... 59995     
Total pages used.................................. 104071489 
Unused bytes on index pages....................... 96815925     5.5% 
Unused bytes on primary pages..................... 4383344069   1.0% 
Unused bytes on overflow pages.................... 5242782      2.1% 
Unused bytes on all pages......................... 4485402776   1.1% 

*** All tables
****************************************************************

Percentage of total database......................  59.0%    
Number of entries................................. 9031683455
Bytes of storage consumed......................... 251362652160
Bytes of payload.................................. 174138410911  69.3% 
Bytes of metadata................................. 73116919243  29.1% 
Average payload per entry......................... 19.28     
Average unused bytes per entry.................... 0.45      
Average metadata per entry........................ 8.10      
Average fanout.................................... 332.00    
Maximum payload per entry......................... 37003     
Entries that use overflow......................... 53547        0.0% 
Index pages used.................................. 184608    
Primary pages used................................ 61123232  
Overflow pages used............................... 59995     
Total pages used.................................. 61367835  
Unused bytes on index pages....................... 94142971    12.5% 
Unused bytes on primary pages..................... 4007962045   1.6% 
Unused bytes on overflow pages.................... 5242782      2.1% 
Unused bytes on all pages......................... 4107347798   1.6% 

*** All indices
***************************************************************

Percentage of total database......................  41.0%    
Number of entries................................. 8916366543
Bytes of storage consumed......................... 174914166784
Bytes of payload.................................. 147274568333  84.2% 
Bytes of metadata................................. 27261543473  15.6% 
B-tree depth...................................... 5         
Average payload per entry......................... 16.52     
Average unused bytes per entry.................... 0.04      
Average metadata per entry........................ 3.06      
Average fanout.................................... 173.00    
Maximum payload per entry......................... 17        
Entries that use overflow......................... 0            0.0% 
Index pages used.................................. 245539    
Primary pages used................................ 42458115  
Overflow pages used............................... 0         
Total pages used.................................. 42703654  
Unused bytes on index pages....................... 2672954      0.27% 
Unused bytes on primary pages..................... 375382024    0.22% 
Unused bytes on overflow pages.................... 0         
Unused bytes on all pages......................... 378054978    0.22% 

*** Table MAINDATA
************************************************************

Percentage of total database......................  10.6%    
Number of entries................................. 115316909 
Bytes of storage consumed......................... 45315276800
Bytes of payload.................................. 41033664786  90.6% 
Bytes of metadata................................. 1103219478   2.4% 
B-tree depth...................................... 4         
Average payload per entry......................... 355.83    
Average unused bytes per entry.................... 27.56     
Average metadata per entry........................ 9.57      
Average fanout.................................... 358.00    
Non-sequential pages.............................. 10954556    99.02% 
Maximum payload per entry......................... 37003     
Entries that use overflow......................... 53547        0.046% 
Index pages used.................................. 30681     
Primary pages used................................ 10972624  
Overflow pages used............................... 59995     
Total pages used.................................. 11063300  
Unused bytes on index pages....................... 15769540    12.5% 
Unused bytes on primary pages..................... 3157406006   7.0% 
Unused bytes on overflow pages.................... 5242782      2.1% 
Unused bytes on all pages......................... 3178418328   7.0% 

*** Table REFERENCE and all its indices
***************************************

Percentage of total database......................  89.4%    
Number of entries................................. 17832733086
Bytes of storage consumed......................... 380961538048
Bytes of payload.................................. 280379314188  73.6% 
Bytes of metadata................................. 99275243118  26.1% 
Average payload per entry......................... 15.72     
Average unused bytes per entry.................... 0.07      
Average metadata per entry........................ 5.57      
Average fanout.................................... 232.00    
Maximum payload per entry......................... 17        
Entries that use overflow......................... 0            0.0% 
Index pages used.................................. 399466    
Primary pages used................................ 92608722  
Overflow pages used............................... 0         
Total pages used.................................. 93008188  
Unused bytes on index pages....................... 81046385     5.0% 
Unused bytes on primary pages..................... 1225934357   0.32% 
Unused bytes on overflow pages.................... 0         
Unused bytes on all pages......................... 1306980742   0.34% 

*** Table REFERENCE w/o any indices
*******************************************

Percentage of total database......................  48.3%    
Number of entries................................. 8916366543
Bytes of storage consumed......................... 206047371264
Bytes of payload.................................. 133104745855  64.6% 
Bytes of metadata................................. 72013699645  35.0% 
B-tree depth...................................... 5         
Average payload per entry......................... 14.93     
Average unused bytes per entry.................... 0.10      
Average metadata per entry........................ 8.08      
Average fanout.................................... 326.00    
Non-sequential pages.............................. 11004959    21.9% 
Maximum payload per entry......................... 15        
Entries that use overflow......................... 0            0.0% 
Index pages used.................................. 153927    
Primary pages used................................ 50150607  
Overflow pages used............................... 0         
Total pages used.................................. 50304534  
Unused bytes on index pages....................... 78373431    12.4% 
Unused bytes on primary pages..................... 850552333    0.41% 
Unused bytes on overflow pages.................... 0         
Unused bytes on all pages......................... 928925764    0.45% 

*** Index HASHINDEX of table REFERENCE
****************************************

Percentage of total database......................  41.0%    
Number of entries................................. 8916366543
Bytes of storage consumed......................... 174914166784
Bytes of payload.................................. 147274568333  84.2% 
Bytes of metadata................................. 27261543473  15.6% 
B-tree depth...................................... 5         
Average payload per entry......................... 16.52     
Average unused bytes per entry.................... 0.04      
Average metadata per entry........................ 3.06      
Average fanout.................................... 173.00    
Non-sequential pages.............................. 0            0.0% 
Maximum payload per entry......................... 17        
Entries that use overflow......................... 0            0.0% 
Index pages used.................................. 245539    
Primary pages used................................ 42458115  
Overflow pages used............................... 0         
Total pages used.................................. 42703654  
Unused bytes on index pages....................... 2672954      0.27% 
Unused bytes on primary pages..................... 375382024    0.22% 
Unused bytes on overflow pages.................... 0         
Unused bytes on all pages......................... 378054978    0.22% 

*** Table SQLITE_MASTER
*******************************************************

Percentage of total database......................   0.0%    
Number of entries................................. 3         
Bytes of storage consumed......................... 4096      
Bytes of payload.................................. 270          6.6% 
Bytes of metadata................................. 120          2.9% 
B-tree depth...................................... 1         
Average payload per entry......................... 90.00     
Average unused bytes per entry.................... 1235.33   
Average metadata per entry........................ 40.00     
Maximum payload per entry......................... 94        
Entries that use overflow......................... 0            0.0% 
Primary pages used................................ 1         
Overflow pages used............................... 0         
Total pages used.................................. 1         
Unused bytes on primary pages..................... 3706        90.5% 
Unused bytes on overflow pages.................... 0         
Unused bytes on all pages......................... 3706        90.5% 

*** Definitions
***************************************************************

Page size in bytes

    The number of bytes in a single page of the database file.  
    Usually 1024.

Number of pages in the whole file

    The number of 4096-byte pages that go into forming the complete
    database

Pages that store data

    The number of pages that store data, either as primary B*Tree pages or
    as overflow pages.  The number at the right is the data pages divided by
    the total number of pages in the file.

Pages on the freelist

    The number of pages that are not currently in use but are reserved for
    future use.  The percentage at the right is the number of freelist pages
    divided by the total number of pages in the file.

Pages of auto-vacuum overhead

    The number of pages that store data used by the database to facilitate
    auto-vacuum. This is zero for databases that do not support auto-vacuum.

Number of tables in the database

    The number of tables in the database, including the SQLITE_MASTER table
    used to store schema information.

Number of indices

    The total number of indices in the database.

Number of defined indices

    The number of indices created using an explicit CREATE INDEX statement.

Number of implied indices

    The number of indices used to implement PRIMARY KEY or UNIQUE
constraints
    on tables.

Size of the file in bytes

    The total amount of disk space used by the entire database files.

Bytes of user payload stored

    The total number of bytes of user payload stored in the database. The
    schema information in the SQLITE_MASTER table is not counted when
    computing this number.  The percentage at the right shows the payload
    divided by the total file size.

Percentage of total database

    The amount of the complete database file that is devoted to storing
    information described by this category.

Number of entries

    The total number of B-Tree key/value pairs stored under this category.

Bytes of storage consumed

    The total amount of disk space required to store all B-Tree entries
    under this category.  The is the total number of pages used times
    the pages size.

Bytes of payload

    The amount of payload stored under this category.  Payload is the data
    part of table entries and the key part of index entries.  The percentage
    at the right is the bytes of payload divided by the bytes of storage 
    consumed.

Bytes of metadata

    The amount of formatting and structural information stored in the
    table or index.  Metadata includes the btree page header, the cell
pointer
    array, the size field for each cell, the left child pointer or non-leaf
    cells, the overflow pointers for overflow cells, and the rowid value for
    rowid table cells.  In other words, metadata is everything that is
neither
    unused space nor content.  The record header in the payload is counted
as
    content, not metadata.

Average payload per entry

    The average amount of payload on each entry.  This is just the bytes of
    payload divided by the number of entries.

Average unused bytes per entry

    The average amount of free space remaining on all pages under this
    category on a per-entry basis.  This is the number of unused bytes on
    all pages divided by the number of entries.

Non-sequential pages

    The number of pages in the table or index that are out of sequence.
    Many filesystems are optimized for sequential file access so a small
    number of non-sequential pages might result in faster queries,
    especially for larger database files that do not fit in the disk cache.
    Note that after running VACUUM, the root page of each table or index is
    at the beginning of the database file and all other pages are in a
    separate part of the database file, resulting in a single non-
    sequential page.

Maximum payload per entry

    The largest payload size of any entry.

Entries that use overflow

    The number of entries that user one or more overflow pages.

Total pages used

    This is the number of pages used to hold all information in the current
    category.  This is the sum of index, primary, and overflow pages.

Index pages used

    This is the number of pages in a table B-tree that hold only key (rowid)
    information and no data.

Primary pages used

    This is the number of B-tree pages that hold both key and data.

Overflow pages used

    The total number of overflow pages used for this category.

Unused bytes on index pages

    The total number of bytes of unused space on all index pages.  The
    percentage at the right is the number of unused bytes divided by the
    total number of bytes on index pages.

Unused bytes on primary pages

    The total number of bytes of unused space on all primary pages.  The
    percentage at the right is the number of unused bytes divided by the
    total number of bytes on primary pages.

Unused bytes on overflow pages

    The total number of bytes of unused space on all overflow pages.  The
    percentage at the right is the number of unused bytes divided by the
    total number of bytes on overflow pages.

Unused bytes on all pages

    The total number of bytes of unused space on all primary and overflow 
    pages.  The percentage at the right is the number of unused bytes 
    divided by the total number of bytes.

*******************************************************************************
The entire text of this report can be sourced into any SQL database
engine for further analysis.  All of the text above is an SQL comment.
The data used to generate this report follows:
*/
BEGIN;
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
   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
   mx_payload int,   -- Maximum payload size
   int_pages int,    -- Number of interior pages used
   leaf_pages int,   -- Number of leaf pages used
   ovfl_pages int,   -- Number of overflow pages used
   int_unused int,   -- Number of unused bytes on interior pages
   leaf_unused int,  -- Number of unused bytes on primary pages
   ovfl_unused int,  -- Number of unused bytes on overflow pages
   gap_cnt int,      -- Number of gaps in the page layout
   compressed_size int  -- Total bytes stored on disk
);
INSERT INTO space_used
VALUES('sqlite_master','sqlite_master',0,0,3,3,1,270,0,0,94,0,1,0,0,3706,0,0,4096);
INSERT INTO space_used VALUES

('MainData','MainData',0,0,126289532,115316909,4,41033664786,240256758,53547,37003,30681,10972624,59995,15769540,3157406006,

5242782,10954556,45315276800);
INSERT INTO space_used VALUES

('Reference','Reference',0,0,8966517149,8916366543,5,133104745855,0,0,15,153927,50150607,0,78373431,850552333,0,11004959,206

047371264);
INSERT INTO space_used VALUES

('HashIndex','Reference',1,0,8916366543,8873908429,5,147274568333,0,0,17,245539,42458115,0,2672954,375382024,0,0,17491416678

4);
COMMIT;




--
Sent from: http://sqlite.1065341.n5.nabble.com/
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to