Back-patch fix to prevent core dump in EXPLAIN if optimizer has
authorTom Lane <[email protected]>
Thu, 12 Dec 2002 16:16:58 +0000 (16:16 +0000)
committerTom Lane <[email protected]>
Thu, 12 Dec 2002 16:16:58 +0000 (16:16 +0000)
simplified function call to a constant.  (7.3 won't actually execute
such a plan anyway, but core dump is bad regardless.)

src/backend/commands/explain.c

index 6ddf2e28b8a162bbb263af0ea866184a7677f4d8..44ad03a6733dbe1fa4615f20d57a9c2350776e7e 100644 (file)
@@ -367,19 +367,28 @@ explain_outNode(StringInfo str, Plan *plan, Plan *outer_plan,
                                RangeTblEntry *rte = rt_fetch(((Scan *) plan)->scanrelid,
                                                                                          es->rtable);
                                Expr       *expr;
-                               Func       *funcnode;
-                               Oid                     funcid;
                                char       *proname;
 
                                /* Assert it's on a RangeFunction */
                                Assert(rte->rtekind == RTE_FUNCTION);
 
+                               /*
+                                * If the expression is still a function call, we can get
+                                * the real name of the function.  Otherwise, punt (this
+                                * can happen if the optimizer simplified away the function
+                                * call, for example).
+                                */
                                expr = (Expr *) rte->funcexpr;
-                               funcnode = (Func *) expr->oper;
-                               funcid = funcnode->funcid;
-
-                               /* We only show the func name, not schema name */
-                               proname = get_func_name(funcid);
+                               if (expr && IsA(expr, Expr) && expr->opType == FUNC_EXPR)
+                               {
+                                       Func       *funcnode = (Func *) expr->oper;
+                                       Oid                     funcid = funcnode->funcid;
+
+                                       /* We only show the func name, not schema name */
+                                       proname = get_func_name(funcid);
+                               }
+                               else
+                                       proname = rte->eref->aliasname;
 
                                appendStringInfo(str, " on %s",
                                                                 quote_identifier(proname));