]> granicus.if.org Git - postgresql/commitdiff
Match the buffer usage tracking for leader and worker backends.
authorAmit Kapila <akapila@postgresql.org>
Fri, 3 Aug 2018 04:20:24 +0000 (09:50 +0530)
committerAmit Kapila <akapila@postgresql.org>
Fri, 3 Aug 2018 04:20:24 +0000 (09:50 +0530)
In the leader backend, we don't track the buffer usage for ExecutorStart
phase whereas in worker backend we track it for ExecutorStart phase as
well.  This leads to different value for buffer usage stats for the
parallel and non-parallel query.  Change the code so that worker backend
also starts tracking buffer usage after ExecutorStart.

Author: Amit Kapila and Robert Haas
Reviewed-by: Robert Haas and Andres Freund
Backpatch-through: 9.6 where this code was introduced
Discussion:https://postgr.es/m/86137f17-1dfb-42f9-7421-82fd786b04a1@anayrat.info

src/backend/executor/execParallel.c

index 60aaa822b7e2f24e42f78ce22fb4f7fc4f0fd5dc..892372338fc8eb4a044bf87f0b65879ecba53f8f 100644 (file)
@@ -979,9 +979,6 @@ ParallelQueryMain(dsm_segment *seg, shm_toc *toc)
        /* Report workers' query for monitoring purposes */
        pgstat_report_activity(STATE_RUNNING, debug_query_string);
 
-       /* Prepare to track buffer usage during query execution. */
-       InstrStartParallelQuery();
-
        /* Attach to the dynamic shared memory area. */
        area_space = shm_toc_lookup(toc, PARALLEL_KEY_DSA, false);
        area = dsa_attach_in_place(area_space, seg);
@@ -993,6 +990,15 @@ ParallelQueryMain(dsm_segment *seg, shm_toc *toc)
        queryDesc->planstate->state->es_query_dsa = area;
        ExecParallelInitializeWorker(queryDesc->planstate, toc);
 
+       /*
+        * Prepare to track buffer usage during query execution.
+        *
+        * We do this after starting up the executor to match what happens in the
+        * leader, which also doesn't count buffer accesses that occur during
+        * executor startup.
+        */
+       InstrStartParallelQuery();
+
        /* Run the plan */
        ExecutorRun(queryDesc, ForwardScanDirection, 0L, true);