postgresql/src/include
Andrew Dunstan a0b6ef29a5 Enable fast default for domains with non-volatile constraints
Previously, ALTER TABLE ADD COLUMN always forced a table rewrite when
the column type was a domain with constraints (CHECK or NOT NULL), even
if the default value satisfied those constraints.  This was because
contain_volatile_functions() considers CoerceToDomain immutable, so
the code conservatively assumed any constrained domain might fail.

Improve this by using soft error handling (ErrorSaveContext) to evaluate
the CoerceToDomain expression at ALTER TABLE time.  If the default value
passes the domain's constraints, the value is stored as a "missing"
attribute default and no table rewrite is needed.  If the constraint
check fails, we fall back to a table rewrite, preserving the historical
behavior that constraint violations are only raised when the table
actually contains rows.

Domains with volatile constraint expressions always require a table
rewrite since the constraint result could differ per evaluation and
cannot be cached.

Author: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Reviewed-by: Viktor Holmberg <viktor.holmberg@aiven.io>
Discussion: https://postgr.es/m/CACJufxE_+iZBR1i49k_AHigppPwLTJi6km8NOsC7FWvKdEmmXg@mail.gmail.com
2026-03-12 18:05:01 -04:00
..
access nbtree: Avoid allocating _bt_search stack. 2026-03-12 13:22:36 -04:00
archive Update copyright for 2026 2026-01-01 13:24:10 -05:00
backup Update copyright for 2026 2026-01-01 13:24:10 -05:00
bootstrap Simplify creation of built-in functions with non-default ACLs. 2026-03-05 17:43:09 -05:00
catalog Introduce the REPACK command 2026-03-10 19:56:39 +01:00
commands Introduce the REPACK command 2026-03-10 19:56:39 +01:00
common Use fallthrough attribute instead of comment 2026-02-19 08:51:12 +01:00
datatype Update copyright for 2026 2026-01-01 13:24:10 -05:00
executor Enable fast default for domains with non-volatile constraints 2026-03-12 18:05:01 -04:00
fe_utils pg_dumpall: Fix handling of conflicting options. 2026-03-06 14:00:04 -06:00
foreign CREATE SUBSCRIPTION ... SERVER. 2026-03-06 08:27:56 -08:00
jit Fix typos and inconsistencies in code and comments 2026-01-05 09:19:15 +09:00
lib Make use of pg_popcount() in more places. 2026-02-23 09:26:00 -06:00
libpq Don't include proc.h in shm_mq.h 2026-02-27 10:53:47 +01:00
mb Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:44:04 +13:00
nodes Introduce the REPACK command 2026-03-10 19:56:39 +01:00
optimizer Convert NOT IN sublinks to anti-joins when safe 2026-03-12 09:45:18 +09:00
parser Introduce the REPACK command 2026-03-10 19:56:39 +01:00
partitioning Update copyright for 2026 2026-01-01 13:24:10 -05:00
pch Update copyright for 2026 2026-01-01 13:24:10 -05:00
port Fix some -Wcast-qual warnings 2026-02-27 21:57:33 +01:00
portability instrumentation: Drop INSTR_TIME_SET_CURRENT_LAZY macro 2026-02-26 10:39:29 -05:00
postmaster Fix some -Wcast-qual warnings 2026-02-27 21:57:33 +01:00
regex Update copyright for 2026 2026-01-01 13:24:10 -05:00
replication Avoid including utils/timestamp.h in conflict.h. 2026-02-23 10:19:05 +05:30
rewrite Update copyright for 2026 2026-01-01 13:24:10 -05:00
snowball Update to latest Snowball sources. 2026-01-05 15:22:37 -05:00
statistics Add support for "mcv" in pg_restore_extended_stats() 2026-01-29 12:14:08 +09:00
storage bufmgr: Remove the, now obsolete, BM_JUST_DIRTIED 2026-03-11 14:58:29 -04:00
tcop Introduce the REPACK command 2026-03-10 19:56:39 +01:00
tsearch Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:44:04 +13:00
utils Extend DomainHasConstraints() to optionally check constraint volatility 2026-03-12 18:04:16 -04:00
.gitignore Use <stdint.h> and <inttypes.h> for c.h integers. 2024-12-04 15:05:38 +13:00
c.h Fixes for C++ typeof implementation 2026-03-11 11:54:10 +01:00
fmgr.h Improve type handling of varlena structures 2026-02-11 07:33:24 +09:00
funcapi.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
getopt_long.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
Makefile Fix build inconsistency due to the generation of wait-event code 2026-02-02 08:02:39 +09:00
meson.build Ensure that all three build methods install the same set of files. 2026-02-16 15:20:15 -05:00
miscadmin.h Add password expiration warnings. 2026-02-11 10:36:15 -06:00
pg_config.h.in Portable StaticAssertExpr 2026-03-06 09:27:54 +01:00
pg_config_manual.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_getopt.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_trace.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pgstat.h Don't include wait_event.h in pgstat.h 2026-03-06 16:24:58 +01:00
pgtar.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pgtime.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
port.h strnlen() is now required 2026-01-08 08:51:20 +01:00
postgres.h Remove Int8GetDatum function 2026-03-11 10:46:08 +01:00
postgres_ext.h Move pg_int64 back to postgres_ext.h 2025-09-16 10:48:56 +02:00
postgres_fe.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
varatt.h Improve type handling of varlena structures 2026-02-11 07:33:24 +09:00
windowapi.h Update copyright for 2026 2026-01-01 13:24:10 -05:00