@@ -133,29 +133,27 @@ ExecInitAppend(Append *node, EState *estate, int eflags)
133
133
{
134
134
PartitionPruneState * prunestate ;
135
135
136
+ /* We may need an expression context to evaluate partition exprs */
136
137
ExecAssignExprContext (estate , & appendstate -> ps );
137
138
138
139
prunestate = ExecSetupPartitionPruneState (& appendstate -> ps ,
139
140
node -> part_prune_infos );
140
141
141
- /*
142
- * When there are external params matching the partition key we may be
143
- * able to prune away Append subplans now.
144
- */
145
- if (!bms_is_empty (prunestate -> extparams ))
142
+ /* Perform an initial partition prune, if required. */
143
+ if (prunestate -> do_initial_prune )
146
144
{
147
- /* Determine which subplans match the external params */
145
+ /* Determine which subplans survive initial pruning */
148
146
validsubplans = ExecFindInitialMatchingSubPlans (prunestate ,
149
147
list_length (node -> appendplans ));
150
148
151
149
/*
152
- * If no subplans match the given parameters then we must handle
153
- * this case in a special way . The problem here is that code in
154
- * explain.c requires an Append to have at least one subplan in
155
- * order for it to properly determine the Vars in that subplan's
156
- * targetlist. We sidestep this issue by just initializing the
157
- * first subplan and setting as_whichplan to NO_MATCHING_SUBPLANS
158
- * to indicate that we don't need to scan any subnodes.
150
+ * The case where no subplans survive pruning must be handled
151
+ * specially . The problem here is that code in explain.c requires
152
+ * an Append to have at least one subplan in order for it to
153
+ * properly determine the Vars in that subplan's targetlist. We
154
+ * sidestep this issue by just initializing the first subplan and
155
+ * setting as_whichplan to NO_MATCHING_SUBPLANS to indicate that
156
+ * we don't really need to scan any subnodes.
159
157
*/
160
158
if (bms_is_empty (validsubplans ))
161
159
{
@@ -175,22 +173,21 @@ ExecInitAppend(Append *node, EState *estate, int eflags)
175
173
}
176
174
177
175
/*
178
- * If there's no exec params then no further pruning can be done, we
179
- * can just set the valid subplans to all remaining subplans .
176
+ * If no runtime pruning is required, we can fill as_valid_subplans
177
+ * immediately, preventing later calls to ExecFindMatchingSubPlans .
180
178
*/
181
- if (bms_is_empty ( prunestate -> execparams ) )
179
+ if (! prunestate -> do_exec_prune )
182
180
appendstate -> as_valid_subplans = bms_add_range (NULL , 0 , nplans - 1 );
183
181
184
182
appendstate -> as_prune_state = prunestate ;
185
-
186
183
}
187
184
else
188
185
{
189
186
nplans = list_length (node -> appendplans );
190
187
191
188
/*
192
189
* When run-time partition pruning is not enabled we can just mark all
193
- * subplans as valid, they must also all be initialized.
190
+ * subplans as valid; they must also all be initialized.
194
191
*/
195
192
appendstate -> as_valid_subplans = validsubplans =
196
193
bms_add_range (NULL , 0 , nplans - 1 );
@@ -341,13 +338,13 @@ ExecReScanAppend(AppendState *node)
341
338
int i ;
342
339
343
340
/*
344
- * If any of the parameters being used for partition pruning have changed,
345
- * then we'd better unset the valid subplans so that they are reselected
346
- * for the new parameter values.
341
+ * If any PARAM_EXEC Params used in pruning expressions have changed, then
342
+ * we'd better unset the valid subplans so that they are reselected for
343
+ * the new parameter values.
347
344
*/
348
345
if (node -> as_prune_state &&
349
346
bms_overlap (node -> ps .chgParam ,
350
- node -> as_prune_state -> execparams ))
347
+ node -> as_prune_state -> execparamids ))
351
348
{
352
349
bms_free (node -> as_valid_subplans );
353
350
node -> as_valid_subplans = NULL ;
@@ -531,9 +528,9 @@ choose_next_subplan_for_leader(AppendState *node)
531
528
node -> as_whichplan = node -> as_nplans - 1 ;
532
529
533
530
/*
534
- * If we've yet to determine the valid subplans for these parameters
535
- * then do so now. If run-time pruning is disabled then the valid
536
- * subplans will always be set to all subplans.
531
+ * If we've yet to determine the valid subplans then do so now. If
532
+ * run-time pruning is disabled then the valid subplans will always be
533
+ * set to all subplans.
537
534
*/
538
535
if (node -> as_valid_subplans == NULL )
539
536
{
@@ -606,9 +603,9 @@ choose_next_subplan_for_worker(AppendState *node)
606
603
node -> as_pstate -> pa_finished [node -> as_whichplan ] = true;
607
604
608
605
/*
609
- * If we've yet to determine the valid subplans for these parameters then
610
- * do so now. If run-time pruning is disabled then the valid subplans
611
- * will always be set to all subplans.
606
+ * If we've yet to determine the valid subplans then do so now. If
607
+ * run-time pruning is disabled then the valid subplans will always be set
608
+ * to all subplans.
612
609
*/
613
610
else if (node -> as_valid_subplans == NULL )
614
611
{
0 commit comments