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