MCPcopy Create free account
hub / github.com/apache/cloudberry / choose_next_subplan_for_worker

Function choose_next_subplan_for_worker

src/backend/executor/nodeAppend.c:727–846  ·  view source on GitHub ↗

---------------------------------------------------------------- * choose_next_subplan_for_worker * * Choose next subplan for a parallel-aware Append, returning * false if there are no more. * * We start from the first plan and advance through the list; * when we get back to the end, we loop back to the first * partial plan. This assigns the non-partial plans first in * order of d

Source from the content-addressed store, hash-verified

725 * ----------------------------------------------------------------
726 */
727static bool
728choose_next_subplan_for_worker(AppendState *node)
729{
730 ParallelAppendState *pstate = node->as_pstate;
731
732 /* Backward scan is not supported by parallel-aware plans */
733 Assert(ScanDirectionIsForward(node->ps.state->es_direction));
734
735 /* We should never be called when there are no subplans */
736 Assert(node->as_nplans > 0);
737
738 LWLockAcquire(&pstate->pa_lock, LW_EXCLUSIVE);
739
740 /* Mark just-completed subplan as finished. */
741 if (node->as_whichplan != INVALID_SUBPLAN_INDEX)
742 node->as_pstate->pa_finished[node->as_whichplan] = true;
743
744 /*
745 * If we've yet to determine the valid subplans then do so now. If
746 * run-time pruning is disabled then the valid subplans will always be set
747 * to all subplans.
748 */
749 else if (node->as_valid_subplans == NULL)
750 {
751 Append *plan = (Append *) node->ps.plan;
752
753 node->as_valid_subplans =
754 ExecFindMatchingSubPlans(node->as_prune_state,
755 node->ps.state,
756 list_length(plan->appendplans),
757 plan->join_prune_paramids);
758 mark_invalid_subplans_as_finished(node);
759 }
760
761 /* If all the plans are already done, we have nothing to do */
762 if (pstate->pa_next_plan == INVALID_SUBPLAN_INDEX)
763 {
764 LWLockRelease(&pstate->pa_lock);
765 return false;
766 }
767
768 /* Save the plan from which we are starting the search. */
769 node->as_whichplan = pstate->pa_next_plan;
770
771 /* Loop until we find a valid subplan to execute. */
772 while (pstate->pa_finished[pstate->pa_next_plan])
773 {
774 int nextplan;
775
776 nextplan = bms_next_member(node->as_valid_subplans,
777 pstate->pa_next_plan);
778 if (nextplan >= 0)
779 {
780 /* Advance to the next valid plan. */
781 pstate->pa_next_plan = nextplan;
782 }
783 else if (node->as_whichplan > node->as_first_partial_plan)
784 {

Callers

nothing calls this directly

Calls 6

LWLockAcquireFunction · 0.85
ExecFindMatchingSubPlansFunction · 0.85
list_lengthFunction · 0.85
LWLockReleaseFunction · 0.85
bms_next_memberFunction · 0.85

Tested by

no test coverage detected