The query ran in a second, but the table was wrong. A missing column had broken everything.
Adding a new column sounds simple. Yet in production systems, it can be one of the most disruptive schema changes you make. A single ALTER TABLE can lock writes, spike CPU, and trigger long replication delays. Knowing the right approach separates a clean migration from hours of downtime.
When you add a new column, the first question is: do you need to backfill data immediately? If the column is nullable and defaults are acceptable, create it without backfill to avoid table-wide rewrites. Use a non-blocking migration tool like gh-ost or pt-online-schema-change for large datasets. For smaller tables, a direct ALTER may be safe if you can tolerate short locks.
In PostgreSQL, adding a column with a constant default before version 11 rewrites the whole table. After 11, it’s fast. In MySQL, adding a nullable column without a default is nearly instant in recent versions. Always test on a clone of production with realistic data size.