Skip to content

Commit e2e433b

Browse files
committed
Fix segfault in ExplainNode() on a QE
A receiving Motion has no child PlanState when its child slice runs on another gang. ExplainNode() recursed into it anyway and crashed. Return early when planstate is NULL.
1 parent db9e849 commit e2e433b

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/backend/commands/explain.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ ExplainNode(PlanState *planstate, List *ancestors,
15401540
const char *relationship, const char *plan_name,
15411541
ExplainState *es)
15421542
{
1543-
Plan *plan = planstate->plan;
1543+
Plan *plan;
15441544
PlanState *parentplanstate;
15451545
ExecSlice *save_currentSlice = es->currentSlice; /* save */
15461546
const char *pname; /* node type name for text output */
@@ -1557,6 +1557,14 @@ ExplainNode(PlanState *planstate, List *ancestors,
15571557
int motion_recv;
15581558
int motion_snd;
15591559
ExecSlice *parentSlice = NULL;
1560+
/*
1561+
* Guard if subtree on QE lives in another slice
1562+
* and not instantiated here.
1563+
*/
1564+
if (planstate == NULL)
1565+
return;
1566+
1567+
plan = planstate->plan;
15601568

15611569
/* Remember who called us. */
15621570
parentplanstate = es->parentPlanState;
@@ -2945,8 +2953,11 @@ ExplainNode(PlanState *planstate, List *ancestors,
29452953
/* lefttree */
29462954
if (outerPlan(plan) && !skip_outer)
29472955
{
2948-
ExplainNode(outerPlanState(planstate), ancestors,
2949-
"Outer", NULL, es);
2956+
if (outerPlanState(planstate))
2957+
{
2958+
ExplainNode(outerPlanState(planstate), ancestors,
2959+
"Outer", NULL, es);
2960+
}
29502961
}
29512962
else if (skip_outer)
29522963
{

0 commit comments

Comments
 (0)