INDEX
Warning
Supported only for row-oriented tables. Support for column-oriented tables is currently under development.
The INDEX construct is used to define a secondary index in a row-oriented table:
CREATE TABLE table_name (
...
INDEX <index_name> GLOBAL [UNIQUE] [SYNC|ASYNC] ON ( <index_columns> ) COVER ( <cover_columns> ),
...
)
Where:
- Index_name is the unique name of the index to be used to access data.
- SYNC/ASYNC indicates synchronous/asynchronous data writes to the index. If not specified, synchronous.
- UNIQUE indicates that the index should guarantee the uniqueness of the indexed column set, thereby enforcing the unique constraint.
- Index_columns is a list of comma-separated names of columns in the created table to be used for a search in the index.
- Cover_columns is a list of comma-separated names of columns in the created table, which will be stored in the index in addition to the search columns, making it possible to fetch additional data without accessing the table for it.
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),
INDEX idx_bc GLOBAL UNIQUE SYNC ON (b, c),
PRIMARY KEY (a)
)