Indexes

This section describes the DDL commands pertaining to indexes.

Create index

Define an new index for a given object type or link.

  1. create index on ( index-expr )
  2. [ except ( except-expr ) ]
  3. [ "{" subcommand; [...] "}" ] ;
  4. where subcommand is one of
  5. create annotation annotation-name := value

Description

The command create index constructs a new index for a given object type or link using index-expr.

Parameters

Most sub-commands and options of this command are identical to the SDL index declaration. There’s only one subcommand that is allowed in the create index block:

create annotation annotation-name := value

Set object type annotation-name to value.

See create annotation for details.

Example

Create an object type User with an indexed name property:

  1. create type User {
  2. create property name -> str {
  3. set default := '';
  4. };
  5. create index on (.name);
  6. };

Alter index

Alter the definition of an index.

  1. alter index on ( index-expr ) [ except ( except-expr ) ]
  2. [ "{" subcommand; [...] "}" ] ;
  3. where subcommand is one of
  4. create annotation annotation-name := value
  5. alter annotation annotation-name := value
  6. drop annotation annotation-name

Description

The command alter index is used to change the annotations of an index. The index-expr is used to identify the index to be altered.

Parameters

on ( index-expr )

The specific expression for which the index is made. Note also that <index-expr> itself has to be parenthesized.

The following subcommands are allowed in the alter index block:

create annotation annotation-name := value

Set index annotation-name to value. See create annotation for details.

alter annotation annotation-name;

Alter index annotation-name. See alter annotation for details.

drop annotation annotation-name;

Remove constraint annotation-name. See drop annotation for details.

Example

Add an annotation to the index on the name property of object type User:

  1. alter type User {
  2. alter index on (.name) {
  3. create annotation title := "User name index";
  4. };
  5. };

Drop index

Remove an index from a given schema item.

  1. drop index on ( index-expr ) [ except ( except-expr ) ];

Description

The command drop index removes an index from a schema item.

on ( index-expr )

The specific expression for which the index was made.

This statement can only be used as a subdefinition in another DDL statement.

Example

Drop the name index from the User object type:

  1. alter type User {
  2. drop index on (.name);
  3. };

See also

Schema > Indexes

SDL > Indexes

Introspection > Indexes