Give subplans names that are known while planning that subplan.
authorRobert Haas <rhaas@postgresql.org>
Thu, 5 Dec 2024 20:19:17 +0000 (15:19 -0500)
committerRobert Haas <rhaas@postgresql.org>
Mon, 19 May 2025 15:02:50 +0000 (11:02 -0400)
commit624854b1dfec7f6c603b0275b44e4eaeb69783e0
tree4f53413465eed70b1989851dcb9c05c4ea3425ff
parentf28f3c2498855f8def62d65aed9db70cf3bc4f36
Give subplans names that are known while planning that subplan.

Previously, subplans were shown in EXPLAIN output identified by
a number, like "InitPlan 1", and some were identified by a name,
like "CTE foo". Now, each subplan gets a name, which for InitPlans
and SubPlans is based on the type of sublink e.g. expr_1 or any_1,
and these names are guaranteed to be unique across the whole plan.

The numerical portion of the name may be different than it was
previously, because InitPlan 1 meant the first subplan that we
finished planning (which happened to be an InitPlan). This number
couldn't be known at the time we began planning that subplan,
because the query planner might recurse into other subplans which
would then be fully planned before finishing the plan at the outer
level. These new subplan names are assigned when we *start* planning
a subplan, which allows extensions that affect planning to know the
name that will ultimately be assigned while planning is still in
progress.

Some subplans aren't shown as subplans in EXPLAIN output. This
happens when the subquery is a FROM-cluse item or a branch of a
set operation, rather than, for example, an expression that will
be transformed into something render as an InitPlan or SubPlan.
These subplans also get unique names, although those names are not
currently shown in the EXPLAIN output. This means that it's now
possible to use unique, human-readable names to refer to any
subplan within a query; only the topmost query level is nameless.
33 files changed:
contrib/postgres_fdw/expected/postgres_fdw.out
src/backend/commands/explain.c
src/backend/optimizer/path/allpaths.c
src/backend/optimizer/plan/planagg.c
src/backend/optimizer/plan/planner.c
src/backend/optimizer/plan/subselect.c
src/backend/optimizer/prep/prepjointree.c
src/backend/optimizer/prep/prepunion.c
src/include/nodes/pathnodes.h
src/include/nodes/primnodes.h
src/include/optimizer/planner.h
src/test/regress/expected/aggregates.out
src/test/regress/expected/create_index.out
src/test/regress/expected/groupingsets.out
src/test/regress/expected/incremental_sort.out
src/test/regress/expected/inherit.out
src/test/regress/expected/insert_conflict.out
src/test/regress/expected/join.out
src/test/regress/expected/join_hash.out
src/test/regress/expected/memoize.out
src/test/regress/expected/merge.out
src/test/regress/expected/partition_prune.out
src/test/regress/expected/portals.out
src/test/regress/expected/returning.out
src/test/regress/expected/rowsecurity.out
src/test/regress/expected/rowtypes.out
src/test/regress/expected/select_parallel.out
src/test/regress/expected/sqljson.out
src/test/regress/expected/subselect.out
src/test/regress/expected/updatable_views.out
src/test/regress/expected/update.out
src/test/regress/expected/window.out
src/test/regress/expected/with.out