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

Commit85c9d34

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 parentccc84a9 commit85c9d34

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
@@ -752,6 +752,19 @@ ExecShutdownNode(PlanState *node)
752752

753753
planstate_tree_walker(node,ExecShutdownNode,NULL);
754754

755+
/*
756+
* Treat the node as running while we shut it down, but only if it's run
757+
* at least once already. We don't expect much CPU consumption during
758+
* node shutdown, but in the case of Gather or Gather Merge, we may shut
759+
* down workers at this stage. If so, their buffer usage will get
760+
* propagated into pgBufferUsage at this point, and we want to make sure
761+
* that it gets associated with the Gather node. We skip this if the node
762+
* has never been executed, so as to avoid incorrectly making it appear
763+
* that it has.
764+
*/
765+
if (node->instrument&&node->instrument->running)
766+
InstrStartNode(node->instrument);
767+
755768
switch (nodeTag(node))
756769
{
757770
caseT_GatherState:
@@ -776,6 +789,10 @@ ExecShutdownNode(PlanState *node)
776789
break;
777790
}
778791

792+
/* Stop the node if we started it above, reporting 0 tuples. */
793+
if (node->instrument&&node->instrument->running)
794+
InstrStopNode(node->instrument,0);
795+
779796
return false;
780797
}
781798

‎src/backend/executor/nodeGather.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,10 @@ gather_readnext(GatherState *gatherstate)
324324
Assert(!tup);
325325
--gatherstate->nreaders;
326326
if (gatherstate->nreaders==0)
327+
{
328+
ExecShutdownGatherWorkers(gatherstate);
327329
returnNULL;
330+
}
328331
memmove(&gatherstate->reader[gatherstate->nextreader],
329332
&gatherstate->reader[gatherstate->nextreader+1],
330333
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