fix_accum_instr_parallel_workers_v1.patch
application/octet-stream
Filename: fix_accum_instr_parallel_workers_v1.patch
Type: application/octet-stream
Part: 0
Patch
Format: unified
Series: patch v1
| File | + | − |
|---|---|---|
| src/backend/executor/execParallel.c | 30 | 7 |
diff --git a/src/backend/executor/execParallel.c b/src/backend/executor/execParallel.c
index 53c5254..6a6bf20 100644
--- a/src/backend/executor/execParallel.c
+++ b/src/backend/executor/execParallel.c
@@ -919,14 +919,25 @@ ExecParallelRetrieveInstrumentation(PlanState *planstate,
* regular instrumentation information, which is the per-query context.
* Switch into per-query memory context.
*/
- oldcontext = MemoryContextSwitchTo(planstate->state->es_query_cxt);
- ibytes = mul_size(instrumentation->num_workers, sizeof(Instrumentation));
- planstate->worker_instrument =
- palloc(ibytes + offsetof(WorkerInstrumentation, instrument));
- MemoryContextSwitchTo(oldcontext);
+ if (!planstate->worker_instrument)
+ {
+ oldcontext = MemoryContextSwitchTo(planstate->state->es_query_cxt);
+ ibytes = mul_size(instrumentation->num_workers, sizeof(Instrumentation));
+ planstate->worker_instrument =
+ palloc(ibytes + offsetof(WorkerInstrumentation, instrument));
+ MemoryContextSwitchTo(oldcontext);
+
+ for (n = 0; n < instrumentation->num_workers; ++n)
+ InstrInit(&planstate->worker_instrument->instrument[n],
+ planstate->state->es_instrument);
+ }
planstate->worker_instrument->num_workers = instrumentation->num_workers;
- memcpy(&planstate->worker_instrument->instrument, instrument, ibytes);
+
+ /* Accumulate the per-worker detail. */
+ for (n = 0; n < instrumentation->num_workers; ++n)
+ InstrAggNode(&planstate->worker_instrument->instrument[n],
+ &instrument[n]);
/*
* Perform any node-type-specific work that needs to be done. Currently,
@@ -989,8 +1000,20 @@ ExecParallelFinish(ParallelExecutorInfo *pei)
/* Finally, accumulate instrumentation, if any. */
if (pei->instrumentation)
+ {
+ Instrumentation *instrument;
+ SharedExecutorInstrumentation *sh_instr;
+
+ sh_instr = pei->instrumentation;
+
ExecParallelRetrieveInstrumentation(pei->planstate,
- pei->instrumentation);
+ sh_instr);
+
+ /* Clear the instrumentation space for next time. */
+ instrument = GetInstrumentationArray(sh_instr);
+ for (i = 0; i < sh_instr->num_workers * sh_instr->num_plan_nodes; ++i)
+ InstrInit(&instrument[i], pei->planstate->state->es_instrument);
+ }
pei->finished = true;
}