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

Function ExecParallelHashIncreaseNumBuckets

src/backend/executor/nodeHash.c:1773–1859  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1771}
1772
1773static void
1774ExecParallelHashIncreaseNumBuckets(HashJoinTable hashtable)
1775{
1776 ParallelHashJoinState *pstate = hashtable->parallel_state;
1777 int i;
1778 HashMemoryChunk chunk;
1779 dsa_pointer chunk_s;
1780
1781 Assert(BarrierPhase(&pstate->build_barrier) == PHJ_BUILD_HASHING_INNER);
1782
1783 /*
1784 * It's unlikely, but we need to be prepared for new participants to show
1785 * up while we're in the middle of this operation so we need to switch on
1786 * barrier phase here.
1787 */
1788 switch (PHJ_GROW_BUCKETS_PHASE(BarrierPhase(&pstate->grow_buckets_barrier)))
1789 {
1790 case PHJ_GROW_BUCKETS_ELECTING:
1791 /* Elect one participant to prepare to increase nbuckets. */
1792 if (BarrierArriveAndWait(&pstate->grow_buckets_barrier,
1793 WAIT_EVENT_HASH_GROW_BUCKETS_ELECT))
1794 {
1795 size_t size;
1796 dsa_pointer_atomic *buckets;
1797
1798 /* Double the size of the bucket array. */
1799 pstate->nbuckets *= 2;
1800 size = pstate->nbuckets * sizeof(dsa_pointer_atomic);
1801 hashtable->batches[0].shared->size += size / 2;
1802 dsa_free(hashtable->area, hashtable->batches[0].shared->buckets);
1803 hashtable->batches[0].shared->buckets =
1804 dsa_allocate(hashtable->area, size);
1805 buckets = (dsa_pointer_atomic *)
1806 dsa_get_address(hashtable->area,
1807 hashtable->batches[0].shared->buckets);
1808 for (i = 0; i < pstate->nbuckets; ++i)
1809 dsa_pointer_atomic_init(&buckets[i], InvalidDsaPointer);
1810
1811 /* Put the chunk list onto the work queue. */
1812 pstate->chunk_work_queue = hashtable->batches[0].shared->chunks;
1813
1814 /* Clear the flag. */
1815 pstate->growth = PHJ_GROWTH_OK;
1816 }
1817 /* Fall through. */
1818
1819 case PHJ_GROW_BUCKETS_ALLOCATING:
1820 /* Wait for the above to complete. */
1821 BarrierArriveAndWait(&pstate->grow_buckets_barrier,
1822 WAIT_EVENT_HASH_GROW_BUCKETS_ALLOCATE);
1823 /* Fall through. */
1824
1825 case PHJ_GROW_BUCKETS_REINSERTING:
1826 /* Reinsert all tuples into the hash table. */
1827 ExecParallelHashEnsureBatchAccessors(hashtable);
1828 ExecParallelHashTableSetCurrentBatch(hashtable, 0);
1829 while ((chunk = ExecParallelHashPopChunkQueue(hashtable, &chunk_s)))
1830 {

Callers 3

MultiExecParallelHashFunction · 0.85

Calls 9

BarrierPhaseFunction · 0.85
BarrierArriveAndWaitFunction · 0.85
dsa_freeFunction · 0.85
dsa_get_addressFunction · 0.85

Tested by

no test coverage detected