* Repartition the tuples currently loaded into memory for inner batch 0 * because the number of batches has been increased. Some tuples are retained * in memory and some are written out to a later batch. */
| 1551 | * in memory and some are written out to a later batch. |
| 1552 | */ |
| 1553 | static void |
| 1554 | ExecParallelHashRepartitionFirst(HashJoinTable hashtable) |
| 1555 | { |
| 1556 | dsa_pointer chunk_shared; |
| 1557 | HashMemoryChunk chunk; |
| 1558 | |
| 1559 | Assert(hashtable->nbatch == hashtable->parallel_state->nbatch); |
| 1560 | |
| 1561 | while ((chunk = ExecParallelHashPopChunkQueue(hashtable, &chunk_shared))) |
| 1562 | { |
| 1563 | size_t idx = 0; |
| 1564 | |
| 1565 | /* Repartition all tuples in this chunk. */ |
| 1566 | while (idx < chunk->used) |
| 1567 | { |
| 1568 | HashJoinTuple hashTuple = (HashJoinTuple) (HASH_CHUNK_DATA(chunk) + idx); |
| 1569 | MinimalTuple tuple = HJTUPLE_MINTUPLE(hashTuple); |
| 1570 | HashJoinTuple copyTuple; |
| 1571 | dsa_pointer shared; |
| 1572 | int bucketno; |
| 1573 | int batchno; |
| 1574 | |
| 1575 | ExecHashGetBucketAndBatch(hashtable, hashTuple->hashvalue, |
| 1576 | &bucketno, &batchno); |
| 1577 | |
| 1578 | Assert(batchno < hashtable->nbatch); |
| 1579 | if (batchno == 0) |
| 1580 | { |
| 1581 | /* It still belongs in batch 0. Copy to a new chunk. */ |
| 1582 | copyTuple = |
| 1583 | ExecParallelHashTupleAlloc(hashtable, |
| 1584 | HJTUPLE_OVERHEAD + tuple->t_len, |
| 1585 | &shared); |
| 1586 | copyTuple->hashvalue = hashTuple->hashvalue; |
| 1587 | memcpy(HJTUPLE_MINTUPLE(copyTuple), tuple, tuple->t_len); |
| 1588 | ExecParallelHashPushTuple(&hashtable->buckets.shared[bucketno], |
| 1589 | copyTuple, shared); |
| 1590 | } |
| 1591 | else |
| 1592 | { |
| 1593 | size_t tuple_size = |
| 1594 | MAXALIGN(HJTUPLE_OVERHEAD + tuple->t_len); |
| 1595 | |
| 1596 | /* It belongs in a later batch. */ |
| 1597 | hashtable->batches[batchno].estimated_size += tuple_size; |
| 1598 | sts_puttuple(hashtable->batches[batchno].inner_tuples, |
| 1599 | &hashTuple->hashvalue, tuple); |
| 1600 | } |
| 1601 | |
| 1602 | /* Count this tuple. */ |
| 1603 | ++hashtable->batches[0].old_ntuples; |
| 1604 | ++hashtable->batches[batchno].ntuples; |
| 1605 | |
| 1606 | idx += MAXALIGN(HJTUPLE_OVERHEAD + |
| 1607 | HJTUPLE_MINTUPLE(hashTuple)->t_len); |
| 1608 | } |
| 1609 | |
| 1610 | /* Free this chunk. */ |
no test coverage detected