1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Fix costing for parallel aggregation.

The original patch kind of ignored the fact that we were doing something
different from a costing point of view, but nobody noticed.  This patch
fixes that oversight.

David Rowley
This commit is contained in:
Robert Haas
2016-04-12 16:24:55 -04:00
parent 46d73e0d65
commit deb71fa971
3 changed files with 92 additions and 25 deletions

View File

@ -3262,6 +3262,8 @@ create_grouping_paths(PlannerInfo *root,
RelOptInfo *grouped_rel;
PathTarget *partial_grouping_target = NULL;
AggClauseCosts agg_costs;
AggClauseCosts agg_partial_costs; /* parallel only */
AggClauseCosts agg_final_costs; /* parallel only */
Size hashaggtablesize;
double dNumGroups;
double dNumPartialGroups = 0;
@ -3346,8 +3348,10 @@ create_grouping_paths(PlannerInfo *root,
MemSet(&agg_costs, 0, sizeof(AggClauseCosts));
if (parse->hasAggs)
{
count_agg_clauses(root, (Node *) target->exprs, &agg_costs);
count_agg_clauses(root, parse->havingQual, &agg_costs);
count_agg_clauses(root, (Node *) target->exprs, &agg_costs, true,
false, false);
count_agg_clauses(root, parse->havingQual, &agg_costs, true, false,
false);
}
/*
@ -3422,6 +3426,25 @@ create_grouping_paths(PlannerInfo *root,
NIL,
NIL);
/*
* Collect statistics about aggregates for estimating costs of
* performing aggregation in parallel.
*/
MemSet(&agg_partial_costs, 0, sizeof(AggClauseCosts));
MemSet(&agg_final_costs, 0, sizeof(AggClauseCosts));
if (parse->hasAggs)
{
/* partial phase */
count_agg_clauses(root, (Node *) partial_grouping_target->exprs,
&agg_partial_costs, false, false, true);
/* final phase */
count_agg_clauses(root, (Node *) target->exprs, &agg_final_costs,
true, true, true);
count_agg_clauses(root, parse->havingQual, &agg_final_costs, true,
true, true);
}
if (can_sort)
{
/* Checked in set_grouped_rel_consider_parallel() */
@ -3457,7 +3480,7 @@ create_grouping_paths(PlannerInfo *root,
parse->groupClause ? AGG_SORTED : AGG_PLAIN,
parse->groupClause,
NIL,
&agg_costs,
&agg_partial_costs,
dNumPartialGroups,
false,
false,
@ -3482,7 +3505,7 @@ create_grouping_paths(PlannerInfo *root,
hashaggtablesize =
estimate_hashagg_tablesize(cheapest_partial_path,
&agg_costs,
&agg_partial_costs,
dNumPartialGroups);
/*
@ -3499,7 +3522,7 @@ create_grouping_paths(PlannerInfo *root,
AGG_HASHED,
parse->groupClause,
NIL,
&agg_costs,
&agg_partial_costs,
dNumPartialGroups,
false,
false,
@ -3631,7 +3654,7 @@ create_grouping_paths(PlannerInfo *root,
parse->groupClause ? AGG_SORTED : AGG_PLAIN,
parse->groupClause,
(List *) parse->havingQual,
&agg_costs,
&agg_final_costs,
dNumGroups,
true,
true,
@ -3691,7 +3714,7 @@ create_grouping_paths(PlannerInfo *root,
Path *path = (Path *) linitial(grouped_rel->partial_pathlist);
hashaggtablesize = estimate_hashagg_tablesize(path,
&agg_costs,
&agg_final_costs,
dNumGroups);
if (hashaggtablesize < work_mem * 1024L)
@ -3713,7 +3736,7 @@ create_grouping_paths(PlannerInfo *root,
AGG_HASHED,
parse->groupClause,
(List *) parse->havingQual,
&agg_costs,
&agg_final_costs,
dNumGroups,
true,
true,