]> granicus.if.org Git - postgresql/blob - src/backend/nodes/outfuncs.c
Add parse location fields to NullTest and BooleanTest structs.
[postgresql] / src / backend / nodes / outfuncs.c
1 /*-------------------------------------------------------------------------
2  *
3  * outfuncs.c
4  *        Output functions for Postgres tree nodes.
5  *
6  * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  *        src/backend/nodes/outfuncs.c
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/plannodes.h"
28 #include "nodes/relation.h"
29 #include "utils/datum.h"
30
31
32 /*
33  * Macros to simplify output of different kinds of fields.  Use these
34  * wherever possible to reduce the chance for silly typos.  Note that these
35  * hard-wire conventions about the names of the local variables in an Out
36  * routine.
37  */
38
39 /* Write the label for the node type */
40 #define WRITE_NODE_TYPE(nodelabel) \
41         appendStringInfoString(str, nodelabel)
42
43 /* Write an integer field (anything written as ":fldname %d") */
44 #define WRITE_INT_FIELD(fldname) \
45         appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname)
46
47 /* Write an unsigned integer field (anything written as ":fldname %u") */
48 #define WRITE_UINT_FIELD(fldname) \
49         appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
50
51 /* Write an OID field (don't hard-wire assumption that OID is same as uint) */
52 #define WRITE_OID_FIELD(fldname) \
53         appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
54
55 /* Write a long-integer field */
56 #define WRITE_LONG_FIELD(fldname) \
57         appendStringInfo(str, " :" CppAsString(fldname) " %ld", node->fldname)
58
59 /* Write a char field (ie, one ascii character) */
60 #define WRITE_CHAR_FIELD(fldname) \
61         appendStringInfo(str, " :" CppAsString(fldname) " %c", node->fldname)
62
63 /* Write an enumerated-type field as an integer code */
64 #define WRITE_ENUM_FIELD(fldname, enumtype) \
65         appendStringInfo(str, " :" CppAsString(fldname) " %d", \
66                                          (int) node->fldname)
67
68 /* Write a float field --- caller must give format to define precision */
69 #define WRITE_FLOAT_FIELD(fldname,format) \
70         appendStringInfo(str, " :" CppAsString(fldname) " " format, node->fldname)
71
72 /* Write a boolean field */
73 #define WRITE_BOOL_FIELD(fldname) \
74         appendStringInfo(str, " :" CppAsString(fldname) " %s", \
75                                          booltostr(node->fldname))
76
77 /* Write a character-string (possibly NULL) field */
78 #define WRITE_STRING_FIELD(fldname) \
79         (appendStringInfo(str, " :" CppAsString(fldname) " "), \
80          _outToken(str, node->fldname))
81
82 /* Write a parse location field (actually same as INT case) */
83 #define WRITE_LOCATION_FIELD(fldname) \
84         appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname)
85
86 /* Write a Node field */
87 #define WRITE_NODE_FIELD(fldname) \
88         (appendStringInfo(str, " :" CppAsString(fldname) " "), \
89          _outNode(str, node->fldname))
90
91 /* Write a bitmapset field */
92 #define WRITE_BITMAPSET_FIELD(fldname) \
93         (appendStringInfo(str, " :" CppAsString(fldname) " "), \
94          _outBitmapset(str, node->fldname))
95
96
97 #define booltostr(x)  ((x) ? "true" : "false")
98
99 static void _outNode(StringInfo str, const void *obj);
100
101
102 /*
103  * _outToken
104  *        Convert an ordinary string (eg, an identifier) into a form that
105  *        will be decoded back to a plain token by read.c's functions.
106  *
107  *        If a null or empty string is given, it is encoded as "<>".
108  */
109 static void
110 _outToken(StringInfo str, const char *s)
111 {
112         if (s == NULL || *s == '\0')
113         {
114                 appendStringInfoString(str, "<>");
115                 return;
116         }
117
118         /*
119          * Look for characters or patterns that are treated specially by read.c
120          * (either in pg_strtok() or in nodeRead()), and therefore need a
121          * protective backslash.
122          */
123         /* These characters only need to be quoted at the start of the string */
124         if (*s == '<' ||
125                 *s == '\"' ||
126                 isdigit((unsigned char) *s) ||
127                 ((*s == '+' || *s == '-') &&
128                  (isdigit((unsigned char) s[1]) || s[1] == '.')))
129                 appendStringInfoChar(str, '\\');
130         while (*s)
131         {
132                 /* These chars must be backslashed anywhere in the string */
133                 if (*s == ' ' || *s == '\n' || *s == '\t' ||
134                         *s == '(' || *s == ')' || *s == '{' || *s == '}' ||
135                         *s == '\\')
136                         appendStringInfoChar(str, '\\');
137                 appendStringInfoChar(str, *s++);
138         }
139 }
140
141 static void
142 _outList(StringInfo str, const List *node)
143 {
144         const ListCell *lc;
145
146         appendStringInfoChar(str, '(');
147
148         if (IsA(node, IntList))
149                 appendStringInfoChar(str, 'i');
150         else if (IsA(node, OidList))
151                 appendStringInfoChar(str, 'o');
152
153         foreach(lc, node)
154         {
155                 /*
156                  * For the sake of backward compatibility, we emit a slightly
157                  * different whitespace format for lists of nodes vs. other types of
158                  * lists. XXX: is this necessary?
159                  */
160                 if (IsA(node, List))
161                 {
162                         _outNode(str, lfirst(lc));
163                         if (lnext(lc))
164                                 appendStringInfoChar(str, ' ');
165                 }
166                 else if (IsA(node, IntList))
167                         appendStringInfo(str, " %d", lfirst_int(lc));
168                 else if (IsA(node, OidList))
169                         appendStringInfo(str, " %u", lfirst_oid(lc));
170                 else
171                         elog(ERROR, "unrecognized list node type: %d",
172                                  (int) node->type);
173         }
174
175         appendStringInfoChar(str, ')');
176 }
177
178 /*
179  * _outBitmapset -
180  *         converts a bitmap set of integers
181  *
182  * Note: the output format is "(b int int ...)", similar to an integer List.
183  */
184 static void
185 _outBitmapset(StringInfo str, const Bitmapset *bms)
186 {
187         int                     x;
188
189         appendStringInfoChar(str, '(');
190         appendStringInfoChar(str, 'b');
191         x = -1;
192         while ((x = bms_next_member(bms, x)) >= 0)
193                 appendStringInfo(str, " %d", x);
194         appendStringInfoChar(str, ')');
195 }
196
197 /*
198  * Print the value of a Datum given its type.
199  */
200 static void
201 _outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
202 {
203         Size            length,
204                                 i;
205         char       *s;
206
207         length = datumGetSize(value, typbyval, typlen);
208
209         if (typbyval)
210         {
211                 s = (char *) (&value);
212                 appendStringInfo(str, "%u [ ", (unsigned int) length);
213                 for (i = 0; i < (Size) sizeof(Datum); i++)
214                         appendStringInfo(str, "%d ", (int) (s[i]));
215                 appendStringInfoChar(str, ']');
216         }
217         else
218         {
219                 s = (char *) DatumGetPointer(value);
220                 if (!PointerIsValid(s))
221                         appendStringInfoString(str, "0 [ ]");
222                 else
223                 {
224                         appendStringInfo(str, "%u [ ", (unsigned int) length);
225                         for (i = 0; i < length; i++)
226                                 appendStringInfo(str, "%d ", (int) (s[i]));
227                         appendStringInfoChar(str, ']');
228                 }
229         }
230 }
231
232
233 /*
234  *      Stuff from plannodes.h
235  */
236
237 static void
238 _outPlannedStmt(StringInfo str, const PlannedStmt *node)
239 {
240         WRITE_NODE_TYPE("PLANNEDSTMT");
241
242         WRITE_ENUM_FIELD(commandType, CmdType);
243         WRITE_UINT_FIELD(queryId);
244         WRITE_BOOL_FIELD(hasReturning);
245         WRITE_BOOL_FIELD(hasModifyingCTE);
246         WRITE_BOOL_FIELD(canSetTag);
247         WRITE_BOOL_FIELD(transientPlan);
248         WRITE_NODE_FIELD(planTree);
249         WRITE_NODE_FIELD(rtable);
250         WRITE_NODE_FIELD(resultRelations);
251         WRITE_NODE_FIELD(utilityStmt);
252         WRITE_NODE_FIELD(subplans);
253         WRITE_BITMAPSET_FIELD(rewindPlanIDs);
254         WRITE_NODE_FIELD(rowMarks);
255         WRITE_NODE_FIELD(relationOids);
256         WRITE_NODE_FIELD(invalItems);
257         WRITE_INT_FIELD(nParamExec);
258 }
259
260 /*
261  * print the basic stuff of all nodes that inherit from Plan
262  */
263 static void
264 _outPlanInfo(StringInfo str, const Plan *node)
265 {
266         WRITE_FLOAT_FIELD(startup_cost, "%.2f");
267         WRITE_FLOAT_FIELD(total_cost, "%.2f");
268         WRITE_FLOAT_FIELD(plan_rows, "%.0f");
269         WRITE_INT_FIELD(plan_width);
270         WRITE_NODE_FIELD(targetlist);
271         WRITE_NODE_FIELD(qual);
272         WRITE_NODE_FIELD(lefttree);
273         WRITE_NODE_FIELD(righttree);
274         WRITE_NODE_FIELD(initPlan);
275         WRITE_BITMAPSET_FIELD(extParam);
276         WRITE_BITMAPSET_FIELD(allParam);
277 }
278
279 /*
280  * print the basic stuff of all nodes that inherit from Scan
281  */
282 static void
283 _outScanInfo(StringInfo str, const Scan *node)
284 {
285         _outPlanInfo(str, (const Plan *) node);
286
287         WRITE_UINT_FIELD(scanrelid);
288 }
289
290 /*
291  * print the basic stuff of all nodes that inherit from Join
292  */
293 static void
294 _outJoinPlanInfo(StringInfo str, const Join *node)
295 {
296         _outPlanInfo(str, (const Plan *) node);
297
298         WRITE_ENUM_FIELD(jointype, JoinType);
299         WRITE_NODE_FIELD(joinqual);
300 }
301
302
303 static void
304 _outPlan(StringInfo str, const Plan *node)
305 {
306         WRITE_NODE_TYPE("PLAN");
307
308         _outPlanInfo(str, (const Plan *) node);
309 }
310
311 static void
312 _outResult(StringInfo str, const Result *node)
313 {
314         WRITE_NODE_TYPE("RESULT");
315
316         _outPlanInfo(str, (const Plan *) node);
317
318         WRITE_NODE_FIELD(resconstantqual);
319 }
320
321 static void
322 _outModifyTable(StringInfo str, const ModifyTable *node)
323 {
324         WRITE_NODE_TYPE("MODIFYTABLE");
325
326         _outPlanInfo(str, (const Plan *) node);
327
328         WRITE_ENUM_FIELD(operation, CmdType);
329         WRITE_BOOL_FIELD(canSetTag);
330         WRITE_UINT_FIELD(nominalRelation);
331         WRITE_NODE_FIELD(resultRelations);
332         WRITE_INT_FIELD(resultRelIndex);
333         WRITE_NODE_FIELD(plans);
334         WRITE_NODE_FIELD(withCheckOptionLists);
335         WRITE_NODE_FIELD(returningLists);
336         WRITE_NODE_FIELD(fdwPrivLists);
337         WRITE_NODE_FIELD(rowMarks);
338         WRITE_INT_FIELD(epqParam);
339 }
340
341 static void
342 _outAppend(StringInfo str, const Append *node)
343 {
344         WRITE_NODE_TYPE("APPEND");
345
346         _outPlanInfo(str, (const Plan *) node);
347
348         WRITE_NODE_FIELD(appendplans);
349 }
350
351 static void
352 _outMergeAppend(StringInfo str, const MergeAppend *node)
353 {
354         int                     i;
355
356         WRITE_NODE_TYPE("MERGEAPPEND");
357
358         _outPlanInfo(str, (const Plan *) node);
359
360         WRITE_NODE_FIELD(mergeplans);
361
362         WRITE_INT_FIELD(numCols);
363
364         appendStringInfoString(str, " :sortColIdx");
365         for (i = 0; i < node->numCols; i++)
366                 appendStringInfo(str, " %d", node->sortColIdx[i]);
367
368         appendStringInfoString(str, " :sortOperators");
369         for (i = 0; i < node->numCols; i++)
370                 appendStringInfo(str, " %u", node->sortOperators[i]);
371
372         appendStringInfoString(str, " :collations");
373         for (i = 0; i < node->numCols; i++)
374                 appendStringInfo(str, " %u", node->collations[i]);
375
376         appendStringInfoString(str, " :nullsFirst");
377         for (i = 0; i < node->numCols; i++)
378                 appendStringInfo(str, " %s", booltostr(node->nullsFirst[i]));
379 }
380
381 static void
382 _outRecursiveUnion(StringInfo str, const RecursiveUnion *node)
383 {
384         int                     i;
385
386         WRITE_NODE_TYPE("RECURSIVEUNION");
387
388         _outPlanInfo(str, (const Plan *) node);
389
390         WRITE_INT_FIELD(wtParam);
391         WRITE_INT_FIELD(numCols);
392
393         appendStringInfoString(str, " :dupColIdx");
394         for (i = 0; i < node->numCols; i++)
395                 appendStringInfo(str, " %d", node->dupColIdx[i]);
396
397         appendStringInfoString(str, " :dupOperators");
398         for (i = 0; i < node->numCols; i++)
399                 appendStringInfo(str, " %u", node->dupOperators[i]);
400
401         WRITE_LONG_FIELD(numGroups);
402 }
403
404 static void
405 _outBitmapAnd(StringInfo str, const BitmapAnd *node)
406 {
407         WRITE_NODE_TYPE("BITMAPAND");
408
409         _outPlanInfo(str, (const Plan *) node);
410
411         WRITE_NODE_FIELD(bitmapplans);
412 }
413
414 static void
415 _outBitmapOr(StringInfo str, const BitmapOr *node)
416 {
417         WRITE_NODE_TYPE("BITMAPOR");
418
419         _outPlanInfo(str, (const Plan *) node);
420
421         WRITE_NODE_FIELD(bitmapplans);
422 }
423
424 static void
425 _outScan(StringInfo str, const Scan *node)
426 {
427         WRITE_NODE_TYPE("SCAN");
428
429         _outScanInfo(str, node);
430 }
431
432 static void
433 _outSeqScan(StringInfo str, const SeqScan *node)
434 {
435         WRITE_NODE_TYPE("SEQSCAN");
436
437         _outScanInfo(str, (const Scan *) node);
438 }
439
440 static void
441 _outIndexScan(StringInfo str, const IndexScan *node)
442 {
443         WRITE_NODE_TYPE("INDEXSCAN");
444
445         _outScanInfo(str, (const Scan *) node);
446
447         WRITE_OID_FIELD(indexid);
448         WRITE_NODE_FIELD(indexqual);
449         WRITE_NODE_FIELD(indexqualorig);
450         WRITE_NODE_FIELD(indexorderby);
451         WRITE_NODE_FIELD(indexorderbyorig);
452         WRITE_ENUM_FIELD(indexorderdir, ScanDirection);
453 }
454
455 static void
456 _outIndexOnlyScan(StringInfo str, const IndexOnlyScan *node)
457 {
458         WRITE_NODE_TYPE("INDEXONLYSCAN");
459
460         _outScanInfo(str, (const Scan *) node);
461
462         WRITE_OID_FIELD(indexid);
463         WRITE_NODE_FIELD(indexqual);
464         WRITE_NODE_FIELD(indexorderby);
465         WRITE_NODE_FIELD(indextlist);
466         WRITE_ENUM_FIELD(indexorderdir, ScanDirection);
467 }
468
469 static void
470 _outBitmapIndexScan(StringInfo str, const BitmapIndexScan *node)
471 {
472         WRITE_NODE_TYPE("BITMAPINDEXSCAN");
473
474         _outScanInfo(str, (const Scan *) node);
475
476         WRITE_OID_FIELD(indexid);
477         WRITE_NODE_FIELD(indexqual);
478         WRITE_NODE_FIELD(indexqualorig);
479 }
480
481 static void
482 _outBitmapHeapScan(StringInfo str, const BitmapHeapScan *node)
483 {
484         WRITE_NODE_TYPE("BITMAPHEAPSCAN");
485
486         _outScanInfo(str, (const Scan *) node);
487
488         WRITE_NODE_FIELD(bitmapqualorig);
489 }
490
491 static void
492 _outTidScan(StringInfo str, const TidScan *node)
493 {
494         WRITE_NODE_TYPE("TIDSCAN");
495
496         _outScanInfo(str, (const Scan *) node);
497
498         WRITE_NODE_FIELD(tidquals);
499 }
500
501 static void
502 _outSubqueryScan(StringInfo str, const SubqueryScan *node)
503 {
504         WRITE_NODE_TYPE("SUBQUERYSCAN");
505
506         _outScanInfo(str, (const Scan *) node);
507
508         WRITE_NODE_FIELD(subplan);
509 }
510
511 static void
512 _outFunctionScan(StringInfo str, const FunctionScan *node)
513 {
514         WRITE_NODE_TYPE("FUNCTIONSCAN");
515
516         _outScanInfo(str, (const Scan *) node);
517
518         WRITE_NODE_FIELD(functions);
519         WRITE_BOOL_FIELD(funcordinality);
520 }
521
522 static void
523 _outValuesScan(StringInfo str, const ValuesScan *node)
524 {
525         WRITE_NODE_TYPE("VALUESSCAN");
526
527         _outScanInfo(str, (const Scan *) node);
528
529         WRITE_NODE_FIELD(values_lists);
530 }
531
532 static void
533 _outCteScan(StringInfo str, const CteScan *node)
534 {
535         WRITE_NODE_TYPE("CTESCAN");
536
537         _outScanInfo(str, (const Scan *) node);
538
539         WRITE_INT_FIELD(ctePlanId);
540         WRITE_INT_FIELD(cteParam);
541 }
542
543 static void
544 _outWorkTableScan(StringInfo str, const WorkTableScan *node)
545 {
546         WRITE_NODE_TYPE("WORKTABLESCAN");
547
548         _outScanInfo(str, (const Scan *) node);
549
550         WRITE_INT_FIELD(wtParam);
551 }
552
553 static void
554 _outForeignScan(StringInfo str, const ForeignScan *node)
555 {
556         WRITE_NODE_TYPE("FOREIGNSCAN");
557
558         _outScanInfo(str, (const Scan *) node);
559
560         WRITE_NODE_FIELD(fdw_exprs);
561         WRITE_NODE_FIELD(fdw_private);
562         WRITE_BOOL_FIELD(fsSystemCol);
563 }
564
565 static void
566 _outCustomScan(StringInfo str, const CustomScan *node)
567 {
568         WRITE_NODE_TYPE("CUSTOMSCAN");
569
570         _outScanInfo(str, (const Scan *) node);
571
572         WRITE_UINT_FIELD(flags);
573         WRITE_NODE_FIELD(custom_exprs);
574         WRITE_NODE_FIELD(custom_private);
575         appendStringInfoString(str, " :methods ");
576         _outToken(str, node->methods->CustomName);
577         if (node->methods->TextOutCustomScan)
578                 node->methods->TextOutCustomScan(str, node);
579 }
580
581 static void
582 _outJoin(StringInfo str, const Join *node)
583 {
584         WRITE_NODE_TYPE("JOIN");
585
586         _outJoinPlanInfo(str, (const Join *) node);
587 }
588
589 static void
590 _outNestLoop(StringInfo str, const NestLoop *node)
591 {
592         WRITE_NODE_TYPE("NESTLOOP");
593
594         _outJoinPlanInfo(str, (const Join *) node);
595
596         WRITE_NODE_FIELD(nestParams);
597 }
598
599 static void
600 _outMergeJoin(StringInfo str, const MergeJoin *node)
601 {
602         int                     numCols;
603         int                     i;
604
605         WRITE_NODE_TYPE("MERGEJOIN");
606
607         _outJoinPlanInfo(str, (const Join *) node);
608
609         WRITE_NODE_FIELD(mergeclauses);
610
611         numCols = list_length(node->mergeclauses);
612
613         appendStringInfoString(str, " :mergeFamilies");
614         for (i = 0; i < numCols; i++)
615                 appendStringInfo(str, " %u", node->mergeFamilies[i]);
616
617         appendStringInfoString(str, " :mergeCollations");
618         for (i = 0; i < numCols; i++)
619                 appendStringInfo(str, " %u", node->mergeCollations[i]);
620
621         appendStringInfoString(str, " :mergeStrategies");
622         for (i = 0; i < numCols; i++)
623                 appendStringInfo(str, " %d", node->mergeStrategies[i]);
624
625         appendStringInfoString(str, " :mergeNullsFirst");
626         for (i = 0; i < numCols; i++)
627                 appendStringInfo(str, " %d", (int) node->mergeNullsFirst[i]);
628 }
629
630 static void
631 _outHashJoin(StringInfo str, const HashJoin *node)
632 {
633         WRITE_NODE_TYPE("HASHJOIN");
634
635         _outJoinPlanInfo(str, (const Join *) node);
636
637         WRITE_NODE_FIELD(hashclauses);
638 }
639
640 static void
641 _outAgg(StringInfo str, const Agg *node)
642 {
643         int                     i;
644
645         WRITE_NODE_TYPE("AGG");
646
647         _outPlanInfo(str, (const Plan *) node);
648
649         WRITE_ENUM_FIELD(aggstrategy, AggStrategy);
650         WRITE_INT_FIELD(numCols);
651
652         appendStringInfoString(str, " :grpColIdx");
653         for (i = 0; i < node->numCols; i++)
654                 appendStringInfo(str, " %d", node->grpColIdx[i]);
655
656         appendStringInfoString(str, " :grpOperators");
657         for (i = 0; i < node->numCols; i++)
658                 appendStringInfo(str, " %u", node->grpOperators[i]);
659
660         WRITE_LONG_FIELD(numGroups);
661 }
662
663 static void
664 _outWindowAgg(StringInfo str, const WindowAgg *node)
665 {
666         int                     i;
667
668         WRITE_NODE_TYPE("WINDOWAGG");
669
670         _outPlanInfo(str, (const Plan *) node);
671
672         WRITE_UINT_FIELD(winref);
673         WRITE_INT_FIELD(partNumCols);
674
675         appendStringInfoString(str, " :partColIdx");
676         for (i = 0; i < node->partNumCols; i++)
677                 appendStringInfo(str, " %d", node->partColIdx[i]);
678
679         appendStringInfoString(str, " :partOperations");
680         for (i = 0; i < node->partNumCols; i++)
681                 appendStringInfo(str, " %u", node->partOperators[i]);
682
683         WRITE_INT_FIELD(ordNumCols);
684
685         appendStringInfoString(str, " :ordColIdx");
686         for (i = 0; i < node->ordNumCols; i++)
687                 appendStringInfo(str, " %d", node->ordColIdx[i]);
688
689         appendStringInfoString(str, " :ordOperations");
690         for (i = 0; i < node->ordNumCols; i++)
691                 appendStringInfo(str, " %u", node->ordOperators[i]);
692
693         WRITE_INT_FIELD(frameOptions);
694         WRITE_NODE_FIELD(startOffset);
695         WRITE_NODE_FIELD(endOffset);
696 }
697
698 static void
699 _outGroup(StringInfo str, const Group *node)
700 {
701         int                     i;
702
703         WRITE_NODE_TYPE("GROUP");
704
705         _outPlanInfo(str, (const Plan *) node);
706
707         WRITE_INT_FIELD(numCols);
708
709         appendStringInfoString(str, " :grpColIdx");
710         for (i = 0; i < node->numCols; i++)
711                 appendStringInfo(str, " %d", node->grpColIdx[i]);
712
713         appendStringInfoString(str, " :grpOperators");
714         for (i = 0; i < node->numCols; i++)
715                 appendStringInfo(str, " %u", node->grpOperators[i]);
716 }
717
718 static void
719 _outMaterial(StringInfo str, const Material *node)
720 {
721         WRITE_NODE_TYPE("MATERIAL");
722
723         _outPlanInfo(str, (const Plan *) node);
724 }
725
726 static void
727 _outSort(StringInfo str, const Sort *node)
728 {
729         int                     i;
730
731         WRITE_NODE_TYPE("SORT");
732
733         _outPlanInfo(str, (const Plan *) node);
734
735         WRITE_INT_FIELD(numCols);
736
737         appendStringInfoString(str, " :sortColIdx");
738         for (i = 0; i < node->numCols; i++)
739                 appendStringInfo(str, " %d", node->sortColIdx[i]);
740
741         appendStringInfoString(str, " :sortOperators");
742         for (i = 0; i < node->numCols; i++)
743                 appendStringInfo(str, " %u", node->sortOperators[i]);
744
745         appendStringInfoString(str, " :collations");
746         for (i = 0; i < node->numCols; i++)
747                 appendStringInfo(str, " %u", node->collations[i]);
748
749         appendStringInfoString(str, " :nullsFirst");
750         for (i = 0; i < node->numCols; i++)
751                 appendStringInfo(str, " %s", booltostr(node->nullsFirst[i]));
752 }
753
754 static void
755 _outUnique(StringInfo str, const Unique *node)
756 {
757         int                     i;
758
759         WRITE_NODE_TYPE("UNIQUE");
760
761         _outPlanInfo(str, (const Plan *) node);
762
763         WRITE_INT_FIELD(numCols);
764
765         appendStringInfoString(str, " :uniqColIdx");
766         for (i = 0; i < node->numCols; i++)
767                 appendStringInfo(str, " %d", node->uniqColIdx[i]);
768
769         appendStringInfoString(str, " :uniqOperators");
770         for (i = 0; i < node->numCols; i++)
771                 appendStringInfo(str, " %u", node->uniqOperators[i]);
772 }
773
774 static void
775 _outHash(StringInfo str, const Hash *node)
776 {
777         WRITE_NODE_TYPE("HASH");
778
779         _outPlanInfo(str, (const Plan *) node);
780
781         WRITE_OID_FIELD(skewTable);
782         WRITE_INT_FIELD(skewColumn);
783         WRITE_BOOL_FIELD(skewInherit);
784         WRITE_OID_FIELD(skewColType);
785         WRITE_INT_FIELD(skewColTypmod);
786 }
787
788 static void
789 _outSetOp(StringInfo str, const SetOp *node)
790 {
791         int                     i;
792
793         WRITE_NODE_TYPE("SETOP");
794
795         _outPlanInfo(str, (const Plan *) node);
796
797         WRITE_ENUM_FIELD(cmd, SetOpCmd);
798         WRITE_ENUM_FIELD(strategy, SetOpStrategy);
799         WRITE_INT_FIELD(numCols);
800
801         appendStringInfoString(str, " :dupColIdx");
802         for (i = 0; i < node->numCols; i++)
803                 appendStringInfo(str, " %d", node->dupColIdx[i]);
804
805         appendStringInfoString(str, " :dupOperators");
806         for (i = 0; i < node->numCols; i++)
807                 appendStringInfo(str, " %u", node->dupOperators[i]);
808
809         WRITE_INT_FIELD(flagColIdx);
810         WRITE_INT_FIELD(firstFlag);
811         WRITE_LONG_FIELD(numGroups);
812 }
813
814 static void
815 _outLockRows(StringInfo str, const LockRows *node)
816 {
817         WRITE_NODE_TYPE("LOCKROWS");
818
819         _outPlanInfo(str, (const Plan *) node);
820
821         WRITE_NODE_FIELD(rowMarks);
822         WRITE_INT_FIELD(epqParam);
823 }
824
825 static void
826 _outLimit(StringInfo str, const Limit *node)
827 {
828         WRITE_NODE_TYPE("LIMIT");
829
830         _outPlanInfo(str, (const Plan *) node);
831
832         WRITE_NODE_FIELD(limitOffset);
833         WRITE_NODE_FIELD(limitCount);
834 }
835
836 static void
837 _outNestLoopParam(StringInfo str, const NestLoopParam *node)
838 {
839         WRITE_NODE_TYPE("NESTLOOPPARAM");
840
841         WRITE_INT_FIELD(paramno);
842         WRITE_NODE_FIELD(paramval);
843 }
844
845 static void
846 _outPlanRowMark(StringInfo str, const PlanRowMark *node)
847 {
848         WRITE_NODE_TYPE("PLANROWMARK");
849
850         WRITE_UINT_FIELD(rti);
851         WRITE_UINT_FIELD(prti);
852         WRITE_UINT_FIELD(rowmarkId);
853         WRITE_ENUM_FIELD(markType, RowMarkType);
854         WRITE_BOOL_FIELD(waitPolicy);
855         WRITE_BOOL_FIELD(isParent);
856 }
857
858 static void
859 _outPlanInvalItem(StringInfo str, const PlanInvalItem *node)
860 {
861         WRITE_NODE_TYPE("PLANINVALITEM");
862
863         WRITE_INT_FIELD(cacheId);
864         WRITE_UINT_FIELD(hashValue);
865 }
866
867 /*****************************************************************************
868  *
869  *      Stuff from primnodes.h.
870  *
871  *****************************************************************************/
872
873 static void
874 _outAlias(StringInfo str, const Alias *node)
875 {
876         WRITE_NODE_TYPE("ALIAS");
877
878         WRITE_STRING_FIELD(aliasname);
879         WRITE_NODE_FIELD(colnames);
880 }
881
882 static void
883 _outRangeVar(StringInfo str, const RangeVar *node)
884 {
885         WRITE_NODE_TYPE("RANGEVAR");
886
887         /*
888          * we deliberately ignore catalogname here, since it is presently not
889          * semantically meaningful
890          */
891         WRITE_STRING_FIELD(schemaname);
892         WRITE_STRING_FIELD(relname);
893         WRITE_ENUM_FIELD(inhOpt, InhOption);
894         WRITE_CHAR_FIELD(relpersistence);
895         WRITE_NODE_FIELD(alias);
896         WRITE_LOCATION_FIELD(location);
897 }
898
899 static void
900 _outIntoClause(StringInfo str, const IntoClause *node)
901 {
902         WRITE_NODE_TYPE("INTOCLAUSE");
903
904         WRITE_NODE_FIELD(rel);
905         WRITE_NODE_FIELD(colNames);
906         WRITE_NODE_FIELD(options);
907         WRITE_ENUM_FIELD(onCommit, OnCommitAction);
908         WRITE_STRING_FIELD(tableSpaceName);
909         WRITE_NODE_FIELD(viewQuery);
910         WRITE_BOOL_FIELD(skipData);
911 }
912
913 static void
914 _outVar(StringInfo str, const Var *node)
915 {
916         WRITE_NODE_TYPE("VAR");
917
918         WRITE_UINT_FIELD(varno);
919         WRITE_INT_FIELD(varattno);
920         WRITE_OID_FIELD(vartype);
921         WRITE_INT_FIELD(vartypmod);
922         WRITE_OID_FIELD(varcollid);
923         WRITE_UINT_FIELD(varlevelsup);
924         WRITE_UINT_FIELD(varnoold);
925         WRITE_INT_FIELD(varoattno);
926         WRITE_LOCATION_FIELD(location);
927 }
928
929 static void
930 _outConst(StringInfo str, const Const *node)
931 {
932         WRITE_NODE_TYPE("CONST");
933
934         WRITE_OID_FIELD(consttype);
935         WRITE_INT_FIELD(consttypmod);
936         WRITE_OID_FIELD(constcollid);
937         WRITE_INT_FIELD(constlen);
938         WRITE_BOOL_FIELD(constbyval);
939         WRITE_BOOL_FIELD(constisnull);
940         WRITE_LOCATION_FIELD(location);
941
942         appendStringInfoString(str, " :constvalue ");
943         if (node->constisnull)
944                 appendStringInfoString(str, "<>");
945         else
946                 _outDatum(str, node->constvalue, node->constlen, node->constbyval);
947 }
948
949 static void
950 _outParam(StringInfo str, const Param *node)
951 {
952         WRITE_NODE_TYPE("PARAM");
953
954         WRITE_ENUM_FIELD(paramkind, ParamKind);
955         WRITE_INT_FIELD(paramid);
956         WRITE_OID_FIELD(paramtype);
957         WRITE_INT_FIELD(paramtypmod);
958         WRITE_OID_FIELD(paramcollid);
959         WRITE_LOCATION_FIELD(location);
960 }
961
962 static void
963 _outAggref(StringInfo str, const Aggref *node)
964 {
965         WRITE_NODE_TYPE("AGGREF");
966
967         WRITE_OID_FIELD(aggfnoid);
968         WRITE_OID_FIELD(aggtype);
969         WRITE_OID_FIELD(aggcollid);
970         WRITE_OID_FIELD(inputcollid);
971         WRITE_NODE_FIELD(aggdirectargs);
972         WRITE_NODE_FIELD(args);
973         WRITE_NODE_FIELD(aggorder);
974         WRITE_NODE_FIELD(aggdistinct);
975         WRITE_NODE_FIELD(aggfilter);
976         WRITE_BOOL_FIELD(aggstar);
977         WRITE_BOOL_FIELD(aggvariadic);
978         WRITE_CHAR_FIELD(aggkind);
979         WRITE_UINT_FIELD(agglevelsup);
980         WRITE_LOCATION_FIELD(location);
981 }
982
983 static void
984 _outWindowFunc(StringInfo str, const WindowFunc *node)
985 {
986         WRITE_NODE_TYPE("WINDOWFUNC");
987
988         WRITE_OID_FIELD(winfnoid);
989         WRITE_OID_FIELD(wintype);
990         WRITE_OID_FIELD(wincollid);
991         WRITE_OID_FIELD(inputcollid);
992         WRITE_NODE_FIELD(args);
993         WRITE_NODE_FIELD(aggfilter);
994         WRITE_UINT_FIELD(winref);
995         WRITE_BOOL_FIELD(winstar);
996         WRITE_BOOL_FIELD(winagg);
997         WRITE_LOCATION_FIELD(location);
998 }
999
1000 static void
1001 _outArrayRef(StringInfo str, const ArrayRef *node)
1002 {
1003         WRITE_NODE_TYPE("ARRAYREF");
1004
1005         WRITE_OID_FIELD(refarraytype);
1006         WRITE_OID_FIELD(refelemtype);
1007         WRITE_INT_FIELD(reftypmod);
1008         WRITE_OID_FIELD(refcollid);
1009         WRITE_NODE_FIELD(refupperindexpr);
1010         WRITE_NODE_FIELD(reflowerindexpr);
1011         WRITE_NODE_FIELD(refexpr);
1012         WRITE_NODE_FIELD(refassgnexpr);
1013 }
1014
1015 static void
1016 _outFuncExpr(StringInfo str, const FuncExpr *node)
1017 {
1018         WRITE_NODE_TYPE("FUNCEXPR");
1019
1020         WRITE_OID_FIELD(funcid);
1021         WRITE_OID_FIELD(funcresulttype);
1022         WRITE_BOOL_FIELD(funcretset);
1023         WRITE_BOOL_FIELD(funcvariadic);
1024         WRITE_ENUM_FIELD(funcformat, CoercionForm);
1025         WRITE_OID_FIELD(funccollid);
1026         WRITE_OID_FIELD(inputcollid);
1027         WRITE_NODE_FIELD(args);
1028         WRITE_LOCATION_FIELD(location);
1029 }
1030
1031 static void
1032 _outNamedArgExpr(StringInfo str, const NamedArgExpr *node)
1033 {
1034         WRITE_NODE_TYPE("NAMEDARGEXPR");
1035
1036         WRITE_NODE_FIELD(arg);
1037         WRITE_STRING_FIELD(name);
1038         WRITE_INT_FIELD(argnumber);
1039         WRITE_LOCATION_FIELD(location);
1040 }
1041
1042 static void
1043 _outOpExpr(StringInfo str, const OpExpr *node)
1044 {
1045         WRITE_NODE_TYPE("OPEXPR");
1046
1047         WRITE_OID_FIELD(opno);
1048         WRITE_OID_FIELD(opfuncid);
1049         WRITE_OID_FIELD(opresulttype);
1050         WRITE_BOOL_FIELD(opretset);
1051         WRITE_OID_FIELD(opcollid);
1052         WRITE_OID_FIELD(inputcollid);
1053         WRITE_NODE_FIELD(args);
1054         WRITE_LOCATION_FIELD(location);
1055 }
1056
1057 static void
1058 _outDistinctExpr(StringInfo str, const DistinctExpr *node)
1059 {
1060         WRITE_NODE_TYPE("DISTINCTEXPR");
1061
1062         WRITE_OID_FIELD(opno);
1063         WRITE_OID_FIELD(opfuncid);
1064         WRITE_OID_FIELD(opresulttype);
1065         WRITE_BOOL_FIELD(opretset);
1066         WRITE_OID_FIELD(opcollid);
1067         WRITE_OID_FIELD(inputcollid);
1068         WRITE_NODE_FIELD(args);
1069         WRITE_LOCATION_FIELD(location);
1070 }
1071
1072 static void
1073 _outNullIfExpr(StringInfo str, const NullIfExpr *node)
1074 {
1075         WRITE_NODE_TYPE("NULLIFEXPR");
1076
1077         WRITE_OID_FIELD(opno);
1078         WRITE_OID_FIELD(opfuncid);
1079         WRITE_OID_FIELD(opresulttype);
1080         WRITE_BOOL_FIELD(opretset);
1081         WRITE_OID_FIELD(opcollid);
1082         WRITE_OID_FIELD(inputcollid);
1083         WRITE_NODE_FIELD(args);
1084         WRITE_LOCATION_FIELD(location);
1085 }
1086
1087 static void
1088 _outScalarArrayOpExpr(StringInfo str, const ScalarArrayOpExpr *node)
1089 {
1090         WRITE_NODE_TYPE("SCALARARRAYOPEXPR");
1091
1092         WRITE_OID_FIELD(opno);
1093         WRITE_OID_FIELD(opfuncid);
1094         WRITE_BOOL_FIELD(useOr);
1095         WRITE_OID_FIELD(inputcollid);
1096         WRITE_NODE_FIELD(args);
1097         WRITE_LOCATION_FIELD(location);
1098 }
1099
1100 static void
1101 _outBoolExpr(StringInfo str, const BoolExpr *node)
1102 {
1103         char       *opstr = NULL;
1104
1105         WRITE_NODE_TYPE("BOOLEXPR");
1106
1107         /* do-it-yourself enum representation */
1108         switch (node->boolop)
1109         {
1110                 case AND_EXPR:
1111                         opstr = "and";
1112                         break;
1113                 case OR_EXPR:
1114                         opstr = "or";
1115                         break;
1116                 case NOT_EXPR:
1117                         opstr = "not";
1118                         break;
1119         }
1120         appendStringInfoString(str, " :boolop ");
1121         _outToken(str, opstr);
1122
1123         WRITE_NODE_FIELD(args);
1124         WRITE_LOCATION_FIELD(location);
1125 }
1126
1127 static void
1128 _outSubLink(StringInfo str, const SubLink *node)
1129 {
1130         WRITE_NODE_TYPE("SUBLINK");
1131
1132         WRITE_ENUM_FIELD(subLinkType, SubLinkType);
1133         WRITE_INT_FIELD(subLinkId);
1134         WRITE_NODE_FIELD(testexpr);
1135         WRITE_NODE_FIELD(operName);
1136         WRITE_NODE_FIELD(subselect);
1137         WRITE_LOCATION_FIELD(location);
1138 }
1139
1140 static void
1141 _outSubPlan(StringInfo str, const SubPlan *node)
1142 {
1143         WRITE_NODE_TYPE("SUBPLAN");
1144
1145         WRITE_ENUM_FIELD(subLinkType, SubLinkType);
1146         WRITE_NODE_FIELD(testexpr);
1147         WRITE_NODE_FIELD(paramIds);
1148         WRITE_INT_FIELD(plan_id);
1149         WRITE_STRING_FIELD(plan_name);
1150         WRITE_OID_FIELD(firstColType);
1151         WRITE_INT_FIELD(firstColTypmod);
1152         WRITE_OID_FIELD(firstColCollation);
1153         WRITE_BOOL_FIELD(useHashTable);
1154         WRITE_BOOL_FIELD(unknownEqFalse);
1155         WRITE_NODE_FIELD(setParam);
1156         WRITE_NODE_FIELD(parParam);
1157         WRITE_NODE_FIELD(args);
1158         WRITE_FLOAT_FIELD(startup_cost, "%.2f");
1159         WRITE_FLOAT_FIELD(per_call_cost, "%.2f");
1160 }
1161
1162 static void
1163 _outAlternativeSubPlan(StringInfo str, const AlternativeSubPlan *node)
1164 {
1165         WRITE_NODE_TYPE("ALTERNATIVESUBPLAN");
1166
1167         WRITE_NODE_FIELD(subplans);
1168 }
1169
1170 static void
1171 _outFieldSelect(StringInfo str, const FieldSelect *node)
1172 {
1173         WRITE_NODE_TYPE("FIELDSELECT");
1174
1175         WRITE_NODE_FIELD(arg);
1176         WRITE_INT_FIELD(fieldnum);
1177         WRITE_OID_FIELD(resulttype);
1178         WRITE_INT_FIELD(resulttypmod);
1179         WRITE_OID_FIELD(resultcollid);
1180 }
1181
1182 static void
1183 _outFieldStore(StringInfo str, const FieldStore *node)
1184 {
1185         WRITE_NODE_TYPE("FIELDSTORE");
1186
1187         WRITE_NODE_FIELD(arg);
1188         WRITE_NODE_FIELD(newvals);
1189         WRITE_NODE_FIELD(fieldnums);
1190         WRITE_OID_FIELD(resulttype);
1191 }
1192
1193 static void
1194 _outRelabelType(StringInfo str, const RelabelType *node)
1195 {
1196         WRITE_NODE_TYPE("RELABELTYPE");
1197
1198         WRITE_NODE_FIELD(arg);
1199         WRITE_OID_FIELD(resulttype);
1200         WRITE_INT_FIELD(resulttypmod);
1201         WRITE_OID_FIELD(resultcollid);
1202         WRITE_ENUM_FIELD(relabelformat, CoercionForm);
1203         WRITE_LOCATION_FIELD(location);
1204 }
1205
1206 static void
1207 _outCoerceViaIO(StringInfo str, const CoerceViaIO *node)
1208 {
1209         WRITE_NODE_TYPE("COERCEVIAIO");
1210
1211         WRITE_NODE_FIELD(arg);
1212         WRITE_OID_FIELD(resulttype);
1213         WRITE_OID_FIELD(resultcollid);
1214         WRITE_ENUM_FIELD(coerceformat, CoercionForm);
1215         WRITE_LOCATION_FIELD(location);
1216 }
1217
1218 static void
1219 _outArrayCoerceExpr(StringInfo str, const ArrayCoerceExpr *node)
1220 {
1221         WRITE_NODE_TYPE("ARRAYCOERCEEXPR");
1222
1223         WRITE_NODE_FIELD(arg);
1224         WRITE_OID_FIELD(elemfuncid);
1225         WRITE_OID_FIELD(resulttype);
1226         WRITE_INT_FIELD(resulttypmod);
1227         WRITE_OID_FIELD(resultcollid);
1228         WRITE_BOOL_FIELD(isExplicit);
1229         WRITE_ENUM_FIELD(coerceformat, CoercionForm);
1230         WRITE_LOCATION_FIELD(location);
1231 }
1232
1233 static void
1234 _outConvertRowtypeExpr(StringInfo str, const ConvertRowtypeExpr *node)
1235 {
1236         WRITE_NODE_TYPE("CONVERTROWTYPEEXPR");
1237
1238         WRITE_NODE_FIELD(arg);
1239         WRITE_OID_FIELD(resulttype);
1240         WRITE_ENUM_FIELD(convertformat, CoercionForm);
1241         WRITE_LOCATION_FIELD(location);
1242 }
1243
1244 static void
1245 _outCollateExpr(StringInfo str, const CollateExpr *node)
1246 {
1247         WRITE_NODE_TYPE("COLLATE");
1248
1249         WRITE_NODE_FIELD(arg);
1250         WRITE_OID_FIELD(collOid);
1251         WRITE_LOCATION_FIELD(location);
1252 }
1253
1254 static void
1255 _outCaseExpr(StringInfo str, const CaseExpr *node)
1256 {
1257         WRITE_NODE_TYPE("CASE");
1258
1259         WRITE_OID_FIELD(casetype);
1260         WRITE_OID_FIELD(casecollid);
1261         WRITE_NODE_FIELD(arg);
1262         WRITE_NODE_FIELD(args);
1263         WRITE_NODE_FIELD(defresult);
1264         WRITE_LOCATION_FIELD(location);
1265 }
1266
1267 static void
1268 _outCaseWhen(StringInfo str, const CaseWhen *node)
1269 {
1270         WRITE_NODE_TYPE("WHEN");
1271
1272         WRITE_NODE_FIELD(expr);
1273         WRITE_NODE_FIELD(result);
1274         WRITE_LOCATION_FIELD(location);
1275 }
1276
1277 static void
1278 _outCaseTestExpr(StringInfo str, const CaseTestExpr *node)
1279 {
1280         WRITE_NODE_TYPE("CASETESTEXPR");
1281
1282         WRITE_OID_FIELD(typeId);
1283         WRITE_INT_FIELD(typeMod);
1284         WRITE_OID_FIELD(collation);
1285 }
1286
1287 static void
1288 _outArrayExpr(StringInfo str, const ArrayExpr *node)
1289 {
1290         WRITE_NODE_TYPE("ARRAY");
1291
1292         WRITE_OID_FIELD(array_typeid);
1293         WRITE_OID_FIELD(array_collid);
1294         WRITE_OID_FIELD(element_typeid);
1295         WRITE_NODE_FIELD(elements);
1296         WRITE_BOOL_FIELD(multidims);
1297         WRITE_LOCATION_FIELD(location);
1298 }
1299
1300 static void
1301 _outRowExpr(StringInfo str, const RowExpr *node)
1302 {
1303         WRITE_NODE_TYPE("ROW");
1304
1305         WRITE_NODE_FIELD(args);
1306         WRITE_OID_FIELD(row_typeid);
1307         WRITE_ENUM_FIELD(row_format, CoercionForm);
1308         WRITE_NODE_FIELD(colnames);
1309         WRITE_LOCATION_FIELD(location);
1310 }
1311
1312 static void
1313 _outRowCompareExpr(StringInfo str, const RowCompareExpr *node)
1314 {
1315         WRITE_NODE_TYPE("ROWCOMPARE");
1316
1317         WRITE_ENUM_FIELD(rctype, RowCompareType);
1318         WRITE_NODE_FIELD(opnos);
1319         WRITE_NODE_FIELD(opfamilies);
1320         WRITE_NODE_FIELD(inputcollids);
1321         WRITE_NODE_FIELD(largs);
1322         WRITE_NODE_FIELD(rargs);
1323 }
1324
1325 static void
1326 _outCoalesceExpr(StringInfo str, const CoalesceExpr *node)
1327 {
1328         WRITE_NODE_TYPE("COALESCE");
1329
1330         WRITE_OID_FIELD(coalescetype);
1331         WRITE_OID_FIELD(coalescecollid);
1332         WRITE_NODE_FIELD(args);
1333         WRITE_LOCATION_FIELD(location);
1334 }
1335
1336 static void
1337 _outMinMaxExpr(StringInfo str, const MinMaxExpr *node)
1338 {
1339         WRITE_NODE_TYPE("MINMAX");
1340
1341         WRITE_OID_FIELD(minmaxtype);
1342         WRITE_OID_FIELD(minmaxcollid);
1343         WRITE_OID_FIELD(inputcollid);
1344         WRITE_ENUM_FIELD(op, MinMaxOp);
1345         WRITE_NODE_FIELD(args);
1346         WRITE_LOCATION_FIELD(location);
1347 }
1348
1349 static void
1350 _outXmlExpr(StringInfo str, const XmlExpr *node)
1351 {
1352         WRITE_NODE_TYPE("XMLEXPR");
1353
1354         WRITE_ENUM_FIELD(op, XmlExprOp);
1355         WRITE_STRING_FIELD(name);
1356         WRITE_NODE_FIELD(named_args);
1357         WRITE_NODE_FIELD(arg_names);
1358         WRITE_NODE_FIELD(args);
1359         WRITE_ENUM_FIELD(xmloption, XmlOptionType);
1360         WRITE_OID_FIELD(type);
1361         WRITE_INT_FIELD(typmod);
1362         WRITE_LOCATION_FIELD(location);
1363 }
1364
1365 static void
1366 _outNullTest(StringInfo str, const NullTest *node)
1367 {
1368         WRITE_NODE_TYPE("NULLTEST");
1369
1370         WRITE_NODE_FIELD(arg);
1371         WRITE_ENUM_FIELD(nulltesttype, NullTestType);
1372         WRITE_BOOL_FIELD(argisrow);
1373         WRITE_LOCATION_FIELD(location);
1374 }
1375
1376 static void
1377 _outBooleanTest(StringInfo str, const BooleanTest *node)
1378 {
1379         WRITE_NODE_TYPE("BOOLEANTEST");
1380
1381         WRITE_NODE_FIELD(arg);
1382         WRITE_ENUM_FIELD(booltesttype, BoolTestType);
1383         WRITE_LOCATION_FIELD(location);
1384 }
1385
1386 static void
1387 _outCoerceToDomain(StringInfo str, const CoerceToDomain *node)
1388 {
1389         WRITE_NODE_TYPE("COERCETODOMAIN");
1390
1391         WRITE_NODE_FIELD(arg);
1392         WRITE_OID_FIELD(resulttype);
1393         WRITE_INT_FIELD(resulttypmod);
1394         WRITE_OID_FIELD(resultcollid);
1395         WRITE_ENUM_FIELD(coercionformat, CoercionForm);
1396         WRITE_LOCATION_FIELD(location);
1397 }
1398
1399 static void
1400 _outCoerceToDomainValue(StringInfo str, const CoerceToDomainValue *node)
1401 {
1402         WRITE_NODE_TYPE("COERCETODOMAINVALUE");
1403
1404         WRITE_OID_FIELD(typeId);
1405         WRITE_INT_FIELD(typeMod);
1406         WRITE_OID_FIELD(collation);
1407         WRITE_LOCATION_FIELD(location);
1408 }
1409
1410 static void
1411 _outSetToDefault(StringInfo str, const SetToDefault *node)
1412 {
1413         WRITE_NODE_TYPE("SETTODEFAULT");
1414
1415         WRITE_OID_FIELD(typeId);
1416         WRITE_INT_FIELD(typeMod);
1417         WRITE_OID_FIELD(collation);
1418         WRITE_LOCATION_FIELD(location);
1419 }
1420
1421 static void
1422 _outCurrentOfExpr(StringInfo str, const CurrentOfExpr *node)
1423 {
1424         WRITE_NODE_TYPE("CURRENTOFEXPR");
1425
1426         WRITE_UINT_FIELD(cvarno);
1427         WRITE_STRING_FIELD(cursor_name);
1428         WRITE_INT_FIELD(cursor_param);
1429 }
1430
1431 static void
1432 _outTargetEntry(StringInfo str, const TargetEntry *node)
1433 {
1434         WRITE_NODE_TYPE("TARGETENTRY");
1435
1436         WRITE_NODE_FIELD(expr);
1437         WRITE_INT_FIELD(resno);
1438         WRITE_STRING_FIELD(resname);
1439         WRITE_UINT_FIELD(ressortgroupref);
1440         WRITE_OID_FIELD(resorigtbl);
1441         WRITE_INT_FIELD(resorigcol);
1442         WRITE_BOOL_FIELD(resjunk);
1443 }
1444
1445 static void
1446 _outRangeTblRef(StringInfo str, const RangeTblRef *node)
1447 {
1448         WRITE_NODE_TYPE("RANGETBLREF");
1449
1450         WRITE_INT_FIELD(rtindex);
1451 }
1452
1453 static void
1454 _outJoinExpr(StringInfo str, const JoinExpr *node)
1455 {
1456         WRITE_NODE_TYPE("JOINEXPR");
1457
1458         WRITE_ENUM_FIELD(jointype, JoinType);
1459         WRITE_BOOL_FIELD(isNatural);
1460         WRITE_NODE_FIELD(larg);
1461         WRITE_NODE_FIELD(rarg);
1462         WRITE_NODE_FIELD(usingClause);
1463         WRITE_NODE_FIELD(quals);
1464         WRITE_NODE_FIELD(alias);
1465         WRITE_INT_FIELD(rtindex);
1466 }
1467
1468 static void
1469 _outFromExpr(StringInfo str, const FromExpr *node)
1470 {
1471         WRITE_NODE_TYPE("FROMEXPR");
1472
1473         WRITE_NODE_FIELD(fromlist);
1474         WRITE_NODE_FIELD(quals);
1475 }
1476
1477 /*****************************************************************************
1478  *
1479  *      Stuff from relation.h.
1480  *
1481  *****************************************************************************/
1482
1483 /*
1484  * print the basic stuff of all nodes that inherit from Path
1485  *
1486  * Note we do NOT print the parent, else we'd be in infinite recursion.
1487  * We can print the parent's relids for identification purposes, though.
1488  * We also do not print the whole of param_info, since it's printed by
1489  * _outRelOptInfo; it's sufficient and less cluttering to print just the
1490  * required outer relids.
1491  */
1492 static void
1493 _outPathInfo(StringInfo str, const Path *node)
1494 {
1495         WRITE_ENUM_FIELD(pathtype, NodeTag);
1496         appendStringInfoString(str, " :parent_relids ");
1497         if (node->parent)
1498                 _outBitmapset(str, node->parent->relids);
1499         else
1500                 _outBitmapset(str, NULL);
1501         appendStringInfoString(str, " :required_outer ");
1502         if (node->param_info)
1503                 _outBitmapset(str, node->param_info->ppi_req_outer);
1504         else
1505                 _outBitmapset(str, NULL);
1506         WRITE_FLOAT_FIELD(rows, "%.0f");
1507         WRITE_FLOAT_FIELD(startup_cost, "%.2f");
1508         WRITE_FLOAT_FIELD(total_cost, "%.2f");
1509         WRITE_NODE_FIELD(pathkeys);
1510 }
1511
1512 /*
1513  * print the basic stuff of all nodes that inherit from JoinPath
1514  */
1515 static void
1516 _outJoinPathInfo(StringInfo str, const JoinPath *node)
1517 {
1518         _outPathInfo(str, (const Path *) node);
1519
1520         WRITE_ENUM_FIELD(jointype, JoinType);
1521         WRITE_NODE_FIELD(outerjoinpath);
1522         WRITE_NODE_FIELD(innerjoinpath);
1523         WRITE_NODE_FIELD(joinrestrictinfo);
1524 }
1525
1526 static void
1527 _outPath(StringInfo str, const Path *node)
1528 {
1529         WRITE_NODE_TYPE("PATH");
1530
1531         _outPathInfo(str, (const Path *) node);
1532 }
1533
1534 static void
1535 _outIndexPath(StringInfo str, const IndexPath *node)
1536 {
1537         WRITE_NODE_TYPE("INDEXPATH");
1538
1539         _outPathInfo(str, (const Path *) node);
1540
1541         WRITE_NODE_FIELD(indexinfo);
1542         WRITE_NODE_FIELD(indexclauses);
1543         WRITE_NODE_FIELD(indexquals);
1544         WRITE_NODE_FIELD(indexqualcols);
1545         WRITE_NODE_FIELD(indexorderbys);
1546         WRITE_NODE_FIELD(indexorderbycols);
1547         WRITE_ENUM_FIELD(indexscandir, ScanDirection);
1548         WRITE_FLOAT_FIELD(indextotalcost, "%.2f");
1549         WRITE_FLOAT_FIELD(indexselectivity, "%.4f");
1550 }
1551
1552 static void
1553 _outBitmapHeapPath(StringInfo str, const BitmapHeapPath *node)
1554 {
1555         WRITE_NODE_TYPE("BITMAPHEAPPATH");
1556
1557         _outPathInfo(str, (const Path *) node);
1558
1559         WRITE_NODE_FIELD(bitmapqual);
1560 }
1561
1562 static void
1563 _outBitmapAndPath(StringInfo str, const BitmapAndPath *node)
1564 {
1565         WRITE_NODE_TYPE("BITMAPANDPATH");
1566
1567         _outPathInfo(str, (const Path *) node);
1568
1569         WRITE_NODE_FIELD(bitmapquals);
1570         WRITE_FLOAT_FIELD(bitmapselectivity, "%.4f");
1571 }
1572
1573 static void
1574 _outBitmapOrPath(StringInfo str, const BitmapOrPath *node)
1575 {
1576         WRITE_NODE_TYPE("BITMAPORPATH");
1577
1578         _outPathInfo(str, (const Path *) node);
1579
1580         WRITE_NODE_FIELD(bitmapquals);
1581         WRITE_FLOAT_FIELD(bitmapselectivity, "%.4f");
1582 }
1583
1584 static void
1585 _outTidPath(StringInfo str, const TidPath *node)
1586 {
1587         WRITE_NODE_TYPE("TIDPATH");
1588
1589         _outPathInfo(str, (const Path *) node);
1590
1591         WRITE_NODE_FIELD(tidquals);
1592 }
1593
1594 static void
1595 _outForeignPath(StringInfo str, const ForeignPath *node)
1596 {
1597         WRITE_NODE_TYPE("FOREIGNPATH");
1598
1599         _outPathInfo(str, (const Path *) node);
1600
1601         WRITE_NODE_FIELD(fdw_private);
1602 }
1603
1604 static void
1605 _outCustomPath(StringInfo str, const CustomPath *node)
1606 {
1607         WRITE_NODE_TYPE("CUSTOMPATH");
1608
1609         _outPathInfo(str, (const Path *) node);
1610
1611         WRITE_UINT_FIELD(flags);
1612         WRITE_NODE_FIELD(custom_private);
1613         appendStringInfoString(str, " :methods ");
1614         _outToken(str, node->methods->CustomName);
1615         if (node->methods->TextOutCustomPath)
1616                 node->methods->TextOutCustomPath(str, node);
1617 }
1618
1619 static void
1620 _outAppendPath(StringInfo str, const AppendPath *node)
1621 {
1622         WRITE_NODE_TYPE("APPENDPATH");
1623
1624         _outPathInfo(str, (const Path *) node);
1625
1626         WRITE_NODE_FIELD(subpaths);
1627 }
1628
1629 static void
1630 _outMergeAppendPath(StringInfo str, const MergeAppendPath *node)
1631 {
1632         WRITE_NODE_TYPE("MERGEAPPENDPATH");
1633
1634         _outPathInfo(str, (const Path *) node);
1635
1636         WRITE_NODE_FIELD(subpaths);
1637         WRITE_FLOAT_FIELD(limit_tuples, "%.0f");
1638 }
1639
1640 static void
1641 _outResultPath(StringInfo str, const ResultPath *node)
1642 {
1643         WRITE_NODE_TYPE("RESULTPATH");
1644
1645         _outPathInfo(str, (const Path *) node);
1646
1647         WRITE_NODE_FIELD(quals);
1648 }
1649
1650 static void
1651 _outMaterialPath(StringInfo str, const MaterialPath *node)
1652 {
1653         WRITE_NODE_TYPE("MATERIALPATH");
1654
1655         _outPathInfo(str, (const Path *) node);
1656
1657         WRITE_NODE_FIELD(subpath);
1658 }
1659
1660 static void
1661 _outUniquePath(StringInfo str, const UniquePath *node)
1662 {
1663         WRITE_NODE_TYPE("UNIQUEPATH");
1664
1665         _outPathInfo(str, (const Path *) node);
1666
1667         WRITE_NODE_FIELD(subpath);
1668         WRITE_ENUM_FIELD(umethod, UniquePathMethod);
1669         WRITE_NODE_FIELD(in_operators);
1670         WRITE_NODE_FIELD(uniq_exprs);
1671 }
1672
1673 static void
1674 _outNestPath(StringInfo str, const NestPath *node)
1675 {
1676         WRITE_NODE_TYPE("NESTPATH");
1677
1678         _outJoinPathInfo(str, (const JoinPath *) node);
1679 }
1680
1681 static void
1682 _outMergePath(StringInfo str, const MergePath *node)
1683 {
1684         WRITE_NODE_TYPE("MERGEPATH");
1685
1686         _outJoinPathInfo(str, (const JoinPath *) node);
1687
1688         WRITE_NODE_FIELD(path_mergeclauses);
1689         WRITE_NODE_FIELD(outersortkeys);
1690         WRITE_NODE_FIELD(innersortkeys);
1691         WRITE_BOOL_FIELD(materialize_inner);
1692 }
1693
1694 static void
1695 _outHashPath(StringInfo str, const HashPath *node)
1696 {
1697         WRITE_NODE_TYPE("HASHPATH");
1698
1699         _outJoinPathInfo(str, (const JoinPath *) node);
1700
1701         WRITE_NODE_FIELD(path_hashclauses);
1702         WRITE_INT_FIELD(num_batches);
1703 }
1704
1705 static void
1706 _outPlannerGlobal(StringInfo str, const PlannerGlobal *node)
1707 {
1708         WRITE_NODE_TYPE("PLANNERGLOBAL");
1709
1710         /* NB: this isn't a complete set of fields */
1711         WRITE_NODE_FIELD(subplans);
1712         WRITE_BITMAPSET_FIELD(rewindPlanIDs);
1713         WRITE_NODE_FIELD(finalrtable);
1714         WRITE_NODE_FIELD(finalrowmarks);
1715         WRITE_NODE_FIELD(resultRelations);
1716         WRITE_NODE_FIELD(relationOids);
1717         WRITE_NODE_FIELD(invalItems);
1718         WRITE_INT_FIELD(nParamExec);
1719         WRITE_UINT_FIELD(lastPHId);
1720         WRITE_UINT_FIELD(lastRowMarkId);
1721         WRITE_BOOL_FIELD(transientPlan);
1722 }
1723
1724 static void
1725 _outPlannerInfo(StringInfo str, const PlannerInfo *node)
1726 {
1727         WRITE_NODE_TYPE("PLANNERINFO");
1728
1729         /* NB: this isn't a complete set of fields */
1730         WRITE_NODE_FIELD(parse);
1731         WRITE_NODE_FIELD(glob);
1732         WRITE_UINT_FIELD(query_level);
1733         WRITE_NODE_FIELD(plan_params);
1734         WRITE_BITMAPSET_FIELD(all_baserels);
1735         WRITE_BITMAPSET_FIELD(nullable_baserels);
1736         WRITE_NODE_FIELD(join_rel_list);
1737         WRITE_INT_FIELD(join_cur_level);
1738         WRITE_NODE_FIELD(init_plans);
1739         WRITE_NODE_FIELD(cte_plan_ids);
1740         WRITE_NODE_FIELD(multiexpr_params);
1741         WRITE_NODE_FIELD(eq_classes);
1742         WRITE_NODE_FIELD(canon_pathkeys);
1743         WRITE_NODE_FIELD(left_join_clauses);
1744         WRITE_NODE_FIELD(right_join_clauses);
1745         WRITE_NODE_FIELD(full_join_clauses);
1746         WRITE_NODE_FIELD(join_info_list);
1747         WRITE_NODE_FIELD(lateral_info_list);
1748         WRITE_NODE_FIELD(append_rel_list);
1749         WRITE_NODE_FIELD(rowMarks);
1750         WRITE_NODE_FIELD(placeholder_list);
1751         WRITE_NODE_FIELD(query_pathkeys);
1752         WRITE_NODE_FIELD(group_pathkeys);
1753         WRITE_NODE_FIELD(window_pathkeys);
1754         WRITE_NODE_FIELD(distinct_pathkeys);
1755         WRITE_NODE_FIELD(sort_pathkeys);
1756         WRITE_NODE_FIELD(minmax_aggs);
1757         WRITE_FLOAT_FIELD(total_table_pages, "%.0f");
1758         WRITE_FLOAT_FIELD(tuple_fraction, "%.4f");
1759         WRITE_FLOAT_FIELD(limit_tuples, "%.0f");
1760         WRITE_BOOL_FIELD(hasInheritedTarget);
1761         WRITE_BOOL_FIELD(hasJoinRTEs);
1762         WRITE_BOOL_FIELD(hasLateralRTEs);
1763         WRITE_BOOL_FIELD(hasHavingQual);
1764         WRITE_BOOL_FIELD(hasPseudoConstantQuals);
1765         WRITE_BOOL_FIELD(hasRecursion);
1766         WRITE_INT_FIELD(wt_param_id);
1767         WRITE_BITMAPSET_FIELD(curOuterRels);
1768         WRITE_NODE_FIELD(curOuterParams);
1769 }
1770
1771 static void
1772 _outRelOptInfo(StringInfo str, const RelOptInfo *node)
1773 {
1774         WRITE_NODE_TYPE("RELOPTINFO");
1775
1776         /* NB: this isn't a complete set of fields */
1777         WRITE_ENUM_FIELD(reloptkind, RelOptKind);
1778         WRITE_BITMAPSET_FIELD(relids);
1779         WRITE_FLOAT_FIELD(rows, "%.0f");
1780         WRITE_INT_FIELD(width);
1781         WRITE_BOOL_FIELD(consider_startup);
1782         WRITE_NODE_FIELD(reltargetlist);
1783         WRITE_NODE_FIELD(pathlist);
1784         WRITE_NODE_FIELD(ppilist);
1785         WRITE_NODE_FIELD(cheapest_startup_path);
1786         WRITE_NODE_FIELD(cheapest_total_path);
1787         WRITE_NODE_FIELD(cheapest_unique_path);
1788         WRITE_NODE_FIELD(cheapest_parameterized_paths);
1789         WRITE_UINT_FIELD(relid);
1790         WRITE_OID_FIELD(reltablespace);
1791         WRITE_ENUM_FIELD(rtekind, RTEKind);
1792         WRITE_INT_FIELD(min_attr);
1793         WRITE_INT_FIELD(max_attr);
1794         WRITE_NODE_FIELD(lateral_vars);
1795         WRITE_BITMAPSET_FIELD(lateral_relids);
1796         WRITE_BITMAPSET_FIELD(lateral_referencers);
1797         WRITE_NODE_FIELD(indexlist);
1798         WRITE_UINT_FIELD(pages);
1799         WRITE_FLOAT_FIELD(tuples, "%.0f");
1800         WRITE_FLOAT_FIELD(allvisfrac, "%.6f");
1801         WRITE_NODE_FIELD(subplan);
1802         WRITE_NODE_FIELD(subroot);
1803         WRITE_NODE_FIELD(subplan_params);
1804         /* we don't try to print fdwroutine or fdw_private */
1805         WRITE_NODE_FIELD(baserestrictinfo);
1806         WRITE_NODE_FIELD(joininfo);
1807         WRITE_BOOL_FIELD(has_eclass_joins);
1808 }
1809
1810 static void
1811 _outIndexOptInfo(StringInfo str, const IndexOptInfo *node)
1812 {
1813         WRITE_NODE_TYPE("INDEXOPTINFO");
1814
1815         /* NB: this isn't a complete set of fields */
1816         WRITE_OID_FIELD(indexoid);
1817         /* Do NOT print rel field, else infinite recursion */
1818         WRITE_UINT_FIELD(pages);
1819         WRITE_FLOAT_FIELD(tuples, "%.0f");
1820         WRITE_INT_FIELD(tree_height);
1821         WRITE_INT_FIELD(ncolumns);
1822         /* array fields aren't really worth the trouble to print */
1823         WRITE_OID_FIELD(relam);
1824         /* indexprs is redundant since we print indextlist */
1825         WRITE_NODE_FIELD(indpred);
1826         WRITE_NODE_FIELD(indextlist);
1827         WRITE_BOOL_FIELD(predOK);
1828         WRITE_BOOL_FIELD(unique);
1829         WRITE_BOOL_FIELD(immediate);
1830         WRITE_BOOL_FIELD(hypothetical);
1831         /* we don't bother with fields copied from the pg_am entry */
1832 }
1833
1834 static void
1835 _outEquivalenceClass(StringInfo str, const EquivalenceClass *node)
1836 {
1837         /*
1838          * To simplify reading, we just chase up to the topmost merged EC and
1839          * print that, without bothering to show the merge-ees separately.
1840          */
1841         while (node->ec_merged)
1842                 node = node->ec_merged;
1843
1844         WRITE_NODE_TYPE("EQUIVALENCECLASS");
1845
1846         WRITE_NODE_FIELD(ec_opfamilies);
1847         WRITE_OID_FIELD(ec_collation);
1848         WRITE_NODE_FIELD(ec_members);
1849         WRITE_NODE_FIELD(ec_sources);
1850         WRITE_NODE_FIELD(ec_derives);
1851         WRITE_BITMAPSET_FIELD(ec_relids);
1852         WRITE_BOOL_FIELD(ec_has_const);
1853         WRITE_BOOL_FIELD(ec_has_volatile);
1854         WRITE_BOOL_FIELD(ec_below_outer_join);
1855         WRITE_BOOL_FIELD(ec_broken);
1856         WRITE_UINT_FIELD(ec_sortref);
1857 }
1858
1859 static void
1860 _outEquivalenceMember(StringInfo str, const EquivalenceMember *node)
1861 {
1862         WRITE_NODE_TYPE("EQUIVALENCEMEMBER");
1863
1864         WRITE_NODE_FIELD(em_expr);
1865         WRITE_BITMAPSET_FIELD(em_relids);
1866         WRITE_BITMAPSET_FIELD(em_nullable_relids);
1867         WRITE_BOOL_FIELD(em_is_const);
1868         WRITE_BOOL_FIELD(em_is_child);
1869         WRITE_OID_FIELD(em_datatype);
1870 }
1871
1872 static void
1873 _outPathKey(StringInfo str, const PathKey *node)
1874 {
1875         WRITE_NODE_TYPE("PATHKEY");
1876
1877         WRITE_NODE_FIELD(pk_eclass);
1878         WRITE_OID_FIELD(pk_opfamily);
1879         WRITE_INT_FIELD(pk_strategy);
1880         WRITE_BOOL_FIELD(pk_nulls_first);
1881 }
1882
1883 static void
1884 _outParamPathInfo(StringInfo str, const ParamPathInfo *node)
1885 {
1886         WRITE_NODE_TYPE("PARAMPATHINFO");
1887
1888         WRITE_BITMAPSET_FIELD(ppi_req_outer);
1889         WRITE_FLOAT_FIELD(ppi_rows, "%.0f");
1890         WRITE_NODE_FIELD(ppi_clauses);
1891 }
1892
1893 static void
1894 _outRestrictInfo(StringInfo str, const RestrictInfo *node)
1895 {
1896         WRITE_NODE_TYPE("RESTRICTINFO");
1897
1898         /* NB: this isn't a complete set of fields */
1899         WRITE_NODE_FIELD(clause);
1900         WRITE_BOOL_FIELD(is_pushed_down);
1901         WRITE_BOOL_FIELD(outerjoin_delayed);
1902         WRITE_BOOL_FIELD(can_join);
1903         WRITE_BOOL_FIELD(pseudoconstant);
1904         WRITE_BITMAPSET_FIELD(clause_relids);
1905         WRITE_BITMAPSET_FIELD(required_relids);
1906         WRITE_BITMAPSET_FIELD(outer_relids);
1907         WRITE_BITMAPSET_FIELD(nullable_relids);
1908         WRITE_BITMAPSET_FIELD(left_relids);
1909         WRITE_BITMAPSET_FIELD(right_relids);
1910         WRITE_NODE_FIELD(orclause);
1911         /* don't write parent_ec, leads to infinite recursion in plan tree dump */
1912         WRITE_FLOAT_FIELD(norm_selec, "%.4f");
1913         WRITE_FLOAT_FIELD(outer_selec, "%.4f");
1914         WRITE_NODE_FIELD(mergeopfamilies);
1915         /* don't write left_ec, leads to infinite recursion in plan tree dump */
1916         /* don't write right_ec, leads to infinite recursion in plan tree dump */
1917         WRITE_NODE_FIELD(left_em);
1918         WRITE_NODE_FIELD(right_em);
1919         WRITE_BOOL_FIELD(outer_is_left);
1920         WRITE_OID_FIELD(hashjoinoperator);
1921 }
1922
1923 static void
1924 _outPlaceHolderVar(StringInfo str, const PlaceHolderVar *node)
1925 {
1926         WRITE_NODE_TYPE("PLACEHOLDERVAR");
1927
1928         WRITE_NODE_FIELD(phexpr);
1929         WRITE_BITMAPSET_FIELD(phrels);
1930         WRITE_UINT_FIELD(phid);
1931         WRITE_UINT_FIELD(phlevelsup);
1932 }
1933
1934 static void
1935 _outSpecialJoinInfo(StringInfo str, const SpecialJoinInfo *node)
1936 {
1937         WRITE_NODE_TYPE("SPECIALJOININFO");
1938
1939         WRITE_BITMAPSET_FIELD(min_lefthand);
1940         WRITE_BITMAPSET_FIELD(min_righthand);
1941         WRITE_BITMAPSET_FIELD(syn_lefthand);
1942         WRITE_BITMAPSET_FIELD(syn_righthand);
1943         WRITE_ENUM_FIELD(jointype, JoinType);
1944         WRITE_BOOL_FIELD(lhs_strict);
1945         WRITE_BOOL_FIELD(delay_upper_joins);
1946         WRITE_NODE_FIELD(join_quals);
1947 }
1948
1949 static void
1950 _outLateralJoinInfo(StringInfo str, const LateralJoinInfo *node)
1951 {
1952         WRITE_NODE_TYPE("LATERALJOININFO");
1953
1954         WRITE_BITMAPSET_FIELD(lateral_lhs);
1955         WRITE_BITMAPSET_FIELD(lateral_rhs);
1956 }
1957
1958 static void
1959 _outAppendRelInfo(StringInfo str, const AppendRelInfo *node)
1960 {
1961         WRITE_NODE_TYPE("APPENDRELINFO");
1962
1963         WRITE_UINT_FIELD(parent_relid);
1964         WRITE_UINT_FIELD(child_relid);
1965         WRITE_OID_FIELD(parent_reltype);
1966         WRITE_OID_FIELD(child_reltype);
1967         WRITE_NODE_FIELD(translated_vars);
1968         WRITE_OID_FIELD(parent_reloid);
1969 }
1970
1971 static void
1972 _outPlaceHolderInfo(StringInfo str, const PlaceHolderInfo *node)
1973 {
1974         WRITE_NODE_TYPE("PLACEHOLDERINFO");
1975
1976         WRITE_UINT_FIELD(phid);
1977         WRITE_NODE_FIELD(ph_var);
1978         WRITE_BITMAPSET_FIELD(ph_eval_at);
1979         WRITE_BITMAPSET_FIELD(ph_lateral);
1980         WRITE_BITMAPSET_FIELD(ph_needed);
1981         WRITE_INT_FIELD(ph_width);
1982 }
1983
1984 static void
1985 _outMinMaxAggInfo(StringInfo str, const MinMaxAggInfo *node)
1986 {
1987         WRITE_NODE_TYPE("MINMAXAGGINFO");
1988
1989         WRITE_OID_FIELD(aggfnoid);
1990         WRITE_OID_FIELD(aggsortop);
1991         WRITE_NODE_FIELD(target);
1992         /* We intentionally omit subroot --- too large, not interesting enough */
1993         WRITE_NODE_FIELD(path);
1994         WRITE_FLOAT_FIELD(pathcost, "%.2f");
1995         WRITE_NODE_FIELD(param);
1996 }
1997
1998 static void
1999 _outPlannerParamItem(StringInfo str, const PlannerParamItem *node)
2000 {
2001         WRITE_NODE_TYPE("PLANNERPARAMITEM");
2002
2003         WRITE_NODE_FIELD(item);
2004         WRITE_INT_FIELD(paramId);
2005 }
2006
2007 /*****************************************************************************
2008  *
2009  *      Stuff from parsenodes.h.
2010  *
2011  *****************************************************************************/
2012
2013 /*
2014  * print the basic stuff of all nodes that inherit from CreateStmt
2015  */
2016 static void
2017 _outCreateStmtInfo(StringInfo str, const CreateStmt *node)
2018 {
2019         WRITE_NODE_FIELD(relation);
2020         WRITE_NODE_FIELD(tableElts);
2021         WRITE_NODE_FIELD(inhRelations);
2022         WRITE_NODE_FIELD(ofTypename);
2023         WRITE_NODE_FIELD(constraints);
2024         WRITE_NODE_FIELD(options);
2025         WRITE_ENUM_FIELD(oncommit, OnCommitAction);
2026         WRITE_STRING_FIELD(tablespacename);
2027         WRITE_BOOL_FIELD(if_not_exists);
2028 }
2029
2030 static void
2031 _outCreateStmt(StringInfo str, const CreateStmt *node)
2032 {
2033         WRITE_NODE_TYPE("CREATESTMT");
2034
2035         _outCreateStmtInfo(str, (const CreateStmt *) node);
2036 }
2037
2038 static void
2039 _outCreateForeignTableStmt(StringInfo str, const CreateForeignTableStmt *node)
2040 {
2041         WRITE_NODE_TYPE("CREATEFOREIGNTABLESTMT");
2042
2043         _outCreateStmtInfo(str, (const CreateStmt *) node);
2044
2045         WRITE_STRING_FIELD(servername);
2046         WRITE_NODE_FIELD(options);
2047 }
2048
2049 static void
2050 _outImportForeignSchemaStmt(StringInfo str, const ImportForeignSchemaStmt *node)
2051 {
2052         WRITE_NODE_TYPE("IMPORTFOREIGNSCHEMASTMT");
2053
2054         WRITE_STRING_FIELD(server_name);
2055         WRITE_STRING_FIELD(remote_schema);
2056         WRITE_STRING_FIELD(local_schema);
2057         WRITE_ENUM_FIELD(list_type, ImportForeignSchemaType);
2058         WRITE_NODE_FIELD(table_list);
2059         WRITE_NODE_FIELD(options);
2060 }
2061
2062 static void
2063 _outIndexStmt(StringInfo str, const IndexStmt *node)
2064 {
2065         WRITE_NODE_TYPE("INDEXSTMT");
2066
2067         WRITE_STRING_FIELD(idxname);
2068         WRITE_NODE_FIELD(relation);
2069         WRITE_STRING_FIELD(accessMethod);
2070         WRITE_STRING_FIELD(tableSpace);
2071         WRITE_NODE_FIELD(indexParams);
2072         WRITE_NODE_FIELD(options);
2073         WRITE_NODE_FIELD(whereClause);
2074         WRITE_NODE_FIELD(excludeOpNames);
2075         WRITE_STRING_FIELD(idxcomment);
2076         WRITE_OID_FIELD(indexOid);
2077         WRITE_OID_FIELD(oldNode);
2078         WRITE_BOOL_FIELD(unique);
2079         WRITE_BOOL_FIELD(primary);
2080         WRITE_BOOL_FIELD(isconstraint);
2081         WRITE_BOOL_FIELD(deferrable);
2082         WRITE_BOOL_FIELD(initdeferred);
2083         WRITE_BOOL_FIELD(transformed);
2084         WRITE_BOOL_FIELD(concurrent);
2085         WRITE_BOOL_FIELD(if_not_exists);
2086 }
2087
2088 static void
2089 _outNotifyStmt(StringInfo str, const NotifyStmt *node)
2090 {
2091         WRITE_NODE_TYPE("NOTIFY");
2092
2093         WRITE_STRING_FIELD(conditionname);
2094         WRITE_STRING_FIELD(payload);
2095 }
2096
2097 static void
2098 _outDeclareCursorStmt(StringInfo str, const DeclareCursorStmt *node)
2099 {
2100         WRITE_NODE_TYPE("DECLARECURSOR");
2101
2102         WRITE_STRING_FIELD(portalname);
2103         WRITE_INT_FIELD(options);
2104         WRITE_NODE_FIELD(query);
2105 }
2106
2107 static void
2108 _outSelectStmt(StringInfo str, const SelectStmt *node)
2109 {
2110         WRITE_NODE_TYPE("SELECT");
2111
2112         WRITE_NODE_FIELD(distinctClause);
2113         WRITE_NODE_FIELD(intoClause);
2114         WRITE_NODE_FIELD(targetList);
2115         WRITE_NODE_FIELD(fromClause);
2116         WRITE_NODE_FIELD(whereClause);
2117         WRITE_NODE_FIELD(groupClause);
2118         WRITE_NODE_FIELD(havingClause);
2119         WRITE_NODE_FIELD(windowClause);
2120         WRITE_NODE_FIELD(valuesLists);
2121         WRITE_NODE_FIELD(sortClause);
2122         WRITE_NODE_FIELD(limitOffset);
2123         WRITE_NODE_FIELD(limitCount);
2124         WRITE_NODE_FIELD(lockingClause);
2125         WRITE_NODE_FIELD(withClause);
2126         WRITE_ENUM_FIELD(op, SetOperation);
2127         WRITE_BOOL_FIELD(all);
2128         WRITE_NODE_FIELD(larg);
2129         WRITE_NODE_FIELD(rarg);
2130 }
2131
2132 static void
2133 _outFuncCall(StringInfo str, const FuncCall *node)
2134 {
2135         WRITE_NODE_TYPE("FUNCCALL");
2136
2137         WRITE_NODE_FIELD(funcname);
2138         WRITE_NODE_FIELD(args);
2139         WRITE_NODE_FIELD(agg_order);
2140         WRITE_NODE_FIELD(agg_filter);
2141         WRITE_BOOL_FIELD(agg_within_group);
2142         WRITE_BOOL_FIELD(agg_star);
2143         WRITE_BOOL_FIELD(agg_distinct);
2144         WRITE_BOOL_FIELD(func_variadic);
2145         WRITE_NODE_FIELD(over);
2146         WRITE_LOCATION_FIELD(location);
2147 }
2148
2149 static void
2150 _outDefElem(StringInfo str, const DefElem *node)
2151 {
2152         WRITE_NODE_TYPE("DEFELEM");
2153
2154         WRITE_STRING_FIELD(defnamespace);
2155         WRITE_STRING_FIELD(defname);
2156         WRITE_NODE_FIELD(arg);
2157         WRITE_ENUM_FIELD(defaction, DefElemAction);
2158 }
2159
2160 static void
2161 _outTableLikeClause(StringInfo str, const TableLikeClause *node)
2162 {
2163         WRITE_NODE_TYPE("TABLELIKECLAUSE");
2164
2165         WRITE_NODE_FIELD(relation);
2166         WRITE_UINT_FIELD(options);
2167 }
2168
2169 static void
2170 _outLockingClause(StringInfo str, const LockingClause *node)
2171 {
2172         WRITE_NODE_TYPE("LOCKINGCLAUSE");
2173
2174         WRITE_NODE_FIELD(lockedRels);
2175         WRITE_ENUM_FIELD(strength, LockClauseStrength);
2176         WRITE_ENUM_FIELD(waitPolicy, LockWaitPolicy);
2177 }
2178
2179 static void
2180 _outXmlSerialize(StringInfo str, const XmlSerialize *node)
2181 {
2182         WRITE_NODE_TYPE("XMLSERIALIZE");
2183
2184         WRITE_ENUM_FIELD(xmloption, XmlOptionType);
2185         WRITE_NODE_FIELD(expr);
2186         WRITE_NODE_FIELD(typeName);
2187         WRITE_LOCATION_FIELD(location);
2188 }
2189
2190 static void
2191 _outColumnDef(StringInfo str, const ColumnDef *node)
2192 {
2193         WRITE_NODE_TYPE("COLUMNDEF");
2194
2195         WRITE_STRING_FIELD(colname);
2196         WRITE_NODE_FIELD(typeName);
2197         WRITE_INT_FIELD(inhcount);
2198         WRITE_BOOL_FIELD(is_local);
2199         WRITE_BOOL_FIELD(is_not_null);
2200         WRITE_BOOL_FIELD(is_from_type);
2201         WRITE_CHAR_FIELD(storage);
2202         WRITE_NODE_FIELD(raw_default);
2203         WRITE_NODE_FIELD(cooked_default);
2204         WRITE_NODE_FIELD(collClause);
2205         WRITE_OID_FIELD(collOid);
2206         WRITE_NODE_FIELD(constraints);
2207         WRITE_NODE_FIELD(fdwoptions);
2208         WRITE_LOCATION_FIELD(location);
2209 }
2210
2211 static void
2212 _outTypeName(StringInfo str, const TypeName *node)
2213 {
2214         WRITE_NODE_TYPE("TYPENAME");
2215
2216         WRITE_NODE_FIELD(names);
2217         WRITE_OID_FIELD(typeOid);
2218         WRITE_BOOL_FIELD(setof);
2219         WRITE_BOOL_FIELD(pct_type);
2220         WRITE_NODE_FIELD(typmods);
2221         WRITE_INT_FIELD(typemod);
2222         WRITE_NODE_FIELD(arrayBounds);
2223         WRITE_LOCATION_FIELD(location);
2224 }
2225
2226 static void
2227 _outTypeCast(StringInfo str, const TypeCast *node)
2228 {
2229         WRITE_NODE_TYPE("TYPECAST");
2230
2231         WRITE_NODE_FIELD(arg);
2232         WRITE_NODE_FIELD(typeName);
2233         WRITE_LOCATION_FIELD(location);
2234 }
2235
2236 static void
2237 _outCollateClause(StringInfo str, const CollateClause *node)
2238 {
2239         WRITE_NODE_TYPE("COLLATECLAUSE");
2240
2241         WRITE_NODE_FIELD(arg);
2242         WRITE_NODE_FIELD(collname);
2243         WRITE_LOCATION_FIELD(location);
2244 }
2245
2246 static void
2247 _outIndexElem(StringInfo str, const IndexElem *node)
2248 {
2249         WRITE_NODE_TYPE("INDEXELEM");
2250
2251         WRITE_STRING_FIELD(name);
2252         WRITE_NODE_FIELD(expr);
2253         WRITE_STRING_FIELD(indexcolname);
2254         WRITE_NODE_FIELD(collation);
2255         WRITE_NODE_FIELD(opclass);
2256         WRITE_ENUM_FIELD(ordering, SortByDir);
2257         WRITE_ENUM_FIELD(nulls_ordering, SortByNulls);
2258 }
2259
2260 static void
2261 _outQuery(StringInfo str, const Query *node)
2262 {
2263         WRITE_NODE_TYPE("QUERY");
2264
2265         WRITE_ENUM_FIELD(commandType, CmdType);
2266         WRITE_ENUM_FIELD(querySource, QuerySource);
2267         /* we intentionally do not print the queryId field */
2268         WRITE_BOOL_FIELD(canSetTag);
2269
2270         /*
2271          * Hack to work around missing outfuncs routines for a lot of the
2272          * utility-statement node types.  (The only one we actually *need* for
2273          * rules support is NotifyStmt.)  Someday we ought to support 'em all, but
2274          * for the meantime do this to avoid getting lots of warnings when running
2275          * with debug_print_parse on.
2276          */
2277         if (node->utilityStmt)
2278         {
2279                 switch (nodeTag(node->utilityStmt))
2280                 {
2281                         case T_CreateStmt:
2282                         case T_IndexStmt:
2283                         case T_NotifyStmt:
2284                         case T_DeclareCursorStmt:
2285                                 WRITE_NODE_FIELD(utilityStmt);
2286                                 break;
2287                         default:
2288                                 appendStringInfoString(str, " :utilityStmt ?");
2289                                 break;
2290                 }
2291         }
2292         else
2293                 appendStringInfoString(str, " :utilityStmt <>");
2294
2295         WRITE_INT_FIELD(resultRelation);
2296         WRITE_BOOL_FIELD(hasAggs);
2297         WRITE_BOOL_FIELD(hasWindowFuncs);
2298         WRITE_BOOL_FIELD(hasSubLinks);
2299         WRITE_BOOL_FIELD(hasDistinctOn);
2300         WRITE_BOOL_FIELD(hasRecursive);
2301         WRITE_BOOL_FIELD(hasModifyingCTE);
2302         WRITE_BOOL_FIELD(hasForUpdate);
2303         WRITE_BOOL_FIELD(hasRowSecurity);
2304         WRITE_NODE_FIELD(cteList);
2305         WRITE_NODE_FIELD(rtable);
2306         WRITE_NODE_FIELD(jointree);
2307         WRITE_NODE_FIELD(targetList);
2308         WRITE_NODE_FIELD(withCheckOptions);
2309         WRITE_NODE_FIELD(returningList);
2310         WRITE_NODE_FIELD(groupClause);
2311         WRITE_NODE_FIELD(havingQual);
2312         WRITE_NODE_FIELD(windowClause);
2313         WRITE_NODE_FIELD(distinctClause);
2314         WRITE_NODE_FIELD(sortClause);
2315         WRITE_NODE_FIELD(limitOffset);
2316         WRITE_NODE_FIELD(limitCount);
2317         WRITE_NODE_FIELD(rowMarks);
2318         WRITE_NODE_FIELD(setOperations);
2319         WRITE_NODE_FIELD(constraintDeps);
2320 }
2321
2322 static void
2323 _outWithCheckOption(StringInfo str, const WithCheckOption *node)
2324 {
2325         WRITE_NODE_TYPE("WITHCHECKOPTION");
2326
2327         WRITE_STRING_FIELD(viewname);
2328         WRITE_NODE_FIELD(qual);
2329         WRITE_BOOL_FIELD(cascaded);
2330 }
2331
2332 static void
2333 _outSortGroupClause(StringInfo str, const SortGroupClause *node)
2334 {
2335         WRITE_NODE_TYPE("SORTGROUPCLAUSE");
2336
2337         WRITE_UINT_FIELD(tleSortGroupRef);
2338         WRITE_OID_FIELD(eqop);
2339         WRITE_OID_FIELD(sortop);
2340         WRITE_BOOL_FIELD(nulls_first);
2341         WRITE_BOOL_FIELD(hashable);
2342 }
2343
2344 static void
2345 _outWindowClause(StringInfo str, const WindowClause *node)
2346 {
2347         WRITE_NODE_TYPE("WINDOWCLAUSE");
2348
2349         WRITE_STRING_FIELD(name);
2350         WRITE_STRING_FIELD(refname);
2351         WRITE_NODE_FIELD(partitionClause);
2352         WRITE_NODE_FIELD(orderClause);
2353         WRITE_INT_FIELD(frameOptions);
2354         WRITE_NODE_FIELD(startOffset);
2355         WRITE_NODE_FIELD(endOffset);
2356         WRITE_UINT_FIELD(winref);
2357         WRITE_BOOL_FIELD(copiedOrder);
2358 }
2359
2360 static void
2361 _outRowMarkClause(StringInfo str, const RowMarkClause *node)
2362 {
2363         WRITE_NODE_TYPE("ROWMARKCLAUSE");
2364
2365         WRITE_UINT_FIELD(rti);
2366         WRITE_ENUM_FIELD(strength, LockClauseStrength);
2367         WRITE_ENUM_FIELD(waitPolicy, LockWaitPolicy);
2368         WRITE_BOOL_FIELD(pushedDown);
2369 }
2370
2371 static void
2372 _outWithClause(StringInfo str, const WithClause *node)
2373 {
2374         WRITE_NODE_TYPE("WITHCLAUSE");
2375
2376         WRITE_NODE_FIELD(ctes);
2377         WRITE_BOOL_FIELD(recursive);
2378         WRITE_LOCATION_FIELD(location);
2379 }
2380
2381 static void
2382 _outCommonTableExpr(StringInfo str, const CommonTableExpr *node)
2383 {
2384         WRITE_NODE_TYPE("COMMONTABLEEXPR");
2385
2386         WRITE_STRING_FIELD(ctename);
2387         WRITE_NODE_FIELD(aliascolnames);
2388         WRITE_NODE_FIELD(ctequery);
2389         WRITE_LOCATION_FIELD(location);
2390         WRITE_BOOL_FIELD(cterecursive);
2391         WRITE_INT_FIELD(cterefcount);
2392         WRITE_NODE_FIELD(ctecolnames);
2393         WRITE_NODE_FIELD(ctecoltypes);
2394         WRITE_NODE_FIELD(ctecoltypmods);
2395         WRITE_NODE_FIELD(ctecolcollations);
2396 }
2397
2398 static void
2399 _outSetOperationStmt(StringInfo str, const SetOperationStmt *node)
2400 {
2401         WRITE_NODE_TYPE("SETOPERATIONSTMT");
2402
2403         WRITE_ENUM_FIELD(op, SetOperation);
2404         WRITE_BOOL_FIELD(all);
2405         WRITE_NODE_FIELD(larg);
2406         WRITE_NODE_FIELD(rarg);
2407         WRITE_NODE_FIELD(colTypes);
2408         WRITE_NODE_FIELD(colTypmods);
2409         WRITE_NODE_FIELD(colCollations);
2410         WRITE_NODE_FIELD(groupClauses);
2411 }
2412
2413 static void
2414 _outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
2415 {
2416         WRITE_NODE_TYPE("RTE");
2417
2418         /* put alias + eref first to make dump more legible */
2419         WRITE_NODE_FIELD(alias);
2420         WRITE_NODE_FIELD(eref);
2421         WRITE_ENUM_FIELD(rtekind, RTEKind);
2422
2423         switch (node->rtekind)
2424         {
2425                 case RTE_RELATION:
2426                         WRITE_OID_FIELD(relid);
2427                         WRITE_CHAR_FIELD(relkind);
2428                         break;
2429                 case RTE_SUBQUERY:
2430                         WRITE_NODE_FIELD(subquery);
2431                         WRITE_BOOL_FIELD(security_barrier);
2432                         break;
2433                 case RTE_JOIN:
2434                         WRITE_ENUM_FIELD(jointype, JoinType);
2435                         WRITE_NODE_FIELD(joinaliasvars);
2436                         break;
2437                 case RTE_FUNCTION:
2438                         WRITE_NODE_FIELD(functions);
2439                         WRITE_BOOL_FIELD(funcordinality);
2440                         break;
2441                 case RTE_VALUES:
2442                         WRITE_NODE_FIELD(values_lists);
2443                         WRITE_NODE_FIELD(values_collations);
2444                         break;
2445                 case RTE_CTE:
2446                         WRITE_STRING_FIELD(ctename);
2447                         WRITE_UINT_FIELD(ctelevelsup);
2448                         WRITE_BOOL_FIELD(self_reference);
2449                         WRITE_NODE_FIELD(ctecoltypes);
2450                         WRITE_NODE_FIELD(ctecoltypmods);
2451                         WRITE_NODE_FIELD(ctecolcollations);
2452                         break;
2453                 default:
2454                         elog(ERROR, "unrecognized RTE kind: %d", (int) node->rtekind);
2455                         break;
2456         }
2457
2458         WRITE_BOOL_FIELD(lateral);
2459         WRITE_BOOL_FIELD(inh);
2460         WRITE_BOOL_FIELD(inFromCl);
2461         WRITE_UINT_FIELD(requiredPerms);
2462         WRITE_OID_FIELD(checkAsUser);
2463         WRITE_BITMAPSET_FIELD(selectedCols);
2464         WRITE_BITMAPSET_FIELD(modifiedCols);
2465         WRITE_NODE_FIELD(securityQuals);
2466 }
2467
2468 static void
2469 _outRangeTblFunction(StringInfo str, const RangeTblFunction *node)
2470 {
2471         WRITE_NODE_TYPE("RANGETBLFUNCTION");
2472
2473         WRITE_NODE_FIELD(funcexpr);
2474         WRITE_INT_FIELD(funccolcount);
2475         WRITE_NODE_FIELD(funccolnames);
2476         WRITE_NODE_FIELD(funccoltypes);
2477         WRITE_NODE_FIELD(funccoltypmods);
2478         WRITE_NODE_FIELD(funccolcollations);
2479         WRITE_BITMAPSET_FIELD(funcparams);
2480 }
2481
2482 static void
2483 _outAExpr(StringInfo str, const A_Expr *node)
2484 {
2485         WRITE_NODE_TYPE("AEXPR");
2486
2487         switch (node->kind)
2488         {
2489                 case AEXPR_OP:
2490                         appendStringInfoChar(str, ' ');
2491                         WRITE_NODE_FIELD(name);
2492                         break;
2493                 case AEXPR_OP_ANY:
2494                         appendStringInfoChar(str, ' ');
2495                         WRITE_NODE_FIELD(name);
2496                         appendStringInfoString(str, " ANY ");
2497                         break;
2498                 case AEXPR_OP_ALL:
2499                         appendStringInfoChar(str, ' ');
2500                         WRITE_NODE_FIELD(name);
2501                         appendStringInfoString(str, " ALL ");
2502                         break;
2503                 case AEXPR_DISTINCT:
2504                         appendStringInfoString(str, " DISTINCT ");
2505                         WRITE_NODE_FIELD(name);
2506                         break;
2507                 case AEXPR_NULLIF:
2508                         appendStringInfoString(str, " NULLIF ");
2509                         WRITE_NODE_FIELD(name);
2510                         break;
2511                 case AEXPR_OF:
2512                         appendStringInfoString(str, " OF ");
2513                         WRITE_NODE_FIELD(name);
2514                         break;
2515                 case AEXPR_IN:
2516                         appendStringInfoString(str, " IN ");
2517                         WRITE_NODE_FIELD(name);
2518                         break;
2519                 case AEXPR_BETWEEN:
2520                         appendStringInfoString(str, " BETWEEN ");
2521                         WRITE_NODE_FIELD(name);
2522                         break;
2523                 case AEXPR_NOT_BETWEEN:
2524                         appendStringInfoString(str, " NOT_BETWEEN ");
2525                         WRITE_NODE_FIELD(name);
2526                         break;
2527                 case AEXPR_BETWEEN_SYM:
2528                         appendStringInfoString(str, " BETWEEN_SYM ");
2529                         WRITE_NODE_FIELD(name);
2530                         break;
2531                 case AEXPR_NOT_BETWEEN_SYM:
2532                         appendStringInfoString(str, " NOT_BETWEEN_SYM ");
2533                         WRITE_NODE_FIELD(name);
2534                         break;
2535                 default:
2536                         appendStringInfoString(str, " ??");
2537                         break;
2538         }
2539
2540         WRITE_NODE_FIELD(lexpr);
2541         WRITE_NODE_FIELD(rexpr);
2542         WRITE_LOCATION_FIELD(location);
2543 }
2544
2545 static void
2546 _outValue(StringInfo str, const Value *value)
2547 {
2548         switch (value->type)
2549         {
2550                 case T_Integer:
2551                         appendStringInfo(str, "%ld", value->val.ival);
2552                         break;
2553                 case T_Float:
2554
2555                         /*
2556                          * We assume the value is a valid numeric literal and so does not
2557                          * need quoting.
2558                          */
2559                         appendStringInfoString(str, value->val.str);
2560                         break;
2561                 case T_String:
2562
2563                         /*
2564                          * We use _outToken to provide escaping of the string's content,
2565                          * but we don't want it to do anything with an empty string.
2566                          */
2567                         appendStringInfoChar(str, '"');
2568                         if (value->val.str[0] != '\0')
2569                                 _outToken(str, value->val.str);
2570                         appendStringInfoChar(str, '"');
2571                         break;
2572                 case T_BitString:
2573                         /* internal representation already has leading 'b' */
2574                         appendStringInfoString(str, value->val.str);
2575                         break;
2576                 case T_Null:
2577                         /* this is seen only within A_Const, not in transformed trees */
2578                         appendStringInfoString(str, "NULL");
2579                         break;
2580                 default:
2581                         elog(ERROR, "unrecognized node type: %d", (int) value->type);
2582                         break;
2583         }
2584 }
2585
2586 static void
2587 _outColumnRef(StringInfo str, const ColumnRef *node)
2588 {
2589         WRITE_NODE_TYPE("COLUMNREF");
2590
2591         WRITE_NODE_FIELD(fields);
2592         WRITE_LOCATION_FIELD(location);
2593 }
2594
2595 static void
2596 _outParamRef(StringInfo str, const ParamRef *node)
2597 {
2598         WRITE_NODE_TYPE("PARAMREF");
2599
2600         WRITE_INT_FIELD(number);
2601         WRITE_LOCATION_FIELD(location);
2602 }
2603
2604 static void
2605 _outAConst(StringInfo str, const A_Const *node)
2606 {
2607         WRITE_NODE_TYPE("A_CONST");
2608
2609         appendStringInfoString(str, " :val ");
2610         _outValue(str, &(node->val));
2611         WRITE_LOCATION_FIELD(location);
2612 }
2613
2614 static void
2615 _outA_Star(StringInfo str, const A_Star *node)
2616 {
2617         WRITE_NODE_TYPE("A_STAR");
2618 }
2619
2620 static void
2621 _outA_Indices(StringInfo str, const A_Indices *node)
2622 {
2623         WRITE_NODE_TYPE("A_INDICES");
2624
2625         WRITE_NODE_FIELD(lidx);
2626         WRITE_NODE_FIELD(uidx);
2627 }
2628
2629 static void
2630 _outA_Indirection(StringInfo str, const A_Indirection *node)
2631 {
2632         WRITE_NODE_TYPE("A_INDIRECTION");
2633
2634         WRITE_NODE_FIELD(arg);
2635         WRITE_NODE_FIELD(indirection);
2636 }
2637
2638 static void
2639 _outA_ArrayExpr(StringInfo str, const A_ArrayExpr *node)
2640 {
2641         WRITE_NODE_TYPE("A_ARRAYEXPR");
2642
2643         WRITE_NODE_FIELD(elements);
2644         WRITE_LOCATION_FIELD(location);
2645 }
2646
2647 static void
2648 _outResTarget(StringInfo str, const ResTarget *node)
2649 {
2650         WRITE_NODE_TYPE("RESTARGET");
2651
2652         WRITE_STRING_FIELD(name);
2653         WRITE_NODE_FIELD(indirection);
2654         WRITE_NODE_FIELD(val);
2655         WRITE_LOCATION_FIELD(location);
2656 }
2657
2658 static void
2659 _outMultiAssignRef(StringInfo str, const MultiAssignRef *node)
2660 {
2661         WRITE_NODE_TYPE("MULTIASSIGNREF");
2662
2663         WRITE_NODE_FIELD(source);
2664         WRITE_INT_FIELD(colno);
2665         WRITE_INT_FIELD(ncolumns);
2666 }
2667
2668 static void
2669 _outSortBy(StringInfo str, const SortBy *node)
2670 {
2671         WRITE_NODE_TYPE("SORTBY");
2672
2673         WRITE_NODE_FIELD(node);
2674         WRITE_ENUM_FIELD(sortby_dir, SortByDir);
2675         WRITE_ENUM_FIELD(sortby_nulls, SortByNulls);
2676         WRITE_NODE_FIELD(useOp);
2677         WRITE_LOCATION_FIELD(location);
2678 }
2679
2680 static void
2681 _outWindowDef(StringInfo str, const WindowDef *node)
2682 {
2683         WRITE_NODE_TYPE("WINDOWDEF");
2684
2685         WRITE_STRING_FIELD(name);
2686         WRITE_STRING_FIELD(refname);
2687         WRITE_NODE_FIELD(partitionClause);
2688         WRITE_NODE_FIELD(orderClause);
2689         WRITE_INT_FIELD(frameOptions);
2690         WRITE_NODE_FIELD(startOffset);
2691         WRITE_NODE_FIELD(endOffset);
2692         WRITE_LOCATION_FIELD(location);
2693 }
2694
2695 static void
2696 _outRangeSubselect(StringInfo str, const RangeSubselect *node)
2697 {
2698         WRITE_NODE_TYPE("RANGESUBSELECT");
2699
2700         WRITE_BOOL_FIELD(lateral);
2701         WRITE_NODE_FIELD(subquery);
2702         WRITE_NODE_FIELD(alias);
2703 }
2704
2705 static void
2706 _outRangeFunction(StringInfo str, const RangeFunction *node)
2707 {
2708         WRITE_NODE_TYPE("RANGEFUNCTION");
2709
2710         WRITE_BOOL_FIELD(lateral);
2711         WRITE_BOOL_FIELD(ordinality);
2712         WRITE_BOOL_FIELD(is_rowsfrom);
2713         WRITE_NODE_FIELD(functions);
2714         WRITE_NODE_FIELD(alias);
2715         WRITE_NODE_FIELD(coldeflist);
2716 }
2717
2718 static void
2719 _outConstraint(StringInfo str, const Constraint *node)
2720 {
2721         WRITE_NODE_TYPE("CONSTRAINT");
2722
2723         WRITE_STRING_FIELD(conname);
2724         WRITE_BOOL_FIELD(deferrable);
2725         WRITE_BOOL_FIELD(initdeferred);
2726         WRITE_LOCATION_FIELD(location);
2727
2728         appendStringInfoString(str, " :contype ");
2729         switch (node->contype)
2730         {
2731                 case CONSTR_NULL:
2732                         appendStringInfoString(str, "NULL");
2733                         break;
2734
2735                 case CONSTR_NOTNULL:
2736                         appendStringInfoString(str, "NOT_NULL");
2737                         break;
2738
2739                 case CONSTR_DEFAULT:
2740                         appendStringInfoString(str, "DEFAULT");
2741                         WRITE_NODE_FIELD(raw_expr);
2742                         WRITE_STRING_FIELD(cooked_expr);
2743                         break;
2744
2745                 case CONSTR_CHECK:
2746                         appendStringInfoString(str, "CHECK");
2747                         WRITE_BOOL_FIELD(is_no_inherit);
2748                         WRITE_NODE_FIELD(raw_expr);
2749                         WRITE_STRING_FIELD(cooked_expr);
2750                         break;
2751
2752                 case CONSTR_PRIMARY:
2753                         appendStringInfoString(str, "PRIMARY_KEY");
2754                         WRITE_NODE_FIELD(keys);
2755                         WRITE_NODE_FIELD(options);
2756                         WRITE_STRING_FIELD(indexname);
2757                         WRITE_STRING_FIELD(indexspace);
2758                         /* access_method and where_clause not currently used */
2759                         break;
2760
2761                 case CONSTR_UNIQUE:
2762                         appendStringInfoString(str, "UNIQUE");
2763                         WRITE_NODE_FIELD(keys);
2764                         WRITE_NODE_FIELD(options);
2765                         WRITE_STRING_FIELD(indexname);
2766                         WRITE_STRING_FIELD(indexspace);
2767                         /* access_method and where_clause not currently used */
2768                         break;
2769
2770                 case CONSTR_EXCLUSION:
2771                         appendStringInfoString(str, "EXCLUSION");
2772                         WRITE_NODE_FIELD(exclusions);
2773                         WRITE_NODE_FIELD(options);
2774                         WRITE_STRING_FIELD(indexname);
2775                         WRITE_STRING_FIELD(indexspace);
2776                         WRITE_STRING_FIELD(access_method);
2777                         WRITE_NODE_FIELD(where_clause);
2778                         break;
2779
2780                 case CONSTR_FOREIGN:
2781                         appendStringInfoString(str, "FOREIGN_KEY");
2782                         WRITE_NODE_FIELD(pktable);
2783                         WRITE_NODE_FIELD(fk_attrs);
2784                         WRITE_NODE_FIELD(pk_attrs);
2785                         WRITE_CHAR_FIELD(fk_matchtype);
2786                         WRITE_CHAR_FIELD(fk_upd_action);
2787                         WRITE_CHAR_FIELD(fk_del_action);
2788                         WRITE_NODE_FIELD(old_conpfeqop);
2789                         WRITE_OID_FIELD(old_pktable_oid);
2790                         WRITE_BOOL_FIELD(skip_validation);
2791                         WRITE_BOOL_FIELD(initially_valid);
2792                         break;
2793
2794                 case CONSTR_ATTR_DEFERRABLE:
2795                         appendStringInfoString(str, "ATTR_DEFERRABLE");
2796                         break;
2797
2798                 case CONSTR_ATTR_NOT_DEFERRABLE:
2799                         appendStringInfoString(str, "ATTR_NOT_DEFERRABLE");
2800                         break;
2801
2802                 case CONSTR_ATTR_DEFERRED:
2803                         appendStringInfoString(str, "ATTR_DEFERRED");
2804                         break;
2805
2806                 case CONSTR_ATTR_IMMEDIATE:
2807                         appendStringInfoString(str, "ATTR_IMMEDIATE");
2808                         break;
2809
2810                 default:
2811                         appendStringInfo(str, "<unrecognized_constraint %d>",
2812                                                          (int) node->contype);
2813                         break;
2814         }
2815 }
2816
2817
2818 /*
2819  * _outNode -
2820  *        converts a Node into ascii string and append it to 'str'
2821  */
2822 static void
2823 _outNode(StringInfo str, const void *obj)
2824 {
2825         if (obj == NULL)
2826                 appendStringInfoString(str, "<>");
2827         else if (IsA(obj, List) ||IsA(obj, IntList) || IsA(obj, OidList))
2828                 _outList(str, obj);
2829         else if (IsA(obj, Integer) ||
2830                          IsA(obj, Float) ||
2831                          IsA(obj, String) ||
2832                          IsA(obj, BitString))
2833         {
2834                 /* nodeRead does not want to see { } around these! */
2835                 _outValue(str, obj);
2836         }
2837         else
2838         {
2839                 appendStringInfoChar(str, '{');
2840                 switch (nodeTag(obj))
2841                 {
2842                         case T_PlannedStmt:
2843                                 _outPlannedStmt(str, obj);
2844                                 break;
2845                         case T_Plan:
2846                                 _outPlan(str, obj);
2847                                 break;
2848                         case T_Result:
2849                                 _outResult(str, obj);
2850                                 break;
2851                         case T_ModifyTable:
2852                                 _outModifyTable(str, obj);
2853                                 break;
2854                         case T_Append:
2855                                 _outAppend(str, obj);
2856                                 break;
2857                         case T_MergeAppend:
2858                                 _outMergeAppend(str, obj);
2859                                 break;
2860                         case T_RecursiveUnion:
2861                                 _outRecursiveUnion(str, obj);
2862                                 break;
2863                         case T_BitmapAnd:
2864                                 _outBitmapAnd(str, obj);
2865                                 break;
2866                         case T_BitmapOr:
2867                                 _outBitmapOr(str, obj);
2868                                 break;
2869                         case T_Scan:
2870                                 _outScan(str, obj);
2871                                 break;
2872                         case T_SeqScan:
2873                                 _outSeqScan(str, obj);
2874                                 break;
2875                         case T_IndexScan:
2876                                 _outIndexScan(str, obj);
2877                                 break;
2878                         case T_IndexOnlyScan:
2879                                 _outIndexOnlyScan(str, obj);
2880                                 break;
2881                         case T_BitmapIndexScan:
2882                                 _outBitmapIndexScan(str, obj);
2883                                 break;
2884                         case T_BitmapHeapScan:
2885                                 _outBitmapHeapScan(str, obj);
2886                                 break;
2887                         case T_TidScan:
2888                                 _outTidScan(str, obj);
2889                                 break;
2890                         case T_SubqueryScan:
2891                                 _outSubqueryScan(str, obj);
2892                                 break;
2893                         case T_FunctionScan:
2894                                 _outFunctionScan(str, obj);
2895                                 break;
2896                         case T_ValuesScan:
2897                                 _outValuesScan(str, obj);
2898                                 break;
2899                         case T_CteScan:
2900                                 _outCteScan(str, obj);
2901                                 break;
2902                         case T_WorkTableScan:
2903                                 _outWorkTableScan(str, obj);
2904                                 break;
2905                         case T_ForeignScan:
2906                                 _outForeignScan(str, obj);
2907                                 break;
2908                         case T_CustomScan:
2909                                 _outCustomScan(str, obj);
2910                                 break;
2911                         case T_Join:
2912                                 _outJoin(str, obj);
2913                                 break;
2914                         case T_NestLoop:
2915                                 _outNestLoop(str, obj);
2916                                 break;
2917                         case T_MergeJoin:
2918                                 _outMergeJoin(str, obj);
2919                                 break;
2920                         case T_HashJoin:
2921                                 _outHashJoin(str, obj);
2922                                 break;
2923                         case T_Agg:
2924                                 _outAgg(str, obj);
2925                                 break;
2926                         case T_WindowAgg:
2927                                 _outWindowAgg(str, obj);
2928                                 break;
2929                         case T_Group:
2930                                 _outGroup(str, obj);
2931                                 break;
2932                         case T_Material:
2933                                 _outMaterial(str, obj);
2934                                 break;
2935                         case T_Sort:
2936                                 _outSort(str, obj);
2937                                 break;
2938                         case T_Unique:
2939                                 _outUnique(str, obj);
2940                                 break;
2941                         case T_Hash:
2942                                 _outHash(str, obj);
2943                                 break;
2944                         case T_SetOp:
2945                                 _outSetOp(str, obj);
2946                                 break;
2947                         case T_LockRows:
2948                                 _outLockRows(str, obj);
2949                                 break;
2950                         case T_Limit:
2951                                 _outLimit(str, obj);
2952                                 break;
2953                         case T_NestLoopParam:
2954                                 _outNestLoopParam(str, obj);
2955                                 break;
2956                         case T_PlanRowMark:
2957                                 _outPlanRowMark(str, obj);
2958                                 break;
2959                         case T_PlanInvalItem:
2960                                 _outPlanInvalItem(str, obj);
2961                                 break;
2962                         case T_Alias:
2963                                 _outAlias(str, obj);
2964                                 break;
2965                         case T_RangeVar:
2966                                 _outRangeVar(str, obj);
2967                                 break;
2968                         case T_IntoClause:
2969                                 _outIntoClause(str, obj);
2970                                 break;
2971                         case T_Var:
2972                                 _outVar(str, obj);
2973                                 break;
2974                         case T_Const:
2975                                 _outConst(str, obj);
2976                                 break;
2977                         case T_Param:
2978                                 _outParam(str, obj);
2979                                 break;
2980                         case T_Aggref:
2981                                 _outAggref(str, obj);
2982                                 break;
2983                         case T_WindowFunc:
2984                                 _outWindowFunc(str, obj);
2985                                 break;
2986                         case T_ArrayRef:
2987                                 _outArrayRef(str, obj);
2988                                 break;
2989                         case T_FuncExpr:
2990                                 _outFuncExpr(str, obj);
2991                                 break;
2992                         case T_NamedArgExpr:
2993                                 _outNamedArgExpr(str, obj);
2994                                 break;
2995                         case T_OpExpr:
2996                                 _outOpExpr(str, obj);
2997                                 break;
2998                         case T_DistinctExpr:
2999                                 _outDistinctExpr(str, obj);
3000                                 break;
3001                         case T_NullIfExpr:
3002                                 _outNullIfExpr(str, obj);
3003                                 break;
3004                         case T_ScalarArrayOpExpr:
3005                                 _outScalarArrayOpExpr(str, obj);
3006                                 break;
3007                         case T_BoolExpr:
3008                                 _outBoolExpr(str, obj);
3009                                 break;
3010                         case T_SubLink:
3011                                 _outSubLink(str, obj);
3012                                 break;
3013                         case T_SubPlan:
3014                                 _outSubPlan(str, obj);
3015                                 break;
3016                         case T_AlternativeSubPlan:
3017                                 _outAlternativeSubPlan(str, obj);
3018                                 break;
3019                         case T_FieldSelect:
3020                                 _outFieldSelect(str, obj);
3021                                 break;
3022                         case T_FieldStore:
3023                                 _outFieldStore(str, obj);
3024                                 break;
3025                         case T_RelabelType:
3026                                 _outRelabelType(str, obj);
3027                                 break;
3028                         case T_CoerceViaIO:
3029                                 _outCoerceViaIO(str, obj);
3030                                 break;
3031                         case T_ArrayCoerceExpr:
3032                                 _outArrayCoerceExpr(str, obj);
3033                                 break;
3034                         case T_ConvertRowtypeExpr:
3035                                 _outConvertRowtypeExpr(str, obj);
3036                                 break;
3037                         case T_CollateExpr:
3038                                 _outCollateExpr(str, obj);
3039                                 break;
3040                         case T_CaseExpr:
3041                                 _outCaseExpr(str, obj);
3042                                 break;
3043                         case T_CaseWhen:
3044                                 _outCaseWhen(str, obj);
3045                                 break;
3046                         case T_CaseTestExpr:
3047                                 _outCaseTestExpr(str, obj);
3048                                 break;
3049                         case T_ArrayExpr:
3050                                 _outArrayExpr(str, obj);
3051                                 break;
3052                         case T_RowExpr:
3053                                 _outRowExpr(str, obj);
3054                                 break;
3055                         case T_RowCompareExpr:
3056                                 _outRowCompareExpr(str, obj);
3057                                 break;
3058                         case T_CoalesceExpr:
3059                                 _outCoalesceExpr(str, obj);
3060                                 break;
3061                         case T_MinMaxExpr:
3062                                 _outMinMaxExpr(str, obj);
3063                                 break;
3064                         case T_XmlExpr:
3065                                 _outXmlExpr(str, obj);
3066                                 break;
3067                         case T_NullTest:
3068                                 _outNullTest(str, obj);
3069                                 break;
3070                         case T_BooleanTest:
3071                                 _outBooleanTest(str, obj);
3072                                 break;
3073                         case T_CoerceToDomain:
3074                                 _outCoerceToDomain(str, obj);
3075                                 break;
3076                         case T_CoerceToDomainValue:
3077                                 _outCoerceToDomainValue(str, obj);
3078                                 break;
3079                         case T_SetToDefault:
3080                                 _outSetToDefault(str, obj);
3081                                 break;
3082                         case T_CurrentOfExpr:
3083                                 _outCurrentOfExpr(str, obj);
3084                                 break;
3085                         case T_TargetEntry:
3086                                 _outTargetEntry(str, obj);
3087                                 break;
3088                         case T_RangeTblRef:
3089                                 _outRangeTblRef(str, obj);
3090                                 break;
3091                         case T_JoinExpr:
3092                                 _outJoinExpr(str, obj);
3093                                 break;
3094                         case T_FromExpr:
3095                                 _outFromExpr(str, obj);
3096                                 break;
3097
3098                         case T_Path:
3099                                 _outPath(str, obj);
3100                                 break;
3101                         case T_IndexPath:
3102                                 _outIndexPath(str, obj);
3103                                 break;
3104                         case T_BitmapHeapPath:
3105                                 _outBitmapHeapPath(str, obj);
3106                                 break;
3107                         case T_BitmapAndPath:
3108                                 _outBitmapAndPath(str, obj);
3109                                 break;
3110                         case T_BitmapOrPath:
3111                                 _outBitmapOrPath(str, obj);
3112                                 break;
3113                         case T_TidPath:
3114                                 _outTidPath(str, obj);
3115                                 break;
3116                         case T_ForeignPath:
3117                                 _outForeignPath(str, obj);
3118                                 break;
3119                         case T_CustomPath:
3120                                 _outCustomPath(str, obj);
3121                                 break;
3122                         case T_AppendPath:
3123                                 _outAppendPath(str, obj);
3124                                 break;
3125                         case T_MergeAppendPath:
3126                                 _outMergeAppendPath(str, obj);
3127                                 break;
3128                         case T_ResultPath:
3129                                 _outResultPath(str, obj);
3130                                 break;
3131                         case T_MaterialPath:
3132                                 _outMaterialPath(str, obj);
3133                                 break;
3134                         case T_UniquePath:
3135                                 _outUniquePath(str, obj);
3136                                 break;
3137                         case T_NestPath:
3138                                 _outNestPath(str, obj);
3139                                 break;
3140                         case T_MergePath:
3141                                 _outMergePath(str, obj);
3142                                 break;
3143                         case T_HashPath:
3144                                 _outHashPath(str, obj);
3145                                 break;
3146                         case T_PlannerGlobal:
3147                                 _outPlannerGlobal(str, obj);
3148                                 break;
3149                         case T_PlannerInfo:
3150                                 _outPlannerInfo(str, obj);
3151                                 break;
3152                         case T_RelOptInfo:
3153                                 _outRelOptInfo(str, obj);
3154                                 break;
3155                         case T_IndexOptInfo:
3156                                 _outIndexOptInfo(str, obj);
3157                                 break;
3158                         case T_EquivalenceClass:
3159                                 _outEquivalenceClass(str, obj);
3160                                 break;
3161                         case T_EquivalenceMember:
3162                                 _outEquivalenceMember(str, obj);
3163                                 break;
3164                         case T_PathKey:
3165                                 _outPathKey(str, obj);
3166                                 break;
3167                         case T_ParamPathInfo:
3168                                 _outParamPathInfo(str, obj);
3169                                 break;
3170                         case T_RestrictInfo:
3171                                 _outRestrictInfo(str, obj);
3172                                 break;
3173                         case T_PlaceHolderVar:
3174                                 _outPlaceHolderVar(str, obj);
3175                                 break;
3176                         case T_SpecialJoinInfo:
3177                                 _outSpecialJoinInfo(str, obj);
3178                                 break;
3179                         case T_LateralJoinInfo:
3180                                 _outLateralJoinInfo(str, obj);
3181                                 break;
3182                         case T_AppendRelInfo:
3183                                 _outAppendRelInfo(str, obj);
3184                                 break;
3185                         case T_PlaceHolderInfo:
3186                                 _outPlaceHolderInfo(str, obj);
3187                                 break;
3188                         case T_MinMaxAggInfo:
3189                                 _outMinMaxAggInfo(str, obj);
3190                                 break;
3191                         case T_PlannerParamItem:
3192                                 _outPlannerParamItem(str, obj);
3193                                 break;
3194
3195                         case T_CreateStmt:
3196                                 _outCreateStmt(str, obj);
3197                                 break;
3198                         case T_CreateForeignTableStmt:
3199                                 _outCreateForeignTableStmt(str, obj);
3200                                 break;
3201                         case T_ImportForeignSchemaStmt:
3202                                 _outImportForeignSchemaStmt(str, obj);
3203                                 break;
3204                         case T_IndexStmt:
3205                                 _outIndexStmt(str, obj);
3206                                 break;
3207                         case T_NotifyStmt:
3208                                 _outNotifyStmt(str, obj);
3209                                 break;
3210                         case T_DeclareCursorStmt:
3211                                 _outDeclareCursorStmt(str, obj);
3212                                 break;
3213                         case T_SelectStmt:
3214                                 _outSelectStmt(str, obj);
3215                                 break;
3216                         case T_ColumnDef:
3217                                 _outColumnDef(str, obj);
3218                                 break;
3219                         case T_TypeName:
3220                                 _outTypeName(str, obj);
3221                                 break;
3222                         case T_TypeCast:
3223                                 _outTypeCast(str, obj);
3224                                 break;
3225                         case T_CollateClause:
3226                                 _outCollateClause(str, obj);
3227                                 break;
3228                         case T_IndexElem:
3229                                 _outIndexElem(str, obj);
3230                                 break;
3231                         case T_Query:
3232                                 _outQuery(str, obj);
3233                                 break;
3234                         case T_WithCheckOption:
3235                                 _outWithCheckOption(str, obj);
3236                                 break;
3237                         case T_SortGroupClause:
3238                                 _outSortGroupClause(str, obj);
3239                                 break;
3240                         case T_WindowClause:
3241                                 _outWindowClause(str, obj);
3242                                 break;
3243                         case T_RowMarkClause:
3244                                 _outRowMarkClause(str, obj);
3245                                 break;
3246                         case T_WithClause:
3247                                 _outWithClause(str, obj);
3248                                 break;
3249                         case T_CommonTableExpr:
3250                                 _outCommonTableExpr(str, obj);
3251                                 break;
3252                         case T_SetOperationStmt:
3253                                 _outSetOperationStmt(str, obj);
3254                                 break;
3255                         case T_RangeTblEntry:
3256                                 _outRangeTblEntry(str, obj);
3257                                 break;
3258                         case T_RangeTblFunction:
3259                                 _outRangeTblFunction(str, obj);
3260                                 break;
3261                         case T_A_Expr:
3262                                 _outAExpr(str, obj);
3263                                 break;
3264                         case T_ColumnRef:
3265                                 _outColumnRef(str, obj);
3266                                 break;
3267                         case T_ParamRef:
3268                                 _outParamRef(str, obj);
3269                                 break;
3270                         case T_A_Const:
3271                                 _outAConst(str, obj);
3272                                 break;
3273                         case T_A_Star:
3274                                 _outA_Star(str, obj);
3275                                 break;
3276                         case T_A_Indices:
3277                                 _outA_Indices(str, obj);
3278                                 break;
3279                         case T_A_Indirection:
3280                                 _outA_Indirection(str, obj);
3281                                 break;
3282                         case T_A_ArrayExpr:
3283                                 _outA_ArrayExpr(str, obj);
3284                                 break;
3285                         case T_ResTarget:
3286                                 _outResTarget(str, obj);
3287                                 break;
3288                         case T_MultiAssignRef:
3289                                 _outMultiAssignRef(str, obj);
3290                                 break;
3291                         case T_SortBy:
3292                                 _outSortBy(str, obj);
3293                                 break;
3294                         case T_WindowDef:
3295                                 _outWindowDef(str, obj);
3296                                 break;
3297                         case T_RangeSubselect:
3298                                 _outRangeSubselect(str, obj);
3299                                 break;
3300                         case T_RangeFunction:
3301                                 _outRangeFunction(str, obj);
3302                                 break;
3303                         case T_Constraint:
3304                                 _outConstraint(str, obj);
3305                                 break;
3306                         case T_FuncCall:
3307                                 _outFuncCall(str, obj);
3308                                 break;
3309                         case T_DefElem:
3310                                 _outDefElem(str, obj);
3311                                 break;
3312                         case T_TableLikeClause:
3313                                 _outTableLikeClause(str, obj);
3314                                 break;
3315                         case T_LockingClause:
3316                                 _outLockingClause(str, obj);
3317                                 break;
3318                         case T_XmlSerialize:
3319                                 _outXmlSerialize(str, obj);
3320                                 break;
3321
3322                         default:
3323
3324                                 /*
3325                                  * This should be an ERROR, but it's too useful to be able to
3326                                  * dump structures that _outNode only understands part of.
3327                                  */
3328                                 elog(WARNING, "could not dump unrecognized node type: %d",
3329                                          (int) nodeTag(obj));
3330                                 break;
3331                 }
3332                 appendStringInfoChar(str, '}');
3333         }
3334 }
3335
3336 /*
3337  * nodeToString -
3338  *         returns the ascii representation of the Node as a palloc'd string
3339  */
3340 char *
3341 nodeToString(const void *obj)
3342 {
3343         StringInfoData str;
3344
3345         /* see stringinfo.h for an explanation of this maneuver */
3346         initStringInfo(&str);
3347         _outNode(&str, obj);
3348         return str.data;
3349 }