1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-29 10:41:53 +03:00

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>
This commit is contained in:
Jeff Davis
2025-03-24 22:06:02 -07:00
parent a0942f441e
commit 626df47ad9
3 changed files with 16 additions and 7 deletions

View File

@ -485,11 +485,18 @@ LookupTupleHashEntry_internal(TupleHashTable hashtable, TupleTableSlot *slot,
MemoryContextSwitchTo(hashtable->tablecxt); MemoryContextSwitchTo(hashtable->tablecxt);
entry->firstTuple = ExecCopySlotMinimalTuple(slot); /*
if (hashtable->additionalsize > 0) * Copy the first tuple into the table context, and request
entry->additional = palloc0(hashtable->additionalsize); * additionalsize extra bytes before the allocation.
else *
entry->additional = NULL; * 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 else

View File

@ -188,7 +188,10 @@ TupleHashEntryGetTuple(TupleHashEntry entry)
static inline void * static inline void *
TupleHashEntryGetAdditional(TupleHashTable hashtable, TupleHashEntry entry) TupleHashEntryGetAdditional(TupleHashTable hashtable, TupleHashEntry entry)
{ {
return entry->additional; if (hashtable->additionalsize > 0)
return (char *) entry->firstTuple - hashtable->additionalsize;
else
return NULL;
} }
#endif #endif

View File

@ -840,7 +840,6 @@ typedef struct TupleHashTableData *TupleHashTable;
typedef struct TupleHashEntryData typedef struct TupleHashEntryData
{ {
MinimalTuple firstTuple; /* copy of first tuple in this group */ MinimalTuple firstTuple; /* copy of first tuple in this group */
void *additional; /* user data */
uint32 status; /* hash status */ uint32 status; /* hash status */
uint32 hash; /* hash value (cached) */ uint32 hash; /* hash value (cached) */
} TupleHashEntryData; } TupleHashEntryData;