bookmark

Waiting for PostgreSQL 11 – Fast ALTER TABLE ADD COLUMN with a non-NULL default – select * from depesz;


Description

Currently adding a column to a table with a non-NULL default results in a rewrite of the table. For large tables this can be both expensive and disruptive. This patch removes the need for the rewrite as long as the default value is not volatile. The default expression is evaluated at the time of the ALTER TABLE and the result stored in a new column (attmissingval) in pg_attribute, and a new column (atthasmissing) is set to true. Any existing row when fetched will be supplied with the attmissingval. New rows will have the supplied value or the default and so will never need the attmissingval.

Preview

Tags

Users

  • @jil

Comments and Reviews