Improve RowMark handling during Self-Join Elimination
authorAlexander Korotkov <akorotkov@postgresql.org>
Sun, 24 Aug 2025 00:34:22 +0000 (03:34 +0300)
committerAlexander Korotkov <akorotkov@postgresql.org>
Tue, 26 Aug 2025 10:23:53 +0000 (13:23 +0300)
commit8951941fb8a4d7f239760d7a4cd8fcaeecde13e2
tree32435e79cb55ead235a74c867de67d942395f01b
parent8202b0e83d0928ce9344c31f90cdd4a1e963b568
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@gmail.com>
Reviewed-by: Greg Sabino Mullane <htamfids@gmail.com>
Backpatch-through: 18
src/backend/optimizer/plan/analyzejoins.c
src/backend/optimizer/plan/setrefs.c