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