diff --git a/src/backend/executor/nodeAppend.c b/src/backend/executor/nodeAppend.c
index 64a17fb032..640269564e 100644
--- a/src/backend/executor/nodeAppend.c
+++ b/src/backend/executor/nodeAppend.c
@@ -481,14 +481,18 @@ choose_next_subplan_for_worker(AppendState *node)
 			/* Advance to next plan. */
 			pstate->pa_next_plan++;
 		}
-		else if (append->first_partial_plan < node->as_nplans)
+		else if (append->first_partial_plan < node->as_nplans &&
+				 node->as_whichplan > append->first_partial_plan)
 		{
 			/* Loop back to first partial plan. */
 			pstate->pa_next_plan = append->first_partial_plan;
 		}
 		else
 		{
-			/* At last plan, no partial plans, arrange to bail out. */
+			/*
+			 * At last plan, and either there are no partial plans or we've
+			 * tried them all.  Arrange to bail out.
+			 */
 			pstate->pa_next_plan = node->as_whichplan;
 		}
 
