Re: Foreign key validation failure in 18beta1

From: Amul Sul <sulamul(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Tender Wang <tndrwang(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Antonin Houska <ah(at)cybertec(dot)at>
Subject: Re: Foreign key validation failure in 18beta1
Date: 2025-05-29 12:12:10
Message-ID: CAAJ_b963jUYc7Wfuz0_ehs96tnT_gYqv1WqhAWwVVip0N5N1hg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, May 29, 2025 at 12:38 PM jian he <jian(dot)universality(at)gmail(dot)com> wrote:
>
> On Wed, May 28, 2025 at 8:38 PM Tender Wang <tndrwang(at)gmail(dot)com> wrote:
> >
> >
> >
> > Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> 于2025年5月28日周三 20:26写道:
> >>
> >> On 2025-May-28, Tender Wang wrote:
> >>
> >> > [...]
> The attached *draft* patch is based on your idea.
>
> The idea is that we only need to conditionally do
> ``tab->constraints = lappend(tab->constraints, newcon);`` within
> QueueFKConstraintValidation.
> but the catalog update needs to be done recursively.

I like this approach, but I don’t think the flag name "recursing" is
appropriate, as the flag is meant to indicate whether we want to
enqueue constraints for validation or not.

Additionally, I noticed that we can skip opening child partitions
inside QueueFKConstraintValidation() when the referencing table is not
partitioned -- that is, when it is the same as the input rel. Based on
that, we can decide whether to queue the validation. However, I am not
sure this optimization is worth the added complexity in the code.

I have tried this in the attached patch (not the final version), with
a brief explanation in the code comments. If we choose to move forward
with this patch, I am happy to refine it and add proper tests.

Regards,
Amul

Attachment Content-Type Size
v3-0001-foreign_key_validation-WIP.patch application/x-patch 4.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Joe Conway 2025-05-29 12:18:21 Re: PG 18 release notes draft committed
Previous Message Alexander Korotkov 2025-05-29 11:59:39 Re: Slot's restart_lsn may point to removed WAL segment after hard restart unexpectedly