The query returned fast, but the data wasn’t enough. The table needed a new column.
Adding a new column sounds simple. In production, it is not. Schema changes can lock tables, cause downtime, or corrupt data if handled carelessly. The key is to plan the migration so it runs safely at scale.
First, decide the type and constraints for the new column. Choose defaults that won’t force a full table rewrite unless necessary. For large datasets, avoid adding non-nullable columns with no default value. This can trigger immediate data backfill, spiking CPU and I/O.
Second, choose the right migration strategy. Use tools like ALTER TABLE with caution. Online schema change utilities such as gh-ost or pt-online-schema-change can help add a new column without downtime. These tools build a shadow table, copy data in batches, and then swap it in.