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

Commit 7d4395d

Browse files
committed
Refactor hash_agg_entry_size().
Consolidate the calculations for hash table size estimation. This will help with upcoming Hash Aggregation work that will add additional call sites.
1 parent c02fdc9 commit 7d4395d

File tree

4 files changed

+14
-33
lines changed

4 files changed

+14
-33
lines changed

src/backend/executor/nodeAgg.c

+8-15
Original file line numberDiff line numberDiff line change
@@ -1422,24 +1422,17 @@ find_hash_columns(AggState *aggstate)
14221422
}
14231423

14241424
/*
1425-
* Estimate per-hash-table-entry overhead for the planner.
1426-
*
1427-
* Note that the estimate does not include space for pass-by-reference
1428-
* transition data values, nor for the representative tuple of each group.
1429-
* Nor does this account of the target fill-factor and growth policy of the
1430-
* hash table.
1425+
* Estimate per-hash-table-entry overhead.
14311426
*/
14321427
Size
1433-
hash_agg_entry_size(int numAggs)
1428+
hash_agg_entry_size(int numAggs, Size tupleWidth, Size transitionSpace)
14341429
{
1435-
Size entrysize;
1436-
1437-
/* This must match build_hash_table */
1438-
entrysize = sizeof(TupleHashEntryData) +
1439-
numAggs * sizeof(AggStatePerGroupData);
1440-
entrysize = MAXALIGN(entrysize);
1441-
1442-
return entrysize;
1430+
return
1431+
MAXALIGN(SizeofMinimalTupleHeader) +
1432+
MAXALIGN(tupleWidth) +
1433+
MAXALIGN(sizeof(TupleHashEntryData) +
1434+
numAggs * sizeof(AggStatePerGroupData)) +
1435+
transitionSpace;
14431436
}
14441437

14451438
/*

src/backend/optimizer/plan/planner.c

+2-7
Original file line numberDiff line numberDiff line change
@@ -4867,13 +4867,8 @@ create_distinct_paths(PlannerInfo *root,
48674867
allow_hash = false; /* policy-based decision not to hash */
48684868
else
48694869
{
4870-
Size hashentrysize;
4871-
4872-
/* Estimate per-hash-entry space at tuple width... */
4873-
hashentrysize = MAXALIGN(cheapest_input_path->pathtarget->width) +
4874-
MAXALIGN(SizeofMinimalTupleHeader);
4875-
/* plus the per-hash-entry overhead */
4876-
hashentrysize += hash_agg_entry_size(0);
4870+
Size hashentrysize = hash_agg_entry_size(
4871+
0, cheapest_input_path->pathtarget->width, 0);
48774872

48784873
/* Allow hashing only if hashtable is predicted to fit in work_mem */
48794874
allow_hash = (hashentrysize * numDistinctRows <= work_mem * 1024L);

src/backend/utils/adt/selfuncs.c

+2-10
Original file line numberDiff line numberDiff line change
@@ -3526,16 +3526,8 @@ double
35263526
estimate_hashagg_tablesize(Path *path, const AggClauseCosts *agg_costs,
35273527
double dNumGroups)
35283528
{
3529-
Size hashentrysize;
3530-
3531-
/* Estimate per-hash-entry space at tuple width... */
3532-
hashentrysize = MAXALIGN(path->pathtarget->width) +
3533-
MAXALIGN(SizeofMinimalTupleHeader);
3534-
3535-
/* plus space for pass-by-ref transition values... */
3536-
hashentrysize += agg_costs->transitionSpace;
3537-
/* plus the per-hash-entry overhead */
3538-
hashentrysize += hash_agg_entry_size(agg_costs->numAggs);
3529+
Size hashentrysize = hash_agg_entry_size(
3530+
agg_costs->numAggs, path->pathtarget->width, agg_costs->transitionSpace);
35393531

35403532
/*
35413533
* Note that this disregards the effect of fill-factor and growth policy

src/include/executor/nodeAgg.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ extern AggState *ExecInitAgg(Agg *node, EState *estate, int eflags);
309309
extern void ExecEndAgg(AggState *node);
310310
extern void ExecReScanAgg(AggState *node);
311311

312-
extern Size hash_agg_entry_size(int numAggs);
312+
extern Size hash_agg_entry_size(int numAggs, Size tupleWidth,
313+
Size transitionSpace);
313314

314315
#endif /* NODEAGG_H */

0 commit comments

Comments
 (0)