Syntax and options of the REBUILD INDEX control statement

The REBUILD INDEX utility control statement, with its multiple options, defines the function that the utility job performs.

You can create a control statement with the ISPF/PDF edit function. After creating it, save it in a sequential or partitioned data set. When you create the JCL for running the job, use the SYSIN DD statement to specify the name of the data set that contains the utility control statement.

Start of change

Syntax diagram

Read syntax diagramSkip visual syntax diagram REBUILD INDEX(,creatorid. index-name1PARTinteger)(ALL)table-space-specLISTlistdef-nameINDEXSPACE(,database-name.index-space-namePARTinteger)(ALL)table-space-specLISTlistdef-nameSHRLEVELREFERENCESHRLEVELCHANGEchange-specdrain-specCLONESCOPEALLSCOPEPENDINGREUSESORTDEVTdevice-typeSORTNUMintegerstats-specFLASHCOPYNOFLASHCOPYYESCONSISTENTFCCOPYDDN( template-name)PARALLEL(0)PARALLEL( num-subtasks)RBALRSN_CONVERSIONEXTENDEDRBALRSN_CONVERSIONNONE
table-space-spec
Read syntax diagramSkip visual syntax diagram TABLESPACE database-name. table-space-name PARTinteger
change-spec
Read syntax diagramSkip visual syntax diagramMAXROIRLMRWT-valueMAXROintegerDEFERLONGLOGCONTINUELONGLOGTERMDRAINDELAY1200DELAYinteger
drain-spec
Read syntax diagramSkip visual syntax diagramDRAIN_WAITIRLMRWT-valueDRAIN_WAITintegerRETRYUTIMOUT-valueRETRYintegerRETRY_DELAYcalculated-defaultRETRY_DELAYinteger
stats-spec
Read syntax diagramSkip visual syntax diagram STATISTICS REPORTNOREPORTYEScorrelation-stats-specUPDATEALLUPDATEACCESSPATHSPACE NONEINVALIDATECACHENOINVALIDATECACHEYESHISTORYALLACCESSPATHSPACE NONEFORCEROLLUPYESNO
correlation-stats-spec
Read syntax diagramSkip visual syntax diagramKEYCARD2FREQVALNUMCOLS1COUNT10FREQVALNUMCOLSintegerCOUNTinteger3MOSTBOTHLEASTHISTOGRAMNUMCOLS1NUMQUANTILES100NUMCOLSintegerNUMQUANTILES100NUMQUANTILESinteger
Notes:
  • 1 All listed indexes must reside in the same table space.
  • 2 The KEYCARD option is deprecated. The functionality previously controlled by KEYCARD is incorporated into the default processing of inline statistics during the execution of REBUILD INDEX STATISTICS and cannot be disabled.
  • 3 When the COUNT keyword is not specified, the utility automatically determines the count value and collects the most frequently occurring values.
End of change

Option descriptions

INDEX creator-id.index-name
Indicates the qualified name of the index to be rebuilt. Use the form creator-id.index-name to specify the name.
creator-id
Specifies the creator of the index. This qualifier is optional. If you omit the qualifier creator-id, Db2 uses the user identifier for the utility job.
index-name
Specifies the qualified name of the index that is to be rebuilt. For an index, you can specify either an index name or an index space name. Enclose the index name in quotation marks if the name contains a blank.

To rebuild multiple indexes, separate each index name with a comma. All listed indexes must reside in the same table space. If more than one index is listed and the TABLESPACE keyword is not specified, Db2 locates the first valid index name that is cited and determines the table space in which that index resides. That table space is used as the target table space for all other valid index names that are listed.

INDEXSPACE database-name.index-space-name
Specifies the qualified name of the index space that is obtained from the SYSIBM.SYSINDEXES table.
database-name
Specifies the name of the database that is associated with the index. This qualifier is optional.
index-space-name
Specifies the qualified name of the index space to copy. For an index, you can specify either an index name or an index space name.
If you specify more than one index space, they must all be defined on the same table space.

For an index, you can specify either an index name or an index space name.

(ALL)
Specifies that all indexes in the table space that is referred to by the TABLESPACE keyword are to be rebuilt. If you specify ALL, only indexes on the base table are included.
TABLESPACE database-name.table-space-name
Specifies the table space from which all indexes are to be rebuilt.
database-name
Identifies the database to which the table space belongs.

The default value is DSNDB04.

