The query ran fast and clean until it hit the table. Then it stalled. The missing piece was a new column.
Adding a new column is one of the most common schema changes, but done wrong, it can lock a table and choke performance. Done right, it expands capability without downtime. Whether you’re adjusting a production database or building fresh tables in a migration, precision is essential.
Start with a clear purpose. Decide if the new column should be nullable, have a default value, or require constraints. These decisions affect both storage and query speed. For large datasets, adding defaults can rewrite the entire table, so consider adding the column without defaults first, then backfilling in batches.
Foreign keys and indexes demand careful thought. Indexing the new column immediately can cause heavy write locks. Often it’s better to create the column, populate it, and add indexes after. For high-traffic systems, use online schema change tools like pt-online-schema-change or native features such as PostgreSQL’s ADD COLUMN without a rewrite.