* Help repartition inner batches 1..n. */
| 1618 | * Help repartition inner batches 1..n. |
| 1619 | */ |
| 1620 | static void |
| 1621 | ExecParallelHashRepartitionRest(HashJoinTable hashtable) |
| 1622 | { |
| 1623 | ParallelHashJoinState *pstate = hashtable->parallel_state; |
| 1624 | int old_nbatch = pstate->old_nbatch; |
| 1625 | SharedTuplestoreAccessor **old_inner_tuples; |
| 1626 | ParallelHashJoinBatch *old_batches; |
| 1627 | int i; |
| 1628 | |
| 1629 | /* Get our hands on the previous generation of batches. */ |
| 1630 | old_batches = (ParallelHashJoinBatch *) |
| 1631 | dsa_get_address(hashtable->area, pstate->old_batches); |
| 1632 | old_inner_tuples = palloc0(sizeof(SharedTuplestoreAccessor *) * old_nbatch); |
| 1633 | for (i = 1; i < old_nbatch; ++i) |
| 1634 | { |
| 1635 | ParallelHashJoinBatch *shared = |
| 1636 | NthParallelHashJoinBatch(old_batches, i); |
| 1637 | |
| 1638 | old_inner_tuples[i] = sts_attach(ParallelHashJoinBatchInner(shared), |
| 1639 | hashtable->hjstate->worker_id, |
| 1640 | &pstate->fileset); |
| 1641 | } |
| 1642 | |
| 1643 | /* Join in the effort to repartition them. */ |
| 1644 | for (i = 1; i < old_nbatch; ++i) |
| 1645 | { |
| 1646 | MinimalTuple tuple; |
| 1647 | uint32 hashvalue; |
| 1648 | |
| 1649 | /* Scan one partition from the previous generation. */ |
| 1650 | sts_begin_parallel_scan(old_inner_tuples[i]); |
| 1651 | while ((tuple = sts_parallel_scan_next(old_inner_tuples[i], &hashvalue))) |
| 1652 | { |
| 1653 | size_t tuple_size = MAXALIGN(HJTUPLE_OVERHEAD + tuple->t_len); |
| 1654 | int bucketno; |
| 1655 | int batchno; |
| 1656 | |
| 1657 | /* Decide which partition it goes to in the new generation. */ |
| 1658 | ExecHashGetBucketAndBatch(hashtable, hashvalue, &bucketno, |
| 1659 | &batchno); |
| 1660 | |
| 1661 | hashtable->batches[batchno].estimated_size += tuple_size; |
| 1662 | ++hashtable->batches[batchno].ntuples; |
| 1663 | ++hashtable->batches[i].old_ntuples; |
| 1664 | |
| 1665 | /* Store the tuple its new batch. */ |
| 1666 | sts_puttuple(hashtable->batches[batchno].inner_tuples, |
| 1667 | &hashvalue, tuple); |
| 1668 | |
| 1669 | CHECK_FOR_INTERRUPTS(); |
| 1670 | } |
| 1671 | sts_end_parallel_scan(old_inner_tuples[i]); |
| 1672 | } |
| 1673 | |
| 1674 | pfree(old_inner_tuples); |
| 1675 | } |
| 1676 | |
| 1677 | /* |
no test coverage detected