1 /*-------------------------------------------------------------------------
4 * Output functions for Postgres tree nodes.
6 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.186 2002/12/05 15:50:35 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/parsenodes.h"
28 #include "nodes/plannodes.h"
29 #include "nodes/relation.h"
30 #include "parser/parse.h"
31 #include "utils/datum.h"
35 * Macros to simplify output of different kinds of fields. Use these
36 * wherever possible to reduce the chance for silly typos. Note that these
37 * hard-wire conventions about the names of the local variables in an Out
41 /* Write the label for the node type */
42 #define WRITE_NODE_TYPE(nodelabel) \
43 appendStringInfo(str, nodelabel)
45 /* Write an integer field (anything written as ":fldname %d") */
46 #define WRITE_INT_FIELD(fldname) \
47 appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname)
49 /* Write an unsigned integer field (anything written as ":fldname %u") */
50 #define WRITE_UINT_FIELD(fldname) \
51 appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
53 /* Write an OID field (don't hard-wire assumption that OID is same as uint) */
54 #define WRITE_OID_FIELD(fldname) \
55 appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
57 /* Write a long-integer field */
58 #define WRITE_LONG_FIELD(fldname) \
59 appendStringInfo(str, " :" CppAsString(fldname) " %ld", node->fldname)
61 /* Write a char field (ie, one ascii character) */
62 #define WRITE_CHAR_FIELD(fldname) \
63 appendStringInfo(str, " :" CppAsString(fldname) " %c", node->fldname)
65 /* Write an enumerated-type field as an integer code */
66 #define WRITE_ENUM_FIELD(fldname, enumtype) \
67 appendStringInfo(str, " :" CppAsString(fldname) " %d", \
70 /* Write a float field --- caller must give format to define precision */
71 #define WRITE_FLOAT_FIELD(fldname,format) \
72 appendStringInfo(str, " :" CppAsString(fldname) " " format, node->fldname)
74 /* Write a boolean field */
75 #define WRITE_BOOL_FIELD(fldname) \
76 appendStringInfo(str, " :" CppAsString(fldname) " %s", \
77 booltostr(node->fldname))
79 /* Write a character-string (possibly NULL) field */
80 #define WRITE_STRING_FIELD(fldname) \
81 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
82 _outToken(str, node->fldname))
84 /* Write a Node field */
85 #define WRITE_NODE_FIELD(fldname) \
86 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
87 _outNode(str, node->fldname))
89 /* Write an integer-list field */
90 #define WRITE_INTLIST_FIELD(fldname) \
91 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
92 _outIntList(str, node->fldname))
94 /* Write an OID-list field */
95 #define WRITE_OIDLIST_FIELD(fldname) \
96 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
97 _outOidList(str, node->fldname))
100 #define booltostr(x) ((x) ? "true" : "false")
102 static void _outDatum(StringInfo str, Datum value, int typlen, bool typbyval);
103 static void _outNode(StringInfo str, void *obj);
107 * Convert an ordinary string (eg, an identifier) into a form that
108 * will be decoded back to a plain token by read.c's functions.
110 * If a null or empty string is given, it is encoded as "<>".
113 _outToken(StringInfo str, char *s)
115 if (s == NULL || *s == '\0')
117 appendStringInfo(str, "<>");
122 * Look for characters or patterns that are treated specially by
123 * read.c (either in pg_strtok() or in nodeRead()), and therefore need
124 * a protective backslash.
126 /* These characters only need to be quoted at the start of the string */
130 isdigit((unsigned char) *s) ||
131 ((*s == '+' || *s == '-') &&
132 (isdigit((unsigned char) s[1]) || s[1] == '.')))
133 appendStringInfoChar(str, '\\');
136 /* These chars must be backslashed anywhere in the string */
137 if (*s == ' ' || *s == '\n' || *s == '\t' ||
138 *s == '(' || *s == ')' || *s == '{' || *s == '}' ||
140 appendStringInfoChar(str, '\\');
141 appendStringInfoChar(str, *s++);
147 * converts a List of integers
150 _outIntList(StringInfo str, List *list)
154 appendStringInfoChar(str, '(');
156 appendStringInfo(str, " %d", lfirsti(l));
157 appendStringInfoChar(str, ')');
162 * converts a List of OIDs
165 _outOidList(StringInfo str, List *list)
169 appendStringInfoChar(str, '(');
171 appendStringInfo(str, " %u", (Oid) lfirsti(l));
172 appendStringInfoChar(str, ')');
176 _outCreateStmt(StringInfo str, CreateStmt *node)
178 WRITE_NODE_TYPE("CREATE");
180 WRITE_NODE_FIELD(relation);
181 WRITE_NODE_FIELD(tableElts);
182 WRITE_NODE_FIELD(inhRelations);
183 WRITE_NODE_FIELD(constraints);
184 WRITE_BOOL_FIELD(hasoids);
185 WRITE_ENUM_FIELD(oncommit, OnCommitAction);
189 _outIndexStmt(StringInfo str, IndexStmt *node)
191 WRITE_NODE_TYPE("INDEX");
193 WRITE_STRING_FIELD(idxname);
194 WRITE_NODE_FIELD(relation);
195 WRITE_STRING_FIELD(accessMethod);
196 WRITE_NODE_FIELD(indexParams);
197 WRITE_NODE_FIELD(whereClause);
198 WRITE_NODE_FIELD(rangetable);
199 WRITE_BOOL_FIELD(unique);
200 WRITE_BOOL_FIELD(primary);
201 WRITE_BOOL_FIELD(isconstraint);
205 _outNotifyStmt(StringInfo str, NotifyStmt *node)
207 WRITE_NODE_TYPE("NOTIFY");
209 WRITE_NODE_FIELD(relation);
213 _outSelectStmt(StringInfo str, SelectStmt *node)
215 WRITE_NODE_TYPE("SELECT");
217 /* XXX this is pretty durn incomplete */
218 WRITE_NODE_FIELD(whereClause);
222 _outFuncCall(StringInfo str, FuncCall *node)
224 WRITE_NODE_TYPE("FUNCCALL");
226 WRITE_NODE_FIELD(funcname);
227 WRITE_NODE_FIELD(args);
228 WRITE_BOOL_FIELD(agg_star);
229 WRITE_BOOL_FIELD(agg_distinct);
233 _outColumnDef(StringInfo str, ColumnDef *node)
235 WRITE_NODE_TYPE("COLUMNDEF");
237 WRITE_STRING_FIELD(colname);
238 WRITE_NODE_FIELD(typename);
239 WRITE_INT_FIELD(inhcount);
240 WRITE_BOOL_FIELD(is_local);
241 WRITE_BOOL_FIELD(is_not_null);
242 WRITE_NODE_FIELD(raw_default);
243 WRITE_STRING_FIELD(cooked_default);
244 WRITE_NODE_FIELD(constraints);
245 WRITE_NODE_FIELD(support);
249 _outTypeName(StringInfo str, TypeName *node)
251 WRITE_NODE_TYPE("TYPENAME");
253 WRITE_NODE_FIELD(names);
254 WRITE_OID_FIELD(typeid);
255 WRITE_BOOL_FIELD(timezone);
256 WRITE_BOOL_FIELD(setof);
257 WRITE_BOOL_FIELD(pct_type);
258 WRITE_INT_FIELD(typmod);
259 WRITE_NODE_FIELD(arrayBounds);
263 _outTypeCast(StringInfo str, TypeCast *node)
265 WRITE_NODE_TYPE("TYPECAST");
267 WRITE_NODE_FIELD(arg);
268 WRITE_NODE_FIELD(typename);
272 _outIndexElem(StringInfo str, IndexElem *node)
274 WRITE_NODE_TYPE("INDEXELEM");
276 WRITE_STRING_FIELD(name);
277 WRITE_NODE_FIELD(funcname);
278 WRITE_NODE_FIELD(args);
279 WRITE_NODE_FIELD(opclass);
283 _outQuery(StringInfo str, Query *node)
285 WRITE_NODE_TYPE("QUERY");
287 WRITE_ENUM_FIELD(commandType, CmdType);
288 WRITE_ENUM_FIELD(querySource, QuerySource);
291 * Hack to work around missing outfuncs routines for a lot of the
292 * utility-statement node types. (The only one we actually *need* for
293 * rules support is NotifyStmt.) Someday we ought to support 'em all,
294 * but for the meantime do this to avoid getting lots of warnings when
295 * running with debug_print_parse on.
297 if (node->utilityStmt)
299 switch (nodeTag(node->utilityStmt))
304 WRITE_NODE_FIELD(utilityStmt);
307 appendStringInfo(str, " :utilityStmt ?");
312 appendStringInfo(str, " :utilityStmt <>");
314 WRITE_INT_FIELD(resultRelation);
315 WRITE_NODE_FIELD(into);
316 WRITE_BOOL_FIELD(isPortal);
317 WRITE_BOOL_FIELD(isBinary);
318 WRITE_BOOL_FIELD(hasAggs);
319 WRITE_BOOL_FIELD(hasSubLinks);
320 WRITE_NODE_FIELD(rtable);
321 WRITE_NODE_FIELD(jointree);
322 WRITE_INTLIST_FIELD(rowMarks);
323 WRITE_NODE_FIELD(targetList);
324 WRITE_NODE_FIELD(groupClause);
325 WRITE_NODE_FIELD(havingQual);
326 WRITE_NODE_FIELD(distinctClause);
327 WRITE_NODE_FIELD(sortClause);
328 WRITE_NODE_FIELD(limitOffset);
329 WRITE_NODE_FIELD(limitCount);
330 WRITE_NODE_FIELD(setOperations);
331 WRITE_INTLIST_FIELD(resultRelations);
333 /* planner-internal fields are not written out */
337 _outSortClause(StringInfo str, SortClause *node)
339 WRITE_NODE_TYPE("SORTCLAUSE");
341 WRITE_UINT_FIELD(tleSortGroupRef);
342 WRITE_OID_FIELD(sortop);
346 _outGroupClause(StringInfo str, GroupClause *node)
348 WRITE_NODE_TYPE("GROUPCLAUSE");
350 WRITE_UINT_FIELD(tleSortGroupRef);
351 WRITE_OID_FIELD(sortop);
355 _outSetOperationStmt(StringInfo str, SetOperationStmt *node)
357 WRITE_NODE_TYPE("SETOPERATIONSTMT");
359 WRITE_ENUM_FIELD(op, SetOperation);
360 WRITE_BOOL_FIELD(all);
361 WRITE_NODE_FIELD(larg);
362 WRITE_NODE_FIELD(rarg);
363 WRITE_OIDLIST_FIELD(colTypes);
367 * Stuff from plannodes.h
371 * print the basic stuff of all nodes that inherit from Plan
373 * NOTE: we deliberately omit the execution state (EState)
376 _outPlanInfo(StringInfo str, Plan *node)
378 WRITE_FLOAT_FIELD(startup_cost, "%.2f");
379 WRITE_FLOAT_FIELD(total_cost, "%.2f");
380 WRITE_FLOAT_FIELD(plan_rows, "%.0f");
381 WRITE_INT_FIELD(plan_width);
382 WRITE_NODE_FIELD(targetlist);
383 WRITE_NODE_FIELD(qual);
384 WRITE_NODE_FIELD(lefttree);
385 WRITE_NODE_FIELD(righttree);
386 WRITE_NODE_FIELD(initPlan);
387 WRITE_INTLIST_FIELD(extParam);
388 WRITE_INTLIST_FIELD(locParam);
389 WRITE_INT_FIELD(nParamExec);
393 * print the basic stuff of all nodes that inherit from Scan
396 _outScanInfo(StringInfo str, Scan *node)
398 _outPlanInfo(str, (Plan *) node);
400 WRITE_UINT_FIELD(scanrelid);
404 * print the basic stuff of all nodes that inherit from Join
407 _outJoinPlanInfo(StringInfo str, Join *node)
409 _outPlanInfo(str, (Plan *) node);
411 WRITE_ENUM_FIELD(jointype, JoinType);
412 WRITE_NODE_FIELD(joinqual);
417 _outPlan(StringInfo str, Plan *node)
419 WRITE_NODE_TYPE("PLAN");
421 _outPlanInfo(str, (Plan *) node);
425 _outResult(StringInfo str, Result *node)
427 WRITE_NODE_TYPE("RESULT");
429 _outPlanInfo(str, (Plan *) node);
431 WRITE_NODE_FIELD(resconstantqual);
435 _outAppend(StringInfo str, Append *node)
437 WRITE_NODE_TYPE("APPEND");
439 _outPlanInfo(str, (Plan *) node);
441 WRITE_NODE_FIELD(appendplans);
442 WRITE_BOOL_FIELD(isTarget);
446 _outScan(StringInfo str, Scan *node)
448 WRITE_NODE_TYPE("SCAN");
450 _outScanInfo(str, (Scan *) node);
454 _outSeqScan(StringInfo str, SeqScan *node)
456 WRITE_NODE_TYPE("SEQSCAN");
458 _outScanInfo(str, (Scan *) node);
462 _outIndexScan(StringInfo str, IndexScan *node)
464 WRITE_NODE_TYPE("INDEXSCAN");
466 _outScanInfo(str, (Scan *) node);
468 WRITE_OIDLIST_FIELD(indxid);
469 WRITE_NODE_FIELD(indxqual);
470 WRITE_NODE_FIELD(indxqualorig);
471 WRITE_ENUM_FIELD(indxorderdir, ScanDirection);
475 _outTidScan(StringInfo str, TidScan *node)
477 WRITE_NODE_TYPE("TIDSCAN");
479 _outScanInfo(str, (Scan *) node);
481 WRITE_NODE_FIELD(tideval);
485 _outSubqueryScan(StringInfo str, SubqueryScan *node)
487 WRITE_NODE_TYPE("SUBQUERYSCAN");
489 _outScanInfo(str, (Scan *) node);
491 WRITE_NODE_FIELD(subplan);
495 _outFunctionScan(StringInfo str, FunctionScan *node)
497 WRITE_NODE_TYPE("FUNCTIONSCAN");
499 _outScanInfo(str, (Scan *) node);
503 _outJoin(StringInfo str, Join *node)
505 WRITE_NODE_TYPE("JOIN");
507 _outJoinPlanInfo(str, (Join *) node);
511 _outNestLoop(StringInfo str, NestLoop *node)
513 WRITE_NODE_TYPE("NESTLOOP");
515 _outJoinPlanInfo(str, (Join *) node);
519 _outMergeJoin(StringInfo str, MergeJoin *node)
521 WRITE_NODE_TYPE("MERGEJOIN");
523 _outJoinPlanInfo(str, (Join *) node);
525 WRITE_NODE_FIELD(mergeclauses);
529 _outHashJoin(StringInfo str, HashJoin *node)
531 WRITE_NODE_TYPE("HASHJOIN");
533 _outJoinPlanInfo(str, (Join *) node);
535 WRITE_NODE_FIELD(hashclauses);
539 _outAgg(StringInfo str, Agg *node)
541 WRITE_NODE_TYPE("AGG");
543 _outPlanInfo(str, (Plan *) node);
545 WRITE_ENUM_FIELD(aggstrategy, AggStrategy);
546 WRITE_INT_FIELD(numCols);
547 WRITE_LONG_FIELD(numGroups);
551 _outGroup(StringInfo str, Group *node)
553 WRITE_NODE_TYPE("GRP");
555 _outPlanInfo(str, (Plan *) node);
557 WRITE_INT_FIELD(numCols);
561 _outMaterial(StringInfo str, Material *node)
563 WRITE_NODE_TYPE("MATERIAL");
565 _outPlanInfo(str, (Plan *) node);
569 _outSort(StringInfo str, Sort *node)
571 WRITE_NODE_TYPE("SORT");
573 _outPlanInfo(str, (Plan *) node);
575 WRITE_INT_FIELD(keycount);
579 _outUnique(StringInfo str, Unique *node)
583 WRITE_NODE_TYPE("UNIQUE");
585 _outPlanInfo(str, (Plan *) node);
587 WRITE_INT_FIELD(numCols);
589 appendStringInfo(str, " :uniqColIdx");
590 for (i = 0; i < node->numCols; i++)
591 appendStringInfo(str, " %d", node->uniqColIdx[i]);
595 _outSetOp(StringInfo str, SetOp *node)
599 WRITE_NODE_TYPE("SETOP");
601 _outPlanInfo(str, (Plan *) node);
603 WRITE_ENUM_FIELD(cmd, SetOpCmd);
604 WRITE_INT_FIELD(numCols);
606 appendStringInfo(str, " :dupColIdx");
607 for (i = 0; i < node->numCols; i++)
608 appendStringInfo(str, " %d", node->dupColIdx[i]);
610 WRITE_INT_FIELD(flagColIdx);
614 _outLimit(StringInfo str, Limit *node)
616 WRITE_NODE_TYPE("LIMIT");
618 _outPlanInfo(str, (Plan *) node);
620 WRITE_NODE_FIELD(limitOffset);
621 WRITE_NODE_FIELD(limitCount);
625 _outHash(StringInfo str, Hash *node)
627 WRITE_NODE_TYPE("HASH");
629 _outPlanInfo(str, (Plan *) node);
631 WRITE_NODE_FIELD(hashkeys);
635 _outSubPlan(StringInfo str, SubPlan *node)
637 WRITE_NODE_TYPE("SUBPLAN");
639 WRITE_NODE_FIELD(plan);
640 WRITE_INT_FIELD(plan_id);
641 WRITE_NODE_FIELD(rtable);
642 WRITE_INTLIST_FIELD(setParam);
643 WRITE_INTLIST_FIELD(parParam);
644 WRITE_NODE_FIELD(sublink);
647 /*****************************************************************************
649 * Stuff from primnodes.h.
651 *****************************************************************************/
654 _outResdom(StringInfo str, Resdom *node)
656 WRITE_NODE_TYPE("RESDOM");
658 WRITE_INT_FIELD(resno);
659 WRITE_OID_FIELD(restype);
660 WRITE_INT_FIELD(restypmod);
661 WRITE_STRING_FIELD(resname);
662 WRITE_UINT_FIELD(ressortgroupref);
663 WRITE_UINT_FIELD(reskey);
664 WRITE_OID_FIELD(reskeyop);
665 WRITE_BOOL_FIELD(resjunk);
669 _outExpr(StringInfo str, Expr *node)
673 WRITE_NODE_TYPE("EXPR");
675 WRITE_OID_FIELD(typeOid);
677 /* do-it-yourself enum representation */
678 switch (node->opType)
702 appendStringInfo(str, " :opType ");
703 _outToken(str, opstr);
705 WRITE_NODE_FIELD(oper);
706 WRITE_NODE_FIELD(args);
710 _outVar(StringInfo str, Var *node)
712 WRITE_NODE_TYPE("VAR");
714 WRITE_UINT_FIELD(varno);
715 WRITE_INT_FIELD(varattno);
716 WRITE_OID_FIELD(vartype);
717 WRITE_INT_FIELD(vartypmod);
718 WRITE_UINT_FIELD(varlevelsup);
719 WRITE_UINT_FIELD(varnoold);
720 WRITE_INT_FIELD(varoattno);
724 _outConst(StringInfo str, Const *node)
726 WRITE_NODE_TYPE("CONST");
728 WRITE_OID_FIELD(consttype);
729 WRITE_INT_FIELD(constlen);
730 WRITE_BOOL_FIELD(constbyval);
731 WRITE_BOOL_FIELD(constisnull);
733 appendStringInfo(str, " :constvalue ");
734 if (node->constisnull)
735 appendStringInfo(str, "<>");
737 _outDatum(str, node->constvalue, node->constlen, node->constbyval);
741 _outAggref(StringInfo str, Aggref *node)
743 WRITE_NODE_TYPE("AGGREF");
745 WRITE_OID_FIELD(aggfnoid);
746 WRITE_OID_FIELD(aggtype);
747 WRITE_NODE_FIELD(target);
748 WRITE_BOOL_FIELD(aggstar);
749 WRITE_BOOL_FIELD(aggdistinct);
750 /* aggno is not saved since it is just executor state */
754 _outSubLink(StringInfo str, SubLink *node)
756 WRITE_NODE_TYPE("SUBLINK");
758 WRITE_ENUM_FIELD(subLinkType, SubLinkType);
759 WRITE_BOOL_FIELD(useor);
760 WRITE_NODE_FIELD(lefthand);
761 WRITE_NODE_FIELD(oper);
762 WRITE_NODE_FIELD(subselect);
766 _outArrayRef(StringInfo str, ArrayRef *node)
768 WRITE_NODE_TYPE("ARRAYREF");
770 WRITE_OID_FIELD(refrestype);
771 WRITE_INT_FIELD(refattrlength);
772 WRITE_INT_FIELD(refelemlength);
773 WRITE_BOOL_FIELD(refelembyval);
774 WRITE_CHAR_FIELD(refelemalign);
775 WRITE_NODE_FIELD(refupperindexpr);
776 WRITE_NODE_FIELD(reflowerindexpr);
777 WRITE_NODE_FIELD(refexpr);
778 WRITE_NODE_FIELD(refassgnexpr);
782 _outFunc(StringInfo str, Func *node)
784 WRITE_NODE_TYPE("FUNC");
786 WRITE_OID_FIELD(funcid);
787 WRITE_OID_FIELD(funcresulttype);
788 WRITE_BOOL_FIELD(funcretset);
789 WRITE_ENUM_FIELD(funcformat, CoercionForm);
793 _outOper(StringInfo str, Oper *node)
795 WRITE_NODE_TYPE("OPER");
797 WRITE_OID_FIELD(opno);
798 WRITE_OID_FIELD(opid);
799 WRITE_OID_FIELD(opresulttype);
800 WRITE_BOOL_FIELD(opretset);
804 _outParam(StringInfo str, Param *node)
806 WRITE_NODE_TYPE("PARAM");
808 WRITE_INT_FIELD(paramkind);
809 WRITE_INT_FIELD(paramid);
810 WRITE_STRING_FIELD(paramname);
811 WRITE_OID_FIELD(paramtype);
815 _outFieldSelect(StringInfo str, FieldSelect *node)
817 WRITE_NODE_TYPE("FIELDSELECT");
819 WRITE_NODE_FIELD(arg);
820 WRITE_INT_FIELD(fieldnum);
821 WRITE_OID_FIELD(resulttype);
822 WRITE_INT_FIELD(resulttypmod);
826 _outRelabelType(StringInfo str, RelabelType *node)
828 WRITE_NODE_TYPE("RELABELTYPE");
830 WRITE_NODE_FIELD(arg);
831 WRITE_OID_FIELD(resulttype);
832 WRITE_INT_FIELD(resulttypmod);
833 WRITE_ENUM_FIELD(relabelformat, CoercionForm);
837 _outRangeTblRef(StringInfo str, RangeTblRef *node)
839 WRITE_NODE_TYPE("RANGETBLREF");
841 WRITE_INT_FIELD(rtindex);
845 _outJoinExpr(StringInfo str, JoinExpr *node)
847 WRITE_NODE_TYPE("JOINEXPR");
849 WRITE_ENUM_FIELD(jointype, JoinType);
850 WRITE_BOOL_FIELD(isNatural);
851 WRITE_NODE_FIELD(larg);
852 WRITE_NODE_FIELD(rarg);
853 WRITE_NODE_FIELD(using);
854 WRITE_NODE_FIELD(quals);
855 WRITE_NODE_FIELD(alias);
856 WRITE_INT_FIELD(rtindex);
860 _outFromExpr(StringInfo str, FromExpr *node)
862 WRITE_NODE_TYPE("FROMEXPR");
864 WRITE_NODE_FIELD(fromlist);
865 WRITE_NODE_FIELD(quals);
869 _outTargetEntry(StringInfo str, TargetEntry *node)
871 WRITE_NODE_TYPE("TARGETENTRY");
873 WRITE_NODE_FIELD(resdom);
874 /* fjoin not supported ... */
875 WRITE_NODE_FIELD(expr);
879 _outAlias(StringInfo str, Alias *node)
881 WRITE_NODE_TYPE("ALIAS");
883 WRITE_STRING_FIELD(aliasname);
884 WRITE_NODE_FIELD(colnames);
888 _outRangeTblEntry(StringInfo str, RangeTblEntry *node)
890 WRITE_NODE_TYPE("RTE");
892 /* put alias + eref first to make dump more legible */
893 WRITE_NODE_FIELD(alias);
894 WRITE_NODE_FIELD(eref);
895 WRITE_ENUM_FIELD(rtekind, RTEKind);
897 switch (node->rtekind)
901 WRITE_OID_FIELD(relid);
904 WRITE_NODE_FIELD(subquery);
907 WRITE_NODE_FIELD(funcexpr);
908 WRITE_NODE_FIELD(coldeflist);
911 WRITE_ENUM_FIELD(jointype, JoinType);
912 WRITE_NODE_FIELD(joinaliasvars);
915 elog(ERROR, "bogus rte kind %d", (int) node->rtekind);
919 WRITE_BOOL_FIELD(inh);
920 WRITE_BOOL_FIELD(inFromCl);
921 WRITE_BOOL_FIELD(checkForRead);
922 WRITE_BOOL_FIELD(checkForWrite);
923 WRITE_OID_FIELD(checkAsUser);
927 * print the basic stuff of all nodes that inherit from Path
929 * Note we do NOT print the parent, else we'd be in infinite recursion
932 _outPathInfo(StringInfo str, Path *node)
934 WRITE_ENUM_FIELD(pathtype, NodeTag);
935 WRITE_FLOAT_FIELD(startup_cost, "%.2f");
936 WRITE_FLOAT_FIELD(total_cost, "%.2f");
937 WRITE_NODE_FIELD(pathkeys);
941 * print the basic stuff of all nodes that inherit from JoinPath
944 _outJoinPathInfo(StringInfo str, JoinPath *node)
946 _outPathInfo(str, (Path *) node);
948 WRITE_ENUM_FIELD(jointype, JoinType);
949 WRITE_NODE_FIELD(outerjoinpath);
950 WRITE_NODE_FIELD(innerjoinpath);
951 WRITE_NODE_FIELD(joinrestrictinfo);
955 _outPath(StringInfo str, Path *node)
957 WRITE_NODE_TYPE("PATH");
959 _outPathInfo(str, (Path *) node);
963 * IndexPath is a subclass of Path.
966 _outIndexPath(StringInfo str, IndexPath *node)
968 WRITE_NODE_TYPE("INDEXPATH");
970 _outPathInfo(str, (Path *) node);
972 WRITE_NODE_FIELD(indexinfo);
973 WRITE_NODE_FIELD(indexqual);
974 WRITE_ENUM_FIELD(indexscandir, ScanDirection);
975 WRITE_FLOAT_FIELD(rows, "%.2f");
979 _outTidPath(StringInfo str, TidPath *node)
981 WRITE_NODE_TYPE("TIDPATH");
983 _outPathInfo(str, (Path *) node);
985 WRITE_NODE_FIELD(tideval);
989 _outAppendPath(StringInfo str, AppendPath *node)
991 WRITE_NODE_TYPE("APPENDPATH");
993 _outPathInfo(str, (Path *) node);
995 WRITE_NODE_FIELD(subpaths);
999 _outResultPath(StringInfo str, ResultPath *node)
1001 WRITE_NODE_TYPE("RESULTPATH");
1003 _outPathInfo(str, (Path *) node);
1005 WRITE_NODE_FIELD(subpath);
1006 WRITE_NODE_FIELD(constantqual);
1010 _outMaterialPath(StringInfo str, MaterialPath *node)
1012 WRITE_NODE_TYPE("MATERIALPATH");
1014 _outPathInfo(str, (Path *) node);
1016 WRITE_NODE_FIELD(subpath);
1020 _outNestPath(StringInfo str, NestPath *node)
1022 WRITE_NODE_TYPE("NESTPATH");
1024 _outJoinPathInfo(str, (JoinPath *) node);
1028 _outMergePath(StringInfo str, MergePath *node)
1030 WRITE_NODE_TYPE("MERGEPATH");
1032 _outJoinPathInfo(str, (JoinPath *) node);
1034 WRITE_NODE_FIELD(path_mergeclauses);
1035 WRITE_NODE_FIELD(outersortkeys);
1036 WRITE_NODE_FIELD(innersortkeys);
1040 _outHashPath(StringInfo str, HashPath *node)
1042 WRITE_NODE_TYPE("HASHPATH");
1044 _outJoinPathInfo(str, (JoinPath *) node);
1046 WRITE_NODE_FIELD(path_hashclauses);
1050 _outPathKeyItem(StringInfo str, PathKeyItem *node)
1052 WRITE_NODE_TYPE("PATHKEYITEM");
1054 WRITE_NODE_FIELD(key);
1055 WRITE_OID_FIELD(sortop);
1059 _outRestrictInfo(StringInfo str, RestrictInfo *node)
1061 WRITE_NODE_TYPE("RESTRICTINFO");
1063 WRITE_NODE_FIELD(clause);
1064 WRITE_BOOL_FIELD(ispusheddown);
1065 WRITE_NODE_FIELD(subclauseindices);
1066 WRITE_OID_FIELD(mergejoinoperator);
1067 WRITE_OID_FIELD(left_sortop);
1068 WRITE_OID_FIELD(right_sortop);
1069 WRITE_OID_FIELD(hashjoinoperator);
1073 _outJoinInfo(StringInfo str, JoinInfo *node)
1075 WRITE_NODE_TYPE("JOININFO");
1077 WRITE_INTLIST_FIELD(unjoined_relids);
1078 WRITE_NODE_FIELD(jinfo_restrictinfo);
1082 * Print the value of a Datum given its type.
1085 _outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
1091 length = datumGetSize(value, typbyval, typlen);
1095 s = (char *) (&value);
1096 appendStringInfo(str, "%u [ ", (unsigned int) length);
1097 for (i = 0; i < (Size) sizeof(Datum); i++)
1098 appendStringInfo(str, "%d ", (int) (s[i]));
1099 appendStringInfo(str, "]");
1103 s = (char *) DatumGetPointer(value);
1104 if (!PointerIsValid(s))
1105 appendStringInfo(str, "0 [ ]");
1108 appendStringInfo(str, "%u [ ", (unsigned int) length);
1109 for (i = 0; i < length; i++)
1110 appendStringInfo(str, "%d ", (int) (s[i]));
1111 appendStringInfo(str, "]");
1117 _outAExpr(StringInfo str, A_Expr *node)
1119 WRITE_NODE_TYPE("AEXPR");
1124 appendStringInfo(str, " AND");
1127 appendStringInfo(str, " OR");
1130 appendStringInfo(str, " NOT");
1133 appendStringInfo(str, " ");
1134 WRITE_NODE_FIELD(name);
1137 appendStringInfo(str, " ??");
1141 WRITE_NODE_FIELD(lexpr);
1142 WRITE_NODE_FIELD(rexpr);
1146 _outValue(StringInfo str, Value *value)
1148 switch (value->type)
1151 appendStringInfo(str, "%ld", value->val.ival);
1156 * We assume the value is a valid numeric literal and so does
1159 appendStringInfo(str, "%s", value->val.str);
1162 appendStringInfoChar(str, '"');
1163 _outToken(str, value->val.str);
1164 appendStringInfoChar(str, '"');
1167 /* internal representation already has leading 'b' */
1168 appendStringInfo(str, "%s", value->val.str);
1171 elog(WARNING, "_outValue: don't know how to print type %d",
1178 _outRangeVar(StringInfo str, RangeVar *node)
1180 WRITE_NODE_TYPE("RANGEVAR");
1183 * we deliberately ignore catalogname here, since it is presently not
1184 * semantically meaningful
1186 WRITE_STRING_FIELD(schemaname);
1187 WRITE_STRING_FIELD(relname);
1188 WRITE_ENUM_FIELD(inhOpt, InhOption);
1189 WRITE_BOOL_FIELD(istemp);
1190 WRITE_NODE_FIELD(alias);
1194 _outColumnRef(StringInfo str, ColumnRef *node)
1196 WRITE_NODE_TYPE("COLUMNREF");
1198 WRITE_NODE_FIELD(fields);
1199 WRITE_NODE_FIELD(indirection);
1203 _outParamRef(StringInfo str, ParamRef *node)
1205 WRITE_NODE_TYPE("PARAMREF");
1207 WRITE_INT_FIELD(number);
1208 WRITE_NODE_FIELD(fields);
1209 WRITE_NODE_FIELD(indirection);
1213 _outAConst(StringInfo str, A_Const *node)
1215 WRITE_NODE_TYPE("CONST ");
1217 _outValue(str, &(node->val));
1218 WRITE_NODE_FIELD(typename);
1222 _outExprFieldSelect(StringInfo str, ExprFieldSelect *node)
1224 WRITE_NODE_TYPE("EXPRFIELDSELECT");
1226 WRITE_NODE_FIELD(arg);
1227 WRITE_NODE_FIELD(fields);
1228 WRITE_NODE_FIELD(indirection);
1232 _outConstraint(StringInfo str, Constraint *node)
1234 WRITE_NODE_TYPE("CONSTRAINT");
1236 WRITE_STRING_FIELD(name);
1238 appendStringInfo(str, " :contype ");
1239 switch (node->contype)
1241 case CONSTR_PRIMARY:
1242 appendStringInfo(str, "PRIMARY_KEY");
1243 WRITE_NODE_FIELD(keys);
1247 appendStringInfo(str, "CHECK");
1248 WRITE_NODE_FIELD(raw_expr);
1249 WRITE_STRING_FIELD(cooked_expr);
1252 case CONSTR_DEFAULT:
1253 appendStringInfo(str, "DEFAULT");
1254 WRITE_NODE_FIELD(raw_expr);
1255 WRITE_STRING_FIELD(cooked_expr);
1258 case CONSTR_NOTNULL:
1259 appendStringInfo(str, "NOT_NULL");
1263 appendStringInfo(str, "UNIQUE");
1264 WRITE_NODE_FIELD(keys);
1268 appendStringInfo(str, "<unrecognized_constraint>");
1274 _outFkConstraint(StringInfo str, FkConstraint *node)
1276 WRITE_NODE_TYPE("FKCONSTRAINT");
1278 WRITE_STRING_FIELD(constr_name);
1279 WRITE_NODE_FIELD(pktable);
1280 WRITE_NODE_FIELD(fk_attrs);
1281 WRITE_NODE_FIELD(pk_attrs);
1282 WRITE_CHAR_FIELD(fk_matchtype);
1283 WRITE_CHAR_FIELD(fk_upd_action);
1284 WRITE_CHAR_FIELD(fk_del_action);
1285 WRITE_BOOL_FIELD(deferrable);
1286 WRITE_BOOL_FIELD(initdeferred);
1287 WRITE_BOOL_FIELD(skip_validation);
1291 _outCaseExpr(StringInfo str, CaseExpr *node)
1293 WRITE_NODE_TYPE("CASE");
1295 WRITE_OID_FIELD(casetype);
1296 WRITE_NODE_FIELD(arg);
1297 WRITE_NODE_FIELD(args);
1298 WRITE_NODE_FIELD(defresult);
1302 _outCaseWhen(StringInfo str, CaseWhen *node)
1304 WRITE_NODE_TYPE("WHEN");
1306 WRITE_NODE_FIELD(expr);
1307 WRITE_NODE_FIELD(result);
1311 _outNullTest(StringInfo str, NullTest *node)
1313 WRITE_NODE_TYPE("NULLTEST");
1315 WRITE_NODE_FIELD(arg);
1316 WRITE_ENUM_FIELD(nulltesttype, NullTestType);
1320 _outBooleanTest(StringInfo str, BooleanTest *node)
1322 WRITE_NODE_TYPE("BOOLEANTEST");
1324 WRITE_NODE_FIELD(arg);
1325 WRITE_ENUM_FIELD(booltesttype, BoolTestType);
1329 _outConstraintTest(StringInfo str, ConstraintTest *node)
1331 WRITE_NODE_TYPE("CONSTRAINTTEST");
1333 WRITE_NODE_FIELD(arg);
1334 WRITE_ENUM_FIELD(testtype, ConstraintTestType);
1335 WRITE_STRING_FIELD(name);
1336 WRITE_STRING_FIELD(domname);
1337 WRITE_NODE_FIELD(check_expr);
1341 _outDomainConstraintValue(StringInfo str, DomainConstraintValue *node)
1343 WRITE_NODE_TYPE("DOMAINCONSTRAINTVALUE");
1347 _outConstraintTestValue(StringInfo str, ConstraintTestValue *node)
1349 WRITE_NODE_TYPE("CONSTRAINTTESTVALUE");
1351 WRITE_OID_FIELD(typeId);
1352 WRITE_INT_FIELD(typeMod);
1358 * converts a Node into ascii string and append it to 'str'
1361 _outNode(StringInfo str, void *obj)
1365 appendStringInfo(str, "<>");
1373 appendStringInfoChar(str, '(');
1374 foreach(l, (List *) obj)
1376 _outNode(str, lfirst(l));
1378 appendStringInfoChar(str, ' ');
1380 appendStringInfoChar(str, ')');
1382 else if (IsA(obj, Integer) ||
1385 IsA(obj, BitString))
1387 /* nodeRead does not want to see { } around these! */
1388 _outValue(str, obj);
1392 appendStringInfoChar(str, '{');
1393 switch (nodeTag(obj))
1396 _outCreateStmt(str, obj);
1399 _outIndexStmt(str, obj);
1402 _outNotifyStmt(str, obj);
1405 _outSelectStmt(str, obj);
1408 _outColumnDef(str, obj);
1411 _outTypeName(str, obj);
1414 _outTypeCast(str, obj);
1417 _outIndexElem(str, obj);
1420 _outQuery(str, obj);
1423 _outSortClause(str, obj);
1426 _outGroupClause(str, obj);
1428 case T_SetOperationStmt:
1429 _outSetOperationStmt(str, obj);
1435 _outResult(str, obj);
1438 _outAppend(str, obj);
1444 _outNestLoop(str, obj);
1447 _outMergeJoin(str, obj);
1450 _outHashJoin(str, obj);
1456 _outSeqScan(str, obj);
1459 _outIndexScan(str, obj);
1462 _outTidScan(str, obj);
1464 case T_SubqueryScan:
1465 _outSubqueryScan(str, obj);
1467 case T_FunctionScan:
1468 _outFunctionScan(str, obj);
1471 _outMaterial(str, obj);
1480 _outGroup(str, obj);
1483 _outUnique(str, obj);
1486 _outSetOp(str, obj);
1489 _outLimit(str, obj);
1495 _outSubPlan(str, obj);
1498 _outResdom(str, obj);
1507 _outConst(str, obj);
1510 _outAggref(str, obj);
1513 _outSubLink(str, obj);
1516 _outArrayRef(str, obj);
1525 _outParam(str, obj);
1528 _outFieldSelect(str, obj);
1531 _outRelabelType(str, obj);
1534 _outRangeTblRef(str, obj);
1537 _outFromExpr(str, obj);
1540 _outJoinExpr(str, obj);
1543 _outTargetEntry(str, obj);
1546 _outAlias(str, obj);
1548 case T_RangeTblEntry:
1549 _outRangeTblEntry(str, obj);
1555 _outIndexPath(str, obj);
1558 _outTidPath(str, obj);
1561 _outAppendPath(str, obj);
1564 _outResultPath(str, obj);
1566 case T_MaterialPath:
1567 _outMaterialPath(str, obj);
1570 _outNestPath(str, obj);
1573 _outMergePath(str, obj);
1576 _outHashPath(str, obj);
1579 _outPathKeyItem(str, obj);
1581 case T_RestrictInfo:
1582 _outRestrictInfo(str, obj);
1585 _outJoinInfo(str, obj);
1588 _outAExpr(str, obj);
1591 _outRangeVar(str, obj);
1594 _outColumnRef(str, obj);
1597 _outParamRef(str, obj);
1600 _outAConst(str, obj);
1602 case T_ExprFieldSelect:
1603 _outExprFieldSelect(str, obj);
1606 _outConstraint(str, obj);
1608 case T_FkConstraint:
1609 _outFkConstraint(str, obj);
1612 _outCaseExpr(str, obj);
1615 _outCaseWhen(str, obj);
1618 _outNullTest(str, obj);
1621 _outBooleanTest(str, obj);
1623 case T_ConstraintTest:
1624 _outConstraintTest(str, obj);
1626 case T_ConstraintTestValue:
1627 _outConstraintTestValue(str, obj);
1630 _outFuncCall(str, obj);
1632 case T_DomainConstraintValue:
1633 _outDomainConstraintValue(str, obj);
1637 elog(WARNING, "_outNode: don't know how to print type %d",
1641 appendStringInfoChar(str, '}');
1647 * returns the ascii representation of the Node as a palloc'd string
1650 nodeToString(void *obj)
1654 /* see stringinfo.h for an explanation of this maneuver */
1655 initStringInfo(&str);
1656 _outNode(&str, obj);