1 /*-------------------------------------------------------------------------
4 * various print routines (used mostly for debugging)
6 * Copyright (c) 1994, Regents of the University of California
10 * $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.33 1999/11/23 20:06:53 momjian Exp $
13 * AUTHOR DATE MAJOR EVENT
14 * Andrew Yu Oct 26, 1994 file creation
16 *-------------------------------------------------------------------------
21 #include "access/printtup.h"
22 #include "nodes/print.h"
23 #include "optimizer/clauses.h"
24 #include "parser/parsetree.h"
25 #include "utils/lsyscache.h"
27 static char *plannode_type(Plan *p);
31 * print contents of Node to stdout
38 s = nodeToString(obj);
45 * pretty print hack extraordinaire. -ay 10/94
56 s = nodeToString(obj);
62 for (j = 0; j < indentLev * 3; j++)
64 for (; j < 75 && s[i] != '\0'; i++, j++)
70 if (j != indentLev * 3)
74 line[indentLev * 3] = '\0';
75 printf("%s}\n", line);
80 printf("%s}\n", line);
83 j = indentLev * 3 - 1; /* print the line before :
89 j = indentLev * 3 - 1;
93 /* !!! FALLS THROUGH */
99 /* print the line before : and resets */
100 for (j = 0; j < indentLev * 3; j++)
110 printf("%s\n", line);
113 printf("%s\n", line);
120 * print contents of range table
123 print_rt(List *rtable)
128 printf("resno\trelname(refname)\trelid\tinFromCl\n");
129 printf("-----\t----------------\t-----\t--------\n");
132 RangeTblEntry *rte = lfirst(l);
134 printf("%d\t%s(%s)\t%u\t%d\t%s\n",
135 i, rte->relname, rte->refname, rte->relid,
137 (rte->inh ? "inh" : ""));
145 * print an expression
148 print_expr(Node *expr, List *rtable)
158 Var *var = (Var *) expr;
175 rt = rt_fetch(var->varno, rtable);
176 relname = rt->relname;
178 relname = rt->refname; /* table renamed */
179 attname = get_attname(rt->relid, var->varattno);
183 printf("%s.%s", relname, attname);
185 else if (IsA(expr, Expr))
187 Expr *e = (Expr *) expr;
189 if (is_opclause(expr))
193 print_expr((Node *) get_leftop(e), rtable);
194 opname = get_opname(((Oper *) e->oper)->opno);
195 printf(" %s ", ((opname != NULL) ? opname : "(invalid operator)"));
196 print_expr((Node *) get_rightop(e), rtable);
202 printf("not an expr");
207 * pathkeys list of list of PathKeyItems
210 print_pathkeys(List *pathkeys, List *rtable)
218 List *pathkey = lfirst(i);
223 PathKeyItem *item = lfirst(k);
225 print_expr(item->key, rtable);
238 * print targetlist in a more legible way.
241 print_tl(List *tlist, List *rtable)
248 TargetEntry *tle = lfirst(tl);
250 printf("\t%d %s\t", tle->resdom->resno, tle->resdom->resname);
251 if (tle->resdom->reskey != 0)
252 printf("(%d):\t", tle->resdom->reskey);
255 print_expr(tle->expr, rtable);
263 * print out the tuple with the given TupleTableSlot
266 print_slot(TupleTableSlot *slot)
270 printf("tuple is null.\n");
273 if (!slot->ttc_tupleDescriptor)
275 printf("no tuple descriptor.\n");
279 debugtup(slot->val, slot->ttc_tupleDescriptor, NULL);
283 plannode_type(Plan *p)
351 prints the ascii description of the plan nodes
352 does this recursively by doing a depth-first traversal of the
353 plan tree. for SeqScan and IndexScan, the name of the table is also
358 print_plan_recursive(Plan *p, Query *parsetree, int indentLevel, char *label)
365 for (i = 0; i < indentLevel; i++)
367 printf("%s%s :c=%.4f :s=%d :w=%d ", label, plannode_type(p),
368 p->cost, p->plan_size, p->plan_width);
369 if (IsA(p, Scan) ||IsA(p, SeqScan))
373 rte = rt_fetch(((Scan *) p)->scanrelid, parsetree->rtable);
374 StrNCpy(extraInfo, rte->relname, NAMEDATALEN);
376 else if (IsA(p, IndexScan))
379 ((RangeTblEntry *) (nth(((IndexScan *) p)->scan.scanrelid - 1,
380 parsetree->rtable)))->relname,
385 if (extraInfo[0] != '\0')
386 printf(" ( %s )\n", extraInfo);
389 print_plan_recursive(p->lefttree, parsetree, indentLevel + 3, "l: ");
390 print_plan_recursive(p->righttree, parsetree, indentLevel + 3, "r: ");
392 if (nodeTag(p) == T_Append)
396 Append *appendplan = (Append *) p;
398 foreach(lst, appendplan->appendplans)
400 Plan *subnode = (Plan *) lfirst(lst);
403 * I don't think we need to fiddle with the range table here,
406 print_plan_recursive(subnode, parsetree, indentLevel + 3, "a: ");
414 prints just the plan node types */
417 print_plan(Plan *p, Query *parsetree)
419 print_plan_recursive(p, parsetree, 0, "");