pgsql: Keep track of what RTIs a Result node is scanning.

From: Robert Haas <rhaas(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Keep track of what RTIs a Result node is scanning.
Date: 2025-09-23 13:21:41
Message-ID: E1v12xh-0026S5-0Y@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Keep track of what RTIs a Result node is scanning.

Result nodes now include an RTI set, which is only non-NULL when they
have no subplan, and is taken from the relid set of the RelOptInfo that
the Result is generating. ExplainPreScanNode now takes notice of these
RTIs, which means that a few things get schema-qualified in the
regression tests that previously did not. This makes the output more
consistent between cases where some part of the plan tree is replaced by
a Result node and those where this does not happen.

Likewise, pg_overexplain's EXPLAIN (RANGE_TABLE) now displays the RTIs
stored in a Result node just as it already does for other RTI-bearing
node types.

Result nodes also now include a result_reason, which tells us something
about why the Result node was inserted. Using that information, EXPLAIN
now emits, where relevant, a "Replaces" line describing the origin of
a Result node.

The purpose of these changes is to allow code that inspects a Plan
tree to understand the origin of Result nodes that appear therein.

Discussion: http://postgr.es/m/CA+TgmoYeUZePZWLsSO+1FAN7UPePT_RMEZBKkqYBJVCF1s60=w@mail.gmail.com
Reviewed-by: Alexandra Wang <alexandra(dot)wang(dot)oss(at)gmail(dot)com>
Reviewed-by: Richard Guo <guofenglinux(at)gmail(dot)com>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Reviewed-by: Junwang Zhao <zhjwpku(at)gmail(dot)com>

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f2bae51dfd5b2edc460c86071c577a45a1acbfd7

Modified Files
--------------
contrib/file_fdw/expected/file_fdw.out | 1 +
contrib/pg_overexplain/expected/pg_overexplain.out | 6 +-
contrib/pg_overexplain/pg_overexplain.c | 12 ++
contrib/postgres_fdw/expected/postgres_fdw.out | 9 +-
src/backend/commands/explain.c | 102 +++++++++++++++
src/backend/optimizer/plan/createplan.c | 117 +++++++++++------
src/backend/optimizer/plan/setrefs.c | 2 +
src/include/nodes/plannodes.h | 22 ++++
src/test/regress/expected/aggregates.out | 51 +++++---
src/test/regress/expected/case.out | 21 +--
src/test/regress/expected/explain.out | 8 ++
src/test/regress/expected/generated_virtual.out | 25 ++--
src/test/regress/expected/groupingsets.out | 3 +-
src/test/regress/expected/inherit.out | 28 ++--
src/test/regress/expected/join.out | 143 ++++++++++++---------
src/test/regress/expected/merge.out | 3 +-
src/test/regress/expected/partition_aggregate.out | 21 +--
src/test/regress/expected/partition_join.out | 35 ++---
src/test/regress/expected/partition_prune.out | 141 +++++++++++---------
src/test/regress/expected/predicate.out | 33 +++--
src/test/regress/expected/rowsecurity.out | 13 +-
src/test/regress/expected/rowtypes.out | 6 +-
src/test/regress/expected/select.out | 7 +-
src/test/regress/expected/subselect.out | 17 ++-
src/test/regress/expected/tsrf.out | 6 +-
src/test/regress/sql/explain.sql | 1 +
src/tools/pgindent/typedefs.list | 1 +
27 files changed, 567 insertions(+), 267 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message noreply 2025-09-23 20:47:02 pgsql: Tag refs/tags/REL_18_0 was created
Previous Message Tom Lane 2025-09-22 20:13:29 pgsql: Stamp 18.0.