* ExecHashSkewTableInsert * * Insert a tuple into the skew hashtable. * * This should generally match up with the current-batch case in * ExecHashTableInsert. */
| 3121 | * ExecHashTableInsert. |
| 3122 | */ |
| 3123 | static void |
| 3124 | ExecHashSkewTableInsert(HashState *hashState, |
| 3125 | HashJoinTable hashtable, |
| 3126 | TupleTableSlot *slot, |
| 3127 | uint32 hashvalue, |
| 3128 | int bucketNumber) |
| 3129 | { |
| 3130 | bool shouldFree; |
| 3131 | MinimalTuple tuple = ExecFetchSlotMinimalTuple(slot, &shouldFree); |
| 3132 | HashJoinTuple hashTuple; |
| 3133 | int hashTupleSize; |
| 3134 | |
| 3135 | /* Create the HashJoinTuple */ |
| 3136 | hashTupleSize = HJTUPLE_OVERHEAD + tuple->t_len; |
| 3137 | hashTuple = (HashJoinTuple) MemoryContextAlloc(hashtable->batchCxt, |
| 3138 | hashTupleSize); |
| 3139 | hashTuple->hashvalue = hashvalue; |
| 3140 | memcpy(HJTUPLE_MINTUPLE(hashTuple), tuple, tuple->t_len); |
| 3141 | HeapTupleHeaderClearMatch(HJTUPLE_MINTUPLE(hashTuple)); |
| 3142 | |
| 3143 | /* Push it onto the front of the skew bucket's list */ |
| 3144 | hashTuple->next.unshared = hashtable->skewBucket[bucketNumber]->tuples; |
| 3145 | hashtable->skewBucket[bucketNumber]->tuples = hashTuple; |
| 3146 | Assert(hashTuple != hashTuple->next.unshared); |
| 3147 | |
| 3148 | /* Account for space used, and back off if we've used too much */ |
| 3149 | hashtable->spaceUsed += hashTupleSize; |
| 3150 | hashtable->spaceUsedSkew += hashTupleSize; |
| 3151 | if (hashtable->spaceUsed > hashtable->spacePeak) |
| 3152 | hashtable->spacePeak = hashtable->spaceUsed; |
| 3153 | while (hashtable->spaceUsedSkew > hashtable->spaceAllowedSkew) |
| 3154 | ExecHashRemoveNextSkewBucket(hashState, hashtable); |
| 3155 | |
| 3156 | /* Check we are not over the total spaceAllowed, either */ |
| 3157 | if (hashtable->spaceUsed > hashtable->spaceAllowed) |
| 3158 | ExecHashIncreaseNumBatches(hashtable); |
| 3159 | |
| 3160 | if (shouldFree) |
| 3161 | heap_free_minimal_tuple(tuple); |
| 3162 | } |
| 3163 | |
| 3164 | /* |
| 3165 | * ExecHashRemoveNextSkewBucket |
no test coverage detected