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.14 1998/01/20 05:03:54 momjian Exp $
13 * AUTHOR DATE MAJOR EVENT
14 * Andrew Yu Oct 26, 1994 file creation
16 *-------------------------------------------------------------------------
23 #include "access/printtup.h"
24 #include "nodes/pg_list.h"
25 #include "nodes/execnodes.h"
26 #include "nodes/parsenodes.h"
27 #include "nodes/print.h"
28 #include "parser/parsetree.h"
29 #include "access/heapam.h"
30 #include "utils/lsyscache.h"
31 #include "nodes/nodes.h"
32 #include "nodes/plannodes.h"
33 #include "parser/parse_relation.h"
34 #include "optimizer/clauses.h"
36 static char *plannode_type(Plan *p);
40 * print contents of Node to stdout
47 s = nodeToString(obj);
54 * pretty print hack extraordinaire. -ay 10/94
65 s = nodeToString(obj);
71 for (j = 0; j < indentLev * 3; j++)
75 for (; j < 75 && s[i] != '\0'; i++, j++)
81 if (j != indentLev * 3)
85 line[indentLev * 3] = '\0';
86 printf("%s}\n", line);
91 printf("%s}\n", line);
94 j = indentLev * 3 - 1; /* print the line before :
100 j = indentLev * 3 - 1;
104 /* !!! FALLS THROUGH */
109 printf("%s\n", line);
110 /* print the line before : and resets */
111 for (j = 0; j < indentLev * 3; j++)
123 printf("%s\n", line);
127 printf("%s\n", line);
135 * print contents of range table
138 print_rt(List *rtable)
143 printf("resno\trelname(refname)\trelid\tinFromCl\n");
144 printf("-----\t----------------\t-----\t--------\n");
147 RangeTblEntry *rte = lfirst(l);
149 printf("%d\t%s(%s)\t%d\t%d\t%s\n",
150 i, rte->relname, rte->refname, rte->relid,
152 (rte->inh ? "inh" : ""));
160 * print an expression
163 print_expr(Node *expr, List *rtable)
173 Var *var = (Var *) expr;
190 rt = rt_fetch(var->varno, rtable);
191 relname = rt->relname;
193 relname = rt->refname; /* table renamed */
194 attname = get_attname(rt->relid, var->varattno);
198 printf("%s.%s", relname, attname);
200 else if (IsA(expr, Expr))
202 Expr *e = (Expr *) expr;
204 if (is_opclause(expr))
208 print_expr((Node *) get_leftop(e), rtable);
209 opname = get_opname(((Oper *) e->oper)->opno);
210 printf(" %s ", opname);
211 print_expr((Node *) get_rightop(e), rtable);
220 printf("not an expr");
226 * temporary here. where is keys list of list??
229 print_keys(List *keys, List *rtable)
236 Node *var = lfirst((List *) lfirst(k));
238 print_expr(var, rtable);
247 * print targetlist in a more legible way.
250 print_tl(List *tlist, List *rtable)
257 TargetEntry *tle = lfirst(tl);
259 printf("\t%d %s\t", tle->resdom->resno, tle->resdom->resname);
260 if (tle->resdom->reskey != 0)
262 printf("(%d):\t", tle->resdom->reskey);
268 print_expr(tle->expr, rtable);
276 * print out the tuple with the given TupleTableSlot
279 print_slot(TupleTableSlot *slot)
283 printf("tuple is null.\n");
286 if (!slot->ttc_tupleDescriptor)
288 printf("no tuple descriptor.\n");
292 debugtup(slot->val, slot->ttc_tupleDescriptor);
296 plannode_type(Plan *p)
364 prints the ascii description of the plan nodes
365 does this recursively by doing a depth-first traversal of the
366 plan tree. for SeqScan and IndexScan, the name of the table is also
371 print_plan_recursive(Plan *p, Query *parsetree, int indentLevel, char *label)
378 for (i = 0; i < indentLevel; i++)
380 printf("%s%s :c=%.4f :s=%d :w=%d ", label, plannode_type(p),
381 p->cost, p->plan_size, p->plan_width);
382 if (IsA(p, Scan) ||IsA(p, SeqScan))
386 rte = rt_fetch(((Scan *) p)->scanrelid, parsetree->rtable);
387 StrNCpy(extraInfo, rte->relname, NAMEDATALEN);
389 else if (IsA(p, IndexScan))
392 ((RangeTblEntry *) (nth(((IndexScan *) p)->scan.scanrelid - 1,
393 parsetree->rtable)))->relname,
398 if (extraInfo[0] != '\0')
399 printf(" ( %s )\n", extraInfo);
402 print_plan_recursive(p->lefttree, parsetree, indentLevel + 3, "l: ");
403 print_plan_recursive(p->righttree, parsetree, indentLevel + 3, "r: ");
407 prints just the plan node types */
410 print_plan(Plan *p, Query *parsetree)
412 print_plan_recursive(p, parsetree, 0, "");