The query was slow. The table was large. You needed a new column, and you needed it now.
Adding a new column to a database sounds simple, but the wrong move can lock tables, stall queries, and break production systems. You want speed, safety, and zero downtime. That means knowing exactly how your database handles schema changes in practice—not just in theory.
First, decide on the column type. A VARCHAR behaves differently from a TEXT or JSONB. Choose a type that matches your data while minimizing storage overhead. Default values can speed writes but also force a full table rewrite on most engines. If you must set a default, watch for the cost of backfilling millions of rows.
Second, use online schema changes if your database supports them. MySQL’s ALTER TABLE … ALGORITHM=INPLACE and PostgreSQL’s ALTER TABLE … ADD COLUMN without a default can avoid long locks. For massive tables, tools like pt-online-schema-change or gh-ost can migrate columns live.