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.215 2003/08/04 00:43:19 momjian 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 "utils/datum.h"
34 * Macros to simplify output of different kinds of fields. Use these
35 * wherever possible to reduce the chance for silly typos. Note that these
36 * hard-wire conventions about the names of the local variables in an Out
40 /* Write the label for the node type */
41 #define WRITE_NODE_TYPE(nodelabel) \
42 appendStringInfoString(str, nodelabel)
44 /* Write an integer field (anything written as ":fldname %d") */
45 #define WRITE_INT_FIELD(fldname) \
46 appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname)
48 /* Write an unsigned integer field (anything written as ":fldname %u") */
49 #define WRITE_UINT_FIELD(fldname) \
50 appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
52 /* Write an OID field (don't hard-wire assumption that OID is same as uint) */
53 #define WRITE_OID_FIELD(fldname) \
54 appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
56 /* Write a long-integer field */
57 #define WRITE_LONG_FIELD(fldname) \
58 appendStringInfo(str, " :" CppAsString(fldname) " %ld", node->fldname)
60 /* Write a char field (ie, one ascii character) */
61 #define WRITE_CHAR_FIELD(fldname) \
62 appendStringInfo(str, " :" CppAsString(fldname) " %c", node->fldname)
64 /* Write an enumerated-type field as an integer code */
65 #define WRITE_ENUM_FIELD(fldname, enumtype) \
66 appendStringInfo(str, " :" CppAsString(fldname) " %d", \
69 /* Write a float field --- caller must give format to define precision */
70 #define WRITE_FLOAT_FIELD(fldname,format) \
71 appendStringInfo(str, " :" CppAsString(fldname) " " format, node->fldname)
73 /* Write a boolean field */
74 #define WRITE_BOOL_FIELD(fldname) \
75 appendStringInfo(str, " :" CppAsString(fldname) " %s", \
76 booltostr(node->fldname))
78 /* Write a character-string (possibly NULL) field */
79 #define WRITE_STRING_FIELD(fldname) \
80 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
81 _outToken(str, node->fldname))
83 /* Write a Node field */
84 #define WRITE_NODE_FIELD(fldname) \
85 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
86 _outNode(str, node->fldname))
88 /* Write an integer-list field */
89 #define WRITE_INTLIST_FIELD(fldname) \
90 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
91 _outIntList(str, node->fldname))
93 /* Write an OID-list field */
94 #define WRITE_OIDLIST_FIELD(fldname) \
95 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
96 _outOidList(str, node->fldname))
98 /* Write a bitmapset field */
99 #define WRITE_BITMAPSET_FIELD(fldname) \
100 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
101 _outBitmapset(str, node->fldname))
104 #define booltostr(x) ((x) ? "true" : "false")
106 static void _outNode(StringInfo str, void *obj);
111 * Convert an ordinary string (eg, an identifier) into a form that
112 * will be decoded back to a plain token by read.c's functions.
114 * If a null or empty string is given, it is encoded as "<>".
117 _outToken(StringInfo str, char *s)
119 if (s == NULL || *s == '\0')
121 appendStringInfo(str, "<>");
126 * Look for characters or patterns that are treated specially by
127 * read.c (either in pg_strtok() or in nodeRead()), and therefore need
128 * a protective backslash.
130 /* These characters only need to be quoted at the start of the string */
134 isdigit((unsigned char) *s) ||
135 ((*s == '+' || *s == '-') &&
136 (isdigit((unsigned char) s[1]) || s[1] == '.')))
137 appendStringInfoChar(str, '\\');
140 /* These chars must be backslashed anywhere in the string */
141 if (*s == ' ' || *s == '\n' || *s == '\t' ||
142 *s == '(' || *s == ')' || *s == '{' || *s == '}' ||
144 appendStringInfoChar(str, '\\');
145 appendStringInfoChar(str, *s++);
151 * converts a List of integers
154 _outIntList(StringInfo str, List *list)
158 appendStringInfoChar(str, '(');
160 appendStringInfo(str, " %d", lfirsti(l));
161 appendStringInfoChar(str, ')');
166 * converts a List of OIDs
169 _outOidList(StringInfo str, List *list)
173 appendStringInfoChar(str, '(');
175 appendStringInfo(str, " %u", lfirsto(l));
176 appendStringInfoChar(str, ')');
181 * converts a bitmap set of integers
183 * Note: for historical reasons, the output is formatted exactly like
184 * an integer List would be.
187 _outBitmapset(StringInfo str, Bitmapset * bms)
192 appendStringInfoChar(str, '(');
193 tmpset = bms_copy(bms);
194 while ((x = bms_first_member(tmpset)) >= 0)
195 appendStringInfo(str, " %d", x);
197 appendStringInfoChar(str, ')');
201 * Print the value of a Datum given its type.
204 _outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
210 length = datumGetSize(value, typbyval, typlen);
214 s = (char *) (&value);
215 appendStringInfo(str, "%u [ ", (unsigned int) length);
216 for (i = 0; i < (Size) sizeof(Datum); i++)
217 appendStringInfo(str, "%d ", (int) (s[i]));
218 appendStringInfo(str, "]");
222 s = (char *) DatumGetPointer(value);
223 if (!PointerIsValid(s))
224 appendStringInfo(str, "0 [ ]");
227 appendStringInfo(str, "%u [ ", (unsigned int) length);
228 for (i = 0; i < length; i++)
229 appendStringInfo(str, "%d ", (int) (s[i]));
230 appendStringInfo(str, "]");
237 * Stuff from plannodes.h
241 * print the basic stuff of all nodes that inherit from Plan
244 _outPlanInfo(StringInfo str, Plan *node)
246 WRITE_FLOAT_FIELD(startup_cost, "%.2f");
247 WRITE_FLOAT_FIELD(total_cost, "%.2f");
248 WRITE_FLOAT_FIELD(plan_rows, "%.0f");
249 WRITE_INT_FIELD(plan_width);
250 WRITE_NODE_FIELD(targetlist);
251 WRITE_NODE_FIELD(qual);
252 WRITE_NODE_FIELD(lefttree);
253 WRITE_NODE_FIELD(righttree);
254 WRITE_NODE_FIELD(initPlan);
255 WRITE_BITMAPSET_FIELD(extParam);
256 WRITE_BITMAPSET_FIELD(allParam);
257 WRITE_INT_FIELD(nParamExec);
261 * print the basic stuff of all nodes that inherit from Scan
264 _outScanInfo(StringInfo str, Scan *node)
266 _outPlanInfo(str, (Plan *) node);
268 WRITE_UINT_FIELD(scanrelid);
272 * print the basic stuff of all nodes that inherit from Join
275 _outJoinPlanInfo(StringInfo str, Join *node)
277 _outPlanInfo(str, (Plan *) node);
279 WRITE_ENUM_FIELD(jointype, JoinType);
280 WRITE_NODE_FIELD(joinqual);
285 _outPlan(StringInfo str, Plan *node)
287 WRITE_NODE_TYPE("PLAN");
289 _outPlanInfo(str, (Plan *) node);
293 _outResult(StringInfo str, Result *node)
295 WRITE_NODE_TYPE("RESULT");
297 _outPlanInfo(str, (Plan *) node);
299 WRITE_NODE_FIELD(resconstantqual);
303 _outAppend(StringInfo str, Append *node)
305 WRITE_NODE_TYPE("APPEND");
307 _outPlanInfo(str, (Plan *) node);
309 WRITE_NODE_FIELD(appendplans);
310 WRITE_BOOL_FIELD(isTarget);
314 _outScan(StringInfo str, Scan *node)
316 WRITE_NODE_TYPE("SCAN");
318 _outScanInfo(str, (Scan *) node);
322 _outSeqScan(StringInfo str, SeqScan *node)
324 WRITE_NODE_TYPE("SEQSCAN");
326 _outScanInfo(str, (Scan *) node);
330 _outIndexScan(StringInfo str, IndexScan *node)
332 WRITE_NODE_TYPE("INDEXSCAN");
334 _outScanInfo(str, (Scan *) node);
336 WRITE_OIDLIST_FIELD(indxid);
337 WRITE_NODE_FIELD(indxqual);
338 WRITE_NODE_FIELD(indxqualorig);
339 WRITE_ENUM_FIELD(indxorderdir, ScanDirection);
343 _outTidScan(StringInfo str, TidScan *node)
345 WRITE_NODE_TYPE("TIDSCAN");
347 _outScanInfo(str, (Scan *) node);
349 WRITE_NODE_FIELD(tideval);
353 _outSubqueryScan(StringInfo str, SubqueryScan *node)
355 WRITE_NODE_TYPE("SUBQUERYSCAN");
357 _outScanInfo(str, (Scan *) node);
359 WRITE_NODE_FIELD(subplan);
363 _outFunctionScan(StringInfo str, FunctionScan *node)
365 WRITE_NODE_TYPE("FUNCTIONSCAN");
367 _outScanInfo(str, (Scan *) node);
371 _outJoin(StringInfo str, Join *node)
373 WRITE_NODE_TYPE("JOIN");
375 _outJoinPlanInfo(str, (Join *) node);
379 _outNestLoop(StringInfo str, NestLoop *node)
381 WRITE_NODE_TYPE("NESTLOOP");
383 _outJoinPlanInfo(str, (Join *) node);
387 _outMergeJoin(StringInfo str, MergeJoin *node)
389 WRITE_NODE_TYPE("MERGEJOIN");
391 _outJoinPlanInfo(str, (Join *) node);
393 WRITE_NODE_FIELD(mergeclauses);
397 _outHashJoin(StringInfo str, HashJoin *node)
399 WRITE_NODE_TYPE("HASHJOIN");
401 _outJoinPlanInfo(str, (Join *) node);
403 WRITE_NODE_FIELD(hashclauses);
407 _outAgg(StringInfo str, Agg *node)
409 WRITE_NODE_TYPE("AGG");
411 _outPlanInfo(str, (Plan *) node);
413 WRITE_ENUM_FIELD(aggstrategy, AggStrategy);
414 WRITE_INT_FIELD(numCols);
415 WRITE_LONG_FIELD(numGroups);
419 _outGroup(StringInfo str, Group *node)
423 WRITE_NODE_TYPE("GROUP");
425 _outPlanInfo(str, (Plan *) node);
427 WRITE_INT_FIELD(numCols);
429 appendStringInfo(str, " :grpColIdx");
430 for (i = 0; i < node->numCols; i++)
431 appendStringInfo(str, " %d", node->grpColIdx[i]);
435 _outMaterial(StringInfo str, Material *node)
437 WRITE_NODE_TYPE("MATERIAL");
439 _outPlanInfo(str, (Plan *) node);
443 _outSort(StringInfo str, Sort *node)
447 WRITE_NODE_TYPE("SORT");
449 _outPlanInfo(str, (Plan *) node);
451 WRITE_INT_FIELD(numCols);
453 appendStringInfo(str, " :sortColIdx");
454 for (i = 0; i < node->numCols; i++)
455 appendStringInfo(str, " %d", node->sortColIdx[i]);
457 appendStringInfo(str, " :sortOperators");
458 for (i = 0; i < node->numCols; i++)
459 appendStringInfo(str, " %u", node->sortOperators[i]);
463 _outUnique(StringInfo str, Unique *node)
467 WRITE_NODE_TYPE("UNIQUE");
469 _outPlanInfo(str, (Plan *) node);
471 WRITE_INT_FIELD(numCols);
473 appendStringInfo(str, " :uniqColIdx");
474 for (i = 0; i < node->numCols; i++)
475 appendStringInfo(str, " %d", node->uniqColIdx[i]);
479 _outSetOp(StringInfo str, SetOp *node)
483 WRITE_NODE_TYPE("SETOP");
485 _outPlanInfo(str, (Plan *) node);
487 WRITE_ENUM_FIELD(cmd, SetOpCmd);
488 WRITE_INT_FIELD(numCols);
490 appendStringInfo(str, " :dupColIdx");
491 for (i = 0; i < node->numCols; i++)
492 appendStringInfo(str, " %d", node->dupColIdx[i]);
494 WRITE_INT_FIELD(flagColIdx);
498 _outLimit(StringInfo str, Limit *node)
500 WRITE_NODE_TYPE("LIMIT");
502 _outPlanInfo(str, (Plan *) node);
504 WRITE_NODE_FIELD(limitOffset);
505 WRITE_NODE_FIELD(limitCount);
509 _outHash(StringInfo str, Hash *node)
511 WRITE_NODE_TYPE("HASH");
513 _outPlanInfo(str, (Plan *) node);
515 WRITE_NODE_FIELD(hashkeys);
518 /*****************************************************************************
520 * Stuff from primnodes.h.
522 *****************************************************************************/
525 _outResdom(StringInfo str, Resdom *node)
527 WRITE_NODE_TYPE("RESDOM");
529 WRITE_INT_FIELD(resno);
530 WRITE_OID_FIELD(restype);
531 WRITE_INT_FIELD(restypmod);
532 WRITE_STRING_FIELD(resname);
533 WRITE_UINT_FIELD(ressortgroupref);
534 WRITE_OID_FIELD(resorigtbl);
535 WRITE_INT_FIELD(resorigcol);
536 WRITE_BOOL_FIELD(resjunk);
540 _outAlias(StringInfo str, Alias *node)
542 WRITE_NODE_TYPE("ALIAS");
544 WRITE_STRING_FIELD(aliasname);
545 WRITE_NODE_FIELD(colnames);
549 _outRangeVar(StringInfo str, RangeVar *node)
551 WRITE_NODE_TYPE("RANGEVAR");
554 * we deliberately ignore catalogname here, since it is presently not
555 * semantically meaningful
557 WRITE_STRING_FIELD(schemaname);
558 WRITE_STRING_FIELD(relname);
559 WRITE_ENUM_FIELD(inhOpt, InhOption);
560 WRITE_BOOL_FIELD(istemp);
561 WRITE_NODE_FIELD(alias);
565 _outVar(StringInfo str, Var *node)
567 WRITE_NODE_TYPE("VAR");
569 WRITE_UINT_FIELD(varno);
570 WRITE_INT_FIELD(varattno);
571 WRITE_OID_FIELD(vartype);
572 WRITE_INT_FIELD(vartypmod);
573 WRITE_UINT_FIELD(varlevelsup);
574 WRITE_UINT_FIELD(varnoold);
575 WRITE_INT_FIELD(varoattno);
579 _outConst(StringInfo str, Const *node)
581 WRITE_NODE_TYPE("CONST");
583 WRITE_OID_FIELD(consttype);
584 WRITE_INT_FIELD(constlen);
585 WRITE_BOOL_FIELD(constbyval);
586 WRITE_BOOL_FIELD(constisnull);
588 appendStringInfo(str, " :constvalue ");
589 if (node->constisnull)
590 appendStringInfo(str, "<>");
592 _outDatum(str, node->constvalue, node->constlen, node->constbyval);
596 _outParam(StringInfo str, Param *node)
598 WRITE_NODE_TYPE("PARAM");
600 WRITE_INT_FIELD(paramkind);
601 WRITE_INT_FIELD(paramid);
602 WRITE_STRING_FIELD(paramname);
603 WRITE_OID_FIELD(paramtype);
607 _outAggref(StringInfo str, Aggref *node)
609 WRITE_NODE_TYPE("AGGREF");
611 WRITE_OID_FIELD(aggfnoid);
612 WRITE_OID_FIELD(aggtype);
613 WRITE_NODE_FIELD(target);
614 WRITE_UINT_FIELD(agglevelsup);
615 WRITE_BOOL_FIELD(aggstar);
616 WRITE_BOOL_FIELD(aggdistinct);
620 _outArrayRef(StringInfo str, ArrayRef *node)
622 WRITE_NODE_TYPE("ARRAYREF");
624 WRITE_OID_FIELD(refrestype);
625 WRITE_OID_FIELD(refarraytype);
626 WRITE_OID_FIELD(refelemtype);
627 WRITE_NODE_FIELD(refupperindexpr);
628 WRITE_NODE_FIELD(reflowerindexpr);
629 WRITE_NODE_FIELD(refexpr);
630 WRITE_NODE_FIELD(refassgnexpr);
634 _outFuncExpr(StringInfo str, FuncExpr * node)
636 WRITE_NODE_TYPE("FUNCEXPR");
638 WRITE_OID_FIELD(funcid);
639 WRITE_OID_FIELD(funcresulttype);
640 WRITE_BOOL_FIELD(funcretset);
641 WRITE_ENUM_FIELD(funcformat, CoercionForm);
642 WRITE_NODE_FIELD(args);
646 _outOpExpr(StringInfo str, OpExpr * node)
648 WRITE_NODE_TYPE("OPEXPR");
650 WRITE_OID_FIELD(opno);
651 WRITE_OID_FIELD(opfuncid);
652 WRITE_OID_FIELD(opresulttype);
653 WRITE_BOOL_FIELD(opretset);
654 WRITE_NODE_FIELD(args);
658 _outDistinctExpr(StringInfo str, DistinctExpr * node)
660 WRITE_NODE_TYPE("DISTINCTEXPR");
662 WRITE_OID_FIELD(opno);
663 WRITE_OID_FIELD(opfuncid);
664 WRITE_OID_FIELD(opresulttype);
665 WRITE_BOOL_FIELD(opretset);
666 WRITE_NODE_FIELD(args);
670 _outScalarArrayOpExpr(StringInfo str, ScalarArrayOpExpr * node)
672 WRITE_NODE_TYPE("SCALARARRAYOPEXPR");
674 WRITE_OID_FIELD(opno);
675 WRITE_OID_FIELD(opfuncid);
676 WRITE_BOOL_FIELD(useOr);
677 WRITE_NODE_FIELD(args);
681 _outBoolExpr(StringInfo str, BoolExpr * node)
685 WRITE_NODE_TYPE("BOOLEXPR");
687 /* do-it-yourself enum representation */
688 switch (node->boolop)
700 appendStringInfo(str, " :boolop ");
701 _outToken(str, opstr);
703 WRITE_NODE_FIELD(args);
707 _outSubLink(StringInfo str, SubLink *node)
709 WRITE_NODE_TYPE("SUBLINK");
711 WRITE_ENUM_FIELD(subLinkType, SubLinkType);
712 WRITE_BOOL_FIELD(useOr);
713 WRITE_NODE_FIELD(lefthand);
714 WRITE_NODE_FIELD(operName);
715 WRITE_OIDLIST_FIELD(operOids);
716 WRITE_NODE_FIELD(subselect);
720 _outSubPlan(StringInfo str, SubPlan *node)
722 WRITE_NODE_TYPE("SUBPLAN");
724 WRITE_ENUM_FIELD(subLinkType, SubLinkType);
725 WRITE_BOOL_FIELD(useOr);
726 WRITE_NODE_FIELD(exprs);
727 WRITE_INTLIST_FIELD(paramIds);
728 WRITE_NODE_FIELD(plan);
729 WRITE_INT_FIELD(plan_id);
730 WRITE_NODE_FIELD(rtable);
731 WRITE_BOOL_FIELD(useHashTable);
732 WRITE_BOOL_FIELD(unknownEqFalse);
733 WRITE_INTLIST_FIELD(setParam);
734 WRITE_INTLIST_FIELD(parParam);
735 WRITE_NODE_FIELD(args);
739 _outFieldSelect(StringInfo str, FieldSelect *node)
741 WRITE_NODE_TYPE("FIELDSELECT");
743 WRITE_NODE_FIELD(arg);
744 WRITE_INT_FIELD(fieldnum);
745 WRITE_OID_FIELD(resulttype);
746 WRITE_INT_FIELD(resulttypmod);
750 _outRelabelType(StringInfo str, RelabelType *node)
752 WRITE_NODE_TYPE("RELABELTYPE");
754 WRITE_NODE_FIELD(arg);
755 WRITE_OID_FIELD(resulttype);
756 WRITE_INT_FIELD(resulttypmod);
757 WRITE_ENUM_FIELD(relabelformat, CoercionForm);
761 _outCaseExpr(StringInfo str, CaseExpr *node)
763 WRITE_NODE_TYPE("CASE");
765 WRITE_OID_FIELD(casetype);
766 WRITE_NODE_FIELD(arg);
767 WRITE_NODE_FIELD(args);
768 WRITE_NODE_FIELD(defresult);
772 _outCaseWhen(StringInfo str, CaseWhen *node)
774 WRITE_NODE_TYPE("WHEN");
776 WRITE_NODE_FIELD(expr);
777 WRITE_NODE_FIELD(result);
781 _outArrayExpr(StringInfo str, ArrayExpr * node)
783 WRITE_NODE_TYPE("ARRAY");
785 WRITE_OID_FIELD(array_typeid);
786 WRITE_OID_FIELD(element_typeid);
787 WRITE_NODE_FIELD(elements);
788 WRITE_INT_FIELD(ndims);
792 _outCoalesceExpr(StringInfo str, CoalesceExpr * node)
794 WRITE_NODE_TYPE("COALESCE");
796 WRITE_OID_FIELD(coalescetype);
797 WRITE_NODE_FIELD(args);
801 _outNullIfExpr(StringInfo str, NullIfExpr * node)
803 WRITE_NODE_TYPE("NULLIFEXPR");
805 WRITE_OID_FIELD(opno);
806 WRITE_OID_FIELD(opfuncid);
807 WRITE_OID_FIELD(opresulttype);
808 WRITE_BOOL_FIELD(opretset);
809 WRITE_NODE_FIELD(args);
813 _outNullTest(StringInfo str, NullTest *node)
815 WRITE_NODE_TYPE("NULLTEST");
817 WRITE_NODE_FIELD(arg);
818 WRITE_ENUM_FIELD(nulltesttype, NullTestType);
822 _outBooleanTest(StringInfo str, BooleanTest *node)
824 WRITE_NODE_TYPE("BOOLEANTEST");
826 WRITE_NODE_FIELD(arg);
827 WRITE_ENUM_FIELD(booltesttype, BoolTestType);
831 _outCoerceToDomain(StringInfo str, CoerceToDomain * node)
833 WRITE_NODE_TYPE("COERCETODOMAIN");
835 WRITE_NODE_FIELD(arg);
836 WRITE_OID_FIELD(resulttype);
837 WRITE_INT_FIELD(resulttypmod);
838 WRITE_ENUM_FIELD(coercionformat, CoercionForm);
842 _outCoerceToDomainValue(StringInfo str, CoerceToDomainValue * node)
844 WRITE_NODE_TYPE("COERCETODOMAINVALUE");
846 WRITE_OID_FIELD(typeId);
847 WRITE_INT_FIELD(typeMod);
851 _outSetToDefault(StringInfo str, SetToDefault * node)
853 WRITE_NODE_TYPE("SETTODEFAULT");
855 WRITE_OID_FIELD(typeId);
856 WRITE_INT_FIELD(typeMod);
860 _outTargetEntry(StringInfo str, TargetEntry *node)
862 WRITE_NODE_TYPE("TARGETENTRY");
864 WRITE_NODE_FIELD(resdom);
865 WRITE_NODE_FIELD(expr);
869 _outRangeTblRef(StringInfo str, RangeTblRef *node)
871 WRITE_NODE_TYPE("RANGETBLREF");
873 WRITE_INT_FIELD(rtindex);
877 _outJoinExpr(StringInfo str, JoinExpr *node)
879 WRITE_NODE_TYPE("JOINEXPR");
881 WRITE_ENUM_FIELD(jointype, JoinType);
882 WRITE_BOOL_FIELD(isNatural);
883 WRITE_NODE_FIELD(larg);
884 WRITE_NODE_FIELD(rarg);
885 WRITE_NODE_FIELD(using);
886 WRITE_NODE_FIELD(quals);
887 WRITE_NODE_FIELD(alias);
888 WRITE_INT_FIELD(rtindex);
892 _outFromExpr(StringInfo str, FromExpr *node)
894 WRITE_NODE_TYPE("FROMEXPR");
896 WRITE_NODE_FIELD(fromlist);
897 WRITE_NODE_FIELD(quals);
900 /*****************************************************************************
902 * Stuff from relation.h.
904 *****************************************************************************/
907 * print the basic stuff of all nodes that inherit from Path
909 * Note we do NOT print the parent, else we'd be in infinite recursion
912 _outPathInfo(StringInfo str, Path *node)
914 WRITE_ENUM_FIELD(pathtype, NodeTag);
915 WRITE_FLOAT_FIELD(startup_cost, "%.2f");
916 WRITE_FLOAT_FIELD(total_cost, "%.2f");
917 WRITE_NODE_FIELD(pathkeys);
921 * print the basic stuff of all nodes that inherit from JoinPath
924 _outJoinPathInfo(StringInfo str, JoinPath *node)
926 _outPathInfo(str, (Path *) node);
928 WRITE_ENUM_FIELD(jointype, JoinType);
929 WRITE_NODE_FIELD(outerjoinpath);
930 WRITE_NODE_FIELD(innerjoinpath);
931 WRITE_NODE_FIELD(joinrestrictinfo);
935 _outPath(StringInfo str, Path *node)
937 WRITE_NODE_TYPE("PATH");
939 _outPathInfo(str, (Path *) node);
943 * IndexPath is a subclass of Path.
946 _outIndexPath(StringInfo str, IndexPath *node)
948 WRITE_NODE_TYPE("INDEXPATH");
950 _outPathInfo(str, (Path *) node);
952 WRITE_NODE_FIELD(indexinfo);
953 WRITE_NODE_FIELD(indexqual);
954 WRITE_NODE_FIELD(indexjoinclauses);
955 WRITE_ENUM_FIELD(indexscandir, ScanDirection);
956 WRITE_FLOAT_FIELD(rows, "%.2f");
960 _outTidPath(StringInfo str, TidPath *node)
962 WRITE_NODE_TYPE("TIDPATH");
964 _outPathInfo(str, (Path *) node);
966 WRITE_NODE_FIELD(tideval);
970 _outAppendPath(StringInfo str, AppendPath *node)
972 WRITE_NODE_TYPE("APPENDPATH");
974 _outPathInfo(str, (Path *) node);
976 WRITE_NODE_FIELD(subpaths);
980 _outResultPath(StringInfo str, ResultPath * node)
982 WRITE_NODE_TYPE("RESULTPATH");
984 _outPathInfo(str, (Path *) node);
986 WRITE_NODE_FIELD(subpath);
987 WRITE_NODE_FIELD(constantqual);
991 _outMaterialPath(StringInfo str, MaterialPath * node)
993 WRITE_NODE_TYPE("MATERIALPATH");
995 _outPathInfo(str, (Path *) node);
997 WRITE_NODE_FIELD(subpath);
1001 _outUniquePath(StringInfo str, UniquePath * node)
1003 WRITE_NODE_TYPE("UNIQUEPATH");
1005 _outPathInfo(str, (Path *) node);
1007 WRITE_NODE_FIELD(subpath);
1008 WRITE_BOOL_FIELD(use_hash);
1009 WRITE_FLOAT_FIELD(rows, "%.0f");
1013 _outNestPath(StringInfo str, NestPath *node)
1015 WRITE_NODE_TYPE("NESTPATH");
1017 _outJoinPathInfo(str, (JoinPath *) node);
1021 _outMergePath(StringInfo str, MergePath *node)
1023 WRITE_NODE_TYPE("MERGEPATH");
1025 _outJoinPathInfo(str, (JoinPath *) node);
1027 WRITE_NODE_FIELD(path_mergeclauses);
1028 WRITE_NODE_FIELD(outersortkeys);
1029 WRITE_NODE_FIELD(innersortkeys);
1033 _outHashPath(StringInfo str, HashPath *node)
1035 WRITE_NODE_TYPE("HASHPATH");
1037 _outJoinPathInfo(str, (JoinPath *) node);
1039 WRITE_NODE_FIELD(path_hashclauses);
1043 _outPathKeyItem(StringInfo str, PathKeyItem *node)
1045 WRITE_NODE_TYPE("PATHKEYITEM");
1047 WRITE_NODE_FIELD(key);
1048 WRITE_OID_FIELD(sortop);
1052 _outRestrictInfo(StringInfo str, RestrictInfo *node)
1054 WRITE_NODE_TYPE("RESTRICTINFO");
1056 /* NB: this isn't a complete set of fields */
1057 WRITE_NODE_FIELD(clause);
1058 WRITE_BOOL_FIELD(ispusheddown);
1059 WRITE_NODE_FIELD(subclauseindices);
1060 WRITE_BITMAPSET_FIELD(left_relids);
1061 WRITE_BITMAPSET_FIELD(right_relids);
1062 WRITE_OID_FIELD(mergejoinoperator);
1063 WRITE_OID_FIELD(left_sortop);
1064 WRITE_OID_FIELD(right_sortop);
1065 WRITE_NODE_FIELD(left_pathkey);
1066 WRITE_NODE_FIELD(right_pathkey);
1067 WRITE_OID_FIELD(hashjoinoperator);
1071 _outJoinInfo(StringInfo str, JoinInfo *node)
1073 WRITE_NODE_TYPE("JOININFO");
1075 WRITE_BITMAPSET_FIELD(unjoined_relids);
1076 WRITE_NODE_FIELD(jinfo_restrictinfo);
1080 _outInClauseInfo(StringInfo str, InClauseInfo * node)
1082 WRITE_NODE_TYPE("INCLAUSEINFO");
1084 WRITE_BITMAPSET_FIELD(lefthand);
1085 WRITE_BITMAPSET_FIELD(righthand);
1086 WRITE_NODE_FIELD(sub_targetlist);
1089 /*****************************************************************************
1091 * Stuff from parsenodes.h.
1093 *****************************************************************************/
1096 _outCreateStmt(StringInfo str, CreateStmt *node)
1098 WRITE_NODE_TYPE("CREATE");
1100 WRITE_NODE_FIELD(relation);
1101 WRITE_NODE_FIELD(tableElts);
1102 WRITE_NODE_FIELD(inhRelations);
1103 WRITE_NODE_FIELD(constraints);
1104 WRITE_BOOL_FIELD(hasoids);
1105 WRITE_ENUM_FIELD(oncommit, OnCommitAction);
1109 _outIndexStmt(StringInfo str, IndexStmt *node)
1111 WRITE_NODE_TYPE("INDEX");
1113 WRITE_STRING_FIELD(idxname);
1114 WRITE_NODE_FIELD(relation);
1115 WRITE_STRING_FIELD(accessMethod);
1116 WRITE_NODE_FIELD(indexParams);
1117 WRITE_NODE_FIELD(whereClause);
1118 WRITE_NODE_FIELD(rangetable);
1119 WRITE_BOOL_FIELD(unique);
1120 WRITE_BOOL_FIELD(primary);
1121 WRITE_BOOL_FIELD(isconstraint);
1125 _outNotifyStmt(StringInfo str, NotifyStmt *node)
1127 WRITE_NODE_TYPE("NOTIFY");
1129 WRITE_NODE_FIELD(relation);
1133 _outDeclareCursorStmt(StringInfo str, DeclareCursorStmt * node)
1135 WRITE_NODE_TYPE("DECLARECURSOR");
1137 WRITE_STRING_FIELD(portalname);
1138 WRITE_INT_FIELD(options);
1139 WRITE_NODE_FIELD(query);
1143 _outSelectStmt(StringInfo str, SelectStmt *node)
1145 WRITE_NODE_TYPE("SELECT");
1147 /* XXX this is pretty durn incomplete */
1148 WRITE_NODE_FIELD(whereClause);
1152 _outFuncCall(StringInfo str, FuncCall *node)
1154 WRITE_NODE_TYPE("FUNCCALL");
1156 WRITE_NODE_FIELD(funcname);
1157 WRITE_NODE_FIELD(args);
1158 WRITE_BOOL_FIELD(agg_star);
1159 WRITE_BOOL_FIELD(agg_distinct);
1163 _outColumnDef(StringInfo str, ColumnDef *node)
1165 WRITE_NODE_TYPE("COLUMNDEF");
1167 WRITE_STRING_FIELD(colname);
1168 WRITE_NODE_FIELD(typename);
1169 WRITE_INT_FIELD(inhcount);
1170 WRITE_BOOL_FIELD(is_local);
1171 WRITE_BOOL_FIELD(is_not_null);
1172 WRITE_NODE_FIELD(raw_default);
1173 WRITE_STRING_FIELD(cooked_default);
1174 WRITE_NODE_FIELD(constraints);
1175 WRITE_NODE_FIELD(support);
1179 _outTypeName(StringInfo str, TypeName *node)
1181 WRITE_NODE_TYPE("TYPENAME");
1183 WRITE_NODE_FIELD(names);
1184 WRITE_OID_FIELD(typeid);
1185 WRITE_BOOL_FIELD(timezone);
1186 WRITE_BOOL_FIELD(setof);
1187 WRITE_BOOL_FIELD(pct_type);
1188 WRITE_INT_FIELD(typmod);
1189 WRITE_NODE_FIELD(arrayBounds);
1193 _outTypeCast(StringInfo str, TypeCast *node)
1195 WRITE_NODE_TYPE("TYPECAST");
1197 WRITE_NODE_FIELD(arg);
1198 WRITE_NODE_FIELD(typename);
1202 _outIndexElem(StringInfo str, IndexElem *node)
1204 WRITE_NODE_TYPE("INDEXELEM");
1206 WRITE_STRING_FIELD(name);
1207 WRITE_NODE_FIELD(expr);
1208 WRITE_NODE_FIELD(opclass);
1212 _outQuery(StringInfo str, Query *node)
1214 WRITE_NODE_TYPE("QUERY");
1216 WRITE_ENUM_FIELD(commandType, CmdType);
1217 WRITE_ENUM_FIELD(querySource, QuerySource);
1218 WRITE_BOOL_FIELD(canSetTag);
1221 * Hack to work around missing outfuncs routines for a lot of the
1222 * utility-statement node types. (The only one we actually *need* for
1223 * rules support is NotifyStmt.) Someday we ought to support 'em all,
1224 * but for the meantime do this to avoid getting lots of warnings when
1225 * running with debug_print_parse on.
1227 if (node->utilityStmt)
1229 switch (nodeTag(node->utilityStmt))
1234 case T_DeclareCursorStmt:
1235 WRITE_NODE_FIELD(utilityStmt);
1238 appendStringInfo(str, " :utilityStmt ?");
1243 appendStringInfo(str, " :utilityStmt <>");
1245 WRITE_INT_FIELD(resultRelation);
1246 WRITE_NODE_FIELD(into);
1247 WRITE_BOOL_FIELD(hasAggs);
1248 WRITE_BOOL_FIELD(hasSubLinks);
1249 WRITE_NODE_FIELD(rtable);
1250 WRITE_NODE_FIELD(jointree);
1251 WRITE_INTLIST_FIELD(rowMarks);
1252 WRITE_NODE_FIELD(targetList);
1253 WRITE_NODE_FIELD(groupClause);
1254 WRITE_NODE_FIELD(havingQual);
1255 WRITE_NODE_FIELD(distinctClause);
1256 WRITE_NODE_FIELD(sortClause);
1257 WRITE_NODE_FIELD(limitOffset);
1258 WRITE_NODE_FIELD(limitCount);
1259 WRITE_NODE_FIELD(setOperations);
1260 WRITE_INTLIST_FIELD(resultRelations);
1262 /* planner-internal fields are not written out */
1266 _outSortClause(StringInfo str, SortClause *node)
1268 WRITE_NODE_TYPE("SORTCLAUSE");
1270 WRITE_UINT_FIELD(tleSortGroupRef);
1271 WRITE_OID_FIELD(sortop);
1275 _outGroupClause(StringInfo str, GroupClause *node)
1277 WRITE_NODE_TYPE("GROUPCLAUSE");
1279 WRITE_UINT_FIELD(tleSortGroupRef);
1280 WRITE_OID_FIELD(sortop);
1284 _outSetOperationStmt(StringInfo str, SetOperationStmt *node)
1286 WRITE_NODE_TYPE("SETOPERATIONSTMT");
1288 WRITE_ENUM_FIELD(op, SetOperation);
1289 WRITE_BOOL_FIELD(all);
1290 WRITE_NODE_FIELD(larg);
1291 WRITE_NODE_FIELD(rarg);
1292 WRITE_OIDLIST_FIELD(colTypes);
1296 _outRangeTblEntry(StringInfo str, RangeTblEntry *node)
1298 WRITE_NODE_TYPE("RTE");
1300 /* put alias + eref first to make dump more legible */
1301 WRITE_NODE_FIELD(alias);
1302 WRITE_NODE_FIELD(eref);
1303 WRITE_ENUM_FIELD(rtekind, RTEKind);
1305 switch (node->rtekind)
1309 WRITE_OID_FIELD(relid);
1312 WRITE_NODE_FIELD(subquery);
1315 WRITE_NODE_FIELD(funcexpr);
1316 WRITE_NODE_FIELD(coldeflist);
1319 WRITE_ENUM_FIELD(jointype, JoinType);
1320 WRITE_NODE_FIELD(joinaliasvars);
1323 elog(ERROR, "unrecognized RTE kind: %d", (int) node->rtekind);
1327 WRITE_BOOL_FIELD(inh);
1328 WRITE_BOOL_FIELD(inFromCl);
1329 WRITE_BOOL_FIELD(checkForRead);
1330 WRITE_BOOL_FIELD(checkForWrite);
1331 WRITE_OID_FIELD(checkAsUser);
1335 _outAExpr(StringInfo str, A_Expr *node)
1337 WRITE_NODE_TYPE("AEXPR");
1342 appendStringInfo(str, " ");
1343 WRITE_NODE_FIELD(name);
1346 appendStringInfo(str, " AND");
1349 appendStringInfo(str, " OR");
1352 appendStringInfo(str, " NOT");
1355 appendStringInfo(str, " ");
1356 WRITE_NODE_FIELD(name);
1357 appendStringInfo(str, " ANY ");
1360 appendStringInfo(str, " ");
1361 WRITE_NODE_FIELD(name);
1362 appendStringInfo(str, " ALL ");
1364 case AEXPR_DISTINCT:
1365 appendStringInfo(str, " DISTINCT ");
1366 WRITE_NODE_FIELD(name);
1369 appendStringInfo(str, " NULLIF ");
1370 WRITE_NODE_FIELD(name);
1373 appendStringInfo(str, " OF ");
1374 WRITE_NODE_FIELD(name);
1377 appendStringInfo(str, " ??");
1381 WRITE_NODE_FIELD(lexpr);
1382 WRITE_NODE_FIELD(rexpr);
1386 _outValue(StringInfo str, Value *value)
1388 switch (value->type)
1391 appendStringInfo(str, "%ld", value->val.ival);
1396 * We assume the value is a valid numeric literal and so does
1399 appendStringInfo(str, "%s", value->val.str);
1402 appendStringInfoChar(str, '"');
1403 _outToken(str, value->val.str);
1404 appendStringInfoChar(str, '"');
1407 /* internal representation already has leading 'b' */
1408 appendStringInfo(str, "%s", value->val.str);
1411 elog(ERROR, "unrecognized node type: %d", (int) value->type);
1417 _outColumnRef(StringInfo str, ColumnRef *node)
1419 WRITE_NODE_TYPE("COLUMNREF");
1421 WRITE_NODE_FIELD(fields);
1422 WRITE_NODE_FIELD(indirection);
1426 _outParamRef(StringInfo str, ParamRef *node)
1428 WRITE_NODE_TYPE("PARAMREF");
1430 WRITE_INT_FIELD(number);
1431 WRITE_NODE_FIELD(fields);
1432 WRITE_NODE_FIELD(indirection);
1436 _outAConst(StringInfo str, A_Const *node)
1438 WRITE_NODE_TYPE("CONST ");
1440 _outValue(str, &(node->val));
1441 WRITE_NODE_FIELD(typename);
1445 _outExprFieldSelect(StringInfo str, ExprFieldSelect *node)
1447 WRITE_NODE_TYPE("EXPRFIELDSELECT");
1449 WRITE_NODE_FIELD(arg);
1450 WRITE_NODE_FIELD(fields);
1451 WRITE_NODE_FIELD(indirection);
1455 _outConstraint(StringInfo str, Constraint *node)
1457 WRITE_NODE_TYPE("CONSTRAINT");
1459 WRITE_STRING_FIELD(name);
1461 appendStringInfo(str, " :contype ");
1462 switch (node->contype)
1464 case CONSTR_PRIMARY:
1465 appendStringInfo(str, "PRIMARY_KEY");
1466 WRITE_NODE_FIELD(keys);
1470 appendStringInfo(str, "CHECK");
1471 WRITE_NODE_FIELD(raw_expr);
1472 WRITE_STRING_FIELD(cooked_expr);
1475 case CONSTR_DEFAULT:
1476 appendStringInfo(str, "DEFAULT");
1477 WRITE_NODE_FIELD(raw_expr);
1478 WRITE_STRING_FIELD(cooked_expr);
1481 case CONSTR_NOTNULL:
1482 appendStringInfo(str, "NOT_NULL");
1486 appendStringInfo(str, "UNIQUE");
1487 WRITE_NODE_FIELD(keys);
1491 appendStringInfo(str, "<unrecognized_constraint>");
1497 _outFkConstraint(StringInfo str, FkConstraint *node)
1499 WRITE_NODE_TYPE("FKCONSTRAINT");
1501 WRITE_STRING_FIELD(constr_name);
1502 WRITE_NODE_FIELD(pktable);
1503 WRITE_NODE_FIELD(fk_attrs);
1504 WRITE_NODE_FIELD(pk_attrs);
1505 WRITE_CHAR_FIELD(fk_matchtype);
1506 WRITE_CHAR_FIELD(fk_upd_action);
1507 WRITE_CHAR_FIELD(fk_del_action);
1508 WRITE_BOOL_FIELD(deferrable);
1509 WRITE_BOOL_FIELD(initdeferred);
1510 WRITE_BOOL_FIELD(skip_validation);
1516 * converts a Node into ascii string and append it to 'str'
1519 _outNode(StringInfo str, void *obj)
1523 appendStringInfo(str, "<>");
1531 appendStringInfoChar(str, '(');
1532 foreach(l, (List *) obj)
1534 _outNode(str, lfirst(l));
1536 appendStringInfoChar(str, ' ');
1538 appendStringInfoChar(str, ')');
1540 else if (IsA(obj, Integer) ||
1543 IsA(obj, BitString))
1545 /* nodeRead does not want to see { } around these! */
1546 _outValue(str, obj);
1550 appendStringInfoChar(str, '{');
1551 switch (nodeTag(obj))
1557 _outResult(str, obj);
1560 _outAppend(str, obj);
1566 _outSeqScan(str, obj);
1569 _outIndexScan(str, obj);
1572 _outTidScan(str, obj);
1574 case T_SubqueryScan:
1575 _outSubqueryScan(str, obj);
1577 case T_FunctionScan:
1578 _outFunctionScan(str, obj);
1584 _outNestLoop(str, obj);
1587 _outMergeJoin(str, obj);
1590 _outHashJoin(str, obj);
1596 _outGroup(str, obj);
1599 _outMaterial(str, obj);
1605 _outUnique(str, obj);
1608 _outSetOp(str, obj);
1611 _outLimit(str, obj);
1617 _outResdom(str, obj);
1620 _outAlias(str, obj);
1623 _outRangeVar(str, obj);
1629 _outConst(str, obj);
1632 _outParam(str, obj);
1635 _outAggref(str, obj);
1638 _outArrayRef(str, obj);
1641 _outFuncExpr(str, obj);
1644 _outOpExpr(str, obj);
1646 case T_DistinctExpr:
1647 _outDistinctExpr(str, obj);
1649 case T_ScalarArrayOpExpr:
1650 _outScalarArrayOpExpr(str, obj);
1653 _outBoolExpr(str, obj);
1656 _outSubLink(str, obj);
1659 _outSubPlan(str, obj);
1662 _outFieldSelect(str, obj);
1665 _outRelabelType(str, obj);
1668 _outCaseExpr(str, obj);
1671 _outCaseWhen(str, obj);
1674 _outArrayExpr(str, obj);
1676 case T_CoalesceExpr:
1677 _outCoalesceExpr(str, obj);
1680 _outNullIfExpr(str, obj);
1683 _outNullTest(str, obj);
1686 _outBooleanTest(str, obj);
1688 case T_CoerceToDomain:
1689 _outCoerceToDomain(str, obj);
1691 case T_CoerceToDomainValue:
1692 _outCoerceToDomainValue(str, obj);
1694 case T_SetToDefault:
1695 _outSetToDefault(str, obj);
1698 _outTargetEntry(str, obj);
1701 _outRangeTblRef(str, obj);
1704 _outJoinExpr(str, obj);
1707 _outFromExpr(str, obj);
1714 _outIndexPath(str, obj);
1717 _outTidPath(str, obj);
1720 _outAppendPath(str, obj);
1723 _outResultPath(str, obj);
1725 case T_MaterialPath:
1726 _outMaterialPath(str, obj);
1729 _outUniquePath(str, obj);
1732 _outNestPath(str, obj);
1735 _outMergePath(str, obj);
1738 _outHashPath(str, obj);
1741 _outPathKeyItem(str, obj);
1743 case T_RestrictInfo:
1744 _outRestrictInfo(str, obj);
1747 _outJoinInfo(str, obj);
1749 case T_InClauseInfo:
1750 _outInClauseInfo(str, obj);
1754 _outCreateStmt(str, obj);
1757 _outIndexStmt(str, obj);
1760 _outNotifyStmt(str, obj);
1762 case T_DeclareCursorStmt:
1763 _outDeclareCursorStmt(str, obj);
1766 _outSelectStmt(str, obj);
1769 _outColumnDef(str, obj);
1772 _outTypeName(str, obj);
1775 _outTypeCast(str, obj);
1778 _outIndexElem(str, obj);
1781 _outQuery(str, obj);
1784 _outSortClause(str, obj);
1787 _outGroupClause(str, obj);
1789 case T_SetOperationStmt:
1790 _outSetOperationStmt(str, obj);
1792 case T_RangeTblEntry:
1793 _outRangeTblEntry(str, obj);
1796 _outAExpr(str, obj);
1799 _outColumnRef(str, obj);
1802 _outParamRef(str, obj);
1805 _outAConst(str, obj);
1807 case T_ExprFieldSelect:
1808 _outExprFieldSelect(str, obj);
1811 _outConstraint(str, obj);
1813 case T_FkConstraint:
1814 _outFkConstraint(str, obj);
1817 _outFuncCall(str, obj);
1823 * This should be an ERROR, but it's too useful to be able
1824 * to dump structures that _outNode only understands part
1827 elog(WARNING, "could not dump unrecognized node type: %d",
1828 (int) nodeTag(obj));
1831 appendStringInfoChar(str, '}');
1837 * returns the ascii representation of the Node as a palloc'd string
1840 nodeToString(void *obj)
1844 /* see stringinfo.h for an explanation of this maneuver */
1845 initStringInfo(&str);
1846 _outNode(&str, obj);