PostgreSQL Source Code git master
Loading...
Searching...
No Matches
print.c File Reference
#include "postgres.h"
#include "access/printtup.h"
#include "lib/stringinfo.h"
#include "nodes/nodeFuncs.h"
#include "nodes/pathnodes.h"
#include "nodes/print.h"
#include "parser/parsetree.h"
#include "utils/lsyscache.h"
Include dependency graph for print.c:

Go to the source code of this file.

Macros

#define LINELEN   78
 
#define INDENTSTOP   3
 
#define MAXINDENT   60
 
#define LINELEN   78
 

Functions

void print (const void *obj)
 
void pprint (const void *obj)
 
void elog_node_display (int lev, const char *title, const void *obj, bool pretty)
 
charformat_node_dump (const char *dump)
 
charpretty_format_node_dump (const char *dump)
 
void print_rt (const List *rtable)
 
void print_expr (const Node *expr, const List *rtable)
 
void print_pathkeys (const List *pathkeys, const List *rtable)
 
void print_tl (const List *tlist, const List *rtable)
 
void print_slot (TupleTableSlot *slot)
 

Macro Definition Documentation

◆ INDENTSTOP

#define INDENTSTOP   3

◆ LINELEN [1/2]

#define LINELEN   78

◆ LINELEN [2/2]

#define LINELEN   78

◆ MAXINDENT

#define MAXINDENT   60

Function Documentation

◆ elog_node_display()

void elog_node_display ( int  lev,
const char title,
const void obj,
bool  pretty 
)

Definition at line 72 of file print.c.

