Re: UPDATE run check constraints for affected columns only

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: UPDATE run check constraints for affected columns only
Date: 2026-03-06 02:17:35
Message-ID: CACJufxFSedy4S_dpNg_cK3z49d72sLtrUvARriMmUpCMUzxuvg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hi.

We cache ri_CheckConstraintExprs in ExecConstraints and must initialize them all
if different actions like INSERT and UPDATE, happen together in a query.
Both INSERT and UPDATE need to use these ri_CheckConstraintExprs.
Invoke INSERT AND UPDATE together can happen within MERGE command. We confirm
it's a MERGE operation by checking that resultRelInfo->ri_MergeActions is not
NIL. See ExecMergeNotMatched and ExecMergeMatched.

For cross-partition updates (ExecCrossPartitionUpdate), the operation splits
into an INSERT and DELETE, we can treat it as a single action.

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

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2026-03-06 02:40:53 Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access)
Previous Message Jelte Fennema-Nio 2026-03-06 02:12:49 Re: Don't use the deprecated and insecure PQcancel in our frontend tools anymore