aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeAgg.c
diff options
context:
space:
mode:
authorJeff Davis <jdavis@postgresql.org>2020-04-03 19:52:16 -0700
committerJeff Davis <jdavis@postgresql.org>2020-04-03 20:07:58 -0700
commit0588ee63aa2d8c5765d086991555cd9acdd4d86f (patch)
tree6992318ae8adc1e241c73f063b55f61203daa136 /src/backend/executor/nodeAgg.c
parent3e0d80fd8d3dd4f999e0d3aa3e591f480d8ad1fd (diff)
downloadpostgresql-0588ee63aa2d8c5765d086991555cd9acdd4d86f.tar.gz
postgresql-0588ee63aa2d8c5765d086991555cd9acdd4d86f.zip
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
Diffstat (limited to 'src/backend/executor/nodeAgg.c')
-rw-r--r--src/backend/executor/nodeAgg.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c
index 4c8c5cfc07a..4e100e5755f 100644
--- a/src/backend/executor/nodeAgg.c
+++ b/src/backend/executor/nodeAgg.c
@@ -298,6 +298,12 @@
#define HASHAGG_MIN_BUCKETS 256
/*
+ * Estimate chunk overhead as a constant 16 bytes. XXX: should this be
+ * improved?
+ */
+#define CHUNKHDRSZ 16
+
+/*
* Track all tapes needed for a HashAgg that spills. We don't know the maximum
* number of tapes needed at the start of the algorithm (because it can
* recurse), so one tape set is allocated and extended as needed for new
@@ -1639,14 +1645,32 @@ find_hash_columns(AggState *aggstate)
* Estimate per-hash-table-entry overhead.
*/
Size
-hash_agg_entry_size(int numAggs, Size tupleWidth, Size transitionSpace)
+hash_agg_entry_size(int numTrans, Size tupleWidth, Size transitionSpace)
{
+ Size tupleChunkSize;
+ Size pergroupChunkSize;
+ Size transitionChunkSize;
+ Size tupleSize = (MAXALIGN(SizeofMinimalTupleHeader) +
+ tupleWidth);
+ Size pergroupSize = numTrans * sizeof(AggStatePerGroupData);
+
+ tupleChunkSize = CHUNKHDRSZ + tupleSize;
+
+ if (pergroupSize > 0)
+ pergroupChunkSize = CHUNKHDRSZ + pergroupSize;
+ else
+ pergroupChunkSize = 0;
+
+ if (transitionSpace > 0)
+ transitionChunkSize = CHUNKHDRSZ + transitionSpace;
+ else
+ transitionChunkSize = 0;
+
return
- MAXALIGN(SizeofMinimalTupleHeader) +
- MAXALIGN(tupleWidth) +
- MAXALIGN(sizeof(TupleHashEntryData) +
- numAggs * sizeof(AggStatePerGroupData)) +
- transitionSpace;
+ sizeof(TupleHashEntryData) +
+ tupleChunkSize +
+ pergroupChunkSize +
+ transitionChunkSize;
}
/*