DB2 Version 10.1 for Linux, UNIX, and Windows

db2Reorg API - Reorganize an index or a table

Reorganizes a table or all indexes defined on a table by compacting the information and reconstructing the rows or index data to eliminate fragmented data.

Authorization

One of the following authorities:

Required connection

Database

API include file

db2ApiDf.h

API and data structure syntax

SQL_API_RC SQL_API_FN
  db2Reorg (
             db2Uint32 versionNumber,
             void * pReorgStruct,
             struct sqlca * pSqlca);

typedef SQL_STRUCTURE db2ReorgStruct
{
  db2Uint32 reorgType;
  db2Uint32 reorgFlags;
  db2int32 nodeListFlag;
  db2Uint32 numNodes;
  SQL_PDB_NODE_TYPE *pNodeList;
  union db2ReorgObject        reorgObject;
} db2ReorgStruct;

union db2ReorgObject
{
  struct db2ReorgTable             tableStruct;
  struct db2ReorgIndexesAll        indexesAllStruct;
};

typedef SQL_STRUCTURE db2ReorgTable
{
  char *pTableName;
  char *pOrderByIndex;
  char *pSysTempSpace;
  char *pLongTempSpace;
  char *pPartitionName;
} db2ReorgTable;

typedef SQL_STRUCTURE db2ReorgIndexesAll
{
  char *pTableName;
  char *pIndexName;
  char *pPartitionName;
} db2ReorgIndexesAll;

SQL_API_RC SQL_API_FN
  db2gReorg (
              db2Uint32 versionNumber,
              void * pReorgStruct,
              struct sqlca * pSqlca);

typedef SQL_STRUCTURE db2gReorgStruct
{
  db2Uint32 reorgType;
  db2Uint32 reorgFlags;
  db2int32 nodeListFlag;
  db2Uint32 numNodes;
  SQL_PDB_NODE_TYPE *pNodeList;
  union db2gReorgObject       reorgObject;
} db2gReorgStruct;

typedef SQL_STRUCTURE db2gReorgNodes
{
  SQL_PDB_NODE_TYPE nodeNum[SQL_PDB_MAX_NUM_NODE];
} db2gReorgNodes;

union db2gReorgObject
{
  struct db2gReorgTable            tableStruct;
  struct db2gReorgIndexesAll       indexesAllStruct;
};

typedef SQL_STRUCTURE db2gReorgTable
{
  db2Uint32 tableNameLen;
  char *pTableName;
  db2Uint32 orderByIndexLen;
  char *pOrderByIndex;
  db2Uint32 sysTempSpaceLen;
  char *pSysTempSpace;
  db2Uint32 longTempSpaceLen;
  char *pLongTempSpace;
  db2Uint32 partitionNameLen;
  char *pPartitionName;
} db2gReorgTable;

typedef SQL_STRUCTURE db2gReorgIndexesAll
{
  db2Uint32 tableNameLen;
  char *pTableName;
  db2Uint32 indexNameLen;
  char *pIndexName;
  db2Uint32  partitionNameLen;
  char *pPartitionName;
} db2gReorgIndexesAll;

db2Reorg API parameters

versionNumber
Input. Specifies the version and release level of the structure passed as the second parameter, pReorgStruct.
pReorgStruct
Input. A pointer to the db2ReorgStruct structure.
pSqlca
Output. A pointer to the sqlca structure.

db2ReorgStruct data structure parameters

reorgType
Input. Specifies the type of reorganization. Valid values (defined in db2ApiDf header file, located in the include directory) are:
DB2REORG_OBJ_TABLE_OFFLINE
Reorganize the table offline.
DB2REORG_OBJ_TABLE_INPLACE
Reorganize the table inplace.

INPLACE (online) reorganization is not supported in DB2® pureScale® environments. Any attempts to perform an inplace reorganization in DB2 pureScale environments will fail with SQL1419N.

