The query ran fast, but the table could not keep up. A new column was the only fix.
Creating a new column in a database is simple in theory and heavy in consequence. You can reshape data models, speed up queries, and unlock features that were impossible before. But if handled poorly, you can slow the whole system, burn CPU, and wreck uptime.
The first step is precision. Define the new column in the schema with the exact type and constraints. In SQL:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP NOT NULL DEFAULT NOW();
Choose types that match your data and avoid nullable pitfalls unless they serve a real purpose. Default values should be explicit to prevent inconsistent states.
Consider the cost. Adding a new column locks the table in many databases. On high-traffic systems, this can cause blocking. Use online schema change tools or migrations with minimal locking when possible. For example, PostgreSQL supports adding columns with defaults more efficiently in recent versions, while MySQL may require pt-online-schema-change for safety in production.