The query was slow, but the new column was already in place.
Adding a new column to a production database sounds simple. It can be, if the schema change is planned and executed with precision. Done poorly, it risks downtime, locks, and broken dependencies. The goal is to move fast without corrupting data or blocking critical reads and writes.
First, define the purpose of the new column. Set clear data types, constraints, and defaults. Defaults can be useful, but they can also slow migrations if the database engine rewrites entire tables. Consider applying them after the column is live.
Second, choose the right migration strategy. For small tables, an ALTER TABLE ADD COLUMN may run instantly. For large ones, online schema change tools like pt-online-schema-change or gh-ost help avoid blocking queries. Use transactional DDL when supported. Always test the migration in an isolated environment loaded with production-like data.