table-space-name
Identifies the table space from which all indexes are to be rebuilt.
PART integer

Specifies the physical partition of a partitioning index or a data-partitioned secondary index in a partitioned table that is to be rebuilt. When the target of the REBUILD operation is a nonpartitioned secondary index, the utility reconstructs logical partitions. If any of the following situations are true for a nonpartitioned index, you cannot rebuild individual logical partitions:

  • the index was created with DEFER YES
  • the index must be completely rebuilt (This situation is likely in a disaster recovery scenario)
  • the index is in page set REBUILD-pending (PSRBD) status

For these cases, you must rebuild the entire index.

integer is the physical partition number. It must be in the range from 1 to the number of partitions that are defined for the table space. The maximum is 4096.

Start of changeYou cannot specify PART with the LIST keyword. Use LISTDEF PARTLEVEL for partitioning or data-partitioned secondary indexes. The PARTLEVEL keyword is ignored for nonpartitioned secondary indexes; if it is specified, the entire index will be rebuilt. End of change

LIST listdef-name
Specifies the name of a previously defined LISTDEF list name. The utility allows one LIST keyword for each REBUILD INDEX control statement. The list must contain either all index spaces or all table spaces. For a table space list, REBUILD is invoked once per table space. For an index space list, Db2 groups indexes by their related table space and executes the rebuild once per table space. This utility will only process clone data if the CLONE keyword is specified. The use of CLONED YES on the LISTDEF utility control statement is not sufficient.

Start of changeThe partitions or partition ranges for partitioning or data-partitioned secondary indexes can be specified in a list. Logical partitions for nonpartitioned secondary indexes cannot be specified in a list.End of change

SHRLEVEL
Indicates the type of access that is to be allowed for the index, table space, or partition that is to be checked during REBUILD INDEX processing.
REFERENCE
Specifies that applications can read from but cannot write to the table space or partition that REBUILD accesses. Applications cannot read or write from the index REBUILD is building.
CHANGE
Specifies that applications can read from and write to the table space or partition. The index is placed in RBDP and can be avoided by dynamic SQL. CHANGE is invalid for indexes over XML tables.

Do not specify SHRLEVEL CHANGE for an index on a NOT LOGGED table space.

Restriction:
  • SHRLEVEL CHANGE is not well suited for unique indexes and concurrent DML because the index is placed in RBDP while being built. Inserts and updates of the index will fail with a resource unavailable (-904) because uniqueness checking cannot be done while the index is in RBDP.
  • SHRLEVEL CHANGE is not allowed on not logged tables, XML indexes, or spatial indexes.
MAXRO
Specifies the maximum amount of time for the last iteration of log processing. During that iteration, applications have read-only access.

The actual execution time of the last iteration might exceed the specified value for MAXRO.

integer
integer is the number of seconds. Specifying a small positive value reduces the length of the period of read-only access, but it might increase the elapsed time for REBUILD INDEX to complete. If you specify a huge positive value, the second iteration of log processing is probably the last iteration.

The default value is the value of the lock timeout subsystem parameter IRLMRWT.

LONGLOG
Specifies the action that Db2 is to perform, after sending a message to the console, if the number of records that the next iteration of logging is to process is not sufficiently lower than the number that the previous iterations processed. This situation means that the reading of the log by the REBUILD INDEX utility is not being done at the same time as the writing of the application log.
CONTINUE
Specifies that until the time on the JOB statement expires, Db2 is to continue performing reorganization, including iterations of log processing, if the estimated time to perform an iteration exceeds the time that is specified for MAXRO.
TERM
Specifies that Db2 is to terminate the reorganization after the delay that is specified by the DELAY parameter.
DRAIN
Specifies that Db2 is to drain the write claim class after the delay that is specified by the DELAY parameter. This action forces the final iteration of log processing to occur.
DELAY integer
Specifies the minimum integer between the time that REBUILD send the LONGLOG message to the console and the time that REBUILD performs the action the LONGLOG parameter specifies.

The integer specifies the number of seconds.

The default value is 1200.

DRAIN_WAIT
Specifies the number of seconds that REBUILD INDEX is to wait when draining the table space or index. The specified time is the aggregate time for objects that are to be checked. This value overrides the values that are specified by the IRLMRWT and UTIMOUT subsystem parameters.

integer can be any integer from 0 to 1800. If you do not specify DRAIN_WAIT or specify a value of 0, the utility uses the value of the lock timeout subsystem parameter IRLMRWT.

