The data was growing fast, and a new column was the only fix that made sense.
Adding a new column sounds simple. It isn’t always. In small datasets, altering a table is instant. In production systems with millions of rows, it can block queries, spike CPU usage, and lock writes.
Before you create a new column in SQL, you need three decisions:
- Data type — Choose the smallest type that works. Smaller types mean less storage and faster reads.
- Default values — Setting a default on creation can avoid null issues, but large defaults can slow migrations.
- NULL vs NOT NULL — Adding a NOT NULL column without a default may fail if existing rows have no value.
In PostgreSQL, ALTER TABLE ADD COLUMN is straightforward, but the execution plan changes once constraints or indexes are added during the same migration. In MySQL, adding columns to large InnoDB tables can cause long locks unless you use ALGORITHM=INPLACE or ALGORITHM=INSTANT (available in newer versions).