public inbox for [email protected]
help / color / mirror / Atom feedFrom: Chao Li <[email protected]>
To: Zsolt Parragi <[email protected]>
Cc: [email protected]
Subject: Re: Fix bug of CHECK constraint enforceability recursion
Date: Wed, 3 Jun 2026 09:54:01 +0800
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAN4CZFMgVDOosK_aM15+VV=WC_wgT52d4xgnaOBzvh4LtRq=1A@mail.gmail.com>
References: <[email protected]>
<CACJufxGRkCSqqRwd+3MMVFbosKXHv=Jc+KyGK+NM3YAHN7eu+g@mail.gmail.com>
<[email protected]>
<[email protected]>
<[email protected]>
<CACJufxGxY=1mxcNz8-bjp6R+ZoCRE3O7DYt2ZqObv-Le+aMOqw@mail.gmail.com>
<[email protected]>
<CACJufxFwJH5K1jgL1ryckYX8gxp1sfqz_2ypey1sYtWZ5u45oQ@mail.gmail.com>
<[email protected]>
<[email protected]>
<CACJufxHbVuY683j3DHEU4LSswo8DTzLJbTvhv2Uj6gqN8pJs7Q@mail.gmail.com>
<CAN4CZFMgVDOosK_aM15+VV=WC_wgT52d4xgnaOBzvh4LtRq=1A@mail.gmail.com>
> On Jun 3, 2026, at 04:56, Zsolt Parragi <[email protected]> wrote:
>
> 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
>
Hi Zsolt,
Thanks for your view.
I just tried your test with v6, but didn't see the bug you mentioned:
```
evantest=# create table g(a int constraint k check(a > 0) enforced);
CREATE TABLE
evantest=# create table o(a int constraint k check(a > 0) enforced);
CREATE TABLE
evantest=# create table s1() inherits(g);
CREATE TABLE
evantest=# create table s2() inherits(g, o);
NOTICE: merging multiple inherited definitions of column "a"
CREATE TABLE
evantest=# create table s3() inherits(g);
CREATE TABLE
evantest=# alter table g alter constraint k not enforced;
ALTER TABLE
evantest=# select conrelid::regclass as tbl, conenforced
evantest-# from pg_constraint
evantest-# where conname = 'k';
tbl | conenforced
-----+-------------
o | t
s2 | t
g | f
s1 | f
s3 | f
(5 rows)
evantest=# insert into s1 values (-1);
INSERT 0 1
evantest=# insert into s3 values (-1);
INSERT 0 1
```
Here, both s1 and s3 are the direct child of g, thus when g is set to “not enforced”, s1 and s3 is set to “not enforced" as well. While s2 is a child of both g and o, as o is still enforced, s2 remains enforced. The test result is right as expected.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
view thread (32+ messages) latest in thread
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: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Fix bug of CHECK constraint enforceability recursion
In-Reply-To: <[email protected]>
* 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