]> granicus.if.org Git - postgresql/blob - src/backend/nodes/outfuncs.c
Recast "ONLY" column CHECK constraints as NO INHERIT
[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_OID_FIELD(indexOid);
1998         WRITE_OID_FIELD(oldNode);
1999         WRITE_BOOL_FIELD(unique);
2000         WRITE_BOOL_FIELD(primary);
2001         WRITE_BOOL_FIELD(isconstraint);
2002         WRITE_BOOL_FIELD(deferrable);
2003         WRITE_BOOL_FIELD(initdeferred);
2004         WRITE_BOOL_FIELD(concurrent);
2005 }
2006
2007 static void
2008 _outNotifyStmt(StringInfo str, const NotifyStmt *node)
2009 {
2010         WRITE_NODE_TYPE("NOTIFY");
2011
2012         WRITE_STRING_FIELD(conditionname);
2013         WRITE_STRING_FIELD(payload);
2014 }
2015
2016 static void
2017 _outDeclareCursorStmt(StringInfo str, const DeclareCursorStmt *node)
2018 {
2019         WRITE_NODE_TYPE("DECLARECURSOR");
2020
2021         WRITE_STRING_FIELD(portalname);
2022         WRITE_INT_FIELD(options);
2023         WRITE_NODE_FIELD(query);
2024 }
2025
2026 static void
2027 _outSelectStmt(StringInfo str, const SelectStmt *node)
2028 {
2029         WRITE_NODE_TYPE("SELECT");
2030
2031         WRITE_NODE_FIELD(distinctClause);
2032         WRITE_NODE_FIELD(intoClause);
2033         WRITE_NODE_FIELD(targetList);
2034         WRITE_NODE_FIELD(fromClause);
2035         WRITE_NODE_FIELD(whereClause);
2036         WRITE_NODE_FIELD(groupClause);
2037         WRITE_NODE_FIELD(havingClause);
2038         WRITE_NODE_FIELD(windowClause);
2039         WRITE_NODE_FIELD(withClause);
2040         WRITE_NODE_FIELD(valuesLists);
2041         WRITE_NODE_FIELD(sortClause);
2042         WRITE_NODE_FIELD(limitOffset);
2043         WRITE_NODE_FIELD(limitCount);
2044         WRITE_NODE_FIELD(lockingClause);
2045         WRITE_ENUM_FIELD(op, SetOperation);
2046         WRITE_BOOL_FIELD(all);
2047         WRITE_NODE_FIELD(larg);
2048         WRITE_NODE_FIELD(rarg);
2049 }
2050
2051 static void
2052 _outFuncCall(StringInfo str, const FuncCall *node)
2053 {
2054         WRITE_NODE_TYPE("FUNCCALL");
2055
2056         WRITE_NODE_FIELD(funcname);
2057         WRITE_NODE_FIELD(args);
2058         WRITE_NODE_FIELD(agg_order);
2059         WRITE_BOOL_FIELD(agg_star);
2060         WRITE_BOOL_FIELD(agg_distinct);
2061         WRITE_BOOL_FIELD(func_variadic);
2062         WRITE_NODE_FIELD(over);
2063         WRITE_LOCATION_FIELD(location);
2064 }
2065
2066 static void
2067 _outDefElem(StringInfo str, const DefElem *node)
2068 {
2069         WRITE_NODE_TYPE("DEFELEM");
2070
2071         WRITE_STRING_FIELD(defnamespace);
2072         WRITE_STRING_FIELD(defname);
2073         WRITE_NODE_FIELD(arg);
2074         WRITE_ENUM_FIELD(defaction, DefElemAction);
2075 }
2076
2077 static void
2078 _outTableLikeClause(StringInfo str, const TableLikeClause *node)
2079 {
2080         WRITE_NODE_TYPE("TABLELIKECLAUSE");
2081
2082         WRITE_NODE_FIELD(relation);
2083         WRITE_UINT_FIELD(options);
2084 }
2085
2086 static void
2087 _outLockingClause(StringInfo str, const LockingClause *node)
2088 {
2089         WRITE_NODE_TYPE("LOCKINGCLAUSE");
2090
2091         WRITE_NODE_FIELD(lockedRels);
2092         WRITE_BOOL_FIELD(forUpdate);
2093         WRITE_BOOL_FIELD(noWait);
2094 }
2095
2096 static void
2097 _outXmlSerialize(StringInfo str, const XmlSerialize *node)
2098 {
2099         WRITE_NODE_TYPE("XMLSERIALIZE");
2100
2101         WRITE_ENUM_FIELD(xmloption, XmlOptionType);
2102         WRITE_NODE_FIELD(expr);
2103         WRITE_NODE_FIELD(typeName);
2104         WRITE_LOCATION_FIELD(location);
2105 }
2106
2107 static void
2108 _outColumnDef(StringInfo str, const ColumnDef *node)
2109 {
2110         WRITE_NODE_TYPE("COLUMNDEF");
2111
2112         WRITE_STRING_FIELD(colname);
2113         WRITE_NODE_FIELD(typeName);
2114         WRITE_INT_FIELD(inhcount);
2115         WRITE_BOOL_FIELD(is_local);
2116         WRITE_BOOL_FIELD(is_not_null);
2117         WRITE_BOOL_FIELD(is_from_type);
2118         WRITE_CHAR_FIELD(storage);
2119         WRITE_NODE_FIELD(raw_default);
2120         WRITE_NODE_FIELD(cooked_default);
2121         WRITE_NODE_FIELD(collClause);
2122         WRITE_OID_FIELD(collOid);
2123         WRITE_NODE_FIELD(constraints);
2124         WRITE_NODE_FIELD(fdwoptions);
2125 }
2126
2127 static void
2128 _outTypeName(StringInfo str, const TypeName *node)
2129 {
2130         WRITE_NODE_TYPE("TYPENAME");
2131
2132         WRITE_NODE_FIELD(names);
2133         WRITE_OID_FIELD(typeOid);
2134         WRITE_BOOL_FIELD(setof);
2135         WRITE_BOOL_FIELD(pct_type);
2136         WRITE_NODE_FIELD(typmods);
2137         WRITE_INT_FIELD(typemod);
2138         WRITE_NODE_FIELD(arrayBounds);
2139         WRITE_LOCATION_FIELD(location);
2140 }
2141
2142 static void
2143 _outTypeCast(StringInfo str, const TypeCast *node)
2144 {
2145         WRITE_NODE_TYPE("TYPECAST");
2146
2147         WRITE_NODE_FIELD(arg);
2148         WRITE_NODE_FIELD(typeName);
2149         WRITE_LOCATION_FIELD(location);
2150 }
2151
2152 static void
2153 _outCollateClause(StringInfo str, const CollateClause *node)
2154 {
2155         WRITE_NODE_TYPE("COLLATECLAUSE");
2156
2157         WRITE_NODE_FIELD(arg);
2158         WRITE_NODE_FIELD(collname);
2159         WRITE_LOCATION_FIELD(location);
2160 }
2161
2162 static void
2163 _outIndexElem(StringInfo str, const IndexElem *node)
2164 {
2165         WRITE_NODE_TYPE("INDEXELEM");
2166
2167         WRITE_STRING_FIELD(name);
2168         WRITE_NODE_FIELD(expr);
2169         WRITE_STRING_FIELD(indexcolname);
2170         WRITE_NODE_FIELD(collation);
2171         WRITE_NODE_FIELD(opclass);
2172         WRITE_ENUM_FIELD(ordering, SortByDir);
2173         WRITE_ENUM_FIELD(nulls_ordering, SortByNulls);
2174 }
2175
2176 static void
2177 _outQuery(StringInfo str, const Query *node)
2178 {
2179         WRITE_NODE_TYPE("QUERY");
2180
2181         WRITE_ENUM_FIELD(commandType, CmdType);
2182         WRITE_ENUM_FIELD(querySource, QuerySource);
2183         /* we intentionally do not print the queryId field */
2184         WRITE_BOOL_FIELD(canSetTag);
2185
2186         /*
2187          * Hack to work around missing outfuncs routines for a lot of the
2188          * utility-statement node types.  (The only one we actually *need* for
2189          * rules support is NotifyStmt.)  Someday we ought to support 'em all, but
2190          * for the meantime do this to avoid getting lots of warnings when running
2191          * with debug_print_parse on.
2192          */
2193         if (node->utilityStmt)
2194         {
2195                 switch (nodeTag(node->utilityStmt))
2196                 {
2197                         case T_CreateStmt:
2198                         case T_IndexStmt:
2199                         case T_NotifyStmt:
2200                         case T_DeclareCursorStmt:
2201                                 WRITE_NODE_FIELD(utilityStmt);
2202                                 break;
2203                         default:
2204                                 appendStringInfo(str, " :utilityStmt ?");
2205                                 break;
2206                 }
2207         }
2208         else
2209                 appendStringInfo(str, " :utilityStmt <>");
2210
2211         WRITE_INT_FIELD(resultRelation);
2212         WRITE_BOOL_FIELD(hasAggs);
2213         WRITE_BOOL_FIELD(hasWindowFuncs);
2214         WRITE_BOOL_FIELD(hasSubLinks);
2215         WRITE_BOOL_FIELD(hasDistinctOn);
2216         WRITE_BOOL_FIELD(hasRecursive);
2217         WRITE_BOOL_FIELD(hasModifyingCTE);
2218         WRITE_BOOL_FIELD(hasForUpdate);
2219         WRITE_NODE_FIELD(cteList);
2220         WRITE_NODE_FIELD(rtable);
2221         WRITE_NODE_FIELD(jointree);
2222         WRITE_NODE_FIELD(targetList);
2223         WRITE_NODE_FIELD(returningList);
2224         WRITE_NODE_FIELD(groupClause);
2225         WRITE_NODE_FIELD(havingQual);
2226         WRITE_NODE_FIELD(windowClause);
2227         WRITE_NODE_FIELD(distinctClause);
2228         WRITE_NODE_FIELD(sortClause);
2229         WRITE_NODE_FIELD(limitOffset);
2230         WRITE_NODE_FIELD(limitCount);
2231         WRITE_NODE_FIELD(rowMarks);
2232         WRITE_NODE_FIELD(setOperations);
2233         WRITE_NODE_FIELD(constraintDeps);
2234 }
2235
2236 static void
2237 _outSortGroupClause(StringInfo str, const SortGroupClause *node)
2238 {
2239         WRITE_NODE_TYPE("SORTGROUPCLAUSE");
2240
2241         WRITE_UINT_FIELD(tleSortGroupRef);
2242         WRITE_OID_FIELD(eqop);
2243         WRITE_OID_FIELD(sortop);
2244         WRITE_BOOL_FIELD(nulls_first);
2245         WRITE_BOOL_FIELD(hashable);
2246 }
2247
2248 static void
2249 _outWindowClause(StringInfo str, const WindowClause *node)
2250 {
2251         WRITE_NODE_TYPE("WINDOWCLAUSE");
2252
2253         WRITE_STRING_FIELD(name);
2254         WRITE_STRING_FIELD(refname);
2255         WRITE_NODE_FIELD(partitionClause);
2256         WRITE_NODE_FIELD(orderClause);
2257         WRITE_INT_FIELD(frameOptions);
2258         WRITE_NODE_FIELD(startOffset);
2259         WRITE_NODE_FIELD(endOffset);
2260         WRITE_UINT_FIELD(winref);
2261         WRITE_BOOL_FIELD(copiedOrder);
2262 }
2263
2264 static void
2265 _outRowMarkClause(StringInfo str, const RowMarkClause *node)
2266 {
2267         WRITE_NODE_TYPE("ROWMARKCLAUSE");
2268
2269         WRITE_UINT_FIELD(rti);
2270         WRITE_BOOL_FIELD(forUpdate);
2271         WRITE_BOOL_FIELD(noWait);
2272         WRITE_BOOL_FIELD(pushedDown);
2273 }
2274
2275 static void
2276 _outWithClause(StringInfo str, const WithClause *node)
2277 {
2278         WRITE_NODE_TYPE("WITHCLAUSE");
2279
2280         WRITE_NODE_FIELD(ctes);
2281         WRITE_BOOL_FIELD(recursive);
2282         WRITE_LOCATION_FIELD(location);
2283 }
2284
2285 static void
2286 _outCommonTableExpr(StringInfo str, const CommonTableExpr *node)
2287 {
2288         WRITE_NODE_TYPE("COMMONTABLEEXPR");
2289
2290         WRITE_STRING_FIELD(ctename);
2291         WRITE_NODE_FIELD(aliascolnames);
2292         WRITE_NODE_FIELD(ctequery);
2293         WRITE_LOCATION_FIELD(location);
2294         WRITE_BOOL_FIELD(cterecursive);
2295         WRITE_INT_FIELD(cterefcount);
2296         WRITE_NODE_FIELD(ctecolnames);
2297         WRITE_NODE_FIELD(ctecoltypes);
2298         WRITE_NODE_FIELD(ctecoltypmods);
2299         WRITE_NODE_FIELD(ctecolcollations);
2300 }
2301
2302 static void
2303 _outSetOperationStmt(StringInfo str, const SetOperationStmt *node)
2304 {
2305         WRITE_NODE_TYPE("SETOPERATIONSTMT");
2306
2307         WRITE_ENUM_FIELD(op, SetOperation);
2308         WRITE_BOOL_FIELD(all);
2309         WRITE_NODE_FIELD(larg);
2310         WRITE_NODE_FIELD(rarg);
2311         WRITE_NODE_FIELD(colTypes);
2312         WRITE_NODE_FIELD(colTypmods);
2313         WRITE_NODE_FIELD(colCollations);
2314         WRITE_NODE_FIELD(groupClauses);
2315 }
2316
2317 static void
2318 _outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
2319 {
2320         WRITE_NODE_TYPE("RTE");
2321
2322         /* put alias + eref first to make dump more legible */
2323         WRITE_NODE_FIELD(alias);
2324         WRITE_NODE_FIELD(eref);
2325         WRITE_ENUM_FIELD(rtekind, RTEKind);
2326
2327         switch (node->rtekind)
2328         {
2329                 case RTE_RELATION:
2330                         WRITE_OID_FIELD(relid);
2331                         WRITE_CHAR_FIELD(relkind);
2332                         break;
2333                 case RTE_SUBQUERY:
2334                         WRITE_NODE_FIELD(subquery);
2335                         WRITE_BOOL_FIELD(security_barrier);
2336                         break;
2337                 case RTE_JOIN:
2338                         WRITE_ENUM_FIELD(jointype, JoinType);
2339                         WRITE_NODE_FIELD(joinaliasvars);
2340                         break;
2341                 case RTE_FUNCTION:
2342                         WRITE_NODE_FIELD(funcexpr);
2343                         WRITE_NODE_FIELD(funccoltypes);
2344                         WRITE_NODE_FIELD(funccoltypmods);
2345                         WRITE_NODE_FIELD(funccolcollations);
2346                         break;
2347                 case RTE_VALUES:
2348                         WRITE_NODE_FIELD(values_lists);
2349                         WRITE_NODE_FIELD(values_collations);
2350                         break;
2351                 case RTE_CTE:
2352                         WRITE_STRING_FIELD(ctename);
2353                         WRITE_UINT_FIELD(ctelevelsup);
2354                         WRITE_BOOL_FIELD(self_reference);
2355                         WRITE_NODE_FIELD(ctecoltypes);
2356                         WRITE_NODE_FIELD(ctecoltypmods);
2357                         WRITE_NODE_FIELD(ctecolcollations);
2358                         break;
2359                 default:
2360                         elog(ERROR, "unrecognized RTE kind: %d", (int) node->rtekind);
2361                         break;
2362         }
2363
2364         WRITE_BOOL_FIELD(inh);
2365         WRITE_BOOL_FIELD(inFromCl);
2366         WRITE_UINT_FIELD(requiredPerms);
2367         WRITE_OID_FIELD(checkAsUser);
2368         WRITE_BITMAPSET_FIELD(selectedCols);
2369         WRITE_BITMAPSET_FIELD(modifiedCols);
2370 }
2371
2372 static void
2373 _outAExpr(StringInfo str, const A_Expr *node)
2374 {
2375         WRITE_NODE_TYPE("AEXPR");
2376
2377         switch (node->kind)
2378         {
2379                 case AEXPR_OP:
2380                         appendStringInfo(str, " ");
2381                         WRITE_NODE_FIELD(name);
2382                         break;
2383                 case AEXPR_AND:
2384                         appendStringInfo(str, " AND");
2385                         break;
2386                 case AEXPR_OR:
2387                         appendStringInfo(str, " OR");
2388                         break;
2389                 case AEXPR_NOT:
2390                         appendStringInfo(str, " NOT");
2391                         break;
2392                 case AEXPR_OP_ANY:
2393                         appendStringInfo(str, " ");
2394                         WRITE_NODE_FIELD(name);
2395                         appendStringInfo(str, " ANY ");
2396                         break;
2397                 case AEXPR_OP_ALL:
2398                         appendStringInfo(str, " ");
2399                         WRITE_NODE_FIELD(name);
2400                         appendStringInfo(str, " ALL ");
2401                         break;
2402                 case AEXPR_DISTINCT:
2403                         appendStringInfo(str, " DISTINCT ");
2404                         WRITE_NODE_FIELD(name);
2405                         break;
2406                 case AEXPR_NULLIF:
2407                         appendStringInfo(str, " NULLIF ");
2408                         WRITE_NODE_FIELD(name);
2409                         break;
2410                 case AEXPR_OF:
2411                         appendStringInfo(str, " OF ");
2412                         WRITE_NODE_FIELD(name);
2413                         break;
2414                 case AEXPR_IN:
2415                         appendStringInfo(str, " IN ");
2416                         WRITE_NODE_FIELD(name);
2417                         break;
2418                 default:
2419                         appendStringInfo(str, " ??");
2420                         break;
2421         }
2422
2423         WRITE_NODE_FIELD(lexpr);
2424         WRITE_NODE_FIELD(rexpr);
2425         WRITE_LOCATION_FIELD(location);
2426 }
2427
2428 static void
2429 _outValue(StringInfo str, const Value *value)
2430 {
2431         switch (value->type)
2432         {
2433                 case T_Integer:
2434                         appendStringInfo(str, "%ld", value->val.ival);
2435                         break;
2436                 case T_Float:
2437
2438                         /*
2439                          * We assume the value is a valid numeric literal and so does not
2440                          * need quoting.
2441                          */
2442                         appendStringInfoString(str, value->val.str);
2443                         break;
2444                 case T_String:
2445                         appendStringInfoChar(str, '"');
2446                         _outToken(str, value->val.str);
2447                         appendStringInfoChar(str, '"');
2448                         break;
2449                 case T_BitString:
2450                         /* internal representation already has leading 'b' */
2451                         appendStringInfoString(str, value->val.str);
2452                         break;
2453                 case T_Null:
2454                         /* this is seen only within A_Const, not in transformed trees */
2455                         appendStringInfoString(str, "NULL");
2456                         break;
2457                 default:
2458                         elog(ERROR, "unrecognized node type: %d", (int) value->type);
2459                         break;
2460         }
2461 }
2462
2463 static void
2464 _outColumnRef(StringInfo str, const ColumnRef *node)
2465 {
2466         WRITE_NODE_TYPE("COLUMNREF");
2467
2468         WRITE_NODE_FIELD(fields);
2469         WRITE_LOCATION_FIELD(location);
2470 }
2471
2472 static void
2473 _outParamRef(StringInfo str, const ParamRef *node)
2474 {
2475         WRITE_NODE_TYPE("PARAMREF");
2476
2477         WRITE_INT_FIELD(number);
2478         WRITE_LOCATION_FIELD(location);
2479 }
2480
2481 static void
2482 _outAConst(StringInfo str, const A_Const *node)
2483 {
2484         WRITE_NODE_TYPE("A_CONST");
2485
2486         appendStringInfo(str, " :val ");
2487         _outValue(str, &(node->val));
2488         WRITE_LOCATION_FIELD(location);
2489 }
2490
2491 static void
2492 _outA_Star(StringInfo str, const A_Star *node)
2493 {
2494         WRITE_NODE_TYPE("A_STAR");
2495 }
2496
2497 static void
2498 _outA_Indices(StringInfo str, const A_Indices *node)
2499 {
2500         WRITE_NODE_TYPE("A_INDICES");
2501
2502         WRITE_NODE_FIELD(lidx);
2503         WRITE_NODE_FIELD(uidx);
2504 }
2505
2506 static void
2507 _outA_Indirection(StringInfo str, const A_Indirection *node)
2508 {
2509         WRITE_NODE_TYPE("A_INDIRECTION");
2510
2511         WRITE_NODE_FIELD(arg);
2512         WRITE_NODE_FIELD(indirection);
2513 }
2514
2515 static void
2516 _outA_ArrayExpr(StringInfo str, const A_ArrayExpr *node)
2517 {
2518         WRITE_NODE_TYPE("A_ARRAYEXPR");
2519
2520         WRITE_NODE_FIELD(elements);
2521         WRITE_LOCATION_FIELD(location);
2522 }
2523
2524 static void
2525 _outResTarget(StringInfo str, const ResTarget *node)
2526 {
2527         WRITE_NODE_TYPE("RESTARGET");
2528
2529         WRITE_STRING_FIELD(name);
2530         WRITE_NODE_FIELD(indirection);
2531         WRITE_NODE_FIELD(val);
2532         WRITE_LOCATION_FIELD(location);
2533 }
2534
2535 static void
2536 _outSortBy(StringInfo str, const SortBy *node)
2537 {
2538         WRITE_NODE_TYPE("SORTBY");
2539
2540         WRITE_NODE_FIELD(node);
2541         WRITE_ENUM_FIELD(sortby_dir, SortByDir);
2542         WRITE_ENUM_FIELD(sortby_nulls, SortByNulls);
2543         WRITE_NODE_FIELD(useOp);
2544         WRITE_LOCATION_FIELD(location);
2545 }
2546
2547 static void
2548 _outWindowDef(StringInfo str, const WindowDef *node)
2549 {
2550         WRITE_NODE_TYPE("WINDOWDEF");
2551
2552         WRITE_STRING_FIELD(name);
2553         WRITE_STRING_FIELD(refname);
2554         WRITE_NODE_FIELD(partitionClause);
2555         WRITE_NODE_FIELD(orderClause);
2556         WRITE_INT_FIELD(frameOptions);
2557         WRITE_NODE_FIELD(startOffset);
2558         WRITE_NODE_FIELD(endOffset);
2559         WRITE_LOCATION_FIELD(location);
2560 }
2561
2562 static void
2563 _outRangeSubselect(StringInfo str, const RangeSubselect *node)
2564 {
2565         WRITE_NODE_TYPE("RANGESUBSELECT");
2566
2567         WRITE_NODE_FIELD(subquery);
2568         WRITE_NODE_FIELD(alias);
2569 }
2570
2571 static void
2572 _outRangeFunction(StringInfo str, const RangeFunction *node)
2573 {
2574         WRITE_NODE_TYPE("RANGEFUNCTION");
2575
2576         WRITE_NODE_FIELD(funccallnode);
2577         WRITE_NODE_FIELD(alias);
2578         WRITE_NODE_FIELD(coldeflist);
2579 }
2580
2581 static void
2582 _outConstraint(StringInfo str, const Constraint *node)
2583 {
2584         WRITE_NODE_TYPE("CONSTRAINT");
2585
2586         WRITE_STRING_FIELD(conname);
2587         WRITE_BOOL_FIELD(deferrable);
2588         WRITE_BOOL_FIELD(initdeferred);
2589         WRITE_LOCATION_FIELD(location);
2590
2591         appendStringInfo(str, " :contype ");
2592         switch (node->contype)
2593         {
2594                 case CONSTR_NULL:
2595                         appendStringInfo(str, "NULL");
2596                         break;
2597
2598                 case CONSTR_NOTNULL:
2599                         appendStringInfo(str, "NOT_NULL");
2600                         break;
2601
2602                 case CONSTR_DEFAULT:
2603                         appendStringInfo(str, "DEFAULT");
2604                         WRITE_NODE_FIELD(raw_expr);
2605                         WRITE_STRING_FIELD(cooked_expr);
2606                         break;
2607
2608                 case CONSTR_CHECK:
2609                         appendStringInfo(str, "CHECK");
2610                         WRITE_BOOL_FIELD(is_no_inherit);
2611                         WRITE_NODE_FIELD(raw_expr);
2612                         WRITE_STRING_FIELD(cooked_expr);
2613                         break;
2614
2615                 case CONSTR_PRIMARY:
2616                         appendStringInfo(str, "PRIMARY_KEY");
2617                         WRITE_NODE_FIELD(keys);
2618                         WRITE_NODE_FIELD(options);
2619                         WRITE_STRING_FIELD(indexname);
2620                         WRITE_STRING_FIELD(indexspace);
2621                         /* access_method and where_clause not currently used */
2622                         break;
2623
2624                 case CONSTR_UNIQUE:
2625                         appendStringInfo(str, "UNIQUE");
2626                         WRITE_NODE_FIELD(keys);
2627                         WRITE_NODE_FIELD(options);
2628                         WRITE_STRING_FIELD(indexname);
2629                         WRITE_STRING_FIELD(indexspace);
2630                         /* access_method and where_clause not currently used */
2631                         break;
2632
2633                 case CONSTR_EXCLUSION:
2634                         appendStringInfo(str, "EXCLUSION");
2635                         WRITE_NODE_FIELD(exclusions);
2636                         WRITE_NODE_FIELD(options);
2637                         WRITE_STRING_FIELD(indexname);
2638                         WRITE_STRING_FIELD(indexspace);
2639                         WRITE_STRING_FIELD(access_method);
2640                         WRITE_NODE_FIELD(where_clause);
2641                         break;
2642
2643                 case CONSTR_FOREIGN:
2644                         appendStringInfo(str, "FOREIGN_KEY");
2645                         WRITE_NODE_FIELD(pktable);
2646                         WRITE_NODE_FIELD(fk_attrs);
2647                         WRITE_NODE_FIELD(pk_attrs);
2648                         WRITE_CHAR_FIELD(fk_matchtype);
2649                         WRITE_CHAR_FIELD(fk_upd_action);
2650                         WRITE_CHAR_FIELD(fk_del_action);
2651                         WRITE_NODE_FIELD(old_conpfeqop);
2652                         WRITE_BOOL_FIELD(skip_validation);
2653                         WRITE_BOOL_FIELD(initially_valid);
2654                         break;
2655
2656                 case CONSTR_ATTR_DEFERRABLE:
2657                         appendStringInfo(str, "ATTR_DEFERRABLE");
2658                         break;
2659
2660                 case CONSTR_ATTR_NOT_DEFERRABLE:
2661                         appendStringInfo(str, "ATTR_NOT_DEFERRABLE");
2662                         break;
2663
2664                 case CONSTR_ATTR_DEFERRED:
2665                         appendStringInfo(str, "ATTR_DEFERRED");
2666                         break;
2667
2668                 case CONSTR_ATTR_IMMEDIATE:
2669                         appendStringInfo(str, "ATTR_IMMEDIATE");
2670                         break;
2671
2672                 default:
2673                         appendStringInfo(str, "<unrecognized_constraint %d>",
2674                                                          (int) node->contype);
2675                         break;
2676         }
2677 }
2678
2679
2680 /*
2681  * _outNode -
2682  *        converts a Node into ascii string and append it to 'str'
2683  */
2684 static void
2685 _outNode(StringInfo str, const void *obj)
2686 {
2687         if (obj == NULL)
2688                 appendStringInfo(str, "<>");
2689         else if (IsA(obj, List) ||IsA(obj, IntList) || IsA(obj, OidList))
2690                 _outList(str, obj);
2691         else if (IsA(obj, Integer) ||
2692                          IsA(obj, Float) ||
2693                          IsA(obj, String) ||
2694                          IsA(obj, BitString))
2695         {
2696                 /* nodeRead does not want to see { } around these! */
2697                 _outValue(str, obj);
2698         }
2699         else
2700         {
2701                 appendStringInfoChar(str, '{');
2702                 switch (nodeTag(obj))
2703                 {
2704                         case T_PlannedStmt:
2705                                 _outPlannedStmt(str, obj);
2706                                 break;
2707                         case T_Plan:
2708                                 _outPlan(str, obj);
2709                                 break;
2710                         case T_Result:
2711                                 _outResult(str, obj);
2712                                 break;
2713                         case T_ModifyTable:
2714                                 _outModifyTable(str, obj);
2715                                 break;
2716                         case T_Append:
2717                                 _outAppend(str, obj);
2718                                 break;
2719                         case T_MergeAppend:
2720                                 _outMergeAppend(str, obj);
2721                                 break;
2722                         case T_RecursiveUnion:
2723                                 _outRecursiveUnion(str, obj);
2724                                 break;
2725                         case T_BitmapAnd:
2726                                 _outBitmapAnd(str, obj);
2727                                 break;
2728                         case T_BitmapOr:
2729                                 _outBitmapOr(str, obj);
2730                                 break;
2731                         case T_Scan:
2732                                 _outScan(str, obj);
2733                                 break;
2734                         case T_SeqScan:
2735                                 _outSeqScan(str, obj);
2736                                 break;
2737                         case T_IndexScan:
2738                                 _outIndexScan(str, obj);
2739                                 break;
2740                         case T_IndexOnlyScan:
2741                                 _outIndexOnlyScan(str, obj);
2742                                 break;
2743                         case T_BitmapIndexScan:
2744                                 _outBitmapIndexScan(str, obj);
2745                                 break;
2746                         case T_BitmapHeapScan:
2747                                 _outBitmapHeapScan(str, obj);
2748                                 break;
2749                         case T_TidScan:
2750                                 _outTidScan(str, obj);
2751                                 break;
2752                         case T_SubqueryScan:
2753                                 _outSubqueryScan(str, obj);
2754                                 break;
2755                         case T_FunctionScan:
2756                                 _outFunctionScan(str, obj);
2757                                 break;
2758                         case T_ValuesScan:
2759                                 _outValuesScan(str, obj);
2760                                 break;
2761                         case T_CteScan:
2762                                 _outCteScan(str, obj);
2763                                 break;
2764                         case T_WorkTableScan:
2765                                 _outWorkTableScan(str, obj);
2766                                 break;
2767                         case T_ForeignScan:
2768                                 _outForeignScan(str, obj);
2769                                 break;
2770                         case T_Join:
2771                                 _outJoin(str, obj);
2772                                 break;
2773                         case T_NestLoop:
2774                                 _outNestLoop(str, obj);
2775                                 break;
2776                         case T_MergeJoin:
2777                                 _outMergeJoin(str, obj);
2778                                 break;
2779                         case T_HashJoin:
2780                                 _outHashJoin(str, obj);
2781                                 break;
2782                         case T_Agg:
2783                                 _outAgg(str, obj);
2784                                 break;
2785                         case T_WindowAgg:
2786                                 _outWindowAgg(str, obj);
2787                                 break;
2788                         case T_Group:
2789                                 _outGroup(str, obj);
2790                                 break;
2791                         case T_Material:
2792                                 _outMaterial(str, obj);
2793                                 break;
2794                         case T_Sort:
2795                                 _outSort(str, obj);
2796                                 break;
2797                         case T_Unique:
2798                                 _outUnique(str, obj);
2799                                 break;
2800                         case T_Hash:
2801                                 _outHash(str, obj);
2802                                 break;
2803                         case T_SetOp:
2804                                 _outSetOp(str, obj);
2805                                 break;
2806                         case T_LockRows:
2807                                 _outLockRows(str, obj);
2808                                 break;
2809                         case T_Limit:
2810                                 _outLimit(str, obj);
2811                                 break;
2812                         case T_NestLoopParam:
2813                                 _outNestLoopParam(str, obj);
2814                                 break;
2815                         case T_PlanRowMark:
2816                                 _outPlanRowMark(str, obj);
2817                                 break;
2818                         case T_PlanInvalItem:
2819                                 _outPlanInvalItem(str, obj);
2820                                 break;
2821                         case T_Alias:
2822                                 _outAlias(str, obj);
2823                                 break;
2824                         case T_RangeVar:
2825                                 _outRangeVar(str, obj);
2826                                 break;
2827                         case T_IntoClause:
2828                                 _outIntoClause(str, obj);
2829                                 break;
2830                         case T_Var:
2831                                 _outVar(str, obj);
2832                                 break;
2833                         case T_Const:
2834                                 _outConst(str, obj);
2835                                 break;
2836                         case T_Param:
2837                                 _outParam(str, obj);
2838                                 break;
2839                         case T_Aggref:
2840                                 _outAggref(str, obj);
2841                                 break;
2842                         case T_WindowFunc:
2843                                 _outWindowFunc(str, obj);
2844                                 break;
2845                         case T_ArrayRef:
2846                                 _outArrayRef(str, obj);
2847                                 break;
2848                         case T_FuncExpr:
2849                                 _outFuncExpr(str, obj);
2850                                 break;
2851                         case T_NamedArgExpr:
2852                                 _outNamedArgExpr(str, obj);
2853                                 break;
2854                         case T_OpExpr:
2855                                 _outOpExpr(str, obj);
2856                                 break;
2857                         case T_DistinctExpr:
2858                                 _outDistinctExpr(str, obj);
2859                                 break;
2860                         case T_NullIfExpr:
2861                                 _outNullIfExpr(str, obj);
2862                                 break;
2863                         case T_ScalarArrayOpExpr:
2864                                 _outScalarArrayOpExpr(str, obj);
2865                                 break;
2866                         case T_BoolExpr:
2867                                 _outBoolExpr(str, obj);
2868                                 break;
2869                         case T_SubLink:
2870                                 _outSubLink(str, obj);
2871                                 break;
2872                         case T_SubPlan:
2873                                 _outSubPlan(str, obj);
2874                                 break;
2875                         case T_AlternativeSubPlan:
2876                                 _outAlternativeSubPlan(str, obj);
2877                                 break;
2878                         case T_FieldSelect:
2879                                 _outFieldSelect(str, obj);
2880                                 break;
2881                         case T_FieldStore:
2882                                 _outFieldStore(str, obj);
2883                                 break;
2884                         case T_RelabelType:
2885                                 _outRelabelType(str, obj);
2886                                 break;
2887                         case T_CoerceViaIO:
2888                                 _outCoerceViaIO(str, obj);
2889                                 break;
2890                         case T_ArrayCoerceExpr:
2891                                 _outArrayCoerceExpr(str, obj);
2892                                 break;
2893                         case T_ConvertRowtypeExpr:
2894                                 _outConvertRowtypeExpr(str, obj);
2895                                 break;
2896                         case T_CollateExpr:
2897                                 _outCollateExpr(str, obj);
2898                                 break;
2899                         case T_CaseExpr:
2900                                 _outCaseExpr(str, obj);
2901                                 break;
2902                         case T_CaseWhen:
2903                                 _outCaseWhen(str, obj);
2904                                 break;
2905                         case T_CaseTestExpr:
2906                                 _outCaseTestExpr(str, obj);
2907                                 break;
2908                         case T_ArrayExpr:
2909                                 _outArrayExpr(str, obj);
2910                                 break;
2911                         case T_RowExpr:
2912                                 _outRowExpr(str, obj);
2913                                 break;
2914                         case T_RowCompareExpr:
2915                                 _outRowCompareExpr(str, obj);
2916                                 break;
2917                         case T_CoalesceExpr:
2918                                 _outCoalesceExpr(str, obj);
2919                                 break;
2920                         case T_MinMaxExpr:
2921                                 _outMinMaxExpr(str, obj);
2922                                 break;
2923                         case T_XmlExpr:
2924                                 _outXmlExpr(str, obj);
2925                                 break;
2926                         case T_NullTest:
2927                                 _outNullTest(str, obj);
2928                                 break;
2929                         case T_BooleanTest:
2930                                 _outBooleanTest(str, obj);
2931                                 break;
2932                         case T_CoerceToDomain:
2933                                 _outCoerceToDomain(str, obj);
2934                                 break;
2935                         case T_CoerceToDomainValue:
2936                                 _outCoerceToDomainValue(str, obj);
2937                                 break;
2938                         case T_SetToDefault:
2939                                 _outSetToDefault(str, obj);
2940                                 break;
2941                         case T_CurrentOfExpr:
2942                                 _outCurrentOfExpr(str, obj);
2943                                 break;
2944                         case T_TargetEntry:
2945                                 _outTargetEntry(str, obj);
2946                                 break;
2947                         case T_RangeTblRef:
2948                                 _outRangeTblRef(str, obj);
2949                                 break;
2950                         case T_JoinExpr:
2951                                 _outJoinExpr(str, obj);
2952                                 break;
2953                         case T_FromExpr:
2954                                 _outFromExpr(str, obj);
2955                                 break;
2956
2957                         case T_Path:
2958                                 _outPath(str, obj);
2959                                 break;
2960                         case T_IndexPath:
2961                                 _outIndexPath(str, obj);
2962                                 break;
2963                         case T_BitmapHeapPath:
2964                                 _outBitmapHeapPath(str, obj);
2965                                 break;
2966                         case T_BitmapAndPath:
2967                                 _outBitmapAndPath(str, obj);
2968                                 break;
2969                         case T_BitmapOrPath:
2970                                 _outBitmapOrPath(str, obj);
2971                                 break;
2972                         case T_TidPath:
2973                                 _outTidPath(str, obj);
2974                                 break;
2975                         case T_ForeignPath:
2976                                 _outForeignPath(str, obj);
2977                                 break;
2978                         case T_AppendPath:
2979                                 _outAppendPath(str, obj);
2980                                 break;
2981                         case T_MergeAppendPath:
2982                                 _outMergeAppendPath(str, obj);
2983                                 break;
2984                         case T_ResultPath:
2985                                 _outResultPath(str, obj);
2986                                 break;
2987                         case T_MaterialPath:
2988                                 _outMaterialPath(str, obj);
2989                                 break;
2990                         case T_UniquePath:
2991                                 _outUniquePath(str, obj);
2992                                 break;
2993                         case T_NestPath:
2994                                 _outNestPath(str, obj);
2995                                 break;
2996                         case T_MergePath:
2997                                 _outMergePath(str, obj);
2998                                 break;
2999                         case T_HashPath:
3000                                 _outHashPath(str, obj);
3001                                 break;
3002                         case T_PlannerGlobal:
3003                                 _outPlannerGlobal(str, obj);
3004                                 break;
3005                         case T_PlannerInfo:
3006                                 _outPlannerInfo(str, obj);
3007                                 break;
3008                         case T_RelOptInfo:
3009                                 _outRelOptInfo(str, obj);
3010                                 break;
3011                         case T_IndexOptInfo:
3012                                 _outIndexOptInfo(str, obj);
3013                                 break;
3014                         case T_EquivalenceClass:
3015                                 _outEquivalenceClass(str, obj);
3016                                 break;
3017                         case T_EquivalenceMember:
3018                                 _outEquivalenceMember(str, obj);
3019                                 break;
3020                         case T_PathKey:
3021                                 _outPathKey(str, obj);
3022                                 break;
3023                         case T_ParamPathInfo:
3024                                 _outParamPathInfo(str, obj);
3025                                 break;
3026                         case T_RestrictInfo:
3027                                 _outRestrictInfo(str, obj);
3028                                 break;
3029                         case T_PlaceHolderVar:
3030                                 _outPlaceHolderVar(str, obj);
3031                                 break;
3032                         case T_SpecialJoinInfo:
3033                                 _outSpecialJoinInfo(str, obj);
3034                                 break;
3035                         case T_AppendRelInfo:
3036                                 _outAppendRelInfo(str, obj);
3037                                 break;
3038                         case T_PlaceHolderInfo:
3039                                 _outPlaceHolderInfo(str, obj);
3040                                 break;
3041                         case T_MinMaxAggInfo:
3042                                 _outMinMaxAggInfo(str, obj);
3043                                 break;
3044                         case T_PlannerParamItem:
3045                                 _outPlannerParamItem(str, obj);
3046                                 break;
3047
3048                         case T_CreateStmt:
3049                                 _outCreateStmt(str, obj);
3050                                 break;
3051                         case T_CreateForeignTableStmt:
3052                                 _outCreateForeignTableStmt(str, obj);
3053                                 break;
3054                         case T_IndexStmt:
3055                                 _outIndexStmt(str, obj);
3056                                 break;
3057                         case T_NotifyStmt:
3058                                 _outNotifyStmt(str, obj);
3059                                 break;
3060                         case T_DeclareCursorStmt:
3061                                 _outDeclareCursorStmt(str, obj);
3062                                 break;
3063                         case T_SelectStmt:
3064                                 _outSelectStmt(str, obj);
3065                                 break;
3066                         case T_ColumnDef:
3067                                 _outColumnDef(str, obj);
3068                                 break;
3069                         case T_TypeName:
3070                                 _outTypeName(str, obj);
3071                                 break;
3072                         case T_TypeCast:
3073                                 _outTypeCast(str, obj);
3074                                 break;
3075                         case T_CollateClause:
3076                                 _outCollateClause(str, obj);
3077                                 break;
3078                         case T_IndexElem:
3079                                 _outIndexElem(str, obj);
3080                                 break;
3081                         case T_Query:
3082                                 _outQuery(str, obj);
3083                                 break;
3084                         case T_SortGroupClause:
3085                                 _outSortGroupClause(str, obj);
3086                                 break;
3087                         case T_WindowClause:
3088                                 _outWindowClause(str, obj);
3089                                 break;
3090                         case T_RowMarkClause:
3091                                 _outRowMarkClause(str, obj);
3092                                 break;
3093                         case T_WithClause:
3094                                 _outWithClause(str, obj);
3095                                 break;
3096                         case T_CommonTableExpr:
3097                                 _outCommonTableExpr(str, obj);
3098                                 break;
3099                         case T_SetOperationStmt:
3100                                 _outSetOperationStmt(str, obj);
3101                                 break;
3102                         case T_RangeTblEntry:
3103                                 _outRangeTblEntry(str, obj);
3104                                 break;
3105                         case T_A_Expr:
3106                                 _outAExpr(str, obj);
3107                                 break;
3108                         case T_ColumnRef:
3109                                 _outColumnRef(str, obj);
3110                                 break;
3111                         case T_ParamRef:
3112                                 _outParamRef(str, obj);
3113                                 break;
3114                         case T_A_Const:
3115                                 _outAConst(str, obj);
3116                                 break;
3117                         case T_A_Star:
3118                                 _outA_Star(str, obj);
3119                                 break;
3120                         case T_A_Indices:
3121                                 _outA_Indices(str, obj);
3122                                 break;
3123                         case T_A_Indirection:
3124                                 _outA_Indirection(str, obj);
3125                                 break;
3126                         case T_A_ArrayExpr:
3127                                 _outA_ArrayExpr(str, obj);
3128                                 break;
3129                         case T_ResTarget:
3130                                 _outResTarget(str, obj);
3131                                 break;
3132                         case T_SortBy:
3133                                 _outSortBy(str, obj);
3134                                 break;
3135                         case T_WindowDef:
3136                                 _outWindowDef(str, obj);
3137                                 break;
3138                         case T_RangeSubselect:
3139                                 _outRangeSubselect(str, obj);
3140                                 break;
3141                         case T_RangeFunction:
3142                                 _outRangeFunction(str, obj);
3143                                 break;
3144                         case T_Constraint:
3145                                 _outConstraint(str, obj);
3146                                 break;
3147                         case T_FuncCall:
3148                                 _outFuncCall(str, obj);
3149                                 break;
3150                         case T_DefElem:
3151                                 _outDefElem(str, obj);
3152                                 break;
3153                         case T_TableLikeClause:
3154                                 _outTableLikeClause(str, obj);
3155                                 break;
3156                         case T_LockingClause:
3157                                 _outLockingClause(str, obj);
3158                                 break;
3159                         case T_XmlSerialize:
3160                                 _outXmlSerialize(str, obj);
3161                                 break;
3162
3163                         default:
3164
3165                                 /*
3166                                  * This should be an ERROR, but it's too useful to be able to
3167                                  * dump structures that _outNode only understands part of.
3168                                  */
3169                                 elog(WARNING, "could not dump unrecognized node type: %d",
3170                                          (int) nodeTag(obj));
3171                                 break;
3172                 }
3173                 appendStringInfoChar(str, '}');
3174         }
3175 }
3176
3177 /*
3178  * nodeToString -
3179  *         returns the ascii representation of the Node as a palloc'd string
3180  */
3181 char *
3182 nodeToString(const void *obj)
3183 {
3184         StringInfoData str;
3185
3186         /* see stringinfo.h for an explanation of this maneuver */
3187         initStringInfo(&str);
3188         _outNode(&str, obj);
3189         return str.data;
3190 }