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