Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.derby.iapi.db
Class OnlineCompress  view OnlineCompress download OnlineCompress.java

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, org.apache.derby.iapi.sql.dictionary.DataDictionary data_dictionary, org.apache.derby.iapi.store.access.TransactionController tc)
          Defragment rows in the given table.
private static void fixIndex(org.apache.derby.iapi.types.DataValueDescriptor[] base_row, org.apache.derby.iapi.types.DataValueDescriptor[] index_row, org.apache.derby.iapi.types.RowLocation old_row_loc, org.apache.derby.iapi.types.RowLocation new_row_loc, org.apache.derby.iapi.store.access.ConglomerateController index_cc, org.apache.derby.iapi.store.access.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, org.apache.derby.iapi.sql.dictionary.DataDictionary data_dictionary, org.apache.derby.iapi.store.access.TransactionController tc)
          Purge committed deleted rows from conglomerate.
private static void setup_indexes(org.apache.derby.iapi.store.access.TransactionController tc, org.apache.derby.iapi.sql.dictionary.TableDescriptor td, int[][] index_col_map, org.apache.derby.iapi.store.access.ScanController[] index_scan, org.apache.derby.iapi.store.access.ConglomerateController[] index_cc, org.apache.derby.iapi.types.DataValueDescriptor[][] index_row)
           
private static void truncateEnd(java.lang.String schemaName, java.lang.String tableName, org.apache.derby.iapi.sql.dictionary.DataDictionary data_dictionary, org.apache.derby.iapi.store.access.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.


defragmentRows

private static void defragmentRows(java.lang.String schemaName,
                                   java.lang.String tableName,
                                   org.apache.derby.iapi.sql.dictionary.DataDictionary data_dictionary,
                                   org.apache.derby.iapi.store.access.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.


purgeRows

private static void purgeRows(java.lang.String schemaName,
                              java.lang.String tableName,
                              org.apache.derby.iapi.sql.dictionary.DataDictionary data_dictionary,
                              org.apache.derby.iapi.store.access.TransactionController tc)
                       throws org.apache.derby.iapi.error.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.


truncateEnd

private static void truncateEnd(java.lang.String schemaName,
                                java.lang.String tableName,
                                org.apache.derby.iapi.sql.dictionary.DataDictionary data_dictionary,
                                org.apache.derby.iapi.store.access.TransactionController tc)
                         throws org.apache.derby.iapi.error.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.


setup_indexes

private static void setup_indexes(org.apache.derby.iapi.store.access.TransactionController tc,
                                  org.apache.derby.iapi.sql.dictionary.TableDescriptor td,
                                  int[][] index_col_map,
                                  org.apache.derby.iapi.store.access.ScanController[] index_scan,
                                  org.apache.derby.iapi.store.access.ConglomerateController[] index_cc,
                                  org.apache.derby.iapi.types.DataValueDescriptor[][] index_row)
                           throws org.apache.derby.iapi.error.StandardException

fixIndex

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