if (planstate->plan->parallel_aware)
ExecBitmapHeapEstimate((BitmapHeapScanState *) planstate,
e->pcxt);
+ /* even when not parallel-aware, for EXPLAIN ANALYZE */
+ ExecBitmapHeapInstrumentEstimate((BitmapHeapScanState *) planstate,
+ e->pcxt);
break;
case T_HashJoinState:
if (planstate->plan->parallel_aware)
if (planstate->plan->parallel_aware)
ExecBitmapHeapInitializeDSM((BitmapHeapScanState *) planstate,
d->pcxt);
+ /* even when not parallel-aware, for EXPLAIN ANALYZE */
+ ExecBitmapHeapInstrumentInitDSM((BitmapHeapScanState *) planstate,
+ d->pcxt);
break;
case T_HashJoinState:
if (planstate->plan->parallel_aware)
if (planstate->plan->parallel_aware)
ExecBitmapHeapInitializeWorker((BitmapHeapScanState *) planstate,
pwcxt);
+ /* even when not parallel-aware, for EXPLAIN ANALYZE */
+ ExecBitmapHeapInstrumentInitWorker((BitmapHeapScanState *) planstate,
+ pwcxt);
break;
case T_HashJoinState:
if (planstate->plan->parallel_aware)
ExecBitmapHeapEstimate(BitmapHeapScanState *node,
ParallelContext *pcxt)
{
- Size size;
-
- size = MAXALIGN(sizeof(ParallelBitmapHeapState));
-
- /* account for instrumentation, if required */
- if (node->ss.ps.instrument && pcxt->nworkers > 0)
- {
- size = add_size(size, offsetof(SharedBitmapHeapInstrumentation, sinstrument));
- size = add_size(size, mul_size(pcxt->nworkers, sizeof(BitmapHeapScanInstrumentation)));
- }
-
- shm_toc_estimate_chunk(&pcxt->estimator, size);
+ shm_toc_estimate_chunk(&pcxt->estimator,
+ MAXALIGN(sizeof(ParallelBitmapHeapState)));
shm_toc_estimate_keys(&pcxt->estimator, 1);
}
ParallelContext *pcxt)
{
ParallelBitmapHeapState *pstate;
- SharedBitmapHeapInstrumentation *sinstrument = NULL;
dsa_area *dsa = node->ss.ps.state->es_query_dsa;
- char *ptr;
- Size size;
/* If there's no DSA, there are no workers; initialize nothing. */
if (dsa == NULL)
return;
- size = MAXALIGN(sizeof(ParallelBitmapHeapState));
- if (node->ss.ps.instrument && pcxt->nworkers > 0)
- {
- size = add_size(size, offsetof(SharedBitmapHeapInstrumentation, sinstrument));
- size = add_size(size, mul_size(pcxt->nworkers, sizeof(BitmapHeapScanInstrumentation)));
- }
-
- ptr = shm_toc_allocate(pcxt->toc, size);
- pstate = (ParallelBitmapHeapState *) ptr;
- ptr += MAXALIGN(sizeof(ParallelBitmapHeapState));
- if (node->ss.ps.instrument && pcxt->nworkers > 0)
- sinstrument = (SharedBitmapHeapInstrumentation *) ptr;
+ pstate = (ParallelBitmapHeapState *)
+ shm_toc_allocate(pcxt->toc,
+ MAXALIGN(sizeof(ParallelBitmapHeapState)));
pstate->tbmiterator = 0;
ConditionVariableInit(&pstate->cv);
- if (sinstrument)
- {
- sinstrument->num_workers = pcxt->nworkers;
-
- /* ensure any unfilled slots will contain zeroes */
- memset(sinstrument->sinstrument, 0,
- pcxt->nworkers * sizeof(BitmapHeapScanInstrumentation));
- }
-
shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pstate);
node->pstate = pstate;
- node->sinstrument = sinstrument;
}
/* ----------------------------------------------------------------
ExecBitmapHeapInitializeWorker(BitmapHeapScanState *node,
ParallelWorkerContext *pwcxt)
{
- char *ptr;
-
Assert(node->ss.ps.state->es_query_dsa != NULL);
- ptr = shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false);
+ node->pstate = (ParallelBitmapHeapState *)
+ shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false);
+}
+
+/*
+ * Compute the amount of space we'll need for the shared instrumentation and
+ * inform pcxt->estimator.
+ */
+void
+ExecBitmapHeapInstrumentEstimate(BitmapHeapScanState *node,
+ ParallelContext *pcxt)
+{
+ Size size;
+
+ if (!node->ss.ps.instrument || pcxt->nworkers == 0)
+ return;
+
+ size = add_size(offsetof(SharedBitmapHeapInstrumentation, sinstrument),
+ mul_size(pcxt->nworkers, sizeof(BitmapHeapScanInstrumentation)));
+ shm_toc_estimate_chunk(&pcxt->estimator, size);
+ shm_toc_estimate_keys(&pcxt->estimator, 1);
+}
+
+/*
+ * Set up parallel bitmap heap scan instrumentation.
+ */
+void
+ExecBitmapHeapInstrumentInitDSM(BitmapHeapScanState *node,
+ ParallelContext *pcxt)
+{
+ Size size;
+
+ if (!node->ss.ps.instrument || pcxt->nworkers == 0)
+ return;
+
+ size = add_size(offsetof(SharedBitmapHeapInstrumentation, sinstrument),
+ mul_size(pcxt->nworkers, sizeof(BitmapHeapScanInstrumentation)));
+ node->sinstrument =
+ (SharedBitmapHeapInstrumentation *) shm_toc_allocate(pcxt->toc, size);
+
+ /* Each per-worker area must start out as zeroes */
+ memset(node->sinstrument, 0, size);
+ node->sinstrument->num_workers = pcxt->nworkers;
+ shm_toc_insert(pcxt->toc,
+ node->ss.ps.plan->plan_node_id +
+ PARALLEL_KEY_SCAN_INSTRUMENT_OFFSET,
+ node->sinstrument);
+}
- node->pstate = (ParallelBitmapHeapState *) ptr;
- ptr += MAXALIGN(sizeof(ParallelBitmapHeapState));
+/*
+ * Look up and save the location of the shared instrumentation.
+ */
+void
+ExecBitmapHeapInstrumentInitWorker(BitmapHeapScanState *node,
+ ParallelWorkerContext *pwcxt)
+{
+ if (!node->ss.ps.instrument)
+ return;
- if (node->ss.ps.instrument)
- node->sinstrument = (SharedBitmapHeapInstrumentation *) ptr;
+ node->sinstrument = (SharedBitmapHeapInstrumentation *)
+ shm_toc_lookup(pwcxt->toc,
+ node->ss.ps.plan->plan_node_id +
+ PARALLEL_KEY_SCAN_INSTRUMENT_OFFSET,
+ false);
}
/* ----------------------------------------------------------------