The query ran. The data was clean. Then you saw it — you needed a new column.
Adding a new column sounds simple, but the wrong move can lock tables, stall queries, or break production systems. The right approach depends on scale, schema, and the performance profile of your database.
First, define the column with precision. Choose the smallest data type that fits the values you expect. A boolean beats an integer if it’s true/false. A varchar(50) beats text when you know the length. Smaller types mean less disk usage, faster scans, and reduced memory pressure.
Second, decide on nullability. Avoid nullable columns unless the data model truly allows missing values. Nulls can complicate indexing and equality comparisons.
Third, plan the migration. On small tables, a direct ALTER TABLE ADD COLUMN might be safe. On large tables, this can trigger a full rewrite. Use online schema change tools like pt-online-schema-change or gh-ost for MySQL, or new features like Postgres’ fast column addition when possible.