This is an automated email from the ASF dual-hosted git repository.

leborchuk pushed a commit to branch REL_2_STABLE
in repository https://gitbox.apache.org/repos/asf/cloudberry.git


The following commit(s) were added to refs/heads/REL_2_STABLE by this push:
     new ef0b0248533 fix: ExplainNode guard against NULL planstate on QE (#1865)
ef0b0248533 is described below

commit ef0b0248533c99436d1bccda8443a4f4f15a5056
Author: Aleksey Rozhok <[email protected]>
AuthorDate: Thu Jul 30 14:41:49 2026 +0300

    fix: ExplainNode guard against NULL planstate on QE (#1865)
    
    * 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.
    
    ---------
    
    Co-authored-by: Copilot Autofix powered by AI 
<[email protected]>
---
 src/backend/commands/explain.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 0d63d374128..9cfd09d5f7c 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -1540,7 +1540,7 @@ ExplainNode(PlanState *planstate, List *ancestors,
                        const char *relationship, const char *plan_name,
                        ExplainState *es)
 {
-       Plan       *plan = planstate->plan;
+       Plan       *plan;
        PlanState  *parentplanstate;
        ExecSlice  *save_currentSlice = es->currentSlice;    /* save */
        const char *pname;                      /* node type name for text 
output */
@@ -1557,6 +1557,13 @@ ExplainNode(PlanState *planstate, List *ancestors,
        int                     motion_recv;
        int                     motion_snd;
        ExecSlice  *parentSlice = NULL;
+       /*
+        * Guard against the case where a subtree on the QE lives in another 
slice
+        * and is not instantiated in this slice.
+        */
+       if (planstate == NULL)
+               return;
+       plan = planstate->plan;
 
        /* Remember who called us. */
        parentplanstate = es->parentPlanState;
@@ -2945,8 +2952,11 @@ ExplainNode(PlanState *planstate, List *ancestors,
        /* lefttree */
        if (outerPlan(plan) && !skip_outer)
        {
-               ExplainNode(outerPlanState(planstate), ancestors,
-                                       "Outer", NULL, es);
+               if (outerPlanState(planstate))
+               {
+                       ExplainNode(outerPlanState(planstate), ancestors, 
+                                               "Outer", NULL, es);
+               }
        }
     else if (skip_outer)
     {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to