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