DB2REORG_OBJ_INDEXESALL
Reorganize all indexes.
DB2REORG_OBJ_INDEX
Reorganize one index.
DB2REORG_RECLAIM_EXTENTS
Reorganize a multidimensional clustering (MDC) or insert time clustering (ITC) table to reclaim empty extents for the table space.
reorgFlags
Input. Reorganization options. Valid values (defined in db2ApiDf header file, located in the include directory) are:
DB2REORG_OPTION_NONE
Default action.
DB2REORG_LONGLOB
Reorganize long fields and lobs, used when DB2REORG_OBJ_TABLE_OFFLINE is specified as the reorgType. If DB2REORG_RESETDICTIONARY or DB2REORG_KEEPDICTIONARY option is also specified, the options apply to the XML storage object of the table in addition to the table object.
DB2REORG_INDEXSCAN
Recluster utilizing index scan, used when DB2REORG_OBJ_TABLE_OFFLINE is specified as the reorgType.
DB2REORG_START_ONLINE
Start online reorganization, used when DB2REORG_OBJ_TABLE_INPLACE is specified as the reorgType. This parameter is not supported in DB2 pureScale environments.
DB2REORG_PAUSE_ONLINE
Pause an existing online reorganization, used when DB2REORG_OBJ_TABLE_INPLACE is specified as the reorgType. This parameter is not supported in DB2 pureScale environments.
DB2REORG_STOP_ONLINE
Stop an existing online reorganization, used when DB2REORG_OBJ_TABLE_INPLACE is specified as the reorgType. This parameter is not supported in DB2 pureScale environments.
DB2REORG_RESUME_ONLINE
Resume a paused online reorganization, used when DB2REORG_OBJ_TABLE_INPLACE is specified as the reorgType. This parameter is not supported in DB2 pureScale environments.
DB2REORG_NOTRUNCATE_ONLINE
Do not perform table truncation, used when DB2REORG_OBJ_TABLE_INPLACE is specified as the reorgType. This parameter is not supported in DB2 pureScale environments.
DB2REORG_ALLOW_NONE
No read or write access to the table. This parameter is not supported when DB2REORG_OBJ_TABLE_INPLACE is specified as the reorgType.
DB2REORG_ALLOW_WRITE
Allow read and write access to the table. This parameter is not supported when DB2REORG_OBJ_TABLE_OFFLINE is specified as the reorgType. This parameter is supported in DB2 pureScale environments only when the DB2REORG_INDEX_RECLAIM_EXTENTS, DB2REORG_CLEANUP_ALL or the DB2REORG_CLEANUP_PAGES option is also specified.
DB2REORG_ALLOW_READ
Allow only read access to the table. This parameter is supported in DB2 pureScale environments only when the DB2REORG_INDEX_RECLAIM_EXTENTS, DB2REORG_CLEANUP_ALL or the DB2REORG_CLEANUP_PAGES option is also specified.
DB2REORG_CLEANUP_NONE
This value has been deprecated in Version 10.1. It indicates that no clean up is required when the reorgType is set to DB2REORG_OBJ_INDEXESALL or DB2REORG_OBJ_INDEX. Not specifying this value has the same effect, therefore, specifying the value is redundant.
DB2REORG_CLEANUP_ALL
Clean up the committed pseudo deleted keys and committed pseudo empty pages, used when DB2REORG_OBJ_INDEXESALL or DB2REORG_OBJ_INDEX are specified as the reorgType.
If DB2REORG_CLEANUP_ALL is specified with DB2REORG_INDEX_REBUILD an error, SQL2218N, is returned.
DB2REORG_CLEANUP_PAGES
Clean up committed pseudo empty pages only, but do not clean up pseudo deleted keys on pages that are not pseudo empty, used when DB2REORG_OBJ_INDEXESALL or DB2REORG_OBJ_INDEX are specified as the reorgType.
If DB2REORG_CLEANUP_PAGES is specified with DB2REORG_INDEX_REBUILD an error, SQL2218N, is returned.
DB2REORG_CONVERT_NONE
This value has been deprecated in Version 10.1. In earlier releases, this value indicated that no index conversion was required when the reorgType is set to DB2REORG_OBJ_INDEXESALL or DB2REORG_OBJ_INDEX. This value has become obsolete because type-1 indexes were discontinued since Version 9.7.
DB2REORG_RESET_DICTIONARY
If the DB2REORG_LONGLOB option is also specified, DB2REORG_RESETDICTIONARY applies to the XML storage object of the table also. If the COMPRESS attribute for the table is YES then a new compression dictionary is built. All the rows processed during reorganization are subject to compression using this new dictionary. This dictionary replaces any previous dictionary in the object. If the COMPRESS attribute for the table is NO and the table object or the XML storage object does have an existing compression dictionary then reorg processing will remove the dictionary and all rows in the newly reorganized table will be in non-compressed format. This parameter is only supported for the DB2REORG_OBJ_TABLE_OFFLINE reorgType.
DB2REORG_KEEP_DICTIONARY
If DB2REORG_LONGLOB keyword is also specified, DB2REORG_KEEPDICTIONARY applies to the table object and the XML storage object of the table. If DB2REORG_LONGLOB is not specified, the following applies only to the table object.
If the COMPRESS attribute for the table is YES and a dictionary exists, it is kept. If the COMPRESS attribute for the table is YES and a dictionary does not exist, one is built, as the option defaults to DB2REORG_RESET_DICTIONARY in that case. All rows processed by reorganization are subject to compression. If the COMPRESS attribute for the table is NO, the dictionary will be retained (if one existed), and all rows in the newly reorganized table will be in non-compressed format. This parameter is only supported for the DB2REORG_OBJ_TABLE_OFFLINE reorgType.
DB2REORG_INDEX_RECLAIM_EXTENTS
Reclaim extents from the index object back to the table space, used when DB2REORG_OBJ_INDEXESALL or DB2REORG_OBJ_INDEX is specified as the reorgType.
If DB2REORG_INDEX_RECLAIM_EXTENTS is specified with DB2REORG_INDEX_REBUILD an error, SQL2218N, is returned.
DB2REORG_INDEX_REBUILD
Rebuild the index data, used when DB2REORG_OBJ_INDEXESALL or DB2REORG_OBJ_INDEX is specified as the reorgType.
If DB2REORG_INDEX_REBUILD is specified with DB2REORG_INDEX_RECLAIM_EXTENTS, DB2REORG_CLEANUP_ALL, or DB2REORG_CLEANUP_PAGES an error, SQL2218N, is returned.
nodeListFlag
Input. Specifies which nodes to reorganize. Valid values (defined in db2ApiDf header file, located in the include directory) are:
DB2REORG_NODE_LIST
Submit to all nodes in the nodelist array.
DB2REORG_ALL_NODES
Submit to all nodes in the database partition group.
DB2REORG_ALL_EXCEPT
Submit to all nodes except the ones specified by the nodelist parameter.
numNodes
Input. Number of nodes in the nodelist array.
pNodeList
A pointer to the array of node numbers.
reorgObject
Input. Specifies the type of object to be reorganized.

db2ReorgObject union parameters

tableStruct
Specifies the options for a table reorganization.
indexesAllStruct
Specifies the options for an index reorganization.

db2ReorgTable data structure parameters

pTableName
Input. Specifies the name of the table to reorganize.
pOrderByIndex
Input. Specifies the index to order the table by.
pSysTempSpace
Input. Specifies the system temporary table space where temporary objects are created. The REORG command may expand rows in cases where a column is added to a table (such as from ALTER TABLE ADD COLUMN) and the rows were inserted before the column was added. For a nonpartitioned table, this parameter must specify a table space with enough room to create the new table object. A partitioned table is reorganized a single data partition at a time. In this case, there must be enough free space in the table space to hold the largest data partition of the table. When the pPartitionName parameter is specified, the temporary table space must be able to hold the specified partition.

If this parameter is not specified for a nonpartitioned table the table space the table resides in is used. If this parameter is not specified for a partitioned table, the table space where each data partition is located is used for temporary storage of that data partition. There must be enough free space in each data partition's table space to hold a copy of the data partition.

pLongTempSpace
Input. Specifies the temporary table space to create long objects (LONG VARCHAR and LOB columns) in during table reorganization. If the pSysTempSpace parameter is not specified, this parameter is ignored. If this parameter is not specified, but the pSysTempSpace parameter is specified, then DB2 will create the long data objects in the table space specified by the pSysTempSpace parameter, unless the page sizes differ.

When page sizes differ, if pSysTempSpace is specified, but this parameter is not, DB2 will attempt to find an existing table space with a matching page size to create the long objects in.

pPartitionName
Input. Specifies the name of the data partition to reorganize.

db2ReorgIndexesAll data structure parameters

pTableName
Input. Specifies the name of the table for index reorganization. If DB2REORG_OBJ_INDEX is specified as the reorgType, the pTableName parameter is not required and can be NULL. However, if the pTableName parameter is specified, it must be the table on which the index is defined.
pIndexName
Input. Specifies the name of the index to reorganize. This parameter is used only when the reorgType parameter is set to a value of DB2REORG_OBJ_INDEX otherwise set pIndexName parameter to NULL.
pPartitionName
Input. Specifies the name of the data partition whose indexes are to be reorganized.

db2gReorgTable data structure specific parameters

tableNameLen
Input. Specifies the length in bytes of pTableName.
orderByIndexLen
Input. Specifies the length in byte of pOrderByIndex.
sysTempSpaceLen
Input. Specifies the length in bytes of pSysTempSpace.
longTempSpaceLen
Input. Specifies the length of the name stored in the pLongTempSpace
partitionNameLen
Input. Specifies the length, in bytes, of pPartitionName.
pPartitionName
Input. Specifies the name of the data partition to reorganize.

db2gReorgIndexesAll data structure specific parameters

tableNameLen
Input. Specifies the length in bytes of pTableName.
indexNameLen
Input. Specifies the length in bytes of the pIndexName parameter.
partitionNameLen
Input. Specifies the length, in bytes, of pPartitionName.
pPartitionName
Input. Specifies the name of the data partition for the index.

Usage notes