Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 72567f6

Browse files
committed
Try again to fix accumulation of parallel worker instrumentation.
When a Gather or Gather Merge node is started and stopped multiple times, accumulate instrumentation data only once, at the end, instead of after each execution, to avoid recording inflated totals. Commit 778e78a, the previous attempt at a fix, instead reset the state after every execution, which worked for the general instrumentation data but had problems for the additional instrumentation specific to Sort and Hash nodes. Report by hubert depesz lubaczewski. Analysis and fix by Amit Kapila, following a design proposal from Thomas Munro, with a comment tweak by me. Discussion: http://postgr.es/m/20171127175631.GA405@depesz.com
1 parent db2ee07 commit 72567f6

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

src/backend/executor/execParallel.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ ExecParallelRetrieveInstrumentation(PlanState *planstate,
723723

724724
/*
725725
* Finish parallel execution. We wait for parallel workers to finish, and
726-
* accumulate their buffer usage and instrumentation.
726+
* accumulate their buffer usage.
727727
*/
728728
void
729729
ExecParallelFinish(ParallelExecutorInfo *pei)
@@ -769,23 +769,23 @@ ExecParallelFinish(ParallelExecutorInfo *pei)
769769
for (i = 0; i < nworkers; i++)
770770
InstrAccumParallelQuery(&pei->buffer_usage[i]);
771771

772-
/* Finally, accumulate instrumentation, if any. */
773-
if (pei->instrumentation)
774-
ExecParallelRetrieveInstrumentation(pei->planstate,
775-
pei->instrumentation);
776-
777772
pei->finished = true;
778773
}
779774

780775
/*
781-
* Clean up whatever ParallelExecutorInfo resources still exist after
782-
* ExecParallelFinish. We separate these routines because someone might
783-
* want to examine the contents of the DSM after ExecParallelFinish and
784-
* before calling this routine.
776+
* Accumulate instrumentation, and then clean up whatever ParallelExecutorInfo
777+
* resources still exist after ExecParallelFinish. We separate these
778+
* routines because someone might want to examine the contents of the DSM
779+
* after ExecParallelFinish and before calling this routine.
785780
*/
786781
void
787782
ExecParallelCleanup(ParallelExecutorInfo *pei)
788783
{
784+
/* Accumulate instrumentation, if any. */
785+
if (pei->instrumentation)
786+
ExecParallelRetrieveInstrumentation(pei->planstate,
787+
pei->instrumentation);
788+
789789
if (pei->area != NULL)
790790
{
791791
dsa_detach(pei->area);

src/test/regress/expected/select_parallel.out

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,28 @@ select count(*) from bmscantest where a>1;
300300
99999
301301
(1 row)
302302

303+
-- test accumulation of stats for parallel nodes
303304
reset enable_seqscan;
305+
alter table tenk2 set (parallel_workers = 0);
306+
explain (analyze, timing off, summary off, costs off)
307+
select count(*) from tenk1, tenk2 where tenk1.hundred > 1
308+
and tenk2.thousand=0;
309+
QUERY PLAN
310+
--------------------------------------------------------------------------
311+
Aggregate (actual rows=1 loops=1)
312+
-> Nested Loop (actual rows=98000 loops=1)
313+
-> Seq Scan on tenk2 (actual rows=10 loops=1)
314+
Filter: (thousand = 0)
315+
Rows Removed by Filter: 9990
316+
-> Gather (actual rows=9800 loops=10)
317+
Workers Planned: 4
318+
Workers Launched: 4
319+
-> Parallel Seq Scan on tenk1 (actual rows=1960 loops=50)
320+
Filter: (hundred > 1)
321+
Rows Removed by Filter: 40
322+
(11 rows)
323+
324+
alter table tenk2 reset (parallel_workers);
304325
reset enable_indexscan;
305326
reset enable_hashjoin;
306327
reset enable_mergejoin;

src/test/regress/sql/select_parallel.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,14 @@ insert into bmscantest select r, 'fooooooooooooooooooooooooooooooooooooooooooooo
116116
create index i_bmtest ON bmscantest(a);
117117
select count(*) from bmscantest where a>1;
118118

119+
-- test accumulation of stats for parallel nodes
119120
reset enable_seqscan;
121+
alter table tenk2 set (parallel_workers = 0);
122+
explain (analyze, timing off, summary off, costs off)
123+
select count(*) from tenk1, tenk2 where tenk1.hundred > 1
124+
and tenk2.thousand=0;
125+
alter table tenk2 reset (parallel_workers);
126+
120127
reset enable_indexscan;
121128
reset enable_hashjoin;
122129
reset enable_mergejoin;

0 commit comments

Comments
 (0)