bool can_hash;
bool can_sort;
bool try_parallel_aggregation;
+ bool try_distributed_aggregation;
ListCell *lc;
try_parallel_aggregation = true;
}
+ /*
+ * The distributed aggregation however works even if there are no partial
+ * paths, and for grouping sets (we need to be able to at least push them
+ * on top of remote subplan).
+ */
+ if (!grouped_rel->consider_parallel)
+ {
+ /* Not even parallel-safe. */
+ try_distributed_aggregation = false;
+ }
+ else if (!parse->hasAggs && parse->groupClause == NIL)
+ {
+ /*
+ * We don't know how to do parallel aggregation unless we have either
+ * some aggregates or a grouping clause.
+ */
+ try_distributed_aggregation = false;
+ }
+ else if (agg_costs->hasNonPartial || agg_costs->hasNonSerial)
+ {
+ /* Insufficient support for partial mode. */
+ try_distributed_aggregation = false;
+ }
+ else
+ {
+ /* Everything looks good. */
+ try_distributed_aggregation = true;
+ }
+
/*
* Before generating paths for grouped_rel, we first generate any possible
* partial paths; that way, later code can easily consider both parallel
* we know the per-node groupings won't overlap. But here we need to be
* more careful.
*/
- if (! try_parallel_aggregation)
+ if (try_distributed_aggregation && (! try_parallel_aggregation))
{
partial_grouping_target = make_partial_grouping_target(root, target);
}
/* Build final XL grouping paths */
- if (can_sort && !(agg_costs->hasNonPartial || agg_costs->hasNonSerial))
+ if (can_sort && try_distributed_aggregation)
{
/*
* Use any available suitably-sorted path as input, and also consider
}
}
- if (can_hash && !(agg_costs->hasNonPartial || agg_costs->hasNonSerial))
+ if (can_hash && try_distributed_aggregation)
{
hashaggtablesize = estimate_hashagg_tablesize(cheapest_path,
agg_costs,