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

From jian he
Subject Re: Fix bug of CHECK constraint enforceability recursion
Date
Msg-id CACJufxE2B6nrfV9inubVifY-8Y6hObBAtyXHEAtPLA6JATXjgA@mail.gmail.com
Whole thread
In response to Re: Fix bug of CHECK constraint enforceability recursion  (Chao Li <li.evan.chao@gmail.com>)
Responses Re: Fix bug of CHECK constraint enforceability recursion
List pgsql-hackers
On Sat, Jun 6, 2026 at 11:06 AM Chao Li <li.evan.chao@gmail.com> wrote:
>
> PFA v8: 0001 and 0003 unchanged. 0002  addressed Zsolt’s comment.
>

drop table root_t cascade;
create table root_t (a int constraint c check (a > 0) enforced);
create table p2 (a int constraint c check (a > 0) enforced);
create table d () inherits (root_t, p2);
create table e () inherits (d);
CREATE OR REPLACE PROCEDURE create_table(i int) AS $$
DECLARE
  r int;
  query text;
BEGIN
    FOR i IN 20..$1 LOOP
        query := 'create table f' || i || '() inherits (e)';
        raise notice 'query: %', query;
        EXECUTE query;
    END LOOP;
END; $$ LANGUAGE plpgsql;

call create_table(1000);
alter table root_t alter constraint c not enforced;

ATCheckCheckConstrHasEnforcedParent invoked 996070 times
ATCheckCheckConstrHasEnforcedParent will call itself, so I think we
need check_stack_depth() on it.

I also made a minor refactoring to reduce unnecessary work in
ATCheckCheckConstrHasEnforcedParent().
A single call to table_open(parentoid, ...) is enough.

Keep errmsg() messages on a single line to improve grepability.



--
jian
https://www.enterprisedb.com/

Attachment

pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: [Patch] Fix check_pub_rdt bypass when origin is set in same ALTER SUBSCRIPTION
Next
From: Nazir Bilal Yavuz
Date:
Subject: Re: ci: CCache churns through available space too quickly