The query ran fast, but the table was static. You needed a new column.
Adding a new column can be trivial or it can break production. The difference is in the approach. Whether you use MySQL, PostgreSQL, or a modern NoSQL engine, schema changes demand precision. The wrong migration locks the table and stalls writes. The right migration rolls out without a blip.
First, define the column’s purpose. Set the correct data type—integer, text, timestamp, JSONB—before running any ALTER TABLE. Avoid NULL defaults unless intentional, and consider indexing only after data backfill to reduce load. For large datasets, run migrations in batches or in low-traffic windows.
In PostgreSQL, ALTER TABLE ... ADD COLUMN is fast for empty defaults but slow for computed or non-null defaults. In MySQL, the storage engine matters—InnoDB handles adding columns faster than MyISAM for most workloads. For distributed databases, check how replicas handle schema changes to prevent replication lag.