The query had been running fine for months. Then the spec changed. You need a new column.
Adding a new column to a table feels simple, but in production, every change has weight. Schema changes can lock tables, block writes, or slow queries. On large datasets, an ALTER TABLE ADD COLUMN can take seconds or hours depending on the database engine, indexes, and constraints.
Before you add a new column, check the impact on application code, migrations, and data integrity. In PostgreSQL, adding a nullable column with no default is fast because it updates only the catalog. Adding a column with a non-null default rewrites the table and can be dangerous on high-traffic systems. In MySQL, the cost varies depending on storage engine and column type.
Plan the data type carefully. Pick the smallest type that fits your data to avoid bloating the table. Decide on NULL vs NOT NULL early. A column that starts nullable can be migrated to non-null after the required values are backfilled without locking the table for long. Use background jobs or batched updates to populate new columns without killing performance.