Re: Support for NO INHERIT to INHERIT state change with named NOT NULL constraints

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Suraj Kharage <suraj(dot)kharage(at)enterprisedb(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Support for NO INHERIT to INHERIT state change with named NOT NULL constraints
Date: 2024-11-25 20:41:28
Message-ID: CA+Tgmoa-T_rfhxVwD0-MZ0ZikdKE=zSK8EKsVPHoE-6OXik9cA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Nov 19, 2024 at 8:22 AM jian he <jian(dot)universality(at)gmail(dot)com> wrote:
> current status:
> drop table if exists idxpart,idxpart0,idxpart1 cascade;
> create table idxpart (a int not null) partition by list (a);
> create table idxpart0 (a int constraint foo not null no inherit);
>
> alter table idxpart attach partition idxpart0 for values in (0,1);
> ERROR: constraint "foo" conflicts with non-inherited constraint on
> child table "idxpart0"
>
> to make it attach to the partition, we need to drop and recreate the
> not-null constraint "foo".
> that would be very expensive, since recreate, we need to revalidate
> the previous row is not null or not.

In a simple implementation of ALTER TABLE this would be true, but I
don't see why it should need to be true in ours. It should be possible
to notice that there's an existing NOT NULL constraint and use that as
evidence that the new one can be added without needing to revalidate
the table contents. ALTER TABLE does similar things already. For
instance, TryReuseIndex() can attempt to attach an existing index file
to a new index definition without rebuilding it; TryReuseForeignKey
can attempt to re-add a foreign key constraint without needing to
revalidate it. But even more to the point, ATAddCheckNNConstraint and
MergeWithExistingConstraint know about merging a newly-added
constraint with a preexisting one without needing to revalidate the
table.

--
Robert Haas
EDB: http://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2024-11-25 20:44:00 Re: Planner picks n² query plan when available
Previous Message Masahiko Sawada 2024-11-25 20:11:55 Re: UUID v7