MySQL & InnoDB (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
Online DDL in MySQL 8.0: `ALGORITHM=INPLACE` vs `ALGORITHM=COPY`.
senior LevelCode ExampleDatabases & SQLMySQL
In Simple Words:
When running schema migrations (ALTER TABLE):
ALGORITHM=COPY: Creates a temporary table copy, copies all rows, locks writes, and swaps tables. High disk usage and long write locks.ALGORITHM=INPLACE: Modifies the table directly without rebuilding the entire file or blocking concurrentDML(SELECT,INSERT,UPDATE), enabling zero-downtime index creation and column additions.
sql
-- Online non-blocking index creation
ALTER TABLE users ADD INDEX idx_status (status), ALGORITHM=INPLACE, LOCK=NONE;