Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb805b63

Browse files
author
Amit Kapila
committed
Fix buffer usage stats for parallel nodes.
The buffer usage stats is accounted only for the execution phase of thenode. For Gather and Gather Merge nodes, such stats are accumulated atthe time of shutdown of workers which is done after execution of node dueto which we missed to account them for such nodes. Fix it by treatingnodes as running while we shut down them.We can also miss accounting for a Limit node when Gather or Gather Mergeis beneath it, because it can finish the execution before shutting downsuch nodes. So we allow a Limit node to shut down the resources before itcompletes the execution.In the passing fix the gather node code to allow workers to shut down assoon as we find that all the tuples from the workers have been retrieved.The original code use to do that, but is accidently removed by commit01edb5c.Reported-by: Adrien NayratAuthor: Amit Kapila and Robert HaasReviewed-by: Robert Haas and Andres FreundBackpatch-through: 9.6 where this code was introducedDiscussion:https://postgr.es/m/86137f17-1dfb-42f9-7421-82fd786b04a1@anayrat.info
1 parent3f02b51 commitb805b63

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

‎src/backend/executor/execProcnode.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,19 @@ ExecShutdownNode(PlanState *node)
737737

738738
planstate_tree_walker(node,ExecShutdownNode,NULL);
739739

740+
/*
741+
* Treat the node as running while we shut it down, but only if it's run
742+
* at least once already. We don't expect much CPU consumption during
743+
* node shutdown, but in the case of Gather or Gather Merge, we may shut
744+
* down workers at this stage. If so, their buffer usage will get
745+
* propagated into pgBufferUsage at this point, and we want to make sure
746+
* that it gets associated with the Gather node. We skip this if the node
747+
* has never been executed, so as to avoid incorrectly making it appear
748+
* that it has.
749+
*/
750+
if (node->instrument&&node->instrument->running)
751+
InstrStartNode(node->instrument);
752+
740753
switch (nodeTag(node))
741754
{
742755
caseT_GatherState:
@@ -755,5 +768,9 @@ ExecShutdownNode(PlanState *node)
755768
break;
756769
}
757770

771+
/* Stop the node if we started it above, reporting 0 tuples. */
772+
if (node->instrument&&node->instrument->running)
773+
InstrStopNode(node->instrument,0);
774+
758775
return false;
759776
}

‎src/backend/executor/nodeGather.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,10 @@ gather_readnext(GatherState *gatherstate)
327327
Assert(!tup);
328328
--gatherstate->nreaders;
329329
if (gatherstate->nreaders==0)
330+
{
331+
ExecShutdownGatherWorkers(gatherstate);
330332
returnNULL;
333+
}
331334
memmove(&gatherstate->reader[gatherstate->nextreader],
332335
&gatherstate->reader[gatherstate->nextreader+1],
333336
sizeof(TupleQueueReader*)

‎src/backend/executor/nodeLimit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ ExecLimit(PlanState *pstate)
134134
node->position-node->offset >=node->count)
135135
{
136136
node->lstate=LIMIT_WINDOWEND;
137+
/* Allow nodes to release or shut down resources. */
138+
(void)ExecShutdownNode(outerPlan);
137139
returnNULL;
138140
}
139141

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp