Use SHOW INDEX to list all indexes on a table in PolarDB-X, including local secondary indexes (LSIs) and global secondary indexes (GSIs).
Syntax
SHOW {INDEX | INDEXES | KEYS}
{FROM | IN} tbl_name
[{FROM | IN} db_name]
[WHERE expr]The keywords INDEX, INDEXES, and KEYS are interchangeable. Use FROM or IN to specify the table, and optionally the database. Add a WHERE clause to filter results by column value.
Example
SHOW INDEX FROM t_order;Output:
+---------+------------+-----------+--------------+----------------+-----------+-------------+----------+--------+------+------------+----------+---------------+
| TABLE | NON_UNIQUE | KEY_NAME | SEQ_IN_INDEX | COLUMN_NAME | COLLATION | CARDINALITY | SUB_PART | PACKED | NULL | INDEX_TYPE | COMMENT | INDEX_COMMENT |
+---------+------------+-----------+--------------+----------------+-----------+-------------+----------+--------+------+------------+----------+---------------+
| t_order | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | | |
| t_order | 1 | l_i_order | 1 | order_id | A | 0 | NULL | NULL | YES | BTREE | | |
| t_order | 0 | g_i_buyer | 1 | buyer_id | NULL | 0 | NULL | NULL | YES | GLOBAL | INDEX | |
| t_order | 1 | g_i_buyer | 2 | id | NULL | 0 | NULL | NULL | | GLOBAL | COVERING | |
| t_order | 1 | g_i_buyer | 3 | order_id | NULL | 0 | NULL | NULL | YES | GLOBAL | COVERING | |
| t_order | 1 | g_i_buyer | 4 | order_snapshot | NULL | 0 | NULL | NULL | YES | GLOBAL | COVERING | |
+---------+------------+-----------+--------------+----------------+-----------+-------------+----------+--------+------+------------+----------+---------------+
6 rows in set (0.01 sec)The output shows three indexes on t_order: the PRIMARY key, a local secondary index l_i_order, and a global secondary index g_i_buyer. The GSI g_i_buyer spans four rows — one for its index key column (buyer_id, marked INDEX) and three for its covering columns (id, order_id, order_snapshot, each marked COVERING).
Output columns
| Column | Description |
|---|---|
TABLE | The table name. |
NON_UNIQUE | Whether the index allows duplicate values. 0 means the index is unique; 1 means it is not unique. |
KEY_NAME | The index name. |
SEQ_IN_INDEX | The position of the column within the index, starting from 1. |
COLUMN_NAME | The column included in the index. |
COLLATION | The sort order for the column in the index. A = ascending, D = descending, NULL = unsorted. |
CARDINALITY | The estimated number of unique values in the index. |
SUB_PART | The index prefix length in characters. NULL means the entire column is indexed rather than a prefix. |
PACKED | Whether the key is packed (compressed). NULL means no compression is applied. |
NULL | Whether the column allows NULL values. YES means NULL is allowed; blank means it is not. |
INDEX_TYPE | The index implementation. BTREE or HASH for local indexes; GLOBAL for global secondary indexes. NULL means the type is unspecified. |
COMMENT | The role of the column in a global secondary index. Blank indicates a local secondary index. For GSIs, INDEX marks an index key column and COVERING marks a covering column. |
INDEX_COMMENT | Additional comments about the index, specified when the index was created. |
TheCOMMENTcolumn is PolarDB-X-specific. Standard MySQL always returns a blank value here. UseCOMMENTto distinguish LSIs from GSIs and to identify which columns are index key columns versus covering columns within a GSI.