73{
74 char *s;
75 char *f;
76
78 if (pretty)
80 else
81 f = format_node_dump(s);
82 pfree(s);
84 (errmsg_internal("%s:", title),
85 errdetail_internal("%s", f)));
86 pfree(f);
87}
char * pretty_format_node_dump(const char *dump)
Definition print.c:151
char * format_node_dump(const char *dump)
Definition print.c:97
int int errdetail_internal(const char *fmt,...) pg_attribute_printf(1
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define ereport(elevel,...)
Definition elog.h:150
void pfree(void *pointer)
Definition mcxt.c:1616
char * nodeToStringWithLocations(const void *obj)
Definition outfuncs.c:817
static int fb(int x)

References ereport, errdetail_internal(), errmsg_internal(), fb(), format_node_dump(), nodeToStringWithLocations(), pfree(), and pretty_format_node_dump().

Referenced by pg_parse_query(), pg_plan_query(), and pg_rewrite_query().

◆ format_node_dump()

char * format_node_dump ( const char dump)

Definition at line 97 of file print.c.

98{
99#define LINELEN 78
100 char line[LINELEN + 1];
102 int i;
103 int j;
104 int k;
105
107 i = 0;
108 for (;;)
109 {
110 for (j = 0; j < LINELEN && dump[i] != '\0'; i++, j++)
111 line[j] = dump[i];
112 if (dump[i] == '\0')
113 break;
114 if (dump[i] == ' ')
115 {
116 /* ok to break at adjacent space */
117 i++;
118 }
119 else
120 {
121 for (k = j - 1; k > 0; k--)
122 if (line[k] == ' ')
123 break;
124 if (k > 0)
125 {
126 /* back up; will reprint all after space */
127 i -= (j - k - 1);
128 j = k;
129 }
130 }
131 line[j] = '\0';
132 appendStringInfo(&str, "%s\n", line);
133 }
134 if (j > 0)
135 {
136 line[j] = '\0';
137 appendStringInfo(&str, "%s\n", line);
138 }
139 return str.data;
140#undef LINELEN
141}
#define LINELEN
const char * str
int j
Definition isn.c:78
int i
Definition isn.c:77
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void initStringInfo(StringInfo str)
Definition stringinfo.c:97

References appendStringInfo(), i, initStringInfo(), j, LINELEN, and str.

Referenced by elog_node_display(), and print().

◆ pprint()

void pprint ( const void obj)

Definition at line 54 of file print.c.

55{
56 char *s;
57 char *f;
58
61 pfree(s);
62 printf("%s\n", f);
63 fflush(stdout);
64 pfree(f);
65}
#define printf(...)
Definition port.h:266

References fb(), nodeToStringWithLocations(), pfree(), pretty_format_node_dump(), and printf.

Referenced by generate_partitionwise_join_paths(), preprocess_expression(), set_rel_pathlist(), and standard_join_search().

◆ pretty_format_node_dump()

char * pretty_format_node_dump ( const char dump)

Definition at line 151 of file print.c.

152{
153#define INDENTSTOP 3
154#define MAXINDENT 60
155#define LINELEN 78
156 char line[LINELEN + 1];
158 int indentLev;
159 int indentDist;
160 int i;
161 int j;
162
164 indentLev = 0; /* logical indent level */
165 indentDist = 0; /* physical indent distance */
166 i = 0;
167 for (;;)
168 {
169 for (j = 0; j < indentDist; j++)
170 line[j] = ' ';
171 for (; j < LINELEN && dump[i] != '\0'; i++, j++)
172 {
173 line[j] = dump[i];
174 switch (line[j])
175 {
176 case '}':
177 if (j != indentDist)
178 {
179 /* print data before the } */
180 line[j] = '\0';
181 appendStringInfo(&str, "%s\n", line);
182 }
183 /* print the } at indentDist */
184 line[indentDist] = '}';
185 line[indentDist + 1] = '\0';
186 appendStringInfo(&str, "%s\n", line);
187 /* outdent */
188 if (indentLev > 0)
189 {
190 indentLev--;
192 }
193 j = indentDist - 1;
194 /* j will equal indentDist on next loop iteration */
195 /* suppress whitespace just after } */
196 while (dump[i + 1] == ' ')
197 i++;
198 break;
199 case ')':
200 /* force line break after ), unless another ) follows */
201 if (dump[i + 1] != ')')
202 {
203 line[j + 1] = '\0';
204 appendStringInfo(&str, "%s\n", line);
205 j = indentDist - 1;
206 while (dump[i + 1] == ' ')
207 i++;
208 }
209 break;
210 case '{':
211 /* force line break before { */
212 if (j != indentDist)
213 {
214 line[j] = '\0';
215 appendStringInfo(&str, "%s\n", line);
216 }
217 /* indent */
218 indentLev++;
220 for (j = 0; j < indentDist; j++)
221 line[j] = ' ';
222 line[j] = dump[i];
223 break;
224 case ':':
225 /* force line break before : */
226 if (j != indentDist)
227 {
228 line[j] = '\0';
229 appendStringInfo(&str, "%s\n", line);
230 }
231 j = indentDist;
232 line[j] = dump[i];
233 break;
234 }
235 }
236 line[j] = '\0';
237 if (dump[i] == '\0')
238 break;
239 appendStringInfo(&str, "%s\n", line);
240 }
241 if (j > 0)
242 appendStringInfo(&str, "%s\n", line);
243 return str.data;
244#undef INDENTSTOP
245#undef MAXINDENT
246#undef LINELEN
247}
#define MAXINDENT
#define INDENTSTOP
#define Min(x, y)
Definition c.h:1093

References appendStringInfo(), fb(), i, INDENTSTOP, initStringInfo(), j, LINELEN, MAXINDENT, Min, and str.

Referenced by elog_node_display(), and pprint().

◆ print()

void print ( const void obj)

Definition at line 36 of file print.c.

37{
38 char *s;
39 char *f;
40
42 f = format_node_dump(s);
43 pfree(s);
44 printf("%s\n", f);
45 fflush(stdout);
46 pfree(f);
47}

References fb(), format_node_dump(), nodeToStringWithLocations(), pfree(), and printf.

Referenced by ecpg_free_params(), pgp_session_data::main(), oauth_server::main(), and generate_unaccent_rules::print_record().

◆ print_expr()

void print_expr ( const Node expr,
const List rtable 
)

Definition at line 329 of file print.c.

330{
331 if (expr == NULL)
332 {
333 printf("<>");
334 return;
335 }
336
337 if (IsA(expr, Var))
338 {
339 const Var *var = (const Var *) expr;
340 char *relname,
341 *attname;
342
343 switch (var->varno)
344 {
345 case INNER_VAR:
346 relname = "INNER";
347 attname = "?";
348 break;
349 case OUTER_VAR:
350 relname = "OUTER";
351 attname = "?";
352 break;
353 case INDEX_VAR:
354 relname = "INDEX";
355 attname = "?";
356 break;
357 default:
358 {
360
361 Assert(var->varno > 0 &&
362 (int) var->varno <= list_length(rtable));
363 rte = rt_fetch(var->varno, rtable);
364 relname = rte->eref->aliasname;
366 }
367 break;
368 }
369 printf("%s.%s", relname, attname);
370 }
371 else if (IsA(expr, Const))
372 {
373 const Const *c = (const Const *) expr;
374 Oid typoutput;
375 bool typIsVarlena;
376 char *outputstr;
377
378 if (c->constisnull)
379 {
380 printf("NULL");
381 return;
382 }
383
384 getTypeOutputInfo(c->consttype,
385 &typoutput, &typIsVarlena);
386
387 outputstr = OidOutputFunctionCall(typoutput, c->constvalue);
388 printf("%s", outputstr);
390 }
391 else if (IsA(expr, OpExpr))
392 {
393 const OpExpr *e = (const OpExpr *) expr;
394 char *opname;
395
396 opname = get_opname(e->opno);
397 if (list_length(e->args) > 1)
398 {
399 print_expr(get_leftop((const Expr *) e), rtable);
400 printf(" %s ", ((opname != NULL) ? opname : "(invalid operator)"));
401 print_expr(get_rightop((const Expr *) e), rtable);
402 }
403 else
404 {
405 printf("%s ", ((opname != NULL) ? opname : "(invalid operator)"));
406 print_expr(get_leftop((const Expr *) e), rtable);
407 }
408 }
409 else if (IsA(expr, FuncExpr))
410 {
411 const FuncExpr *e = (const FuncExpr *) expr;
412 char *funcname;
413 ListCell *l;
414
415 funcname = get_func_name(e->funcid);
416 printf("%s(", ((funcname != NULL) ? funcname : "(invalid function)"));
417 foreach(l, e->args)
418 {
419 print_expr(lfirst(l), rtable);
420 if (lnext(e->args, l))
421 printf(",");
422 }
423 printf(")");
424 }
425 else
426 printf("unknown expr");
427}
void print_expr(const Node *expr, const List *rtable)
Definition print.c:329
#define Assert(condition)
Definition c.h:945
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition fmgr.c:1764
#define funcname
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
Definition lsyscache.c:3129
char * get_opname(Oid opno)
Definition lsyscache.c:1530
char * get_func_name(Oid funcid)
Definition lsyscache.c:1828
static Node * get_rightop(const void *clause)
Definition nodeFuncs.h:95
static Node * get_leftop(const void *clause)
Definition nodeFuncs.h:83
#define IsA(nodeptr, _type_)
Definition nodes.h:164
char * get_rte_attribute_name(RangeTblEntry *rte, AttrNumber attnum)
#define rt_fetch(rangetable_index, rangetable)
Definition parsetree.h:31
NameData attname
NameData relname
Definition pg_class.h:40
#define lfirst(lc)
Definition pg_list.h:172
static int list_length(const List *l)
Definition pg_list.h:152
static ListCell * lnext(const List *l, const ListCell *c)
Definition pg_list.h:343
unsigned int Oid
char * c
e
#define OUTER_VAR
Definition primnodes.h:244
#define INNER_VAR
Definition primnodes.h:243
#define INDEX_VAR
Definition primnodes.h:245
AttrNumber varattno
Definition primnodes.h:275
int varno
Definition primnodes.h:270

References Assert, attname, fb(), funcname, get_func_name(), get_leftop(), get_opname(), get_rightop(), get_rte_attribute_name(), getTypeOutputInfo(), INDEX_VAR, INNER_VAR, IsA, lfirst, list_length(), lnext(), OidOutputFunctionCall(), OUTER_VAR, pfree(), print_expr(), printf, relname, rt_fetch, Var::varattno, and Var::varno.

Referenced by print_expr(), print_pathkeys(), and print_tl().

◆ print_pathkeys()

void print_pathkeys ( const List pathkeys,
const List rtable 
)

Definition at line 434 of file print.c.

435{
436 const ListCell *i;
437
438 printf("(");
439 foreach(i, pathkeys)
440 {
443 ListCell *k;
444 bool first = true;
445
446 eclass = pathkey->pk_eclass;
447 /* chase up, in case pathkey is non-canonical */
448 while (eclass->ec_merged)
449 eclass = eclass->ec_merged;
450
451 printf("(");
452 foreach(k, eclass->ec_members)
453 {
455
456 if (first)
457 first = false;
458 else
459 printf(", ");
460 print_expr((Node *) mem->em_expr, rtable);
461 }
462 printf(")");
463 if (lnext(pathkeys, i))
464 printf(", ");
465 }
466 printf(")\n");
467}
static struct cvec * eclass(struct vars *v, chr c, int cases)
Definition nodes.h:135

References eclass(), fb(), i, lfirst, lnext(), print_expr(), and printf.

◆ print_rt()

void print_rt ( const List rtable)

Definition at line 254 of file print.c.

255{
256 const ListCell *l;
257 int i = 1;
258
259 printf("resno\trefname \trelid\tinFromCl\n");
260 printf("-----\t---------\t-----\t--------\n");
261 foreach(l, rtable)
262 {
264
265 switch (rte->rtekind)
266 {
267 case RTE_RELATION:
268 printf("%d\t%s\t%u\t%c",
269 i, rte->eref->aliasname, rte->relid, rte->relkind);
270 break;
271 case RTE_SUBQUERY:
272 printf("%d\t%s\t[subquery]",
273 i, rte->eref->aliasname);
274 break;
275 case RTE_JOIN:
276 printf("%d\t%s\t[join]",
277 i, rte->eref->aliasname);
278 break;
279 case RTE_FUNCTION:
280 printf("%d\t%s\t[rangefunction]",
281 i, rte->eref->aliasname);
282 break;
283 case RTE_TABLEFUNC:
284 printf("%d\t%s\t[table function]",
285 i, rte->eref->aliasname);
286 break;
287 case RTE_VALUES:
288 printf("%d\t%s\t[values list]",
289 i, rte->eref->aliasname);
290 break;
291 case RTE_CTE:
292 printf("%d\t%s\t[cte]",
293 i, rte->eref->aliasname);
294 break;
296 printf("%d\t%s\t[tuplestore]",
297 i, rte->eref->aliasname);
298 break;
299 case RTE_RESULT:
300 printf("%d\t%s\t[result]",
301 i, rte->eref->aliasname);
302 break;
303 case RTE_GROUP:
304 printf("%d\t%s\t[group]",
305 i, rte->eref->aliasname);
306 break;
307 case RTE_GRAPH_TABLE:
308 printf("%d\t%s\t[graph table]",
309 i, rte->eref->aliasname);
310 break;
311 default:
312 printf("%d\t%s\t[unknown rtekind]",
313 i, rte->eref->aliasname);
314 }
315
316 printf("\t%s\t%s\n",
317 (rte->inh ? "inh" : ""),
318 (rte->inFromCl ? "inFromCl" : ""));
319 i++;
320 }
321}
@ RTE_JOIN
@ RTE_CTE
@ RTE_NAMEDTUPLESTORE
@ RTE_VALUES
@ RTE_SUBQUERY
@ RTE_RESULT
@ RTE_FUNCTION
@ RTE_TABLEFUNC
@ RTE_GROUP
@ RTE_GRAPH_TABLE
@ RTE_RELATION

References fb(), i, lfirst, printf, RTE_CTE, RTE_FUNCTION, RTE_GRAPH_TABLE, RTE_GROUP, RTE_JOIN, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, and RTE_VALUES.

◆ print_slot()

void print_slot ( TupleTableSlot slot)

Definition at line 500 of file print.c.

501{
502 if (TupIsNull(slot))
503 {
504 printf("tuple is null.\n");
505 return;
506 }
507 if (!slot->tts_tupleDescriptor)
508 {
509 printf("no tuple descriptor.\n");
510 return;
511 }
512
513 debugtup(slot, NULL);
514}
bool debugtup(TupleTableSlot *slot, DestReceiver *self)
Definition printtup.c:463
TupleDesc tts_tupleDescriptor
Definition tuptable.h:129
#define TupIsNull(slot)
Definition tuptable.h:325

References debugtup(), fb(), printf, TupleTableSlot::tts_tupleDescriptor, and TupIsNull.

◆ print_tl()

void print_tl ( const List tlist,
const List rtable 
)

Definition at line 474 of file print.c.

475{
476 const ListCell *tl;
477
478 printf("(\n");
479 foreach(tl, tlist)
480 {
482
483 printf("\t%d %s\t", tle->resno,
484 tle->resname ? tle->resname : "<null>");
485 if (tle->ressortgroupref != 0)
486 printf("(%u):\t", tle->ressortgroupref);
487 else
488 printf(" :\t");
489 print_expr((Node *) tle->expr, rtable);
490 printf("\n");
491 }
492 printf(")\n");
493}

References fb(), lfirst, print_expr(), and printf.