diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2022-04-05 11:46:48 +0200 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2022-04-05 11:46:48 +0200 |
commit | 297daa9d43539fbf5fbb3c3a2cca190d0e3da471 (patch) | |
tree | e6d41498060adc3f95958609032263a9771a033d /src/backend/executor/nodeMergeAppend.c | |
parent | 7a43a1fc52d0fefdcb008f2fc460ab46f242da69 (diff) | |
download | postgresql-297daa9d43539fbf5fbb3c3a2cca190d0e3da471.tar.gz postgresql-297daa9d43539fbf5fbb3c3a2cca190d0e3da471.zip |
Refactor and cleanup runtime partition prune code a little
* Move the execution pruning initialization steps that are common
between both ExecInitAppend() and ExecInitMergeAppend() into a new
function ExecInitPartitionPruning() defined in execPartition.c.
Those steps include creation of a PartitionPruneState to be used for
all instances of pruning and determining the minimal set of child
subplans that need to be initialized by performing initial pruning if
needed, and finally adjusting the subplan_map arrays in the
PartitionPruneState to reflect the new set of subplans remaining
after initial pruning if it was indeed performed.
ExecCreatePartitionPruneState() is no longer exported out of
execPartition.c and has been renamed to CreatePartitionPruneState()
as a local sub-routine of ExecInitPartitionPruning().
* Likewise, ExecFindInitialMatchingSubPlans() that was in charge of
performing initial pruning no longer needs to be exported. In fact,
since it would now have the same body as the more generally named
ExecFindMatchingSubPlans(), except differing in the value of
initial_prune passed to the common subroutine
find_matching_subplans_recurse(), it seems better to remove it and add
an initial_prune argument to ExecFindMatchingSubPlans().
* Add an ExprContext field to PartitionPruneContext to remove the
implicit assumption in the runtime pruning code that the ExprContext to
use to compute pruning expressions that need one can always rely on the
PlanState providing it. A future patch will allow runtime pruning (at
least the initial pruning steps) to be performed without the
corresponding PlanState yet having been created, so this will help.
Author: Amit Langote <amitlangote09@gmail.com>
Discussion: https://postgr.es/m/CA+HiwqEYCpEqh2LMDOp9mT+4-QoVe8HgFMKBjntEMCTZLpcCCA@mail.gmail.com
Diffstat (limited to 'src/backend/executor/nodeMergeAppend.c')
-rw-r--r-- | src/backend/executor/nodeMergeAppend.c | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/src/backend/executor/nodeMergeAppend.c b/src/backend/executor/nodeMergeAppend.c index 418f89dea8c..ecf9052e038 100644 --- a/src/backend/executor/nodeMergeAppend.c +++ b/src/backend/executor/nodeMergeAppend.c @@ -86,29 +86,17 @@ ExecInitMergeAppend(MergeAppend *node, EState *estate, int eflags) { PartitionPruneState *prunestate; - /* We may need an expression context to evaluate partition exprs */ - ExecAssignExprContext(estate, &mergestate->ps); - - prunestate = ExecCreatePartitionPruneState(&mergestate->ps, - node->part_prune_info); + /* + * Set up pruning data structure. This also initializes the set of + * subplans to initialize (validsubplans) by taking into account the + * result of performing initial pruning if any. + */ + prunestate = ExecInitPartitionPruning(&mergestate->ps, + list_length(node->mergeplans), + node->part_prune_info, + &validsubplans); mergestate->ms_prune_state = prunestate; - - /* Perform an initial partition prune, if required. */ - if (prunestate->do_initial_prune) - { - /* Determine which subplans survive initial pruning */ - validsubplans = ExecFindInitialMatchingSubPlans(prunestate, - list_length(node->mergeplans)); - - nplans = bms_num_members(validsubplans); - } - else - { - /* We'll need to initialize all subplans */ - nplans = list_length(node->mergeplans); - Assert(nplans > 0); - validsubplans = bms_add_range(NULL, 0, nplans - 1); - } + nplans = bms_num_members(validsubplans); /* * When no run-time pruning is required and there's at least one @@ -230,7 +218,7 @@ ExecMergeAppend(PlanState *pstate) */ if (node->ms_valid_subplans == NULL) node->ms_valid_subplans = - ExecFindMatchingSubPlans(node->ms_prune_state); + ExecFindMatchingSubPlans(node->ms_prune_state, false); /* * First time through: pull the first tuple from each valid subplan, |