| 2048 | } |
| 2049 | |
| 2050 | void |
| 2051 | ExecHashJoinInitializeDSM(HashJoinState *state, ParallelContext *pcxt) |
| 2052 | { |
| 2053 | int plan_node_id = state->js.ps.plan->plan_node_id; |
| 2054 | HashState *hashNode; |
| 2055 | ParallelHashJoinState *pstate; |
| 2056 | EState *estate = state->js.ps.state; |
| 2057 | /* |
| 2058 | * Disable shared hash table mode if we failed to create a real DSM |
| 2059 | * segment, because that means that we don't have a DSA area to work with. |
| 2060 | */ |
| 2061 | if (pcxt->seg == NULL) |
| 2062 | return; |
| 2063 | |
| 2064 | ExecSetExecProcNode(&state->js.ps, ExecParallelHashJoin); |
| 2065 | |
| 2066 | /* |
| 2067 | * Set up the state needed to coordinate access to the shared hash |
| 2068 | * table(s), using the plan node ID as the toc key. |
| 2069 | */ |
| 2070 | pstate = shm_toc_allocate(pcxt->toc, sizeof(ParallelHashJoinState)); |
| 2071 | shm_toc_insert(pcxt->toc, plan_node_id, pstate); |
| 2072 | |
| 2073 | /* |
| 2074 | * Set up the shared hash join state with no batches initially. |
| 2075 | * ExecHashTableCreate() will prepare at least one later and set nbatch |
| 2076 | * and space_allowed. |
| 2077 | */ |
| 2078 | pstate->nbatch = 0; |
| 2079 | pstate->space_allowed = 0; |
| 2080 | pstate->batches = InvalidDsaPointer; |
| 2081 | pstate->old_batches = InvalidDsaPointer; |
| 2082 | pstate->nbuckets = 0; |
| 2083 | pstate->growth = PHJ_GROWTH_OK; |
| 2084 | pstate->chunk_work_queue = InvalidDsaPointer; |
| 2085 | pg_atomic_init_u32(&pstate->distributor, 0); |
| 2086 | if (estate->useMppParallelMode) |
| 2087 | pstate->nparticipants = pcxt->nworkers; |
| 2088 | else |
| 2089 | pstate->nparticipants = pcxt->nworkers + 1; |
| 2090 | |
| 2091 | pstate->total_tuples = 0; |
| 2092 | LWLockInitialize(&pstate->lock, |
| 2093 | LWTRANCHE_PARALLEL_HASH_JOIN); |
| 2094 | BarrierInit(&pstate->build_barrier, 0); |
| 2095 | BarrierInit(&pstate->grow_batches_barrier, 0); |
| 2096 | BarrierInit(&pstate->grow_buckets_barrier, 0); |
| 2097 | |
| 2098 | BarrierInit(&pstate->sync_barrier, pcxt->nworkers); |
| 2099 | BarrierInit(&pstate->batch0_barrier, pcxt->nworkers); |
| 2100 | |
| 2101 | if (((HashJoin *)state->js.ps.plan)->outer_motionhazard) |
| 2102 | BarrierInit(&pstate->outer_motion_barrier, pcxt->nworkers); |
| 2103 | |
| 2104 | pstate->phs_lasj_has_null = false; |
| 2105 | |
| 2106 | /* Set up the space we'll use for shared temporary files. */ |
| 2107 | SharedFileSetInit(&pstate->fileset, pcxt->seg); |
no test coverage detected