In my experienceALTER TABLE
is one of the more
maligned and misunderstood features of MySQL. It has a lot of
potential to cause unexpected problems if you don't understand
it. Here are a few common gotchas when using ALTER
TABLE
to modify a column attribute:
1) Alter Table is slow
For those of us who spend a lot of time working with MySQL this is expected behavior. Nonetheless, many people are still surprised when they're doing something simple like disallowing NULL values in a column, and it takes hours to run on a table with several GB of data. The reason for this is that most column changes affect the row format, and that requires rebuilding all of the rows for the entire table.
Here are some recommendations to mitigate this issue:
- Use master-master active/passive replication so you can always execute DDL on a passive DB
- Use …