agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: Andrew Dunstan <andrew@dunslane.net>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Prevent inherited CHECK constraints from being weakened
Date: Sat, 27 Jun 2026 22:10:21 +0000
Message-ID: <E1wdbED-000SMf-0v@gemulon.postgresql.org> (raw)
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
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(-)
Message-ID: <E1wdbED-000SMf-0v@gemulon.postgresql.org>
Permalink: ../E1wdbED-000SMf-0v@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1wdbED-000SMf-0v@gemulon.postgresql.org
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: andrew@dunslane.net, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Prevent inherited CHECK constraints from being weakened
In-Reply-To: <E1wdbED-000SMf-0v@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox