CREATE INDEX#

The CREATE INDEX statement is used to create a new index on existing table. If there is data in the table, data will be loaded asynchronously. The job status can be checked through the showopstatus command of ns_client, see Operations in CLI.

Syntax#

CreateIndexstmt ::=
    'CREATE' 'INDEX' IndexName ON TableName IndexColumn OptOptionsList

IndexName ::= Identifier

TableName ::=
    Identifier ('.' Identifier)?


IndexColumn ::=
    IndexColumnPrefix ")"

IndexColumnPrefix ::=
    "(" ColumnExpression
    | IndexColumnPrefix "," ColumnExpression

ColumnExpression ::=
    Identifier
     
OptOptionsList ::=
    "OPTIONS" OptionList

OptionList ::=
    OptionsListPrefix ")"

OptionsListPrefix ::=
    "(" OptionEntry
    | OptionsListPrefix "," OptionEntry

OptionEntry ::=
    Identifier "=" Identifier

Example#

CREATE INDEX index2 ON t5 (col2);
-- SUCCEED

Note

If OPTIONS is not provided, the SQL with the created index cannot be deployed online, since the index doesn’t have TS (timestamp).

We can also set TS column as below:

CREATE INDEX index3 ON t5 (col3) OPTIONS (ts=ts1, ttl_type=absolute, ttl=30d);
-- SUCCEED

Please refer here for more details about TTL and TTL_TYPE.