pgsql: Improve RowMark handling during Self-Join Elimination

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Improve RowMark handling during Self-Join Elimination
Date: 2025-08-26 10:23:35
Message-ID: E1uqqpz-001k6N-0k@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Improve RowMark handling during Self-Join Elimination

The Self-Join Elimination SJE feature messes up keeping and removing RowMark's
in remove_self_joins_one_group(). That didn't lead to user-level error,
because the planned RowMark is only used to reference a rtable entry in later
execution stages. An RTE entry for keeping and removing relations is
identical and refers to the same relation OID.

To reduce confusion and prevent future issues, this commit cleans up the code
and fixes the incorrect behaviour. Furthermore, it includes sanity checks in
setrefs.c on existing non-null RTE and RelOptInfo entries for each RowMark.

Discussion: https://postgr.es/m/18c6bd6c-6d2a-419a-b0da-dfedef34b585%40gmail.com
Author: Andrei Lepikhov <lepihov(at)gmail(dot)com>
Reviewed-by: Greg Sabino Mullane <htamfids(at)gmail(dot)com>
Backpatch-through: 18

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/5f6f951f88e53630b3ebe9bde762a9612ca6202f

Modified Files
--------------
src/backend/optimizer/plan/analyzejoins.c | 9 ++++++---
src/backend/optimizer/plan/setrefs.c | 4 ++++
2 files changed, 10 insertions(+), 3 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Alexander Korotkov 2025-08-26 10:24:03 pgsql: Refactor variable names in remove_self_joins_one_group()
Previous Message Peter Eisentraut 2025-08-26 09:56:34 pgsql: Raise C requirement to C11