Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 626df47

Browse files
committed
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 <[email protected]>
1 parent a0942f4 commit 626df47

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/backend/executor/execGrouping.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,18 @@ LookupTupleHashEntry_internal(TupleHashTable hashtable, TupleTableSlot *slot,
485485

486486
MemoryContextSwitchTo(hashtable->tablecxt);
487487

488-
entry->firstTuple = ExecCopySlotMinimalTuple(slot);
489-
if (hashtable->additionalsize > 0)
490-
entry->additional = palloc0(hashtable->additionalsize);
491-
else
492-
entry->additional = NULL;
488+
/*
489+
* Copy the first tuple into the table context, and request
490+
* additionalsize extra bytes before the allocation.
491+
*
492+
* The caller can get a pointer to the additional data with
493+
* TupleHashEntryGetAdditional(), and store arbitrary data there.
494+
* Placing both the tuple and additional data in the same
495+
* allocation avoids the need to store an extra pointer in
496+
* TupleHashEntryData or allocate an additional chunk.
497+
*/
498+
entry->firstTuple = ExecCopySlotMinimalTupleExtra(slot,
499+
hashtable->additionalsize);
493500
}
494501
}
495502
else

src/include/executor/executor.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,10 @@ TupleHashEntryGetTuple(TupleHashEntry entry)
188188
static inline void *
189189
TupleHashEntryGetAdditional(TupleHashTable hashtable, TupleHashEntry entry)
190190
{
191-
return entry->additional;
191+
if (hashtable->additionalsize > 0)
192+
return (char *) entry->firstTuple - hashtable->additionalsize;
193+
else
194+
return NULL;
192195
}
193196
#endif
194197

src/include/nodes/execnodes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,6 @@ typedef struct TupleHashTableData *TupleHashTable;
840840
typedef struct TupleHashEntryData
841841
{
842842
MinimalTuple firstTuple; /* copy of first tuple in this group */
843-
void *additional; /* user data */
844843
uint32 status; /* hash status */
845844
uint32 hash; /* hash value (cached) */
846845
} TupleHashEntryData;

0 commit comments

Comments
 (0)