RETRY integer
Specifies the maximum number of retries that REBUILD INDEX is to attempt.

integer can be any integer from 0 to 255. If you do not specify RETRY, REBUILD INDEX uses the value of the utility multiplier system parameter UTIMOUT.

Specifying RETRY can increase processing costs and result in multiple or extended periods during which the specified index, table space, or partition is in read-only access.

RETRY_DELAY integer
Specifies the minimum duration, in seconds, between retries. integer can be any integer from 1 to 1800.

If you do not specify RETRY_DELAY, REBUILD INDEX uses the DRAIN_WAIT value × RETRY value.

CLONE
Indicates that REBUILD INDEX is to reconstruct only the specified indexes that are on clone tables. This utility will only process clone data if the CLONE keyword is specified. The use of CLONED YES on the LISTDEF statement is not sufficient. If you specify CLONE, you cannot specify STATISTICS. Statistics are not collected for clone objects.
SCOPE
Indicates the scope of the rebuild organization of the specified index or indexes.
ALL
Indicates that you want the specified index or indexes to be rebuilt.
PENDING
Indicates that you want the specified index or indexes with one or more partitions in the following states to be rebuilt:
  • REBUILD-pending (RBDP)
  • REBUILD-pending star (RBDP*)
  • page set REBUILD-pending (PSRBD)
  • RECOVER-pending (RECP)
  • advisory REORG-pending (AREO*)
REUSE
Specifies that REBUILD should logically reset and reuse Db2-managed data sets without deleting and redefining them. If you do not specify REUSE, Db2 deletes and redefines Db2-managed data sets to reset them.

If you are rebuilding the index because of a media failure, do not specify REUSE.

If a data set has multiple extents, the extents are not released if you use the REUSE parameter.

SORTDEVT device-type
Specifies the device type for temporary data sets that are to be dynamically allocated by the sort program. For device-type, you can specify any disk device that is valid on the DYNALLOC parameter of the SORT or OPTION options for the sort program. Tape devices are not supported by the sort program.

device-type is the device type.

A TEMPLATE specification does not dynamically allocate sort work data sets. The SORTDEVT keyword controls dynamic allocation of these data sets.

SORTNUM integer
Specifies the number of temporary data sets that are to be dynamically allocated by the sort program. If you omit SORTDEVT, SORTNUM is ignored. If you use SORTDEVT and omit SORTNUM, no value is passed to the sort program; the sort program uses its own default.

integer is the number of temporary data sets that can range from 2 to 255.

You need at least two sort work data sets for each sort. The SORTNUM value applies to each sort invocation in the utility. For example, if there are three indexes, SORTKEYS is specified, there are no constraints limiting parallelism, and SORTNUM is specified as 8, then a total of 24 sort work data sets will be allocated for a job.

Each sort work data set consumes both above the line and below the line virtual storage, so if you specify too high a value for SORTNUM, the utility may decrease the degree of parallelism due to virtual storage constraints, and possibly decreasing the degree down to one, meaning no parallelism.

Important: Start of changeThe SORTNUM keyword is ignored if the IGNSORTN subsystem parameter is set to YES.End of change
STATISTICS
Specifies that index statistics are to be collected.

If you specify the STATISTICS and UPDATE options, statistics are stored in the Db2 catalog. You cannot collect inline statistics for indexes on the catalog and directory tables.

Restriction:
  • If you specify STATISTICS for encrypted data, Db2 might not provide useful statistics on this data.
  • You cannot specify STATISTICS for a clone index.
REPORT
Indicates whether a set of messages to report the collected statistics is to be generated.
NO
Indicates that the set of messages is not to be sent as output to SYSPRINT.
YES
Indicates that the set of messages is to be sent as output to SYSPRINT. The generated messages are dependent on the combination of keywords (such as TABLESPACE, INDEX, TABLE, and COLUMN) that you specify with the RUNSTATS utility. However, these messages are not dependent on the specification of the UPDATE option. REPORT YES always generates a report of SPACE and ACCESSPATH statistics.
KEYCARD
The KEYCARD option is deprecated in the utility control statement and no longer needs to be specified to collect cardinality statistics on the values in the key columns of an index.

When the STATISTICS option is specified, the utility automatically collects all of the distinct values in all of the 1 to n key column combinations for the indexes being rebuilt.n is the number of columns in the index. With the deprecation of KEYCARD, this functionality cannot be disabled.

