]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Prevent inherited CHECK constraints from being weakened
authorAndrew Dunstan <andrew@dunslane.net>
Sat, 27 Jun 2026 21:42:51 +0000 (17:42 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Sat, 27 Jun 2026 21:51:26 +0000 (17:51 -0400)
commit0cd17fdd3c000f6e64e79da0fea5e65dc9f562df
tree7618c92203cbf3264b81977485f79ffbb33b9b4f
parenteffb923d9dec8fd4a5102fee80e52d65d86747c8
Prevent inherited CHECK constraints from being weakened

Disallow marking an inherited CHECK constraint as NOT ENFORCED when an
equivalent parent constraint remains ENFORCED. This prevents ALTER
CONSTRAINT from producing a child constraint that is weaker than one of
its inherited parent definitions.

When recursively altering a CHECK constraint to NOT ENFORCED, collect the
corresponding constraints in the affected inheritance subtree and ignore
those parent constraints while checking descendants. If a descendant also
inherits an equivalent ENFORCED constraint from a parent outside the
current ALTER, keep the descendant ENFORCED by merging to the stricter
state.

This was missed in commit 342051d73b3, which introduced the ability to
alter CHECK constraint enforceability.

Add regression coverage for direct child ALTER, ONLY ALTER, mixed-parent
inheritance, and a common-ancestor diamond where all equivalent inherited
constraints can be changed together.

Author: Chao Li <lic@highgo.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Zsolt Parragi <zsolt.parragi@percona.com>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Discussion: https://postgr.es/m/E74C57FA-1DD0-4C8E-8FB1-538034752592@gmail.com
src/backend/commands/tablecmds.c
src/test/regress/expected/constraints.out
src/test/regress/expected/inherit.out
src/test/regress/sql/constraints.sql
src/test/regress/sql/inherit.sql