postgresql/src
Richard Guo 20efbdffeb Clean up remove_rel_from_query() after self-join elimination commit
The self-join elimination (SJE) commit grafted self-join removal onto
remove_rel_from_query(), which was originally written for left-join
removal only.  This resulted in several issues:

- Comments throughout remove_rel_from_query() still assumed only
  left-join removal, making the code misleading.

- ChangeVarNodesExtended was called on phv->phexpr with subst=-1
  during left-join removal, which is pointless and confusing since any
  surviving PHV shouldn't reference the removed rel.

- phinfo->ph_lateral was adjusted for left-join removal, which is
  unnecessary since the removed relid cannot appear in ph_lateral for
  outer joins.

- The comment about attr_needed reconstruction was in
  remove_rel_from_query(), but the actual rebuild is performed by the
  callers.

- EquivalenceClass processing in remove_rel_from_query() is redundant
  for self-join removal, since the caller (remove_self_join_rel)
  already handles ECs via update_eclasses().

- In remove_self_join_rel(), ChangeVarNodesExtended was called on
  root->processed_groupClause, which contains SortGroupClause nodes
  that have no Var nodes to rewrite.  The accompanying comment
  incorrectly mentioned "HAVING clause".

This patch fixes all these issues, clarifying the separation between
left-join removal and self-join elimination code paths within
remove_rel_from_query().  The resulting code is also better structured
for adding new types of join removal (such as inner-join removal) in
the future.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Reviewed-by: Andrei Lepikhov <lepihov@gmail.com>
Reviewed-by: wenhui qiu <qiuwenhuifx@gmail.com>
Discussion: https://postgr.es/m/CAMbWs48JC4OVqE=3gMB6se2WmRNNfMyFyYxm-09vgpm+Vwe8Hg@mail.gmail.com
2026-04-20 17:00:22 +09:00
..
backend Clean up remove_rel_from_query() after self-join elimination commit 2026-04-20 17:00:22 +09:00
bin Fix incorrect format placeholders 2026-04-20 07:09:13 +02:00
common Fix comments for Korean encodings in encnames.c 2026-04-16 18:17:05 +12:00
fe_utils Rework signal handler infrastructure to pass sender info as argument. 2026-04-15 07:30:34 -04:00
include Change PointerGetDatum() back to a macro 2026-04-17 22:14:40 +03:00
interfaces Rework signal handler infrastructure to pass sender info as argument. 2026-04-15 07:30:34 -04:00
makefiles Add CONCURRENTLY option to REPACK 2026-04-06 21:55:08 +02:00
pl Remove MULE_INTERNAL encoding. 2026-04-08 17:40:06 +12:00
port Rework signal handler infrastructure to pass sender info as argument. 2026-04-15 07:30:34 -04:00
template Switch the semaphore API on Solaris to unnamed POSIX. 2026-03-14 14:10:32 -04:00
test Minor fixes for test_bitmapset.c 2026-04-20 09:58:40 +12:00
timezone Use fallthrough attribute instead of comment 2026-02-19 08:51:12 +01:00
tools Rework signal handler infrastructure to pass sender info as argument. 2026-04-15 07:30:34 -04:00
tutorial Force standard_conforming_strings to always be ON. 2026-01-21 15:08:38 -05:00
.gitignore
DEVELOPERS
Makefile Add CONCURRENTLY option to REPACK 2026-04-06 21:55:08 +02:00
Makefile.global.in Update Unicode data to CLDR 48.2 2026-04-13 11:13:36 +02:00
Makefile.shlib Restore AIX support. 2026-02-23 13:34:22 -05:00
meson.build Update copyright for 2026 2026-01-01 13:24:10 -05:00
nls-global.mk Fix update-po for the PGXS case 2025-10-16 20:21:05 +02:00