INDEX

The INDEX construct is used to define a secondary index in a row-oriented table:

CREATE TABLE `<table_name>` (
  ...
    INDEX `<index_name>`
    [GLOBAL|LOCAL]
    [SYNC|ASYNC]
    [USING <index_type>]
    ON ( <index_columns> )
    [COVER ( <cover_columns> )]
    [WITH ( <parameter_name> = <parameter_value>[, ...])]
  [,   ...]
)

where:

  • GLOBAL/LOCAL — global or local index; depending on the index type (<index_type>), only one of them may be available:

    • GLOBAL — an index implemented as a separate table or set of tables. Synchronous updates to such an index require distributed transactions.
    • LOCAL — a local index within a shard of a row-oriented or column-oriented table. Does not require distributed transactions for updates, but does not provide pruning during search.
  • <index_name> — unique index name that will be used to access data.

  • SYNC/ASYNC — the index synchronization mode.

  • <index_type> — index type, currently supported:

    • secondary — secondary index. Only GLOBAL is available. This is the default value.
    • vector_kmeans_tree — vector index. Described in detail in Vector index.
  • <index_columns> — comma-separated list of column names for the table being created. This list defines the composition and order of columns included in the index key. Must be specified. The index key will include both the columns listed and the columns from the table's primary key.

  • <cover_columns> — comma-separated list of column names from the created table that will be saved in the index in addition to index key columns, providing the ability to get additional data without accessing the table. Empty by default.

  • <parameter_name> and <parameter_value> — index parameters specific to a particular <index_type>.

Warning

Supported only for row-oriented tables. Support for column-oriented tables is currently under development.

Example

CREATE TABLE my_table (
    a Uint64,
    b Bool,
    c Utf8,
    d Date,
    INDEX idx_d GLOBAL ON (d),
    INDEX idx_ba GLOBAL ASYNC ON (b, a) COVER (c),
    PRIMARY KEY (a)
)