| From: | jian he <jian(dot)universality(at)gmail(dot)com> |
|---|---|
| To: | shihao zhong <zhong950419(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>, Álvaro Herrera <alvherre(at)kurilemu(dot)de> |
| Subject: | Re: [PG19] Three bugs with a CHECK constraint that only the child enforces |
| Date: | 2026-10-23 12:04:34 |
| Message-ID: | CACJufxGjsWkmyhP8QTMTT6doWwuCjG9q+fw2nkFiiAfLTxNMMg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Tue, Oct 20, 2026 at 10:24 AM shihao zhong <zhong950419(at)gmail(dot)com> wrote:
>
> Hi jian,
>
> v4 looks good to me. One case is still lost after dump and restore,
> on master and 19, and also on 18:
>
> create table p1 (a int, constraint c check (a > 0));
> create table p2 (a int, constraint c check (a > 0) not enforced);
> create table k () inherits (p1, p2);
> alter table k no inherit p1;
>
> k's c is not local here, so it comes back NOT ENFORCED.
Great!
mimic the above for convalidated, we can easily find out a very old
pg_dump bug. (at least PG16)
drop table if exists p1, p2, k cascade;
create table p1 (a int, constraint c check (a > 0));
create table p2 (a int);
alter table p2 add constraint c check (a > 0) not valid;
create table k () inherits (p1, p2);
alter table k no inherit p1;
Table k comes back as NOT VALID, but it should be valid.
To preserve conislocal and convalidated, pg_dump need emit a
ALTER TABLE public.k VALIDATE CONSTRAINT c;
*after*
ALTER TABLE public.p2
ADD CONSTRAINT c CHECK ((a > 0)) NOT VALID;
Regarding pg_constraint.conislocal, we already have inconsistency, see
function flagInhAttrs.
/*
* For versions >18, we must print the not-null constraint locally
* for this table even if it isn't really locally defined, but is
* valid for the child and no parent has it as valid.
*/
if (fout->remoteVersion >= 180000 && allNotNullsInvalid)
tbinfo->notnull_islocal[j] = true;
Not preserving pg_constraint.conislocal in pg_dump would surely make
life easier.
Related thread:
https://www.postgresql.org/message-id/202504281450.4powv4cchler%40alvherre.pgsql
Now we kow the visible consequences: after pg_dump, ALTER TABLE DROP
CONSTRAINT will no longer cascade to the child table's constraint.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Heikki Linnakangas | 2026-10-23 12:15:03 | Re: [PATCH v1 1/1] Add GENERATED ALWAYS AS ROW IDENTITY columns |
| Previous Message | Álvaro Herrera | 2026-10-23 11:41:13 | Re: [PATCH v1 1/1] Add GENERATED ALWAYS AS ROW IDENTITY columns |