agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix FOR PORTION OF for inheritance children
Date: Mon, 08 Jun 2026 17:32:30 +0000
Message-ID: <E1wWdpu-001cyM-2y@gemulon.postgresql.org> (raw)
Fix FOR PORTION OF for inheritance children
ExecForPortionOfLeftovers() assumed that any result relation with
ri_RootResultRelInfo should reinsert temporal leftovers through the
root relation. That is correct for partitioned tables, where tuple
routing is needed, but it is wrong for plain inheritance.
When UPDATE/DELETE FOR PORTION OF is run on an inheritance parent and
a child row is split, the leftover rows must be inserted back into the
child relation. Reinserting through the parent can lose child-only
columns and place the leftover rows in the wrong relation.
Fix this by distinguishing partitioned-table routing from plain
inheritance. For partitioned tables, keep using the root leftover
slot and insert through the root relation. For plain inheritance
children, use a leftover slot matching the child relation and insert
directly into the child. Also keep translating the application-time
column attno for child relations, so multiple-inheritance cases with
different attribute numbers are handled correctly.
Added an ExecInitForPortionOf function to set up the ForPortionOfState
for each child table, which keeps most of these decisions localized
instead of spread out through ExecForPortionOfLeftovers. Incidentally
clarified a comment about the rangetype stored in ForPortionOfState.
Add regression tests for UPDATE and DELETE FOR PORTION OF on
inheritance children, including a multiple-inheritance case where the
range column has a different attnum in the parent and child.
Author: jian he <jian.universality@gmail.com>
Co-authored-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Paul A. Jungwirth <pj@illuminatedcomputing.com>
Discussion: https://www.postgresql.org/message-id/flat/4245F94D-84F1-4E05-BF81-C458A6CF9901%40gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/7d13b03a2e677b78047cf537e519166dcbafa117
Modified Files
--------------
src/backend/executor/nodeModifyTable.c | 158 ++++++++++++++++++---------
src/include/nodes/execnodes.h | 3 +-
src/test/regress/expected/for_portion_of.out | 158 +++++++++++++++++++++++++++
src/test/regress/sql/for_portion_of.sql | 85 ++++++++++++++
4 files changed, 353 insertions(+), 51 deletions(-)
Message-ID: <E1wWdpu-001cyM-2y@gemulon.postgresql.org>
Permalink: ../E1wWdpu-001cyM-2y@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1wWdpu-001cyM-2y@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: peter@eisentraut.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Fix FOR PORTION OF for inheritance children
In-Reply-To: <E1wWdpu-001cyM-2y@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox