The query was slow, and everyone knew why. The table needed a new column.
Adding a new column sounds simple. In practice, the wrong approach can bring production to a crawl. Schema changes in live databases can lock rows, block writes, or cause downtime that costs real money. The key is to choose a method that fits the database engine, the size of the dataset, and the access patterns of the application.
In PostgreSQL, ALTER TABLE ADD COLUMN is fast if the column has no default that requires rewriting every row. Use DEFAULT with caution. For large tables, avoid backfilling in the same statement. Instead, add the new column as nullable, then backfill in controlled batches. MySQL behaves differently. Adding a column may trigger a table rebuild unless the storage engine supports instant DDL for that operation. Evaluate your version and configuration before running it on production.