Fast ALTER TABLE ADD COLUMN with a non-NULL defaultCurrently adding a column to a table with a non-NULL default results ina rewrite of the table. For large tables this can be both expensive anddisruptive. This patch removes the need for the rewrite as long as thedefault value is not volatile. The default expression is evaluated atthe time of the ALTER TABLE and the result stored in a new column(attmissingval) in pg_attribute, and a new column (atthasmissing) is setto true. Any existing row when fetched will be supplied with theattmissingval. New rows will have the supplied value or the default andso will never need the attmissingval.Any time the table is rewritten all the atthasmissing and attmissingvalsettings for the attributes are cleared, as they are no longer needed.The most visible code change from this is in heap_attisnull, whichacquires a third TupleDesc argument, allowing it to detect a missingvalue if there is one. In many cases where it is known that there willnot be any (e.g. catalog relations) NULL can be passed for thisargument.Andrew Dunstan, heavily modified from an original patch from SergeRielau.Reviewed by Tom Lane, Andres Freund, Tomas Vondra and David Rowley.Discussion: https://postgr.es/m/ 31e2e921 -7002-4c27-59f5- 51f08404c858 @2ndQuadrant.com