* ExecParallelHashIncreaseNumBatches * Every participant attached to grow_batches_barrier must run this * function when it observes growth == PHJ_GROWTH_NEED_MORE_BATCHES. */
| 1334 | * function when it observes growth == PHJ_GROWTH_NEED_MORE_BATCHES. |
| 1335 | */ |
| 1336 | static void |
| 1337 | ExecParallelHashIncreaseNumBatches(HashJoinTable hashtable) |
| 1338 | { |
| 1339 | ParallelHashJoinState *pstate = hashtable->parallel_state; |
| 1340 | int i; |
| 1341 | |
| 1342 | Assert(BarrierPhase(&pstate->build_barrier) == PHJ_BUILD_HASHING_INNER); |
| 1343 | |
| 1344 | /* |
| 1345 | * It's unlikely, but we need to be prepared for new participants to show |
| 1346 | * up while we're in the middle of this operation so we need to switch on |
| 1347 | * barrier phase here. |
| 1348 | */ |
| 1349 | switch (PHJ_GROW_BATCHES_PHASE(BarrierPhase(&pstate->grow_batches_barrier))) |
| 1350 | { |
| 1351 | case PHJ_GROW_BATCHES_ELECTING: |
| 1352 | |
| 1353 | /* |
| 1354 | * Elect one participant to prepare to grow the number of batches. |
| 1355 | * This involves reallocating or resetting the buckets of batch 0 |
| 1356 | * in preparation for all participants to begin repartitioning the |
| 1357 | * tuples. |
| 1358 | */ |
| 1359 | if (BarrierArriveAndWait(&pstate->grow_batches_barrier, |
| 1360 | WAIT_EVENT_HASH_GROW_BATCHES_ELECT)) |
| 1361 | { |
| 1362 | dsa_pointer_atomic *buckets; |
| 1363 | ParallelHashJoinBatch *old_batch0; |
| 1364 | int new_nbatch; |
| 1365 | int i; |
| 1366 | |
| 1367 | /* Move the old batch out of the way. */ |
| 1368 | old_batch0 = hashtable->batches[0].shared; |
| 1369 | pstate->old_batches = pstate->batches; |
| 1370 | pstate->old_nbatch = hashtable->nbatch; |
| 1371 | pstate->batches = InvalidDsaPointer; |
| 1372 | |
| 1373 | /* Free this backend's old accessors. */ |
| 1374 | ExecParallelHashCloseBatchAccessors(hashtable); |
| 1375 | |
| 1376 | /* Figure out how many batches to use. */ |
| 1377 | if (hashtable->nbatch == 1) |
| 1378 | { |
| 1379 | /* |
| 1380 | * We are going from single-batch to multi-batch. We need |
| 1381 | * to switch from one large combined memory budget to the |
| 1382 | * regular hash_mem budget. |
| 1383 | */ |
| 1384 | pstate->space_allowed = get_hash_memory_limit(); |
| 1385 | |
| 1386 | /* |
| 1387 | * The combined hash_mem of all participants wasn't |
| 1388 | * enough. Therefore one batch per participant would be |
| 1389 | * approximately equivalent and would probably also be |
| 1390 | * insufficient. So try two batches per participant, |
| 1391 | * rounded up to a power of two. |
| 1392 | */ |
| 1393 | new_nbatch = pg_nextpower2_32(pstate->nparticipants * 2); |
no test coverage detected