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

jian he <jian.universality@gmail.com>

From: jian he <jian.universality@gmail.com>
To: Rushabh Lathia <rushabh.lathia@gmail.com>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2025-04-05T07:29:55Z
Lists: pgsql-hackers

Attachments

On Fri, Apr 4, 2025 at 7:54 PM Rushabh Lathia <rushabh.lathia@gmail.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.

Commits

  1. Allow NOT NULL constraints to be added as NOT VALID

  2. Add missing deparsing of [NO] IDENT to XMLSERIALIZE()

  3. backend launchers void * arguments for binary data

  4. Add pg_constraint rows for not-null constraints

  5. Create the infrastructure for planner support functions.

  6. Add prokind column, replacing proisagg and proiswindow