Why we cannot perform a ALTER TABLE directly to update schema?
How MySQL performs ALTER TABLE:
Lock the table
Make a copy of the table
Modify the copy (the "New Table")
Copy all the rows into the new table
Swap the old and new table
Unlock the table
The key issue here was that lock time would be quite long for large table, whick blocks online transaction.
Percona ' s Solution:
Make a copy of the table
Modify the copy (the "New Table")
Copy all the rows into the new table (does in small chunks, insert: Select)
ADD triggers to keep track of changes
Swap the old and new table
Pros:
Remove the Lock/unlock steps, no longer blocking
Replication-awareness
Load awareness-Chunk size is auto adjusted
Cons:
About 4th slower than ALTER TABLE directly
Limitation:
Cannot handle foreign key perfectly
Xtrabackup
This article from "Shadowisper" blog, declined reprint!
Mysql Zero Downtime Deployment