patternsqlMinor
What's the complexity of renaming a column in MySql?
Viewed 0 times
thewhatcolumnmysqlrenamingcomplexity
Problem
We want to rename a column in our MySql (version 5.5) database with something like this:
Is this an O(N) (N=number of rows in the table) or an O(1) operation? I can't seem to find an answer in the manual nor on Google. The table has millions of records, and it wouldn't be feasible directly if it's O(N).
ALTER TABLE t1 CHANGE a b INTEGER;Is this an O(N) (N=number of rows in the table) or an O(1) operation? I can't seem to find an answer in the manual nor on Google. The table has millions of records, and it wouldn't be feasible directly if it's O(N).
Solution
It can be an O(1) operation if only the name is changing, see:
https://dev.mysql.com/doc/refman/8.0/en/alter-table.html
and search for:
Renaming, Redefining, and Reordering Columns
That is in a section that explains that the operation only modifies table metadata.
Back in MySQL 5.5 the manual says it works there too, except for InnoDB tables.
https://dev.mysql.com/doc/refman/8.0/en/alter-table.html
and search for:
Renaming, Redefining, and Reordering Columns
That is in a section that explains that the operation only modifies table metadata.
Back in MySQL 5.5 the manual says it works there too, except for InnoDB tables.
Context
StackExchange Database Administrators Q#61293, answer score: 6
Revisions (0)
No revisions yet.