Skip to content

Commit 0588ee6

Browse files
committed
Include chunk overhead in hash table entry size estimate.
Don't try to be precise about it, just use a constant 16 bytes of chunk overhead. Being smarter would require knowing the memory context where the chunk will be allocated, which is not known by all callers. Discussion: https://postgr.es/m/20200325220936.il3ni2fj2j2b45y5@alap3.anarazel.de
1 parent 3e0d80f commit 0588ee6

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/backend/executor/nodeAgg.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@
297297
/* minimum number of initial hash table buckets */
298298
#define HASHAGG_MIN_BUCKETS 256
299299

300+
/*
301+
* Estimate chunk overhead as a constant 16 bytes. XXX: should this be
302+
* improved?
303+
*/
304+
#define CHUNKHDRSZ 16
305+
300306
/*
301307
* Track all tapes needed for a HashAgg that spills. We don't know the maximum
302308
* number of tapes needed at the start of the algorithm (because it can
@@ -1639,14 +1645,32 @@ find_hash_columns(AggState *aggstate)
16391645
* Estimate per-hash-table-entry overhead.
16401646
*/
16411647
Size
1642-
hash_agg_entry_size(int numAggs, Size tupleWidth, Size transitionSpace)
1648+
hash_agg_entry_size(int numTrans, Size tupleWidth, Size transitionSpace)
16431649
{
1650+
Size tupleChunkSize;
1651+
Size pergroupChunkSize;
1652+
Size transitionChunkSize;
1653+
Size tupleSize = (MAXALIGN(SizeofMinimalTupleHeader) +
1654+
tupleWidth);
1655+
Size pergroupSize = numTrans * sizeof(AggStatePerGroupData);
1656+
1657+
tupleChunkSize = CHUNKHDRSZ + tupleSize;
1658+
1659+
if (pergroupSize > 0)
1660+
pergroupChunkSize = CHUNKHDRSZ + pergroupSize;
1661+
else
1662+
pergroupChunkSize = 0;
1663+
1664+
if (transitionSpace > 0)
1665+
transitionChunkSize = CHUNKHDRSZ + transitionSpace;
1666+
else
1667+
transitionChunkSize = 0;
1668+
16441669
return
1645-
MAXALIGN(SizeofMinimalTupleHeader) +
1646-
MAXALIGN(tupleWidth) +
1647-
MAXALIGN(sizeof(TupleHashEntryData) +
1648-
numAggs * sizeof(AggStatePerGroupData)) +
1649-
transitionSpace;
1670+
sizeof(TupleHashEntryData) +
1671+
tupleChunkSize +
1672+
pergroupChunkSize +
1673+
transitionChunkSize;
16501674
}
16511675

16521676
/*

src/include/executor/nodeAgg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ extern AggState *ExecInitAgg(Agg *node, EState *estate, int eflags);
314314
extern void ExecEndAgg(AggState *node);
315315
extern void ExecReScanAgg(AggState *node);
316316

317-
extern Size hash_agg_entry_size(int numAggs, Size tupleWidth,
317+
extern Size hash_agg_entry_size(int numTrans, Size tupleWidth,
318318
Size transitionSpace);
319319
extern void hash_agg_set_limits(double hashentrysize, uint64 input_groups,
320320
int used_bits, Size *mem_limit,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy