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