New column operations can look simple, but they hide real costs. In SQL, ALTER TABLE ... ADD COLUMN rewrites metadata. In some databases, it locks the table. In others, it triggers a full table copy. On high-traffic systems, that’s downtime you cannot afford.
Choosing the right path is critical.
- PostgreSQL can add a new column with a default
NULLalmost instantly. But if you set aDEFAULTwith a non-null value, it rewrites every row. - MySQL may copy the entire table on an
ALTER TABLEdepending on engine and configuration. For InnoDB,ALGORITHM=INPLACEcan avoid a full copy in supported cases. - SQLite supports only appending a new column at the end, with no complex constraints.
Plan for schema migrations that minimize locks and replication lag. On large datasets, create the new column with a safe default, backfill in batches, then alter constraints. Tools like pt-online-schema-change or logical replication pipelines keep reads and writes flowing.