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>, Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Subject: Re: [PG19] Three bugs with a CHECK constraint that only the child enforces
Date: 2026-10-17 03:41:20
Message-ID: CAGRkXqRk3JfQTEXg1=CeD=1RboXUJfOqYKirTKeHxojQK4sqfQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi jian,

Thanks for v3. It passes my 0002 test, so I will drop 0002 and leave
2 to your patch. 0001 and 0003 still apply on top of v3, and the
tests pass.

v3 also fixes a wrong result that 18 and 19 have:

create table p (b int, constraint c check (b > 0) not enforced);
create table k (b int);
insert into k values (-1);
alter table k add constraint c check (b > 0) not valid;
alter table k inherit p;
alter table p alter column b type bigint;
select count(*) from p where b < 0;

This returns 0. The ALTER TYPE marks the child's NOT VALID constraint
as validated, so the planner skips k. The one line change in
MergeWithExistingConstraint() from Nikolay's patch [1] fixes it on 18
and 19.

In your p3 example only convalidated changes after a restore, not
conislocal. I think this is your Bug A. I would leave it out of this set.

Bug B reproduces on 18 and later. It is about NOT NULL, so maybe it
needs its own thread.

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

Thanks,
Shihao

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message shihao zhong 2026-10-17 03:52:34 Re: [PG19] psql backslash commands fail with translated messages and a non UTF-8 client encoding
Previous Message shihao zhong 2026-10-17 03:32:24 Re: [PG19] Indexes from 18 miss rows after pg_upgrade