Add support for user-defined I/O conversion casts.
[PostgreSQL.git] / src / backend / nodes / outfuncs.c
blobafcc1e90ea3e87aba0dd544385217ed146f9c4fe
1 /*-------------------------------------------------------------------------
3 * outfuncs.c
4 * Output functions for Postgres tree nodes.
6 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
10 * IDENTIFICATION
11 * $PostgreSQL$
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.
20 *-------------------------------------------------------------------------
22 #include "postgres.h"
24 #include <ctype.h>
26 #include "lib/stringinfo.h"
27 #include "nodes/plannodes.h"
28 #include "nodes/relation.h"
29 #include "utils/datum.h"
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.
39 /* Write the label for the node type */
40 #define WRITE_NODE_TYPE(nodelabel) \
41 appendStringInfoString(str, nodelabel)
43 /* Write an integer field (anything written as ":fldname %d") */
44 #define WRITE_INT_FIELD(fldname) \
45 appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname)
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)
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)
55 /* Write a long-integer field */
56 #define WRITE_LONG_FIELD(fldname) \
57 appendStringInfo(str, " :" CppAsString(fldname) " %ld", node->fldname)
59 /* Write a char field (ie, one ascii character) */
60 #define WRITE_CHAR_FIELD(fldname) \
61 appendStringInfo(str, " :" CppAsString(fldname) " %c", node->fldname)
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)
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)
72 /* Write a boolean field */
73 #define WRITE_BOOL_FIELD(fldname) \
74 appendStringInfo(str, " :" CppAsString(fldname) " %s", \
75 booltostr(node->fldname))
77 /* Write a character-string (possibly NULL) field */
78 #define WRITE_STRING_FIELD(fldname) \
79 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
80 _outToken(str, node->fldname))
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)
86 /* Write a Node field */
87 #define WRITE_NODE_FIELD(fldname) \
88 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
89 _outNode(str, node->fldname))
91 /* Write a bitmapset field */
92 #define WRITE_BITMAPSET_FIELD(fldname) \
93 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
94 _outBitmapset(str, node->fldname))
97 #define booltostr(x) ((x) ? "true" : "false")
99 static void _outNode(StringInfo str, void *obj);
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.
107 * If a null or empty string is given, it is encoded as "<>".
109 static void
110 _outToken(StringInfo str, char *s)
112 if (s == NULL || *s == '\0')
114 appendStringInfo(str, "<>");
115 return;
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.
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)
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++);
141 static void
142 _outList(StringInfo str, List *node)
144 ListCell *lc;
146 appendStringInfoChar(str, '(');
148 if (IsA(node, IntList))
149 appendStringInfoChar(str, 'i');
150 else if (IsA(node, OidList))
151 appendStringInfoChar(str, 'o');
153 foreach(lc, node)
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?
160 if (IsA(node, List))
162 _outNode(str, lfirst(lc));
163 if (lnext(lc))
164 appendStringInfoChar(str, ' ');
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);
175 appendStringInfoChar(str, ')');
179 * _outBitmapset -
180 * converts a bitmap set of integers
182 * Note: the output format is "(b int int ...)", similar to an integer List.
183 * Currently bitmapsets do not appear in any node type that is stored in
184 * rules, so there is no support in readfuncs.c for reading this format.
186 static void
187 _outBitmapset(StringInfo str, Bitmapset *bms)
189 Bitmapset *tmpset;
190 int x;
192 appendStringInfoChar(str, '(');
193 appendStringInfoChar(str, 'b');
194 tmpset = bms_copy(bms);
195 while ((x = bms_first_member(tmpset)) >= 0)
196 appendStringInfo(str, " %d", x);
197 bms_free(tmpset);
198 appendStringInfoChar(str, ')');
202 * Print the value of a Datum given its type.
204 static void
205 _outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
207 Size length,
209 char *s;
211 length = datumGetSize(value, typbyval, typlen);
213 if (typbyval)
215 s = (char *) (&value);
216 appendStringInfo(str, "%u [ ", (unsigned int) length);
217 for (i = 0; i < (Size) sizeof(Datum); i++)
218 appendStringInfo(str, "%d ", (int) (s[i]));
219 appendStringInfo(str, "]");
221 else
223 s = (char *) DatumGetPointer(value);
224 if (!PointerIsValid(s))
225 appendStringInfo(str, "0 [ ]");
226 else
228 appendStringInfo(str, "%u [ ", (unsigned int) length);
229 for (i = 0; i < length; i++)
230 appendStringInfo(str, "%d ", (int) (s[i]));
231 appendStringInfo(str, "]");
238 * Stuff from plannodes.h
241 static void
242 _outPlannedStmt(StringInfo str, PlannedStmt *node)
244 WRITE_NODE_TYPE("PLANNEDSTMT");
246 WRITE_ENUM_FIELD(commandType, CmdType);
247 WRITE_BOOL_FIELD(canSetTag);
248 WRITE_NODE_FIELD(planTree);
249 WRITE_NODE_FIELD(rtable);
250 WRITE_NODE_FIELD(resultRelations);
251 WRITE_NODE_FIELD(utilityStmt);
252 WRITE_NODE_FIELD(intoClause);
253 WRITE_NODE_FIELD(subplans);
254 WRITE_BITMAPSET_FIELD(rewindPlanIDs);
255 WRITE_NODE_FIELD(returningLists);
256 WRITE_NODE_FIELD(rowMarks);
257 WRITE_NODE_FIELD(relationOids);
258 WRITE_NODE_FIELD(invalItems);
259 WRITE_INT_FIELD(nParamExec);
263 * print the basic stuff of all nodes that inherit from Plan
265 static void
266 _outPlanInfo(StringInfo str, Plan *node)
268 WRITE_FLOAT_FIELD(startup_cost, "%.2f");
269 WRITE_FLOAT_FIELD(total_cost, "%.2f");
270 WRITE_FLOAT_FIELD(plan_rows, "%.0f");
271 WRITE_INT_FIELD(plan_width);
272 WRITE_NODE_FIELD(targetlist);
273 WRITE_NODE_FIELD(qual);
274 WRITE_NODE_FIELD(lefttree);
275 WRITE_NODE_FIELD(righttree);
276 WRITE_NODE_FIELD(initPlan);
277 WRITE_BITMAPSET_FIELD(extParam);
278 WRITE_BITMAPSET_FIELD(allParam);
282 * print the basic stuff of all nodes that inherit from Scan
284 static void
285 _outScanInfo(StringInfo str, Scan *node)
287 _outPlanInfo(str, (Plan *) node);
289 WRITE_UINT_FIELD(scanrelid);
293 * print the basic stuff of all nodes that inherit from Join
295 static void
296 _outJoinPlanInfo(StringInfo str, Join *node)
298 _outPlanInfo(str, (Plan *) node);
300 WRITE_ENUM_FIELD(jointype, JoinType);
301 WRITE_NODE_FIELD(joinqual);
305 static void
306 _outPlan(StringInfo str, Plan *node)
308 WRITE_NODE_TYPE("PLAN");
310 _outPlanInfo(str, (Plan *) node);
313 static void
314 _outResult(StringInfo str, Result *node)
316 WRITE_NODE_TYPE("RESULT");
318 _outPlanInfo(str, (Plan *) node);
320 WRITE_NODE_FIELD(resconstantqual);
323 static void
324 _outAppend(StringInfo str, Append *node)
326 WRITE_NODE_TYPE("APPEND");
328 _outPlanInfo(str, (Plan *) node);
330 WRITE_NODE_FIELD(appendplans);
331 WRITE_BOOL_FIELD(isTarget);
334 static void
335 _outRecursiveUnion(StringInfo str, RecursiveUnion *node)
337 int i;
339 WRITE_NODE_TYPE("RECURSIVEUNION");
341 _outPlanInfo(str, (Plan *) node);
343 WRITE_INT_FIELD(wtParam);
344 WRITE_INT_FIELD(numCols);
346 appendStringInfo(str, " :dupColIdx");
347 for (i = 0; i < node->numCols; i++)
348 appendStringInfo(str, " %d", node->dupColIdx[i]);
350 appendStringInfo(str, " :dupOperators");
351 for (i = 0; i < node->numCols; i++)
352 appendStringInfo(str, " %u", node->dupOperators[i]);
354 WRITE_LONG_FIELD(numGroups);
357 static void
358 _outBitmapAnd(StringInfo str, BitmapAnd *node)
360 WRITE_NODE_TYPE("BITMAPAND");
362 _outPlanInfo(str, (Plan *) node);
364 WRITE_NODE_FIELD(bitmapplans);
367 static void
368 _outBitmapOr(StringInfo str, BitmapOr *node)
370 WRITE_NODE_TYPE("BITMAPOR");
372 _outPlanInfo(str, (Plan *) node);
374 WRITE_NODE_FIELD(bitmapplans);
377 static void
378 _outScan(StringInfo str, Scan *node)
380 WRITE_NODE_TYPE("SCAN");
382 _outScanInfo(str, (Scan *) node);
385 static void
386 _outSeqScan(StringInfo str, SeqScan *node)
388 WRITE_NODE_TYPE("SEQSCAN");
390 _outScanInfo(str, (Scan *) node);
393 static void
394 _outIndexScan(StringInfo str, IndexScan *node)
396 WRITE_NODE_TYPE("INDEXSCAN");
398 _outScanInfo(str, (Scan *) node);
400 WRITE_OID_FIELD(indexid);
401 WRITE_NODE_FIELD(indexqual);
402 WRITE_NODE_FIELD(indexqualorig);
403 WRITE_ENUM_FIELD(indexorderdir, ScanDirection);
406 static void
407 _outBitmapIndexScan(StringInfo str, BitmapIndexScan *node)
409 WRITE_NODE_TYPE("BITMAPINDEXSCAN");
411 _outScanInfo(str, (Scan *) node);
413 WRITE_OID_FIELD(indexid);
414 WRITE_NODE_FIELD(indexqual);
415 WRITE_NODE_FIELD(indexqualorig);
418 static void
419 _outBitmapHeapScan(StringInfo str, BitmapHeapScan *node)
421 WRITE_NODE_TYPE("BITMAPHEAPSCAN");
423 _outScanInfo(str, (Scan *) node);
425 WRITE_NODE_FIELD(bitmapqualorig);
428 static void
429 _outTidScan(StringInfo str, TidScan *node)
431 WRITE_NODE_TYPE("TIDSCAN");
433 _outScanInfo(str, (Scan *) node);
435 WRITE_NODE_FIELD(tidquals);
438 static void
439 _outSubqueryScan(StringInfo str, SubqueryScan *node)
441 WRITE_NODE_TYPE("SUBQUERYSCAN");
443 _outScanInfo(str, (Scan *) node);
445 WRITE_NODE_FIELD(subplan);
446 WRITE_NODE_FIELD(subrtable);
449 static void
450 _outFunctionScan(StringInfo str, FunctionScan *node)
452 WRITE_NODE_TYPE("FUNCTIONSCAN");
454 _outScanInfo(str, (Scan *) node);
456 WRITE_NODE_FIELD(funcexpr);
457 WRITE_NODE_FIELD(funccolnames);
458 WRITE_NODE_FIELD(funccoltypes);
459 WRITE_NODE_FIELD(funccoltypmods);
462 static void
463 _outValuesScan(StringInfo str, ValuesScan *node)
465 WRITE_NODE_TYPE("VALUESSCAN");
467 _outScanInfo(str, (Scan *) node);
469 WRITE_NODE_FIELD(values_lists);
472 static void
473 _outCteScan(StringInfo str, CteScan *node)
475 WRITE_NODE_TYPE("CTESCAN");
477 _outScanInfo(str, (Scan *) node);
479 WRITE_INT_FIELD(ctePlanId);
480 WRITE_INT_FIELD(cteParam);
483 static void
484 _outWorkTableScan(StringInfo str, WorkTableScan *node)
486 WRITE_NODE_TYPE("WORKTABLESCAN");
488 _outScanInfo(str, (Scan *) node);
490 WRITE_INT_FIELD(wtParam);
493 static void
494 _outJoin(StringInfo str, Join *node)
496 WRITE_NODE_TYPE("JOIN");
498 _outJoinPlanInfo(str, (Join *) node);
501 static void
502 _outNestLoop(StringInfo str, NestLoop *node)
504 WRITE_NODE_TYPE("NESTLOOP");
506 _outJoinPlanInfo(str, (Join *) node);
509 static void
510 _outMergeJoin(StringInfo str, MergeJoin *node)
512 int numCols;
513 int i;
515 WRITE_NODE_TYPE("MERGEJOIN");
517 _outJoinPlanInfo(str, (Join *) node);
519 WRITE_NODE_FIELD(mergeclauses);
521 numCols = list_length(node->mergeclauses);
523 appendStringInfo(str, " :mergeFamilies");
524 for (i = 0; i < numCols; i++)
525 appendStringInfo(str, " %u", node->mergeFamilies[i]);
527 appendStringInfo(str, " :mergeStrategies");
528 for (i = 0; i < numCols; i++)
529 appendStringInfo(str, " %d", node->mergeStrategies[i]);
531 appendStringInfo(str, " :mergeNullsFirst");
532 for (i = 0; i < numCols; i++)
533 appendStringInfo(str, " %d", (int) node->mergeNullsFirst[i]);
536 static void
537 _outHashJoin(StringInfo str, HashJoin *node)
539 WRITE_NODE_TYPE("HASHJOIN");
541 _outJoinPlanInfo(str, (Join *) node);
543 WRITE_NODE_FIELD(hashclauses);
546 static void
547 _outAgg(StringInfo str, Agg *node)
549 int i;
551 WRITE_NODE_TYPE("AGG");
553 _outPlanInfo(str, (Plan *) node);
555 WRITE_ENUM_FIELD(aggstrategy, AggStrategy);
556 WRITE_INT_FIELD(numCols);
558 appendStringInfo(str, " :grpColIdx");
559 for (i = 0; i < node->numCols; i++)
560 appendStringInfo(str, " %d", node->grpColIdx[i]);
562 appendStringInfo(str, " :grpOperators");
563 for (i = 0; i < node->numCols; i++)
564 appendStringInfo(str, " %u", node->grpOperators[i]);
566 WRITE_LONG_FIELD(numGroups);
569 static void
570 _outGroup(StringInfo str, Group *node)
572 int i;
574 WRITE_NODE_TYPE("GROUP");
576 _outPlanInfo(str, (Plan *) node);
578 WRITE_INT_FIELD(numCols);
580 appendStringInfo(str, " :grpColIdx");
581 for (i = 0; i < node->numCols; i++)
582 appendStringInfo(str, " %d", node->grpColIdx[i]);
584 appendStringInfo(str, " :grpOperators");
585 for (i = 0; i < node->numCols; i++)
586 appendStringInfo(str, " %u", node->grpOperators[i]);
589 static void
590 _outMaterial(StringInfo str, Material *node)
592 WRITE_NODE_TYPE("MATERIAL");
594 _outPlanInfo(str, (Plan *) node);
597 static void
598 _outSort(StringInfo str, Sort *node)
600 int i;
602 WRITE_NODE_TYPE("SORT");
604 _outPlanInfo(str, (Plan *) node);
606 WRITE_INT_FIELD(numCols);
608 appendStringInfo(str, " :sortColIdx");
609 for (i = 0; i < node->numCols; i++)
610 appendStringInfo(str, " %d", node->sortColIdx[i]);
612 appendStringInfo(str, " :sortOperators");
613 for (i = 0; i < node->numCols; i++)
614 appendStringInfo(str, " %u", node->sortOperators[i]);
616 appendStringInfo(str, " :nullsFirst");
617 for (i = 0; i < node->numCols; i++)
618 appendStringInfo(str, " %s", booltostr(node->nullsFirst[i]));
621 static void
622 _outUnique(StringInfo str, Unique *node)
624 int i;
626 WRITE_NODE_TYPE("UNIQUE");
628 _outPlanInfo(str, (Plan *) node);
630 WRITE_INT_FIELD(numCols);
632 appendStringInfo(str, " :uniqColIdx");
633 for (i = 0; i < node->numCols; i++)
634 appendStringInfo(str, " %d", node->uniqColIdx[i]);
636 appendStringInfo(str, " :uniqOperators");
637 for (i = 0; i < node->numCols; i++)
638 appendStringInfo(str, " %u", node->uniqOperators[i]);
641 static void
642 _outHash(StringInfo str, Hash *node)
644 WRITE_NODE_TYPE("HASH");
646 _outPlanInfo(str, (Plan *) node);
649 static void
650 _outSetOp(StringInfo str, SetOp *node)
652 int i;
654 WRITE_NODE_TYPE("SETOP");
656 _outPlanInfo(str, (Plan *) node);
658 WRITE_ENUM_FIELD(cmd, SetOpCmd);
659 WRITE_ENUM_FIELD(strategy, SetOpStrategy);
660 WRITE_INT_FIELD(numCols);
662 appendStringInfo(str, " :dupColIdx");
663 for (i = 0; i < node->numCols; i++)
664 appendStringInfo(str, " %d", node->dupColIdx[i]);
666 appendStringInfo(str, " :dupOperators");
667 for (i = 0; i < node->numCols; i++)
668 appendStringInfo(str, " %u", node->dupOperators[i]);
670 WRITE_INT_FIELD(flagColIdx);
671 WRITE_INT_FIELD(firstFlag);
672 WRITE_LONG_FIELD(numGroups);
675 static void
676 _outLimit(StringInfo str, Limit *node)
678 WRITE_NODE_TYPE("LIMIT");
680 _outPlanInfo(str, (Plan *) node);
682 WRITE_NODE_FIELD(limitOffset);
683 WRITE_NODE_FIELD(limitCount);
686 static void
687 _outPlanInvalItem(StringInfo str, PlanInvalItem *node)
689 WRITE_NODE_TYPE("PLANINVALITEM");
691 WRITE_INT_FIELD(cacheId);
692 appendStringInfo(str, " :tupleId (%u,%u)",
693 ItemPointerGetBlockNumber(&node->tupleId),
694 ItemPointerGetOffsetNumber(&node->tupleId));
697 /*****************************************************************************
699 * Stuff from primnodes.h.
701 *****************************************************************************/
703 static void
704 _outAlias(StringInfo str, Alias *node)
706 WRITE_NODE_TYPE("ALIAS");
708 WRITE_STRING_FIELD(aliasname);
709 WRITE_NODE_FIELD(colnames);
712 static void
713 _outRangeVar(StringInfo str, RangeVar *node)
715 WRITE_NODE_TYPE("RANGEVAR");
718 * we deliberately ignore catalogname here, since it is presently not
719 * semantically meaningful
721 WRITE_STRING_FIELD(schemaname);
722 WRITE_STRING_FIELD(relname);
723 WRITE_ENUM_FIELD(inhOpt, InhOption);
724 WRITE_BOOL_FIELD(istemp);
725 WRITE_NODE_FIELD(alias);
726 WRITE_LOCATION_FIELD(location);
729 static void
730 _outIntoClause(StringInfo str, IntoClause *node)
732 WRITE_NODE_TYPE("INTOCLAUSE");
734 WRITE_NODE_FIELD(rel);
735 WRITE_NODE_FIELD(colNames);
736 WRITE_NODE_FIELD(options);
737 WRITE_ENUM_FIELD(onCommit, OnCommitAction);
738 WRITE_STRING_FIELD(tableSpaceName);
741 static void
742 _outVar(StringInfo str, Var *node)
744 WRITE_NODE_TYPE("VAR");
746 WRITE_UINT_FIELD(varno);
747 WRITE_INT_FIELD(varattno);
748 WRITE_OID_FIELD(vartype);
749 WRITE_INT_FIELD(vartypmod);
750 WRITE_UINT_FIELD(varlevelsup);
751 WRITE_UINT_FIELD(varnoold);
752 WRITE_INT_FIELD(varoattno);
753 WRITE_LOCATION_FIELD(location);
756 static void
757 _outConst(StringInfo str, Const *node)
759 WRITE_NODE_TYPE("CONST");
761 WRITE_OID_FIELD(consttype);
762 WRITE_INT_FIELD(consttypmod);
763 WRITE_INT_FIELD(constlen);
764 WRITE_BOOL_FIELD(constbyval);
765 WRITE_BOOL_FIELD(constisnull);
766 WRITE_LOCATION_FIELD(location);
768 appendStringInfo(str, " :constvalue ");
769 if (node->constisnull)
770 appendStringInfo(str, "<>");
771 else
772 _outDatum(str, node->constvalue, node->constlen, node->constbyval);
775 static void
776 _outParam(StringInfo str, Param *node)
778 WRITE_NODE_TYPE("PARAM");
780 WRITE_ENUM_FIELD(paramkind, ParamKind);
781 WRITE_INT_FIELD(paramid);
782 WRITE_OID_FIELD(paramtype);
783 WRITE_INT_FIELD(paramtypmod);
784 WRITE_LOCATION_FIELD(location);
787 static void
788 _outAggref(StringInfo str, Aggref *node)
790 WRITE_NODE_TYPE("AGGREF");
792 WRITE_OID_FIELD(aggfnoid);
793 WRITE_OID_FIELD(aggtype);
794 WRITE_NODE_FIELD(args);
795 WRITE_UINT_FIELD(agglevelsup);
796 WRITE_BOOL_FIELD(aggstar);
797 WRITE_BOOL_FIELD(aggdistinct);
798 WRITE_LOCATION_FIELD(location);
801 static void
802 _outArrayRef(StringInfo str, ArrayRef *node)
804 WRITE_NODE_TYPE("ARRAYREF");
806 WRITE_OID_FIELD(refarraytype);
807 WRITE_OID_FIELD(refelemtype);
808 WRITE_INT_FIELD(reftypmod);
809 WRITE_NODE_FIELD(refupperindexpr);
810 WRITE_NODE_FIELD(reflowerindexpr);
811 WRITE_NODE_FIELD(refexpr);
812 WRITE_NODE_FIELD(refassgnexpr);
815 static void
816 _outFuncExpr(StringInfo str, FuncExpr *node)
818 WRITE_NODE_TYPE("FUNCEXPR");
820 WRITE_OID_FIELD(funcid);
821 WRITE_OID_FIELD(funcresulttype);
822 WRITE_BOOL_FIELD(funcretset);
823 WRITE_ENUM_FIELD(funcformat, CoercionForm);
824 WRITE_NODE_FIELD(args);
825 WRITE_LOCATION_FIELD(location);
828 static void
829 _outOpExpr(StringInfo str, OpExpr *node)
831 WRITE_NODE_TYPE("OPEXPR");
833 WRITE_OID_FIELD(opno);
834 WRITE_OID_FIELD(opfuncid);
835 WRITE_OID_FIELD(opresulttype);
836 WRITE_BOOL_FIELD(opretset);
837 WRITE_NODE_FIELD(args);
838 WRITE_LOCATION_FIELD(location);
841 static void
842 _outDistinctExpr(StringInfo str, DistinctExpr *node)
844 WRITE_NODE_TYPE("DISTINCTEXPR");
846 WRITE_OID_FIELD(opno);
847 WRITE_OID_FIELD(opfuncid);
848 WRITE_OID_FIELD(opresulttype);
849 WRITE_BOOL_FIELD(opretset);
850 WRITE_NODE_FIELD(args);
851 WRITE_LOCATION_FIELD(location);
854 static void
855 _outScalarArrayOpExpr(StringInfo str, ScalarArrayOpExpr *node)
857 WRITE_NODE_TYPE("SCALARARRAYOPEXPR");
859 WRITE_OID_FIELD(opno);
860 WRITE_OID_FIELD(opfuncid);
861 WRITE_BOOL_FIELD(useOr);
862 WRITE_NODE_FIELD(args);
863 WRITE_LOCATION_FIELD(location);
866 static void
867 _outBoolExpr(StringInfo str, BoolExpr *node)
869 char *opstr = NULL;
871 WRITE_NODE_TYPE("BOOLEXPR");
873 /* do-it-yourself enum representation */
874 switch (node->boolop)
876 case AND_EXPR:
877 opstr = "and";
878 break;
879 case OR_EXPR:
880 opstr = "or";
881 break;
882 case NOT_EXPR:
883 opstr = "not";
884 break;
886 appendStringInfo(str, " :boolop ");
887 _outToken(str, opstr);
889 WRITE_NODE_FIELD(args);
890 WRITE_LOCATION_FIELD(location);
893 static void
894 _outSubLink(StringInfo str, SubLink *node)
896 WRITE_NODE_TYPE("SUBLINK");
898 WRITE_ENUM_FIELD(subLinkType, SubLinkType);
899 WRITE_NODE_FIELD(testexpr);
900 WRITE_NODE_FIELD(operName);
901 WRITE_NODE_FIELD(subselect);
902 WRITE_LOCATION_FIELD(location);
905 static void
906 _outSubPlan(StringInfo str, SubPlan *node)
908 WRITE_NODE_TYPE("SUBPLAN");
910 WRITE_ENUM_FIELD(subLinkType, SubLinkType);
911 WRITE_NODE_FIELD(testexpr);
912 WRITE_NODE_FIELD(paramIds);
913 WRITE_INT_FIELD(plan_id);
914 WRITE_OID_FIELD(firstColType);
915 WRITE_BOOL_FIELD(useHashTable);
916 WRITE_BOOL_FIELD(unknownEqFalse);
917 WRITE_NODE_FIELD(setParam);
918 WRITE_NODE_FIELD(parParam);
919 WRITE_NODE_FIELD(args);
920 WRITE_FLOAT_FIELD(startup_cost, "%.2f");
921 WRITE_FLOAT_FIELD(per_call_cost, "%.2f");
924 static void
925 _outAlternativeSubPlan(StringInfo str, AlternativeSubPlan *node)
927 WRITE_NODE_TYPE("ALTERNATIVESUBPLAN");
929 WRITE_NODE_FIELD(subplans);
932 static void
933 _outFieldSelect(StringInfo str, FieldSelect *node)
935 WRITE_NODE_TYPE("FIELDSELECT");
937 WRITE_NODE_FIELD(arg);
938 WRITE_INT_FIELD(fieldnum);
939 WRITE_OID_FIELD(resulttype);
940 WRITE_INT_FIELD(resulttypmod);
943 static void
944 _outFieldStore(StringInfo str, FieldStore *node)
946 WRITE_NODE_TYPE("FIELDSTORE");
948 WRITE_NODE_FIELD(arg);
949 WRITE_NODE_FIELD(newvals);
950 WRITE_NODE_FIELD(fieldnums);
951 WRITE_OID_FIELD(resulttype);
954 static void
955 _outRelabelType(StringInfo str, RelabelType *node)
957 WRITE_NODE_TYPE("RELABELTYPE");
959 WRITE_NODE_FIELD(arg);
960 WRITE_OID_FIELD(resulttype);
961 WRITE_INT_FIELD(resulttypmod);
962 WRITE_ENUM_FIELD(relabelformat, CoercionForm);
963 WRITE_LOCATION_FIELD(location);
966 static void
967 _outCoerceViaIO(StringInfo str, CoerceViaIO *node)
969 WRITE_NODE_TYPE("COERCEVIAIO");
971 WRITE_NODE_FIELD(arg);
972 WRITE_OID_FIELD(resulttype);
973 WRITE_ENUM_FIELD(coerceformat, CoercionForm);
974 WRITE_LOCATION_FIELD(location);
977 static void
978 _outArrayCoerceExpr(StringInfo str, ArrayCoerceExpr *node)
980 WRITE_NODE_TYPE("ARRAYCOERCEEXPR");
982 WRITE_NODE_FIELD(arg);
983 WRITE_OID_FIELD(elemfuncid);
984 WRITE_OID_FIELD(resulttype);
985 WRITE_INT_FIELD(resulttypmod);
986 WRITE_BOOL_FIELD(isExplicit);
987 WRITE_ENUM_FIELD(coerceformat, CoercionForm);
988 WRITE_LOCATION_FIELD(location);
991 static void
992 _outConvertRowtypeExpr(StringInfo str, ConvertRowtypeExpr *node)
994 WRITE_NODE_TYPE("CONVERTROWTYPEEXPR");
996 WRITE_NODE_FIELD(arg);
997 WRITE_OID_FIELD(resulttype);
998 WRITE_ENUM_FIELD(convertformat, CoercionForm);
999 WRITE_LOCATION_FIELD(location);
1002 static void
1003 _outCaseExpr(StringInfo str, CaseExpr *node)
1005 WRITE_NODE_TYPE("CASE");
1007 WRITE_OID_FIELD(casetype);
1008 WRITE_NODE_FIELD(arg);
1009 WRITE_NODE_FIELD(args);
1010 WRITE_NODE_FIELD(defresult);
1011 WRITE_LOCATION_FIELD(location);
1014 static void
1015 _outCaseWhen(StringInfo str, CaseWhen *node)
1017 WRITE_NODE_TYPE("WHEN");
1019 WRITE_NODE_FIELD(expr);
1020 WRITE_NODE_FIELD(result);
1021 WRITE_LOCATION_FIELD(location);
1024 static void
1025 _outCaseTestExpr(StringInfo str, CaseTestExpr *node)
1027 WRITE_NODE_TYPE("CASETESTEXPR");
1029 WRITE_OID_FIELD(typeId);
1030 WRITE_INT_FIELD(typeMod);
1033 static void
1034 _outArrayExpr(StringInfo str, ArrayExpr *node)
1036 WRITE_NODE_TYPE("ARRAY");
1038 WRITE_OID_FIELD(array_typeid);
1039 WRITE_OID_FIELD(element_typeid);
1040 WRITE_NODE_FIELD(elements);
1041 WRITE_BOOL_FIELD(multidims);
1042 WRITE_LOCATION_FIELD(location);
1045 static void
1046 _outRowExpr(StringInfo str, RowExpr *node)
1048 WRITE_NODE_TYPE("ROW");
1050 WRITE_NODE_FIELD(args);
1051 WRITE_OID_FIELD(row_typeid);
1052 WRITE_ENUM_FIELD(row_format, CoercionForm);
1053 WRITE_NODE_FIELD(colnames);
1054 WRITE_LOCATION_FIELD(location);
1057 static void
1058 _outRowCompareExpr(StringInfo str, RowCompareExpr *node)
1060 WRITE_NODE_TYPE("ROWCOMPARE");
1062 WRITE_ENUM_FIELD(rctype, RowCompareType);
1063 WRITE_NODE_FIELD(opnos);
1064 WRITE_NODE_FIELD(opfamilies);
1065 WRITE_NODE_FIELD(largs);
1066 WRITE_NODE_FIELD(rargs);
1069 static void
1070 _outCoalesceExpr(StringInfo str, CoalesceExpr *node)
1072 WRITE_NODE_TYPE("COALESCE");
1074 WRITE_OID_FIELD(coalescetype);
1075 WRITE_NODE_FIELD(args);
1076 WRITE_LOCATION_FIELD(location);
1079 static void
1080 _outMinMaxExpr(StringInfo str, MinMaxExpr *node)
1082 WRITE_NODE_TYPE("MINMAX");
1084 WRITE_OID_FIELD(minmaxtype);
1085 WRITE_ENUM_FIELD(op, MinMaxOp);
1086 WRITE_NODE_FIELD(args);
1087 WRITE_LOCATION_FIELD(location);
1090 static void
1091 _outXmlExpr(StringInfo str, XmlExpr *node)
1093 WRITE_NODE_TYPE("XMLEXPR");
1095 WRITE_ENUM_FIELD(op, XmlExprOp);
1096 WRITE_STRING_FIELD(name);
1097 WRITE_NODE_FIELD(named_args);
1098 WRITE_NODE_FIELD(arg_names);
1099 WRITE_NODE_FIELD(args);
1100 WRITE_ENUM_FIELD(xmloption, XmlOptionType);
1101 WRITE_OID_FIELD(type);
1102 WRITE_INT_FIELD(typmod);
1103 WRITE_LOCATION_FIELD(location);
1106 static void
1107 _outNullIfExpr(StringInfo str, NullIfExpr *node)
1109 WRITE_NODE_TYPE("NULLIFEXPR");
1111 WRITE_OID_FIELD(opno);
1112 WRITE_OID_FIELD(opfuncid);
1113 WRITE_OID_FIELD(opresulttype);
1114 WRITE_BOOL_FIELD(opretset);
1115 WRITE_NODE_FIELD(args);
1116 WRITE_LOCATION_FIELD(location);
1119 static void
1120 _outNullTest(StringInfo str, NullTest *node)
1122 WRITE_NODE_TYPE("NULLTEST");
1124 WRITE_NODE_FIELD(arg);
1125 WRITE_ENUM_FIELD(nulltesttype, NullTestType);
1128 static void
1129 _outBooleanTest(StringInfo str, BooleanTest *node)
1131 WRITE_NODE_TYPE("BOOLEANTEST");
1133 WRITE_NODE_FIELD(arg);
1134 WRITE_ENUM_FIELD(booltesttype, BoolTestType);
1137 static void
1138 _outCoerceToDomain(StringInfo str, CoerceToDomain *node)
1140 WRITE_NODE_TYPE("COERCETODOMAIN");
1142 WRITE_NODE_FIELD(arg);
1143 WRITE_OID_FIELD(resulttype);
1144 WRITE_INT_FIELD(resulttypmod);
1145 WRITE_ENUM_FIELD(coercionformat, CoercionForm);
1146 WRITE_LOCATION_FIELD(location);
1149 static void
1150 _outCoerceToDomainValue(StringInfo str, CoerceToDomainValue *node)
1152 WRITE_NODE_TYPE("COERCETODOMAINVALUE");
1154 WRITE_OID_FIELD(typeId);
1155 WRITE_INT_FIELD(typeMod);
1156 WRITE_LOCATION_FIELD(location);
1159 static void
1160 _outSetToDefault(StringInfo str, SetToDefault *node)
1162 WRITE_NODE_TYPE("SETTODEFAULT");
1164 WRITE_OID_FIELD(typeId);
1165 WRITE_INT_FIELD(typeMod);
1166 WRITE_LOCATION_FIELD(location);
1169 static void
1170 _outCurrentOfExpr(StringInfo str, CurrentOfExpr *node)
1172 WRITE_NODE_TYPE("CURRENTOFEXPR");
1174 WRITE_UINT_FIELD(cvarno);
1175 WRITE_STRING_FIELD(cursor_name);
1176 WRITE_INT_FIELD(cursor_param);
1179 static void
1180 _outTargetEntry(StringInfo str, TargetEntry *node)
1182 WRITE_NODE_TYPE("TARGETENTRY");
1184 WRITE_NODE_FIELD(expr);
1185 WRITE_INT_FIELD(resno);
1186 WRITE_STRING_FIELD(resname);
1187 WRITE_UINT_FIELD(ressortgroupref);
1188 WRITE_OID_FIELD(resorigtbl);
1189 WRITE_INT_FIELD(resorigcol);
1190 WRITE_BOOL_FIELD(resjunk);
1193 static void
1194 _outRangeTblRef(StringInfo str, RangeTblRef *node)
1196 WRITE_NODE_TYPE("RANGETBLREF");
1198 WRITE_INT_FIELD(rtindex);
1201 static void
1202 _outJoinExpr(StringInfo str, JoinExpr *node)
1204 WRITE_NODE_TYPE("JOINEXPR");
1206 WRITE_ENUM_FIELD(jointype, JoinType);
1207 WRITE_BOOL_FIELD(isNatural);
1208 WRITE_NODE_FIELD(larg);
1209 WRITE_NODE_FIELD(rarg);
1210 WRITE_NODE_FIELD(using);
1211 WRITE_NODE_FIELD(quals);
1212 WRITE_NODE_FIELD(alias);
1213 WRITE_INT_FIELD(rtindex);
1216 static void
1217 _outFromExpr(StringInfo str, FromExpr *node)
1219 WRITE_NODE_TYPE("FROMEXPR");
1221 WRITE_NODE_FIELD(fromlist);
1222 WRITE_NODE_FIELD(quals);
1225 /*****************************************************************************
1227 * Stuff from relation.h.
1229 *****************************************************************************/
1232 * print the basic stuff of all nodes that inherit from Path
1234 * Note we do NOT print the parent, else we'd be in infinite recursion
1236 static void
1237 _outPathInfo(StringInfo str, Path *node)
1239 WRITE_ENUM_FIELD(pathtype, NodeTag);
1240 WRITE_FLOAT_FIELD(startup_cost, "%.2f");
1241 WRITE_FLOAT_FIELD(total_cost, "%.2f");
1242 WRITE_NODE_FIELD(pathkeys);
1246 * print the basic stuff of all nodes that inherit from JoinPath
1248 static void
1249 _outJoinPathInfo(StringInfo str, JoinPath *node)
1251 _outPathInfo(str, (Path *) node);
1253 WRITE_ENUM_FIELD(jointype, JoinType);
1254 WRITE_NODE_FIELD(outerjoinpath);
1255 WRITE_NODE_FIELD(innerjoinpath);
1256 WRITE_NODE_FIELD(joinrestrictinfo);
1259 static void
1260 _outPath(StringInfo str, Path *node)
1262 WRITE_NODE_TYPE("PATH");
1264 _outPathInfo(str, (Path *) node);
1267 static void
1268 _outIndexPath(StringInfo str, IndexPath *node)
1270 WRITE_NODE_TYPE("INDEXPATH");
1272 _outPathInfo(str, (Path *) node);
1274 WRITE_NODE_FIELD(indexinfo);
1275 WRITE_NODE_FIELD(indexclauses);
1276 WRITE_NODE_FIELD(indexquals);
1277 WRITE_BOOL_FIELD(isjoininner);
1278 WRITE_ENUM_FIELD(indexscandir, ScanDirection);
1279 WRITE_FLOAT_FIELD(indextotalcost, "%.2f");
1280 WRITE_FLOAT_FIELD(indexselectivity, "%.4f");
1281 WRITE_FLOAT_FIELD(rows, "%.0f");
1284 static void
1285 _outBitmapHeapPath(StringInfo str, BitmapHeapPath *node)
1287 WRITE_NODE_TYPE("BITMAPHEAPPATH");
1289 _outPathInfo(str, (Path *) node);
1291 WRITE_NODE_FIELD(bitmapqual);
1292 WRITE_BOOL_FIELD(isjoininner);
1293 WRITE_FLOAT_FIELD(rows, "%.0f");
1296 static void
1297 _outBitmapAndPath(StringInfo str, BitmapAndPath *node)
1299 WRITE_NODE_TYPE("BITMAPANDPATH");
1301 _outPathInfo(str, (Path *) node);
1303 WRITE_NODE_FIELD(bitmapquals);
1304 WRITE_FLOAT_FIELD(bitmapselectivity, "%.4f");
1307 static void
1308 _outBitmapOrPath(StringInfo str, BitmapOrPath *node)
1310 WRITE_NODE_TYPE("BITMAPORPATH");
1312 _outPathInfo(str, (Path *) node);
1314 WRITE_NODE_FIELD(bitmapquals);
1315 WRITE_FLOAT_FIELD(bitmapselectivity, "%.4f");
1318 static void
1319 _outTidPath(StringInfo str, TidPath *node)
1321 WRITE_NODE_TYPE("TIDPATH");
1323 _outPathInfo(str, (Path *) node);
1325 WRITE_NODE_FIELD(tidquals);
1328 static void
1329 _outAppendPath(StringInfo str, AppendPath *node)
1331 WRITE_NODE_TYPE("APPENDPATH");
1333 _outPathInfo(str, (Path *) node);
1335 WRITE_NODE_FIELD(subpaths);
1338 static void
1339 _outResultPath(StringInfo str, ResultPath *node)
1341 WRITE_NODE_TYPE("RESULTPATH");
1343 _outPathInfo(str, (Path *) node);
1345 WRITE_NODE_FIELD(quals);
1348 static void
1349 _outMaterialPath(StringInfo str, MaterialPath *node)
1351 WRITE_NODE_TYPE("MATERIALPATH");
1353 _outPathInfo(str, (Path *) node);
1355 WRITE_NODE_FIELD(subpath);
1358 static void
1359 _outUniquePath(StringInfo str, UniquePath *node)
1361 WRITE_NODE_TYPE("UNIQUEPATH");
1363 _outPathInfo(str, (Path *) node);
1365 WRITE_NODE_FIELD(subpath);
1366 WRITE_ENUM_FIELD(umethod, UniquePathMethod);
1367 WRITE_NODE_FIELD(in_operators);
1368 WRITE_NODE_FIELD(uniq_exprs);
1369 WRITE_FLOAT_FIELD(rows, "%.0f");
1372 static void
1373 _outNestPath(StringInfo str, NestPath *node)
1375 WRITE_NODE_TYPE("NESTPATH");
1377 _outJoinPathInfo(str, (JoinPath *) node);
1380 static void
1381 _outMergePath(StringInfo str, MergePath *node)
1383 WRITE_NODE_TYPE("MERGEPATH");
1385 _outJoinPathInfo(str, (JoinPath *) node);
1387 WRITE_NODE_FIELD(path_mergeclauses);
1388 WRITE_NODE_FIELD(outersortkeys);
1389 WRITE_NODE_FIELD(innersortkeys);
1392 static void
1393 _outHashPath(StringInfo str, HashPath *node)
1395 WRITE_NODE_TYPE("HASHPATH");
1397 _outJoinPathInfo(str, (JoinPath *) node);
1399 WRITE_NODE_FIELD(path_hashclauses);
1402 static void
1403 _outPlannerGlobal(StringInfo str, PlannerGlobal *node)
1405 WRITE_NODE_TYPE("PLANNERGLOBAL");
1407 /* NB: this isn't a complete set of fields */
1408 WRITE_NODE_FIELD(paramlist);
1409 WRITE_NODE_FIELD(subplans);
1410 WRITE_NODE_FIELD(subrtables);
1411 WRITE_BITMAPSET_FIELD(rewindPlanIDs);
1412 WRITE_NODE_FIELD(finalrtable);
1413 WRITE_NODE_FIELD(relationOids);
1414 WRITE_NODE_FIELD(invalItems);
1415 WRITE_UINT_FIELD(lastPHId);
1416 WRITE_BOOL_FIELD(transientPlan);
1419 static void
1420 _outPlannerInfo(StringInfo str, PlannerInfo *node)
1422 WRITE_NODE_TYPE("PLANNERINFO");
1424 /* NB: this isn't a complete set of fields */
1425 WRITE_NODE_FIELD(parse);
1426 WRITE_NODE_FIELD(glob);
1427 WRITE_UINT_FIELD(query_level);
1428 WRITE_NODE_FIELD(join_rel_list);
1429 WRITE_NODE_FIELD(resultRelations);
1430 WRITE_NODE_FIELD(returningLists);
1431 WRITE_NODE_FIELD(init_plans);
1432 WRITE_NODE_FIELD(cte_plan_ids);
1433 WRITE_NODE_FIELD(eq_classes);
1434 WRITE_NODE_FIELD(canon_pathkeys);
1435 WRITE_NODE_FIELD(left_join_clauses);
1436 WRITE_NODE_FIELD(right_join_clauses);
1437 WRITE_NODE_FIELD(full_join_clauses);
1438 WRITE_NODE_FIELD(join_info_list);
1439 WRITE_NODE_FIELD(append_rel_list);
1440 WRITE_NODE_FIELD(placeholder_list);
1441 WRITE_NODE_FIELD(query_pathkeys);
1442 WRITE_NODE_FIELD(group_pathkeys);
1443 WRITE_NODE_FIELD(distinct_pathkeys);
1444 WRITE_NODE_FIELD(sort_pathkeys);
1445 WRITE_FLOAT_FIELD(total_table_pages, "%.0f");
1446 WRITE_FLOAT_FIELD(tuple_fraction, "%.4f");
1447 WRITE_BOOL_FIELD(hasJoinRTEs);
1448 WRITE_BOOL_FIELD(hasHavingQual);
1449 WRITE_BOOL_FIELD(hasPseudoConstantQuals);
1450 WRITE_BOOL_FIELD(hasRecursion);
1451 WRITE_INT_FIELD(wt_param_id);
1454 static void
1455 _outRelOptInfo(StringInfo str, RelOptInfo *node)
1457 WRITE_NODE_TYPE("RELOPTINFO");
1459 /* NB: this isn't a complete set of fields */
1460 WRITE_ENUM_FIELD(reloptkind, RelOptKind);
1461 WRITE_BITMAPSET_FIELD(relids);
1462 WRITE_FLOAT_FIELD(rows, "%.0f");
1463 WRITE_INT_FIELD(width);
1464 WRITE_NODE_FIELD(reltargetlist);
1465 WRITE_NODE_FIELD(pathlist);
1466 WRITE_NODE_FIELD(cheapest_startup_path);
1467 WRITE_NODE_FIELD(cheapest_total_path);
1468 WRITE_NODE_FIELD(cheapest_unique_path);
1469 WRITE_UINT_FIELD(relid);
1470 WRITE_ENUM_FIELD(rtekind, RTEKind);
1471 WRITE_INT_FIELD(min_attr);
1472 WRITE_INT_FIELD(max_attr);
1473 WRITE_NODE_FIELD(indexlist);
1474 WRITE_UINT_FIELD(pages);
1475 WRITE_FLOAT_FIELD(tuples, "%.0f");
1476 WRITE_NODE_FIELD(subplan);
1477 WRITE_NODE_FIELD(subrtable);
1478 WRITE_NODE_FIELD(baserestrictinfo);
1479 WRITE_NODE_FIELD(joininfo);
1480 WRITE_BOOL_FIELD(has_eclass_joins);
1481 WRITE_BITMAPSET_FIELD(index_outer_relids);
1482 WRITE_NODE_FIELD(index_inner_paths);
1485 static void
1486 _outIndexOptInfo(StringInfo str, IndexOptInfo *node)
1488 WRITE_NODE_TYPE("INDEXOPTINFO");
1490 /* NB: this isn't a complete set of fields */
1491 WRITE_OID_FIELD(indexoid);
1492 /* Do NOT print rel field, else infinite recursion */
1493 WRITE_UINT_FIELD(pages);
1494 WRITE_FLOAT_FIELD(tuples, "%.0f");
1495 WRITE_INT_FIELD(ncolumns);
1496 WRITE_NODE_FIELD(indexprs);
1497 WRITE_NODE_FIELD(indpred);
1498 WRITE_BOOL_FIELD(predOK);
1499 WRITE_BOOL_FIELD(unique);
1502 static void
1503 _outEquivalenceClass(StringInfo str, EquivalenceClass *node)
1506 * To simplify reading, we just chase up to the topmost merged EC and
1507 * print that, without bothering to show the merge-ees separately.
1509 while (node->ec_merged)
1510 node = node->ec_merged;
1512 WRITE_NODE_TYPE("EQUIVALENCECLASS");
1514 WRITE_NODE_FIELD(ec_opfamilies);
1515 WRITE_NODE_FIELD(ec_members);
1516 WRITE_NODE_FIELD(ec_sources);
1517 WRITE_NODE_FIELD(ec_derives);
1518 WRITE_BITMAPSET_FIELD(ec_relids);
1519 WRITE_BOOL_FIELD(ec_has_const);
1520 WRITE_BOOL_FIELD(ec_has_volatile);
1521 WRITE_BOOL_FIELD(ec_below_outer_join);
1522 WRITE_BOOL_FIELD(ec_broken);
1523 WRITE_UINT_FIELD(ec_sortref);
1526 static void
1527 _outEquivalenceMember(StringInfo str, EquivalenceMember *node)
1529 WRITE_NODE_TYPE("EQUIVALENCEMEMBER");
1531 WRITE_NODE_FIELD(em_expr);
1532 WRITE_BITMAPSET_FIELD(em_relids);
1533 WRITE_BOOL_FIELD(em_is_const);
1534 WRITE_BOOL_FIELD(em_is_child);
1535 WRITE_OID_FIELD(em_datatype);
1538 static void
1539 _outPathKey(StringInfo str, PathKey *node)
1541 WRITE_NODE_TYPE("PATHKEY");
1543 WRITE_NODE_FIELD(pk_eclass);
1544 WRITE_OID_FIELD(pk_opfamily);
1545 WRITE_INT_FIELD(pk_strategy);
1546 WRITE_BOOL_FIELD(pk_nulls_first);
1549 static void
1550 _outRestrictInfo(StringInfo str, RestrictInfo *node)
1552 WRITE_NODE_TYPE("RESTRICTINFO");
1554 /* NB: this isn't a complete set of fields */
1555 WRITE_NODE_FIELD(clause);
1556 WRITE_BOOL_FIELD(is_pushed_down);
1557 WRITE_BOOL_FIELD(outerjoin_delayed);
1558 WRITE_BOOL_FIELD(can_join);
1559 WRITE_BOOL_FIELD(pseudoconstant);
1560 WRITE_BITMAPSET_FIELD(clause_relids);
1561 WRITE_BITMAPSET_FIELD(required_relids);
1562 WRITE_BITMAPSET_FIELD(left_relids);
1563 WRITE_BITMAPSET_FIELD(right_relids);
1564 WRITE_NODE_FIELD(orclause);
1565 /* don't write parent_ec, leads to infinite recursion in plan tree dump */
1566 WRITE_NODE_FIELD(mergeopfamilies);
1567 /* don't write left_ec, leads to infinite recursion in plan tree dump */
1568 /* don't write right_ec, leads to infinite recursion in plan tree dump */
1569 WRITE_NODE_FIELD(left_em);
1570 WRITE_NODE_FIELD(right_em);
1571 WRITE_BOOL_FIELD(outer_is_left);
1572 WRITE_OID_FIELD(hashjoinoperator);
1575 static void
1576 _outInnerIndexscanInfo(StringInfo str, InnerIndexscanInfo *node)
1578 WRITE_NODE_TYPE("INNERINDEXSCANINFO");
1579 WRITE_BITMAPSET_FIELD(other_relids);
1580 WRITE_BOOL_FIELD(isouterjoin);
1581 WRITE_NODE_FIELD(cheapest_startup_innerpath);
1582 WRITE_NODE_FIELD(cheapest_total_innerpath);
1585 static void
1586 _outFlattenedSubLink(StringInfo str, FlattenedSubLink *node)
1588 WRITE_NODE_TYPE("FLATTENEDSUBLINK");
1590 WRITE_ENUM_FIELD(jointype, JoinType);
1591 WRITE_BITMAPSET_FIELD(lefthand);
1592 WRITE_BITMAPSET_FIELD(righthand);
1593 WRITE_NODE_FIELD(quals);
1596 static void
1597 _outPlaceHolderVar(StringInfo str, PlaceHolderVar *node)
1599 WRITE_NODE_TYPE("PLACEHOLDERVAR");
1601 WRITE_NODE_FIELD(phexpr);
1602 WRITE_BITMAPSET_FIELD(phrels);
1603 WRITE_UINT_FIELD(phid);
1604 WRITE_UINT_FIELD(phlevelsup);
1607 static void
1608 _outSpecialJoinInfo(StringInfo str, SpecialJoinInfo *node)
1610 WRITE_NODE_TYPE("SPECIALJOININFO");
1612 WRITE_BITMAPSET_FIELD(min_lefthand);
1613 WRITE_BITMAPSET_FIELD(min_righthand);
1614 WRITE_BITMAPSET_FIELD(syn_lefthand);
1615 WRITE_BITMAPSET_FIELD(syn_righthand);
1616 WRITE_ENUM_FIELD(jointype, JoinType);
1617 WRITE_BOOL_FIELD(lhs_strict);
1618 WRITE_BOOL_FIELD(delay_upper_joins);
1619 WRITE_NODE_FIELD(join_quals);
1622 static void
1623 _outAppendRelInfo(StringInfo str, AppendRelInfo *node)
1625 WRITE_NODE_TYPE("APPENDRELINFO");
1627 WRITE_UINT_FIELD(parent_relid);
1628 WRITE_UINT_FIELD(child_relid);
1629 WRITE_OID_FIELD(parent_reltype);
1630 WRITE_OID_FIELD(child_reltype);
1631 WRITE_NODE_FIELD(col_mappings);
1632 WRITE_NODE_FIELD(translated_vars);
1633 WRITE_OID_FIELD(parent_reloid);
1636 static void
1637 _outPlaceHolderInfo(StringInfo str, PlaceHolderInfo *node)
1639 WRITE_NODE_TYPE("PLACEHOLDERINFO");
1641 WRITE_UINT_FIELD(phid);
1642 WRITE_NODE_FIELD(ph_var);
1643 WRITE_BITMAPSET_FIELD(ph_eval_at);
1644 WRITE_BITMAPSET_FIELD(ph_needed);
1645 WRITE_INT_FIELD(ph_width);
1648 static void
1649 _outPlannerParamItem(StringInfo str, PlannerParamItem *node)
1651 WRITE_NODE_TYPE("PLANNERPARAMITEM");
1653 WRITE_NODE_FIELD(item);
1654 WRITE_UINT_FIELD(abslevel);
1657 /*****************************************************************************
1659 * Stuff from parsenodes.h.
1661 *****************************************************************************/
1663 static void
1664 _outCreateStmt(StringInfo str, CreateStmt *node)
1666 WRITE_NODE_TYPE("CREATESTMT");
1668 WRITE_NODE_FIELD(relation);
1669 WRITE_NODE_FIELD(tableElts);
1670 WRITE_NODE_FIELD(inhRelations);
1671 WRITE_NODE_FIELD(constraints);
1672 WRITE_NODE_FIELD(options);
1673 WRITE_ENUM_FIELD(oncommit, OnCommitAction);
1674 WRITE_STRING_FIELD(tablespacename);
1677 static void
1678 _outIndexStmt(StringInfo str, IndexStmt *node)
1680 WRITE_NODE_TYPE("INDEXSTMT");
1682 WRITE_STRING_FIELD(idxname);
1683 WRITE_NODE_FIELD(relation);
1684 WRITE_STRING_FIELD(accessMethod);
1685 WRITE_STRING_FIELD(tableSpace);
1686 WRITE_NODE_FIELD(indexParams);
1687 WRITE_NODE_FIELD(options);
1688 WRITE_NODE_FIELD(whereClause);
1689 WRITE_BOOL_FIELD(unique);
1690 WRITE_BOOL_FIELD(primary);
1691 WRITE_BOOL_FIELD(isconstraint);
1692 WRITE_BOOL_FIELD(concurrent);
1695 static void
1696 _outNotifyStmt(StringInfo str, NotifyStmt *node)
1698 WRITE_NODE_TYPE("NOTIFY");
1700 WRITE_STRING_FIELD(conditionname);
1703 static void
1704 _outDeclareCursorStmt(StringInfo str, DeclareCursorStmt *node)
1706 WRITE_NODE_TYPE("DECLARECURSOR");
1708 WRITE_STRING_FIELD(portalname);
1709 WRITE_INT_FIELD(options);
1710 WRITE_NODE_FIELD(query);
1713 static void
1714 _outSelectStmt(StringInfo str, SelectStmt *node)
1716 WRITE_NODE_TYPE("SELECT");
1718 WRITE_NODE_FIELD(distinctClause);
1719 WRITE_NODE_FIELD(intoClause);
1720 WRITE_NODE_FIELD(targetList);
1721 WRITE_NODE_FIELD(fromClause);
1722 WRITE_NODE_FIELD(whereClause);
1723 WRITE_NODE_FIELD(groupClause);
1724 WRITE_NODE_FIELD(havingClause);
1725 WRITE_NODE_FIELD(withClause);
1726 WRITE_NODE_FIELD(valuesLists);
1727 WRITE_NODE_FIELD(sortClause);
1728 WRITE_NODE_FIELD(limitOffset);
1729 WRITE_NODE_FIELD(limitCount);
1730 WRITE_NODE_FIELD(lockingClause);
1731 WRITE_ENUM_FIELD(op, SetOperation);
1732 WRITE_BOOL_FIELD(all);
1733 WRITE_NODE_FIELD(larg);
1734 WRITE_NODE_FIELD(rarg);
1737 static void
1738 _outFuncCall(StringInfo str, FuncCall *node)
1740 WRITE_NODE_TYPE("FUNCCALL");
1742 WRITE_NODE_FIELD(funcname);
1743 WRITE_NODE_FIELD(args);
1744 WRITE_BOOL_FIELD(agg_star);
1745 WRITE_BOOL_FIELD(agg_distinct);
1746 WRITE_BOOL_FIELD(func_variadic);
1747 WRITE_LOCATION_FIELD(location);
1750 static void
1751 _outDefElem(StringInfo str, DefElem *node)
1753 WRITE_NODE_TYPE("DEFELEM");
1755 WRITE_STRING_FIELD(defname);
1756 WRITE_NODE_FIELD(arg);
1759 static void
1760 _outLockingClause(StringInfo str, LockingClause *node)
1762 WRITE_NODE_TYPE("LOCKINGCLAUSE");
1764 WRITE_NODE_FIELD(lockedRels);
1765 WRITE_BOOL_FIELD(forUpdate);
1766 WRITE_BOOL_FIELD(noWait);
1769 static void
1770 _outXmlSerialize(StringInfo str, XmlSerialize *node)
1772 WRITE_NODE_TYPE("XMLSERIALIZE");
1774 WRITE_ENUM_FIELD(xmloption, XmlOptionType);
1775 WRITE_NODE_FIELD(expr);
1776 WRITE_NODE_FIELD(typename);
1777 WRITE_LOCATION_FIELD(location);
1780 static void
1781 _outColumnDef(StringInfo str, ColumnDef *node)
1783 WRITE_NODE_TYPE("COLUMNDEF");
1785 WRITE_STRING_FIELD(colname);
1786 WRITE_NODE_FIELD(typename);
1787 WRITE_INT_FIELD(inhcount);
1788 WRITE_BOOL_FIELD(is_local);
1789 WRITE_BOOL_FIELD(is_not_null);
1790 WRITE_NODE_FIELD(raw_default);
1791 WRITE_STRING_FIELD(cooked_default);
1792 WRITE_NODE_FIELD(constraints);
1795 static void
1796 _outTypeName(StringInfo str, TypeName *node)
1798 WRITE_NODE_TYPE("TYPENAME");
1800 WRITE_NODE_FIELD(names);
1801 WRITE_OID_FIELD(typeid);
1802 WRITE_BOOL_FIELD(setof);
1803 WRITE_BOOL_FIELD(pct_type);
1804 WRITE_NODE_FIELD(typmods);
1805 WRITE_INT_FIELD(typemod);
1806 WRITE_NODE_FIELD(arrayBounds);
1807 WRITE_LOCATION_FIELD(location);
1810 static void
1811 _outTypeCast(StringInfo str, TypeCast *node)
1813 WRITE_NODE_TYPE("TYPECAST");
1815 WRITE_NODE_FIELD(arg);
1816 WRITE_NODE_FIELD(typename);
1817 WRITE_LOCATION_FIELD(location);
1820 static void
1821 _outIndexElem(StringInfo str, IndexElem *node)
1823 WRITE_NODE_TYPE("INDEXELEM");
1825 WRITE_STRING_FIELD(name);
1826 WRITE_NODE_FIELD(expr);
1827 WRITE_NODE_FIELD(opclass);
1828 WRITE_ENUM_FIELD(ordering, SortByDir);
1829 WRITE_ENUM_FIELD(nulls_ordering, SortByNulls);
1832 static void
1833 _outQuery(StringInfo str, Query *node)
1835 WRITE_NODE_TYPE("QUERY");
1837 WRITE_ENUM_FIELD(commandType, CmdType);
1838 WRITE_ENUM_FIELD(querySource, QuerySource);
1839 WRITE_BOOL_FIELD(canSetTag);
1842 * Hack to work around missing outfuncs routines for a lot of the
1843 * utility-statement node types. (The only one we actually *need* for
1844 * rules support is NotifyStmt.) Someday we ought to support 'em all, but
1845 * for the meantime do this to avoid getting lots of warnings when running
1846 * with debug_print_parse on.
1848 if (node->utilityStmt)
1850 switch (nodeTag(node->utilityStmt))
1852 case T_CreateStmt:
1853 case T_IndexStmt:
1854 case T_NotifyStmt:
1855 case T_DeclareCursorStmt:
1856 WRITE_NODE_FIELD(utilityStmt);
1857 break;
1858 default:
1859 appendStringInfo(str, " :utilityStmt ?");
1860 break;
1863 else
1864 appendStringInfo(str, " :utilityStmt <>");
1866 WRITE_INT_FIELD(resultRelation);
1867 WRITE_NODE_FIELD(intoClause);
1868 WRITE_BOOL_FIELD(hasAggs);
1869 WRITE_BOOL_FIELD(hasSubLinks);
1870 WRITE_BOOL_FIELD(hasDistinctOn);
1871 WRITE_BOOL_FIELD(hasRecursive);
1872 WRITE_NODE_FIELD(cteList);
1873 WRITE_NODE_FIELD(rtable);
1874 WRITE_NODE_FIELD(jointree);
1875 WRITE_NODE_FIELD(targetList);
1876 WRITE_NODE_FIELD(returningList);
1877 WRITE_NODE_FIELD(groupClause);
1878 WRITE_NODE_FIELD(havingQual);
1879 WRITE_NODE_FIELD(distinctClause);
1880 WRITE_NODE_FIELD(sortClause);
1881 WRITE_NODE_FIELD(limitOffset);
1882 WRITE_NODE_FIELD(limitCount);
1883 WRITE_NODE_FIELD(rowMarks);
1884 WRITE_NODE_FIELD(setOperations);
1887 static void
1888 _outSortGroupClause(StringInfo str, SortGroupClause *node)
1890 WRITE_NODE_TYPE("SORTGROUPCLAUSE");
1892 WRITE_UINT_FIELD(tleSortGroupRef);
1893 WRITE_OID_FIELD(eqop);
1894 WRITE_OID_FIELD(sortop);
1895 WRITE_BOOL_FIELD(nulls_first);
1898 static void
1899 _outRowMarkClause(StringInfo str, RowMarkClause *node)
1901 WRITE_NODE_TYPE("ROWMARKCLAUSE");
1903 WRITE_UINT_FIELD(rti);
1904 WRITE_BOOL_FIELD(forUpdate);
1905 WRITE_BOOL_FIELD(noWait);
1908 static void
1909 _outWithClause(StringInfo str, WithClause *node)
1911 WRITE_NODE_TYPE("WITHCLAUSE");
1913 WRITE_NODE_FIELD(ctes);
1914 WRITE_BOOL_FIELD(recursive);
1915 WRITE_LOCATION_FIELD(location);
1918 static void
1919 _outCommonTableExpr(StringInfo str, CommonTableExpr *node)
1921 WRITE_NODE_TYPE("COMMONTABLEEXPR");
1923 WRITE_STRING_FIELD(ctename);
1924 WRITE_NODE_FIELD(aliascolnames);
1925 WRITE_NODE_FIELD(ctequery);
1926 WRITE_LOCATION_FIELD(location);
1927 WRITE_BOOL_FIELD(cterecursive);
1928 WRITE_INT_FIELD(cterefcount);
1929 WRITE_NODE_FIELD(ctecolnames);
1930 WRITE_NODE_FIELD(ctecoltypes);
1931 WRITE_NODE_FIELD(ctecoltypmods);
1934 static void
1935 _outSetOperationStmt(StringInfo str, SetOperationStmt *node)
1937 WRITE_NODE_TYPE("SETOPERATIONSTMT");
1939 WRITE_ENUM_FIELD(op, SetOperation);
1940 WRITE_BOOL_FIELD(all);
1941 WRITE_NODE_FIELD(larg);
1942 WRITE_NODE_FIELD(rarg);
1943 WRITE_NODE_FIELD(colTypes);
1944 WRITE_NODE_FIELD(colTypmods);
1945 WRITE_NODE_FIELD(groupClauses);
1948 static void
1949 _outRangeTblEntry(StringInfo str, RangeTblEntry *node)
1951 WRITE_NODE_TYPE("RTE");
1953 /* put alias + eref first to make dump more legible */
1954 WRITE_NODE_FIELD(alias);
1955 WRITE_NODE_FIELD(eref);
1956 WRITE_ENUM_FIELD(rtekind, RTEKind);
1958 switch (node->rtekind)
1960 case RTE_RELATION:
1961 case RTE_SPECIAL:
1962 WRITE_OID_FIELD(relid);
1963 break;
1964 case RTE_SUBQUERY:
1965 WRITE_NODE_FIELD(subquery);
1966 break;
1967 case RTE_JOIN:
1968 WRITE_ENUM_FIELD(jointype, JoinType);
1969 WRITE_NODE_FIELD(joinaliasvars);
1970 break;
1971 case RTE_FUNCTION:
1972 WRITE_NODE_FIELD(funcexpr);
1973 WRITE_NODE_FIELD(funccoltypes);
1974 WRITE_NODE_FIELD(funccoltypmods);
1975 break;
1976 case RTE_VALUES:
1977 WRITE_NODE_FIELD(values_lists);
1978 break;
1979 case RTE_CTE:
1980 WRITE_STRING_FIELD(ctename);
1981 WRITE_UINT_FIELD(ctelevelsup);
1982 WRITE_BOOL_FIELD(self_reference);
1983 WRITE_NODE_FIELD(ctecoltypes);
1984 WRITE_NODE_FIELD(ctecoltypmods);
1985 break;
1986 default:
1987 elog(ERROR, "unrecognized RTE kind: %d", (int) node->rtekind);
1988 break;
1991 WRITE_BOOL_FIELD(inh);
1992 WRITE_BOOL_FIELD(inFromCl);
1993 WRITE_UINT_FIELD(requiredPerms);
1994 WRITE_OID_FIELD(checkAsUser);
1997 static void
1998 _outAExpr(StringInfo str, A_Expr *node)
2000 WRITE_NODE_TYPE("AEXPR");
2002 switch (node->kind)
2004 case AEXPR_OP:
2005 appendStringInfo(str, " ");
2006 WRITE_NODE_FIELD(name);
2007 break;
2008 case AEXPR_AND:
2009 appendStringInfo(str, " AND");
2010 break;
2011 case AEXPR_OR:
2012 appendStringInfo(str, " OR");
2013 break;
2014 case AEXPR_NOT:
2015 appendStringInfo(str, " NOT");
2016 break;
2017 case AEXPR_OP_ANY:
2018 appendStringInfo(str, " ");
2019 WRITE_NODE_FIELD(name);
2020 appendStringInfo(str, " ANY ");
2021 break;
2022 case AEXPR_OP_ALL:
2023 appendStringInfo(str, " ");
2024 WRITE_NODE_FIELD(name);
2025 appendStringInfo(str, " ALL ");
2026 break;
2027 case AEXPR_DISTINCT:
2028 appendStringInfo(str, " DISTINCT ");
2029 WRITE_NODE_FIELD(name);
2030 break;
2031 case AEXPR_NULLIF:
2032 appendStringInfo(str, " NULLIF ");
2033 WRITE_NODE_FIELD(name);
2034 break;
2035 case AEXPR_OF:
2036 appendStringInfo(str, " OF ");
2037 WRITE_NODE_FIELD(name);
2038 break;
2039 case AEXPR_IN:
2040 appendStringInfo(str, " IN ");
2041 WRITE_NODE_FIELD(name);
2042 break;
2043 default:
2044 appendStringInfo(str, " ??");
2045 break;
2048 WRITE_NODE_FIELD(lexpr);
2049 WRITE_NODE_FIELD(rexpr);
2050 WRITE_LOCATION_FIELD(location);
2053 static void
2054 _outValue(StringInfo str, Value *value)
2056 switch (value->type)
2058 case T_Integer:
2059 appendStringInfo(str, "%ld", value->val.ival);
2060 break;
2061 case T_Float:
2064 * We assume the value is a valid numeric literal and so does not
2065 * need quoting.
2067 appendStringInfoString(str, value->val.str);
2068 break;
2069 case T_String:
2070 appendStringInfoChar(str, '"');
2071 _outToken(str, value->val.str);
2072 appendStringInfoChar(str, '"');
2073 break;
2074 case T_BitString:
2075 /* internal representation already has leading 'b' */
2076 appendStringInfoString(str, value->val.str);
2077 break;
2078 case T_Null:
2079 /* this is seen only within A_Const, not in transformed trees */
2080 appendStringInfoString(str, "NULL");
2081 break;
2082 default:
2083 elog(ERROR, "unrecognized node type: %d", (int) value->type);
2084 break;
2088 static void
2089 _outColumnRef(StringInfo str, ColumnRef *node)
2091 WRITE_NODE_TYPE("COLUMNREF");
2093 WRITE_NODE_FIELD(fields);
2094 WRITE_LOCATION_FIELD(location);
2097 static void
2098 _outParamRef(StringInfo str, ParamRef *node)
2100 WRITE_NODE_TYPE("PARAMREF");
2102 WRITE_INT_FIELD(number);
2103 WRITE_LOCATION_FIELD(location);
2106 static void
2107 _outAConst(StringInfo str, A_Const *node)
2109 WRITE_NODE_TYPE("A_CONST");
2111 appendStringInfo(str, " :val ");
2112 _outValue(str, &(node->val));
2113 WRITE_LOCATION_FIELD(location);
2116 static void
2117 _outA_Star(StringInfo str, A_Star *node)
2119 WRITE_NODE_TYPE("A_STAR");
2122 static void
2123 _outA_Indices(StringInfo str, A_Indices *node)
2125 WRITE_NODE_TYPE("A_INDICES");
2127 WRITE_NODE_FIELD(lidx);
2128 WRITE_NODE_FIELD(uidx);
2131 static void
2132 _outA_Indirection(StringInfo str, A_Indirection *node)
2134 WRITE_NODE_TYPE("A_INDIRECTION");
2136 WRITE_NODE_FIELD(arg);
2137 WRITE_NODE_FIELD(indirection);
2140 static void
2141 _outA_ArrayExpr(StringInfo str, A_ArrayExpr *node)
2143 WRITE_NODE_TYPE("A_ARRAYEXPR");
2145 WRITE_NODE_FIELD(elements);
2146 WRITE_LOCATION_FIELD(location);
2149 static void
2150 _outResTarget(StringInfo str, ResTarget *node)
2152 WRITE_NODE_TYPE("RESTARGET");
2154 WRITE_STRING_FIELD(name);
2155 WRITE_NODE_FIELD(indirection);
2156 WRITE_NODE_FIELD(val);
2157 WRITE_LOCATION_FIELD(location);
2160 static void
2161 _outSortBy(StringInfo str, SortBy *node)
2163 WRITE_NODE_TYPE("SORTBY");
2165 WRITE_NODE_FIELD(node);
2166 WRITE_ENUM_FIELD(sortby_dir, SortByDir);
2167 WRITE_ENUM_FIELD(sortby_nulls, SortByNulls);
2168 WRITE_NODE_FIELD(useOp);
2169 WRITE_LOCATION_FIELD(location);
2172 static void
2173 _outRangeSubselect(StringInfo str, RangeSubselect *node)
2175 WRITE_NODE_TYPE("RANGESUBSELECT");
2177 WRITE_NODE_FIELD(subquery);
2178 WRITE_NODE_FIELD(alias);
2181 static void
2182 _outRangeFunction(StringInfo str, RangeFunction *node)
2184 WRITE_NODE_TYPE("RANGEFUNCTION");
2186 WRITE_NODE_FIELD(funccallnode);
2187 WRITE_NODE_FIELD(alias);
2188 WRITE_NODE_FIELD(coldeflist);
2191 static void
2192 _outConstraint(StringInfo str, Constraint *node)
2194 WRITE_NODE_TYPE("CONSTRAINT");
2196 WRITE_STRING_FIELD(name);
2198 appendStringInfo(str, " :contype ");
2199 switch (node->contype)
2201 case CONSTR_PRIMARY:
2202 appendStringInfo(str, "PRIMARY_KEY");
2203 WRITE_NODE_FIELD(keys);
2204 WRITE_NODE_FIELD(options);
2205 WRITE_STRING_FIELD(indexspace);
2206 break;
2208 case CONSTR_UNIQUE:
2209 appendStringInfo(str, "UNIQUE");
2210 WRITE_NODE_FIELD(keys);
2211 WRITE_NODE_FIELD(options);
2212 WRITE_STRING_FIELD(indexspace);
2213 break;
2215 case CONSTR_CHECK:
2216 appendStringInfo(str, "CHECK");
2217 WRITE_NODE_FIELD(raw_expr);
2218 WRITE_STRING_FIELD(cooked_expr);
2219 break;
2221 case CONSTR_DEFAULT:
2222 appendStringInfo(str, "DEFAULT");
2223 WRITE_NODE_FIELD(raw_expr);
2224 WRITE_STRING_FIELD(cooked_expr);
2225 break;
2227 case CONSTR_NOTNULL:
2228 appendStringInfo(str, "NOT_NULL");
2229 break;
2231 default:
2232 appendStringInfo(str, "<unrecognized_constraint>");
2233 break;
2237 static void
2238 _outFkConstraint(StringInfo str, FkConstraint *node)
2240 WRITE_NODE_TYPE("FKCONSTRAINT");
2242 WRITE_STRING_FIELD(constr_name);
2243 WRITE_NODE_FIELD(pktable);
2244 WRITE_NODE_FIELD(fk_attrs);
2245 WRITE_NODE_FIELD(pk_attrs);
2246 WRITE_CHAR_FIELD(fk_matchtype);
2247 WRITE_CHAR_FIELD(fk_upd_action);
2248 WRITE_CHAR_FIELD(fk_del_action);
2249 WRITE_BOOL_FIELD(deferrable);
2250 WRITE_BOOL_FIELD(initdeferred);
2251 WRITE_BOOL_FIELD(skip_validation);
2256 * _outNode -
2257 * converts a Node into ascii string and append it to 'str'
2259 static void
2260 _outNode(StringInfo str, void *obj)
2262 if (obj == NULL)
2263 appendStringInfo(str, "<>");
2264 else if (IsA(obj, List) ||IsA(obj, IntList) || IsA(obj, OidList))
2265 _outList(str, obj);
2266 else if (IsA(obj, Integer) ||
2267 IsA(obj, Float) ||
2268 IsA(obj, String) ||
2269 IsA(obj, BitString))
2271 /* nodeRead does not want to see { } around these! */
2272 _outValue(str, obj);
2274 else
2276 appendStringInfoChar(str, '{');
2277 switch (nodeTag(obj))
2279 case T_PlannedStmt:
2280 _outPlannedStmt(str, obj);
2281 break;
2282 case T_Plan:
2283 _outPlan(str, obj);
2284 break;
2285 case T_Result:
2286 _outResult(str, obj);
2287 break;
2288 case T_Append:
2289 _outAppend(str, obj);
2290 break;
2291 case T_RecursiveUnion:
2292 _outRecursiveUnion(str, obj);
2293 break;
2294 case T_BitmapAnd:
2295 _outBitmapAnd(str, obj);
2296 break;
2297 case T_BitmapOr:
2298 _outBitmapOr(str, obj);
2299 break;
2300 case T_Scan:
2301 _outScan(str, obj);
2302 break;
2303 case T_SeqScan:
2304 _outSeqScan(str, obj);
2305 break;
2306 case T_IndexScan:
2307 _outIndexScan(str, obj);
2308 break;
2309 case T_BitmapIndexScan:
2310 _outBitmapIndexScan(str, obj);
2311 break;
2312 case T_BitmapHeapScan:
2313 _outBitmapHeapScan(str, obj);
2314 break;
2315 case T_TidScan:
2316 _outTidScan(str, obj);
2317 break;
2318 case T_SubqueryScan:
2319 _outSubqueryScan(str, obj);
2320 break;
2321 case T_FunctionScan:
2322 _outFunctionScan(str, obj);
2323 break;
2324 case T_ValuesScan:
2325 _outValuesScan(str, obj);
2326 break;
2327 case T_CteScan:
2328 _outCteScan(str, obj);
2329 break;
2330 case T_WorkTableScan:
2331 _outWorkTableScan(str, obj);
2332 break;
2333 case T_Join:
2334 _outJoin(str, obj);
2335 break;
2336 case T_NestLoop:
2337 _outNestLoop(str, obj);
2338 break;
2339 case T_MergeJoin:
2340 _outMergeJoin(str, obj);
2341 break;
2342 case T_HashJoin:
2343 _outHashJoin(str, obj);
2344 break;
2345 case T_Agg:
2346 _outAgg(str, obj);
2347 break;
2348 case T_Group:
2349 _outGroup(str, obj);
2350 break;
2351 case T_Material:
2352 _outMaterial(str, obj);
2353 break;
2354 case T_Sort:
2355 _outSort(str, obj);
2356 break;
2357 case T_Unique:
2358 _outUnique(str, obj);
2359 break;
2360 case T_Hash:
2361 _outHash(str, obj);
2362 break;
2363 case T_SetOp:
2364 _outSetOp(str, obj);
2365 break;
2366 case T_Limit:
2367 _outLimit(str, obj);
2368 break;
2369 case T_PlanInvalItem:
2370 _outPlanInvalItem(str, obj);
2371 break;
2372 case T_Alias:
2373 _outAlias(str, obj);
2374 break;
2375 case T_RangeVar:
2376 _outRangeVar(str, obj);
2377 break;
2378 case T_IntoClause:
2379 _outIntoClause(str, obj);
2380 break;
2381 case T_Var:
2382 _outVar(str, obj);
2383 break;
2384 case T_Const:
2385 _outConst(str, obj);
2386 break;
2387 case T_Param:
2388 _outParam(str, obj);
2389 break;
2390 case T_Aggref:
2391 _outAggref(str, obj);
2392 break;
2393 case T_ArrayRef:
2394 _outArrayRef(str, obj);
2395 break;
2396 case T_FuncExpr:
2397 _outFuncExpr(str, obj);
2398 break;
2399 case T_OpExpr:
2400 _outOpExpr(str, obj);
2401 break;
2402 case T_DistinctExpr:
2403 _outDistinctExpr(str, obj);
2404 break;
2405 case T_ScalarArrayOpExpr:
2406 _outScalarArrayOpExpr(str, obj);
2407 break;
2408 case T_BoolExpr:
2409 _outBoolExpr(str, obj);
2410 break;
2411 case T_SubLink:
2412 _outSubLink(str, obj);
2413 break;
2414 case T_SubPlan:
2415 _outSubPlan(str, obj);
2416 break;
2417 case T_AlternativeSubPlan:
2418 _outAlternativeSubPlan(str, obj);
2419 break;
2420 case T_FieldSelect:
2421 _outFieldSelect(str, obj);
2422 break;
2423 case T_FieldStore:
2424 _outFieldStore(str, obj);
2425 break;
2426 case T_RelabelType:
2427 _outRelabelType(str, obj);
2428 break;
2429 case T_CoerceViaIO:
2430 _outCoerceViaIO(str, obj);
2431 break;
2432 case T_ArrayCoerceExpr:
2433 _outArrayCoerceExpr(str, obj);
2434 break;
2435 case T_ConvertRowtypeExpr:
2436 _outConvertRowtypeExpr(str, obj);
2437 break;
2438 case T_CaseExpr:
2439 _outCaseExpr(str, obj);
2440 break;
2441 case T_CaseWhen:
2442 _outCaseWhen(str, obj);
2443 break;
2444 case T_CaseTestExpr:
2445 _outCaseTestExpr(str, obj);
2446 break;
2447 case T_ArrayExpr:
2448 _outArrayExpr(str, obj);
2449 break;
2450 case T_RowExpr:
2451 _outRowExpr(str, obj);
2452 break;
2453 case T_RowCompareExpr:
2454 _outRowCompareExpr(str, obj);
2455 break;
2456 case T_CoalesceExpr:
2457 _outCoalesceExpr(str, obj);
2458 break;
2459 case T_MinMaxExpr:
2460 _outMinMaxExpr(str, obj);
2461 break;
2462 case T_XmlExpr:
2463 _outXmlExpr(str, obj);
2464 break;
2465 case T_NullIfExpr:
2466 _outNullIfExpr(str, obj);
2467 break;
2468 case T_NullTest:
2469 _outNullTest(str, obj);
2470 break;
2471 case T_BooleanTest:
2472 _outBooleanTest(str, obj);
2473 break;
2474 case T_CoerceToDomain:
2475 _outCoerceToDomain(str, obj);
2476 break;
2477 case T_CoerceToDomainValue:
2478 _outCoerceToDomainValue(str, obj);
2479 break;
2480 case T_SetToDefault:
2481 _outSetToDefault(str, obj);
2482 break;
2483 case T_CurrentOfExpr:
2484 _outCurrentOfExpr(str, obj);
2485 break;
2486 case T_TargetEntry:
2487 _outTargetEntry(str, obj);
2488 break;
2489 case T_RangeTblRef:
2490 _outRangeTblRef(str, obj);
2491 break;
2492 case T_JoinExpr:
2493 _outJoinExpr(str, obj);
2494 break;
2495 case T_FromExpr:
2496 _outFromExpr(str, obj);
2497 break;
2499 case T_Path:
2500 _outPath(str, obj);
2501 break;
2502 case T_IndexPath:
2503 _outIndexPath(str, obj);
2504 break;
2505 case T_BitmapHeapPath:
2506 _outBitmapHeapPath(str, obj);
2507 break;
2508 case T_BitmapAndPath:
2509 _outBitmapAndPath(str, obj);
2510 break;
2511 case T_BitmapOrPath:
2512 _outBitmapOrPath(str, obj);
2513 break;
2514 case T_TidPath:
2515 _outTidPath(str, obj);
2516 break;
2517 case T_AppendPath:
2518 _outAppendPath(str, obj);
2519 break;
2520 case T_ResultPath:
2521 _outResultPath(str, obj);
2522 break;
2523 case T_MaterialPath:
2524 _outMaterialPath(str, obj);
2525 break;
2526 case T_UniquePath:
2527 _outUniquePath(str, obj);
2528 break;
2529 case T_NestPath:
2530 _outNestPath(str, obj);
2531 break;
2532 case T_MergePath:
2533 _outMergePath(str, obj);
2534 break;
2535 case T_HashPath:
2536 _outHashPath(str, obj);
2537 break;
2538 case T_PlannerGlobal:
2539 _outPlannerGlobal(str, obj);
2540 break;
2541 case T_PlannerInfo:
2542 _outPlannerInfo(str, obj);
2543 break;
2544 case T_RelOptInfo:
2545 _outRelOptInfo(str, obj);
2546 break;
2547 case T_IndexOptInfo:
2548 _outIndexOptInfo(str, obj);
2549 break;
2550 case T_EquivalenceClass:
2551 _outEquivalenceClass(str, obj);
2552 break;
2553 case T_EquivalenceMember:
2554 _outEquivalenceMember(str, obj);
2555 break;
2556 case T_PathKey:
2557 _outPathKey(str, obj);
2558 break;
2559 case T_RestrictInfo:
2560 _outRestrictInfo(str, obj);
2561 break;
2562 case T_InnerIndexscanInfo:
2563 _outInnerIndexscanInfo(str, obj);
2564 break;
2565 case T_FlattenedSubLink:
2566 _outFlattenedSubLink(str, obj);
2567 break;
2568 case T_PlaceHolderVar:
2569 _outPlaceHolderVar(str, obj);
2570 break;
2571 case T_SpecialJoinInfo:
2572 _outSpecialJoinInfo(str, obj);
2573 break;
2574 case T_AppendRelInfo:
2575 _outAppendRelInfo(str, obj);
2576 break;
2577 case T_PlaceHolderInfo:
2578 _outPlaceHolderInfo(str, obj);
2579 break;
2580 case T_PlannerParamItem:
2581 _outPlannerParamItem(str, obj);
2582 break;
2584 case T_CreateStmt:
2585 _outCreateStmt(str, obj);
2586 break;
2587 case T_IndexStmt:
2588 _outIndexStmt(str, obj);
2589 break;
2590 case T_NotifyStmt:
2591 _outNotifyStmt(str, obj);
2592 break;
2593 case T_DeclareCursorStmt:
2594 _outDeclareCursorStmt(str, obj);
2595 break;
2596 case T_SelectStmt:
2597 _outSelectStmt(str, obj);
2598 break;
2599 case T_ColumnDef:
2600 _outColumnDef(str, obj);
2601 break;
2602 case T_TypeName:
2603 _outTypeName(str, obj);
2604 break;
2605 case T_TypeCast:
2606 _outTypeCast(str, obj);
2607 break;
2608 case T_IndexElem:
2609 _outIndexElem(str, obj);
2610 break;
2611 case T_Query:
2612 _outQuery(str, obj);
2613 break;
2614 case T_SortGroupClause:
2615 _outSortGroupClause(str, obj);
2616 break;
2617 case T_RowMarkClause:
2618 _outRowMarkClause(str, obj);
2619 break;
2620 case T_WithClause:
2621 _outWithClause(str, obj);
2622 break;
2623 case T_CommonTableExpr:
2624 _outCommonTableExpr(str, obj);
2625 break;
2626 case T_SetOperationStmt:
2627 _outSetOperationStmt(str, obj);
2628 break;
2629 case T_RangeTblEntry:
2630 _outRangeTblEntry(str, obj);
2631 break;
2632 case T_A_Expr:
2633 _outAExpr(str, obj);
2634 break;
2635 case T_ColumnRef:
2636 _outColumnRef(str, obj);
2637 break;
2638 case T_ParamRef:
2639 _outParamRef(str, obj);
2640 break;
2641 case T_A_Const:
2642 _outAConst(str, obj);
2643 break;
2644 case T_A_Star:
2645 _outA_Star(str, obj);
2646 break;
2647 case T_A_Indices:
2648 _outA_Indices(str, obj);
2649 break;
2650 case T_A_Indirection:
2651 _outA_Indirection(str, obj);
2652 break;
2653 case T_A_ArrayExpr:
2654 _outA_ArrayExpr(str, obj);
2655 break;
2656 case T_ResTarget:
2657 _outResTarget(str, obj);
2658 break;
2659 case T_SortBy:
2660 _outSortBy(str, obj);
2661 break;
2662 case T_RangeSubselect:
2663 _outRangeSubselect(str, obj);
2664 break;
2665 case T_RangeFunction:
2666 _outRangeFunction(str, obj);
2667 break;
2668 case T_Constraint:
2669 _outConstraint(str, obj);
2670 break;
2671 case T_FkConstraint:
2672 _outFkConstraint(str, obj);
2673 break;
2674 case T_FuncCall:
2675 _outFuncCall(str, obj);
2676 break;
2677 case T_DefElem:
2678 _outDefElem(str, obj);
2679 break;
2680 case T_LockingClause:
2681 _outLockingClause(str, obj);
2682 break;
2683 case T_XmlSerialize:
2684 _outXmlSerialize(str, obj);
2685 break;
2687 default:
2690 * This should be an ERROR, but it's too useful to be able to
2691 * dump structures that _outNode only understands part of.
2693 elog(WARNING, "could not dump unrecognized node type: %d",
2694 (int) nodeTag(obj));
2695 break;
2697 appendStringInfoChar(str, '}');
2702 * nodeToString -
2703 * returns the ascii representation of the Node as a palloc'd string
2705 char *
2706 nodeToString(void *obj)
2708 StringInfoData str;
2710 /* see stringinfo.h for an explanation of this maneuver */
2711 initStringInfo(&str);
2712 _outNode(&str, obj);
2713 return str.data;