]> granicus.if.org Git - postgresql/blob - src/backend/nodes/outfuncs.c
e697196a28767be4251a11b512dd6ffe9b2baa74
[postgresql] / src / backend / nodes / outfuncs.c
1 /*-------------------------------------------------------------------------
2  *
3  * outfuncs.c
4  *        Output functions for Postgres tree nodes.
5  *
6  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  *        $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.224 2004/01/04 00:07:32 tgl Exp $
12  *
13  * NOTES
14  *        Every node type that can appear in stored rules' parsetrees *must*
15  *        have an output function defined here (as well as an input function
16  *        in readfuncs.c).      For use in debugging, we also provide output
17  *        functions for nodes that appear in raw parsetrees, path, and plan trees.
18  *        These nodes however need not have input functions.
19  *
20  *-------------------------------------------------------------------------
21  */
22 #include "postgres.h"
23
24 #include <ctype.h>
25
26 #include "lib/stringinfo.h"
27 #include "nodes/parsenodes.h"
28 #include "nodes/plannodes.h"
29 #include "nodes/relation.h"
30 #include "utils/datum.h"
31
32
33 /*
34  * Macros to simplify output of different kinds of fields.      Use these
35  * wherever possible to reduce the chance for silly typos.      Note that these
36  * hard-wire conventions about the names of the local variables in an Out
37  * routine.
38  */
39
40 /* Write the label for the node type */
41 #define WRITE_NODE_TYPE(nodelabel) \
42         appendStringInfoString(str, nodelabel)
43
44 /* Write an integer field (anything written as ":fldname %d") */
45 #define WRITE_INT_FIELD(fldname) \
46         appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname)
47
48 /* Write an unsigned integer field (anything written as ":fldname %u") */
49 #define WRITE_UINT_FIELD(fldname) \
50         appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
51
52 /* Write an OID field (don't hard-wire assumption that OID is same as uint) */
53 #define WRITE_OID_FIELD(fldname) \
54         appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
55
56 /* Write a long-integer field */
57 #define WRITE_LONG_FIELD(fldname) \
58         appendStringInfo(str, " :" CppAsString(fldname) " %ld", node->fldname)
59
60 /* Write a char field (ie, one ascii character) */
61 #define WRITE_CHAR_FIELD(fldname) \
62         appendStringInfo(str, " :" CppAsString(fldname) " %c", node->fldname)
63
64 /* Write an enumerated-type field as an integer code */
65 #define WRITE_ENUM_FIELD(fldname, enumtype) \
66         appendStringInfo(str, " :" CppAsString(fldname) " %d", \
67                                          (int) node->fldname)
68
69 /* Write a float field --- caller must give format to define precision */
70 #define WRITE_FLOAT_FIELD(fldname,format) \
71         appendStringInfo(str, " :" CppAsString(fldname) " " format, node->fldname)
72
73 /* Write a boolean field */
74 #define WRITE_BOOL_FIELD(fldname) \
75         appendStringInfo(str, " :" CppAsString(fldname) " %s", \
76                                          booltostr(node->fldname))
77
78 /* Write a character-string (possibly NULL) field */
79 #define WRITE_STRING_FIELD(fldname) \
80         (appendStringInfo(str, " :" CppAsString(fldname) " "), \
81          _outToken(str, node->fldname))
82
83 /* Write a Node field */
84 #define WRITE_NODE_FIELD(fldname) \
85         (appendStringInfo(str, " :" CppAsString(fldname) " "), \
86          _outNode(str, node->fldname))
87
88 /* Write an integer-list field */
89 #define WRITE_INTLIST_FIELD(fldname) \
90         (appendStringInfo(str, " :" CppAsString(fldname) " "), \
91          _outIntList(str, node->fldname))
92
93 /* Write an OID-list field */
94 #define WRITE_OIDLIST_FIELD(fldname) \
95         (appendStringInfo(str, " :" CppAsString(fldname) " "), \
96          _outOidList(str, node->fldname))
97
98 /* Write a bitmapset field */
99 #define WRITE_BITMAPSET_FIELD(fldname) \
100         (appendStringInfo(str, " :" CppAsString(fldname) " "), \
101          _outBitmapset(str, node->fldname))
102
103
104 #define booltostr(x)  ((x) ? "true" : "false")
105
106 static void _outNode(StringInfo str, void *obj);
107
108
109 /*
110  * _outToken
111  *        Convert an ordinary string (eg, an identifier) into a form that
112  *        will be decoded back to a plain token by read.c's functions.
113  *
114  *        If a null or empty string is given, it is encoded as "<>".
115  */
116 static void
117 _outToken(StringInfo str, char *s)
118 {
119         if (s == NULL || *s == '\0')
120         {
121                 appendStringInfo(str, "<>");
122                 return;
123         }
124
125         /*
126          * Look for characters or patterns that are treated specially by
127          * read.c (either in pg_strtok() or in nodeRead()), and therefore need
128          * a protective backslash.
129          */
130         /* These characters only need to be quoted at the start of the string */
131         if (*s == '<' ||
132                 *s == '\"' ||
133                 *s == '@' ||
134                 isdigit((unsigned char) *s) ||
135                 ((*s == '+' || *s == '-') &&
136                  (isdigit((unsigned char) s[1]) || s[1] == '.')))
137                 appendStringInfoChar(str, '\\');
138         while (*s)
139         {
140                 /* These chars must be backslashed anywhere in the string */
141                 if (*s == ' ' || *s == '\n' || *s == '\t' ||
142                         *s == '(' || *s == ')' || *s == '{' || *s == '}' ||
143                         *s == '\\')
144                         appendStringInfoChar(str, '\\');
145                 appendStringInfoChar(str, *s++);
146         }
147 }
148
149 /*
150  * _outIntList -
151  *         converts a List of integers
152  */
153 static void
154 _outIntList(StringInfo str, List *list)
155 {
156         List       *l;
157
158         appendStringInfoChar(str, '(');
159         foreach(l, list)
160                 appendStringInfo(str, " %d", lfirsti(l));
161         appendStringInfoChar(str, ')');
162 }
163
164 /*
165  * _outOidList -
166  *         converts a List of OIDs
167  */
168 static void
169 _outOidList(StringInfo str, List *list)
170 {
171         List       *l;
172
173         appendStringInfoChar(str, '(');
174         foreach(l, list)
175                 appendStringInfo(str, " %u", lfirsto(l));
176         appendStringInfoChar(str, ')');
177 }
178
179 /*
180  * _outBitmapset -
181  *         converts a bitmap set of integers
182  *
183  * Note: for historical reasons, the output is formatted exactly like
184  * an integer List would be.
185  */
186 static void
187 _outBitmapset(StringInfo str, Bitmapset *bms)
188 {
189         Bitmapset  *tmpset;
190         int                     x;
191
192         appendStringInfoChar(str, '(');
193         tmpset = bms_copy(bms);
194         while ((x = bms_first_member(tmpset)) >= 0)
195                 appendStringInfo(str, " %d", x);
196         bms_free(tmpset);
197         appendStringInfoChar(str, ')');
198 }
199
200 /*
201  * Print the value of a Datum given its type.
202  */
203 static void
204 _outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
205 {
206         Size            length,
207                                 i;
208         char       *s;
209
210         length = datumGetSize(value, typbyval, typlen);
211
212         if (typbyval)
213         {
214                 s = (char *) (&value);
215                 appendStringInfo(str, "%u [ ", (unsigned int) length);
216                 for (i = 0; i < (Size) sizeof(Datum); i++)
217                         appendStringInfo(str, "%d ", (int) (s[i]));
218                 appendStringInfo(str, "]");
219         }
220         else
221         {
222                 s = (char *) DatumGetPointer(value);
223                 if (!PointerIsValid(s))
224                         appendStringInfo(str, "0 [ ]");
225                 else
226                 {
227                         appendStringInfo(str, "%u [ ", (unsigned int) length);
228                         for (i = 0; i < length; i++)
229                                 appendStringInfo(str, "%d ", (int) (s[i]));
230                         appendStringInfo(str, "]");
231                 }
232         }
233 }
234
235
236 /*
237  *      Stuff from plannodes.h
238  */
239
240 /*
241  * print the basic stuff of all nodes that inherit from Plan
242  */
243 static void
244 _outPlanInfo(StringInfo str, Plan *node)
245 {
246         WRITE_FLOAT_FIELD(startup_cost, "%.2f");
247         WRITE_FLOAT_FIELD(total_cost, "%.2f");
248         WRITE_FLOAT_FIELD(plan_rows, "%.0f");
249         WRITE_INT_FIELD(plan_width);
250         WRITE_NODE_FIELD(targetlist);
251         WRITE_NODE_FIELD(qual);
252         WRITE_NODE_FIELD(lefttree);
253         WRITE_NODE_FIELD(righttree);
254         WRITE_NODE_FIELD(initPlan);
255         WRITE_BITMAPSET_FIELD(extParam);
256         WRITE_BITMAPSET_FIELD(allParam);
257         WRITE_INT_FIELD(nParamExec);
258 }
259
260 /*
261  * print the basic stuff of all nodes that inherit from Scan
262  */
263 static void
264 _outScanInfo(StringInfo str, Scan *node)
265 {
266         _outPlanInfo(str, (Plan *) node);
267
268         WRITE_UINT_FIELD(scanrelid);
269 }
270
271 /*
272  * print the basic stuff of all nodes that inherit from Join
273  */
274 static void
275 _outJoinPlanInfo(StringInfo str, Join *node)
276 {
277         _outPlanInfo(str, (Plan *) node);
278
279         WRITE_ENUM_FIELD(jointype, JoinType);
280         WRITE_NODE_FIELD(joinqual);
281 }
282
283
284 static void
285 _outPlan(StringInfo str, Plan *node)
286 {
287         WRITE_NODE_TYPE("PLAN");
288
289         _outPlanInfo(str, (Plan *) node);
290 }
291
292 static void
293 _outResult(StringInfo str, Result *node)
294 {
295         WRITE_NODE_TYPE("RESULT");
296
297         _outPlanInfo(str, (Plan *) node);
298
299         WRITE_NODE_FIELD(resconstantqual);
300 }
301
302 static void
303 _outAppend(StringInfo str, Append *node)
304 {
305         WRITE_NODE_TYPE("APPEND");
306
307         _outPlanInfo(str, (Plan *) node);
308
309         WRITE_NODE_FIELD(appendplans);
310         WRITE_BOOL_FIELD(isTarget);
311 }
312
313 static void
314 _outScan(StringInfo str, Scan *node)
315 {
316         WRITE_NODE_TYPE("SCAN");
317
318         _outScanInfo(str, (Scan *) node);
319 }
320
321 static void
322 _outSeqScan(StringInfo str, SeqScan *node)
323 {
324         WRITE_NODE_TYPE("SEQSCAN");
325
326         _outScanInfo(str, (Scan *) node);
327 }
328
329 static void
330 _outIndexScan(StringInfo str, IndexScan *node)
331 {
332         WRITE_NODE_TYPE("INDEXSCAN");
333
334         _outScanInfo(str, (Scan *) node);
335
336         WRITE_OIDLIST_FIELD(indxid);
337         WRITE_NODE_FIELD(indxqual);
338         WRITE_NODE_FIELD(indxqualorig);
339         /* this can become WRITE_NODE_FIELD when intlists are normal objects: */
340         {
341                 List    *tmp;
342
343                 appendStringInfo(str, " :indxstrategy ");
344                 foreach(tmp, node->indxstrategy)
345                 {
346                         _outIntList(str, lfirst(tmp));
347                 }
348         }
349         /* this can become WRITE_NODE_FIELD when OID lists are normal objects: */
350         {
351                 List    *tmp;
352
353                 appendStringInfo(str, " :indxsubtype ");
354                 foreach(tmp, node->indxsubtype)
355                 {
356                         _outOidList(str, lfirst(tmp));
357                 }
358         }
359         WRITE_ENUM_FIELD(indxorderdir, ScanDirection);
360 }
361
362 static void
363 _outTidScan(StringInfo str, TidScan *node)
364 {
365         WRITE_NODE_TYPE("TIDSCAN");
366
367         _outScanInfo(str, (Scan *) node);
368
369         WRITE_NODE_FIELD(tideval);
370 }
371
372 static void
373 _outSubqueryScan(StringInfo str, SubqueryScan *node)
374 {
375         WRITE_NODE_TYPE("SUBQUERYSCAN");
376
377         _outScanInfo(str, (Scan *) node);
378
379         WRITE_NODE_FIELD(subplan);
380 }
381
382 static void
383 _outFunctionScan(StringInfo str, FunctionScan *node)
384 {
385         WRITE_NODE_TYPE("FUNCTIONSCAN");
386
387         _outScanInfo(str, (Scan *) node);
388 }
389
390 static void
391 _outJoin(StringInfo str, Join *node)
392 {
393         WRITE_NODE_TYPE("JOIN");
394
395         _outJoinPlanInfo(str, (Join *) node);
396 }
397
398 static void
399 _outNestLoop(StringInfo str, NestLoop *node)
400 {
401         WRITE_NODE_TYPE("NESTLOOP");
402
403         _outJoinPlanInfo(str, (Join *) node);
404 }
405
406 static void
407 _outMergeJoin(StringInfo str, MergeJoin *node)
408 {
409         WRITE_NODE_TYPE("MERGEJOIN");
410
411         _outJoinPlanInfo(str, (Join *) node);
412
413         WRITE_NODE_FIELD(mergeclauses);
414 }
415
416 static void
417 _outHashJoin(StringInfo str, HashJoin *node)
418 {
419         WRITE_NODE_TYPE("HASHJOIN");
420
421         _outJoinPlanInfo(str, (Join *) node);
422
423         WRITE_NODE_FIELD(hashclauses);
424 }
425
426 static void
427 _outAgg(StringInfo str, Agg *node)
428 {
429         WRITE_NODE_TYPE("AGG");
430
431         _outPlanInfo(str, (Plan *) node);
432
433         WRITE_ENUM_FIELD(aggstrategy, AggStrategy);
434         WRITE_INT_FIELD(numCols);
435         WRITE_LONG_FIELD(numGroups);
436 }
437
438 static void
439 _outGroup(StringInfo str, Group *node)
440 {
441         int                     i;
442
443         WRITE_NODE_TYPE("GROUP");
444
445         _outPlanInfo(str, (Plan *) node);
446
447         WRITE_INT_FIELD(numCols);
448
449         appendStringInfo(str, " :grpColIdx");
450         for (i = 0; i < node->numCols; i++)
451                 appendStringInfo(str, " %d", node->grpColIdx[i]);
452 }
453
454 static void
455 _outMaterial(StringInfo str, Material *node)
456 {
457         WRITE_NODE_TYPE("MATERIAL");
458
459         _outPlanInfo(str, (Plan *) node);
460 }
461
462 static void
463 _outSort(StringInfo str, Sort *node)
464 {
465         int                     i;
466
467         WRITE_NODE_TYPE("SORT");
468
469         _outPlanInfo(str, (Plan *) node);
470
471         WRITE_INT_FIELD(numCols);
472
473         appendStringInfo(str, " :sortColIdx");
474         for (i = 0; i < node->numCols; i++)
475                 appendStringInfo(str, " %d", node->sortColIdx[i]);
476
477         appendStringInfo(str, " :sortOperators");
478         for (i = 0; i < node->numCols; i++)
479                 appendStringInfo(str, " %u", node->sortOperators[i]);
480 }
481
482 static void
483 _outUnique(StringInfo str, Unique *node)
484 {
485         int                     i;
486
487         WRITE_NODE_TYPE("UNIQUE");
488
489         _outPlanInfo(str, (Plan *) node);
490
491         WRITE_INT_FIELD(numCols);
492
493         appendStringInfo(str, " :uniqColIdx");
494         for (i = 0; i < node->numCols; i++)
495                 appendStringInfo(str, " %d", node->uniqColIdx[i]);
496 }
497
498 static void
499 _outSetOp(StringInfo str, SetOp *node)
500 {
501         int                     i;
502
503         WRITE_NODE_TYPE("SETOP");
504
505         _outPlanInfo(str, (Plan *) node);
506
507         WRITE_ENUM_FIELD(cmd, SetOpCmd);
508         WRITE_INT_FIELD(numCols);
509
510         appendStringInfo(str, " :dupColIdx");
511         for (i = 0; i < node->numCols; i++)
512                 appendStringInfo(str, " %d", node->dupColIdx[i]);
513
514         WRITE_INT_FIELD(flagColIdx);
515 }
516
517 static void
518 _outLimit(StringInfo str, Limit *node)
519 {
520         WRITE_NODE_TYPE("LIMIT");
521
522         _outPlanInfo(str, (Plan *) node);
523
524         WRITE_NODE_FIELD(limitOffset);
525         WRITE_NODE_FIELD(limitCount);
526 }
527
528 static void
529 _outHash(StringInfo str, Hash *node)
530 {
531         WRITE_NODE_TYPE("HASH");
532
533         _outPlanInfo(str, (Plan *) node);
534 }
535
536 /*****************************************************************************
537  *
538  *      Stuff from primnodes.h.
539  *
540  *****************************************************************************/
541
542 static void
543 _outResdom(StringInfo str, Resdom *node)
544 {
545         WRITE_NODE_TYPE("RESDOM");
546
547         WRITE_INT_FIELD(resno);
548         WRITE_OID_FIELD(restype);
549         WRITE_INT_FIELD(restypmod);
550         WRITE_STRING_FIELD(resname);
551         WRITE_UINT_FIELD(ressortgroupref);
552         WRITE_OID_FIELD(resorigtbl);
553         WRITE_INT_FIELD(resorigcol);
554         WRITE_BOOL_FIELD(resjunk);
555 }
556
557 static void
558 _outAlias(StringInfo str, Alias *node)
559 {
560         WRITE_NODE_TYPE("ALIAS");
561
562         WRITE_STRING_FIELD(aliasname);
563         WRITE_NODE_FIELD(colnames);
564 }
565
566 static void
567 _outRangeVar(StringInfo str, RangeVar *node)
568 {
569         WRITE_NODE_TYPE("RANGEVAR");
570
571         /*
572          * we deliberately ignore catalogname here, since it is presently not
573          * semantically meaningful
574          */
575         WRITE_STRING_FIELD(schemaname);
576         WRITE_STRING_FIELD(relname);
577         WRITE_ENUM_FIELD(inhOpt, InhOption);
578         WRITE_BOOL_FIELD(istemp);
579         WRITE_NODE_FIELD(alias);
580 }
581
582 static void
583 _outVar(StringInfo str, Var *node)
584 {
585         WRITE_NODE_TYPE("VAR");
586
587         WRITE_UINT_FIELD(varno);
588         WRITE_INT_FIELD(varattno);
589         WRITE_OID_FIELD(vartype);
590         WRITE_INT_FIELD(vartypmod);
591         WRITE_UINT_FIELD(varlevelsup);
592         WRITE_UINT_FIELD(varnoold);
593         WRITE_INT_FIELD(varoattno);
594 }
595
596 static void
597 _outConst(StringInfo str, Const *node)
598 {
599         WRITE_NODE_TYPE("CONST");
600
601         WRITE_OID_FIELD(consttype);
602         WRITE_INT_FIELD(constlen);
603         WRITE_BOOL_FIELD(constbyval);
604         WRITE_BOOL_FIELD(constisnull);
605
606         appendStringInfo(str, " :constvalue ");
607         if (node->constisnull)
608                 appendStringInfo(str, "<>");
609         else
610                 _outDatum(str, node->constvalue, node->constlen, node->constbyval);
611 }
612
613 static void
614 _outParam(StringInfo str, Param *node)
615 {
616         WRITE_NODE_TYPE("PARAM");
617
618         WRITE_INT_FIELD(paramkind);
619         WRITE_INT_FIELD(paramid);
620         WRITE_STRING_FIELD(paramname);
621         WRITE_OID_FIELD(paramtype);
622 }
623
624 static void
625 _outAggref(StringInfo str, Aggref *node)
626 {
627         WRITE_NODE_TYPE("AGGREF");
628
629         WRITE_OID_FIELD(aggfnoid);
630         WRITE_OID_FIELD(aggtype);
631         WRITE_NODE_FIELD(target);
632         WRITE_UINT_FIELD(agglevelsup);
633         WRITE_BOOL_FIELD(aggstar);
634         WRITE_BOOL_FIELD(aggdistinct);
635 }
636
637 static void
638 _outArrayRef(StringInfo str, ArrayRef *node)
639 {
640         WRITE_NODE_TYPE("ARRAYREF");
641
642         WRITE_OID_FIELD(refrestype);
643         WRITE_OID_FIELD(refarraytype);
644         WRITE_OID_FIELD(refelemtype);
645         WRITE_NODE_FIELD(refupperindexpr);
646         WRITE_NODE_FIELD(reflowerindexpr);
647         WRITE_NODE_FIELD(refexpr);
648         WRITE_NODE_FIELD(refassgnexpr);
649 }
650
651 static void
652 _outFuncExpr(StringInfo str, FuncExpr *node)
653 {
654         WRITE_NODE_TYPE("FUNCEXPR");
655
656         WRITE_OID_FIELD(funcid);
657         WRITE_OID_FIELD(funcresulttype);
658         WRITE_BOOL_FIELD(funcretset);
659         WRITE_ENUM_FIELD(funcformat, CoercionForm);
660         WRITE_NODE_FIELD(args);
661 }
662
663 static void
664 _outOpExpr(StringInfo str, OpExpr *node)
665 {
666         WRITE_NODE_TYPE("OPEXPR");
667
668         WRITE_OID_FIELD(opno);
669         WRITE_OID_FIELD(opfuncid);
670         WRITE_OID_FIELD(opresulttype);
671         WRITE_BOOL_FIELD(opretset);
672         WRITE_NODE_FIELD(args);
673 }
674
675 static void
676 _outDistinctExpr(StringInfo str, DistinctExpr *node)
677 {
678         WRITE_NODE_TYPE("DISTINCTEXPR");
679
680         WRITE_OID_FIELD(opno);
681         WRITE_OID_FIELD(opfuncid);
682         WRITE_OID_FIELD(opresulttype);
683         WRITE_BOOL_FIELD(opretset);
684         WRITE_NODE_FIELD(args);
685 }
686
687 static void
688 _outScalarArrayOpExpr(StringInfo str, ScalarArrayOpExpr *node)
689 {
690         WRITE_NODE_TYPE("SCALARARRAYOPEXPR");
691
692         WRITE_OID_FIELD(opno);
693         WRITE_OID_FIELD(opfuncid);
694         WRITE_BOOL_FIELD(useOr);
695         WRITE_NODE_FIELD(args);
696 }
697
698 static void
699 _outBoolExpr(StringInfo str, BoolExpr *node)
700 {
701         char       *opstr = NULL;
702
703         WRITE_NODE_TYPE("BOOLEXPR");
704
705         /* do-it-yourself enum representation */
706         switch (node->boolop)
707         {
708                 case AND_EXPR:
709                         opstr = "and";
710                         break;
711                 case OR_EXPR:
712                         opstr = "or";
713                         break;
714                 case NOT_EXPR:
715                         opstr = "not";
716                         break;
717         }
718         appendStringInfo(str, " :boolop ");
719         _outToken(str, opstr);
720
721         WRITE_NODE_FIELD(args);
722 }
723
724 static void
725 _outSubLink(StringInfo str, SubLink *node)
726 {
727         WRITE_NODE_TYPE("SUBLINK");
728
729         WRITE_ENUM_FIELD(subLinkType, SubLinkType);
730         WRITE_BOOL_FIELD(useOr);
731         WRITE_NODE_FIELD(lefthand);
732         WRITE_NODE_FIELD(operName);
733         WRITE_OIDLIST_FIELD(operOids);
734         WRITE_NODE_FIELD(subselect);
735 }
736
737 static void
738 _outSubPlan(StringInfo str, SubPlan *node)
739 {
740         WRITE_NODE_TYPE("SUBPLAN");
741
742         WRITE_ENUM_FIELD(subLinkType, SubLinkType);
743         WRITE_BOOL_FIELD(useOr);
744         WRITE_NODE_FIELD(exprs);
745         WRITE_INTLIST_FIELD(paramIds);
746         WRITE_NODE_FIELD(plan);
747         WRITE_INT_FIELD(plan_id);
748         WRITE_NODE_FIELD(rtable);
749         WRITE_BOOL_FIELD(useHashTable);
750         WRITE_BOOL_FIELD(unknownEqFalse);
751         WRITE_INTLIST_FIELD(setParam);
752         WRITE_INTLIST_FIELD(parParam);
753         WRITE_NODE_FIELD(args);
754 }
755
756 static void
757 _outFieldSelect(StringInfo str, FieldSelect *node)
758 {
759         WRITE_NODE_TYPE("FIELDSELECT");
760
761         WRITE_NODE_FIELD(arg);
762         WRITE_INT_FIELD(fieldnum);
763         WRITE_OID_FIELD(resulttype);
764         WRITE_INT_FIELD(resulttypmod);
765 }
766
767 static void
768 _outRelabelType(StringInfo str, RelabelType *node)
769 {
770         WRITE_NODE_TYPE("RELABELTYPE");
771
772         WRITE_NODE_FIELD(arg);
773         WRITE_OID_FIELD(resulttype);
774         WRITE_INT_FIELD(resulttypmod);
775         WRITE_ENUM_FIELD(relabelformat, CoercionForm);
776 }
777
778 static void
779 _outCaseExpr(StringInfo str, CaseExpr *node)
780 {
781         WRITE_NODE_TYPE("CASE");
782
783         WRITE_OID_FIELD(casetype);
784         WRITE_NODE_FIELD(arg);
785         WRITE_NODE_FIELD(args);
786         WRITE_NODE_FIELD(defresult);
787 }
788
789 static void
790 _outCaseWhen(StringInfo str, CaseWhen *node)
791 {
792         WRITE_NODE_TYPE("WHEN");
793
794         WRITE_NODE_FIELD(expr);
795         WRITE_NODE_FIELD(result);
796 }
797
798 static void
799 _outArrayExpr(StringInfo str, ArrayExpr *node)
800 {
801         WRITE_NODE_TYPE("ARRAY");
802
803         WRITE_OID_FIELD(array_typeid);
804         WRITE_OID_FIELD(element_typeid);
805         WRITE_NODE_FIELD(elements);
806         WRITE_BOOL_FIELD(multidims);
807 }
808
809 static void
810 _outCoalesceExpr(StringInfo str, CoalesceExpr *node)
811 {
812         WRITE_NODE_TYPE("COALESCE");
813
814         WRITE_OID_FIELD(coalescetype);
815         WRITE_NODE_FIELD(args);
816 }
817
818 static void
819 _outNullIfExpr(StringInfo str, NullIfExpr *node)
820 {
821         WRITE_NODE_TYPE("NULLIFEXPR");
822
823         WRITE_OID_FIELD(opno);
824         WRITE_OID_FIELD(opfuncid);
825         WRITE_OID_FIELD(opresulttype);
826         WRITE_BOOL_FIELD(opretset);
827         WRITE_NODE_FIELD(args);
828 }
829
830 static void
831 _outNullTest(StringInfo str, NullTest *node)
832 {
833         WRITE_NODE_TYPE("NULLTEST");
834
835         WRITE_NODE_FIELD(arg);
836         WRITE_ENUM_FIELD(nulltesttype, NullTestType);
837 }
838
839 static void
840 _outBooleanTest(StringInfo str, BooleanTest *node)
841 {
842         WRITE_NODE_TYPE("BOOLEANTEST");
843
844         WRITE_NODE_FIELD(arg);
845         WRITE_ENUM_FIELD(booltesttype, BoolTestType);
846 }
847
848 static void
849 _outCoerceToDomain(StringInfo str, CoerceToDomain *node)
850 {
851         WRITE_NODE_TYPE("COERCETODOMAIN");
852
853         WRITE_NODE_FIELD(arg);
854         WRITE_OID_FIELD(resulttype);
855         WRITE_INT_FIELD(resulttypmod);
856         WRITE_ENUM_FIELD(coercionformat, CoercionForm);
857 }
858
859 static void
860 _outCoerceToDomainValue(StringInfo str, CoerceToDomainValue *node)
861 {
862         WRITE_NODE_TYPE("COERCETODOMAINVALUE");
863
864         WRITE_OID_FIELD(typeId);
865         WRITE_INT_FIELD(typeMod);
866 }
867
868 static void
869 _outSetToDefault(StringInfo str, SetToDefault *node)
870 {
871         WRITE_NODE_TYPE("SETTODEFAULT");
872
873         WRITE_OID_FIELD(typeId);
874         WRITE_INT_FIELD(typeMod);
875 }
876
877 static void
878 _outTargetEntry(StringInfo str, TargetEntry *node)
879 {
880         WRITE_NODE_TYPE("TARGETENTRY");
881
882         WRITE_NODE_FIELD(resdom);
883         WRITE_NODE_FIELD(expr);
884 }
885
886 static void
887 _outRangeTblRef(StringInfo str, RangeTblRef *node)
888 {
889         WRITE_NODE_TYPE("RANGETBLREF");
890
891         WRITE_INT_FIELD(rtindex);
892 }
893
894 static void
895 _outJoinExpr(StringInfo str, JoinExpr *node)
896 {
897         WRITE_NODE_TYPE("JOINEXPR");
898
899         WRITE_ENUM_FIELD(jointype, JoinType);
900         WRITE_BOOL_FIELD(isNatural);
901         WRITE_NODE_FIELD(larg);
902         WRITE_NODE_FIELD(rarg);
903         WRITE_NODE_FIELD(using);
904         WRITE_NODE_FIELD(quals);
905         WRITE_NODE_FIELD(alias);
906         WRITE_INT_FIELD(rtindex);
907 }
908
909 static void
910 _outFromExpr(StringInfo str, FromExpr *node)
911 {
912         WRITE_NODE_TYPE("FROMEXPR");
913
914         WRITE_NODE_FIELD(fromlist);
915         WRITE_NODE_FIELD(quals);
916 }
917
918 /*****************************************************************************
919  *
920  *      Stuff from relation.h.
921  *
922  *****************************************************************************/
923
924 /*
925  * print the basic stuff of all nodes that inherit from Path
926  *
927  * Note we do NOT print the parent, else we'd be in infinite recursion
928  */
929 static void
930 _outPathInfo(StringInfo str, Path *node)
931 {
932         WRITE_ENUM_FIELD(pathtype, NodeTag);
933         WRITE_FLOAT_FIELD(startup_cost, "%.2f");
934         WRITE_FLOAT_FIELD(total_cost, "%.2f");
935         WRITE_NODE_FIELD(pathkeys);
936 }
937
938 /*
939  * print the basic stuff of all nodes that inherit from JoinPath
940  */
941 static void
942 _outJoinPathInfo(StringInfo str, JoinPath *node)
943 {
944         _outPathInfo(str, (Path *) node);
945
946         WRITE_ENUM_FIELD(jointype, JoinType);
947         WRITE_NODE_FIELD(outerjoinpath);
948         WRITE_NODE_FIELD(innerjoinpath);
949         WRITE_NODE_FIELD(joinrestrictinfo);
950 }
951
952 static void
953 _outPath(StringInfo str, Path *node)
954 {
955         WRITE_NODE_TYPE("PATH");
956
957         _outPathInfo(str, (Path *) node);
958 }
959
960 /*
961  *      IndexPath is a subclass of Path.
962  */
963 static void
964 _outIndexPath(StringInfo str, IndexPath *node)
965 {
966         WRITE_NODE_TYPE("INDEXPATH");
967
968         _outPathInfo(str, (Path *) node);
969
970         WRITE_NODE_FIELD(indexinfo);
971         WRITE_NODE_FIELD(indexqual);
972         WRITE_NODE_FIELD(indexjoinclauses);
973         WRITE_ENUM_FIELD(indexscandir, ScanDirection);
974         WRITE_FLOAT_FIELD(rows, "%.2f");
975 }
976
977 static void
978 _outTidPath(StringInfo str, TidPath *node)
979 {
980         WRITE_NODE_TYPE("TIDPATH");
981
982         _outPathInfo(str, (Path *) node);
983
984         WRITE_NODE_FIELD(tideval);
985 }
986
987 static void
988 _outAppendPath(StringInfo str, AppendPath *node)
989 {
990         WRITE_NODE_TYPE("APPENDPATH");
991
992         _outPathInfo(str, (Path *) node);
993
994         WRITE_NODE_FIELD(subpaths);
995 }
996
997 static void
998 _outResultPath(StringInfo str, ResultPath *node)
999 {
1000         WRITE_NODE_TYPE("RESULTPATH");
1001
1002         _outPathInfo(str, (Path *) node);
1003
1004         WRITE_NODE_FIELD(subpath);
1005         WRITE_NODE_FIELD(constantqual);
1006 }
1007
1008 static void
1009 _outMaterialPath(StringInfo str, MaterialPath *node)
1010 {
1011         WRITE_NODE_TYPE("MATERIALPATH");
1012
1013         _outPathInfo(str, (Path *) node);
1014
1015         WRITE_NODE_FIELD(subpath);
1016 }
1017
1018 static void
1019 _outUniquePath(StringInfo str, UniquePath *node)
1020 {
1021         WRITE_NODE_TYPE("UNIQUEPATH");
1022
1023         _outPathInfo(str, (Path *) node);
1024
1025         WRITE_NODE_FIELD(subpath);
1026         WRITE_BOOL_FIELD(use_hash);
1027         WRITE_FLOAT_FIELD(rows, "%.0f");
1028 }
1029
1030 static void
1031 _outNestPath(StringInfo str, NestPath *node)
1032 {
1033         WRITE_NODE_TYPE("NESTPATH");
1034
1035         _outJoinPathInfo(str, (JoinPath *) node);
1036 }
1037
1038 static void
1039 _outMergePath(StringInfo str, MergePath *node)
1040 {
1041         WRITE_NODE_TYPE("MERGEPATH");
1042
1043         _outJoinPathInfo(str, (JoinPath *) node);
1044
1045         WRITE_NODE_FIELD(path_mergeclauses);
1046         WRITE_NODE_FIELD(outersortkeys);
1047         WRITE_NODE_FIELD(innersortkeys);
1048 }
1049
1050 static void
1051 _outHashPath(StringInfo str, HashPath *node)
1052 {
1053         WRITE_NODE_TYPE("HASHPATH");
1054
1055         _outJoinPathInfo(str, (JoinPath *) node);
1056
1057         WRITE_NODE_FIELD(path_hashclauses);
1058 }
1059
1060 static void
1061 _outPathKeyItem(StringInfo str, PathKeyItem *node)
1062 {
1063         WRITE_NODE_TYPE("PATHKEYITEM");
1064
1065         WRITE_NODE_FIELD(key);
1066         WRITE_OID_FIELD(sortop);
1067 }
1068
1069 static void
1070 _outRestrictInfo(StringInfo str, RestrictInfo *node)
1071 {
1072         WRITE_NODE_TYPE("RESTRICTINFO");
1073
1074         /* NB: this isn't a complete set of fields */
1075         WRITE_NODE_FIELD(clause);
1076         WRITE_BOOL_FIELD(ispusheddown);
1077         WRITE_BOOL_FIELD(canjoin);
1078         WRITE_BITMAPSET_FIELD(left_relids);
1079         WRITE_BITMAPSET_FIELD(right_relids);
1080         WRITE_NODE_FIELD(orclause);
1081         WRITE_OID_FIELD(mergejoinoperator);
1082         WRITE_OID_FIELD(left_sortop);
1083         WRITE_OID_FIELD(right_sortop);
1084         WRITE_NODE_FIELD(left_pathkey);
1085         WRITE_NODE_FIELD(right_pathkey);
1086         WRITE_OID_FIELD(hashjoinoperator);
1087 }
1088
1089 static void
1090 _outJoinInfo(StringInfo str, JoinInfo *node)
1091 {
1092         WRITE_NODE_TYPE("JOININFO");
1093
1094         WRITE_BITMAPSET_FIELD(unjoined_relids);
1095         WRITE_NODE_FIELD(jinfo_restrictinfo);
1096 }
1097
1098 static void
1099 _outInClauseInfo(StringInfo str, InClauseInfo *node)
1100 {
1101         WRITE_NODE_TYPE("INCLAUSEINFO");
1102
1103         WRITE_BITMAPSET_FIELD(lefthand);
1104         WRITE_BITMAPSET_FIELD(righthand);
1105         WRITE_NODE_FIELD(sub_targetlist);
1106 }
1107
1108 /*****************************************************************************
1109  *
1110  *      Stuff from parsenodes.h.
1111  *
1112  *****************************************************************************/
1113
1114 static void
1115 _outCreateStmt(StringInfo str, CreateStmt *node)
1116 {
1117         WRITE_NODE_TYPE("CREATE");
1118
1119         WRITE_NODE_FIELD(relation);
1120         WRITE_NODE_FIELD(tableElts);
1121         WRITE_NODE_FIELD(inhRelations);
1122         WRITE_NODE_FIELD(constraints);
1123         WRITE_BOOL_FIELD(hasoids);
1124         WRITE_ENUM_FIELD(oncommit, OnCommitAction);
1125 }
1126
1127 static void
1128 _outIndexStmt(StringInfo str, IndexStmt *node)
1129 {
1130         WRITE_NODE_TYPE("INDEX");
1131
1132         WRITE_STRING_FIELD(idxname);
1133         WRITE_NODE_FIELD(relation);
1134         WRITE_STRING_FIELD(accessMethod);
1135         WRITE_NODE_FIELD(indexParams);
1136         WRITE_NODE_FIELD(whereClause);
1137         WRITE_NODE_FIELD(rangetable);
1138         WRITE_BOOL_FIELD(unique);
1139         WRITE_BOOL_FIELD(primary);
1140         WRITE_BOOL_FIELD(isconstraint);
1141 }
1142
1143 static void
1144 _outNotifyStmt(StringInfo str, NotifyStmt *node)
1145 {
1146         WRITE_NODE_TYPE("NOTIFY");
1147
1148         WRITE_NODE_FIELD(relation);
1149 }
1150
1151 static void
1152 _outDeclareCursorStmt(StringInfo str, DeclareCursorStmt *node)
1153 {
1154         WRITE_NODE_TYPE("DECLARECURSOR");
1155
1156         WRITE_STRING_FIELD(portalname);
1157         WRITE_INT_FIELD(options);
1158         WRITE_NODE_FIELD(query);
1159 }
1160
1161 static void
1162 _outSelectStmt(StringInfo str, SelectStmt *node)
1163 {
1164         WRITE_NODE_TYPE("SELECT");
1165
1166         /* XXX this is pretty durn incomplete */
1167         WRITE_NODE_FIELD(whereClause);
1168 }
1169
1170 static void
1171 _outFuncCall(StringInfo str, FuncCall *node)
1172 {
1173         WRITE_NODE_TYPE("FUNCCALL");
1174
1175         WRITE_NODE_FIELD(funcname);
1176         WRITE_NODE_FIELD(args);
1177         WRITE_BOOL_FIELD(agg_star);
1178         WRITE_BOOL_FIELD(agg_distinct);
1179 }
1180
1181 static void
1182 _outColumnDef(StringInfo str, ColumnDef *node)
1183 {
1184         WRITE_NODE_TYPE("COLUMNDEF");
1185
1186         WRITE_STRING_FIELD(colname);
1187         WRITE_NODE_FIELD(typename);
1188         WRITE_INT_FIELD(inhcount);
1189         WRITE_BOOL_FIELD(is_local);
1190         WRITE_BOOL_FIELD(is_not_null);
1191         WRITE_NODE_FIELD(raw_default);
1192         WRITE_STRING_FIELD(cooked_default);
1193         WRITE_NODE_FIELD(constraints);
1194         WRITE_NODE_FIELD(support);
1195 }
1196
1197 static void
1198 _outTypeName(StringInfo str, TypeName *node)
1199 {
1200         WRITE_NODE_TYPE("TYPENAME");
1201
1202         WRITE_NODE_FIELD(names);
1203         WRITE_OID_FIELD(typeid);
1204         WRITE_BOOL_FIELD(timezone);
1205         WRITE_BOOL_FIELD(setof);
1206         WRITE_BOOL_FIELD(pct_type);
1207         WRITE_INT_FIELD(typmod);
1208         WRITE_NODE_FIELD(arrayBounds);
1209 }
1210
1211 static void
1212 _outTypeCast(StringInfo str, TypeCast *node)
1213 {
1214         WRITE_NODE_TYPE("TYPECAST");
1215
1216         WRITE_NODE_FIELD(arg);
1217         WRITE_NODE_FIELD(typename);
1218 }
1219
1220 static void
1221 _outIndexElem(StringInfo str, IndexElem *node)
1222 {
1223         WRITE_NODE_TYPE("INDEXELEM");
1224
1225         WRITE_STRING_FIELD(name);
1226         WRITE_NODE_FIELD(expr);
1227         WRITE_NODE_FIELD(opclass);
1228 }
1229
1230 static void
1231 _outQuery(StringInfo str, Query *node)
1232 {
1233         WRITE_NODE_TYPE("QUERY");
1234
1235         WRITE_ENUM_FIELD(commandType, CmdType);
1236         WRITE_ENUM_FIELD(querySource, QuerySource);
1237         WRITE_BOOL_FIELD(canSetTag);
1238
1239         /*
1240          * Hack to work around missing outfuncs routines for a lot of the
1241          * utility-statement node types.  (The only one we actually *need* for
1242          * rules support is NotifyStmt.)  Someday we ought to support 'em all,
1243          * but for the meantime do this to avoid getting lots of warnings when
1244          * running with debug_print_parse on.
1245          */
1246         if (node->utilityStmt)
1247         {
1248                 switch (nodeTag(node->utilityStmt))
1249                 {
1250                         case T_CreateStmt:
1251                         case T_IndexStmt:
1252                         case T_NotifyStmt:
1253                         case T_DeclareCursorStmt:
1254                                 WRITE_NODE_FIELD(utilityStmt);
1255                                 break;
1256                         default:
1257                                 appendStringInfo(str, " :utilityStmt ?");
1258                                 break;
1259                 }
1260         }
1261         else
1262                 appendStringInfo(str, " :utilityStmt <>");
1263
1264         WRITE_INT_FIELD(resultRelation);
1265         WRITE_NODE_FIELD(into);
1266         WRITE_BOOL_FIELD(hasAggs);
1267         WRITE_BOOL_FIELD(hasSubLinks);
1268         WRITE_NODE_FIELD(rtable);
1269         WRITE_NODE_FIELD(jointree);
1270         WRITE_INTLIST_FIELD(rowMarks);
1271         WRITE_NODE_FIELD(targetList);
1272         WRITE_NODE_FIELD(groupClause);
1273         WRITE_NODE_FIELD(havingQual);
1274         WRITE_NODE_FIELD(distinctClause);
1275         WRITE_NODE_FIELD(sortClause);
1276         WRITE_NODE_FIELD(limitOffset);
1277         WRITE_NODE_FIELD(limitCount);
1278         WRITE_NODE_FIELD(setOperations);
1279         WRITE_INTLIST_FIELD(resultRelations);
1280
1281         /* planner-internal fields are not written out */
1282 }
1283
1284 static void
1285 _outSortClause(StringInfo str, SortClause *node)
1286 {
1287         WRITE_NODE_TYPE("SORTCLAUSE");
1288
1289         WRITE_UINT_FIELD(tleSortGroupRef);
1290         WRITE_OID_FIELD(sortop);
1291 }
1292
1293 static void
1294 _outGroupClause(StringInfo str, GroupClause *node)
1295 {
1296         WRITE_NODE_TYPE("GROUPCLAUSE");
1297
1298         WRITE_UINT_FIELD(tleSortGroupRef);
1299         WRITE_OID_FIELD(sortop);
1300 }
1301
1302 static void
1303 _outSetOperationStmt(StringInfo str, SetOperationStmt *node)
1304 {
1305         WRITE_NODE_TYPE("SETOPERATIONSTMT");
1306
1307         WRITE_ENUM_FIELD(op, SetOperation);
1308         WRITE_BOOL_FIELD(all);
1309         WRITE_NODE_FIELD(larg);
1310         WRITE_NODE_FIELD(rarg);
1311         WRITE_OIDLIST_FIELD(colTypes);
1312 }
1313
1314 static void
1315 _outRangeTblEntry(StringInfo str, RangeTblEntry *node)
1316 {
1317         WRITE_NODE_TYPE("RTE");
1318
1319         /* put alias + eref first to make dump more legible */
1320         WRITE_NODE_FIELD(alias);
1321         WRITE_NODE_FIELD(eref);
1322         WRITE_ENUM_FIELD(rtekind, RTEKind);
1323
1324         switch (node->rtekind)
1325         {
1326                 case RTE_RELATION:
1327                 case RTE_SPECIAL:
1328                         WRITE_OID_FIELD(relid);
1329                         break;
1330                 case RTE_SUBQUERY:
1331                         WRITE_NODE_FIELD(subquery);
1332                         break;
1333                 case RTE_FUNCTION:
1334                         WRITE_NODE_FIELD(funcexpr);
1335                         WRITE_NODE_FIELD(coldeflist);
1336                         break;
1337                 case RTE_JOIN:
1338                         WRITE_ENUM_FIELD(jointype, JoinType);
1339                         WRITE_NODE_FIELD(joinaliasvars);
1340                         break;
1341                 default:
1342                         elog(ERROR, "unrecognized RTE kind: %d", (int) node->rtekind);
1343                         break;
1344         }
1345
1346         WRITE_BOOL_FIELD(inh);
1347         WRITE_BOOL_FIELD(inFromCl);
1348         WRITE_BOOL_FIELD(checkForRead);
1349         WRITE_BOOL_FIELD(checkForWrite);
1350         WRITE_OID_FIELD(checkAsUser);
1351 }
1352
1353 static void
1354 _outAExpr(StringInfo str, A_Expr *node)
1355 {
1356         WRITE_NODE_TYPE("AEXPR");
1357
1358         switch (node->kind)
1359         {
1360                 case AEXPR_OP:
1361                         appendStringInfo(str, " ");
1362                         WRITE_NODE_FIELD(name);
1363                         break;
1364                 case AEXPR_AND:
1365                         appendStringInfo(str, " AND");
1366                         break;
1367                 case AEXPR_OR:
1368                         appendStringInfo(str, " OR");
1369                         break;
1370                 case AEXPR_NOT:
1371                         appendStringInfo(str, " NOT");
1372                         break;
1373                 case AEXPR_OP_ANY:
1374                         appendStringInfo(str, " ");
1375                         WRITE_NODE_FIELD(name);
1376                         appendStringInfo(str, " ANY ");
1377                         break;
1378                 case AEXPR_OP_ALL:
1379                         appendStringInfo(str, " ");
1380                         WRITE_NODE_FIELD(name);
1381                         appendStringInfo(str, " ALL ");
1382                         break;
1383                 case AEXPR_DISTINCT:
1384                         appendStringInfo(str, " DISTINCT ");
1385                         WRITE_NODE_FIELD(name);
1386                         break;
1387                 case AEXPR_NULLIF:
1388                         appendStringInfo(str, " NULLIF ");
1389                         WRITE_NODE_FIELD(name);
1390                         break;
1391                 case AEXPR_OF:
1392                         appendStringInfo(str, " OF ");
1393                         WRITE_NODE_FIELD(name);
1394                         break;
1395                 default:
1396                         appendStringInfo(str, " ??");
1397                         break;
1398         }
1399
1400         WRITE_NODE_FIELD(lexpr);
1401         WRITE_NODE_FIELD(rexpr);
1402 }
1403
1404 static void
1405 _outValue(StringInfo str, Value *value)
1406 {
1407         switch (value->type)
1408         {
1409                 case T_Integer:
1410                         appendStringInfo(str, "%ld", value->val.ival);
1411                         break;
1412                 case T_Float:
1413
1414                         /*
1415                          * We assume the value is a valid numeric literal and so does
1416                          * not need quoting.
1417                          */
1418                         appendStringInfo(str, "%s", value->val.str);
1419                         break;
1420                 case T_String:
1421                         appendStringInfoChar(str, '"');
1422                         _outToken(str, value->val.str);
1423                         appendStringInfoChar(str, '"');
1424                         break;
1425                 case T_BitString:
1426                         /* internal representation already has leading 'b' */
1427                         appendStringInfo(str, "%s", value->val.str);
1428                         break;
1429                 default:
1430                         elog(ERROR, "unrecognized node type: %d", (int) value->type);
1431                         break;
1432         }
1433 }
1434
1435 static void
1436 _outColumnRef(StringInfo str, ColumnRef *node)
1437 {
1438         WRITE_NODE_TYPE("COLUMNREF");
1439
1440         WRITE_NODE_FIELD(fields);
1441         WRITE_NODE_FIELD(indirection);
1442 }
1443
1444 static void
1445 _outParamRef(StringInfo str, ParamRef *node)
1446 {
1447         WRITE_NODE_TYPE("PARAMREF");
1448
1449         WRITE_INT_FIELD(number);
1450         WRITE_NODE_FIELD(fields);
1451         WRITE_NODE_FIELD(indirection);
1452 }
1453
1454 static void
1455 _outAConst(StringInfo str, A_Const *node)
1456 {
1457         WRITE_NODE_TYPE("CONST ");
1458
1459         _outValue(str, &(node->val));
1460         WRITE_NODE_FIELD(typename);
1461 }
1462
1463 static void
1464 _outExprFieldSelect(StringInfo str, ExprFieldSelect *node)
1465 {
1466         WRITE_NODE_TYPE("EXPRFIELDSELECT");
1467
1468         WRITE_NODE_FIELD(arg);
1469         WRITE_NODE_FIELD(fields);
1470         WRITE_NODE_FIELD(indirection);
1471 }
1472
1473 static void
1474 _outConstraint(StringInfo str, Constraint *node)
1475 {
1476         WRITE_NODE_TYPE("CONSTRAINT");
1477
1478         WRITE_STRING_FIELD(name);
1479
1480         appendStringInfo(str, " :contype ");
1481         switch (node->contype)
1482         {
1483                 case CONSTR_PRIMARY:
1484                         appendStringInfo(str, "PRIMARY_KEY");
1485                         WRITE_NODE_FIELD(keys);
1486                         break;
1487
1488                 case CONSTR_CHECK:
1489                         appendStringInfo(str, "CHECK");
1490                         WRITE_NODE_FIELD(raw_expr);
1491                         WRITE_STRING_FIELD(cooked_expr);
1492                         break;
1493
1494                 case CONSTR_DEFAULT:
1495                         appendStringInfo(str, "DEFAULT");
1496                         WRITE_NODE_FIELD(raw_expr);
1497                         WRITE_STRING_FIELD(cooked_expr);
1498                         break;
1499
1500                 case CONSTR_NOTNULL:
1501                         appendStringInfo(str, "NOT_NULL");
1502                         break;
1503
1504                 case CONSTR_UNIQUE:
1505                         appendStringInfo(str, "UNIQUE");
1506                         WRITE_NODE_FIELD(keys);
1507                         break;
1508
1509                 default:
1510                         appendStringInfo(str, "<unrecognized_constraint>");
1511                         break;
1512         }
1513 }
1514
1515 static void
1516 _outFkConstraint(StringInfo str, FkConstraint *node)
1517 {
1518         WRITE_NODE_TYPE("FKCONSTRAINT");
1519
1520         WRITE_STRING_FIELD(constr_name);
1521         WRITE_NODE_FIELD(pktable);
1522         WRITE_NODE_FIELD(fk_attrs);
1523         WRITE_NODE_FIELD(pk_attrs);
1524         WRITE_CHAR_FIELD(fk_matchtype);
1525         WRITE_CHAR_FIELD(fk_upd_action);
1526         WRITE_CHAR_FIELD(fk_del_action);
1527         WRITE_BOOL_FIELD(deferrable);
1528         WRITE_BOOL_FIELD(initdeferred);
1529         WRITE_BOOL_FIELD(skip_validation);
1530 }
1531
1532
1533 /*
1534  * _outNode -
1535  *        converts a Node into ascii string and append it to 'str'
1536  */
1537 static void
1538 _outNode(StringInfo str, void *obj)
1539 {
1540         if (obj == NULL)
1541         {
1542                 appendStringInfo(str, "<>");
1543                 return;
1544         }
1545
1546         if (IsA(obj, List))
1547         {
1548                 List       *l;
1549
1550                 appendStringInfoChar(str, '(');
1551                 foreach(l, (List *) obj)
1552                 {
1553                         _outNode(str, lfirst(l));
1554                         if (lnext(l))
1555                                 appendStringInfoChar(str, ' ');
1556                 }
1557                 appendStringInfoChar(str, ')');
1558         }
1559         else if (IsA(obj, Integer) ||
1560                          IsA(obj, Float) ||
1561                          IsA(obj, String) ||
1562                          IsA(obj, BitString))
1563         {
1564                 /* nodeRead does not want to see { } around these! */
1565                 _outValue(str, obj);
1566         }
1567         else
1568         {
1569                 appendStringInfoChar(str, '{');
1570                 switch (nodeTag(obj))
1571                 {
1572                         case T_Plan:
1573                                 _outPlan(str, obj);
1574                                 break;
1575                         case T_Result:
1576                                 _outResult(str, obj);
1577                                 break;
1578                         case T_Append:
1579                                 _outAppend(str, obj);
1580                                 break;
1581                         case T_Scan:
1582                                 _outScan(str, obj);
1583                                 break;
1584                         case T_SeqScan:
1585                                 _outSeqScan(str, obj);
1586                                 break;
1587                         case T_IndexScan:
1588                                 _outIndexScan(str, obj);
1589                                 break;
1590                         case T_TidScan:
1591                                 _outTidScan(str, obj);
1592                                 break;
1593                         case T_SubqueryScan:
1594                                 _outSubqueryScan(str, obj);
1595                                 break;
1596                         case T_FunctionScan:
1597                                 _outFunctionScan(str, obj);
1598                                 break;
1599                         case T_Join:
1600                                 _outJoin(str, obj);
1601                                 break;
1602                         case T_NestLoop:
1603                                 _outNestLoop(str, obj);
1604                                 break;
1605                         case T_MergeJoin:
1606                                 _outMergeJoin(str, obj);
1607                                 break;
1608                         case T_HashJoin:
1609                                 _outHashJoin(str, obj);
1610                                 break;
1611                         case T_Agg:
1612                                 _outAgg(str, obj);
1613                                 break;
1614                         case T_Group:
1615                                 _outGroup(str, obj);
1616                                 break;
1617                         case T_Material:
1618                                 _outMaterial(str, obj);
1619                                 break;
1620                         case T_Sort:
1621                                 _outSort(str, obj);
1622                                 break;
1623                         case T_Unique:
1624                                 _outUnique(str, obj);
1625                                 break;
1626                         case T_SetOp:
1627                                 _outSetOp(str, obj);
1628                                 break;
1629                         case T_Limit:
1630                                 _outLimit(str, obj);
1631                                 break;
1632                         case T_Hash:
1633                                 _outHash(str, obj);
1634                                 break;
1635                         case T_Resdom:
1636                                 _outResdom(str, obj);
1637                                 break;
1638                         case T_Alias:
1639                                 _outAlias(str, obj);
1640                                 break;
1641                         case T_RangeVar:
1642                                 _outRangeVar(str, obj);
1643                                 break;
1644                         case T_Var:
1645                                 _outVar(str, obj);
1646                                 break;
1647                         case T_Const:
1648                                 _outConst(str, obj);
1649                                 break;
1650                         case T_Param:
1651                                 _outParam(str, obj);
1652                                 break;
1653                         case T_Aggref:
1654                                 _outAggref(str, obj);
1655                                 break;
1656                         case T_ArrayRef:
1657                                 _outArrayRef(str, obj);
1658                                 break;
1659                         case T_FuncExpr:
1660                                 _outFuncExpr(str, obj);
1661                                 break;
1662                         case T_OpExpr:
1663                                 _outOpExpr(str, obj);
1664                                 break;
1665                         case T_DistinctExpr:
1666                                 _outDistinctExpr(str, obj);
1667                                 break;
1668                         case T_ScalarArrayOpExpr:
1669                                 _outScalarArrayOpExpr(str, obj);
1670                                 break;
1671                         case T_BoolExpr:
1672                                 _outBoolExpr(str, obj);
1673                                 break;
1674                         case T_SubLink:
1675                                 _outSubLink(str, obj);
1676                                 break;
1677                         case T_SubPlan:
1678                                 _outSubPlan(str, obj);
1679                                 break;
1680                         case T_FieldSelect:
1681                                 _outFieldSelect(str, obj);
1682                                 break;
1683                         case T_RelabelType:
1684                                 _outRelabelType(str, obj);
1685                                 break;
1686                         case T_CaseExpr:
1687                                 _outCaseExpr(str, obj);
1688                                 break;
1689                         case T_CaseWhen:
1690                                 _outCaseWhen(str, obj);
1691                                 break;
1692                         case T_ArrayExpr:
1693                                 _outArrayExpr(str, obj);
1694                                 break;
1695                         case T_CoalesceExpr:
1696                                 _outCoalesceExpr(str, obj);
1697                                 break;
1698                         case T_NullIfExpr:
1699                                 _outNullIfExpr(str, obj);
1700                                 break;
1701                         case T_NullTest:
1702                                 _outNullTest(str, obj);
1703                                 break;
1704                         case T_BooleanTest:
1705                                 _outBooleanTest(str, obj);
1706                                 break;
1707                         case T_CoerceToDomain:
1708                                 _outCoerceToDomain(str, obj);
1709                                 break;
1710                         case T_CoerceToDomainValue:
1711                                 _outCoerceToDomainValue(str, obj);
1712                                 break;
1713                         case T_SetToDefault:
1714                                 _outSetToDefault(str, obj);
1715                                 break;
1716                         case T_TargetEntry:
1717                                 _outTargetEntry(str, obj);
1718                                 break;
1719                         case T_RangeTblRef:
1720                                 _outRangeTblRef(str, obj);
1721                                 break;
1722                         case T_JoinExpr:
1723                                 _outJoinExpr(str, obj);
1724                                 break;
1725                         case T_FromExpr:
1726                                 _outFromExpr(str, obj);
1727                                 break;
1728
1729                         case T_Path:
1730                                 _outPath(str, obj);
1731                                 break;
1732                         case T_IndexPath:
1733                                 _outIndexPath(str, obj);
1734                                 break;
1735                         case T_TidPath:
1736                                 _outTidPath(str, obj);
1737                                 break;
1738                         case T_AppendPath:
1739                                 _outAppendPath(str, obj);
1740                                 break;
1741                         case T_ResultPath:
1742                                 _outResultPath(str, obj);
1743                                 break;
1744                         case T_MaterialPath:
1745                                 _outMaterialPath(str, obj);
1746                                 break;
1747                         case T_UniquePath:
1748                                 _outUniquePath(str, obj);
1749                                 break;
1750                         case T_NestPath:
1751                                 _outNestPath(str, obj);
1752                                 break;
1753                         case T_MergePath:
1754                                 _outMergePath(str, obj);
1755                                 break;
1756                         case T_HashPath:
1757                                 _outHashPath(str, obj);
1758                                 break;
1759                         case T_PathKeyItem:
1760                                 _outPathKeyItem(str, obj);
1761                                 break;
1762                         case T_RestrictInfo:
1763                                 _outRestrictInfo(str, obj);
1764                                 break;
1765                         case T_JoinInfo:
1766                                 _outJoinInfo(str, obj);
1767                                 break;
1768                         case T_InClauseInfo:
1769                                 _outInClauseInfo(str, obj);
1770                                 break;
1771
1772                         case T_CreateStmt:
1773                                 _outCreateStmt(str, obj);
1774                                 break;
1775                         case T_IndexStmt:
1776                                 _outIndexStmt(str, obj);
1777                                 break;
1778                         case T_NotifyStmt:
1779                                 _outNotifyStmt(str, obj);
1780                                 break;
1781                         case T_DeclareCursorStmt:
1782                                 _outDeclareCursorStmt(str, obj);
1783                                 break;
1784                         case T_SelectStmt:
1785                                 _outSelectStmt(str, obj);
1786                                 break;
1787                         case T_ColumnDef:
1788                                 _outColumnDef(str, obj);
1789                                 break;
1790                         case T_TypeName:
1791                                 _outTypeName(str, obj);
1792                                 break;
1793                         case T_TypeCast:
1794                                 _outTypeCast(str, obj);
1795                                 break;
1796                         case T_IndexElem:
1797                                 _outIndexElem(str, obj);
1798                                 break;
1799                         case T_Query:
1800                                 _outQuery(str, obj);
1801                                 break;
1802                         case T_SortClause:
1803                                 _outSortClause(str, obj);
1804                                 break;
1805                         case T_GroupClause:
1806                                 _outGroupClause(str, obj);
1807                                 break;
1808                         case T_SetOperationStmt:
1809                                 _outSetOperationStmt(str, obj);
1810                                 break;
1811                         case T_RangeTblEntry:
1812                                 _outRangeTblEntry(str, obj);
1813                                 break;
1814                         case T_A_Expr:
1815                                 _outAExpr(str, obj);
1816                                 break;
1817                         case T_ColumnRef:
1818                                 _outColumnRef(str, obj);
1819                                 break;
1820                         case T_ParamRef:
1821                                 _outParamRef(str, obj);
1822                                 break;
1823                         case T_A_Const:
1824                                 _outAConst(str, obj);
1825                                 break;
1826                         case T_ExprFieldSelect:
1827                                 _outExprFieldSelect(str, obj);
1828                                 break;
1829                         case T_Constraint:
1830                                 _outConstraint(str, obj);
1831                                 break;
1832                         case T_FkConstraint:
1833                                 _outFkConstraint(str, obj);
1834                                 break;
1835                         case T_FuncCall:
1836                                 _outFuncCall(str, obj);
1837                                 break;
1838
1839                         default:
1840
1841                                 /*
1842                                  * This should be an ERROR, but it's too useful to be able
1843                                  * to dump structures that _outNode only understands part
1844                                  * of.
1845                                  */
1846                                 elog(WARNING, "could not dump unrecognized node type: %d",
1847                                          (int) nodeTag(obj));
1848                                 break;
1849                 }
1850                 appendStringInfoChar(str, '}');
1851         }
1852 }
1853
1854 /*
1855  * nodeToString -
1856  *         returns the ascii representation of the Node as a palloc'd string
1857  */
1858 char *
1859 nodeToString(void *obj)
1860 {
1861         StringInfoData str;
1862
1863         /* see stringinfo.h for an explanation of this maneuver */
1864         initStringInfo(&str);
1865         _outNode(&str, obj);
1866         return str.data;
1867 }