RENAME INDEX

The RENAME INDEX statement changes the name of an index for a table.

Note:
It is not possible to rename an index referenced by a view. For more details, see View Dependencies.

This schema change statement is registered as a job. You can view long-running jobs with SHOW JOBS.

Synopsis

ALTERINDEXIFEXISTStable_name@index_nameRENAMETOname

Required privileges

The user must have the CREATE privilege on the table.

Parameters

ParameterDescription
IF EXISTSRename the column only if a column of current_name exists; if one does not exist, do not return an error.
table_nameThe name of the table with the index you want to use
index_nameThe current name of the index
nameThe name you want to use for the index, which must be unique to its table and follow these identifier rules.

Example

Rename an Index

  1. > SHOW INDEXES FROM users;
  1. +------------+------------+------------+--------------+-------------+-----------+---------+----------+
  2. | table_name | index_name | non_unique | seq_in_index | column_name | direction | storing | implicit |
  3. +------------+------------+------------+--------------+-------------+-----------+---------+----------+
  4. | users | primary | false | 1 | id | ASC | false | false |
  5. | users | name_idx | true | 1 | name | ASC | false | false |
  6. | users | name_idx | true | 2 | id | ASC | false | true |
  7. +------------+------------+------------+--------------+-------------+-----------+---------+----------+
  8. (3 rows)
  1. > ALTER INDEX users@name_idx RENAME TO users_name_idx;
  1. > SHOW INDEXES FROM users;
  1. +------------+----------------+------------+--------------+-------------+-----------+---------+----------+
  2. | table_name | index_name | non_unique | seq_in_index | column_name | direction | storing | implicit |
  3. +------------+----------------+------------+--------------+-------------+-----------+---------+----------+
  4. | users | primary | false | 1 | id | ASC | false | false |
  5. | users | users_name_idx | true | 1 | name | ASC | false | false |
  6. | users | users_name_idx | true | 2 | id | ASC | false | true |
  7. +------------+----------------+------------+--------------+-------------+-----------+---------+----------+
  8. (3 rows)

See also

Was this page helpful?
YesNo