From: Álvaro Herrera <alvherre@kurilemu.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid bogus scans of partitions when validating FKs to partition
Date: Thu, 05 Jun 2025 15:18:31 +0000
Message-ID: <E1uNCMR-000JIG-22@gemulon.postgresql.org> (raw)
Avoid bogus scans of partitions when validating FKs to partitioned tables
Validating an unvalidated foreign key that references a partitioned
table would try to queue validations for each individual partition of
the referenced table, but this is wrong: each individual partition would
not necessarily have all the referenced rows, so errors would be raised.
Avoid doing that. The pg_constraint rows that cause this to happen are
only there to support the action triggers that implement the DELETE/
UPDATE actions of the FK, so no validating scan is necessary.
This was an oversight in commit b663b9436e75.
An equivalent oversight exists for NOT ENFORCED constraints, which is
not fixed in this commit.
Author: Amul Sul <sulamul@gmail.com>
Reported-by: Antonin Houska <ah@cybertec.at>
Reviewed-by: jian he <jian.universality@gmail.com>
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Discussion: https://postgr.es/m/26983.1748418675@localhost
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/cc733ed164c5b57fdf34d16e4cc8e9bbdc171699
Modified Files
--------------
src/backend/commands/tablecmds.c | 51 ++++++++++++++++-------
src/test/regress/expected/foreign_key.out | 68 ++++++++++++++++++++++++-------
src/test/regress/sql/foreign_key.sql | 29 ++++++++++---
3 files changed, 114 insertions(+), 34 deletions(-)
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 validating FKs to partition
In-Reply-To: <E1uNCMR-000JIG-22@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