]> granicus.if.org Git - postgresql/blob - src/backend/nodes/outfuncs.c
Cross-data-type comparisons are now indexable by btrees, pursuant to my
[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  *        $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.220 2003/11/12 21:15:52 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         WRITE_NODE_FIELD(hashkeys);
536 }
537
538 /*****************************************************************************
539  *
540  *      Stuff from primnodes.h.
541  *
542  *****************************************************************************/
543
544 static void
545 _outResdom(StringInfo str, Resdom *node)
546 {
547         WRITE_NODE_TYPE("RESDOM");
548
549         WRITE_INT_FIELD(resno);
550         WRITE_OID_FIELD(restype);
551         WRITE_INT_FIELD(restypmod);
552         WRITE_STRING_FIELD(resname);
553         WRITE_UINT_FIELD(ressortgroupref);
554         WRITE_OID_FIELD(resorigtbl);
555         WRITE_INT_FIELD(resorigcol);
556         WRITE_BOOL_FIELD(resjunk);
557 }
558
559 static void
560 _outAlias(StringInfo str, Alias *node)
561 {
562         WRITE_NODE_TYPE("ALIAS");
563
564         WRITE_STRING_FIELD(aliasname);
565         WRITE_NODE_FIELD(colnames);
566 }
567
568 static void
569 _outRangeVar(StringInfo str, RangeVar *node)
570 {
571         WRITE_NODE_TYPE("RANGEVAR");
572
573         /*
574          * we deliberately ignore catalogname here, since it is presently not
575          * semantically meaningful
576          */
577         WRITE_STRING_FIELD(schemaname);
578         WRITE_STRING_FIELD(relname);
579         WRITE_ENUM_FIELD(inhOpt, InhOption);
580         WRITE_BOOL_FIELD(istemp);
581         WRITE_NODE_FIELD(alias);
582 }
583
584 static void
585 _outVar(StringInfo str, Var *node)
586 {
587         WRITE_NODE_TYPE("VAR");
588
589         WRITE_UINT_FIELD(varno);
590         WRITE_INT_FIELD(varattno);
591         WRITE_OID_FIELD(vartype);
592         WRITE_INT_FIELD(vartypmod);
593         WRITE_UINT_FIELD(varlevelsup);
594         WRITE_UINT_FIELD(varnoold);
595         WRITE_INT_FIELD(varoattno);
596 }
597
598 static void
599 _outConst(StringInfo str, Const *node)
600 {
601         WRITE_NODE_TYPE("CONST");
602
603         WRITE_OID_FIELD(consttype);
604         WRITE_INT_FIELD(constlen);
605         WRITE_BOOL_FIELD(constbyval);
606         WRITE_BOOL_FIELD(constisnull);
607
608         appendStringInfo(str, " :constvalue ");
609         if (node->constisnull)
610                 appendStringInfo(str, "<>");
611         else
612                 _outDatum(str, node->constvalue, node->constlen, node->constbyval);
613 }
614
615 static void
616 _outParam(StringInfo str, Param *node)
617 {
618         WRITE_NODE_TYPE("PARAM");
619
620         WRITE_INT_FIELD(paramkind);
621         WRITE_INT_FIELD(paramid);
622         WRITE_STRING_FIELD(paramname);
623         WRITE_OID_FIELD(paramtype);
624 }
625
626 static void
627 _outAggref(StringInfo str, Aggref *node)
628 {
629         WRITE_NODE_TYPE("AGGREF");
630
631         WRITE_OID_FIELD(aggfnoid);
632         WRITE_OID_FIELD(aggtype);
633         WRITE_NODE_FIELD(target);
634         WRITE_UINT_FIELD(agglevelsup);
635         WRITE_BOOL_FIELD(aggstar);
636         WRITE_BOOL_FIELD(aggdistinct);
637 }
638
639 static void
640 _outArrayRef(StringInfo str, ArrayRef *node)
641 {
642         WRITE_NODE_TYPE("ARRAYREF");
643
644         WRITE_OID_FIELD(refrestype);
645         WRITE_OID_FIELD(refarraytype);
646         WRITE_OID_FIELD(refelemtype);
647         WRITE_NODE_FIELD(refupperindexpr);
648         WRITE_NODE_FIELD(reflowerindexpr);
649         WRITE_NODE_FIELD(refexpr);
650         WRITE_NODE_FIELD(refassgnexpr);
651 }
652
653 static void
654 _outFuncExpr(StringInfo str, FuncExpr *node)
655 {
656         WRITE_NODE_TYPE("FUNCEXPR");
657
658         WRITE_OID_FIELD(funcid);
659         WRITE_OID_FIELD(funcresulttype);
660         WRITE_BOOL_FIELD(funcretset);
661         WRITE_ENUM_FIELD(funcformat, CoercionForm);
662         WRITE_NODE_FIELD(args);
663 }
664
665 static void
666 _outOpExpr(StringInfo str, OpExpr *node)
667 {
668         WRITE_NODE_TYPE("OPEXPR");
669
670         WRITE_OID_FIELD(opno);
671         WRITE_OID_FIELD(opfuncid);
672         WRITE_OID_FIELD(opresulttype);
673         WRITE_BOOL_FIELD(opretset);
674         WRITE_NODE_FIELD(args);
675 }
676
677 static void
678 _outDistinctExpr(StringInfo str, DistinctExpr *node)
679 {
680         WRITE_NODE_TYPE("DISTINCTEXPR");
681
682         WRITE_OID_FIELD(opno);
683         WRITE_OID_FIELD(opfuncid);
684         WRITE_OID_FIELD(opresulttype);
685         WRITE_BOOL_FIELD(opretset);
686         WRITE_NODE_FIELD(args);
687 }
688
689 static void
690 _outScalarArrayOpExpr(StringInfo str, ScalarArrayOpExpr *node)
691 {
692         WRITE_NODE_TYPE("SCALARARRAYOPEXPR");
693
694         WRITE_OID_FIELD(opno);
695         WRITE_OID_FIELD(opfuncid);
696         WRITE_BOOL_FIELD(useOr);
697         WRITE_NODE_FIELD(args);
698 }
699
700 static void
701 _outBoolExpr(StringInfo str, BoolExpr *node)
702 {
703         char       *opstr = NULL;
704
705         WRITE_NODE_TYPE("BOOLEXPR");
706
707         /* do-it-yourself enum representation */
708         switch (node->boolop)
709         {
710                 case AND_EXPR:
711                         opstr = "and";
712                         break;
713                 case OR_EXPR:
714                         opstr = "or";
715                         break;
716                 case NOT_EXPR:
717                         opstr = "not";
718                         break;
719         }
720         appendStringInfo(str, " :boolop ");
721         _outToken(str, opstr);
722
723         WRITE_NODE_FIELD(args);
724 }
725
726 static void
727 _outSubLink(StringInfo str, SubLink *node)
728 {
729         WRITE_NODE_TYPE("SUBLINK");
730
731         WRITE_ENUM_FIELD(subLinkType, SubLinkType);
732         WRITE_BOOL_FIELD(useOr);
733         WRITE_NODE_FIELD(lefthand);
734         WRITE_NODE_FIELD(operName);
735         WRITE_OIDLIST_FIELD(operOids);
736         WRITE_NODE_FIELD(subselect);
737 }
738
739 static void
740 _outSubPlan(StringInfo str, SubPlan *node)
741 {
742         WRITE_NODE_TYPE("SUBPLAN");
743
744         WRITE_ENUM_FIELD(subLinkType, SubLinkType);
745         WRITE_BOOL_FIELD(useOr);
746         WRITE_NODE_FIELD(exprs);
747         WRITE_INTLIST_FIELD(paramIds);
748         WRITE_NODE_FIELD(plan);
749         WRITE_INT_FIELD(plan_id);
750         WRITE_NODE_FIELD(rtable);
751         WRITE_BOOL_FIELD(useHashTable);
752         WRITE_BOOL_FIELD(unknownEqFalse);
753         WRITE_INTLIST_FIELD(setParam);
754         WRITE_INTLIST_FIELD(parParam);
755         WRITE_NODE_FIELD(args);
756 }
757
758 static void
759 _outFieldSelect(StringInfo str, FieldSelect *node)
760 {
761         WRITE_NODE_TYPE("FIELDSELECT");
762
763         WRITE_NODE_FIELD(arg);
764         WRITE_INT_FIELD(fieldnum);
765         WRITE_OID_FIELD(resulttype);
766         WRITE_INT_FIELD(resulttypmod);
767 }
768
769 static void
770 _outRelabelType(StringInfo str, RelabelType *node)
771 {
772         WRITE_NODE_TYPE("RELABELTYPE");
773
774         WRITE_NODE_FIELD(arg);
775         WRITE_OID_FIELD(resulttype);
776         WRITE_INT_FIELD(resulttypmod);
777         WRITE_ENUM_FIELD(relabelformat, CoercionForm);
778 }
779
780 static void
781 _outCaseExpr(StringInfo str, CaseExpr *node)
782 {
783         WRITE_NODE_TYPE("CASE");
784
785         WRITE_OID_FIELD(casetype);
786         WRITE_NODE_FIELD(arg);
787         WRITE_NODE_FIELD(args);
788         WRITE_NODE_FIELD(defresult);
789 }
790
791 static void
792 _outCaseWhen(StringInfo str, CaseWhen *node)
793 {
794         WRITE_NODE_TYPE("WHEN");
795
796         WRITE_NODE_FIELD(expr);
797         WRITE_NODE_FIELD(result);
798 }
799
800 static void
801 _outArrayExpr(StringInfo str, ArrayExpr *node)
802 {
803         WRITE_NODE_TYPE("ARRAY");
804
805         WRITE_OID_FIELD(array_typeid);
806         WRITE_OID_FIELD(element_typeid);
807         WRITE_NODE_FIELD(elements);
808         WRITE_BOOL_FIELD(multidims);
809 }
810
811 static void
812 _outCoalesceExpr(StringInfo str, CoalesceExpr *node)
813 {
814         WRITE_NODE_TYPE("COALESCE");
815
816         WRITE_OID_FIELD(coalescetype);
817         WRITE_NODE_FIELD(args);
818 }
819
820 static void
821 _outNullIfExpr(StringInfo str, NullIfExpr *node)
822 {
823         WRITE_NODE_TYPE("NULLIFEXPR");
824
825         WRITE_OID_FIELD(opno);
826         WRITE_OID_FIELD(opfuncid);
827         WRITE_OID_FIELD(opresulttype);
828         WRITE_BOOL_FIELD(opretset);
829         WRITE_NODE_FIELD(args);
830 }
831
832 static void
833 _outNullTest(StringInfo str, NullTest *node)
834 {
835         WRITE_NODE_TYPE("NULLTEST");
836
837         WRITE_NODE_FIELD(arg);
838         WRITE_ENUM_FIELD(nulltesttype, NullTestType);
839 }
840
841 static void
842 _outBooleanTest(StringInfo str, BooleanTest *node)
843 {
844         WRITE_NODE_TYPE("BOOLEANTEST");
845
846         WRITE_NODE_FIELD(arg);
847         WRITE_ENUM_FIELD(booltesttype, BoolTestType);
848 }
849
850 static void
851 _outCoerceToDomain(StringInfo str, CoerceToDomain *node)
852 {
853         WRITE_NODE_TYPE("COERCETODOMAIN");
854
855         WRITE_NODE_FIELD(arg);
856         WRITE_OID_FIELD(resulttype);
857         WRITE_INT_FIELD(resulttypmod);
858         WRITE_ENUM_FIELD(coercionformat, CoercionForm);
859 }
860
861 static void
862 _outCoerceToDomainValue(StringInfo str, CoerceToDomainValue *node)
863 {
864         WRITE_NODE_TYPE("COERCETODOMAINVALUE");
865
866         WRITE_OID_FIELD(typeId);
867         WRITE_INT_FIELD(typeMod);
868 }
869
870 static void
871 _outSetToDefault(StringInfo str, SetToDefault *node)
872 {
873         WRITE_NODE_TYPE("SETTODEFAULT");
874
875         WRITE_OID_FIELD(typeId);
876         WRITE_INT_FIELD(typeMod);
877 }
878
879 static void
880 _outTargetEntry(StringInfo str, TargetEntry *node)
881 {
882         WRITE_NODE_TYPE("TARGETENTRY");
883
884         WRITE_NODE_FIELD(resdom);
885         WRITE_NODE_FIELD(expr);
886 }
887
888 static void
889 _outRangeTblRef(StringInfo str, RangeTblRef *node)
890 {
891         WRITE_NODE_TYPE("RANGETBLREF");
892
893         WRITE_INT_FIELD(rtindex);
894 }
895
896 static void
897 _outJoinExpr(StringInfo str, JoinExpr *node)
898 {
899         WRITE_NODE_TYPE("JOINEXPR");
900
901         WRITE_ENUM_FIELD(jointype, JoinType);
902         WRITE_BOOL_FIELD(isNatural);
903         WRITE_NODE_FIELD(larg);
904         WRITE_NODE_FIELD(rarg);
905         WRITE_NODE_FIELD(using);
906         WRITE_NODE_FIELD(quals);
907         WRITE_NODE_FIELD(alias);
908         WRITE_INT_FIELD(rtindex);
909 }
910
911 static void
912 _outFromExpr(StringInfo str, FromExpr *node)
913 {
914         WRITE_NODE_TYPE("FROMEXPR");
915
916         WRITE_NODE_FIELD(fromlist);
917         WRITE_NODE_FIELD(quals);
918 }
919
920 /*****************************************************************************
921  *
922  *      Stuff from relation.h.
923  *
924  *****************************************************************************/
925
926 /*
927  * print the basic stuff of all nodes that inherit from Path
928  *
929  * Note we do NOT print the parent, else we'd be in infinite recursion
930  */
931 static void
932 _outPathInfo(StringInfo str, Path *node)
933 {
934         WRITE_ENUM_FIELD(pathtype, NodeTag);
935         WRITE_FLOAT_FIELD(startup_cost, "%.2f");
936         WRITE_FLOAT_FIELD(total_cost, "%.2f");
937         WRITE_NODE_FIELD(pathkeys);
938 }
939
940 /*
941  * print the basic stuff of all nodes that inherit from JoinPath
942  */
943 static void
944 _outJoinPathInfo(StringInfo str, JoinPath *node)
945 {
946         _outPathInfo(str, (Path *) node);
947
948         WRITE_ENUM_FIELD(jointype, JoinType);
949         WRITE_NODE_FIELD(outerjoinpath);
950         WRITE_NODE_FIELD(innerjoinpath);
951         WRITE_NODE_FIELD(joinrestrictinfo);
952 }
953
954 static void
955 _outPath(StringInfo str, Path *node)
956 {
957         WRITE_NODE_TYPE("PATH");
958
959         _outPathInfo(str, (Path *) node);
960 }
961
962 /*
963  *      IndexPath is a subclass of Path.
964  */
965 static void
966 _outIndexPath(StringInfo str, IndexPath *node)
967 {
968         WRITE_NODE_TYPE("INDEXPATH");
969
970         _outPathInfo(str, (Path *) node);
971
972         WRITE_NODE_FIELD(indexinfo);
973         WRITE_NODE_FIELD(indexqual);
974         WRITE_NODE_FIELD(indexjoinclauses);
975         WRITE_ENUM_FIELD(indexscandir, ScanDirection);
976         WRITE_FLOAT_FIELD(rows, "%.2f");
977 }
978
979 static void
980 _outTidPath(StringInfo str, TidPath *node)
981 {
982         WRITE_NODE_TYPE("TIDPATH");
983
984         _outPathInfo(str, (Path *) node);
985
986         WRITE_NODE_FIELD(tideval);
987 }
988
989 static void
990 _outAppendPath(StringInfo str, AppendPath *node)
991 {
992         WRITE_NODE_TYPE("APPENDPATH");
993
994         _outPathInfo(str, (Path *) node);
995
996         WRITE_NODE_FIELD(subpaths);
997 }
998
999 static void
1000 _outResultPath(StringInfo str, ResultPath *node)
1001 {
1002         WRITE_NODE_TYPE("RESULTPATH");
1003
1004         _outPathInfo(str, (Path *) node);
1005
1006         WRITE_NODE_FIELD(subpath);
1007         WRITE_NODE_FIELD(constantqual);
1008 }
1009
1010 static void
1011 _outMaterialPath(StringInfo str, MaterialPath *node)
1012 {
1013         WRITE_NODE_TYPE("MATERIALPATH");
1014
1015         _outPathInfo(str, (Path *) node);
1016
1017         WRITE_NODE_FIELD(subpath);
1018 }
1019
1020 static void
1021 _outUniquePath(StringInfo str, UniquePath *node)
1022 {
1023         WRITE_NODE_TYPE("UNIQUEPATH");
1024
1025         _outPathInfo(str, (Path *) node);
1026
1027         WRITE_NODE_FIELD(subpath);
1028         WRITE_BOOL_FIELD(use_hash);
1029         WRITE_FLOAT_FIELD(rows, "%.0f");
1030 }
1031
1032 static void
1033 _outNestPath(StringInfo str, NestPath *node)
1034 {
1035         WRITE_NODE_TYPE("NESTPATH");
1036
1037         _outJoinPathInfo(str, (JoinPath *) node);
1038 }
1039
1040 static void
1041 _outMergePath(StringInfo str, MergePath *node)
1042 {
1043         WRITE_NODE_TYPE("MERGEPATH");
1044
1045         _outJoinPathInfo(str, (JoinPath *) node);
1046
1047         WRITE_NODE_FIELD(path_mergeclauses);
1048         WRITE_NODE_FIELD(outersortkeys);
1049         WRITE_NODE_FIELD(innersortkeys);
1050 }
1051
1052 static void
1053 _outHashPath(StringInfo str, HashPath *node)
1054 {
1055         WRITE_NODE_TYPE("HASHPATH");
1056
1057         _outJoinPathInfo(str, (JoinPath *) node);
1058
1059         WRITE_NODE_FIELD(path_hashclauses);
1060 }
1061
1062 static void
1063 _outPathKeyItem(StringInfo str, PathKeyItem *node)
1064 {
1065         WRITE_NODE_TYPE("PATHKEYITEM");
1066
1067         WRITE_NODE_FIELD(key);
1068         WRITE_OID_FIELD(sortop);
1069 }
1070
1071 static void
1072 _outRestrictInfo(StringInfo str, RestrictInfo *node)
1073 {
1074         WRITE_NODE_TYPE("RESTRICTINFO");
1075
1076         /* NB: this isn't a complete set of fields */
1077         WRITE_NODE_FIELD(clause);
1078         WRITE_BOOL_FIELD(ispusheddown);
1079         WRITE_NODE_FIELD(subclauseindices);
1080         WRITE_BITMAPSET_FIELD(left_relids);
1081         WRITE_BITMAPSET_FIELD(right_relids);
1082         WRITE_OID_FIELD(mergejoinoperator);
1083         WRITE_OID_FIELD(left_sortop);
1084         WRITE_OID_FIELD(right_sortop);
1085         WRITE_NODE_FIELD(left_pathkey);
1086         WRITE_NODE_FIELD(right_pathkey);
1087         WRITE_OID_FIELD(hashjoinoperator);
1088 }
1089
1090 static void
1091 _outJoinInfo(StringInfo str, JoinInfo *node)
1092 {
1093         WRITE_NODE_TYPE("JOININFO");
1094
1095         WRITE_BITMAPSET_FIELD(unjoined_relids);
1096         WRITE_NODE_FIELD(jinfo_restrictinfo);
1097 }
1098
1099 static void
1100 _outInClauseInfo(StringInfo str, InClauseInfo *node)
1101 {
1102         WRITE_NODE_TYPE("INCLAUSEINFO");
1103
1104         WRITE_BITMAPSET_FIELD(lefthand);
1105         WRITE_BITMAPSET_FIELD(righthand);
1106         WRITE_NODE_FIELD(sub_targetlist);
1107 }
1108
1109 /*****************************************************************************
1110  *
1111  *      Stuff from parsenodes.h.
1112  *
1113  *****************************************************************************/
1114
1115 static void
1116 _outCreateStmt(StringInfo str, CreateStmt *node)
1117 {
1118         WRITE_NODE_TYPE("CREATE");
1119
1120         WRITE_NODE_FIELD(relation);
1121         WRITE_NODE_FIELD(tableElts);
1122         WRITE_NODE_FIELD(inhRelations);
1123         WRITE_NODE_FIELD(constraints);
1124         WRITE_BOOL_FIELD(hasoids);
1125         WRITE_ENUM_FIELD(oncommit, OnCommitAction);
1126 }
1127
1128 static void
1129 _outIndexStmt(StringInfo str, IndexStmt *node)
1130 {
1131         WRITE_NODE_TYPE("INDEX");
1132
1133         WRITE_STRING_FIELD(idxname);
1134         WRITE_NODE_FIELD(relation);
1135         WRITE_STRING_FIELD(accessMethod);
1136         WRITE_NODE_FIELD(indexParams);
1137         WRITE_NODE_FIELD(whereClause);
1138         WRITE_NODE_FIELD(rangetable);
1139         WRITE_BOOL_FIELD(unique);
1140         WRITE_BOOL_FIELD(primary);
1141         WRITE_BOOL_FIELD(isconstraint);
1142 }
1143
1144 static void
1145 _outNotifyStmt(StringInfo str, NotifyStmt *node)
1146 {
1147         WRITE_NODE_TYPE("NOTIFY");
1148
1149         WRITE_NODE_FIELD(relation);
1150 }
1151
1152 static void
1153 _outDeclareCursorStmt(StringInfo str, DeclareCursorStmt *node)
1154 {
1155         WRITE_NODE_TYPE("DECLARECURSOR");
1156
1157         WRITE_STRING_FIELD(portalname);
1158         WRITE_INT_FIELD(options);
1159         WRITE_NODE_FIELD(query);
1160 }
1161
1162 static void
1163 _outSelectStmt(StringInfo str, SelectStmt *node)
1164 {
1165         WRITE_NODE_TYPE("SELECT");
1166
1167         /* XXX this is pretty durn incomplete */
1168         WRITE_NODE_FIELD(whereClause);
1169 }
1170
1171 static void
1172 _outFuncCall(StringInfo str, FuncCall *node)
1173 {
1174         WRITE_NODE_TYPE("FUNCCALL");
1175
1176         WRITE_NODE_FIELD(funcname);
1177         WRITE_NODE_FIELD(args);
1178         WRITE_BOOL_FIELD(agg_star);
1179         WRITE_BOOL_FIELD(agg_distinct);
1180 }
1181
1182 static void
1183 _outColumnDef(StringInfo str, ColumnDef *node)
1184 {
1185         WRITE_NODE_TYPE("COLUMNDEF");
1186
1187         WRITE_STRING_FIELD(colname);
1188         WRITE_NODE_FIELD(typename);
1189         WRITE_INT_FIELD(inhcount);
1190         WRITE_BOOL_FIELD(is_local);
1191         WRITE_BOOL_FIELD(is_not_null);
1192         WRITE_NODE_FIELD(raw_default);
1193         WRITE_STRING_FIELD(cooked_default);
1194         WRITE_NODE_FIELD(constraints);
1195         WRITE_NODE_FIELD(support);
1196 }
1197
1198 static void
1199 _outTypeName(StringInfo str, TypeName *node)
1200 {
1201         WRITE_NODE_TYPE("TYPENAME");
1202
1203         WRITE_NODE_FIELD(names);
1204         WRITE_OID_FIELD(typeid);
1205         WRITE_BOOL_FIELD(timezone);
1206         WRITE_BOOL_FIELD(setof);
1207         WRITE_BOOL_FIELD(pct_type);
1208         WRITE_INT_FIELD(typmod);
1209         WRITE_NODE_FIELD(arrayBounds);
1210 }
1211
1212 static void
1213 _outTypeCast(StringInfo str, TypeCast *node)
1214 {
1215         WRITE_NODE_TYPE("TYPECAST");
1216
1217         WRITE_NODE_FIELD(arg);
1218         WRITE_NODE_FIELD(typename);
1219 }
1220
1221 static void
1222 _outIndexElem(StringInfo str, IndexElem *node)
1223 {
1224         WRITE_NODE_TYPE("INDEXELEM");
1225
1226         WRITE_STRING_FIELD(name);
1227         WRITE_NODE_FIELD(expr);
1228         WRITE_NODE_FIELD(opclass);
1229 }
1230
1231 static void
1232 _outQuery(StringInfo str, Query *node)
1233 {
1234         WRITE_NODE_TYPE("QUERY");
1235
1236         WRITE_ENUM_FIELD(commandType, CmdType);
1237         WRITE_ENUM_FIELD(querySource, QuerySource);
1238         WRITE_BOOL_FIELD(canSetTag);
1239
1240         /*
1241          * Hack to work around missing outfuncs routines for a lot of the
1242          * utility-statement node types.  (The only one we actually *need* for
1243          * rules support is NotifyStmt.)  Someday we ought to support 'em all,
1244          * but for the meantime do this to avoid getting lots of warnings when
1245          * running with debug_print_parse on.
1246          */
1247         if (node->utilityStmt)
1248         {
1249                 switch (nodeTag(node->utilityStmt))
1250                 {
1251                         case T_CreateStmt:
1252                         case T_IndexStmt:
1253                         case T_NotifyStmt:
1254                         case T_DeclareCursorStmt:
1255                                 WRITE_NODE_FIELD(utilityStmt);
1256                                 break;
1257                         default:
1258                                 appendStringInfo(str, " :utilityStmt ?");
1259                                 break;
1260                 }
1261         }
1262         else
1263                 appendStringInfo(str, " :utilityStmt <>");
1264
1265         WRITE_INT_FIELD(resultRelation);
1266         WRITE_NODE_FIELD(into);
1267         WRITE_BOOL_FIELD(hasAggs);
1268         WRITE_BOOL_FIELD(hasSubLinks);
1269         WRITE_NODE_FIELD(rtable);
1270         WRITE_NODE_FIELD(jointree);
1271         WRITE_INTLIST_FIELD(rowMarks);
1272         WRITE_NODE_FIELD(targetList);
1273         WRITE_NODE_FIELD(groupClause);
1274         WRITE_NODE_FIELD(havingQual);
1275         WRITE_NODE_FIELD(distinctClause);
1276         WRITE_NODE_FIELD(sortClause);
1277         WRITE_NODE_FIELD(limitOffset);
1278         WRITE_NODE_FIELD(limitCount);
1279         WRITE_NODE_FIELD(setOperations);
1280         WRITE_INTLIST_FIELD(resultRelations);
1281
1282         /* planner-internal fields are not written out */
1283 }
1284
1285 static void
1286 _outSortClause(StringInfo str, SortClause *node)
1287 {
1288         WRITE_NODE_TYPE("SORTCLAUSE");
1289
1290         WRITE_UINT_FIELD(tleSortGroupRef);
1291         WRITE_OID_FIELD(sortop);
1292 }
1293
1294 static void
1295 _outGroupClause(StringInfo str, GroupClause *node)
1296 {
1297         WRITE_NODE_TYPE("GROUPCLAUSE");
1298
1299         WRITE_UINT_FIELD(tleSortGroupRef);
1300         WRITE_OID_FIELD(sortop);
1301 }
1302
1303 static void
1304 _outSetOperationStmt(StringInfo str, SetOperationStmt *node)
1305 {
1306         WRITE_NODE_TYPE("SETOPERATIONSTMT");
1307
1308         WRITE_ENUM_FIELD(op, SetOperation);
1309         WRITE_BOOL_FIELD(all);
1310         WRITE_NODE_FIELD(larg);
1311         WRITE_NODE_FIELD(rarg);
1312         WRITE_OIDLIST_FIELD(colTypes);
1313 }
1314
1315 static void
1316 _outRangeTblEntry(StringInfo str, RangeTblEntry *node)
1317 {
1318         WRITE_NODE_TYPE("RTE");
1319
1320         /* put alias + eref first to make dump more legible */
1321         WRITE_NODE_FIELD(alias);
1322         WRITE_NODE_FIELD(eref);
1323         WRITE_ENUM_FIELD(rtekind, RTEKind);
1324
1325         switch (node->rtekind)
1326         {
1327                 case RTE_RELATION:
1328                 case RTE_SPECIAL:
1329                         WRITE_OID_FIELD(relid);
1330                         break;
1331                 case RTE_SUBQUERY:
1332                         WRITE_NODE_FIELD(subquery);
1333                         break;
1334                 case RTE_FUNCTION:
1335                         WRITE_NODE_FIELD(funcexpr);
1336                         WRITE_NODE_FIELD(coldeflist);
1337                         break;
1338                 case RTE_JOIN:
1339                         WRITE_ENUM_FIELD(jointype, JoinType);
1340                         WRITE_NODE_FIELD(joinaliasvars);
1341                         break;
1342                 default:
1343                         elog(ERROR, "unrecognized RTE kind: %d", (int) node->rtekind);
1344                         break;
1345         }
1346
1347         WRITE_BOOL_FIELD(inh);
1348         WRITE_BOOL_FIELD(inFromCl);
1349         WRITE_BOOL_FIELD(checkForRead);
1350         WRITE_BOOL_FIELD(checkForWrite);
1351         WRITE_OID_FIELD(checkAsUser);
1352 }
1353
1354 static void
1355 _outAExpr(StringInfo str, A_Expr *node)
1356 {
1357         WRITE_NODE_TYPE("AEXPR");
1358
1359         switch (node->kind)
1360         {
1361                 case AEXPR_OP:
1362                         appendStringInfo(str, " ");
1363                         WRITE_NODE_FIELD(name);
1364                         break;
1365                 case AEXPR_AND:
1366                         appendStringInfo(str, " AND");
1367                         break;
1368                 case AEXPR_OR:
1369                         appendStringInfo(str, " OR");
1370                         break;
1371                 case AEXPR_NOT:
1372                         appendStringInfo(str, " NOT");
1373                         break;
1374                 case AEXPR_OP_ANY:
1375                         appendStringInfo(str, " ");
1376                         WRITE_NODE_FIELD(name);
1377                         appendStringInfo(str, " ANY ");
1378                         break;
1379                 case AEXPR_OP_ALL:
1380                         appendStringInfo(str, " ");
1381                         WRITE_NODE_FIELD(name);
1382                         appendStringInfo(str, " ALL ");
1383                         break;
1384                 case AEXPR_DISTINCT:
1385                         appendStringInfo(str, " DISTINCT ");
1386                         WRITE_NODE_FIELD(name);
1387                         break;
1388                 case AEXPR_NULLIF:
1389                         appendStringInfo(str, " NULLIF ");
1390                         WRITE_NODE_FIELD(name);
1391                         break;
1392                 case AEXPR_OF:
1393                         appendStringInfo(str, " OF ");
1394                         WRITE_NODE_FIELD(name);
1395                         break;
1396                 default:
1397                         appendStringInfo(str, " ??");
1398                         break;
1399         }
1400
1401         WRITE_NODE_FIELD(lexpr);
1402         WRITE_NODE_FIELD(rexpr);
1403 }
1404
1405 static void
1406 _outValue(StringInfo str, Value *value)
1407 {
1408         switch (value->type)
1409         {
1410                 case T_Integer:
1411                         appendStringInfo(str, "%ld", value->val.ival);
1412                         break;
1413                 case T_Float:
1414
1415                         /*
1416                          * We assume the value is a valid numeric literal and so does
1417                          * not need quoting.
1418                          */
1419                         appendStringInfo(str, "%s", value->val.str);
1420                         break;
1421                 case T_String:
1422                         appendStringInfoChar(str, '"');
1423                         _outToken(str, value->val.str);
1424                         appendStringInfoChar(str, '"');
1425                         break;
1426                 case T_BitString:
1427                         /* internal representation already has leading 'b' */
1428                         appendStringInfo(str, "%s", value->val.str);
1429                         break;
1430                 default:
1431                         elog(ERROR, "unrecognized node type: %d", (int) value->type);
1432                         break;
1433         }
1434 }
1435
1436 static void
1437 _outColumnRef(StringInfo str, ColumnRef *node)
1438 {
1439         WRITE_NODE_TYPE("COLUMNREF");
1440
1441         WRITE_NODE_FIELD(fields);
1442         WRITE_NODE_FIELD(indirection);
1443 }
1444
1445 static void
1446 _outParamRef(StringInfo str, ParamRef *node)
1447 {
1448         WRITE_NODE_TYPE("PARAMREF");
1449
1450         WRITE_INT_FIELD(number);
1451         WRITE_NODE_FIELD(fields);
1452         WRITE_NODE_FIELD(indirection);
1453 }
1454
1455 static void
1456 _outAConst(StringInfo str, A_Const *node)
1457 {
1458         WRITE_NODE_TYPE("CONST ");
1459
1460         _outValue(str, &(node->val));
1461         WRITE_NODE_FIELD(typename);
1462 }
1463
1464 static void
1465 _outExprFieldSelect(StringInfo str, ExprFieldSelect *node)
1466 {
1467         WRITE_NODE_TYPE("EXPRFIELDSELECT");
1468
1469         WRITE_NODE_FIELD(arg);
1470         WRITE_NODE_FIELD(fields);
1471         WRITE_NODE_FIELD(indirection);
1472 }
1473
1474 static void
1475 _outConstraint(StringInfo str, Constraint *node)
1476 {
1477         WRITE_NODE_TYPE("CONSTRAINT");
1478
1479         WRITE_STRING_FIELD(name);
1480
1481         appendStringInfo(str, " :contype ");
1482         switch (node->contype)
1483         {
1484                 case CONSTR_PRIMARY:
1485                         appendStringInfo(str, "PRIMARY_KEY");
1486                         WRITE_NODE_FIELD(keys);
1487                         break;
1488
1489                 case CONSTR_CHECK:
1490                         appendStringInfo(str, "CHECK");
1491                         WRITE_NODE_FIELD(raw_expr);
1492                         WRITE_STRING_FIELD(cooked_expr);
1493                         break;
1494
1495                 case CONSTR_DEFAULT:
1496                         appendStringInfo(str, "DEFAULT");
1497                         WRITE_NODE_FIELD(raw_expr);
1498                         WRITE_STRING_FIELD(cooked_expr);
1499                         break;
1500
1501                 case CONSTR_NOTNULL:
1502                         appendStringInfo(str, "NOT_NULL");
1503                         break;
1504
1505                 case CONSTR_UNIQUE:
1506                         appendStringInfo(str, "UNIQUE");
1507                         WRITE_NODE_FIELD(keys);
1508                         break;
1509
1510                 default:
1511                         appendStringInfo(str, "<unrecognized_constraint>");
1512                         break;
1513         }
1514 }
1515
1516 static void
1517 _outFkConstraint(StringInfo str, FkConstraint *node)
1518 {
1519         WRITE_NODE_TYPE("FKCONSTRAINT");
1520
1521         WRITE_STRING_FIELD(constr_name);
1522         WRITE_NODE_FIELD(pktable);
1523         WRITE_NODE_FIELD(fk_attrs);
1524         WRITE_NODE_FIELD(pk_attrs);
1525         WRITE_CHAR_FIELD(fk_matchtype);
1526         WRITE_CHAR_FIELD(fk_upd_action);
1527         WRITE_CHAR_FIELD(fk_del_action);
1528         WRITE_BOOL_FIELD(deferrable);
1529         WRITE_BOOL_FIELD(initdeferred);
1530         WRITE_BOOL_FIELD(skip_validation);
1531 }
1532
1533
1534 /*
1535  * _outNode -
1536  *        converts a Node into ascii string and append it to 'str'
1537  */
1538 static void
1539 _outNode(StringInfo str, void *obj)
1540 {
1541         if (obj == NULL)
1542         {
1543                 appendStringInfo(str, "<>");
1544                 return;
1545         }
1546
1547         if (IsA(obj, List))
1548         {
1549                 List       *l;
1550
1551                 appendStringInfoChar(str, '(');
1552                 foreach(l, (List *) obj)
1553                 {
1554                         _outNode(str, lfirst(l));
1555                         if (lnext(l))
1556                                 appendStringInfoChar(str, ' ');
1557                 }
1558                 appendStringInfoChar(str, ')');
1559         }
1560         else if (IsA(obj, Integer) ||
1561                          IsA(obj, Float) ||
1562                          IsA(obj, String) ||
1563                          IsA(obj, BitString))
1564         {
1565                 /* nodeRead does not want to see { } around these! */
1566                 _outValue(str, obj);
1567         }
1568         else
1569         {
1570                 appendStringInfoChar(str, '{');
1571                 switch (nodeTag(obj))
1572                 {
1573                         case T_Plan:
1574                                 _outPlan(str, obj);
1575                                 break;
1576                         case T_Result:
1577                                 _outResult(str, obj);
1578                                 break;
1579                         case T_Append:
1580                                 _outAppend(str, obj);
1581                                 break;
1582                         case T_Scan:
1583                                 _outScan(str, obj);
1584                                 break;
1585                         case T_SeqScan:
1586                                 _outSeqScan(str, obj);
1587                                 break;
1588                         case T_IndexScan:
1589                                 _outIndexScan(str, obj);
1590                                 break;
1591                         case T_TidScan:
1592                                 _outTidScan(str, obj);
1593                                 break;
1594                         case T_SubqueryScan:
1595                                 _outSubqueryScan(str, obj);
1596                                 break;
1597                         case T_FunctionScan:
1598                                 _outFunctionScan(str, obj);
1599                                 break;
1600                         case T_Join:
1601                                 _outJoin(str, obj);
1602                                 break;
1603                         case T_NestLoop:
1604                                 _outNestLoop(str, obj);
1605                                 break;
1606                         case T_MergeJoin:
1607                                 _outMergeJoin(str, obj);
1608                                 break;
1609                         case T_HashJoin:
1610                                 _outHashJoin(str, obj);
1611                                 break;
1612                         case T_Agg:
1613                                 _outAgg(str, obj);
1614                                 break;
1615                         case T_Group:
1616                                 _outGroup(str, obj);
1617                                 break;
1618                         case T_Material:
1619                                 _outMaterial(str, obj);
1620                                 break;
1621                         case T_Sort:
1622                                 _outSort(str, obj);
1623                                 break;
1624                         case T_Unique:
1625                                 _outUnique(str, obj);
1626                                 break;
1627                         case T_SetOp:
1628                                 _outSetOp(str, obj);
1629                                 break;
1630                         case T_Limit:
1631                                 _outLimit(str, obj);
1632                                 break;
1633                         case T_Hash:
1634                                 _outHash(str, obj);
1635                                 break;
1636                         case T_Resdom:
1637                                 _outResdom(str, obj);
1638                                 break;
1639                         case T_Alias:
1640                                 _outAlias(str, obj);
1641                                 break;
1642                         case T_RangeVar:
1643                                 _outRangeVar(str, obj);
1644                                 break;
1645                         case T_Var:
1646                                 _outVar(str, obj);
1647                                 break;
1648                         case T_Const:
1649                                 _outConst(str, obj);
1650                                 break;
1651                         case T_Param:
1652                                 _outParam(str, obj);
1653                                 break;
1654                         case T_Aggref:
1655                                 _outAggref(str, obj);
1656                                 break;
1657                         case T_ArrayRef:
1658                                 _outArrayRef(str, obj);
1659                                 break;
1660                         case T_FuncExpr:
1661                                 _outFuncExpr(str, obj);
1662                                 break;
1663                         case T_OpExpr:
1664                                 _outOpExpr(str, obj);
1665                                 break;
1666                         case T_DistinctExpr:
1667                                 _outDistinctExpr(str, obj);
1668                                 break;
1669                         case T_ScalarArrayOpExpr:
1670                                 _outScalarArrayOpExpr(str, obj);
1671                                 break;
1672                         case T_BoolExpr:
1673                                 _outBoolExpr(str, obj);
1674                                 break;
1675                         case T_SubLink:
1676                                 _outSubLink(str, obj);
1677                                 break;
1678                         case T_SubPlan:
1679                                 _outSubPlan(str, obj);
1680                                 break;
1681                         case T_FieldSelect:
1682                                 _outFieldSelect(str, obj);
1683                                 break;
1684                         case T_RelabelType:
1685                                 _outRelabelType(str, obj);
1686                                 break;
1687                         case T_CaseExpr:
1688                                 _outCaseExpr(str, obj);
1689                                 break;
1690                         case T_CaseWhen:
1691                                 _outCaseWhen(str, obj);
1692                                 break;
1693                         case T_ArrayExpr:
1694                                 _outArrayExpr(str, obj);
1695                                 break;
1696                         case T_CoalesceExpr:
1697                                 _outCoalesceExpr(str, obj);
1698                                 break;
1699                         case T_NullIfExpr:
1700                                 _outNullIfExpr(str, obj);
1701                                 break;
1702                         case T_NullTest:
1703                                 _outNullTest(str, obj);
1704                                 break;
1705                         case T_BooleanTest:
1706                                 _outBooleanTest(str, obj);
1707                                 break;
1708                         case T_CoerceToDomain:
1709                                 _outCoerceToDomain(str, obj);
1710                                 break;
1711                         case T_CoerceToDomainValue:
1712                                 _outCoerceToDomainValue(str, obj);
1713                                 break;
1714                         case T_SetToDefault:
1715                                 _outSetToDefault(str, obj);
1716                                 break;
1717                         case T_TargetEntry:
1718                                 _outTargetEntry(str, obj);
1719                                 break;
1720                         case T_RangeTblRef:
1721                                 _outRangeTblRef(str, obj);
1722                                 break;
1723                         case T_JoinExpr:
1724                                 _outJoinExpr(str, obj);
1725                                 break;
1726                         case T_FromExpr:
1727                                 _outFromExpr(str, obj);
1728                                 break;
1729
1730                         case T_Path:
1731                                 _outPath(str, obj);
1732                                 break;
1733                         case T_IndexPath:
1734                                 _outIndexPath(str, obj);
1735                                 break;
1736                         case T_TidPath:
1737                                 _outTidPath(str, obj);
1738                                 break;
1739                         case T_AppendPath:
1740                                 _outAppendPath(str, obj);
1741                                 break;
1742                         case T_ResultPath:
1743                                 _outResultPath(str, obj);
1744                                 break;
1745                         case T_MaterialPath:
1746                                 _outMaterialPath(str, obj);
1747                                 break;
1748                         case T_UniquePath:
1749                                 _outUniquePath(str, obj);
1750                                 break;
1751                         case T_NestPath:
1752                                 _outNestPath(str, obj);
1753                                 break;
1754                         case T_MergePath:
1755                                 _outMergePath(str, obj);
1756                                 break;
1757                         case T_HashPath:
1758                                 _outHashPath(str, obj);
1759                                 break;
1760                         case T_PathKeyItem:
1761                                 _outPathKeyItem(str, obj);
1762                                 break;
1763                         case T_RestrictInfo:
1764                                 _outRestrictInfo(str, obj);
1765                                 break;
1766                         case T_JoinInfo:
1767                                 _outJoinInfo(str, obj);
1768                                 break;
1769                         case T_InClauseInfo:
1770                                 _outInClauseInfo(str, obj);
1771                                 break;
1772
1773                         case T_CreateStmt:
1774                                 _outCreateStmt(str, obj);
1775                                 break;
1776                         case T_IndexStmt:
1777                                 _outIndexStmt(str, obj);
1778                                 break;
1779                         case T_NotifyStmt:
1780                                 _outNotifyStmt(str, obj);
1781                                 break;
1782                         case T_DeclareCursorStmt:
1783                                 _outDeclareCursorStmt(str, obj);
1784                                 break;
1785                         case T_SelectStmt:
1786                                 _outSelectStmt(str, obj);
1787                                 break;
1788                         case T_ColumnDef:
1789                                 _outColumnDef(str, obj);
1790                                 break;
1791                         case T_TypeName:
1792                                 _outTypeName(str, obj);
1793                                 break;
1794                         case T_TypeCast:
1795                                 _outTypeCast(str, obj);
1796                                 break;
1797                         case T_IndexElem:
1798                                 _outIndexElem(str, obj);
1799                                 break;
1800                         case T_Query:
1801                                 _outQuery(str, obj);
1802                                 break;
1803                         case T_SortClause:
1804                                 _outSortClause(str, obj);
1805                                 break;
1806                         case T_GroupClause:
1807                                 _outGroupClause(str, obj);
1808                                 break;
1809                         case T_SetOperationStmt:
1810                                 _outSetOperationStmt(str, obj);
1811                                 break;
1812                         case T_RangeTblEntry:
1813                                 _outRangeTblEntry(str, obj);
1814                                 break;
1815                         case T_A_Expr:
1816                                 _outAExpr(str, obj);
1817                                 break;
1818                         case T_ColumnRef:
1819                                 _outColumnRef(str, obj);
1820                                 break;
1821                         case T_ParamRef:
1822                                 _outParamRef(str, obj);
1823                                 break;
1824                         case T_A_Const:
1825                                 _outAConst(str, obj);
1826                                 break;
1827                         case T_ExprFieldSelect:
1828                                 _outExprFieldSelect(str, obj);
1829                                 break;
1830                         case T_Constraint:
1831                                 _outConstraint(str, obj);
1832                                 break;
1833                         case T_FkConstraint:
1834                                 _outFkConstraint(str, obj);
1835                                 break;
1836                         case T_FuncCall:
1837                                 _outFuncCall(str, obj);
1838                                 break;
1839
1840                         default:
1841
1842                                 /*
1843                                  * This should be an ERROR, but it's too useful to be able
1844                                  * to dump structures that _outNode only understands part
1845                                  * of.
1846                                  */
1847                                 elog(WARNING, "could not dump unrecognized node type: %d",
1848                                          (int) nodeTag(obj));
1849                                 break;
1850                 }
1851                 appendStringInfoChar(str, '}');
1852         }
1853 }
1854
1855 /*
1856  * nodeToString -
1857  *         returns the ascii representation of the Node as a palloc'd string
1858  */
1859 char *
1860 nodeToString(void *obj)
1861 {
1862         StringInfoData str;
1863
1864         /* see stringinfo.h for an explanation of this maneuver */
1865         initStringInfo(&str);
1866         _outNode(&str, obj);
1867         return str.data;
1868 }