@ -157,7 +157,10 @@ ExecInitAppend(Append *node, EState *estate, int eflags)
* later calls to ExecFindMatchingSubPlans .
* later calls to ExecFindMatchingSubPlans .
*/
*/
if ( ! prunestate - > do_exec_prune & & nplans > 0 )
if ( ! prunestate - > do_exec_prune & & nplans > 0 )
{
appendstate - > as_valid_subplans = bms_add_range ( NULL , 0 , nplans - 1 ) ;
appendstate - > as_valid_subplans = bms_add_range ( NULL , 0 , nplans - 1 ) ;
appendstate - > as_valid_subplans_identified = true ;
}
}
}
else
else
{
{
@ -170,6 +173,7 @@ ExecInitAppend(Append *node, EState *estate, int eflags)
Assert ( nplans > 0 ) ;
Assert ( nplans > 0 ) ;
appendstate - > as_valid_subplans = validsubplans =
appendstate - > as_valid_subplans = validsubplans =
bms_add_range ( NULL , 0 , nplans - 1 ) ;
bms_add_range ( NULL , 0 , nplans - 1 ) ;
appendstate - > as_valid_subplans_identified = true ;
appendstate - > as_prune_state = NULL ;
appendstate - > as_prune_state = NULL ;
}
}
@ -259,7 +263,7 @@ ExecInitAppend(Append *node, EState *estate, int eflags)
appendstate - > as_asyncresults = ( TupleTableSlot * * )
appendstate - > as_asyncresults = ( TupleTableSlot * * )
palloc0 ( nasyncplans * sizeof ( TupleTableSlot * ) ) ;
palloc0 ( nasyncplans * sizeof ( TupleTableSlot * ) ) ;
if ( appendstate - > as_valid_subplans ! = NULL )
if ( appendstate - > as_valid_subplans_identified )
classify_matching_subplans ( appendstate ) ;
classify_matching_subplans ( appendstate ) ;
}
}
@ -414,14 +418,12 @@ ExecReScanAppend(AppendState *node)
bms_overlap ( node - > ps . chgParam ,
bms_overlap ( node - > ps . chgParam ,
node - > as_prune_state - > execparamids ) )
node - > as_prune_state - > execparamids ) )
{
{
node - > as_valid_subplans_identified = false ;
bms_free ( node - > as_valid_subplans ) ;
bms_free ( node - > as_valid_subplans ) ;
node - > as_valid_subplans = NULL ;
node - > as_valid_subplans = NULL ;
if ( nasyncplans > 0 )
{
bms_free ( node - > as_valid_asyncplans ) ;
bms_free ( node - > as_valid_asyncplans ) ;
node - > as_valid_asyncplans = NULL ;
node - > as_valid_asyncplans = NULL ;
}
}
}
for ( i = 0 ; i < node - > as_nplans ; i + + )
for ( i = 0 ; i < node - > as_nplans ; i + + )
{
{
@ -574,11 +576,14 @@ choose_next_subplan_locally(AppendState *node)
if ( node - > as_nasyncplans > 0 )
if ( node - > as_nasyncplans > 0 )
{
{
/* We'd have filled as_valid_subplans already */
/* We'd have filled as_valid_subplans already */
Assert ( node - > as_valid_subplans ) ;
Assert ( node - > as_valid_subplans_identified ) ;
}
}
else if ( node - > as_valid_subplans = = NULL )
else if ( ! node - > as_valid_subplans_identified )
{
node - > as_valid_subplans =
node - > as_valid_subplans =
ExecFindMatchingSubPlans ( node - > as_prune_state , false ) ;
ExecFindMatchingSubPlans ( node - > as_prune_state , false ) ;
node - > as_valid_subplans_identified = true ;
}
whichplan = - 1 ;
whichplan = - 1 ;
}
}
@ -640,10 +645,11 @@ choose_next_subplan_for_leader(AppendState *node)
* run - time pruning is disabled then the valid subplans will always be
* run - time pruning is disabled then the valid subplans will always be
* set to all subplans .
* set to all subplans .
*/
*/
if ( node - > as_valid_subplans = = NULL )
if ( ! node - > as_valid_subplans_identified )
{
{
node - > as_valid_subplans =
node - > as_valid_subplans =
ExecFindMatchingSubPlans ( node - > as_prune_state , false ) ;
ExecFindMatchingSubPlans ( node - > as_prune_state , false ) ;
node - > as_valid_subplans_identified = true ;
/*
/*
* Mark each invalid plan as finished to allow the loop below to
* Mark each invalid plan as finished to allow the loop below to
@ -715,10 +721,12 @@ choose_next_subplan_for_worker(AppendState *node)
* run - time pruning is disabled then the valid subplans will always be set
* run - time pruning is disabled then the valid subplans will always be set
* to all subplans .
* to all subplans .
*/
*/
else if ( node - > as_valid_subplans = = NULL )
else if ( ! node - > as_valid_subplans_identified )
{
{
node - > as_valid_subplans =
node - > as_valid_subplans =
ExecFindMatchingSubPlans ( node - > as_prune_state , false ) ;
ExecFindMatchingSubPlans ( node - > as_prune_state , false ) ;
node - > as_valid_subplans_identified = true ;
mark_invalid_subplans_as_finished ( node ) ;
mark_invalid_subplans_as_finished ( node ) ;
}
}
@ -866,10 +874,11 @@ ExecAppendAsyncBegin(AppendState *node)
Assert ( node - > as_nasyncplans > 0 ) ;
Assert ( node - > as_nasyncplans > 0 ) ;
/* If we've yet to determine the valid subplans then do so now. */
/* If we've yet to determine the valid subplans then do so now. */
if ( node - > as_valid_subplans = = NULL )
if ( ! node - > as_valid_subplans_identified )
{
{
node - > as_valid_subplans =
node - > as_valid_subplans =
ExecFindMatchingSubPlans ( node - > as_prune_state , false ) ;
ExecFindMatchingSubPlans ( node - > as_prune_state , false ) ;
node - > as_valid_subplans_identified = true ;
classify_matching_subplans ( node ) ;
classify_matching_subplans ( node ) ;
}
}
@ -1143,6 +1152,7 @@ classify_matching_subplans(AppendState *node)
{
{
Bitmapset * valid_asyncplans ;
Bitmapset * valid_asyncplans ;
Assert ( node - > as_valid_subplans_identified ) ;
Assert ( node - > as_valid_asyncplans = = NULL ) ;
Assert ( node - > as_valid_asyncplans = = NULL ) ;
/* Nothing to do if there are no valid subplans. */
/* Nothing to do if there are no valid subplans. */
@ -1161,8 +1171,7 @@ classify_matching_subplans(AppendState *node)
}
}
/* Get valid async subplans. */
/* Get valid async subplans. */
valid_asyncplans = bms_copy ( node - > as_asyncplans ) ;
valid_asyncplans = bms_intersect ( node - > as_asyncplans ,
valid_asyncplans = bms_int_members ( valid_asyncplans ,
node - > as_valid_subplans ) ;
node - > as_valid_subplans ) ;
/* Adjust the valid subplans to contain sync subplans only. */
/* Adjust the valid subplans to contain sync subplans only. */