Re: cataloguing NOT NULL constraints

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: cataloguing NOT NULL constraints
Date: 2023-07-11 14:17:20
Message-ID: 20230711141720.wzjikyy3ckjgavas@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I left two questions unanswered here, so here I respond to them while
giving one more revision of the patch.

I realized that the AT_CheckNotNull stuff is now dead code, so in this
version I remove it. I also changed on heap_getattr to
SysCacheGetAttrNotNull, per a very old review comment from Justin that I
hadn't acted upon. The other changes are minor code comments and test

At this point I think this is committable.

On 2023-Jul-03, Peter Eisentraut wrote:

> + /*
> + * Copy NOT NULL constraints, too (these do not require any option to have
> + * been given).
> + */
> Shouldn't that be governed by the INCLUDING CONSTRAINTS option?

To clarify: this is in LIKE, such as
CREATE TABLE (LIKE someother);
and the reason we don't want to make this behavior depend on INCLUDING
CONSTRAINTS, is backwards compatibility; NOT NULL markings have
traditionally been propagated, so it can be used to create partitions
based on the parent table, and if we made that require the option to be
specified, that would no longer occur in the default case. Maybe we can
change that behavior, but I'm pretty sure it would be resisted.

> Btw., there is some asymmetry here between check constraints and
> not-null constraints: Check constraints are in the tuple descriptor,
> but not-null constraints are not. Should that be unified? Or at
> least explained?

Well, the reason check constraints are in the descriptor, is that they
are needed to verify a table. NOT NULL constraint as catalog objects
are (at present) only useful from a DDL point of view; they won't change
the underlying implementation, which still depends on just the
attnotnull markings.

Álvaro Herrera Breisgau, Deutschland —

Attachment Content-Type Size
v11-0001-Add-pg_constraint-rows-for-NOT-NULL-constraints.patch text/x-diff 227.3 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Sabino Mullane 2023-07-11 14:42:19 Forgive trailing semicolons inside of config files
Previous Message Alena Rybakina 2023-07-11 14:13:05 Re: POC, WIP: OR-clause support for indexes