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