| From: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Prevent inherited CHECK constraints from being weakened |
| Date: | 2026-06-27 22:10:21 |
| Message-ID: | E1wdbED-000SMf-0v@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
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(at)highgo(dot)com>
Reviewed-by: Jian He <jian(dot)universality(at)gmail(dot)com>
Reviewed-by: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
Reviewed-by: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Discussion: https://postgr.es/m/E74C57FA-1DD0-4C8E-8FB1-538034752592@gmail.com
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(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andrew Dunstan | 2026-06-28 00:05:59 | pgsql: pgindent fix for commit effb923d9de |
| Previous Message | Peter Eisentraut | 2026-06-27 17:42:33 | pgsql: Reject child partition FDWs in FOR PORTION OF |