The query ran fast, but the schema was already lagging. You needed a new column, and you needed it without breaking production.
Adding a new column is one of the most common schema changes in modern applications. It sounds small, but in high-load systems it can lock tables, spike CPU, and cause downtime if done wrong. The challenge is to design, deploy, and backfill without blocking reads and writes.
First, decide the column’s purpose and data type with precision. A vague requirement leads to migrations you will regret. Keep fields atomic. Choose types that match the smallest needed space. Avoid NULL if you can—define defaults to ensure faster queries.
Second, plan the database migration to be online. For relational databases like PostgreSQL or MySQL, use tools that perform non-blocking schema changes. In PostgreSQL, ALTER TABLE ADD COLUMN with a default and NOT NULL will rewrite data; consider adding the column as nullable first, then updating values in controlled batches.