pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Álvaro Herrera <alvherre@kurilemu.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid bogus scans of partitions when marking FKs enforced
Date: Thu, 05 Jun 2025 16:39:32 +0000
Message-ID: <E1uNDcq-000JlB-0R@gemulon.postgresql.org> (raw)

Avoid bogus scans of partitions when marking FKs enforced

Similar to commit cc733ed164c5: when an unenforced foreign key that
references a partitioned table is altered to be enforced, we scan
the constrained table based on each partition on the referenced
partitioned table.  This is bogus and likely to cause the ALTER TABLE to
fail: we must only scan the constrained table as pointing to the
top-level partitioned table.  Oversight in commit eec0040c4bcd.  Fix by
eliding those scans.

Author: Amul Sul <sulamul@gmail.com>
Reported-by: jian he <jian.universality@gmail.com>
Discussion: https://postgr.es/m/CACJufxF1e_gPOLtsDoaE4VCgQPC8KZW_kPAjPR5Rvv4Ew=fb2A@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e6f98d8848f1803fda32011998c786a1bf4eb87c

Modified Files
--------------
src/backend/commands/tablecmds.c          |  7 ++++--
src/test/regress/expected/foreign_key.out | 41 +++++++++++++++++++------------
src/test/regress/sql/foreign_key.sql      | 11 ++++++---
3 files changed, 37 insertions(+), 22 deletions(-)



view thread (2+ messages)

Message-ID: <E1uNDcq-000JlB-0R@gemulon.postgresql.org>
Permalink:  ../E1uNDcq-000JlB-0R@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1uNDcq-000JlB-0R@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: alvherre@kurilemu.de, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Avoid bogus scans of partitions when marking FKs enforced
  In-Reply-To: <E1uNDcq-000JlB-0R@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox