SHOW INDEX

The SHOW INDEX statement returns index information for a table.

Required privileges

The user must have any privilege on the target table.

Aliases

In CockroachDB, the following are aliases for SHOW INDEX:

  • SHOW INDEXES
  • SHOW KEYS

Synopsis

SHOWINDEXINDEXESKEYSFROMtable_name

Parameters

ParameterDescription
table_nameThe name of the table for which you want to show indexes.

Response

The following fields are returned for each column in each index.

FieldDescription
table_nameThe name of the table.
index_nameThe name of the index.
non_uniqueWhether or not values in the indexed column are unique. Possible values: true or false.
seq_in_indexThe position of the column in the index, starting with 1.
column_nameThe indexed column.
directionHow the column is sorted in the index. Possible values: ASC or DESC for indexed columns; N/A for stored columns.
storingWhether or not the STORING clause was used to index the column during index creation. Possible values: true or false.
implicitWhether or not the column is part of the index despite not being explicitly included during index creation. Possible values: true or falseAt this time, primary key columns are the only columns that get implicitly included in secondary indexes. The inclusion of primary key columns improves performance when retrieving columns not in the index.

Example

  1. > CREATE TABLE t1 (
  2. a INT PRIMARY KEY,
  3. b DECIMAL,
  4. c TIMESTAMP,
  5. d STRING
  6. );
  1. > CREATE INDEX b_c_idx ON t1 (b, c) STORING (d);
  1. > SHOW INDEX FROM t1;
  1. +------------+------------+------------+--------------+-------------+-----------+---------+----------+
  2. | table_name | index_name | non_unique | seq_in_index | column_name | direction | storing | implicit |
  3. +------------+------------+------------+--------------+-------------+-----------+---------+----------+
  4. | t1 | primary | false | 1 | a | ASC | false | false |
  5. | t1 | b_c_idx | true | 1 | b | ASC | false | false |
  6. | t1 | b_c_idx | true | 2 | c | ASC | false | false |
  7. | t1 | b_c_idx | true | 3 | d | N/A | true | false |
  8. | t1 | b_c_idx | true | 4 | a | ASC | false | true |
  9. +------------+------------+------------+--------------+-------------+-----------+---------+----------+
  10. (5 rows)

See also

Was this page helpful?
YesNo