From 5dc229f52e14ba40e6fbf850bcab7a76b6e3648e Mon Sep 17 00:00:00 2001 From: ChangAo Chen Date: Wed, 18 Nov 2026 22:42:50 +0800 Subject: [PATCH v1] Avoid copying MinimalTuple twice in ExecHashSkewTableInsert() --- src/backend/executor/nodeHash.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/backend/executor/nodeHash.c b/src/backend/executor/nodeHash.c index 8825bb6fa23..682dbb002c8 100644 --- a/src/backend/executor/nodeHash.c +++ b/src/backend/executor/nodeHash.c @@ -2629,18 +2629,19 @@ ExecHashSkewTableInsert(HashJoinTable hashtable, uint32 hashvalue, int bucketNumber) { - bool shouldFree; - MinimalTuple tuple = ExecFetchSlotMinimalTuple(slot, &shouldFree); + MinimalTuple tuple; HashJoinTuple hashTuple; int hashTupleSize; + MemoryContext oldcxt; /* Create the HashJoinTuple */ + oldcxt = MemoryContextSwitchTo(hashtable->batchCxt); + tuple = ExecCopySlotMinimalTupleExtra(slot, HJTUPLE_OVERHEAD); + MemoryContextSwitchTo(oldcxt); hashTupleSize = HJTUPLE_OVERHEAD + tuple->t_len; - hashTuple = (HashJoinTuple) MemoryContextAlloc(hashtable->batchCxt, - hashTupleSize); + hashTuple = (HashJoinTuple) ((char *) tuple - HJTUPLE_OVERHEAD); hashTuple->hashvalue = hashvalue; - memcpy(HJTUPLE_MINTUPLE(hashTuple), tuple, tuple->t_len); - HeapTupleHeaderClearMatch(HJTUPLE_MINTUPLE(hashTuple)); + HeapTupleHeaderClearMatch(tuple); /* Push it onto the front of the skew bucket's list */ hashTuple->next.unshared = hashtable->skewBucket[bucketNumber]->tuples; @@ -2659,9 +2660,6 @@ ExecHashSkewTableInsert(HashJoinTable hashtable, /* Check we are not over the total spaceAllowed, either */ if (hashtable->spaceUsed > hashtable->spaceAllowed) ExecHashIncreaseNumBatches(hashtable); - - if (shouldFree) - heap_free_minimal_tuple(tuple); } /* -- 2.56.1