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