The query ran fast, but the schema was wrong. You needed a new column.
Adding a new column to a database table sounds simple. It is not always simple in production. The right approach keeps downtime near zero, protects existing data, and avoids breaking dependencies. A careless change can lock tables, slow queries, or crash features.
The first step is to define the purpose of the new column. Decide its data type, nullability, and constraints before touching the schema. Match these to existing data models and application logic. Avoid generic types. Use the smallest type that can hold the required range.
In relational databases like PostgreSQL, ALTER TABLE ... ADD COLUMN is the standard command. On small tables, this runs fast. On large ones, the impact depends on the database engine. PostgreSQL can add a nullable column with a default value in constant time if the default is immutable. MySQL often rewrites the table unless you use online DDL with ALGORITHM=INPLACE.
Always check ORM migrations. Tools such as Sequelize, Prisma, or ActiveRecord may apply a lock or run a table copy if you accept the defaults. For high-traffic systems, run schema changes in multiple steps: