Re: Fix bug of CHECK constraint enforceability recursion

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Fix bug of CHECK constraint enforceability recursion
Date: 2026-06-02 20:56:40
Message-ID: CAN4CZFMgVDOosK_aM15+VV=WC_wgT52d4xgnaOBzvh4LtRq=1A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello

+ * During recursion, another parent outside this ALTER may still enforce
+ * the same constraint. In that case, keep the child constraint ENFORCED
+ * so that its merged enforceability still reflects the remaining enforced
+ * parent.
+ */
+ if (!cmdcon->is_enforced)
+ {

This means once is_enforced is set to true, it will never be
rechecked. See the following example which showcases an issue with
this:

create table g(a int constraint k check(a > 0) enforced);
create table o(a int constraint k check(a > 0) enforced);
create table s1() inherits(g);
create table s2() inherits(g, o);
create table s3() inherits(g);
alter table g alter constraint k not enforced;
select conrelid::regclass as tbl, conenforced
from pg_constraint
where conname = 'k' and contype = 'c'
order by conrelid::regclass::text collate "C";
insert into s1 values (-1);
insert into s3 values (-1); -- bug: ERRORs out, but shouldn't

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2026-06-02 20:59:17 Re: Wrong unsafe-flag test in check_output_expressions()
Previous Message Daniel Gustafsson 2026-06-02 19:12:16 Re: Heads Up: cirrus-ci is shutting down June 1st