Adding a new column should be fast, safe, and predictable. Yet in production systems with live traffic, schema changes can lock tables, spike latency, or cause downtime. At scale, a single blocking migration can stall the entire pipeline.
A new column in SQL seems simple. In reality, the operation depends on database engine, table size, and schema design. In MySQL or Postgres, ALTER TABLE ADD COLUMN can be instant for small tables but may rewrite large ones in full. For column stores, adding metadata might be near-instant, but backfilling values can be costly.
Best practice starts with understanding how your database handles new column operations:
- Nullable without default: Often fastest, as the database updates metadata only.
- With default value: May require a full table rewrite if the database must populate existing rows.
- NOT NULL with default: Triggers a rewrite; on large datasets, this can take minutes or hours.
- Computed or generated columns: CPU-bound processing, plus possible index changes.
In production, apply these patterns to minimize risk: