org.apache.derby.iapi.db
Class OnlineCompress

java.lang.Object
  extended byorg.apache.derby.iapi.db.OnlineCompress

public class OnlineCompress
extends java.lang.Object

Implementation of SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE().

Code which implements the following system procedure: void SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE( IN SCHEMANAME VARCHAR(128), IN TABLENAME VARCHAR(128), IN PURGE_ROWS SMALLINT, IN DEFRAGMENT_ROWS SMALLINT, IN TRUNCATE_END SMALLINT)

This system procedure can be used to force 3 levels of in place compression of a SQL table. The table is specified using the SCHEMANAME and TABLENAME arguments.

If PURGE_ROWS is set to non-zero then a single pass is made through the table which will purge committed deleted rows from the table. This space is then available for future inserted rows, but remains allocated to the table. As this option scans every page of the table, it's performance is linearly related to the size of the table.

If DEFRAGMENT_ROWS is set to non-zero then a single defragment pass is made which will move existing rows from the end of the table towards the front of the table. The goal of the defragment run is to empty a set of pages at the end of the table which can then be returned to the OS by the TRUNCATE_END option. It is recommended to only run DEFRAGMENT_ROWS, if also specifying the TRUNCATE_END option. This option scans the whole table and needs to update index entries for every base table row move, and thus execution time is linearly related to the size of the table.

If TRUNCATE_END is set to non-zero then all contiguous pages at the end of the table will be returned to the OS. Running the DEFRAGMENT_ROWS option may increase the number of pages affected. This option itself does no scans of the table, so performs on the order of a few system calls. TODO LIST: o defragment requires table level lock in nested user transaction, which will conflict with user lock on same table in user transaction.


Constructor Summary
private OnlineCompress()
          no requirement for a constructor
 
Method Summary
static void compressTable(java.lang.String schemaName, java.lang.String tableName, boolean purgeRows, boolean defragmentRows, boolean truncateEnd)
          Implementation of SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE().
private static void defragmentRows(java.lang.String schemaName, java.lang.String tableName, DataDictionary data_dictionary, TransactionController tc)
          Defragment rows in the given table.
private static void fixIndex(DataValueDescriptor[] base_row, DataValueDescriptor[] index_row, RowLocation old_row_loc, RowLocation new_row_loc, ConglomerateController index_cc, ScanController index_scan, int[] index_col_map)
          Delete old index row and insert new index row in input index.
private static void purgeRows(java.lang.String schemaName, java.lang.String tableName, DataDictionary data_dictionary, TransactionController tc)
          Purge committed deleted rows from conglomerate.
private static void setup_indexes(TransactionController tc, TableDescriptor td, int[][] index_col_map, ScanController[] index_scan, ConglomerateController[] index_cc, DataValueDescriptor[][] index_row)
           
private static void truncateEnd(java.lang.String schemaName, java.lang.String tableName, DataDictionary data_dictionary, TransactionController tc)
          Truncate end of conglomerate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OnlineCompress

private OnlineCompress()
no requirement for a constructor

Method Detail

compressTable

public static void compressTable(java.lang.String schemaName,
                                 java.lang.String tableName,
                                 boolean purgeRows,
                                 boolean defragmentRows,
                                 boolean truncateEnd)
                          throws java.sql.SQLException
Implementation of SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE().

Top level implementation of the system procedure. All the real work is found in the other routines in this file implementing the 3 phases of inplace compression: purge, defragment, and truncate.

Parameters:
schemaName - schema name of table, required
tableName - table name to be compressed
purgeRows - if true, do a purge pass on the table
defragmentRows - if true, do a defragment pass on the table
truncateEnd - if true, return empty pages at end to OS.
Throws:
java.sql.SQLException - Errors returned by throwing SQLException.

defragmentRows

private static void defragmentRows(java.lang.String schemaName,
                                   java.lang.String tableName,
                                   DataDictionary data_dictionary,
                                   TransactionController tc)
                            throws java.sql.SQLException
Defragment rows in the given table.

Scans the rows at the end of a table and moves them to free spots towards the beginning of the table. In the same transaction all associated indexes are updated to reflect the new location of the base table row.

After a defragment pass, if was possible, there will be a set of empty pages at the end of the table which can be returned to the operating system by calling truncateEnd(). The allocation bit maps will be set so that new inserts will tend to go to empty and half filled pages starting from the front of the conglomerate.

Parameters:
schemaName - schema of table to defragement
tableName - name of table to defragment
data_dictionary - An open data dictionary to look up the table in.
tc - transaction controller to use to do updates.
Throws:
java.sql.SQLException

purgeRows

private static void purgeRows(java.lang.String schemaName,
                              java.lang.String tableName,
                              DataDictionary data_dictionary,
                              TransactionController tc)
                       throws StandardException
Purge committed deleted rows from conglomerate.

Scans the table and purges any committed deleted rows from the table. If all rows on a page are purged then page is also reclaimed.

Parameters:
schemaName - schema of table to defragement
tableName - name of table to defragment
data_dictionary - An open data dictionary to look up the table in.
tc - transaction controller to use to do updates.
Throws:
StandardException

truncateEnd

private static void truncateEnd(java.lang.String schemaName,
                                java.lang.String tableName,
                                DataDictionary data_dictionary,
                                TransactionController tc)
                         throws StandardException
Truncate end of conglomerate.

Returns the contiguous free space at the end of the table back to the operating system. Takes care of space allocation bit maps, and OS call to return the actual space.

Parameters:
schemaName - schema of table to defragement
tableName - name of table to defragment
data_dictionary - An open data dictionary to look up the table in.
tc - transaction controller to use to do updates.
Throws:
StandardException

setup_indexes

private static void setup_indexes(TransactionController tc,
                                  TableDescriptor td,
                                  int[][] index_col_map,
                                  ScanController[] index_scan,
                                  ConglomerateController[] index_cc,
                                  DataValueDescriptor[][] index_row)
                           throws StandardException
Throws:
StandardException

fixIndex

private static void fixIndex(DataValueDescriptor[] base_row,
                             DataValueDescriptor[] index_row,
                             RowLocation old_row_loc,
                             RowLocation new_row_loc,
                             ConglomerateController index_cc,
                             ScanController index_scan,
                             int[] index_col_map)
                      throws StandardException
Delete old index row and insert new index row in input index.

Parameters:
base_row - all columns of base row
index_row - an index row template, filled in by this routine
old_row_loc - old location of base row, used to delete index
new_row_loc - new location of base row, used to update index
index_cc - index conglomerate to insert new row
index_scan - index scan to delete old entry
index_col_map - description of mapping of index row to base row,
Throws:
StandardException - Standard exception policy.

Built on Mon 2007-06-04 09:58:47+0400, from revision ???

Apache Derby V10.1 Engine Documentation - Copyright © 1997,2005 The Apache Software Foundation or its licensors, as applicable.