Search
ctrl/
Ask AI
Light
Dark
System

Indexes

This section describes the DDL commands pertaining to indexes.

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

create index on ( index-expr )
[ except ( except-expr ) ]
[ "{" subcommand; [...] "}" ] ;

where subcommand is one of

  create annotation annotation-name := value

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

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.

Create an object type User with an indexed name property:

Copy
create type User {
    create property name -> str {
        set default := '';
    };

    create index on (.name);
};

Alter the definition of an index.

alter index on ( index-expr ) [ except ( except-expr ) ]
[ "{" subcommand; [...] "}" ] ;

where subcommand is one of

  create annotation annotation-name := value
  alter annotation annotation-name := value
  drop annotation annotation-name

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.

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.

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

Copy
alter type User {
    alter index on (.name) {
        create annotation title := "User name index";
    };
};

Remove an index from a given schema item.

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

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.

Drop the name index from the User object type:

Copy
alter type User {
    drop index on (.name);
};