diff options
author | Jeff Davis <jdavis@postgresql.org> | 2025-03-24 22:06:02 -0700 |
---|---|---|
committer | Jeff Davis <jdavis@postgresql.org> | 2025-03-24 22:06:02 -0700 |
commit | 626df47ad9db809dc8f93330175ab95b75914721 (patch) | |
tree | db18183d49021a32b56ba0d42517bbb3f7f416c7 /src/backend/executor/execGrouping.c | |
parent | a0942f441ed651f6345d969b7a8f4774eda1fceb (diff) | |
download | postgresql-626df47ad9db809dc8f93330175ab95b75914721.tar.gz postgresql-626df47ad9db809dc8f93330175ab95b75914721.zip |
Remove 'additional' pointer from TupleHashEntryData.
Reduces memory required for hash aggregation by avoiding an allocation
and a pointer in the TupleHashEntryData structure. That structure is
used for all buckets, whether occupied or not, so the savings is
substantial.
Discussion: https://postgr.es/m/AApHDvpN4v3t_sdz4dvrv1Fx_ZPw=twSnxuTEytRYP7LFz5K9A@mail.gmail.com
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Diffstat (limited to 'src/backend/executor/execGrouping.c')
-rw-r--r-- | src/backend/executor/execGrouping.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/backend/executor/execGrouping.c b/src/backend/executor/execGrouping.c index a9d212aaec6..255bd795361 100644 --- a/src/backend/executor/execGrouping.c +++ b/src/backend/executor/execGrouping.c @@ -485,11 +485,18 @@ LookupTupleHashEntry_internal(TupleHashTable hashtable, TupleTableSlot *slot, MemoryContextSwitchTo(hashtable->tablecxt); - entry->firstTuple = ExecCopySlotMinimalTuple(slot); - if (hashtable->additionalsize > 0) - entry->additional = palloc0(hashtable->additionalsize); - else - entry->additional = NULL; + /* + * Copy the first tuple into the table context, and request + * additionalsize extra bytes before the allocation. + * + * The caller can get a pointer to the additional data with + * TupleHashEntryGetAdditional(), and store arbitrary data there. + * Placing both the tuple and additional data in the same + * allocation avoids the need to store an extra pointer in + * TupleHashEntryData or allocate an additional chunk. + */ + entry->firstTuple = ExecCopySlotMinimalTupleExtra(slot, + hashtable->additionalsize); } } else |