The query returned fast. The table was huge. But something was missing — a new column that could change everything.
Adding a new column sounds simple. In practice, the wrong approach can lock migrations, slow production, or corrupt data. The right method depends on your database engine, table size, and traffic patterns.
In Postgres, ALTER TABLE ADD COLUMN is straightforward for small tables, but large ones require care. Adding a column with a default value rewrites the entire table, causing locks. Instead, add it without a default, then backfill in batches, then set the default.
In MySQL, ALTER TABLE often copies the table under the hood, which can block writes. Use tools like pt-online-schema-change or gh-ost to add the column online. For high-availability systems, test these in staging with production-like data before running in prod.