Re: using index to speedup add not null constraints to a table

jian he <jian.universality@gmail.com>

From: jian he <jian.universality@gmail.com>
To: Álvaro Herrera <alvherre@kurilemu.de>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-04-08T01:45:50Z
Lists: pgsql-hackers

Attachments

On Tue, Apr 7, 2026 at 6:02 PM Álvaro Herrera <alvherre@kurilemu.de> wrote:
>
> Hello,
>
> I think you may have not looked at my review at
> https://postgr.es/m/202601131715.cheonohttbyj@alvherre.pgsql
> because as far as I can tell, this new version has essentially the same
> structure as before that review.
>

Hi.

I guess the point I haven't addressed yet is:

> However, if we do this, then I think computing notnull_attrs is
> pointless.  So we should only change the order: do this new check first,
> and if we find that any new not-null column is on a generated column,
> then we compute both notnull_virtual_attrs and notnull_attrs.  No?
>

The attached patch implements this reordering,
first do index_check_notnull then compute both notnull_virtual_attrs
and notnull_attrs.



--
jian
https://www.enterprisedb.com/