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

Commit16ebab6

Browse files
committed
Avoid transferring parallel-unsafe subplans to parallel workers.
Commit5e6d8d2 allowed parallel workers to execute parallel-safesubplans, but it transmitted the query's entire list of subplans tothe worker(s). Since execMain.c blindly does ExecInitNode and laterExecEndNode on every list element, this resulted in parallel-unsafe plannodes nonetheless getting started up and shut down in parallel workers.That seems mostly harmless as far as core plan node types go (butmaybe not so much for Gather?). But it resulted in postgres_fdwopening and then closing extra remote connections, and it's likelythat other non-parallel-safe FDWs or custom scan providers would haveworse reactions.To fix, just make ExecSerializePlan replace parallel-unsafe subplanswith NULLs in the cut-down plan tree that it transmits to workers.This relies on ExecInitNode and ExecEndNode to do nothing on NULLinput, but they do anyway. If anything else is touching the droppedsubplans in a parallel worker, that would be a bug to be fixed.(This thus provides a strong guarantee that we won't try to dosomething with a parallel-unsafe subplan in a worker.)This is, I think, the last fix directly occasioned by Andreas Seltenreich'sbug report of a few days ago.Tom Lane and Amit KapilaDiscussion:https://postgr.es/m/87tw5x4vcu.fsf@credativ.de
1 parentf6f9f8a commit16ebab6

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

‎src/backend/executor/execParallel.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static char *
123123
ExecSerializePlan(Plan*plan,EState*estate)
124124
{
125125
PlannedStmt*pstmt;
126-
ListCell*tlist;
126+
ListCell*lc;
127127

128128
/* We can't scribble on the original plan, so make a copy. */
129129
plan=copyObject(plan);
@@ -137,9 +137,9 @@ ExecSerializePlan(Plan *plan, EState *estate)
137137
* accordingly. This is sort of a hack; there might be better ways to do
138138
* this...
139139
*/
140-
foreach(tlist,plan->targetlist)
140+
foreach(lc,plan->targetlist)
141141
{
142-
TargetEntry*tle= (TargetEntry*)lfirst(tlist);
142+
TargetEntry*tle=lfirst_node(TargetEntry,lc);
143143

144144
tle->resjunk= false;
145145
}
@@ -162,7 +162,24 @@ ExecSerializePlan(Plan *plan, EState *estate)
162162
pstmt->rtable=estate->es_range_table;
163163
pstmt->resultRelations=NIL;
164164
pstmt->nonleafResultRelations=NIL;
165-
pstmt->subplans=estate->es_plannedstmt->subplans;
165+
166+
/*
167+
* Transfer only parallel-safe subplans, leaving a NULL "hole" in the list
168+
* for unsafe ones (so that the list indexes of the safe ones are
169+
* preserved). This positively ensures that the worker won't try to run,
170+
* or even do ExecInitNode on, an unsafe subplan. That's important to
171+
* protect, eg, non-parallel-aware FDWs from getting into trouble.
172+
*/
173+
pstmt->subplans=NIL;
174+
foreach(lc,estate->es_plannedstmt->subplans)
175+
{
176+
Plan*subplan= (Plan*)lfirst(lc);
177+
178+
if (subplan&& !subplan->parallel_safe)
179+
subplan=NULL;
180+
pstmt->subplans=lappend(pstmt->subplans,subplan);
181+
}
182+
166183
pstmt->rewindPlanIDs=NULL;
167184
pstmt->rowMarks=NIL;
168185
pstmt->relationOids=NIL;

‎src/include/nodes/plannodes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ typedef struct PlannedStmt
6868
/* rtable indexes of non-leaf target relations for INSERT/UPDATE/DELETE */
6969
List*nonleafResultRelations;
7070

71-
List*subplans;/* Plan trees for SubPlan expressions */
71+
List*subplans;/* Plan trees for SubPlan expressions; note
72+
* that some could be NULL */
7273

7374
Bitmapset*rewindPlanIDs;/* indices of subplans that require REWIND */
7475

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp