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