* ExecHashRemoveNextSkewBucket * * Remove the least valuable skew bucket by pushing its tuples into * the main hash table. */
| 3168 | * the main hash table. |
| 3169 | */ |
| 3170 | static void |
| 3171 | ExecHashRemoveNextSkewBucket(HashState *hashState, HashJoinTable hashtable) |
| 3172 | { |
| 3173 | PlanState *ps = &hashState->ps; |
| 3174 | int bucketToRemove; |
| 3175 | HashSkewBucket *bucket; |
| 3176 | uint32 hashvalue; |
| 3177 | int bucketno; |
| 3178 | int batchno; |
| 3179 | HashJoinTuple hashTuple; |
| 3180 | |
| 3181 | /* Locate the bucket to remove */ |
| 3182 | bucketToRemove = hashtable->skewBucketNums[hashtable->nSkewBuckets - 1]; |
| 3183 | bucket = hashtable->skewBucket[bucketToRemove]; |
| 3184 | |
| 3185 | /* |
| 3186 | * Calculate which bucket and batch the tuples belong to in the main |
| 3187 | * hashtable. They all have the same hash value, so it's the same for all |
| 3188 | * of them. Also note that it's not possible for nbatch to increase while |
| 3189 | * we are processing the tuples. |
| 3190 | */ |
| 3191 | hashvalue = bucket->hashvalue; |
| 3192 | ExecHashGetBucketAndBatch(hashtable, hashvalue, &bucketno, &batchno); |
| 3193 | |
| 3194 | /* Process all tuples in the bucket */ |
| 3195 | hashTuple = bucket->tuples; |
| 3196 | while (hashTuple != NULL) |
| 3197 | { |
| 3198 | HashJoinTuple nextHashTuple = hashTuple->next.unshared; |
| 3199 | MinimalTuple tuple; |
| 3200 | Size tupleSize; |
| 3201 | |
| 3202 | /* |
| 3203 | * This code must agree with ExecHashTableInsert. We do not use |
| 3204 | * ExecHashTableInsert directly as ExecHashTableInsert expects a |
| 3205 | * TupleTableSlot while we already have HashJoinTuples. |
| 3206 | */ |
| 3207 | tuple = HJTUPLE_MINTUPLE(hashTuple); |
| 3208 | tupleSize = HJTUPLE_OVERHEAD + tuple->t_len; |
| 3209 | |
| 3210 | /* Decide whether to put the tuple in the hash table or a temp file */ |
| 3211 | if (batchno == hashtable->curbatch) |
| 3212 | { |
| 3213 | /* Move the tuple to the main hash table */ |
| 3214 | HashJoinTuple copyTuple; |
| 3215 | |
| 3216 | /* |
| 3217 | * We must copy the tuple into the dense storage, else it will not |
| 3218 | * be found by, eg, ExecHashIncreaseNumBatches. |
| 3219 | */ |
| 3220 | copyTuple = (HashJoinTuple) dense_alloc(hashtable, tupleSize); |
| 3221 | memcpy(copyTuple, hashTuple, tupleSize); |
| 3222 | pfree(hashTuple); |
| 3223 | |
| 3224 | copyTuple->next.unshared = hashtable->buckets.unshared[bucketno]; |
| 3225 | hashtable->buckets.unshared[bucketno] = copyTuple; |
| 3226 | |
| 3227 | /* We have reduced skew space, but overall space doesn't change */ |
no test coverage detected