Summary
Rebuild existing attribute or spatial indexes in databases and enterprise, workgroup, and desktop geodatabases. Indexes can also be rebuilt on states and state_lineage geodatabase system tables and the delta tables of versioned datasets. Out-of-date indexes can lead to poor query performance.
Usage
- Data must be from a database or an enterprise, workgroup, or desktop 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.
- This tool rebuilds the attribute and spatial indexes of base tables, delta tables, and archive tables in versioned and archive-enabled geodatabases.
- The Include System Tables parameter determines if indexes are rebuilt on the states and state lineages tables in the specified geodatabase. When the option is unselected, the indexes on these tables are not rebuilt. If the Include System Tables parameter is unchecked, at least one dataset needs to be selected in the Datasets to Rebuild Indexes For to run the tool.
- 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.
- This tool is not supported with SAP HANA.
Syntax
RebuildIndexes_management (input_database, include_system, {in_datasets}, {delta_only})
Parameter | Explanation | Data Type |
input_database | The connection (.sde file) to the database or geodatabase that contains the data for which you want to rebuild indexes. | Workspace |
include_system | Indicates whether indexes will be rebuilt on the states and state lineages tables.
| Boolean |
in_datasets [in_datasets,...] (Optional) | Names of the datasets that will have their indexes rebuilt. Dataset names use paths relative to the input_database; full paths are not accepted as input. | String |
delta_only (Optional) | Indicates how the indexes will be rebuilt on the selected datasets. This option has no effect if in_datasets is empty. This option only applies to geodatabases. If the input workspace is a database, this option will be ignored.
| Boolean |
Derived Output
Name | Explanation | Data Type |
out_workspace | Workspace |
Code sample
RebuildIndexes example 1 (Python window)
The following example demonstrates how to rebuild indexes using the Python window.
# Import system modules
import arcpy
arcpy.RebuildIndexes_management("c:/Connections/GDB@DC@server.sde", "NO_SYSTEM","db1.GDB.Roads;db1.GDB.Parcels", "ALL")
RebuildIndexes example 2 (stand-alone script)
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')
Environments
Licensing information
- ArcGIS Desktop Basic: No
- ArcGIS Desktop Standard: Yes
- ArcGIS Desktop Advanced: Yes