RENAME INDEX

The statement ALTER TABLE .. RENAME INDEX renames an existing index to a new name. This operation is instant in TiDB, and requires only a meta data change.

Synopsis

AlterTableStmt

RENAME INDEX - 图1

RenameIndexSpec

RENAME INDEX - 图2

  1. AlterTableStmt
  2. ::= 'ALTER' 'IGNORE'? 'TABLE' TableName RenameIndexSpec ( ',' RenameIndexSpec )*
  3. RenameIndexSpec
  4. ::= 'RENAME' ( 'KEY' | 'INDEX' ) Identifier 'TO' Identifier

Examples

  1. mysql> CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, c1 INT NOT NULL, INDEX col1 (c1));
  2. Query OK, 0 rows affected (0.11 sec)
  3. mysql> SHOW CREATE TABLE t1\G
  4. *************************** 1. row ***************************
  5. Table: t1
  6. Create Table: CREATE TABLE `t1` (
  7. `id` int(11) NOT NULL AUTO_INCREMENT,
  8. `c1` int(11) NOT NULL,
  9. PRIMARY KEY (`id`),
  10. KEY `col1` (`c1`)
  11. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
  12. 1 row in set (0.00 sec)
  13. mysql> ALTER TABLE t1 RENAME INDEX col1 TO c1;
  14. Query OK, 0 rows affected (0.09 sec)
  15. mysql> SHOW CREATE TABLE t1\G
  16. *************************** 1. row ***************************
  17. Table: t1
  18. Create Table: CREATE TABLE `t1` (
  19. `id` int(11) NOT NULL AUTO_INCREMENT,
  20. `c1` int(11) NOT NULL,
  21. PRIMARY KEY (`id`),
  22. KEY `c1` (`c1`)
  23. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
  24. 1 row in set (0.00 sec)

MySQL compatibility

The RENAME INDEX statement in TiDB is fully compatible with MySQL. If you find any compatibility differences, report a bug.

See also