The query hit the database like a hammer, but the numbers didn’t line up. The fix was simple: add a new column. The execution was not.
A new column changes the shape of your data. It alters queries, indexes, constraints, and—if done poorly—it breaks production. In SQL, ALTER TABLE ADD COLUMN is the minimal statement. But scale changes the meaning. At a billion rows, adding a column can lock tables, consume resources, and stall deployments.
For PostgreSQL, use ALTER TABLE ... ADD COLUMN with a default value only when you can afford the write overhead. For MySQL, avoid NOT NULL with a default on massive datasets unless downtime is acceptable. In distributed systems like CockroachDB, a new column might trigger a schema change job that ripples through every node.
When adding a column, decide on its type and constraints before execution. Keep migrations idempotent. Use tools like pg_online_schema_change or gh-ost to roll out changes without halting queries. Always run a dry run on staging with production-like data volume. Measure latency before and after.