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
static inline void *
TupleHashEntryGetAdditional(TupleHashTable hashtable, TupleHashEntry entry)
{
- return entry->additional;
+ if (hashtable->additionalsize > 0)
+ return (char *) entry->firstTuple - hashtable->additionalsize;
+ else
+ return NULL;
}
#endif
typedef struct TupleHashEntryData
{
MinimalTuple firstTuple; /* copy of first tuple in this group */
- void *additional; /* user data */
uint32 status; /* hash status */
uint32 hash; /* hash value (cached) */
} TupleHashEntryData;