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