Re: ALTER COLUMN SET NOT NULL differ from ALTER TABLE ADD CONSTRAINT

From: shihao zhong <zhong950419(at)gmail(dot)com>
To: Haibo Yan <tristan(dot)yim(at)gmail(dot)com>
Cc: jian he <jian(dot)universality(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: ALTER COLUMN SET NOT NULL differ from ALTER TABLE ADD CONSTRAINT
Date: 2026-10-29 03:02:06
Message-ID: CAGRkXqRPSncre8DbKWQ5kK-BYZWD97wGN-o7HsJaMuDcq7z2xg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Haibo,

Thanks for the patch. I reviewed v1 and the main fix looks right to
me. I think it needs to go back to 18.

On 19 the wrong results go further. Take jian's case as a partitioned
table, and add o(x int not null) with one row. Then

select count(*) from o where x not in (select a from p);

returns 1 on 19 and 0 on 18. The bug is from 18, so maybe it belongs
under "Older bugs affecting stable branches" on the 19 open items page.

A few notes.
1. I ran the test before and after I believe it catched the bug, but 1k loc
feels too much for me.

2. with your change
create table tp (a int);
create table tc () inherits (tp);
create table tg () inherits (tc);
alter table tg add constraint tg_nn not null a not valid;
alter table tp add constraint tp_nn not null a no inherit* not valid;*
alter table tp alter constraint tp_nn inherit;
-- ERROR: incompatible NOT VALID constraint "tg_nn" on relation "tg"

INHERIT adds tp_nn to tc as a valid constraint, and then tg is
rejected. Since tp_nn is NOT VALID, maybe the copy on tc should be
NOT VALID too. ADD CONSTRAINT ... NOT VALID works that way.

Thanks,
Shihao

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message shihao zhong 2026-10-29 04:00:56 Racing in ROLLBACK PREAPRED and checkpoint
Previous Message Fujii Masao 2026-10-29 02:41:52 Re: [PATCH] Fix PITR pause bypass when initial XLOG_RUNNING_XACTS has subxid overflow