Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does MariaDB support renaming an index?

Is there a syntax for renaming an index in MariaDB? I understand that MySQL 5.7 supports the syntax, but does MariaDB 10.0 (which includes MySQL 5.6) support it?

like image 273
mme Avatar asked Nov 05 '13 19:11

mme


2 Answers

They added the option on version 10.5.2, but I'm not sure it works because I have the vs 10.3 in my servers. https://mariadb.com/kb/en/alter-table/#rename-indexkey

I'll update it with more info.

like image 189
Sebastián Cabanas Avatar answered Oct 03 '22 13:10

Sebastián Cabanas


I just tried ALTER TABLE thing RENAME INDEX ix_old TO ix_new; in MariaDB 10.2.12 and it failed.

It also doesn't appear in the docs at https://mariadb.com/kb/en/library/alter-table/

And mysteriously an answer to this question displayed in duckduckgo doesn't exist! It said

No, there is no way to rename an index in current versions of MySQL (up to 5.6) or MariaDB (up to 10) or Percona Server (up to 5.6).

You can only drop an index and create a new index of a different name.

As a workaround, you could use pt-online-schema-change to add a new index with the new name and drop the old index by its old name, while allowing continuous read/write access to the original table.

$ pt-online-schema-change --alter "ADD KEY new_idx_name, DROP KEY old_idx_name" \ D=mydatabase,t=mytable

--Bill Karwin

But Bill Karwin's edit to the question remains. Hmmm, why would he have deleted it?

like image 28
Adam Avatar answered Oct 03 '22 12:10

Adam