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