The query was slow, and the log showed why: a missing index and a table scan on millions of rows. The fix needed more than tuning — it needed a new column.
Adding a new column is one of the most common schema changes in a database. Done right, it can unlock speed, simplify queries, or provide the foundation for features that are impossible without it. Done wrong, it can cause downtime, data loss, or silent failure.
The first step is choosing the correct data type. Pick the smallest type that fits your data to save space and improve cache performance. For example, use INT over BIGINT if your range allows. Define constraints at creation time to enforce data quality early.
When modifying production tables, plan for lock behavior. In many relational databases, adding a new column with a default non-null value rewrites the entire table. On large datasets, this can lock writes for minutes or hours. If you must backfill data, do it in small batches and commit often to avoid blocking traffic.