Perform runtime initial pruning outside ExecInitNode()

This commit builds on the prior change that moved PartitionPruneInfos
out of individual plan nodes into a list in PlannedStmt, making it
possible to initialize PartitionPruneStates without traversing the
plan tree and perform runtime initial pruning before ExecInitNode()
initializes the plan trees.  These tasks are now handled in a new
routine, ExecDoInitialPruning(), which is called by InitPlan()
before calling ExecInitNode() on various plan trees.

ExecDoInitialPruning() performs the initial pruning and saves the
result -- a Bitmapset of indexes for surviving child subnodes -- in
es_part_prune_results, a list in EState.

PartitionPruneStates created for initial pruning are stored in
es_part_prune_states, another list in EState, for later use during
exec pruning. Both lists are parallel to es_part_prune_infos, which
holds the PartitionPruneInfos from PlannedStmt, enabling shared
indexing.

PartitionPruneStates initialized in ExecDoInitialPruning() now
include only the PartitionPruneContexts for initial pruning steps.
Exec pruning contexts are initialized later in
ExecInitPartitionExecPruning() when the parent plan node is
initialized, as the exec pruning step expressions depend on the parent
node's PlanState.

The existing function PartitionPruneFixSubPlanMap() has been
repurposed for this initialization to avoid duplicating a similar
loop structure for finding PartitionedRelPruningData to initialize
exec pruning contexts for.  It has been renamed to
InitExecPruningContexts() to reflect its new primary responsibility.
The original logic to "fix subplan maps" remains intact but is now
encapsulated within the renamed function.

This commit removes two obsolete Asserts in partkey_datum_from_expr().
The ExprContext used for pruning expression evaluation is now
independent of the parent PlanState, making these Asserts unnecessary.

By centralizing pruning logic and decoupling it from the plan
initialization step (ExecInitNode()), this change sets the stage for
future patches that will use the result of initial pruning to
save the overhead of redundant processing for pruned partitions.

Reviewed-by: Robert Haas <robertmh...@gmail.com>
Reviewed-by: Tomas Vondra <to...@vondra.me>
Discussion: 
https://postgr.es/m/ca+hiwqfgkmsge6tgc9kqzde0ohpayclquv7ooiteepbkb0o...@mail.gmail.com

Branch
------
master

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

Modified Files
--------------
src/backend/executor/execMain.c        |  12 ++
src/backend/executor/execPartition.c   | 314 +++++++++++++++++++++++----------
src/backend/executor/nodeAppend.c      |  10 +-
src/backend/executor/nodeMergeAppend.c |  10 +-
src/backend/partitioning/partprune.c   |   7 +-
src/include/executor/execPartition.h   |  18 +-
src/include/nodes/execnodes.h          |   2 +
src/include/nodes/plannodes.h          |  12 +-
8 files changed, 271 insertions(+), 114 deletions(-)

Reply via email to