|
5 | 5 | * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
6 | 6 | * Portions Copyright (c) 1994-5, Regents of the University of California
|
7 | 7 | *
|
8 |
| - * $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.95 2002/12/06 19:28:03 tgl Exp $ |
| 8 | + * $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.96 2002/12/12 15:49:24 tgl Exp $ |
9 | 9 | *
|
10 | 10 | */
|
11 | 11 |
|
@@ -417,20 +417,27 @@ explain_outNode(StringInfo str,
|
417 | 417 | {
|
418 | 418 | RangeTblEntry *rte = rt_fetch(((Scan *) plan)->scanrelid,
|
419 | 419 | es->rtable);
|
420 |
| - Expr *expr; |
421 |
| - Func *funcnode; |
422 |
| - Oid funcid; |
423 | 420 | char *proname;
|
424 | 421 |
|
425 | 422 | /* Assert it's on a RangeFunction */
|
426 | 423 | Assert(rte->rtekind == RTE_FUNCTION);
|
427 | 424 |
|
428 |
| - expr = (Expr *) rte->funcexpr; |
429 |
| - funcnode = (Func *) expr->oper; |
430 |
| - funcid = funcnode->funcid; |
431 |
| - |
432 |
| - /* We only show the func name, not schema name */ |
433 |
| - proname = get_func_name(funcid); |
| 425 | + /* |
| 426 | + * If the expression is still a function call, we can get |
| 427 | + * the real name of the function. Otherwise, punt (this |
| 428 | + * can happen if the optimizer simplified away the function |
| 429 | + * call, for example). |
| 430 | + */ |
| 431 | + if (rte->funcexpr && IsA(rte->funcexpr, FuncExpr)) |
| 432 | + { |
| 433 | + FuncExpr *funcexpr = (FuncExpr *) rte->funcexpr; |
| 434 | + Oid funcid = funcexpr->funcid; |
| 435 | + |
| 436 | + /* We only show the func name, not schema name */ |
| 437 | + proname = get_func_name(funcid); |
| 438 | + } |
| 439 | + else |
| 440 | + proname = rte->eref->aliasname; |
434 | 441 |
|
435 | 442 | appendStringInfo(str, " on %s",
|
436 | 443 | quote_identifier(proname));
|
@@ -583,7 +590,7 @@ explain_outNode(StringInfo str,
|
583 | 590 | appendStringInfo(str, " InitPlan\n");
|
584 | 591 | foreach(lst, plan->initPlan)
|
585 | 592 | {
|
586 |
| - SubPlan *subplan = (SubPlan *) lfirst(lst); |
| 593 | + SubPlanExpr *subplan = (SubPlanExpr *) lfirst(lst); |
587 | 594 | SubPlanState *subplanstate = (SubPlanState *) lfirst(pslist);
|
588 | 595 |
|
589 | 596 | es->rtable = subplan->rtable;
|
@@ -683,7 +690,7 @@ explain_outNode(StringInfo str,
|
683 | 690 | foreach(lst, planstate->subPlan)
|
684 | 691 | {
|
685 | 692 | SubPlanState *sps = (SubPlanState *) lfirst(lst);
|
686 |
| - SubPlan *sp = (SubPlan *) sps->ps.plan; |
| 693 | + SubPlanExpr *sp = (SubPlanExpr *) sps->ps.plan; |
687 | 694 |
|
688 | 695 | es->rtable = sp->rtable;
|
689 | 696 | for (i = 0; i < indent; i++)
|
@@ -870,7 +877,7 @@ show_sort_keys(List *tlist, int nkeys, const char *qlabel,
|
870 | 877 | if (target->resdom->reskey == keyno)
|
871 | 878 | {
|
872 | 879 | /* Deparse the expression, showing any top-level cast */
|
873 |
| - exprstr = deparse_expression(target->expr, context, |
| 880 | + exprstr = deparse_expression((Node *) target->expr, context, |
874 | 881 | useprefix, true);
|
875 | 882 | /* And add to str */
|
876 | 883 | if (keyno > 1)
|
|
0 commit comments