The query returned fast, but the dataset had changed. A new column had appeared where none existed before.
Adding a new column to a database table is one of the most common schema changes. It’s also one of the most dangerous if done without planning. Improper execution can lock tables, block writes, or bring down production. The approach depends on your database engine, table size, and uptime needs.
In PostgreSQL, ALTER TABLE ADD COLUMN is instant for metadata-only changes. Adding a column with a constant default can trigger a table rewrite in older versions. Starting in PostgreSQL 11, default values that are non-volatile no longer require a full rewrite, making the operation faster for large data sets. Always check your version before assuming performance characteristics.
In MySQL, adding a new column to an InnoDB table can involve a full table copy unless you use ALGORITHM=INPLACE or ALGORITHM=INSTANT (available in MySQL 8.0+). ALGORITHM=INSTANT supports only certain column types and positions—validate these before deployment to avoid unexpected downtime.