Rebuild Indexes (Data Management)

License Level:BasicStandardAdvanced

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

Syntax

RebuildIndexes_management (input_database, include_system, {in_datasets}, {delta_only})
ParameterExplanationData 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.

NoteNote:

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.

  • 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 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.

  • 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 are a high volume of edits in the delta tables. This is the default.
Boolean

Code Sample

RebuildIndexes example 1 (Python window)

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")
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

Related Topics

Licensing Information

ArcGIS for Desktop Basic: No
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
5/7/2015