The database was fast, but not fast enough. A query hung for half a second too long. The fix was one line: add a new column.
Adding a new column changes both schema and workflow. In SQL, it’s direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This command updates the table definition. The new column can have a default value or be nullable. Defaults populate existing rows; without a default, the column holds NULL until updated.
When adding a new column in production, check for locking behavior. Some engines lock the table during the operation, blocking writes. PostgreSQL 11+ adds many types of columns without a full table rewrite, but older versions might still block. MySQL’s behavior depends on the storage engine, with InnoDB able to add columns online under certain conditions.
Schema migrations with a new column are best done in controlled deployments. Use migration tooling to keep versions in sync across environments. Apply changes in a transaction where supported. Avoid adding non-null columns without defaults on large tables, as they may force expensive rewrites.