Re: UPDATE run check constraints for affected columns only

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Florin Irion <irionr(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Haritabh Gupta <haritabh1992(at)gmail(dot)com>
Subject: Re: UPDATE run check constraints for affected columns only
Date: 2026-03-07 09:46:23
Message-ID: CACJufxHQ0-Ln0g+1UkStANifbQxueCmL7etCEEi-JQ4CWVkQtw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Mar 7, 2026 at 12:10 AM Florin Irion <irionr(at)gmail(dot)com> wrote:
>
> Hi Jian,
>
> An alternative that preserves the optimization for MERGE UPDATE actions
> would be to follow the existing ri_GeneratedExprsI/ri_GeneratedExprsU
> pattern — split into two separate cached arrays:
>
> ```
> /* array of expr states for checking check constraints */
> ExprState **ri_CheckConstraintExprsI; /* for INSERT */
> ExprState **ri_CheckConstraintExprsU; /* for UPDATE */
> ```

I have given it a try, please see attached v7.
I don’t have a strong preference for either v6 or v7.

> 2. The cross-partition update test comment says "cannot be skipped", but
> cross-partition UPDATE goes through ExecCrossPartitionUpdate which
> does DELETE + INSERT. The constraint check happens via ExecInsert with
> CMD_INSERT on the destination partition, so the optimization was never
> applicable. The test doesn't exercise anything specific to this patch.
>

OK. I kept these tests. I think covering this scenario is useful. Perhaps it
has already been tested elsewhere, but including it here makes the tests more
complete

--
jian
https://www.enterprisedb.com/

Attachment Content-Type Size
v7-0001-skip-unnecessary-check-constraint-verification-for-UPDATE.patch text/x-patch 20.6 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2026-03-07 09:54:27 Re: generic plans and "initial" pruning
Previous Message Jelte Fennema-Nio 2026-03-07 08:41:02 Re: Don't use the deprecated and insecure PQcancel in our frontend tools anymore