From 4d143509cbfae0207c35abffae7b0e3b4d078349 Mon Sep 17 00:00:00 2001 From: Jeff Davis Date: Mon, 24 Mar 2025 22:05:41 -0700 Subject: Create accessor functions for TupleHashEntry. Refactor for upcoming optimizations. Reviewed-by: David Rowley Discussion: https://postgr.es/m/1cc3b400a0e8eead18ff967436fa9e42c0c14cfb.camel@j-davis.com --- src/backend/executor/nodeSetOp.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'src/backend/executor/nodeSetOp.c') diff --git a/src/backend/executor/nodeSetOp.c b/src/backend/executor/nodeSetOp.c index 5b7ff9c3748..4068481a523 100644 --- a/src/backend/executor/nodeSetOp.c +++ b/src/backend/executor/nodeSetOp.c @@ -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); } -- cgit v1.2.3