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