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

From Chao Li
Subject Re: Fix bug of CHECK constraint enforceability recursion
Date
Msg-id B41C7375-BA73-4471-9CAA-FA6D8046BDB6@gmail.com
Whole thread
In response to Re: Fix bug of CHECK constraint enforceability recursion  (jian he <jian.universality@gmail.com>)
Responses Re: Fix bug of CHECK constraint enforceability recursion
List pgsql-hackers

> On Jun 8, 2026, at 18:28, jian he <jian.universality@gmail.com> wrote:
>
> 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.
>>
>

Thanks for the review.

> 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.

Good point. Added it in v9.

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

Agreed. I fine-tuned this code a little bit further. Now in v9, it only opens the parent table when needed and only
openat most once. 

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

I’m not sure this needs to be changed. The message is quite long, and there are existing precedents for splitting long
errmsg()strings across multiple lines. For example: 
```
    if (getExtensionOfObject(NamespaceRelationId, nspOid) == extensionOid)
        ereport(ERROR,
                (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
                 errmsg("cannot move extension \"%s\" into schema \"%s\" "
                        "because the extension contains the schema",
                        extensionName, newschema)));
```

So, this does not seem to be a strict rule. I also don’t think this hurts grepability much in practice, since searching
forthe distinctive part of the message still finds it. 

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/





Attachment

pgsql-hackers by date:

Previous
From: Atsushi Torikoshi
Date:
Subject: Re: RFC: Logging plan of the running query
Next
From: Etsuro Fujita
Date:
Subject: Re: [(known) BUG] DELETE/UPDATE more than one row in partitioned foreign table