The query returned fast. Too fast. The numbers looked clean, but the data was wrong. The missing piece was a new column.
Adding a new column should be simple. In practice, schema changes can break production if handled poorly. The first step is to define the column in the database schema. Use explicit types. Avoid NULL defaults unless necessary. If the column is indexed, create it in a way that minimizes lock time. On large tables, use online DDL or a background migration pattern.
After the schema update, ensure the application code can handle the new column. Set default values in code before the database. This reduces reliance on implicit database behaviors and prevents null-pointer issues. Release the code that reads the column first, then the code that writes to it. This two-step deployment avoids downtime.
When populating a new column with derived or migrated data, run backfills in small batches. Monitor query performance during the process. Large updates can cause contention. Tune batch sizes to match your database load capacity. Commit often to release locks quickly.