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

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Support NOT VALID / VALIDATE constraint options for named NOT NULL constraints
Date: 2025-04-24 19:36:49
Message-ID: 202504241936.qg3rct4364rs@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2025-Apr-09, jian he wrote:

> hi.
>
> attached patch is for address pg_dump inconsistency
> when parent is "not null not valid" while child is "not null".

Here's my take on this patch. We don't really need the
notnull_parent_invalid flag; in flagInhAttrs we can just set "islocal"
to convince getTableAttrs to print the constraint. This also fixes the
bug that in getTableAttrs() you handled the case where
shouldPrintColumn() is true and not the other one.

I also added test cases to pg_dump/t/002_pg_dump.pl to verify that the
output was correct in those cases. In constraints.sql I added a couple
of tables to ensure that the pg_upgrade handling (the pg_dump
--binary-upgrade mode) is tested as well.

Looking at the surrounding code in flagInhAttrs I noticed that we're
mishandling this case:

create table parent1 (a int);
create table parent2 (a int);
create table child () inherits (parent1, parent2);
alter table parent1 add not null a;
alter table parent2 add not null a not valid;

We print the constraint for table child for no apparent reason.

Patch 0002 is a part of your proposed patch that I don't think we need,
but I'm open to hearing arguments about why we do, preferrably with some
test cases.

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Hay que recordar que la existencia en el cosmos, y particularmente la
elaboración de civilizaciones dentro de él no son, por desgracia,
nada idílicas" (Ijon Tichy)

Attachment Content-Type Size
0001-Fix-pg_dump-for-inherited-validated-not-null-constra.patch text/x-diff 9.5 KB
0002-Unnecessary-change.patch text/x-diff 1.1 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Matthias van de Meent 2025-04-24 20:46:10 Re: Why doesn't GiST VACUUM require a super-exclusive lock, like nbtree VACUUM?
Previous Message said assemlal 2025-04-24 19:26:24 Re: Available disk space per tablespace