Re: Fix bug of CHECK constraint enforceability recursion - Mailing list pgsql-hackers

From Zsolt Parragi
Subject Re: Fix bug of CHECK constraint enforceability recursion
Date
Msg-id CAN4CZFMgVDOosK_aM15+VV=WC_wgT52d4xgnaOBzvh4LtRq=1A@mail.gmail.com
Whole thread
Responses Re: Fix bug of CHECK constraint enforceability recursion
List 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



pgsql-hackers by date:

Previous
From: Daniel Gustafsson
Date:
Subject: Re: Heads Up: cirrus-ci is shutting down June 1st
Next
From: David Rowley
Date:
Subject: Re: Wrong unsafe-flag test in check_output_expressions()