mirror of
https://github.com/postgres/postgres.git
synced 2025-07-12 21:01:52 +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:
@ -1713,7 +1713,7 @@ hash_agg_entry_size(int numTrans, Size tupleWidth, Size transitionSpace)
|
||||
transitionChunkSize = 0;
|
||||
|
||||
return
|
||||
sizeof(TupleHashEntryData) +
|
||||
TupleHashEntrySize() +
|
||||
tupleChunkSize +
|
||||
pergroupChunkSize +
|
||||
transitionChunkSize;
|
||||
@ -1954,7 +1954,7 @@ hash_agg_update_metrics(AggState *aggstate, bool from_tape, int npartitions)
|
||||
if (aggstate->hash_ngroups_current > 0)
|
||||
{
|
||||
aggstate->hashentrysize =
|
||||
sizeof(TupleHashEntryData) +
|
||||
TupleHashEntrySize() +
|
||||
(hashkey_mem / (double) aggstate->hash_ngroups_current);
|
||||
}
|
||||
}
|
||||
@ -2055,11 +2055,7 @@ initialize_hash_entry(AggState *aggstate, TupleHashTable hashtable,
|
||||
if (aggstate->numtrans == 0)
|
||||
return;
|
||||
|
||||
pergroup = (AggStatePerGroup)
|
||||
MemoryContextAlloc(hashtable->tablecxt,
|
||||
sizeof(AggStatePerGroupData) * aggstate->numtrans);
|
||||
|
||||
entry->additional = pergroup;
|
||||
pergroup = (AggStatePerGroup) TupleHashEntryGetAdditional(entry);
|
||||
|
||||
/*
|
||||
* Initialize aggregates for new tuple group, lookup_hash_entries()
|
||||
@ -2123,7 +2119,7 @@ lookup_hash_entries(AggState *aggstate)
|
||||
{
|
||||
if (isnew)
|
||||
initialize_hash_entry(aggstate, hashtable, entry);
|
||||
pergroup[setno] = entry->additional;
|
||||
pergroup[setno] = TupleHashEntryGetAdditional(entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2681,7 +2677,7 @@ agg_refill_hash_table(AggState *aggstate)
|
||||
{
|
||||
if (isnew)
|
||||
initialize_hash_entry(aggstate, perhash->hashtable, entry);
|
||||
aggstate->hash_pergroup[batch->setno] = entry->additional;
|
||||
aggstate->hash_pergroup[batch->setno] = TupleHashEntryGetAdditional(entry);
|
||||
advance_aggregates(aggstate);
|
||||
}
|
||||
else
|
||||
@ -2773,7 +2769,7 @@ agg_retrieve_hash_table_in_memory(AggState *aggstate)
|
||||
ExprContext *econtext;
|
||||
AggStatePerAgg peragg;
|
||||
AggStatePerGroup pergroup;
|
||||
TupleHashEntryData *entry;
|
||||
TupleHashEntry entry;
|
||||
TupleTableSlot *firstSlot;
|
||||
TupleTableSlot *result;
|
||||
AggStatePerHash perhash;
|
||||
@ -2845,7 +2841,7 @@ agg_retrieve_hash_table_in_memory(AggState *aggstate)
|
||||
* Transform representative tuple back into one with the right
|
||||
* columns.
|
||||
*/
|
||||
ExecStoreMinimalTuple(entry->firstTuple, hashslot, false);
|
||||
ExecStoreMinimalTuple(TupleHashEntryGetTuple(entry), hashslot, false);
|
||||
slot_getallattrs(hashslot);
|
||||
|
||||
ExecClearTuple(firstSlot);
|
||||
@ -2861,7 +2857,7 @@ agg_retrieve_hash_table_in_memory(AggState *aggstate)
|
||||
}
|
||||
ExecStoreVirtualTuple(firstSlot);
|
||||
|
||||
pergroup = (AggStatePerGroup) entry->additional;
|
||||
pergroup = (AggStatePerGroup) TupleHashEntryGetAdditional(entry);
|
||||
|
||||
/*
|
||||
* Use the representative input tuple for any references to
|
||||
|
Reference in New Issue
Block a user