The query ran fast, but the schema stood in its way. You need a new column.
Adding a new column is a simple change in theory, but it can cripple a system if done without care. Schema migrations touch production data. If the database is large, adding a column locks tables, spikes load, and slows every request. The goal is zero downtime and no surprises.
Start by defining the exact type and constraints. Use NULL defaults when adding to live tables unless your code depends on immediate values. This avoids rewriting every existing row during the migration. If data must be prefilled, backfill in small batches with controlled transactions. Watch for IO saturation and replication lag.
Run migrations in staging with full production data copies. Measure execution time. Identify indexes and triggers that could slow the change. In some databases, adding a column without a default is instantaneous. In others, even the smallest alteration rewrites the table. Know the behavior of your engine—PostgreSQL, MySQL, or anything else in use.