Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c11cb17

Browse files
committed
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
1 parent e537aed commit c11cb17

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

src/backend/optimizer/plan/createplan.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,7 @@ create_unique_plan(PlannerInfo *root, UniquePath *best_path, int flags)
16441644
NIL,
16451645
NIL,
16461646
best_path->path.rows,
1647+
0,
16471648
subplan);
16481649
}
16491650
else
@@ -2096,6 +2097,7 @@ create_agg_plan(PlannerInfo *root, AggPath *best_path)
20962097
NIL,
20972098
NIL,
20982099
best_path->numGroups,
2100+
best_path->transitionSpace,
20992101
subplan);
21002102

21012103
copy_generic_path_info(&plan->plan, (Path *) best_path);
@@ -2257,6 +2259,7 @@ create_groupingsets_plan(PlannerInfo *root, GroupingSetsPath *best_path)
22572259
rollup->gsets,
22582260
NIL,
22592261
rollup->numGroups,
2262+
best_path->transitionSpace,
22602263
sort_plan);
22612264

22622265
/*
@@ -2295,6 +2298,7 @@ create_groupingsets_plan(PlannerInfo *root, GroupingSetsPath *best_path)
22952298
rollup->gsets,
22962299
chain,
22972300
rollup->numGroups,
2301+
best_path->transitionSpace,
22982302
subplan);
22992303

23002304
/* Copy cost data from Path to Plan */
@@ -6192,8 +6196,8 @@ Agg *
61926196
make_agg(List *tlist, List *qual,
61936197
AggStrategy aggstrategy, AggSplit aggsplit,
61946198
int numGroupCols, AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
6195-
List *groupingSets, List *chain,
6196-
double dNumGroups, Plan *lefttree)
6199+
List *groupingSets, List *chain, double dNumGroups,
6200+
Size transitionSpace, Plan *lefttree)
61976201
{
61986202
Agg *node = makeNode(Agg);
61996203
Plan *plan = &node->plan;
@@ -6209,6 +6213,7 @@ make_agg(List *tlist, List *qual,
62096213
node->grpOperators = grpOperators;
62106214
node->grpCollations = grpCollations;
62116215
node->numGroups = numGroups;
6216+
node->transitionSpace = transitionSpace;
62126217
node->aggParams = NULL; /* SS_finalize_plan() will fill this */
62136218
node->groupingSets = groupingSets;
62146219
node->chain = chain;

src/backend/optimizer/util/pathnode.c

+2
Original file line numberDiff line numberDiff line change
@@ -2949,6 +2949,7 @@ create_agg_path(PlannerInfo *root,
29492949
pathnode->aggstrategy = aggstrategy;
29502950
pathnode->aggsplit = aggsplit;
29512951
pathnode->numGroups = numGroups;
2952+
pathnode->transitionSpace = aggcosts ? aggcosts->transitionSpace : 0;
29522953
pathnode->groupClause = groupClause;
29532954
pathnode->qual = qual;
29542955

@@ -3036,6 +3037,7 @@ create_groupingsets_path(PlannerInfo *root,
30363037
pathnode->aggstrategy = aggstrategy;
30373038
pathnode->rollups = rollups;
30383039
pathnode->qual = having_qual;
3040+
pathnode->transitionSpace = agg_costs ? agg_costs->transitionSpace : 0;
30393041

30403042
Assert(rollups != NIL);
30413043
Assert(aggstrategy != AGG_PLAIN || list_length(rollups) == 1);

src/include/nodes/pathnodes.h

+2
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,7 @@ typedef struct AggPath
16631663
AggStrategy aggstrategy; /* basic strategy, see nodes.h */
16641664
AggSplit aggsplit; /* agg-splitting mode, see nodes.h */
16651665
double numGroups; /* estimated number of groups in input */
1666+
Size transitionSpace; /* for pass-by-ref transition data */
16661667
List *groupClause; /* a list of SortGroupClause's */
16671668
List *qual; /* quals (HAVING quals), if any */
16681669
} AggPath;
@@ -1700,6 +1701,7 @@ typedef struct GroupingSetsPath
17001701
AggStrategy aggstrategy; /* basic strategy */
17011702
List *rollups; /* list of RollupData */
17021703
List *qual; /* quals (HAVING quals), if any */
1704+
Size transitionSpace; /* for pass-by-ref transition data */
17031705
} GroupingSetsPath;
17041706

17051707
/*

src/include/nodes/plannodes.h

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

src/include/optimizer/planmain.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ extern Sort *make_sort_from_sortclauses(List *sortcls, Plan *lefttree);
5454
extern Agg *make_agg(List *tlist, List *qual,
5555
AggStrategy aggstrategy, AggSplit aggsplit,
5656
int numGroupCols, AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
57-
List *groupingSets, List *chain,
58-
double dNumGroups, Plan *lefttree);
57+
List *groupingSets, List *chain, double dNumGroups,
58+
Size transitionSpace, Plan *lefttree);
5959
extern Limit *make_limit(Plan *lefttree, Node *limitOffset, Node *limitCount);
6060

6161
/*

0 commit comments

Comments
 (0)