Save calculated transitionSpace in Agg node.

This will be useful in the upcoming Hash Aggregation work to improve
estimates for hash table sizing.

Discussion: https://postgr.es/m/37091115219dd522fd9ed67333ee8ed1b7e09443.camel%40j-davis.com
This commit is contained in:
Jeff Davis 2020-02-27 10:46:58 -08:00
parent e537aed61d
commit c11cb17dc5
5 changed files with 14 additions and 4 deletions

View File

@ -1644,6 +1644,7 @@ create_unique_plan(PlannerInfo *root, UniquePath *best_path, int flags)
NIL, NIL,
NIL, NIL,
best_path->path.rows, best_path->path.rows,
0,
subplan); subplan);
} }
else else
@ -2096,6 +2097,7 @@ create_agg_plan(PlannerInfo *root, AggPath *best_path)
NIL, NIL,
NIL, NIL,
best_path->numGroups, best_path->numGroups,
best_path->transitionSpace,
subplan); subplan);
copy_generic_path_info(&plan->plan, (Path *) best_path); copy_generic_path_info(&plan->plan, (Path *) best_path);
@ -2257,6 +2259,7 @@ create_groupingsets_plan(PlannerInfo *root, GroupingSetsPath *best_path)
rollup->gsets, rollup->gsets,
NIL, NIL,
rollup->numGroups, rollup->numGroups,
best_path->transitionSpace,
sort_plan); sort_plan);
/* /*
@ -2295,6 +2298,7 @@ create_groupingsets_plan(PlannerInfo *root, GroupingSetsPath *best_path)
rollup->gsets, rollup->gsets,
chain, chain,
rollup->numGroups, rollup->numGroups,
best_path->transitionSpace,
subplan); subplan);
/* Copy cost data from Path to Plan */ /* Copy cost data from Path to Plan */
@ -6192,8 +6196,8 @@ Agg *
make_agg(List *tlist, List *qual, make_agg(List *tlist, List *qual,
AggStrategy aggstrategy, AggSplit aggsplit, AggStrategy aggstrategy, AggSplit aggsplit,
int numGroupCols, AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations, int numGroupCols, AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
List *groupingSets, List *chain, List *groupingSets, List *chain, double dNumGroups,
double dNumGroups, Plan *lefttree) Size transitionSpace, Plan *lefttree)
{ {
Agg *node = makeNode(Agg); Agg *node = makeNode(Agg);
Plan *plan = &node->plan; Plan *plan = &node->plan;
@ -6209,6 +6213,7 @@ make_agg(List *tlist, List *qual,
node->grpOperators = grpOperators; node->grpOperators = grpOperators;
node->grpCollations = grpCollations; node->grpCollations = grpCollations;
node->numGroups = numGroups; node->numGroups = numGroups;
node->transitionSpace = transitionSpace;
node->aggParams = NULL; /* SS_finalize_plan() will fill this */ node->aggParams = NULL; /* SS_finalize_plan() will fill this */
node->groupingSets = groupingSets; node->groupingSets = groupingSets;
node->chain = chain; node->chain = chain;

View File

@ -2949,6 +2949,7 @@ create_agg_path(PlannerInfo *root,
pathnode->aggstrategy = aggstrategy; pathnode->aggstrategy = aggstrategy;
pathnode->aggsplit = aggsplit; pathnode->aggsplit = aggsplit;
pathnode->numGroups = numGroups; pathnode->numGroups = numGroups;
pathnode->transitionSpace = aggcosts ? aggcosts->transitionSpace : 0;
pathnode->groupClause = groupClause; pathnode->groupClause = groupClause;
pathnode->qual = qual; pathnode->qual = qual;
@ -3036,6 +3037,7 @@ create_groupingsets_path(PlannerInfo *root,
pathnode->aggstrategy = aggstrategy; pathnode->aggstrategy = aggstrategy;
pathnode->rollups = rollups; pathnode->rollups = rollups;
pathnode->qual = having_qual; pathnode->qual = having_qual;
pathnode->transitionSpace = agg_costs ? agg_costs->transitionSpace : 0;
Assert(rollups != NIL); Assert(rollups != NIL);
Assert(aggstrategy != AGG_PLAIN || list_length(rollups) == 1); Assert(aggstrategy != AGG_PLAIN || list_length(rollups) == 1);

View File

@ -1663,6 +1663,7 @@ typedef struct AggPath
AggStrategy aggstrategy; /* basic strategy, see nodes.h */ AggStrategy aggstrategy; /* basic strategy, see nodes.h */
AggSplit aggsplit; /* agg-splitting mode, see nodes.h */ AggSplit aggsplit; /* agg-splitting mode, see nodes.h */
double numGroups; /* estimated number of groups in input */ double numGroups; /* estimated number of groups in input */
Size transitionSpace; /* for pass-by-ref transition data */
List *groupClause; /* a list of SortGroupClause's */ List *groupClause; /* a list of SortGroupClause's */
List *qual; /* quals (HAVING quals), if any */ List *qual; /* quals (HAVING quals), if any */
} AggPath; } AggPath;
@ -1700,6 +1701,7 @@ typedef struct GroupingSetsPath
AggStrategy aggstrategy; /* basic strategy */ AggStrategy aggstrategy; /* basic strategy */
List *rollups; /* list of RollupData */ List *rollups; /* list of RollupData */
List *qual; /* quals (HAVING quals), if any */ List *qual; /* quals (HAVING quals), if any */
Size transitionSpace; /* for pass-by-ref transition data */
} GroupingSetsPath; } GroupingSetsPath;
/* /*

View File

@ -813,6 +813,7 @@ typedef struct Agg
Oid *grpOperators; /* equality operators to compare with */ Oid *grpOperators; /* equality operators to compare with */
Oid *grpCollations; Oid *grpCollations;
long numGroups; /* estimated number of groups in input */ long numGroups; /* estimated number of groups in input */
Size transitionSpace; /* for pass-by-ref transition data */
Bitmapset *aggParams; /* IDs of Params used in Aggref inputs */ Bitmapset *aggParams; /* IDs of Params used in Aggref inputs */
/* Note: planner provides numGroups & aggParams only in HASHED/MIXED case */ /* Note: planner provides numGroups & aggParams only in HASHED/MIXED case */
List *groupingSets; /* grouping sets to use */ List *groupingSets; /* grouping sets to use */

View File

@ -54,8 +54,8 @@ extern Sort *make_sort_from_sortclauses(List *sortcls, Plan *lefttree);
extern Agg *make_agg(List *tlist, List *qual, extern Agg *make_agg(List *tlist, List *qual,
AggStrategy aggstrategy, AggSplit aggsplit, AggStrategy aggstrategy, AggSplit aggsplit,
int numGroupCols, AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations, int numGroupCols, AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
List *groupingSets, List *chain, List *groupingSets, List *chain, double dNumGroups,
double dNumGroups, Plan *lefttree); Size transitionSpace, Plan *lefttree);
extern Limit *make_limit(Plan *lefttree, Node *limitOffset, Node *limitCount); extern Limit *make_limit(Plan *lefttree, Node *limitOffset, Node *limitCount);
/* /*