/* If the whole aggregate was pushed down, we're done. */
if (! can_push_down_grouping(root, parse, cheapest_path))
{
- Path *path;
+ Path *path, *agg_path;
path = (Path *) create_agg_path(root,
grouped_rel,
&agg_partial_costs,
dNumPartialGroups);
+ /* keep partially aggregated path for the can_sort branch */
+ agg_path = path;
+
path = create_remotesubplan_path(root, path, NULL);
/* Generate paths with both hash and sort second phase. */
dNumGroups));
if (can_sort)
+ {
+ /*
+ * AGG_HASHED aggregate paths are always unsorted, so add
+ * a Sorted node for the final AGG_SORTED step.
+ */
+ path = (Path *) create_sort_path(root,
+ grouped_rel,
+ agg_path,
+ root->group_pathkeys,
+ -1.0);
+
+ path = create_remotesubplan_path(root, path, NULL);
+
add_path(grouped_rel, (Path *)
create_agg_path(root,
grouped_rel,
(List *) parse->havingQual,
&agg_final_costs,
dNumGroups));
+ }
}
}