The query returned fast, but something was missing. A new column.
Adding a new column to a database table should be simple. In practice, it can be slow, dangerous, and expensive in production. Schema changes lock tables. They block writes, stall reads, and can break critical services. With the wrong command, you can turn a high-traffic system into a dead system.
The safest approach starts with knowing your database engine. In PostgreSQL, ALTER TABLE ... ADD COLUMN is often instant if you include a NULL default. But setting a non-nullable column with a default value can rewrite the whole table. On MySQL, InnoDB may copy the entire table for some changes. The cost grows with table size.
For large datasets, break the migration into phases. Add the new column as nullable, deploy it, then backfill data in batches. Make writes idempotent. Only enforce constraints and defaults after the backfill is complete. This pattern reduces locks and downtime.