Re: not null constraints, again

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Tender Wang <tndrwang(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: not null constraints, again
Date: 2024-10-02 14:25:13
Message-ID: 202410021425.uwi5d5w4zszg@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2024-Oct-02, Alvaro Herrera wrote:

> On 2024-Oct-02, jian he wrote:
>
> > On Tue, Oct 1, 2024 at 11:20 PM Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> wrote:

> > after v7, still not bullet-proof. as before, pg_dump/restore will fail
> > for the following:
> >
> > drop table if exists t2, t2_0
> > create table t2 (a int, b int, c int, constraint foo primary key(a),
> > constraint foo1 not null a no inherit);
> > create table t2_0 (a int constraint foo1 not null no inherit, b int, c
> > int, constraint foo12 primary key(a));
>
> Rats. Fixing :-)

Hmm, I thought this was going to be a five-minute job: I figured I could
add a check in DefineIndex() that reads all columns and ensure they're
no-inherit. First complication: when creating a partition, we do
DefineIndex to create the indexes that the parent table has, before we
do AddRelationNotNullConstraints(), so the not-null constraint lookup
fails. Easy enough to fix: just move the AddRelationNotNullConstraints
call a few lines up. However, things are still not OK because ALTER
TABLE ALTER COLUMN TYPE does want to recreate the PK before the
not-nulls (per ATPostAlterTypeParse), because AT_PASS_OLD_INDEX comes
before AT_PASS_OLD_CONSTR ... and obviously we cannot change that.

Another possibility is to add something like AT_PASS_OLD_NOTNULL but
that sounds far too ad-hoc.

Maybe I need the restriction to appear somewhere else rather than on
DefineIndex.

Still looking ...

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Los dioses no protegen a los insensatos. Éstos reciben protección de
otros insensatos mejor dotados" (Luis Wu, Mundo Anillo)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Laurenz Albe 2024-10-02 14:44:46 Re: bgwrite process is too lazy
Previous Message Robert Haas 2024-10-02 14:09:45 Re: pg_verifybackup: TAR format backup verification