Add support for altering CHECK constraint enforceability

This commit adds support for ALTER TABLE ALTER CONSTRAINT ... [NOT]
ENFORCED for CHECK constraints.  Previously, only foreign key
constraints could have their enforceability altered.

When changing from NOT ENFORCED to ENFORCED, the operation not only
updates catalog information but also performs a full table scan in
Phase 3 to validate that existing data satisfies the constraint.

For partitioned tables and inheritance hierarchies, the operation
recurses to all child tables.  When changing to NOT ENFORCED, we must
recurse even if the parent is already NOT ENFORCED, since child
constraints may still be ENFORCED.

Author: Jian He <[email protected]>
Reviewed-by: Robert Treat <[email protected]>
Reviewed-by: Kirill Reshke <[email protected]>
Reviewed-by: Amul Sul <[email protected]>
Reviewed-by: Zsolt Parragi <[email protected]>
Reviewed-by: Andrew Dunstan <[email protected]>
Discussion: 
https://postgr.es/m/cacjufxhch_fu-fsewscvg9mn6-5tzr6h9ntn+0kugtcaerd...@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/342051d73b386ad763e13930e15031f7ba5367f5

Modified Files
--------------
doc/src/sgml/ref/alter_table.sgml         |   4 +-
src/backend/commands/tablecmds.c          | 194 ++++++++++++++++++++++++++++--
src/test/regress/expected/constraints.out |  80 ++++++++++++
src/test/regress/expected/inherit.out     |  62 ++++++++++
src/test/regress/sql/constraints.sql      |  52 ++++++++
src/test/regress/sql/inherit.sql          |  43 +++++++
6 files changed, 423 insertions(+), 12 deletions(-)

Reply via email to