The query returned fast, but the table was dead. It needed a new column.
Adding a new column sounds simple. It isn’t—at least not when the table holds millions of rows or drives core application logic. Schema changes in production can lock tables, slow queries, or break downstream systems. Knowing the right approach is the difference between a clean deploy and a firefight at 2 a.m.
First, decide if the new column is nullable or has a default value. A NULL column is fast to add in most relational databases because the engine only changes metadata. Adding a non-nullable column with a default often rewrites the table. That can block reads and writes for minutes—or hours—depending on size.
In PostgreSQL, ALTER TABLE my_table ADD COLUMN new_column_name data_type; runs instantly if the column is nullable. For a non-nullable column, consider creating it as nullable, backfilling in small batches, then setting NOT NULL once every row has data.