The table was fast, but the query was slow. You traced the issue to the schema. It needed a new column.
Adding a new column sounds trivial. It isn’t. In production, it can lock writes. It can block reads. It can cascade failures if done wrong. Handling a schema change safely takes planning, precision, and often, zero downtime techniques.
First, decide the column type and constraints. Keep it as small as possible. Avoid TEXT or BLOB unless you must. Every byte matters when altering live data.
Second, pick your migration method. For small datasets, a direct ALTER TABLE ADD COLUMN is safe. For large ones, use an online schema change tool. PostgreSQL supports ADD COLUMN instantly if no default value is set. MySQL can perform an in-place add for certain types, but others require a full table rebuild. Test before you run it on production.