db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stanley Bradbury <Stan.Bradb...@gmail.com>
Subject Re: How do I tell whether a table has unused space or not?
Date Tue, 28 Mar 2006 18:58:56 GMT
Bryan Pendleton wrote:

> Recently, I had a table which was able to substantially
> benefit from compression. I determined that I had a problem
> by setting derby.logQueryPlan to TRUE, running a "select *"
> query against the table, and then viewing the page and
> row count statistics that were emitted in the query plan,
> where I saw that the optimizer was expecting to process many
> more pages than I thought needed to be in the table.
> Compressing the table made my problem go away, and the
> optimizer returned to choosing my desired query plans.
> But I am left with the desire for an easier way to figure
> out whether my table needs compression or not.
> I tried reading the manual, for example I found
> http://db.apache.org/derby/docs/10.1/adminguide/cadminspace21579.html
> but that page does not offer any clear way to tell whether a
> table needs to be compressed or not.
> What is the preferred way to decide whether a table has unused space?
> thanks,
> bryan
Hi Bryan -
You can use the diagnostic method SpaceTable to find out how many pages 
are allocated to a table and obtain an estimate of how much space might 
be saved by running  the COMPRESS_TABLE procedure (column: 
ESTIMSPACESAVING).  The method takes a SCHEMA name (optional) and a 
TABLE name.  The query looks like this:

select * from NEW org.apache.derby.diag.SpaceTable('SCHEMANAME', 

ij> select * from NEW 
org.apache.derby.diag.SpaceTable('SYS','SYSTABLES') as ST;
        |1     |1                   |0                   
|1                   |4096       |0
        |1     |1                   |0                   
|1                   |4096       |0
        |0     |1                   |0                   
|1                   |4096       |0

3 rows selected

You might be interested in following the enhancement request *DERBY-512 
</jira/browse/DERBY-512> *this identifies the need to reclaim space 
automatically so COMPRESS_TABLE is no longer needed.

View raw message