Re: Support NOT VALID / VALIDATE constraint options for named NOT NULL constraints

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
Cc: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Support NOT VALID / VALIDATE constraint options for named NOT NULL constraints
Date: 2025-04-05 07:29:55
Message-ID: CACJufxF3hJL+Lw5CLp56SLoigMwzfekDRQ5-_RJybMQaXRgT=w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Apr 4, 2025 at 7:54 PM Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com> wrote:
>
> Hi Alvaro,
>
> I’ve consolidated all the changes and attached the latest version of the patch, which
> includes the updates submitted by Jian for pg_dump as well.
>
> Patch 0001 contains changes to MergeWithExistingConstraint to fix the marking on local constraints.
> Patch 0002 includes support for NOT NULL NOT VALID, corresponding pg_dump changes, test cases,
> and documentation updates.
>

hi.
+ /* FIXME use CompactAttribute */
Form_pg_attribute att = TupleDescAttr(relation->rd_att, i - 1);
if (att->attnotnull && att->attnotnullvalid &&
!att->attisdropped)
{
NullTest *ntest = makeNode(NullTest);
ntest->arg = (Expr *) makeVar(varno,
i,
att->atttypid,
att->atttypmod,
att->attcollation,
0);
ntest->nulltesttype = IS_NOT_NULL;

CompactAttribute doesn't have {atttypmod, attcollation} information,
now it is impossible to use CompactAttribute here,
so I removed this FIXME in get_relation_constraints.

i noticed that we have
"mode change 100644 => 100755 src/bin/pg_dump/t/002_pg_dump.pl"
in 0002-Support-NOT-VALID-and-VALIDATE-CONSTRAINT-for-named-.patch.

i am uncomfortable with the change in
'CREATE TABLE dump_test.test_table_generated'
so I only added 'CONSTRAINT NOT NULL / INVALID' tests in
002_pg_dump.pl.
so I only added a test case 'CONSTRAINT NOT NULL / INVALID'
to 002_pg_dump.pl.

v7-0001 commit message explains what kind of problem
MergeWithExistingConstraint is trying to fix.
v7-0002 bullet points summary about NOT NULL NOT VALID added to the
commit message.

add a test for CREATE TABLE LIKE.
CREATE TABLE LIKE will copy the invalid not-null constraint and will become
valid, i think this is what we want.

The added regress test is a little bit verbose, trying to make it less verbose.
polish comments here and there.

Attachment Content-Type Size
v7-0002-NOT-NULL-NOT-VALID.patch text/x-patch 88.7 KB
v7-0001-mark-conislocal-as-false-while-merging-valid-cons.patch text/x-patch 3.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2025-04-05 08:31:14 Re: Change COPY ... ON_ERROR ignore to ON_ERROR ignore_row
Previous Message Atsushi Torikoshi 2025-04-05 06:13:47 Re: RFC: Logging plan of the running query