The utility tolerates the specification of the KEYCARD option. The utility does not issue any messages if the control statement includes or excludes the KEYCARD option when STATISTICS is specified.

FREQVAL
Controls the collection of frequent-value statistics. If you specify FREQVAL, it must be followed by the NUMCOLS keyword.
NUMCOLS
Indicates the number of key columns that are to be concatenated when collecting frequent values from the specified index. If you specify 3, the utility collects frequent values on the concatenation of the first three key columns.

The default value is 1, which means that Db2 is to collect frequent values only on the first key column of the index.

COUNT
Indicates the number of frequent values that are to be collected. If you specify 15, the utility collects 15 frequent values from the specified key columns.

Start of changeWhen the COUNT keyword is not specified, the utility automatically determines the count value and collects the most frequently occurring values.End of change

Start of changeMOSTEnd of change
Start of changeIndicates that the utility is to collect the most frequently occurring values for the specified set of columns when COLGROUP is specified.End of change
Start of changeBOTHEnd of change
Start of changeIndicates that the utility is to collect the most and the least frequently occurring values for the specified set of columns when COLGROUP is specified.End of change
Start of changeLEASTEnd of change
Start of changeIndicates that the utility is to collect the least frequently occurring values for the specified set of columns when COLGROUP is specified.End of change
HISTOGRAM
Indicates that histogram statistics are requested for the specified index.
NUMCOLS
The number of key columns that are to be concatenated when collecting histogram statistics from the specified index.
NUMQUANTILES
The integer values that follows NUMQUANTILES indicates the number quantiles are requested. The integer value must be greater than or equal to 1.

Histogram statistics can be collected only on keys with the same order. If the specified key columns for histogram statistics are of mixed or random order, a DSNU633I warning message is issued.

Histogram statistics that you collect through REBUILD INDEX are not the same as histogram statistics that you collect through RUNSTATS. Histogram statistics that you collect with REBUILD INDEX are only rough estimates. To obtain more exact statistics, use RUNSTATS.

Related information:
UPDATE
Indicates whether the collected statistics are to be inserted into the catalog tables. UPDATE also allows you to select statistics that are used for access path selection or statistics that are used by database administrators.
ALL
Indicates that all collected statistics are to be updated in the catalog.
ACCESSPATH
Indicates that the only catalog table columns that are to be updated are those that provide statistics that are used for access path selection.
SPACE
Indicates that the only catalog table columns that are to be updated are those that provide statistics to help the database administrator assess the status of a particular table space or index.
NONE
Indicates that catalog tables are not to be updated with the collected statistics. This option is valid only when REPORT YES is specified.
Start of changeINVALIDATECACHEEnd of change
Start of changeIndicates whether statements in the dynamic statement cache are invalidated as a result of the inline statistics collection. This option does not prevent the utility from invalidating cached statements for other reasons.
YES
Statements in the dynamic cache are invalidated for the objects that are specified in the job statement.
NO
Statements in the dynamic cache are not invalidated by the collection of inline statistics for the objects that are specified in the job statement. However, cached statements might be invalidated by the utility for reasons other than the inline statistics, such as when the utility resolves objects in restricted states or applies pending ALTER operations.
End of change
HISTORY
Records all catalog table inserts or updates to the catalog history tables.

The default is supplied by the value that is specified in STATISTICS HISTORY on panel DSNTIP6.

ALL
Indicates that all collected statistics are to be updated in the catalog history tables.
ACCESSPATH
Indicates that the only catalog history table columns that are to be updated are those that provide statistics that are used for access path selection.
SPACE
Indicates that only space-related catalog statistics are to be updated in catalog history tables.
NONE
Indicates that catalog history tables are not to be updated with the collected statistics.
FORCEROLLUP
Specifies whether aggregation or rollup of statistics is to take place when you execute RUNSTATS even if some indexes or index partitions are empty. This keyword enables the optimizer to select the best access path.

The following options are available for the FORCEROLLUP keyword:

YES
Indicates that forced aggregation or rollup processing is to be done, even though some indexes or index partitions might not contain data.
NO
Indicates that aggregation or rollup is to be done only if data is available for all indexes or index partitions.

If data is not available, the utility issues DSNU623I message if you have set the installation value for STATISTICS ROLLUP on panel DSNTIP6 to NO.

