v2-0001-Fix-buffer-usage-stats-for-nodes-above-Gather-Merge.patch

application/octet-stream

Filename: v2-0001-Fix-buffer-usage-stats-for-nodes-above-Gather-Merge.patch
Type: application/octet-stream
Part: 0
Message: Re: Buffers from parallel workers not accumulated to upper nodes with gather merge

Patch

Format: format-patch
Series: patch v2-0001
Subject: Fix buffer usage stats for nodes above Gather Merge.
File+
src/backend/executor/execProcnode.c 2 2
From 50ba4f4df8768dc8b9963f6036e4ad1590d4a4a8 Mon Sep 17 00:00:00 2001
From: Amit Kapila <akapila@postgresql.org>
Date: Thu, 23 Jul 2020 15:35:58 +0530
Subject: [PATCH] Fix buffer usage stats for nodes above Gather Merge.

Commit 85c9d347 addressed a similar problem for Gather and Gather
Merge nodes but forgot to account for nodes above parallel nodes.  This
still works for nodes above Gather node because we shut down the workers
for Gather node as soon as there are no more tuples.  We can do a similar
thing for Gather Merge as well but it seems the better way to deal with
this is to account for stats while we shutdown the nodes after completing
the execution.

Reported-by: Stéphane Lorek, Jehan-Guillaume de Rorthais
Author: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
Reviewed-by: Amit Kapila
Backpatch-through: 10, where it was introduced
Discussion: https://postgr.es/m/20200718160206.584532a2@firost
---
 src/backend/executor/execProcnode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/backend/executor/execProcnode.c b/src/backend/executor/execProcnode.c
index d87fb05..ed78cf8 100644
--- a/src/backend/executor/execProcnode.c
+++ b/src/backend/executor/execProcnode.c
@@ -731,8 +731,6 @@ ExecShutdownNode(PlanState *node)
 
 	check_stack_depth();
 
-	planstate_tree_walker(node, ExecShutdownNode, NULL);
-
 	/*
 	 * Treat the node as running while we shut it down, but only if it's run
 	 * at least once already.  We don't expect much CPU consumption during
@@ -746,6 +744,8 @@ ExecShutdownNode(PlanState *node)
 	if (node->instrument && node->instrument->running)
 		InstrStartNode(node->instrument);
 
+	planstate_tree_walker(node, ExecShutdownNode, NULL);
+
 	switch (nodeTag(node))
 	{
 		case T_GatherState:
-- 
1.8.3.1