appendstate->as_whichplan =
appendstate->ps.plan->parallel_aware ? INVALID_SUBPLAN_INDEX : 0;
- /* If parallel-aware, this will be overridden later. */
+ /* For parallel query, this will be overridden later. */
appendstate->choose_next_subplan = choose_next_subplan_locally;
return appendstate;
{
int whichplan = node->as_whichplan;
- /* We should never see INVALID_SUBPLAN_INDEX in this case. */
- Assert(whichplan >= 0 && whichplan <= node->as_nplans);
-
if (ScanDirectionIsForward(node->ps.state->es_direction))
{
- if (whichplan >= node->as_nplans - 1)
- return false;
- node->as_whichplan++;
+ /*
+ * We won't normally see INVALID_SUBPLAN_INDEX in this case, but we
+ * might if a plan intended to be run in parallel ends up being run
+ * serially.
+ */
+ if (whichplan == INVALID_SUBPLAN_INDEX)
+ node->as_whichplan = 0;
+ else
+ {
+ if (whichplan >= node->as_nplans - 1)
+ return false;
+ node->as_whichplan++;
+ }
}
else
{
(1 row)
reset enable_parallel_append;
+-- Parallel Append that runs serially
+create or replace function foobar() returns setof text as
+$$ select 'foo'::varchar union all select 'bar'::varchar $$
+language sql stable;
+select foobar() order by 1;
+ foobar
+--------
+ bar
+ foo
+(2 rows)
+
-- test with leader participation disabled
set parallel_leader_participation = off;
explain (costs off)
select round(avg(aa)), sum(aa) from a_star a4;
reset enable_parallel_append;
+-- Parallel Append that runs serially
+create or replace function foobar() returns setof text as
+$$ select 'foo'::varchar union all select 'bar'::varchar $$
+language sql stable;
+select foobar() order by 1;
+
-- test with leader participation disabled
set parallel_leader_participation = off;
explain (costs off)