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 <[email protected]> Reviewed-by: Jian He <[email protected]> Reviewed-by: Zsolt Parragi <[email protected]> Reviewed-by: Álvaro Herrera <[email protected]> Discussion: https://postgr.es/m/[email protected] Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/0cd17fdd3c000f6e64e79da0fea5e65dc9f562df Modified Files -------------- src/backend/commands/tablecmds.c | 256 +++++++++++++++++++++++++++--- src/test/regress/expected/constraints.out | 15 +- src/test/regress/expected/inherit.out | 92 +++++++++++ src/test/regress/sql/constraints.sql | 5 +- src/test/regress/sql/inherit.sql | 52 ++++++ 5 files changed, 395 insertions(+), 25 deletions(-)
