The query ran fast, but the data lagged. You knew the problem sat in the schema. The fix was clear: a new column.
Adding a new column to a production database sounds simple. It is not. The way you create, populate, and index that column will decide if your system stays online or collapses under load. Whether you use PostgreSQL, MySQL, or a distributed store, schema changes demand precision.
First, define the column in a way that plays well with existing queries. Use a default value that avoids null pitfalls. In high-traffic systems, break large migrations into small, reversible steps. Add the new column with a non-blocking migration, then backfill data in batches to avoid locking tables.
Next, add indexes only after the data is in place. Building an index too soon can cause write bottlenecks. Use partial or functional indexes when they better match query patterns. Remember that every index carries a write cost.