From: Tom Lane Date: Thu, 12 Dec 2002 16:16:58 +0000 (+0000) Subject: Back-patch fix to prevent core dump in EXPLAIN if optimizer has X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=b661c7fb6158f4564d65598e7464ad4881b901bf;p=users%2Fbernd%2Fpostgres.git Back-patch fix to prevent core dump in EXPLAIN if optimizer has simplified function call to a constant. (7.3 won't actually execute such a plan anyway, but core dump is bad regardless.) --- diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index 6ddf2e28b8..44ad03a673 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -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));