postgresql/src/backend/rewrite
Andrew Dunstan 16828d5c02 Fast ALTER TABLE ADD COLUMN with a non-NULL default
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.

Any time the table is rewritten all the atthasmissing and attmissingval
settings for the attributes are cleared, as they are no longer needed.

The most visible code change from this is in heap_attisnull, which
acquires a third TupleDesc argument, allowing it to detect a missing
value if there is one. In many cases where it is known that there will
not be any (e.g.  catalog relations) NULL can be passed for this
argument.

Andrew Dunstan, heavily modified from an original patch from Serge
Rielau.
Reviewed by Tom Lane, Andres Freund, Tomas Vondra and David Rowley.

Discussion: https://postgr.es/m/31e2e921-7002-4c27-59f5-51f08404c858@2ndQuadrant.com
2018-03-28 10:43:52 +10:30
..
Makefile Row-Level Security Policies (RLS) 2014-09-19 11:18:35 -04:00
rewriteDefine.c Remove pg_class.relhaspkey 2018-03-14 15:31:34 -04:00
rewriteHandler.c Fast ALTER TABLE ADD COLUMN with a non-NULL default 2018-03-28 10:43:52 +10:30
rewriteManip.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
rewriteRemove.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
rewriteSupport.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
rowsecurity.c Update copyright for 2018 2018-01-02 23:30:12 -05:00