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

From: Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Support NOT VALID / VALIDATE constraint options for named NOT NULL constraints
Date: 2025-03-10 11:26:14
Message-ID: CAGPqQf2C+KyLkRQ3ToBx2BC-URG2LQDQ1LX0tu7_jvzTJ_caMg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Feb 27, 2025 at 3:25 PM Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
wrote:

> Thank Alvaro for the fixup patch.
>
>
>
>
> On Fri, Feb 21, 2025 at 11:43 AM Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
> wrote:
>
>> Hello,
>>
>> Thanks!
>>
>> I noticed a typo 'constrint' in several places; fixed in the attached.
>>
>> I discovered that this sequence, taken from added regression tests,
>>
>> CREATE TABLE notnull_tbl1 (a int);
>> ALTER TABLE notnull_tbl1 ADD CONSTRAINT nn_parent not null a not valid;
>> CREATE TABLE notnull_chld (a int);
>> ALTER TABLE notnull_chld ADD CONSTRAINT nn_child not null a not valid;
>> ALTER TABLE notnull_chld INHERIT notnull_tbl1;
>> ALTER TABLE notnull_tbl1 VALIDATE CONSTRAINT nn_parent;
>>
>> does mark the constraint as validated in the child, but only in
>> pg_constraint -- pg_attribute continues to be marked as 'i', so if you
>> try to use it for a PK, it fails:
>>
>> alter table notnull_chld add constraint foo primary key (a);
>> ERROR: column "a" of table "notnull_chld" is marked as NOT VALID NOT
>> NULL constrint
>>
>> I thought that was going to be a quick fix, so I tried to do so; since
>> we already have a function 'set_attnotnull', I thought it was the
>> perfect tool to changing attnotnull. However, it's not great, because
>> since that part of the code is already doing the validation, I don't
>> want it to queue the validation again, so the API needs a tweak; I
>> changed it to receiving separately which new value to update attnotnull
>> to, and whether to queue validation. With that change it works
>> correctly, but it is a bit ugly at the callers' side. Maybe it works to
>> pass two booleans instead? Please have a look at whether that can be
>> improved.
>>
>
> I haven't given much thought to improving the API, but I'll look into it
> now. Also,
> I'm considering renaming AdjustNotNullInheritance() since it now also
> checks for invalid NOT NULL constraints. What do you think?
>

I adjusted the set_attnotnull() API and removed the added queue_validation
parameter. Rather, the function start using wqueue input parameter as a
check.
If wqueue is NULL, skip the queue_validation. Attaching patch here, but not
sure how clear it is, in term of understanding the API. Your
thoughts/inputs?

Looking further for AdjustNotNullInheritance() I don't see need of rename
this
API as it's just adding new error check now for an existing NOT NULL
constraint.

JFYI, I can reproduce the failure Ashutosh Bapat reported, while running
the pg_upgrade test through meson commands. I am investigating that
further.

Thanks,
Rushabh Lathia

Attachment Content-Type Size
0004-Adjust-set_attnotnull-API-input-parameters.patch application/octet-stream 3.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Florents Tselai 2025-03-10 11:28:30 Re: encode/decode support for base64url
Previous Message Tomas Vondra 2025-03-10 11:17:58 Re: Changing the state of data checksums in a running cluster