postgresql/src/backend/utils
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
..
adt Fast ALTER TABLE ADD COLUMN with a non-NULL default 2018-03-28 10:43:52 +10:30
cache Fast ALTER TABLE ADD COLUMN with a non-NULL default 2018-03-28 10:43:52 +10:30
error Update copyright for 2018 2018-01-02 23:30:12 -05:00
fmgr Fast ALTER TABLE ADD COLUMN with a non-NULL default 2018-03-28 10:43:52 +10:30
hash Allow memory contexts to have both fixed and variable ident strings. 2018-03-27 16:46:51 -04:00
init Fix cross-checking of ReservedBackends/max_wal_senders/MaxConnections. 2018-03-08 11:25:26 -05:00
mb Update headers of generated files 2018-02-24 14:54:17 -05:00
misc JIT tuple deforming in LLVM JIT provider. 2018-03-26 12:57:19 -07:00
mmgr Allow memory contexts to have both fixed and variable ident strings. 2018-03-27 16:46:51 -04:00
resowner Basic JIT provider and error handling infrastructure. 2018-03-21 19:28:28 -07:00
sort Avoid another valgrind complaint about write() of uninitalized bytes. 2018-02-22 09:28:12 -05:00
time Rename TransactionChain functions 2018-03-16 13:18:06 -04:00
.gitignore Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
errcodes.txt Support all SQL:2011 options for window frame clauses. 2018-02-07 00:06:56 -05:00
Gen_dummy_probes.pl Update copyright for 2018 2018-01-02 23:30:12 -05:00
Gen_dummy_probes.sed Update copyright for 2018 2018-01-02 23:30:12 -05:00
Gen_fmgrtab.pl Update copyright for 2018 2018-01-02 23:30:12 -05:00
generate-errcodes.pl Update copyright for 2018 2018-01-02 23:30:12 -05:00
Makefile Fix make rules that generate multiple output files. 2018-03-23 13:46:00 -04:00
probes.d Support parallel btree index builds. 2018-02-02 13:32:44 -05:00