The query hit the table like a hammer. You needed a new column, and you needed it now. No experiments, no vague schemas—change the data model and move without breaking what works.
A new column is more than an extra field. It alters storage, query plans, and the shape of your API payloads. In SQL, adding a column can be instantaneous for small tables, but on large production datasets it demands caution. Use ALTER TABLE ADD COLUMN for minimal disruption, but understand the lock behavior in your database engine. PostgreSQL will avoid rewriting rows for certain column defaults; MySQL may not. Read the docs, measure the impact, and choose the safest path.
When designing your new column, define its type and constraints early. A nullable column avoids forcing immediate writes to legacy rows, but non-null fields ensure data integrity from day one. Defaults matter—set them in the schema if they are universal, or leave them empty to signal missing values.
Indexing a new column comes with trade-offs. A well-chosen index can speed lookups and filters, but every insert or update will cost more. Avoid indexing until you see real query demand. If the column will be part of joins or filters, consider composite indexes for efficiency.