FLASHCOPY
Specifies whether FlashCopy® technology is used to create a copy of the object. Valid values are YES, NO, or CONSISTENT. When FlashCopy is used, a separate data set is created for each partition or piece of the object.

The FlashCopy specifications on the utility control statement override any specifications for FlashCopy that are defined by using the Db2 subsystem parameters. If the FlashCopy subsystem parameters specify the use of FlashCopy as the default behavior of this utility, the FLASHCOPY option can be omitted from the utility control statement.

Important: If the input data set is less than one cylinder, FlashCopy technology might not be used for copying the objects regardless of the FLASHCOPY settings. The copy is performed by IDCAMS if FlashCopy is not used.
NO
Specifies that no FlashCopy is made. NO is the default value for FLASHCOPY.
YES
Specifies that FlashCopy technology is used to copy the object.

Specify YES only if the Db2 data sets are on FlashCopy Version 2 disk volumes.

Important: Under the following circumstances, the REBUILD INDEX utility might not use FlashCopy even though YES is specified:
  • FlashCopy Version 2 disk volumes are not available
  • The source tracks are already the target of a FlashCopy operation
  • The target tracks are the source of a FlashCopy operation
  • The maximum number of relationships for the copy is exceeded
In the event that FlashCopy is not used, the REBUILD INDEX utility uses traditional I/O methods to copy the object, which can result in longer than expected execution time.
CONSISTENT
Specifies that FlashCopy technology is used to copy the object. Because the copies created by the REBUILD INDEX utility are already consistent, the utility treats a specification of CONSISTENT the same as a specification of YES.
PARALLEL num-subtasks
Specifies the maximum number of subtasks that are to be started in parallel to rebuild indexes. If the PARALLEL keyword is omitted, the maximum number of subtasks is limited by either the number of partitions being unloaded or the number of indexes built.

REBUILD INDEX typically allocates subtasks in groups of two or three, so the actual number of subtasks that are started might be less than the number specified on PARALLEL.

The specified number of subtasks for PARALLEL always overrides the specification of the PARAMDEG_UTIL subsystem parameter, so PARALLEL can be smaller or larger than the value of PARAMDEG_UTIL.

num-subtasks
Specifies the maximum number of subtasks and must be an integer between 0 and 32767, inclusive. If the specified value for num-subtasks is greater than 32767, the REBUILD INDEX statement fails. If 0 or no value is specified for num-subtasks, the REBUILD INDEX utility uses the optimal number of parallel subtasks. If the specified value for num-subtasks is greater than the calculated optimal number, the REBUILD INDEX utility limits the number of parallel subtasks to the optimal number with applied constraints.
Start of change RBALRSN_CONVERSION End of change
Start of changeSpecifies the RBA or LRSN format of the target object after the completion of the REBUILD INDEX utility.
Important: RBALRSN_CONVERSION is deprecated, meaning that its use is discouraged. Although this keyword remains supported, support is likely to be removed eventually. The utility fails if BASIC is specified, or if NONE is specified for an object in the 6-byte format.
EXTENDED
Specifies that if an object is found in basic 6-byte format, it is converted to 10-byte extended format.

EXTENDED is the default value.

NONE
Specifies that no conversion is performed.

The utility fails if RBALRSN_CONVERSION NONE is specified on a table space that is in basic 6-byte format.

If a CLONE relationship exists, the page set conversion cannot be performed. For clone relationships, you must drop the clone table, convert the base table to extended 10-byte format, and then re-create the clone table.

REBUILD of a node ID index, when converting the page format to extended, does not convert versioned XML table spaces that are associated with that base table space.

Specify RBALRSN_CONVERSION NONE during Disaster Recovery scenarios to avoid page set format conversions, which would complicate the recovery, especially when you rebuild indexes over the catalog and directory table spaces.

End of change
FCCOPYDDN
Specifies the template to be used to create the FlashCopy image copy data set names. If a value is not specified for FCCOPYDDN on the REBUILD INDEX control statement when FlashCopy is used, the value specified on the FCCOPYDDN subsystem parameter determines the template to be used.
(template-name)
The data set names for the FlashCopy image copy are allocated according to the template specification. For table space or index space level FlashCopy image copies, because a data set is allocated for each partition or piece, ensure that the data set naming convention in the template specification is unique enough. Use the &DSNUM variable, which resolves to a partition number or piece number at execution time.