Rebuild Indexes (Data Management)
Summary
Updates indexes of datasets and system tables stored in an enterprise geodatabase. This tool is used in enterprise geodatabases to rebuild existing attribute or spatial indexes. Out-of-date indexes can lead to poor geodatabase performance.
Usage
- Data must be from an enterprise geodatabase. This tool does not work with file or personal geodatabases.
- After data loading, deleting, updating, and compressing operations, it is important to rebuild indexes in the database.
- When working with tables or datasets, this tool rebuilds the attribute and spatial indexes of base tables, delta tables, and archive tables.
- The Include System Tables parameter is used to determine if the states and state lineages tables will have their indexes rebuilt. When the option is unselected, the indexes on these tables are not rebuilt. If the Include System Tables parameter is unchecked, then at least one dataset needs to be selected in the Datasets to Rebuild Indexes For parameter in order for the tool to run.
- The Datasets to Rebuild Indexes For parameter's Add Value button is used only in ModelBuilder. In ModelBuilder, where the preceding tool has not been run, or its derived data does not exist, the Datasets to Rebuild Indexes For parameter may not be populated with values. The Add Value button allows you to add expected values so you can complete the dialog box and continue to build your model.
Syntax
Parameter | Explanation | Data Type |
input_database |
The enterprise database that contains the data to be updated. | Workspace |
include_system |
Indicates whether indexes will be rebuilt on the states and state lineages tables. Note: You must be the geodatabase administrator for this option to be executed successfully. This option only applies to geodatabases. If the input workspace is a database this option will be ignored.
| Boolean |
in_datasets [in_datasets,...] (Optional) | Names of the datasets that will have their indexes rebuilt. Dataset names use paths relative to the input workspace; full paths are not accepted as input. | Dataset |
delta_only (Optional) | Indicates how the indexes will be rebuilt on the selected datasets. This option has no effect if input_datasets is empty. This option only applies to geodatabases. If the input workspace is a database this option will be ignored.
| Boolean |
Code Sample
The following example demonstrates how to rebuild indexes using the Python window in ArcGIS.
# Import system modules
import arcpy
arcpy.RebuildIndexes_management("c:/Connections/GDB@DC@server.sde", "NO_SYSTEM","db1.GDB.Roads;db1.GDB.Parcels", "ALL")
The following example demonstrates how to rebuild indexes in a stand alone script.
# Name: RebuildIndexes.py
# Description: rebuilds indexes on delta tables for all datasets in an
# enterprise geodatabase
# Import system modules
import arcpy, os
# set workspace
workspace = arcpy.GetParameterAsText(0)
# set the workspace environment
arcpy.env.workspace = workspace
# NOTE: Rebuild indexes can accept a Python list of datasets.
# Get a list of all the datasets the user has access to.
# First, get all the stand alone tables, feature classes and rasters.
dataList = arcpy.ListTables() + arcpy.ListFeatureClasses() + arcpy.ListRasters()
# Next, for feature datasets get all of the datasets and featureclasses
# from the list and add them to the master list.
for dataset in arcpy.ListDatasets("", "Feature"):
arcpy.env.workspace = os.path.join(workspace,dataset)
dataList += arcpy.ListFeatureClasses() + arcpy.ListDatasets()
# reset the workspace
arcpy.env.workspace = workspace
# Get the user name for the workspace
userName = arcpy.Describe(workspace).connectionProperties.user.lower()
# remove any datasets that are not owned by the connected user.
userDataList = [ds for ds in dataList if ds.lower().find(".%s." % userName) > -1]
# Execute rebuild indexes
# Note: to use the "SYSTEM" option the workspace user must be an administrator.
arcpy.RebuildIndexes_management(workspace, "NO_SYSTEM", userDataList, "ALL")
print 'Rebuild Complete'