From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Move resolution of AlternativeSubPlan choices to the planner.
Date: Sun, 27 Sep 2020 16:51:51 +0000
Message-ID: <E1kMZtv-0002dh-6I@gemulon.postgresql.org> (raw)
Move resolution of AlternativeSubPlan choices to the planner.
When commit bd3daddaf introduced AlternativeSubPlans, I had some
ambitions towards allowing the choice of subplan to change during
execution. That has not happened, or even been thought about, in the
ensuing twelve years; so it seems like a failed experiment. So let's
rip that out and resolve the choice of subplan at the end of planning
(in setrefs.c) rather than during executor startup. This has a number
of positive benefits:
* Removal of a few hundred lines of executor code, since
AlternativeSubPlans need no longer be supported there.
* Removal of executor-startup overhead (particularly, initialization
of subplans that won't be used).
* Removal of incidental costs of having a larger plan tree, such as
tree-scanning and copying costs in the plancache; not to mention
setrefs.c's own costs of processing the discarded subplans.
* EXPLAIN no longer has to print a weird (and undocumented)
representation of an AlternativeSubPlan choice; it sees only the
subplan actually used. This should mean less confusion for users.
* Since setrefs.c knows which subexpression of a plan node it's
working on at any instant, it's possible to adjust the estimated
number of executions of the subplan based on that. For example,
we should usually estimate more executions of a qual expression
than a targetlist expression. The implementation used here is
pretty simplistic, because we don't want to expend a lot of cycles
on the issue; but it's better than ignoring the point entirely,
as the executor had to.
That last point might possibly result in shifting the choice
between hashed and non-hashed EXISTS subplans in a few cases,
but in general this patch isn't meant to change planner choices.
Since we're doing the resolution so late, it's really impossible
to change any plan choices outside the AlternativeSubPlan itself.
Patch by me; thanks to David Rowley for review.
Discussion: https://postgr.es/m/1992952.1592785225@sss.pgh.pa.us
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/41efb8340877e8ffd0023bb6b2ef22ffd1ca014d
Modified Files
--------------
src/backend/executor/execExpr.c | 17 --
src/backend/executor/execExprInterp.c | 23 --
src/backend/executor/nodeSubplan.c | 80 ------
src/backend/jit/llvm/llvmjit_expr.c | 6 -
src/backend/jit/llvm/llvmjit_types.c | 1 -
src/backend/nodes/outfuncs.c | 1 +
src/backend/optimizer/plan/planner.c | 5 +-
src/backend/optimizer/plan/setrefs.c | 372 +++++++++++++++++++-------
src/backend/optimizer/plan/subselect.c | 46 +++-
src/backend/utils/adt/ruleutils.c | 7 +-
src/include/executor/execExpr.h | 10 -
src/include/executor/nodeSubplan.h | 4 -
src/include/nodes/execnodes.h | 12 -
src/include/nodes/nodes.h | 1 -
src/include/nodes/pathnodes.h | 1 +
src/include/nodes/primnodes.h | 3 +
src/test/regress/expected/insert_conflict.out | 6 +-
src/test/regress/expected/subselect.out | 47 ++++
src/test/regress/expected/updatable_views.out | 48 ++--
src/test/regress/sql/subselect.sql | 17 ++
20 files changed, 412 insertions(+), 295 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Move resolution of AlternativeSubPlan choices to the planner.
In-Reply-To: <E1kMZtv-0002dh-6I@gemulon.postgresql.org>
References: <E1kMZtv-0002dh-6I@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox