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