Skip to main content

Syntax of Indexes in Class Definitions

Describes the structure of an index definition. See “Index Definitions” for links to general information on defining indexes.


An index is a structure maintained by a persistent class that is intended to be used to optimize queries and other functions. These indices are automatically maintained whenever INSERT, UPDATE, or DELETE SQL-based operations are carried out against the database; likewise for object-based actions. The SQL Query Processor makes use of available indices when preparing and executing SQL queries.

You can add index definitions to persistent classes. They are not meaningful in other kinds of classes.


An index definition has the following structure:

/// description 
Index name On property_expression_list [ keyword_list ];


  • description (optional) is intended for display in the Class Reference. The description is blank by default. See “Creating Class Documentation” in Defining and Using Classes.

  • name (required) is the name of the index. The name must follow property naming conventions and be unique within this class or table.

    This name is used for database administrative purposes (reporting, index building, dropping indices, and so on). For information on property naming conventions, see Class Members. For information on the relationship between an index name in a class definition and the corresponding SQL index name, see “CREATE INDEX” in the InterSystems SQL Reference.

  • property_expression_list (required) specifies the property or properties on which the index is based and may also include a collation specification for each property. This option is either a single property expression or a comma-separated list of property expressions, enclosed in parentheses.

    A given property expression consists of:

    • The name of the property to be indexed.

    • An optional (ELEMENTS) or (KEYS) expression, which provides a means of indexing on collection subvalues.

    • An optional collation expression.

    For more details, see “Define and Build Indexes” in Defining a High-Performance Schema.

  • keyword_list (optional) is a comma-separated list of keywords that further define the index.

    See “Index Syntax and Keywords” for a complete keyword list.

    If this list is omitted, also omit the square brackets.

For example, the following class definition defines two properties and an index based on each of them:

Class MyApp.Student Extends %Persistent 

Property Name As %String;

Property GPA As %Double;

Index NameIDX On Name;


See Also

FeedbackOpens in a new tab