Outdated Version

You are viewing an older version of this section. View current production version.

CREATE INDEX

Create an index on the specified table.

Syntax

CREATE [UNIQUE] INDEX index_name [index_type] ON tbl_name (index_col_name,...) [index_option]

index_col_name:
    col_name [ASC | DESC]

index_type:
    USING { BTREE | HASH }

index_option:
  | index_type
  | COMMENT 'string'
  | UNENFORCED [RELY | NORELY]

Remarks

  • index_name is the name of the index you want to create.
  • tbl_name is the name of a table in a MemSQL database.
  • Columnstore indexes cannot be created using the CREATE INDEX statement. Columnstore indexes must be defined when the table is created using the CREATE TABLE statement (see CREATE TABLE).
  • This command must be run on the master aggregator node (see Node Requirements for MemSQL Commands).
  • This command will attempt to run as an online operation, but in certain cases cannot. See ALTER TABLE for more information. Operations which must be run offline cannot be run on distributed tables.
  • Every unique index must have all the columns of the shard key. Without it, the database cannot guarantee uniqueness across distributed database partitions.

Example

memsql> CREATE INDEX seq_index ON mytbl (seq);
Query OK, 0 rows affected (9.11 sec)
Records: 0  Duplicates: 0  Warnings: 0