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