diff options
author | Amit Langote <amitlan@postgresql.org> | 2025-01-31 15:47:15 +0900 |
---|---|---|
committer | Amit Langote <amitlan@postgresql.org> | 2025-01-31 15:47:15 +0900 |
commit | d47cbf474ecbd449a47c8c1b4aaa1874f7698271 (patch) | |
tree | cb3d2daf34ecbdbfd3a691f0560bc680839b753b /src/include/executor/execPartition.h | |
parent | f41d8468ddea34170fe19fdc17b5a247e7d3ac78 (diff) | |
download | postgresql-d47cbf474ecbd449a47c8c1b4aaa1874f7698271.tar.gz postgresql-d47cbf474ecbd449a47c8c1b4aaa1874f7698271.zip |
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 <robertmhaas@gmail.com>
Reviewed-by: Tomas Vondra <tomas@vondra.me>
Discussion: https://postgr.es/m/CA+HiwqFGkMSge6TgC9KQzde0ohpAycLQuV7ooitEEpbKB0O_mg@mail.gmail.com
Diffstat (limited to 'src/include/executor/execPartition.h')
-rw-r--r-- | src/include/executor/execPartition.h | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/include/executor/execPartition.h b/src/include/executor/execPartition.h index 13177831d9f..855fed4fea5 100644 --- a/src/include/executor/execPartition.h +++ b/src/include/executor/execPartition.h @@ -42,6 +42,9 @@ extern void ExecCleanupTupleRouting(ModifyTableState *mtstate, * PartitionedRelPruneInfo (see plannodes.h); though note that here, * subpart_map contains indexes into PartitionPruningData.partrelprunedata[]. * + * partrel Partitioned table Relation; obtained by + * ExecGetRangeTableRelation(estate, rti), where + * rti is PartitionedRelPruneInfo.rtindex. * nparts Length of subplan_map[] and subpart_map[]. * subplan_map Subplan index by partition index, or -1. * subpart_map Subpart index by partition index, or -1. @@ -58,6 +61,7 @@ extern void ExecCleanupTupleRouting(ModifyTableState *mtstate, */ typedef struct PartitionedRelPruningData { + Relation partrel; int nparts; int *subplan_map; int *subpart_map; @@ -90,6 +94,8 @@ typedef struct PartitionPruningData * the clauses being unable to match to any tuple that the subplan could * possibly produce. * + * econtext Standalone ExprContext to evaluate expressions in + * the pruning steps * execparamids Contains paramids of PARAM_EXEC Params found within * any of the partprunedata structs. Pruning must be * done again each time the value of one of these @@ -112,6 +118,7 @@ typedef struct PartitionPruningData */ typedef struct PartitionPruneState { + ExprContext *econtext; Bitmapset *execparamids; Bitmapset *other_subplans; MemoryContext prune_context; @@ -121,11 +128,12 @@ typedef struct PartitionPruneState PartitionPruningData *partprunedata[FLEXIBLE_ARRAY_MEMBER]; } PartitionPruneState; -extern PartitionPruneState *ExecInitPartitionPruning(PlanState *planstate, - int n_total_subplans, - int part_prune_index, - Bitmapset *relids, - Bitmapset **initially_valid_subplans); +extern void ExecDoInitialPruning(EState *estate); +extern PartitionPruneState *ExecInitPartitionExecPruning(PlanState *planstate, + int n_total_subplans, + int part_prune_index, + Bitmapset *relids, + Bitmapset **initially_valid_subplans); extern Bitmapset *ExecFindMatchingSubPlans(PartitionPruneState *prunestate, bool initial_prune); |