Re: [PG19] Three bugs with a CHECK constraint that only the child enforces

From: shihao zhong <zhong950419(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Nikolay Samokhvalov <nik(at)postgres(dot)ai>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Subject: Re: [PG19] Three bugs with a CHECK constraint that only the child enforces
Date: 2026-10-15 03:48:46
Message-ID: CAGRkXqQQapfoGHpi2znkMfzkCk-=5GvmC16KKbVa6-BZn0yF6g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

i jian, Chao,

Thanks for the reviews.

1. jian, you are right, that was inconsistent. In v2, ALTER
CONSTRAINT ... ENFORCED on the parent fails with "conflicts with NOT
VALID constraint on child table", the error that ALTER TABLE ...
INHERIT already gives here. The user validates the child first. So
nothing becomes valid behind the user's back, and this does not
depend on the question Chao raised.

2. Yes, 18 has it too, the first mail said so. 0002 fixes your
partition example as well.

3. Dumping the child's constraint as local changes the catalog. With
your patch, k's c comes back with conislocal = true, so ALTER TABLE p
DROP CONSTRAINT c no longer drops it from k. pg_upgrade keeps it
inherited today, and your patch makes it local there too. ALTER
CONSTRAINT is the only command that gives back an inherited
constraint that only the child enforces.

Your partition case is real, my 0003 missed it, and pg_upgrade loses
it on master too. v2-0003 dumps that constraint before its ancestors'
ones, as your patch does, with your test. I added you as co-author.

A local NOT VALID child that sorts after the parent still comes back
validated. That comes from ADD CONSTRAINT merging into the inherited
NOT ENFORCED copy, which Nikolay's patch fixes [1].

[1]
https://postgr.es/m/CAM527d8qCH4q1xV-TftDmm3eBcBie9AxfdTtThPUoGWnYT08gw@mail.gmail.com

Thanks,
Shihao

Attachment Content-Type Size
v2-0002-Keep-a-child-s-ENFORCED-CHECK-when-the-parent-s-c.patch application/octet-stream 5.1 KB
v2-0003-pg_dump-keep-ENFORCED-on-a-child-s-inherited-CHEC.patch application/octet-stream 9.8 KB
v2-0001-Reject-enforcing-a-parent-CHECK-over-a-NOT-VALID-.patch application/octet-stream 4.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message shihao zhong 2026-10-15 03:53:48 [PG19] Promotion hangs behind a backend blocked on a stuck client
Previous Message David Rowley 2026-10-15 03:18:33 Weird usages of sentinel_ok()