1 /*-------------------------------------------------------------------------
4 * Output functions for Postgres tree nodes.
6 * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.310 2007/06/11 01:16:22 tgl Exp $
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 *-------------------------------------------------------------------------
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
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", \
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 Node field */
83 #define WRITE_NODE_FIELD(fldname) \
84 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
85 _outNode(str, node->fldname))
87 /* Write a bitmapset field */
88 #define WRITE_BITMAPSET_FIELD(fldname) \
89 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
90 _outBitmapset(str, node->fldname))
93 #define booltostr(x) ((x) ? "true" : "false")
95 static void _outNode(StringInfo str, void *obj);
100 * Convert an ordinary string (eg, an identifier) into a form that
101 * will be decoded back to a plain token by read.c's functions.
103 * If a null or empty string is given, it is encoded as "<>".
106 _outToken(StringInfo str, char *s)
108 if (s == NULL || *s == '\0')
110 appendStringInfo(str, "<>");
115 * Look for characters or patterns that are treated specially by read.c
116 * (either in pg_strtok() or in nodeRead()), and therefore need a
117 * protective backslash.
119 /* These characters only need to be quoted at the start of the string */
122 isdigit((unsigned char) *s) ||
123 ((*s == '+' || *s == '-') &&
124 (isdigit((unsigned char) s[1]) || s[1] == '.')))
125 appendStringInfoChar(str, '\\');
128 /* These chars must be backslashed anywhere in the string */
129 if (*s == ' ' || *s == '\n' || *s == '\t' ||
130 *s == '(' || *s == ')' || *s == '{' || *s == '}' ||
132 appendStringInfoChar(str, '\\');
133 appendStringInfoChar(str, *s++);
138 _outList(StringInfo str, List *node)
142 appendStringInfoChar(str, '(');
144 if (IsA(node, IntList))
145 appendStringInfoChar(str, 'i');
146 else if (IsA(node, OidList))
147 appendStringInfoChar(str, 'o');
152 * For the sake of backward compatibility, we emit a slightly
153 * different whitespace format for lists of nodes vs. other types of
154 * lists. XXX: is this necessary?
158 _outNode(str, lfirst(lc));
160 appendStringInfoChar(str, ' ');
162 else if (IsA(node, IntList))
163 appendStringInfo(str, " %d", lfirst_int(lc));
164 else if (IsA(node, OidList))
165 appendStringInfo(str, " %u", lfirst_oid(lc));
167 elog(ERROR, "unrecognized list node type: %d",
171 appendStringInfoChar(str, ')');
176 * converts a bitmap set of integers
178 * Note: the output format is "(b int int ...)", similar to an integer List.
179 * Currently bitmapsets do not appear in any node type that is stored in
180 * rules, so there is no support in readfuncs.c for reading this format.
183 _outBitmapset(StringInfo str, Bitmapset *bms)
188 appendStringInfoChar(str, '(');
189 appendStringInfoChar(str, 'b');
190 tmpset = bms_copy(bms);
191 while ((x = bms_first_member(tmpset)) >= 0)
192 appendStringInfo(str, " %d", x);
194 appendStringInfoChar(str, ')');
198 * Print the value of a Datum given its type.
201 _outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
207 length = datumGetSize(value, typbyval, typlen);
211 s = (char *) (&value);
212 appendStringInfo(str, "%u [ ", (unsigned int) length);
213 for (i = 0; i < (Size) sizeof(Datum); i++)
214 appendStringInfo(str, "%d ", (int) (s[i]));
215 appendStringInfo(str, "]");
219 s = (char *) DatumGetPointer(value);
220 if (!PointerIsValid(s))
221 appendStringInfo(str, "0 [ ]");
224 appendStringInfo(str, "%u [ ", (unsigned int) length);
225 for (i = 0; i < length; i++)
226 appendStringInfo(str, "%d ", (int) (s[i]));
227 appendStringInfo(str, "]");
234 * Stuff from plannodes.h
238 _outPlannedStmt(StringInfo str, PlannedStmt *node)
240 WRITE_NODE_TYPE("PLANNEDSTMT");
242 WRITE_ENUM_FIELD(commandType, CmdType);
243 WRITE_BOOL_FIELD(canSetTag);
244 WRITE_NODE_FIELD(planTree);
245 WRITE_NODE_FIELD(rtable);
246 WRITE_NODE_FIELD(resultRelations);
247 WRITE_NODE_FIELD(utilityStmt);
248 WRITE_NODE_FIELD(intoClause);
249 WRITE_NODE_FIELD(subplans);
250 WRITE_BITMAPSET_FIELD(rewindPlanIDs);
251 WRITE_NODE_FIELD(returningLists);
252 WRITE_NODE_FIELD(rowMarks);
253 WRITE_INT_FIELD(nParamExec);
257 * print the basic stuff of all nodes that inherit from Plan
260 _outPlanInfo(StringInfo str, Plan *node)
262 WRITE_FLOAT_FIELD(startup_cost, "%.2f");
263 WRITE_FLOAT_FIELD(total_cost, "%.2f");
264 WRITE_FLOAT_FIELD(plan_rows, "%.0f");
265 WRITE_INT_FIELD(plan_width);
266 WRITE_NODE_FIELD(targetlist);
267 WRITE_NODE_FIELD(qual);
268 WRITE_NODE_FIELD(lefttree);
269 WRITE_NODE_FIELD(righttree);
270 WRITE_NODE_FIELD(initPlan);
271 WRITE_BITMAPSET_FIELD(extParam);
272 WRITE_BITMAPSET_FIELD(allParam);
276 * print the basic stuff of all nodes that inherit from Scan
279 _outScanInfo(StringInfo str, Scan *node)
281 _outPlanInfo(str, (Plan *) node);
283 WRITE_UINT_FIELD(scanrelid);
287 * print the basic stuff of all nodes that inherit from Join
290 _outJoinPlanInfo(StringInfo str, Join *node)
292 _outPlanInfo(str, (Plan *) node);
294 WRITE_ENUM_FIELD(jointype, JoinType);
295 WRITE_NODE_FIELD(joinqual);
300 _outPlan(StringInfo str, Plan *node)
302 WRITE_NODE_TYPE("PLAN");
304 _outPlanInfo(str, (Plan *) node);
308 _outResult(StringInfo str, Result *node)
310 WRITE_NODE_TYPE("RESULT");
312 _outPlanInfo(str, (Plan *) node);
314 WRITE_NODE_FIELD(resconstantqual);
318 _outAppend(StringInfo str, Append *node)
320 WRITE_NODE_TYPE("APPEND");
322 _outPlanInfo(str, (Plan *) node);
324 WRITE_NODE_FIELD(appendplans);
325 WRITE_BOOL_FIELD(isTarget);
329 _outBitmapAnd(StringInfo str, BitmapAnd *node)
331 WRITE_NODE_TYPE("BITMAPAND");
333 _outPlanInfo(str, (Plan *) node);
335 WRITE_NODE_FIELD(bitmapplans);
339 _outBitmapOr(StringInfo str, BitmapOr *node)
341 WRITE_NODE_TYPE("BITMAPOR");
343 _outPlanInfo(str, (Plan *) node);
345 WRITE_NODE_FIELD(bitmapplans);
349 _outScan(StringInfo str, Scan *node)
351 WRITE_NODE_TYPE("SCAN");
353 _outScanInfo(str, (Scan *) node);
357 _outSeqScan(StringInfo str, SeqScan *node)
359 WRITE_NODE_TYPE("SEQSCAN");
361 _outScanInfo(str, (Scan *) node);
365 _outIndexScan(StringInfo str, IndexScan *node)
367 WRITE_NODE_TYPE("INDEXSCAN");
369 _outScanInfo(str, (Scan *) node);
371 WRITE_OID_FIELD(indexid);
372 WRITE_NODE_FIELD(indexqual);
373 WRITE_NODE_FIELD(indexqualorig);
374 WRITE_NODE_FIELD(indexstrategy);
375 WRITE_NODE_FIELD(indexsubtype);
376 WRITE_ENUM_FIELD(indexorderdir, ScanDirection);
380 _outBitmapIndexScan(StringInfo str, BitmapIndexScan *node)
382 WRITE_NODE_TYPE("BITMAPINDEXSCAN");
384 _outScanInfo(str, (Scan *) node);
386 WRITE_OID_FIELD(indexid);
387 WRITE_NODE_FIELD(indexqual);
388 WRITE_NODE_FIELD(indexqualorig);
389 WRITE_NODE_FIELD(indexstrategy);
390 WRITE_NODE_FIELD(indexsubtype);
394 _outBitmapHeapScan(StringInfo str, BitmapHeapScan *node)
396 WRITE_NODE_TYPE("BITMAPHEAPSCAN");
398 _outScanInfo(str, (Scan *) node);
400 WRITE_NODE_FIELD(bitmapqualorig);
404 _outTidScan(StringInfo str, TidScan *node)
406 WRITE_NODE_TYPE("TIDSCAN");
408 _outScanInfo(str, (Scan *) node);
410 WRITE_NODE_FIELD(tidquals);
414 _outSubqueryScan(StringInfo str, SubqueryScan *node)
416 WRITE_NODE_TYPE("SUBQUERYSCAN");
418 _outScanInfo(str, (Scan *) node);
420 WRITE_NODE_FIELD(subplan);
421 WRITE_NODE_FIELD(subrtable);
425 _outFunctionScan(StringInfo str, FunctionScan *node)
427 WRITE_NODE_TYPE("FUNCTIONSCAN");
429 _outScanInfo(str, (Scan *) node);
431 WRITE_NODE_FIELD(funcexpr);
432 WRITE_NODE_FIELD(funccolnames);
433 WRITE_NODE_FIELD(funccoltypes);
434 WRITE_NODE_FIELD(funccoltypmods);
438 _outValuesScan(StringInfo str, ValuesScan *node)
440 WRITE_NODE_TYPE("VALUESSCAN");
442 _outScanInfo(str, (Scan *) node);
444 WRITE_NODE_FIELD(values_lists);
448 _outJoin(StringInfo str, Join *node)
450 WRITE_NODE_TYPE("JOIN");
452 _outJoinPlanInfo(str, (Join *) node);
456 _outNestLoop(StringInfo str, NestLoop *node)
458 WRITE_NODE_TYPE("NESTLOOP");
460 _outJoinPlanInfo(str, (Join *) node);
464 _outMergeJoin(StringInfo str, MergeJoin *node)
469 WRITE_NODE_TYPE("MERGEJOIN");
471 _outJoinPlanInfo(str, (Join *) node);
473 WRITE_NODE_FIELD(mergeclauses);
475 numCols = list_length(node->mergeclauses);
477 appendStringInfo(str, " :mergeFamilies");
478 for (i = 0; i < numCols; i++)
479 appendStringInfo(str, " %u", node->mergeFamilies[i]);
481 appendStringInfo(str, " :mergeStrategies");
482 for (i = 0; i < numCols; i++)
483 appendStringInfo(str, " %d", node->mergeStrategies[i]);
485 appendStringInfo(str, " :mergeNullsFirst");
486 for (i = 0; i < numCols; i++)
487 appendStringInfo(str, " %d", (int) node->mergeNullsFirst[i]);
491 _outHashJoin(StringInfo str, HashJoin *node)
493 WRITE_NODE_TYPE("HASHJOIN");
495 _outJoinPlanInfo(str, (Join *) node);
497 WRITE_NODE_FIELD(hashclauses);
501 _outAgg(StringInfo str, Agg *node)
503 WRITE_NODE_TYPE("AGG");
505 _outPlanInfo(str, (Plan *) node);
507 WRITE_ENUM_FIELD(aggstrategy, AggStrategy);
508 WRITE_INT_FIELD(numCols);
509 WRITE_LONG_FIELD(numGroups);
513 _outGroup(StringInfo str, Group *node)
517 WRITE_NODE_TYPE("GROUP");
519 _outPlanInfo(str, (Plan *) node);
521 WRITE_INT_FIELD(numCols);
523 appendStringInfo(str, " :grpColIdx");
524 for (i = 0; i < node->numCols; i++)
525 appendStringInfo(str, " %d", node->grpColIdx[i]);
527 appendStringInfo(str, " :grpOperators");
528 for (i = 0; i < node->numCols; i++)
529 appendStringInfo(str, " %u", node->grpOperators[i]);
533 _outMaterial(StringInfo str, Material *node)
535 WRITE_NODE_TYPE("MATERIAL");
537 _outPlanInfo(str, (Plan *) node);
541 _outSort(StringInfo str, Sort *node)
545 WRITE_NODE_TYPE("SORT");
547 _outPlanInfo(str, (Plan *) node);
549 WRITE_INT_FIELD(numCols);
551 appendStringInfo(str, " :sortColIdx");
552 for (i = 0; i < node->numCols; i++)
553 appendStringInfo(str, " %d", node->sortColIdx[i]);
555 appendStringInfo(str, " :sortOperators");
556 for (i = 0; i < node->numCols; i++)
557 appendStringInfo(str, " %u", node->sortOperators[i]);
559 appendStringInfo(str, " :nullsFirst");
560 for (i = 0; i < node->numCols; i++)
561 appendStringInfo(str, " %s", booltostr(node->nullsFirst[i]));
565 _outUnique(StringInfo str, Unique *node)
569 WRITE_NODE_TYPE("UNIQUE");
571 _outPlanInfo(str, (Plan *) node);
573 WRITE_INT_FIELD(numCols);
575 appendStringInfo(str, " :uniqColIdx");
576 for (i = 0; i < node->numCols; i++)
577 appendStringInfo(str, " %d", node->uniqColIdx[i]);
579 appendStringInfo(str, " :uniqOperators");
580 for (i = 0; i < node->numCols; i++)
581 appendStringInfo(str, " %u", node->uniqOperators[i]);
585 _outSetOp(StringInfo str, SetOp *node)
589 WRITE_NODE_TYPE("SETOP");
591 _outPlanInfo(str, (Plan *) node);
593 WRITE_ENUM_FIELD(cmd, SetOpCmd);
594 WRITE_INT_FIELD(numCols);
596 appendStringInfo(str, " :dupColIdx");
597 for (i = 0; i < node->numCols; i++)
598 appendStringInfo(str, " %d", node->dupColIdx[i]);
600 appendStringInfo(str, " :dupOperators");
601 for (i = 0; i < node->numCols; i++)
602 appendStringInfo(str, " %d", node->dupOperators[i]);
604 WRITE_INT_FIELD(flagColIdx);
608 _outLimit(StringInfo str, Limit *node)
610 WRITE_NODE_TYPE("LIMIT");
612 _outPlanInfo(str, (Plan *) node);
614 WRITE_NODE_FIELD(limitOffset);
615 WRITE_NODE_FIELD(limitCount);
619 _outHash(StringInfo str, Hash *node)
621 WRITE_NODE_TYPE("HASH");
623 _outPlanInfo(str, (Plan *) node);
626 /*****************************************************************************
628 * Stuff from primnodes.h.
630 *****************************************************************************/
633 _outAlias(StringInfo str, Alias *node)
635 WRITE_NODE_TYPE("ALIAS");
637 WRITE_STRING_FIELD(aliasname);
638 WRITE_NODE_FIELD(colnames);
642 _outRangeVar(StringInfo str, RangeVar *node)
644 WRITE_NODE_TYPE("RANGEVAR");
647 * we deliberately ignore catalogname here, since it is presently not
648 * semantically meaningful
650 WRITE_STRING_FIELD(schemaname);
651 WRITE_STRING_FIELD(relname);
652 WRITE_ENUM_FIELD(inhOpt, InhOption);
653 WRITE_BOOL_FIELD(istemp);
654 WRITE_NODE_FIELD(alias);
658 _outIntoClause(StringInfo str, IntoClause *node)
660 WRITE_NODE_TYPE("INTOCLAUSE");
662 WRITE_NODE_FIELD(rel);
663 WRITE_NODE_FIELD(colNames);
664 WRITE_NODE_FIELD(options);
665 WRITE_ENUM_FIELD(onCommit, OnCommitAction);
666 WRITE_STRING_FIELD(tableSpaceName);
670 _outVar(StringInfo str, Var *node)
672 WRITE_NODE_TYPE("VAR");
674 WRITE_UINT_FIELD(varno);
675 WRITE_INT_FIELD(varattno);
676 WRITE_OID_FIELD(vartype);
677 WRITE_INT_FIELD(vartypmod);
678 WRITE_UINT_FIELD(varlevelsup);
679 WRITE_UINT_FIELD(varnoold);
680 WRITE_INT_FIELD(varoattno);
684 _outConst(StringInfo str, Const *node)
686 WRITE_NODE_TYPE("CONST");
688 WRITE_OID_FIELD(consttype);
689 WRITE_INT_FIELD(consttypmod);
690 WRITE_INT_FIELD(constlen);
691 WRITE_BOOL_FIELD(constbyval);
692 WRITE_BOOL_FIELD(constisnull);
694 appendStringInfo(str, " :constvalue ");
695 if (node->constisnull)
696 appendStringInfo(str, "<>");
698 _outDatum(str, node->constvalue, node->constlen, node->constbyval);
702 _outParam(StringInfo str, Param *node)
704 WRITE_NODE_TYPE("PARAM");
706 WRITE_ENUM_FIELD(paramkind, ParamKind);
707 WRITE_INT_FIELD(paramid);
708 WRITE_OID_FIELD(paramtype);
709 WRITE_INT_FIELD(paramtypmod);
713 _outAggref(StringInfo str, Aggref *node)
715 WRITE_NODE_TYPE("AGGREF");
717 WRITE_OID_FIELD(aggfnoid);
718 WRITE_OID_FIELD(aggtype);
719 WRITE_NODE_FIELD(args);
720 WRITE_UINT_FIELD(agglevelsup);
721 WRITE_BOOL_FIELD(aggstar);
722 WRITE_BOOL_FIELD(aggdistinct);
726 _outArrayRef(StringInfo str, ArrayRef *node)
728 WRITE_NODE_TYPE("ARRAYREF");
730 WRITE_OID_FIELD(refarraytype);
731 WRITE_OID_FIELD(refelemtype);
732 WRITE_INT_FIELD(reftypmod);
733 WRITE_NODE_FIELD(refupperindexpr);
734 WRITE_NODE_FIELD(reflowerindexpr);
735 WRITE_NODE_FIELD(refexpr);
736 WRITE_NODE_FIELD(refassgnexpr);
740 _outFuncExpr(StringInfo str, FuncExpr *node)
742 WRITE_NODE_TYPE("FUNCEXPR");
744 WRITE_OID_FIELD(funcid);
745 WRITE_OID_FIELD(funcresulttype);
746 WRITE_BOOL_FIELD(funcretset);
747 WRITE_ENUM_FIELD(funcformat, CoercionForm);
748 WRITE_NODE_FIELD(args);
752 _outOpExpr(StringInfo str, OpExpr *node)
754 WRITE_NODE_TYPE("OPEXPR");
756 WRITE_OID_FIELD(opno);
757 WRITE_OID_FIELD(opfuncid);
758 WRITE_OID_FIELD(opresulttype);
759 WRITE_BOOL_FIELD(opretset);
760 WRITE_NODE_FIELD(args);
764 _outDistinctExpr(StringInfo str, DistinctExpr *node)
766 WRITE_NODE_TYPE("DISTINCTEXPR");
768 WRITE_OID_FIELD(opno);
769 WRITE_OID_FIELD(opfuncid);
770 WRITE_OID_FIELD(opresulttype);
771 WRITE_BOOL_FIELD(opretset);
772 WRITE_NODE_FIELD(args);
776 _outScalarArrayOpExpr(StringInfo str, ScalarArrayOpExpr *node)
778 WRITE_NODE_TYPE("SCALARARRAYOPEXPR");
780 WRITE_OID_FIELD(opno);
781 WRITE_OID_FIELD(opfuncid);
782 WRITE_BOOL_FIELD(useOr);
783 WRITE_NODE_FIELD(args);
787 _outBoolExpr(StringInfo str, BoolExpr *node)
791 WRITE_NODE_TYPE("BOOLEXPR");
793 /* do-it-yourself enum representation */
794 switch (node->boolop)
806 appendStringInfo(str, " :boolop ");
807 _outToken(str, opstr);
809 WRITE_NODE_FIELD(args);
813 _outSubLink(StringInfo str, SubLink *node)
815 WRITE_NODE_TYPE("SUBLINK");
817 WRITE_ENUM_FIELD(subLinkType, SubLinkType);
818 WRITE_NODE_FIELD(testexpr);
819 WRITE_NODE_FIELD(operName);
820 WRITE_NODE_FIELD(subselect);
824 _outSubPlan(StringInfo str, SubPlan *node)
826 WRITE_NODE_TYPE("SUBPLAN");
828 WRITE_ENUM_FIELD(subLinkType, SubLinkType);
829 WRITE_NODE_FIELD(testexpr);
830 WRITE_NODE_FIELD(paramIds);
831 WRITE_INT_FIELD(plan_id);
832 WRITE_OID_FIELD(firstColType);
833 WRITE_BOOL_FIELD(useHashTable);
834 WRITE_BOOL_FIELD(unknownEqFalse);
835 WRITE_NODE_FIELD(setParam);
836 WRITE_NODE_FIELD(parParam);
837 WRITE_NODE_FIELD(args);
841 _outFieldSelect(StringInfo str, FieldSelect *node)
843 WRITE_NODE_TYPE("FIELDSELECT");
845 WRITE_NODE_FIELD(arg);
846 WRITE_INT_FIELD(fieldnum);
847 WRITE_OID_FIELD(resulttype);
848 WRITE_INT_FIELD(resulttypmod);
852 _outFieldStore(StringInfo str, FieldStore *node)
854 WRITE_NODE_TYPE("FIELDSTORE");
856 WRITE_NODE_FIELD(arg);
857 WRITE_NODE_FIELD(newvals);
858 WRITE_NODE_FIELD(fieldnums);
859 WRITE_OID_FIELD(resulttype);
863 _outRelabelType(StringInfo str, RelabelType *node)
865 WRITE_NODE_TYPE("RELABELTYPE");
867 WRITE_NODE_FIELD(arg);
868 WRITE_OID_FIELD(resulttype);
869 WRITE_INT_FIELD(resulttypmod);
870 WRITE_ENUM_FIELD(relabelformat, CoercionForm);
874 _outCoerceViaIO(StringInfo str, CoerceViaIO *node)
876 WRITE_NODE_TYPE("COERCEVIAIO");
878 WRITE_NODE_FIELD(arg);
879 WRITE_OID_FIELD(resulttype);
880 WRITE_ENUM_FIELD(coerceformat, CoercionForm);
884 _outArrayCoerceExpr(StringInfo str, ArrayCoerceExpr *node)
886 WRITE_NODE_TYPE("ARRAYCOERCEEXPR");
888 WRITE_NODE_FIELD(arg);
889 WRITE_OID_FIELD(elemfuncid);
890 WRITE_OID_FIELD(resulttype);
891 WRITE_INT_FIELD(resulttypmod);
892 WRITE_BOOL_FIELD(isExplicit);
893 WRITE_ENUM_FIELD(coerceformat, CoercionForm);
897 _outConvertRowtypeExpr(StringInfo str, ConvertRowtypeExpr *node)
899 WRITE_NODE_TYPE("CONVERTROWTYPEEXPR");
901 WRITE_NODE_FIELD(arg);
902 WRITE_OID_FIELD(resulttype);
903 WRITE_ENUM_FIELD(convertformat, CoercionForm);
907 _outCaseExpr(StringInfo str, CaseExpr *node)
909 WRITE_NODE_TYPE("CASE");
911 WRITE_OID_FIELD(casetype);
912 WRITE_NODE_FIELD(arg);
913 WRITE_NODE_FIELD(args);
914 WRITE_NODE_FIELD(defresult);
918 _outCaseWhen(StringInfo str, CaseWhen *node)
920 WRITE_NODE_TYPE("WHEN");
922 WRITE_NODE_FIELD(expr);
923 WRITE_NODE_FIELD(result);
927 _outCaseTestExpr(StringInfo str, CaseTestExpr *node)
929 WRITE_NODE_TYPE("CASETESTEXPR");
931 WRITE_OID_FIELD(typeId);
932 WRITE_INT_FIELD(typeMod);
936 _outArrayExpr(StringInfo str, ArrayExpr *node)
938 WRITE_NODE_TYPE("ARRAY");
940 WRITE_OID_FIELD(array_typeid);
941 WRITE_OID_FIELD(element_typeid);
942 WRITE_NODE_FIELD(elements);
943 WRITE_BOOL_FIELD(multidims);
947 _outRowExpr(StringInfo str, RowExpr *node)
949 WRITE_NODE_TYPE("ROW");
951 WRITE_NODE_FIELD(args);
952 WRITE_OID_FIELD(row_typeid);
953 WRITE_ENUM_FIELD(row_format, CoercionForm);
957 _outRowCompareExpr(StringInfo str, RowCompareExpr *node)
959 WRITE_NODE_TYPE("ROWCOMPARE");
961 WRITE_ENUM_FIELD(rctype, RowCompareType);
962 WRITE_NODE_FIELD(opnos);
963 WRITE_NODE_FIELD(opfamilies);
964 WRITE_NODE_FIELD(largs);
965 WRITE_NODE_FIELD(rargs);
969 _outCoalesceExpr(StringInfo str, CoalesceExpr *node)
971 WRITE_NODE_TYPE("COALESCE");
973 WRITE_OID_FIELD(coalescetype);
974 WRITE_NODE_FIELD(args);
978 _outMinMaxExpr(StringInfo str, MinMaxExpr *node)
980 WRITE_NODE_TYPE("MINMAX");
982 WRITE_OID_FIELD(minmaxtype);
983 WRITE_ENUM_FIELD(op, MinMaxOp);
984 WRITE_NODE_FIELD(args);
988 _outXmlExpr(StringInfo str, XmlExpr *node)
990 WRITE_NODE_TYPE("XMLEXPR");
992 WRITE_ENUM_FIELD(op, XmlExprOp);
993 WRITE_STRING_FIELD(name);
994 WRITE_NODE_FIELD(named_args);
995 WRITE_NODE_FIELD(arg_names);
996 WRITE_NODE_FIELD(args);
997 WRITE_ENUM_FIELD(xmloption, XmlOptionType);
998 WRITE_OID_FIELD(type);
999 WRITE_INT_FIELD(typmod);
1003 _outNullIfExpr(StringInfo str, NullIfExpr *node)
1005 WRITE_NODE_TYPE("NULLIFEXPR");
1007 WRITE_OID_FIELD(opno);
1008 WRITE_OID_FIELD(opfuncid);
1009 WRITE_OID_FIELD(opresulttype);
1010 WRITE_BOOL_FIELD(opretset);
1011 WRITE_NODE_FIELD(args);
1015 _outNullTest(StringInfo str, NullTest *node)
1017 WRITE_NODE_TYPE("NULLTEST");
1019 WRITE_NODE_FIELD(arg);
1020 WRITE_ENUM_FIELD(nulltesttype, NullTestType);
1024 _outBooleanTest(StringInfo str, BooleanTest *node)
1026 WRITE_NODE_TYPE("BOOLEANTEST");
1028 WRITE_NODE_FIELD(arg);
1029 WRITE_ENUM_FIELD(booltesttype, BoolTestType);
1033 _outCoerceToDomain(StringInfo str, CoerceToDomain *node)
1035 WRITE_NODE_TYPE("COERCETODOMAIN");
1037 WRITE_NODE_FIELD(arg);
1038 WRITE_OID_FIELD(resulttype);
1039 WRITE_INT_FIELD(resulttypmod);
1040 WRITE_ENUM_FIELD(coercionformat, CoercionForm);
1044 _outCoerceToDomainValue(StringInfo str, CoerceToDomainValue *node)
1046 WRITE_NODE_TYPE("COERCETODOMAINVALUE");
1048 WRITE_OID_FIELD(typeId);
1049 WRITE_INT_FIELD(typeMod);
1053 _outSetToDefault(StringInfo str, SetToDefault *node)
1055 WRITE_NODE_TYPE("SETTODEFAULT");
1057 WRITE_OID_FIELD(typeId);
1058 WRITE_INT_FIELD(typeMod);
1062 _outCurrentOfExpr(StringInfo str, CurrentOfExpr *node)
1064 WRITE_NODE_TYPE("CURRENTOFEXPR");
1066 WRITE_UINT_FIELD(cvarno);
1067 WRITE_STRING_FIELD(cursor_name);
1071 _outTargetEntry(StringInfo str, TargetEntry *node)
1073 WRITE_NODE_TYPE("TARGETENTRY");
1075 WRITE_NODE_FIELD(expr);
1076 WRITE_INT_FIELD(resno);
1077 WRITE_STRING_FIELD(resname);
1078 WRITE_UINT_FIELD(ressortgroupref);
1079 WRITE_OID_FIELD(resorigtbl);
1080 WRITE_INT_FIELD(resorigcol);
1081 WRITE_BOOL_FIELD(resjunk);
1085 _outRangeTblRef(StringInfo str, RangeTblRef *node)
1087 WRITE_NODE_TYPE("RANGETBLREF");
1089 WRITE_INT_FIELD(rtindex);
1093 _outJoinExpr(StringInfo str, JoinExpr *node)
1095 WRITE_NODE_TYPE("JOINEXPR");
1097 WRITE_ENUM_FIELD(jointype, JoinType);
1098 WRITE_BOOL_FIELD(isNatural);
1099 WRITE_NODE_FIELD(larg);
1100 WRITE_NODE_FIELD(rarg);
1101 WRITE_NODE_FIELD(using);
1102 WRITE_NODE_FIELD(quals);
1103 WRITE_NODE_FIELD(alias);
1104 WRITE_INT_FIELD(rtindex);
1108 _outFromExpr(StringInfo str, FromExpr *node)
1110 WRITE_NODE_TYPE("FROMEXPR");
1112 WRITE_NODE_FIELD(fromlist);
1113 WRITE_NODE_FIELD(quals);
1116 /*****************************************************************************
1118 * Stuff from relation.h.
1120 *****************************************************************************/
1123 * print the basic stuff of all nodes that inherit from Path
1125 * Note we do NOT print the parent, else we'd be in infinite recursion
1128 _outPathInfo(StringInfo str, Path *node)
1130 WRITE_ENUM_FIELD(pathtype, NodeTag);
1131 WRITE_FLOAT_FIELD(startup_cost, "%.2f");
1132 WRITE_FLOAT_FIELD(total_cost, "%.2f");
1133 WRITE_NODE_FIELD(pathkeys);
1137 * print the basic stuff of all nodes that inherit from JoinPath
1140 _outJoinPathInfo(StringInfo str, JoinPath *node)
1142 _outPathInfo(str, (Path *) node);
1144 WRITE_ENUM_FIELD(jointype, JoinType);
1145 WRITE_NODE_FIELD(outerjoinpath);
1146 WRITE_NODE_FIELD(innerjoinpath);
1147 WRITE_NODE_FIELD(joinrestrictinfo);
1151 _outPath(StringInfo str, Path *node)
1153 WRITE_NODE_TYPE("PATH");
1155 _outPathInfo(str, (Path *) node);
1159 _outIndexPath(StringInfo str, IndexPath *node)
1161 WRITE_NODE_TYPE("INDEXPATH");
1163 _outPathInfo(str, (Path *) node);
1165 WRITE_NODE_FIELD(indexinfo);
1166 WRITE_NODE_FIELD(indexclauses);
1167 WRITE_NODE_FIELD(indexquals);
1168 WRITE_BOOL_FIELD(isjoininner);
1169 WRITE_ENUM_FIELD(indexscandir, ScanDirection);
1170 WRITE_FLOAT_FIELD(indextotalcost, "%.2f");
1171 WRITE_FLOAT_FIELD(indexselectivity, "%.4f");
1172 WRITE_FLOAT_FIELD(rows, "%.0f");
1176 _outBitmapHeapPath(StringInfo str, BitmapHeapPath *node)
1178 WRITE_NODE_TYPE("BITMAPHEAPPATH");
1180 _outPathInfo(str, (Path *) node);
1182 WRITE_NODE_FIELD(bitmapqual);
1183 WRITE_BOOL_FIELD(isjoininner);
1184 WRITE_FLOAT_FIELD(rows, "%.0f");
1188 _outBitmapAndPath(StringInfo str, BitmapAndPath *node)
1190 WRITE_NODE_TYPE("BITMAPANDPATH");
1192 _outPathInfo(str, (Path *) node);
1194 WRITE_NODE_FIELD(bitmapquals);
1195 WRITE_FLOAT_FIELD(bitmapselectivity, "%.4f");
1199 _outBitmapOrPath(StringInfo str, BitmapOrPath *node)
1201 WRITE_NODE_TYPE("BITMAPORPATH");
1203 _outPathInfo(str, (Path *) node);
1205 WRITE_NODE_FIELD(bitmapquals);
1206 WRITE_FLOAT_FIELD(bitmapselectivity, "%.4f");
1210 _outTidPath(StringInfo str, TidPath *node)
1212 WRITE_NODE_TYPE("TIDPATH");
1214 _outPathInfo(str, (Path *) node);
1216 WRITE_NODE_FIELD(tidquals);
1220 _outAppendPath(StringInfo str, AppendPath *node)
1222 WRITE_NODE_TYPE("APPENDPATH");
1224 _outPathInfo(str, (Path *) node);
1226 WRITE_NODE_FIELD(subpaths);
1230 _outResultPath(StringInfo str, ResultPath *node)
1232 WRITE_NODE_TYPE("RESULTPATH");
1234 _outPathInfo(str, (Path *) node);
1236 WRITE_NODE_FIELD(quals);
1240 _outMaterialPath(StringInfo str, MaterialPath *node)
1242 WRITE_NODE_TYPE("MATERIALPATH");
1244 _outPathInfo(str, (Path *) node);
1246 WRITE_NODE_FIELD(subpath);
1250 _outUniquePath(StringInfo str, UniquePath *node)
1252 WRITE_NODE_TYPE("UNIQUEPATH");
1254 _outPathInfo(str, (Path *) node);
1256 WRITE_NODE_FIELD(subpath);
1257 WRITE_ENUM_FIELD(umethod, UniquePathMethod);
1258 WRITE_FLOAT_FIELD(rows, "%.0f");
1262 _outNestPath(StringInfo str, NestPath *node)
1264 WRITE_NODE_TYPE("NESTPATH");
1266 _outJoinPathInfo(str, (JoinPath *) node);
1270 _outMergePath(StringInfo str, MergePath *node)
1272 WRITE_NODE_TYPE("MERGEPATH");
1274 _outJoinPathInfo(str, (JoinPath *) node);
1276 WRITE_NODE_FIELD(path_mergeclauses);
1277 WRITE_NODE_FIELD(outersortkeys);
1278 WRITE_NODE_FIELD(innersortkeys);
1282 _outHashPath(StringInfo str, HashPath *node)
1284 WRITE_NODE_TYPE("HASHPATH");
1286 _outJoinPathInfo(str, (JoinPath *) node);
1288 WRITE_NODE_FIELD(path_hashclauses);
1292 _outPlannerGlobal(StringInfo str, PlannerGlobal *node)
1294 WRITE_NODE_TYPE("PLANNERGLOBAL");
1296 /* NB: this isn't a complete set of fields */
1297 WRITE_NODE_FIELD(paramlist);
1298 WRITE_NODE_FIELD(subplans);
1299 WRITE_NODE_FIELD(subrtables);
1300 WRITE_BITMAPSET_FIELD(rewindPlanIDs);
1301 WRITE_NODE_FIELD(finalrtable);
1305 _outPlannerInfo(StringInfo str, PlannerInfo *node)
1307 WRITE_NODE_TYPE("PLANNERINFO");
1309 /* NB: this isn't a complete set of fields */
1310 WRITE_NODE_FIELD(parse);
1311 WRITE_NODE_FIELD(glob);
1312 WRITE_UINT_FIELD(query_level);
1313 WRITE_NODE_FIELD(join_rel_list);
1314 WRITE_NODE_FIELD(resultRelations);
1315 WRITE_NODE_FIELD(returningLists);
1316 WRITE_NODE_FIELD(init_plans);
1317 WRITE_NODE_FIELD(eq_classes);
1318 WRITE_NODE_FIELD(canon_pathkeys);
1319 WRITE_NODE_FIELD(left_join_clauses);
1320 WRITE_NODE_FIELD(right_join_clauses);
1321 WRITE_NODE_FIELD(full_join_clauses);
1322 WRITE_NODE_FIELD(oj_info_list);
1323 WRITE_NODE_FIELD(in_info_list);
1324 WRITE_NODE_FIELD(append_rel_list);
1325 WRITE_NODE_FIELD(query_pathkeys);
1326 WRITE_NODE_FIELD(group_pathkeys);
1327 WRITE_NODE_FIELD(sort_pathkeys);
1328 WRITE_FLOAT_FIELD(total_table_pages, "%.0f");
1329 WRITE_FLOAT_FIELD(tuple_fraction, "%.4f");
1330 WRITE_BOOL_FIELD(hasJoinRTEs);
1331 WRITE_BOOL_FIELD(hasOuterJoins);
1332 WRITE_BOOL_FIELD(hasHavingQual);
1333 WRITE_BOOL_FIELD(hasPseudoConstantQuals);
1337 _outRelOptInfo(StringInfo str, RelOptInfo *node)
1339 WRITE_NODE_TYPE("RELOPTINFO");
1341 /* NB: this isn't a complete set of fields */
1342 WRITE_ENUM_FIELD(reloptkind, RelOptKind);
1343 WRITE_BITMAPSET_FIELD(relids);
1344 WRITE_FLOAT_FIELD(rows, "%.0f");
1345 WRITE_INT_FIELD(width);
1346 WRITE_NODE_FIELD(reltargetlist);
1347 WRITE_NODE_FIELD(pathlist);
1348 WRITE_NODE_FIELD(cheapest_startup_path);
1349 WRITE_NODE_FIELD(cheapest_total_path);
1350 WRITE_NODE_FIELD(cheapest_unique_path);
1351 WRITE_UINT_FIELD(relid);
1352 WRITE_ENUM_FIELD(rtekind, RTEKind);
1353 WRITE_INT_FIELD(min_attr);
1354 WRITE_INT_FIELD(max_attr);
1355 WRITE_NODE_FIELD(indexlist);
1356 WRITE_UINT_FIELD(pages);
1357 WRITE_FLOAT_FIELD(tuples, "%.0f");
1358 WRITE_NODE_FIELD(subplan);
1359 WRITE_NODE_FIELD(subrtable);
1360 WRITE_NODE_FIELD(baserestrictinfo);
1361 WRITE_NODE_FIELD(joininfo);
1362 WRITE_BOOL_FIELD(has_eclass_joins);
1363 WRITE_BITMAPSET_FIELD(index_outer_relids);
1364 WRITE_NODE_FIELD(index_inner_paths);
1368 _outIndexOptInfo(StringInfo str, IndexOptInfo *node)
1370 WRITE_NODE_TYPE("INDEXOPTINFO");
1372 /* NB: this isn't a complete set of fields */
1373 WRITE_OID_FIELD(indexoid);
1374 /* Do NOT print rel field, else infinite recursion */
1375 WRITE_UINT_FIELD(pages);
1376 WRITE_FLOAT_FIELD(tuples, "%.0f");
1377 WRITE_INT_FIELD(ncolumns);
1378 WRITE_NODE_FIELD(indexprs);
1379 WRITE_NODE_FIELD(indpred);
1380 WRITE_BOOL_FIELD(predOK);
1381 WRITE_BOOL_FIELD(unique);
1385 _outEquivalenceClass(StringInfo str, EquivalenceClass *node)
1388 * To simplify reading, we just chase up to the topmost merged EC and
1389 * print that, without bothering to show the merge-ees separately.
1391 while (node->ec_merged)
1392 node = node->ec_merged;
1394 WRITE_NODE_TYPE("EQUIVALENCECLASS");
1396 WRITE_NODE_FIELD(ec_opfamilies);
1397 WRITE_NODE_FIELD(ec_members);
1398 WRITE_NODE_FIELD(ec_sources);
1399 WRITE_NODE_FIELD(ec_derives);
1400 WRITE_BITMAPSET_FIELD(ec_relids);
1401 WRITE_BOOL_FIELD(ec_has_const);
1402 WRITE_BOOL_FIELD(ec_has_volatile);
1403 WRITE_BOOL_FIELD(ec_below_outer_join);
1404 WRITE_BOOL_FIELD(ec_broken);
1408 _outEquivalenceMember(StringInfo str, EquivalenceMember *node)
1410 WRITE_NODE_TYPE("EQUIVALENCEMEMBER");
1412 WRITE_NODE_FIELD(em_expr);
1413 WRITE_BITMAPSET_FIELD(em_relids);
1414 WRITE_BOOL_FIELD(em_is_const);
1415 WRITE_BOOL_FIELD(em_is_child);
1416 WRITE_OID_FIELD(em_datatype);
1420 _outPathKey(StringInfo str, PathKey *node)
1422 WRITE_NODE_TYPE("PATHKEY");
1424 WRITE_NODE_FIELD(pk_eclass);
1425 WRITE_OID_FIELD(pk_opfamily);
1426 WRITE_INT_FIELD(pk_strategy);
1427 WRITE_BOOL_FIELD(pk_nulls_first);
1431 _outRestrictInfo(StringInfo str, RestrictInfo *node)
1433 WRITE_NODE_TYPE("RESTRICTINFO");
1435 /* NB: this isn't a complete set of fields */
1436 WRITE_NODE_FIELD(clause);
1437 WRITE_BOOL_FIELD(is_pushed_down);
1438 WRITE_BOOL_FIELD(outerjoin_delayed);
1439 WRITE_BOOL_FIELD(can_join);
1440 WRITE_BOOL_FIELD(pseudoconstant);
1441 WRITE_BITMAPSET_FIELD(clause_relids);
1442 WRITE_BITMAPSET_FIELD(required_relids);
1443 WRITE_BITMAPSET_FIELD(left_relids);
1444 WRITE_BITMAPSET_FIELD(right_relids);
1445 WRITE_NODE_FIELD(orclause);
1446 /* don't write parent_ec, leads to infinite recursion in plan tree dump */
1447 WRITE_NODE_FIELD(mergeopfamilies);
1448 /* don't write left_ec, leads to infinite recursion in plan tree dump */
1449 /* don't write right_ec, leads to infinite recursion in plan tree dump */
1450 WRITE_NODE_FIELD(left_em);
1451 WRITE_NODE_FIELD(right_em);
1452 WRITE_BOOL_FIELD(outer_is_left);
1453 WRITE_OID_FIELD(hashjoinoperator);
1457 _outInnerIndexscanInfo(StringInfo str, InnerIndexscanInfo *node)
1459 WRITE_NODE_TYPE("INNERINDEXSCANINFO");
1460 WRITE_BITMAPSET_FIELD(other_relids);
1461 WRITE_BOOL_FIELD(isouterjoin);
1462 WRITE_NODE_FIELD(cheapest_startup_innerpath);
1463 WRITE_NODE_FIELD(cheapest_total_innerpath);
1467 _outOuterJoinInfo(StringInfo str, OuterJoinInfo *node)
1469 WRITE_NODE_TYPE("OUTERJOININFO");
1471 WRITE_BITMAPSET_FIELD(min_lefthand);
1472 WRITE_BITMAPSET_FIELD(min_righthand);
1473 WRITE_BOOL_FIELD(is_full_join);
1474 WRITE_BOOL_FIELD(lhs_strict);
1475 WRITE_BOOL_FIELD(delay_upper_joins);
1479 _outInClauseInfo(StringInfo str, InClauseInfo *node)
1481 WRITE_NODE_TYPE("INCLAUSEINFO");
1483 WRITE_BITMAPSET_FIELD(lefthand);
1484 WRITE_BITMAPSET_FIELD(righthand);
1485 WRITE_NODE_FIELD(sub_targetlist);
1486 WRITE_NODE_FIELD(in_operators);
1490 _outAppendRelInfo(StringInfo str, AppendRelInfo *node)
1492 WRITE_NODE_TYPE("APPENDRELINFO");
1494 WRITE_UINT_FIELD(parent_relid);
1495 WRITE_UINT_FIELD(child_relid);
1496 WRITE_OID_FIELD(parent_reltype);
1497 WRITE_OID_FIELD(child_reltype);
1498 WRITE_NODE_FIELD(col_mappings);
1499 WRITE_NODE_FIELD(translated_vars);
1500 WRITE_OID_FIELD(parent_reloid);
1504 _outPlannerParamItem(StringInfo str, PlannerParamItem *node)
1506 WRITE_NODE_TYPE("PLANNERPARAMITEM");
1508 WRITE_NODE_FIELD(item);
1509 WRITE_UINT_FIELD(abslevel);
1512 /*****************************************************************************
1514 * Stuff from parsenodes.h.
1516 *****************************************************************************/
1519 _outCreateStmt(StringInfo str, CreateStmt *node)
1521 WRITE_NODE_TYPE("CREATESTMT");
1523 WRITE_NODE_FIELD(relation);
1524 WRITE_NODE_FIELD(tableElts);
1525 WRITE_NODE_FIELD(inhRelations);
1526 WRITE_NODE_FIELD(constraints);
1527 WRITE_NODE_FIELD(options);
1528 WRITE_ENUM_FIELD(oncommit, OnCommitAction);
1529 WRITE_STRING_FIELD(tablespacename);
1533 _outIndexStmt(StringInfo str, IndexStmt *node)
1535 WRITE_NODE_TYPE("INDEXSTMT");
1537 WRITE_STRING_FIELD(idxname);
1538 WRITE_NODE_FIELD(relation);
1539 WRITE_STRING_FIELD(accessMethod);
1540 WRITE_STRING_FIELD(tableSpace);
1541 WRITE_NODE_FIELD(indexParams);
1542 WRITE_NODE_FIELD(options);
1543 WRITE_NODE_FIELD(whereClause);
1544 WRITE_BOOL_FIELD(unique);
1545 WRITE_BOOL_FIELD(primary);
1546 WRITE_BOOL_FIELD(isconstraint);
1547 WRITE_BOOL_FIELD(concurrent);
1551 _outNotifyStmt(StringInfo str, NotifyStmt *node)
1553 WRITE_NODE_TYPE("NOTIFY");
1555 WRITE_NODE_FIELD(relation);
1559 _outDeclareCursorStmt(StringInfo str, DeclareCursorStmt *node)
1561 WRITE_NODE_TYPE("DECLARECURSOR");
1563 WRITE_STRING_FIELD(portalname);
1564 WRITE_INT_FIELD(options);
1565 WRITE_NODE_FIELD(query);
1569 _outSelectStmt(StringInfo str, SelectStmt *node)
1571 WRITE_NODE_TYPE("SELECT");
1573 WRITE_NODE_FIELD(distinctClause);
1574 WRITE_NODE_FIELD(intoClause);
1575 WRITE_NODE_FIELD(targetList);
1576 WRITE_NODE_FIELD(fromClause);
1577 WRITE_NODE_FIELD(whereClause);
1578 WRITE_NODE_FIELD(groupClause);
1579 WRITE_NODE_FIELD(havingClause);
1580 WRITE_NODE_FIELD(valuesLists);
1581 WRITE_NODE_FIELD(sortClause);
1582 WRITE_NODE_FIELD(limitOffset);
1583 WRITE_NODE_FIELD(limitCount);
1584 WRITE_NODE_FIELD(lockingClause);
1585 WRITE_ENUM_FIELD(op, SetOperation);
1586 WRITE_BOOL_FIELD(all);
1587 WRITE_NODE_FIELD(larg);
1588 WRITE_NODE_FIELD(rarg);
1592 _outFuncCall(StringInfo str, FuncCall *node)
1594 WRITE_NODE_TYPE("FUNCCALL");
1596 WRITE_NODE_FIELD(funcname);
1597 WRITE_NODE_FIELD(args);
1598 WRITE_BOOL_FIELD(agg_star);
1599 WRITE_BOOL_FIELD(agg_distinct);
1600 WRITE_INT_FIELD(location);
1604 _outDefElem(StringInfo str, DefElem *node)
1606 WRITE_NODE_TYPE("DEFELEM");
1608 WRITE_STRING_FIELD(defname);
1609 WRITE_NODE_FIELD(arg);
1613 _outLockingClause(StringInfo str, LockingClause *node)
1615 WRITE_NODE_TYPE("LOCKINGCLAUSE");
1617 WRITE_NODE_FIELD(lockedRels);
1618 WRITE_BOOL_FIELD(forUpdate);
1619 WRITE_BOOL_FIELD(noWait);
1623 _outXmlSerialize(StringInfo str, XmlSerialize *node)
1625 WRITE_NODE_TYPE("XMLSERIALIZE");
1627 WRITE_ENUM_FIELD(xmloption, XmlOptionType);
1628 WRITE_NODE_FIELD(expr);
1629 WRITE_NODE_FIELD(typename);
1633 _outColumnDef(StringInfo str, ColumnDef *node)
1635 WRITE_NODE_TYPE("COLUMNDEF");
1637 WRITE_STRING_FIELD(colname);
1638 WRITE_NODE_FIELD(typename);
1639 WRITE_INT_FIELD(inhcount);
1640 WRITE_BOOL_FIELD(is_local);
1641 WRITE_BOOL_FIELD(is_not_null);
1642 WRITE_NODE_FIELD(raw_default);
1643 WRITE_STRING_FIELD(cooked_default);
1644 WRITE_NODE_FIELD(constraints);
1648 _outTypeName(StringInfo str, TypeName *node)
1650 WRITE_NODE_TYPE("TYPENAME");
1652 WRITE_NODE_FIELD(names);
1653 WRITE_OID_FIELD(typeid);
1654 WRITE_BOOL_FIELD(timezone);
1655 WRITE_BOOL_FIELD(setof);
1656 WRITE_BOOL_FIELD(pct_type);
1657 WRITE_NODE_FIELD(typmods);
1658 WRITE_INT_FIELD(typemod);
1659 WRITE_NODE_FIELD(arrayBounds);
1660 WRITE_INT_FIELD(location);
1664 _outTypeCast(StringInfo str, TypeCast *node)
1666 WRITE_NODE_TYPE("TYPECAST");
1668 WRITE_NODE_FIELD(arg);
1669 WRITE_NODE_FIELD(typename);
1673 _outIndexElem(StringInfo str, IndexElem *node)
1675 WRITE_NODE_TYPE("INDEXELEM");
1677 WRITE_STRING_FIELD(name);
1678 WRITE_NODE_FIELD(expr);
1679 WRITE_NODE_FIELD(opclass);
1680 WRITE_ENUM_FIELD(ordering, SortByDir);
1681 WRITE_ENUM_FIELD(nulls_ordering, SortByNulls);
1685 _outQuery(StringInfo str, Query *node)
1687 WRITE_NODE_TYPE("QUERY");
1689 WRITE_ENUM_FIELD(commandType, CmdType);
1690 WRITE_ENUM_FIELD(querySource, QuerySource);
1691 WRITE_BOOL_FIELD(canSetTag);
1694 * Hack to work around missing outfuncs routines for a lot of the
1695 * utility-statement node types. (The only one we actually *need* for
1696 * rules support is NotifyStmt.) Someday we ought to support 'em all, but
1697 * for the meantime do this to avoid getting lots of warnings when running
1698 * with debug_print_parse on.
1700 if (node->utilityStmt)
1702 switch (nodeTag(node->utilityStmt))
1707 case T_DeclareCursorStmt:
1708 WRITE_NODE_FIELD(utilityStmt);
1711 appendStringInfo(str, " :utilityStmt ?");
1716 appendStringInfo(str, " :utilityStmt <>");
1718 WRITE_INT_FIELD(resultRelation);
1719 WRITE_NODE_FIELD(intoClause);
1720 WRITE_BOOL_FIELD(hasAggs);
1721 WRITE_BOOL_FIELD(hasSubLinks);
1722 WRITE_NODE_FIELD(rtable);
1723 WRITE_NODE_FIELD(jointree);
1724 WRITE_NODE_FIELD(targetList);
1725 WRITE_NODE_FIELD(returningList);
1726 WRITE_NODE_FIELD(groupClause);
1727 WRITE_NODE_FIELD(havingQual);
1728 WRITE_NODE_FIELD(distinctClause);
1729 WRITE_NODE_FIELD(sortClause);
1730 WRITE_NODE_FIELD(limitOffset);
1731 WRITE_NODE_FIELD(limitCount);
1732 WRITE_NODE_FIELD(rowMarks);
1733 WRITE_NODE_FIELD(setOperations);
1737 _outSortClause(StringInfo str, SortClause *node)
1739 WRITE_NODE_TYPE("SORTCLAUSE");
1741 WRITE_UINT_FIELD(tleSortGroupRef);
1742 WRITE_OID_FIELD(sortop);
1743 WRITE_BOOL_FIELD(nulls_first);
1747 _outGroupClause(StringInfo str, GroupClause *node)
1749 WRITE_NODE_TYPE("GROUPCLAUSE");
1751 WRITE_UINT_FIELD(tleSortGroupRef);
1752 WRITE_OID_FIELD(sortop);
1753 WRITE_BOOL_FIELD(nulls_first);
1757 _outRowMarkClause(StringInfo str, RowMarkClause *node)
1759 WRITE_NODE_TYPE("ROWMARKCLAUSE");
1761 WRITE_UINT_FIELD(rti);
1762 WRITE_BOOL_FIELD(forUpdate);
1763 WRITE_BOOL_FIELD(noWait);
1767 _outSetOperationStmt(StringInfo str, SetOperationStmt *node)
1769 WRITE_NODE_TYPE("SETOPERATIONSTMT");
1771 WRITE_ENUM_FIELD(op, SetOperation);
1772 WRITE_BOOL_FIELD(all);
1773 WRITE_NODE_FIELD(larg);
1774 WRITE_NODE_FIELD(rarg);
1775 WRITE_NODE_FIELD(colTypes);
1776 WRITE_NODE_FIELD(colTypmods);
1780 _outRangeTblEntry(StringInfo str, RangeTblEntry *node)
1782 WRITE_NODE_TYPE("RTE");
1784 /* put alias + eref first to make dump more legible */
1785 WRITE_NODE_FIELD(alias);
1786 WRITE_NODE_FIELD(eref);
1787 WRITE_ENUM_FIELD(rtekind, RTEKind);
1789 switch (node->rtekind)
1793 WRITE_OID_FIELD(relid);
1796 WRITE_NODE_FIELD(subquery);
1799 WRITE_NODE_FIELD(funcexpr);
1800 WRITE_NODE_FIELD(funccoltypes);
1801 WRITE_NODE_FIELD(funccoltypmods);
1804 WRITE_NODE_FIELD(values_lists);
1807 WRITE_ENUM_FIELD(jointype, JoinType);
1808 WRITE_NODE_FIELD(joinaliasvars);
1811 elog(ERROR, "unrecognized RTE kind: %d", (int) node->rtekind);
1815 WRITE_BOOL_FIELD(inh);
1816 WRITE_BOOL_FIELD(inFromCl);
1817 WRITE_UINT_FIELD(requiredPerms);
1818 WRITE_OID_FIELD(checkAsUser);
1822 _outAExpr(StringInfo str, A_Expr *node)
1824 WRITE_NODE_TYPE("AEXPR");
1829 appendStringInfo(str, " ");
1830 WRITE_NODE_FIELD(name);
1833 appendStringInfo(str, " AND");
1836 appendStringInfo(str, " OR");
1839 appendStringInfo(str, " NOT");
1842 appendStringInfo(str, " ");
1843 WRITE_NODE_FIELD(name);
1844 appendStringInfo(str, " ANY ");
1847 appendStringInfo(str, " ");
1848 WRITE_NODE_FIELD(name);
1849 appendStringInfo(str, " ALL ");
1851 case AEXPR_DISTINCT:
1852 appendStringInfo(str, " DISTINCT ");
1853 WRITE_NODE_FIELD(name);
1856 appendStringInfo(str, " NULLIF ");
1857 WRITE_NODE_FIELD(name);
1860 appendStringInfo(str, " OF ");
1861 WRITE_NODE_FIELD(name);
1864 appendStringInfo(str, " IN ");
1865 WRITE_NODE_FIELD(name);
1868 appendStringInfo(str, " ??");
1872 WRITE_NODE_FIELD(lexpr);
1873 WRITE_NODE_FIELD(rexpr);
1874 WRITE_INT_FIELD(location);
1878 _outValue(StringInfo str, Value *value)
1880 switch (value->type)
1883 appendStringInfo(str, "%ld", value->val.ival);
1888 * We assume the value is a valid numeric literal and so does not
1891 appendStringInfoString(str, value->val.str);
1894 appendStringInfoChar(str, '"');
1895 _outToken(str, value->val.str);
1896 appendStringInfoChar(str, '"');
1899 /* internal representation already has leading 'b' */
1900 appendStringInfoString(str, value->val.str);
1903 elog(ERROR, "unrecognized node type: %d", (int) value->type);
1909 _outColumnRef(StringInfo str, ColumnRef *node)
1911 WRITE_NODE_TYPE("COLUMNREF");
1913 WRITE_NODE_FIELD(fields);
1914 WRITE_INT_FIELD(location);
1918 _outParamRef(StringInfo str, ParamRef *node)
1920 WRITE_NODE_TYPE("PARAMREF");
1922 WRITE_INT_FIELD(number);
1926 _outAConst(StringInfo str, A_Const *node)
1928 WRITE_NODE_TYPE("A_CONST");
1930 appendStringInfo(str, " :val ");
1931 _outValue(str, &(node->val));
1932 WRITE_NODE_FIELD(typename);
1936 _outA_Indices(StringInfo str, A_Indices *node)
1938 WRITE_NODE_TYPE("A_INDICES");
1940 WRITE_NODE_FIELD(lidx);
1941 WRITE_NODE_FIELD(uidx);
1945 _outA_Indirection(StringInfo str, A_Indirection *node)
1947 WRITE_NODE_TYPE("A_INDIRECTION");
1949 WRITE_NODE_FIELD(arg);
1950 WRITE_NODE_FIELD(indirection);
1954 _outResTarget(StringInfo str, ResTarget *node)
1956 WRITE_NODE_TYPE("RESTARGET");
1958 WRITE_STRING_FIELD(name);
1959 WRITE_NODE_FIELD(indirection);
1960 WRITE_NODE_FIELD(val);
1961 WRITE_INT_FIELD(location);
1965 _outConstraint(StringInfo str, Constraint *node)
1967 WRITE_NODE_TYPE("CONSTRAINT");
1969 WRITE_STRING_FIELD(name);
1971 appendStringInfo(str, " :contype ");
1972 switch (node->contype)
1974 case CONSTR_PRIMARY:
1975 appendStringInfo(str, "PRIMARY_KEY");
1976 WRITE_NODE_FIELD(keys);
1977 WRITE_NODE_FIELD(options);
1978 WRITE_STRING_FIELD(indexspace);
1982 appendStringInfo(str, "UNIQUE");
1983 WRITE_NODE_FIELD(keys);
1984 WRITE_NODE_FIELD(options);
1985 WRITE_STRING_FIELD(indexspace);
1989 appendStringInfo(str, "CHECK");
1990 WRITE_NODE_FIELD(raw_expr);
1991 WRITE_STRING_FIELD(cooked_expr);
1994 case CONSTR_DEFAULT:
1995 appendStringInfo(str, "DEFAULT");
1996 WRITE_NODE_FIELD(raw_expr);
1997 WRITE_STRING_FIELD(cooked_expr);
2000 case CONSTR_NOTNULL:
2001 appendStringInfo(str, "NOT_NULL");
2005 appendStringInfo(str, "<unrecognized_constraint>");
2011 _outFkConstraint(StringInfo str, FkConstraint *node)
2013 WRITE_NODE_TYPE("FKCONSTRAINT");
2015 WRITE_STRING_FIELD(constr_name);
2016 WRITE_NODE_FIELD(pktable);
2017 WRITE_NODE_FIELD(fk_attrs);
2018 WRITE_NODE_FIELD(pk_attrs);
2019 WRITE_CHAR_FIELD(fk_matchtype);
2020 WRITE_CHAR_FIELD(fk_upd_action);
2021 WRITE_CHAR_FIELD(fk_del_action);
2022 WRITE_BOOL_FIELD(deferrable);
2023 WRITE_BOOL_FIELD(initdeferred);
2024 WRITE_BOOL_FIELD(skip_validation);
2030 * converts a Node into ascii string and append it to 'str'
2033 _outNode(StringInfo str, void *obj)
2036 appendStringInfo(str, "<>");
2037 else if (IsA(obj, List) ||IsA(obj, IntList) || IsA(obj, OidList))
2039 else if (IsA(obj, Integer) ||
2042 IsA(obj, BitString))
2044 /* nodeRead does not want to see { } around these! */
2045 _outValue(str, obj);
2049 appendStringInfoChar(str, '{');
2050 switch (nodeTag(obj))
2053 _outPlannedStmt(str, obj);
2059 _outResult(str, obj);
2062 _outAppend(str, obj);
2065 _outBitmapAnd(str, obj);
2068 _outBitmapOr(str, obj);
2074 _outSeqScan(str, obj);
2077 _outIndexScan(str, obj);
2079 case T_BitmapIndexScan:
2080 _outBitmapIndexScan(str, obj);
2082 case T_BitmapHeapScan:
2083 _outBitmapHeapScan(str, obj);
2086 _outTidScan(str, obj);
2088 case T_SubqueryScan:
2089 _outSubqueryScan(str, obj);
2091 case T_FunctionScan:
2092 _outFunctionScan(str, obj);
2095 _outValuesScan(str, obj);
2101 _outNestLoop(str, obj);
2104 _outMergeJoin(str, obj);
2107 _outHashJoin(str, obj);
2113 _outGroup(str, obj);
2116 _outMaterial(str, obj);
2122 _outUnique(str, obj);
2125 _outSetOp(str, obj);
2128 _outLimit(str, obj);
2134 _outAlias(str, obj);
2137 _outRangeVar(str, obj);
2140 _outIntoClause(str, obj);
2146 _outConst(str, obj);
2149 _outParam(str, obj);
2152 _outAggref(str, obj);
2155 _outArrayRef(str, obj);
2158 _outFuncExpr(str, obj);
2161 _outOpExpr(str, obj);
2163 case T_DistinctExpr:
2164 _outDistinctExpr(str, obj);
2166 case T_ScalarArrayOpExpr:
2167 _outScalarArrayOpExpr(str, obj);
2170 _outBoolExpr(str, obj);
2173 _outSubLink(str, obj);
2176 _outSubPlan(str, obj);
2179 _outFieldSelect(str, obj);
2182 _outFieldStore(str, obj);
2185 _outRelabelType(str, obj);
2188 _outCoerceViaIO(str, obj);
2190 case T_ArrayCoerceExpr:
2191 _outArrayCoerceExpr(str, obj);
2193 case T_ConvertRowtypeExpr:
2194 _outConvertRowtypeExpr(str, obj);
2197 _outCaseExpr(str, obj);
2200 _outCaseWhen(str, obj);
2202 case T_CaseTestExpr:
2203 _outCaseTestExpr(str, obj);
2206 _outArrayExpr(str, obj);
2209 _outRowExpr(str, obj);
2211 case T_RowCompareExpr:
2212 _outRowCompareExpr(str, obj);
2214 case T_CoalesceExpr:
2215 _outCoalesceExpr(str, obj);
2218 _outMinMaxExpr(str, obj);
2221 _outXmlExpr(str, obj);
2224 _outNullIfExpr(str, obj);
2227 _outNullTest(str, obj);
2230 _outBooleanTest(str, obj);
2232 case T_CoerceToDomain:
2233 _outCoerceToDomain(str, obj);
2235 case T_CoerceToDomainValue:
2236 _outCoerceToDomainValue(str, obj);
2238 case T_SetToDefault:
2239 _outSetToDefault(str, obj);
2241 case T_CurrentOfExpr:
2242 _outCurrentOfExpr(str, obj);
2245 _outTargetEntry(str, obj);
2248 _outRangeTblRef(str, obj);
2251 _outJoinExpr(str, obj);
2254 _outFromExpr(str, obj);
2261 _outIndexPath(str, obj);
2263 case T_BitmapHeapPath:
2264 _outBitmapHeapPath(str, obj);
2266 case T_BitmapAndPath:
2267 _outBitmapAndPath(str, obj);
2269 case T_BitmapOrPath:
2270 _outBitmapOrPath(str, obj);
2273 _outTidPath(str, obj);
2276 _outAppendPath(str, obj);
2279 _outResultPath(str, obj);
2281 case T_MaterialPath:
2282 _outMaterialPath(str, obj);
2285 _outUniquePath(str, obj);
2288 _outNestPath(str, obj);
2291 _outMergePath(str, obj);
2294 _outHashPath(str, obj);
2296 case T_PlannerGlobal:
2297 _outPlannerGlobal(str, obj);
2300 _outPlannerInfo(str, obj);
2303 _outRelOptInfo(str, obj);
2305 case T_IndexOptInfo:
2306 _outIndexOptInfo(str, obj);
2308 case T_EquivalenceClass:
2309 _outEquivalenceClass(str, obj);
2311 case T_EquivalenceMember:
2312 _outEquivalenceMember(str, obj);
2315 _outPathKey(str, obj);
2317 case T_RestrictInfo:
2318 _outRestrictInfo(str, obj);
2320 case T_InnerIndexscanInfo:
2321 _outInnerIndexscanInfo(str, obj);
2323 case T_OuterJoinInfo:
2324 _outOuterJoinInfo(str, obj);
2326 case T_InClauseInfo:
2327 _outInClauseInfo(str, obj);
2329 case T_AppendRelInfo:
2330 _outAppendRelInfo(str, obj);
2332 case T_PlannerParamItem:
2333 _outPlannerParamItem(str, obj);
2337 _outCreateStmt(str, obj);
2340 _outIndexStmt(str, obj);
2343 _outNotifyStmt(str, obj);
2345 case T_DeclareCursorStmt:
2346 _outDeclareCursorStmt(str, obj);
2349 _outSelectStmt(str, obj);
2352 _outColumnDef(str, obj);
2355 _outTypeName(str, obj);
2358 _outTypeCast(str, obj);
2361 _outIndexElem(str, obj);
2364 _outQuery(str, obj);
2367 _outSortClause(str, obj);
2370 _outGroupClause(str, obj);
2372 case T_RowMarkClause:
2373 _outRowMarkClause(str, obj);
2375 case T_SetOperationStmt:
2376 _outSetOperationStmt(str, obj);
2378 case T_RangeTblEntry:
2379 _outRangeTblEntry(str, obj);
2382 _outAExpr(str, obj);
2385 _outColumnRef(str, obj);
2388 _outParamRef(str, obj);
2391 _outAConst(str, obj);
2394 _outA_Indices(str, obj);
2396 case T_A_Indirection:
2397 _outA_Indirection(str, obj);
2400 _outResTarget(str, obj);
2403 _outConstraint(str, obj);
2405 case T_FkConstraint:
2406 _outFkConstraint(str, obj);
2409 _outFuncCall(str, obj);
2412 _outDefElem(str, obj);
2414 case T_LockingClause:
2415 _outLockingClause(str, obj);
2417 case T_XmlSerialize:
2418 _outXmlSerialize(str, obj);
2424 * This should be an ERROR, but it's too useful to be able to
2425 * dump structures that _outNode only understands part of.
2427 elog(WARNING, "could not dump unrecognized node type: %d",
2428 (int) nodeTag(obj));
2431 appendStringInfoChar(str, '}');
2437 * returns the ascii representation of the Node as a palloc'd string
2440 nodeToString(void *obj)
2444 /* see stringinfo.h for an explanation of this maneuver */
2445 initStringInfo(&str);
2446 _outNode(&str, obj);