MCPcopy Create free account
hub / github.com/apache/cloudberry / ExecHashJoinNewBatch

Function ExecHashJoinNewBatch

src/backend/executor/nodeHashjoin.c:1253–1416  ·  view source on GitHub ↗

* ExecHashJoinNewBatch * switch to a new hashjoin batch * * Returns true if successful, false if there are no more batches. */

Source from the content-addressed store, hash-verified

1251 * Returns true if successful, false if there are no more batches.
1252 */
1253static bool
1254ExecHashJoinNewBatch(HashJoinState *hjstate)
1255{
1256 HashJoinTable hashtable = hjstate->hj_HashTable;
1257 int nbatch;
1258 int curbatch;
1259
1260 SIMPLE_FAULT_INJECTOR("exec_hashjoin_new_batch");
1261
1262 HashState *hashState = (HashState *) innerPlanState(hjstate);
1263
1264 nbatch = hashtable->nbatch;
1265 curbatch = hashtable->curbatch;
1266
1267 if (curbatch >= nbatch)
1268 return false;
1269
1270 if (curbatch >= 0 && hashtable->stats)
1271 ExecHashTableExplainBatchEnd(hashState, hashtable);
1272
1273 if (curbatch > 0)
1274 {
1275 /*
1276 * We no longer need the previous outer batch file; close it right
1277 * away to free disk space.
1278 */
1279 if (hashtable->outerBatchFile[curbatch])
1280 BufFileClose(hashtable->outerBatchFile[curbatch]);
1281 hashtable->outerBatchFile[curbatch] = NULL;
1282 }
1283 else /* we just finished the first batch */
1284 {
1285 /*
1286 * Reset some of the skew optimization state variables, since we no
1287 * longer need to consider skew tuples after the first batch. The
1288 * memory context reset we are about to do will release the skew
1289 * hashtable itself.
1290 */
1291 hashtable->skewEnabled = false;
1292 hashtable->skewBucket = NULL;
1293 hashtable->skewBucketNums = NULL;
1294 hashtable->nSkewBuckets = 0;
1295 hashtable->spaceUsedSkew = 0;
1296 }
1297
1298 /*
1299 * If we want to keep the hash table around, for re-scan, then write
1300 * the current batch's state to disk before moving to the next one.
1301 * It's possible that we increase the number of batches later, so that
1302 * by the time we reload this file, some of the tuples we wrote here
1303 * will logically belong to a later file. ExecHashJoinReloadHashTable
1304 * will move such tuples when the file is reloaded.
1305 *
1306 * If we have already re-scanned, we might still have the old file
1307 * around, in which case there's no need to write it again.
1308 * XXX: Currently, we actually always re-create it, see comments in
1309 * ExecHashJoinReloadHashTable.
1310 */

Callers 1

ExecHashJoinImplFunction · 0.85

Calls 7

BufFileCloseFunction · 0.85
SpillCurrentBatchFunction · 0.85
BufFileSeekFunction · 0.85
errcode_for_file_accessFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected