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