1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-19 13:42:17 +03:00

Create accessor functions for TupleHashEntry.

Refactor for upcoming optimizations.

Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/1cc3b400a0e8eead18ff967436fa9e42c0c14cfb.camel@j-davis.com
This commit is contained in:
Jeff Davis
2025-03-24 22:05:41 -07:00
parent cc721c459d
commit 4d143509cb
6 changed files with 83 additions and 33 deletions

View File

@@ -424,7 +424,9 @@ setop_fill_hash_table(SetOpState *setopstate)
for (;;)
{
TupleTableSlot *outerslot;
TupleHashTable hashtable = setopstate->hashtable;
TupleHashEntryData *entry;
SetOpStatePerGroup pergroup;
bool isnew;
outerslot = ExecProcNode(outerPlan);
@@ -433,20 +435,20 @@ setop_fill_hash_table(SetOpState *setopstate)
have_tuples = true;
/* Find or build hashtable entry for this tuple's group */
entry = LookupTupleHashEntry(setopstate->hashtable,
entry = LookupTupleHashEntry(hashtable,
outerslot,
&isnew, NULL);
pergroup = TupleHashEntryGetAdditional(hashtable, 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);
@@ -465,6 +467,7 @@ setop_fill_hash_table(SetOpState *setopstate)
for (;;)
{
TupleTableSlot *innerslot;
TupleHashTable hashtable = setopstate->hashtable;
TupleHashEntryData *entry;
innerslot = ExecProcNode(innerPlan);
@@ -472,13 +475,17 @@ setop_fill_hash_table(SetOpState *setopstate)
break;
/* For tuples not seen previously, do not make hashtable entry */
entry = LookupTupleHashEntry(setopstate->hashtable,
entry = LookupTupleHashEntry(hashtable,
innerslot,
NULL, NULL);
/* Advance the counts if entry is already present */
if (entry)
((SetOpStatePerGroup) entry->additional)->numRight++;
{
SetOpStatePerGroup pergroup = TupleHashEntryGetAdditional(hashtable, entry);
pergroup->numRight++;
}
/* Must reset expression context after each hashtable lookup */
ResetExprContext(econtext);
@@ -496,7 +503,7 @@ setop_fill_hash_table(SetOpState *setopstate)
static TupleTableSlot *
setop_retrieve_hash_table(SetOpState *setopstate)
{
TupleHashEntryData *entry;
TupleHashEntry entry;
TupleTableSlot *resultTupleSlot;
/*
@@ -509,12 +516,15 @@ setop_retrieve_hash_table(SetOpState *setopstate)
*/
while (!setopstate->setop_done)
{
TupleHashTable hashtable = setopstate->hashtable;
SetOpStatePerGroup pergroup;
CHECK_FOR_INTERRUPTS();
/*
* Find the next entry in the hash table
*/
entry = ScanTupleHashTable(setopstate->hashtable, &setopstate->hashiter);
entry = ScanTupleHashTable(hashtable, &setopstate->hashiter);
if (entry == NULL)
{
/* No more entries in hashtable, so done */
@@ -526,12 +536,13 @@ 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);
pergroup = TupleHashEntryGetAdditional(hashtable, entry);
set_output_count(setopstate, pergroup);
if (setopstate->numOutput > 0)
{
setopstate->numOutput--;
return ExecStoreMinimalTuple(entry->firstTuple,
return ExecStoreMinimalTuple(TupleHashEntryGetTuple(entry),
resultTupleSlot,
false);
}