Queries that once returned in milliseconds now dragged for seconds. The solution was clear: add a new column.
A new column in a database is not just a schema change. It’s a structural decision that affects storage, indexing, and future queries. Done right, it improves performance and unlocks new features. Done wrong, it bloats tables, slows writes, and causes painful migrations later.
Before adding a new column, define its purpose with precision. Is it storing derived data, user input, or a system state? Choose the smallest data type possible. Avoid NULLs unless they have a clear meaning. Consider defaults to avoid costly backfills on existing rows.
Alter statements on large tables can lock writes, trigger table rewrites, or block reads. Mitigate this with online schema change tools. In MySQL, use pt-online-schema-change or gh-ost. In PostgreSQL, prefer operations that avoid table rewrites, like adding columns with defaults defined as NULL then updating in batches.