Rebuild Indexes (Data Management)

Summary

Rebuild existing attribute or spatial indexes in enterprise 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 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(input_database, include_system, {in_datasets}, {delta_only})
ParameterExplanationData Type
input_database

The connection (.sde file) to the enterprise 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.

Note:

You must connect as the geodatabase administrator in the connection file you specified for the input_database for this option to be executed successfully.

This option only applies to geodatabases. This option is ignored if you connect to a database.

  • NO_SYSTEM Indexes will not be rebuilt on the states and state lineages table. This is the default.
  • SYSTEM 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.

  • ALLIndexes will be rebuilt on all indexes for the selected datasets. This includes spatial indexes as well as user-created attribute indexes and any geodatabase-maintained indexes for the dataset.
  • ONLY_DELTASIndexes will only be rebuilt for the delta tables of the selected datasets. This option can be used for cases where the business tables for the selected datasets are not updated often and there is a high volume of edits in the delta tables. This is the default.
Boolean

Derived Output

NameExplanationData Type
out_workspace

The updated 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

  • Basic: No
  • Standard: Yes
  • Advanced: Yes

Related topics