mirror of
https://github.com/postgres/postgres.git
synced 2025-08-19 23:22:23 +03:00
TupleHashTable: store additional data along with tuple.
Previously, the caller needed to allocate the memory and the TupleHashTable would store a pointer to it. That wastes space for the palloc overhead as well as the size of the pointer itself. Now, the TupleHashTable relies on the caller to correctly specify the additionalsize, and allocates that amount of space. The caller can then request a pointer into that space. Discussion: https://postgr.es/m/b9cbf0219a9859dc8d240311643ff4362fd9602c.camel@j-davis.com Reviewed-by: Heikki Linnakangas
This commit is contained in:
@@ -425,6 +425,7 @@ setop_fill_hash_table(SetOpState *setopstate)
|
||||
{
|
||||
TupleTableSlot *outerslot;
|
||||
TupleHashEntryData *entry;
|
||||
SetOpStatePerGroup pergroup;
|
||||
bool isnew;
|
||||
|
||||
outerslot = ExecProcNode(outerPlan);
|
||||
@@ -437,16 +438,16 @@ setop_fill_hash_table(SetOpState *setopstate)
|
||||
outerslot,
|
||||
&isnew, NULL);
|
||||
|
||||
pergroup = TupleHashEntryGetAdditional(entry);
|
||||
/* If new tuple group, initialize counts to zero */
|
||||
if (isnew)
|
||||
{
|
||||
entry->additional = (SetOpStatePerGroup)
|
||||
MemoryContextAllocZero(setopstate->hashtable->tablecxt,
|
||||
sizeof(SetOpStatePerGroupData));
|
||||
pergroup->numLeft = 0;
|
||||
pergroup->numRight = 0;
|
||||
}
|
||||
|
||||
/* Advance the counts */
|
||||
((SetOpStatePerGroup) entry->additional)->numLeft++;
|
||||
pergroup->numLeft++;
|
||||
|
||||
/* Must reset expression context after each hashtable lookup */
|
||||
ResetExprContext(econtext);
|
||||
@@ -478,7 +479,7 @@ setop_fill_hash_table(SetOpState *setopstate)
|
||||
|
||||
/* Advance the counts if entry is already present */
|
||||
if (entry)
|
||||
((SetOpStatePerGroup) entry->additional)->numRight++;
|
||||
((SetOpStatePerGroup) TupleHashEntryGetAdditional(entry))->numRight++;
|
||||
|
||||
/* Must reset expression context after each hashtable lookup */
|
||||
ResetExprContext(econtext);
|
||||
@@ -496,7 +497,7 @@ setop_fill_hash_table(SetOpState *setopstate)
|
||||
static TupleTableSlot *
|
||||
setop_retrieve_hash_table(SetOpState *setopstate)
|
||||
{
|
||||
TupleHashEntryData *entry;
|
||||
TupleHashEntry entry;
|
||||
TupleTableSlot *resultTupleSlot;
|
||||
|
||||
/*
|
||||
@@ -526,12 +527,12 @@ setop_retrieve_hash_table(SetOpState *setopstate)
|
||||
* See if we should emit any copies of this tuple, and if so return
|
||||
* the first copy.
|
||||
*/
|
||||
set_output_count(setopstate, (SetOpStatePerGroup) entry->additional);
|
||||
set_output_count(setopstate, (SetOpStatePerGroup) TupleHashEntryGetAdditional(entry));
|
||||
|
||||
if (setopstate->numOutput > 0)
|
||||
{
|
||||
setopstate->numOutput--;
|
||||
return ExecStoreMinimalTuple(entry->firstTuple,
|
||||
return ExecStoreMinimalTuple(TupleHashEntryGetTuple(entry),
|
||||
resultTupleSlot,
|
||||
false);
|
||||
}
|
||||
|
Reference in New Issue
Block a user