diff options
author | Andres Freund <andres@anarazel.de> | 2018-11-15 14:26:14 -0800 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2018-11-15 14:31:12 -0800 |
commit | 763f2edd92095b1ca2f4476da073a28505c13820 (patch) | |
tree | b053d30c95bf1ccf8b291462d654e4726624fe29 /src/backend/executor/nodeHash.c | |
parent | 7ac0069fb880b9b64223f104058c82773321851c (diff) | |
download | postgresql-763f2edd92095b1ca2f4476da073a28505c13820.tar.gz postgresql-763f2edd92095b1ca2f4476da073a28505c13820.zip |
Rejigger materializing and fetching a HeapTuple from a slot.
Previously materializing a slot always returned a HeapTuple. As
current work aims to reduce the reliance on HeapTuples (so other
storage systems can work efficiently), that needs to change. Thus
split the tasks of materializing a slot (i.e. making it independent
from the underlying storage / other memory contexts) from fetching a
HeapTuple from the slot. For brevity, allow to fetch a HeapTuple from
a slot and materializing the slot at the same time, controlled by a
parameter.
For now some callers of ExecFetchSlotHeapTuple, with materialize =
true, expect that changes to the heap tuple will be reflected in the
underlying slot. Those places will be adapted in due course, so while
not pretty, that's OK for now.
Also rename ExecFetchSlotTuple to ExecFetchSlotHeapTupleDatum and
ExecFetchSlotTupleDatum to ExecFetchSlotHeapTupleDatum, as it's likely
that future storage methods will need similar methods. There already
is ExecFetchSlotMinimalTuple, so the new names make the naming scheme
more coherent.
Author: Ashutosh Bapat and Andres Freund, with changes by Amit Khandekar
Discussion: https://postgr.es/m/20181105210039.hh4vvi4vwoq5ba2q@alap3.anarazel.de
Diffstat (limited to 'src/backend/executor/nodeHash.c')
-rw-r--r-- | src/backend/executor/nodeHash.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/backend/executor/nodeHash.c b/src/backend/executor/nodeHash.c index a9f812d66b8..5a9f1ea3c55 100644 --- a/src/backend/executor/nodeHash.c +++ b/src/backend/executor/nodeHash.c @@ -1590,7 +1590,8 @@ ExecHashTableInsert(HashJoinTable hashtable, TupleTableSlot *slot, uint32 hashvalue) { - MinimalTuple tuple = ExecFetchSlotMinimalTuple(slot); + bool shouldFree; + MinimalTuple tuple = ExecFetchSlotMinimalTuple(slot, &shouldFree); int bucketno; int batchno; @@ -1664,6 +1665,9 @@ ExecHashTableInsert(HashJoinTable hashtable, hashvalue, &hashtable->innerBatchFile[batchno]); } + + if (shouldFree) + heap_free_minimal_tuple(tuple); } /* @@ -1675,7 +1679,8 @@ ExecParallelHashTableInsert(HashJoinTable hashtable, TupleTableSlot *slot, uint32 hashvalue) { - MinimalTuple tuple = ExecFetchSlotMinimalTuple(slot); + bool shouldFree; + MinimalTuple tuple = ExecFetchSlotMinimalTuple(slot, &shouldFree); dsa_pointer shared; int bucketno; int batchno; @@ -1723,6 +1728,9 @@ retry: tuple); } ++hashtable->batches[batchno].ntuples; + + if (shouldFree) + heap_free_minimal_tuple(tuple); } /* @@ -1736,7 +1744,8 @@ ExecParallelHashTableInsertCurrentBatch(HashJoinTable hashtable, TupleTableSlot *slot, uint32 hashvalue) { - MinimalTuple tuple = ExecFetchSlotMinimalTuple(slot); + bool shouldFree; + MinimalTuple tuple = ExecFetchSlotMinimalTuple(slot, &shouldFree); HashJoinTuple hashTuple; dsa_pointer shared; int batchno; @@ -1752,6 +1761,9 @@ ExecParallelHashTableInsertCurrentBatch(HashJoinTable hashtable, HeapTupleHeaderClearMatch(HJTUPLE_MINTUPLE(hashTuple)); ExecParallelHashPushTuple(&hashtable->buckets.shared[bucketno], hashTuple, shared); + + if (shouldFree) + heap_free_minimal_tuple(tuple); } /* @@ -2391,7 +2403,8 @@ ExecHashSkewTableInsert(HashJoinTable hashtable, uint32 hashvalue, int bucketNumber) { - MinimalTuple tuple = ExecFetchSlotMinimalTuple(slot); + bool shouldFree; + MinimalTuple tuple = ExecFetchSlotMinimalTuple(slot, &shouldFree); HashJoinTuple hashTuple; int hashTupleSize; @@ -2419,6 +2432,9 @@ 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); } /* |