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.211 2003/06/29 00:33:43 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 "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)
196 appendStringInfo(str, " %d", x);
199 appendStringInfoChar(str, ')');
203 * Print the value of a Datum given its type.
206 _outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
212 length = datumGetSize(value, typbyval, typlen);
216 s = (char *) (&value);
217 appendStringInfo(str, "%u [ ", (unsigned int) length);
218 for (i = 0; i < (Size) sizeof(Datum); i++)
219 appendStringInfo(str, "%d ", (int) (s[i]));
220 appendStringInfo(str, "]");
224 s = (char *) DatumGetPointer(value);
225 if (!PointerIsValid(s))
226 appendStringInfo(str, "0 [ ]");
229 appendStringInfo(str, "%u [ ", (unsigned int) length);
230 for (i = 0; i < length; i++)
231 appendStringInfo(str, "%d ", (int) (s[i]));
232 appendStringInfo(str, "]");
239 * Stuff from plannodes.h
243 * print the basic stuff of all nodes that inherit from Plan
246 _outPlanInfo(StringInfo str, Plan *node)
248 WRITE_FLOAT_FIELD(startup_cost, "%.2f");
249 WRITE_FLOAT_FIELD(total_cost, "%.2f");
250 WRITE_FLOAT_FIELD(plan_rows, "%.0f");
251 WRITE_INT_FIELD(plan_width);
252 WRITE_NODE_FIELD(targetlist);
253 WRITE_NODE_FIELD(qual);
254 WRITE_NODE_FIELD(lefttree);
255 WRITE_NODE_FIELD(righttree);
256 WRITE_NODE_FIELD(initPlan);
257 WRITE_BITMAPSET_FIELD(extParam);
258 WRITE_BITMAPSET_FIELD(allParam);
259 WRITE_INT_FIELD(nParamExec);
263 * print the basic stuff of all nodes that inherit from Scan
266 _outScanInfo(StringInfo str, Scan *node)
268 _outPlanInfo(str, (Plan *) node);
270 WRITE_UINT_FIELD(scanrelid);
274 * print the basic stuff of all nodes that inherit from Join
277 _outJoinPlanInfo(StringInfo str, Join *node)
279 _outPlanInfo(str, (Plan *) node);
281 WRITE_ENUM_FIELD(jointype, JoinType);
282 WRITE_NODE_FIELD(joinqual);
287 _outPlan(StringInfo str, Plan *node)
289 WRITE_NODE_TYPE("PLAN");
291 _outPlanInfo(str, (Plan *) node);
295 _outResult(StringInfo str, Result *node)
297 WRITE_NODE_TYPE("RESULT");
299 _outPlanInfo(str, (Plan *) node);
301 WRITE_NODE_FIELD(resconstantqual);
305 _outAppend(StringInfo str, Append *node)
307 WRITE_NODE_TYPE("APPEND");
309 _outPlanInfo(str, (Plan *) node);
311 WRITE_NODE_FIELD(appendplans);
312 WRITE_BOOL_FIELD(isTarget);
316 _outScan(StringInfo str, Scan *node)
318 WRITE_NODE_TYPE("SCAN");
320 _outScanInfo(str, (Scan *) node);
324 _outSeqScan(StringInfo str, SeqScan *node)
326 WRITE_NODE_TYPE("SEQSCAN");
328 _outScanInfo(str, (Scan *) node);
332 _outIndexScan(StringInfo str, IndexScan *node)
334 WRITE_NODE_TYPE("INDEXSCAN");
336 _outScanInfo(str, (Scan *) node);
338 WRITE_OIDLIST_FIELD(indxid);
339 WRITE_NODE_FIELD(indxqual);
340 WRITE_NODE_FIELD(indxqualorig);
341 WRITE_ENUM_FIELD(indxorderdir, ScanDirection);
345 _outTidScan(StringInfo str, TidScan *node)
347 WRITE_NODE_TYPE("TIDSCAN");
349 _outScanInfo(str, (Scan *) node);
351 WRITE_NODE_FIELD(tideval);
355 _outSubqueryScan(StringInfo str, SubqueryScan *node)
357 WRITE_NODE_TYPE("SUBQUERYSCAN");
359 _outScanInfo(str, (Scan *) node);
361 WRITE_NODE_FIELD(subplan);
365 _outFunctionScan(StringInfo str, FunctionScan *node)
367 WRITE_NODE_TYPE("FUNCTIONSCAN");
369 _outScanInfo(str, (Scan *) node);
373 _outJoin(StringInfo str, Join *node)
375 WRITE_NODE_TYPE("JOIN");
377 _outJoinPlanInfo(str, (Join *) node);
381 _outNestLoop(StringInfo str, NestLoop *node)
383 WRITE_NODE_TYPE("NESTLOOP");
385 _outJoinPlanInfo(str, (Join *) node);
389 _outMergeJoin(StringInfo str, MergeJoin *node)
391 WRITE_NODE_TYPE("MERGEJOIN");
393 _outJoinPlanInfo(str, (Join *) node);
395 WRITE_NODE_FIELD(mergeclauses);
399 _outHashJoin(StringInfo str, HashJoin *node)
401 WRITE_NODE_TYPE("HASHJOIN");
403 _outJoinPlanInfo(str, (Join *) node);
405 WRITE_NODE_FIELD(hashclauses);
409 _outAgg(StringInfo str, Agg *node)
411 WRITE_NODE_TYPE("AGG");
413 _outPlanInfo(str, (Plan *) node);
415 WRITE_ENUM_FIELD(aggstrategy, AggStrategy);
416 WRITE_INT_FIELD(numCols);
417 WRITE_LONG_FIELD(numGroups);
421 _outGroup(StringInfo str, Group *node)
425 WRITE_NODE_TYPE("GROUP");
427 _outPlanInfo(str, (Plan *) node);
429 WRITE_INT_FIELD(numCols);
431 appendStringInfo(str, " :grpColIdx");
432 for (i = 0; i < node->numCols; i++)
433 appendStringInfo(str, " %d", node->grpColIdx[i]);
437 _outMaterial(StringInfo str, Material *node)
439 WRITE_NODE_TYPE("MATERIAL");
441 _outPlanInfo(str, (Plan *) node);
445 _outSort(StringInfo str, Sort *node)
449 WRITE_NODE_TYPE("SORT");
451 _outPlanInfo(str, (Plan *) node);
453 WRITE_INT_FIELD(numCols);
455 appendStringInfo(str, " :sortColIdx");
456 for (i = 0; i < node->numCols; i++)
457 appendStringInfo(str, " %d", node->sortColIdx[i]);
459 appendStringInfo(str, " :sortOperators");
460 for (i = 0; i < node->numCols; i++)
461 appendStringInfo(str, " %u", node->sortOperators[i]);
465 _outUnique(StringInfo str, Unique *node)
469 WRITE_NODE_TYPE("UNIQUE");
471 _outPlanInfo(str, (Plan *) node);
473 WRITE_INT_FIELD(numCols);
475 appendStringInfo(str, " :uniqColIdx");
476 for (i = 0; i < node->numCols; i++)
477 appendStringInfo(str, " %d", node->uniqColIdx[i]);
481 _outSetOp(StringInfo str, SetOp *node)
485 WRITE_NODE_TYPE("SETOP");
487 _outPlanInfo(str, (Plan *) node);
489 WRITE_ENUM_FIELD(cmd, SetOpCmd);
490 WRITE_INT_FIELD(numCols);
492 appendStringInfo(str, " :dupColIdx");
493 for (i = 0; i < node->numCols; i++)
494 appendStringInfo(str, " %d", node->dupColIdx[i]);
496 WRITE_INT_FIELD(flagColIdx);
500 _outLimit(StringInfo str, Limit *node)
502 WRITE_NODE_TYPE("LIMIT");
504 _outPlanInfo(str, (Plan *) node);
506 WRITE_NODE_FIELD(limitOffset);
507 WRITE_NODE_FIELD(limitCount);
511 _outHash(StringInfo str, Hash *node)
513 WRITE_NODE_TYPE("HASH");
515 _outPlanInfo(str, (Plan *) node);
517 WRITE_NODE_FIELD(hashkeys);
520 /*****************************************************************************
522 * Stuff from primnodes.h.
524 *****************************************************************************/
527 _outResdom(StringInfo str, Resdom *node)
529 WRITE_NODE_TYPE("RESDOM");
531 WRITE_INT_FIELD(resno);
532 WRITE_OID_FIELD(restype);
533 WRITE_INT_FIELD(restypmod);
534 WRITE_STRING_FIELD(resname);
535 WRITE_UINT_FIELD(ressortgroupref);
536 WRITE_OID_FIELD(resorigtbl);
537 WRITE_INT_FIELD(resorigcol);
538 WRITE_BOOL_FIELD(resjunk);
542 _outAlias(StringInfo str, Alias *node)
544 WRITE_NODE_TYPE("ALIAS");
546 WRITE_STRING_FIELD(aliasname);
547 WRITE_NODE_FIELD(colnames);
551 _outRangeVar(StringInfo str, RangeVar *node)
553 WRITE_NODE_TYPE("RANGEVAR");
556 * we deliberately ignore catalogname here, since it is presently not
557 * semantically meaningful
559 WRITE_STRING_FIELD(schemaname);
560 WRITE_STRING_FIELD(relname);
561 WRITE_ENUM_FIELD(inhOpt, InhOption);
562 WRITE_BOOL_FIELD(istemp);
563 WRITE_NODE_FIELD(alias);
567 _outVar(StringInfo str, Var *node)
569 WRITE_NODE_TYPE("VAR");
571 WRITE_UINT_FIELD(varno);
572 WRITE_INT_FIELD(varattno);
573 WRITE_OID_FIELD(vartype);
574 WRITE_INT_FIELD(vartypmod);
575 WRITE_UINT_FIELD(varlevelsup);
576 WRITE_UINT_FIELD(varnoold);
577 WRITE_INT_FIELD(varoattno);
581 _outConst(StringInfo str, Const *node)
583 WRITE_NODE_TYPE("CONST");
585 WRITE_OID_FIELD(consttype);
586 WRITE_INT_FIELD(constlen);
587 WRITE_BOOL_FIELD(constbyval);
588 WRITE_BOOL_FIELD(constisnull);
590 appendStringInfo(str, " :constvalue ");
591 if (node->constisnull)
592 appendStringInfo(str, "<>");
594 _outDatum(str, node->constvalue, node->constlen, node->constbyval);
598 _outParam(StringInfo str, Param *node)
600 WRITE_NODE_TYPE("PARAM");
602 WRITE_INT_FIELD(paramkind);
603 WRITE_INT_FIELD(paramid);
604 WRITE_STRING_FIELD(paramname);
605 WRITE_OID_FIELD(paramtype);
609 _outAggref(StringInfo str, Aggref *node)
611 WRITE_NODE_TYPE("AGGREF");
613 WRITE_OID_FIELD(aggfnoid);
614 WRITE_OID_FIELD(aggtype);
615 WRITE_NODE_FIELD(target);
616 WRITE_UINT_FIELD(agglevelsup);
617 WRITE_BOOL_FIELD(aggstar);
618 WRITE_BOOL_FIELD(aggdistinct);
622 _outArrayRef(StringInfo str, ArrayRef *node)
624 WRITE_NODE_TYPE("ARRAYREF");
626 WRITE_OID_FIELD(refrestype);
627 WRITE_OID_FIELD(refarraytype);
628 WRITE_OID_FIELD(refelemtype);
629 WRITE_NODE_FIELD(refupperindexpr);
630 WRITE_NODE_FIELD(reflowerindexpr);
631 WRITE_NODE_FIELD(refexpr);
632 WRITE_NODE_FIELD(refassgnexpr);
636 _outFuncExpr(StringInfo str, FuncExpr *node)
638 WRITE_NODE_TYPE("FUNCEXPR");
640 WRITE_OID_FIELD(funcid);
641 WRITE_OID_FIELD(funcresulttype);
642 WRITE_BOOL_FIELD(funcretset);
643 WRITE_ENUM_FIELD(funcformat, CoercionForm);
644 WRITE_NODE_FIELD(args);
648 _outOpExpr(StringInfo str, OpExpr *node)
650 WRITE_NODE_TYPE("OPEXPR");
652 WRITE_OID_FIELD(opno);
653 WRITE_OID_FIELD(opfuncid);
654 WRITE_OID_FIELD(opresulttype);
655 WRITE_BOOL_FIELD(opretset);
656 WRITE_NODE_FIELD(args);
660 _outDistinctExpr(StringInfo str, DistinctExpr *node)
662 WRITE_NODE_TYPE("DISTINCTEXPR");
664 WRITE_OID_FIELD(opno);
665 WRITE_OID_FIELD(opfuncid);
666 WRITE_OID_FIELD(opresulttype);
667 WRITE_BOOL_FIELD(opretset);
668 WRITE_NODE_FIELD(args);
672 _outScalarArrayOpExpr(StringInfo str, ScalarArrayOpExpr *node)
674 WRITE_NODE_TYPE("SCALARARRAYOPEXPR");
676 WRITE_OID_FIELD(opno);
677 WRITE_OID_FIELD(opfuncid);
678 WRITE_BOOL_FIELD(useOr);
679 WRITE_NODE_FIELD(args);
683 _outBoolExpr(StringInfo str, BoolExpr *node)
687 WRITE_NODE_TYPE("BOOLEXPR");
689 /* do-it-yourself enum representation */
690 switch (node->boolop)
702 appendStringInfo(str, " :boolop ");
703 _outToken(str, opstr);
705 WRITE_NODE_FIELD(args);
709 _outSubLink(StringInfo str, SubLink *node)
711 WRITE_NODE_TYPE("SUBLINK");
713 WRITE_ENUM_FIELD(subLinkType, SubLinkType);
714 WRITE_BOOL_FIELD(useOr);
715 WRITE_NODE_FIELD(lefthand);
716 WRITE_NODE_FIELD(operName);
717 WRITE_OIDLIST_FIELD(operOids);
718 WRITE_NODE_FIELD(subselect);
722 _outSubPlan(StringInfo str, SubPlan *node)
724 WRITE_NODE_TYPE("SUBPLAN");
726 WRITE_ENUM_FIELD(subLinkType, SubLinkType);
727 WRITE_BOOL_FIELD(useOr);
728 WRITE_NODE_FIELD(exprs);
729 WRITE_INTLIST_FIELD(paramIds);
730 WRITE_NODE_FIELD(plan);
731 WRITE_INT_FIELD(plan_id);
732 WRITE_NODE_FIELD(rtable);
733 WRITE_BOOL_FIELD(useHashTable);
734 WRITE_BOOL_FIELD(unknownEqFalse);
735 WRITE_INTLIST_FIELD(setParam);
736 WRITE_INTLIST_FIELD(parParam);
737 WRITE_NODE_FIELD(args);
741 _outFieldSelect(StringInfo str, FieldSelect *node)
743 WRITE_NODE_TYPE("FIELDSELECT");
745 WRITE_NODE_FIELD(arg);
746 WRITE_INT_FIELD(fieldnum);
747 WRITE_OID_FIELD(resulttype);
748 WRITE_INT_FIELD(resulttypmod);
752 _outRelabelType(StringInfo str, RelabelType *node)
754 WRITE_NODE_TYPE("RELABELTYPE");
756 WRITE_NODE_FIELD(arg);
757 WRITE_OID_FIELD(resulttype);
758 WRITE_INT_FIELD(resulttypmod);
759 WRITE_ENUM_FIELD(relabelformat, CoercionForm);
763 _outCaseExpr(StringInfo str, CaseExpr *node)
765 WRITE_NODE_TYPE("CASE");
767 WRITE_OID_FIELD(casetype);
768 WRITE_NODE_FIELD(arg);
769 WRITE_NODE_FIELD(args);
770 WRITE_NODE_FIELD(defresult);
774 _outCaseWhen(StringInfo str, CaseWhen *node)
776 WRITE_NODE_TYPE("WHEN");
778 WRITE_NODE_FIELD(expr);
779 WRITE_NODE_FIELD(result);
783 _outArrayExpr(StringInfo str, ArrayExpr *node)
785 WRITE_NODE_TYPE("ARRAY");
787 WRITE_OID_FIELD(array_typeid);
788 WRITE_OID_FIELD(element_typeid);
789 WRITE_NODE_FIELD(elements);
790 WRITE_INT_FIELD(ndims);
794 _outCoalesceExpr(StringInfo str, CoalesceExpr *node)
796 WRITE_NODE_TYPE("COALESCE");
798 WRITE_OID_FIELD(coalescetype);
799 WRITE_NODE_FIELD(args);
803 _outNullIfExpr(StringInfo str, NullIfExpr *node)
805 WRITE_NODE_TYPE("NULLIFEXPR");
807 WRITE_OID_FIELD(opno);
808 WRITE_OID_FIELD(opfuncid);
809 WRITE_OID_FIELD(opresulttype);
810 WRITE_BOOL_FIELD(opretset);
811 WRITE_NODE_FIELD(args);
815 _outNullTest(StringInfo str, NullTest *node)
817 WRITE_NODE_TYPE("NULLTEST");
819 WRITE_NODE_FIELD(arg);
820 WRITE_ENUM_FIELD(nulltesttype, NullTestType);
824 _outBooleanTest(StringInfo str, BooleanTest *node)
826 WRITE_NODE_TYPE("BOOLEANTEST");
828 WRITE_NODE_FIELD(arg);
829 WRITE_ENUM_FIELD(booltesttype, BoolTestType);
833 _outCoerceToDomain(StringInfo str, CoerceToDomain *node)
835 WRITE_NODE_TYPE("COERCETODOMAIN");
837 WRITE_NODE_FIELD(arg);
838 WRITE_OID_FIELD(resulttype);
839 WRITE_INT_FIELD(resulttypmod);
840 WRITE_ENUM_FIELD(coercionformat, CoercionForm);
844 _outCoerceToDomainValue(StringInfo str, CoerceToDomainValue *node)
846 WRITE_NODE_TYPE("COERCETODOMAINVALUE");
848 WRITE_OID_FIELD(typeId);
849 WRITE_INT_FIELD(typeMod);
853 _outTargetEntry(StringInfo str, TargetEntry *node)
855 WRITE_NODE_TYPE("TARGETENTRY");
857 WRITE_NODE_FIELD(resdom);
858 WRITE_NODE_FIELD(expr);
862 _outRangeTblRef(StringInfo str, RangeTblRef *node)
864 WRITE_NODE_TYPE("RANGETBLREF");
866 WRITE_INT_FIELD(rtindex);
870 _outJoinExpr(StringInfo str, JoinExpr *node)
872 WRITE_NODE_TYPE("JOINEXPR");
874 WRITE_ENUM_FIELD(jointype, JoinType);
875 WRITE_BOOL_FIELD(isNatural);
876 WRITE_NODE_FIELD(larg);
877 WRITE_NODE_FIELD(rarg);
878 WRITE_NODE_FIELD(using);
879 WRITE_NODE_FIELD(quals);
880 WRITE_NODE_FIELD(alias);
881 WRITE_INT_FIELD(rtindex);
885 _outFromExpr(StringInfo str, FromExpr *node)
887 WRITE_NODE_TYPE("FROMEXPR");
889 WRITE_NODE_FIELD(fromlist);
890 WRITE_NODE_FIELD(quals);
893 /*****************************************************************************
895 * Stuff from relation.h.
897 *****************************************************************************/
900 * print the basic stuff of all nodes that inherit from Path
902 * Note we do NOT print the parent, else we'd be in infinite recursion
905 _outPathInfo(StringInfo str, Path *node)
907 WRITE_ENUM_FIELD(pathtype, NodeTag);
908 WRITE_FLOAT_FIELD(startup_cost, "%.2f");
909 WRITE_FLOAT_FIELD(total_cost, "%.2f");
910 WRITE_NODE_FIELD(pathkeys);
914 * print the basic stuff of all nodes that inherit from JoinPath
917 _outJoinPathInfo(StringInfo str, JoinPath *node)
919 _outPathInfo(str, (Path *) node);
921 WRITE_ENUM_FIELD(jointype, JoinType);
922 WRITE_NODE_FIELD(outerjoinpath);
923 WRITE_NODE_FIELD(innerjoinpath);
924 WRITE_NODE_FIELD(joinrestrictinfo);
928 _outPath(StringInfo str, Path *node)
930 WRITE_NODE_TYPE("PATH");
932 _outPathInfo(str, (Path *) node);
936 * IndexPath is a subclass of Path.
939 _outIndexPath(StringInfo str, IndexPath *node)
941 WRITE_NODE_TYPE("INDEXPATH");
943 _outPathInfo(str, (Path *) node);
945 WRITE_NODE_FIELD(indexinfo);
946 WRITE_NODE_FIELD(indexqual);
947 WRITE_NODE_FIELD(indexjoinclauses);
948 WRITE_ENUM_FIELD(indexscandir, ScanDirection);
949 WRITE_FLOAT_FIELD(rows, "%.2f");
953 _outTidPath(StringInfo str, TidPath *node)
955 WRITE_NODE_TYPE("TIDPATH");
957 _outPathInfo(str, (Path *) node);
959 WRITE_NODE_FIELD(tideval);
963 _outAppendPath(StringInfo str, AppendPath *node)
965 WRITE_NODE_TYPE("APPENDPATH");
967 _outPathInfo(str, (Path *) node);
969 WRITE_NODE_FIELD(subpaths);
973 _outResultPath(StringInfo str, ResultPath *node)
975 WRITE_NODE_TYPE("RESULTPATH");
977 _outPathInfo(str, (Path *) node);
979 WRITE_NODE_FIELD(subpath);
980 WRITE_NODE_FIELD(constantqual);
984 _outMaterialPath(StringInfo str, MaterialPath *node)
986 WRITE_NODE_TYPE("MATERIALPATH");
988 _outPathInfo(str, (Path *) node);
990 WRITE_NODE_FIELD(subpath);
994 _outUniquePath(StringInfo str, UniquePath *node)
996 WRITE_NODE_TYPE("UNIQUEPATH");
998 _outPathInfo(str, (Path *) node);
1000 WRITE_NODE_FIELD(subpath);
1001 WRITE_BOOL_FIELD(use_hash);
1002 WRITE_FLOAT_FIELD(rows, "%.0f");
1006 _outNestPath(StringInfo str, NestPath *node)
1008 WRITE_NODE_TYPE("NESTPATH");
1010 _outJoinPathInfo(str, (JoinPath *) node);
1014 _outMergePath(StringInfo str, MergePath *node)
1016 WRITE_NODE_TYPE("MERGEPATH");
1018 _outJoinPathInfo(str, (JoinPath *) node);
1020 WRITE_NODE_FIELD(path_mergeclauses);
1021 WRITE_NODE_FIELD(outersortkeys);
1022 WRITE_NODE_FIELD(innersortkeys);
1026 _outHashPath(StringInfo str, HashPath *node)
1028 WRITE_NODE_TYPE("HASHPATH");
1030 _outJoinPathInfo(str, (JoinPath *) node);
1032 WRITE_NODE_FIELD(path_hashclauses);
1036 _outPathKeyItem(StringInfo str, PathKeyItem *node)
1038 WRITE_NODE_TYPE("PATHKEYITEM");
1040 WRITE_NODE_FIELD(key);
1041 WRITE_OID_FIELD(sortop);
1045 _outRestrictInfo(StringInfo str, RestrictInfo *node)
1047 WRITE_NODE_TYPE("RESTRICTINFO");
1049 /* NB: this isn't a complete set of fields */
1050 WRITE_NODE_FIELD(clause);
1051 WRITE_BOOL_FIELD(ispusheddown);
1052 WRITE_NODE_FIELD(subclauseindices);
1053 WRITE_BITMAPSET_FIELD(left_relids);
1054 WRITE_BITMAPSET_FIELD(right_relids);
1055 WRITE_OID_FIELD(mergejoinoperator);
1056 WRITE_OID_FIELD(left_sortop);
1057 WRITE_OID_FIELD(right_sortop);
1058 WRITE_NODE_FIELD(left_pathkey);
1059 WRITE_NODE_FIELD(right_pathkey);
1060 WRITE_OID_FIELD(hashjoinoperator);
1064 _outJoinInfo(StringInfo str, JoinInfo *node)
1066 WRITE_NODE_TYPE("JOININFO");
1068 WRITE_BITMAPSET_FIELD(unjoined_relids);
1069 WRITE_NODE_FIELD(jinfo_restrictinfo);
1073 _outInClauseInfo(StringInfo str, InClauseInfo *node)
1075 WRITE_NODE_TYPE("INCLAUSEINFO");
1077 WRITE_BITMAPSET_FIELD(lefthand);
1078 WRITE_BITMAPSET_FIELD(righthand);
1079 WRITE_NODE_FIELD(sub_targetlist);
1082 /*****************************************************************************
1084 * Stuff from parsenodes.h.
1086 *****************************************************************************/
1089 _outCreateStmt(StringInfo str, CreateStmt *node)
1091 WRITE_NODE_TYPE("CREATE");
1093 WRITE_NODE_FIELD(relation);
1094 WRITE_NODE_FIELD(tableElts);
1095 WRITE_NODE_FIELD(inhRelations);
1096 WRITE_NODE_FIELD(constraints);
1097 WRITE_BOOL_FIELD(hasoids);
1098 WRITE_ENUM_FIELD(oncommit, OnCommitAction);
1102 _outIndexStmt(StringInfo str, IndexStmt *node)
1104 WRITE_NODE_TYPE("INDEX");
1106 WRITE_STRING_FIELD(idxname);
1107 WRITE_NODE_FIELD(relation);
1108 WRITE_STRING_FIELD(accessMethod);
1109 WRITE_NODE_FIELD(indexParams);
1110 WRITE_NODE_FIELD(whereClause);
1111 WRITE_NODE_FIELD(rangetable);
1112 WRITE_BOOL_FIELD(unique);
1113 WRITE_BOOL_FIELD(primary);
1114 WRITE_BOOL_FIELD(isconstraint);
1118 _outNotifyStmt(StringInfo str, NotifyStmt *node)
1120 WRITE_NODE_TYPE("NOTIFY");
1122 WRITE_NODE_FIELD(relation);
1126 _outDeclareCursorStmt(StringInfo str, DeclareCursorStmt *node)
1128 WRITE_NODE_TYPE("DECLARECURSOR");
1130 WRITE_STRING_FIELD(portalname);
1131 WRITE_INT_FIELD(options);
1132 WRITE_NODE_FIELD(query);
1136 _outSelectStmt(StringInfo str, SelectStmt *node)
1138 WRITE_NODE_TYPE("SELECT");
1140 /* XXX this is pretty durn incomplete */
1141 WRITE_NODE_FIELD(whereClause);
1145 _outFuncCall(StringInfo str, FuncCall *node)
1147 WRITE_NODE_TYPE("FUNCCALL");
1149 WRITE_NODE_FIELD(funcname);
1150 WRITE_NODE_FIELD(args);
1151 WRITE_BOOL_FIELD(agg_star);
1152 WRITE_BOOL_FIELD(agg_distinct);
1156 _outColumnDef(StringInfo str, ColumnDef *node)
1158 WRITE_NODE_TYPE("COLUMNDEF");
1160 WRITE_STRING_FIELD(colname);
1161 WRITE_NODE_FIELD(typename);
1162 WRITE_INT_FIELD(inhcount);
1163 WRITE_BOOL_FIELD(is_local);
1164 WRITE_BOOL_FIELD(is_not_null);
1165 WRITE_NODE_FIELD(raw_default);
1166 WRITE_STRING_FIELD(cooked_default);
1167 WRITE_NODE_FIELD(constraints);
1168 WRITE_NODE_FIELD(support);
1172 _outTypeName(StringInfo str, TypeName *node)
1174 WRITE_NODE_TYPE("TYPENAME");
1176 WRITE_NODE_FIELD(names);
1177 WRITE_OID_FIELD(typeid);
1178 WRITE_BOOL_FIELD(timezone);
1179 WRITE_BOOL_FIELD(setof);
1180 WRITE_BOOL_FIELD(pct_type);
1181 WRITE_INT_FIELD(typmod);
1182 WRITE_NODE_FIELD(arrayBounds);
1186 _outTypeCast(StringInfo str, TypeCast *node)
1188 WRITE_NODE_TYPE("TYPECAST");
1190 WRITE_NODE_FIELD(arg);
1191 WRITE_NODE_FIELD(typename);
1195 _outIndexElem(StringInfo str, IndexElem *node)
1197 WRITE_NODE_TYPE("INDEXELEM");
1199 WRITE_STRING_FIELD(name);
1200 WRITE_NODE_FIELD(expr);
1201 WRITE_NODE_FIELD(opclass);
1205 _outQuery(StringInfo str, Query *node)
1207 WRITE_NODE_TYPE("QUERY");
1209 WRITE_ENUM_FIELD(commandType, CmdType);
1210 WRITE_ENUM_FIELD(querySource, QuerySource);
1211 WRITE_BOOL_FIELD(canSetTag);
1214 * Hack to work around missing outfuncs routines for a lot of the
1215 * utility-statement node types. (The only one we actually *need* for
1216 * rules support is NotifyStmt.) Someday we ought to support 'em all,
1217 * but for the meantime do this to avoid getting lots of warnings when
1218 * running with debug_print_parse on.
1220 if (node->utilityStmt)
1222 switch (nodeTag(node->utilityStmt))
1227 case T_DeclareCursorStmt:
1228 WRITE_NODE_FIELD(utilityStmt);
1231 appendStringInfo(str, " :utilityStmt ?");
1236 appendStringInfo(str, " :utilityStmt <>");
1238 WRITE_INT_FIELD(resultRelation);
1239 WRITE_NODE_FIELD(into);
1240 WRITE_BOOL_FIELD(hasAggs);
1241 WRITE_BOOL_FIELD(hasSubLinks);
1242 WRITE_NODE_FIELD(rtable);
1243 WRITE_NODE_FIELD(jointree);
1244 WRITE_INTLIST_FIELD(rowMarks);
1245 WRITE_NODE_FIELD(targetList);
1246 WRITE_NODE_FIELD(groupClause);
1247 WRITE_NODE_FIELD(havingQual);
1248 WRITE_NODE_FIELD(distinctClause);
1249 WRITE_NODE_FIELD(sortClause);
1250 WRITE_NODE_FIELD(limitOffset);
1251 WRITE_NODE_FIELD(limitCount);
1252 WRITE_NODE_FIELD(setOperations);
1253 WRITE_INTLIST_FIELD(resultRelations);
1255 /* planner-internal fields are not written out */
1259 _outSortClause(StringInfo str, SortClause *node)
1261 WRITE_NODE_TYPE("SORTCLAUSE");
1263 WRITE_UINT_FIELD(tleSortGroupRef);
1264 WRITE_OID_FIELD(sortop);
1268 _outGroupClause(StringInfo str, GroupClause *node)
1270 WRITE_NODE_TYPE("GROUPCLAUSE");
1272 WRITE_UINT_FIELD(tleSortGroupRef);
1273 WRITE_OID_FIELD(sortop);
1277 _outSetOperationStmt(StringInfo str, SetOperationStmt *node)
1279 WRITE_NODE_TYPE("SETOPERATIONSTMT");
1281 WRITE_ENUM_FIELD(op, SetOperation);
1282 WRITE_BOOL_FIELD(all);
1283 WRITE_NODE_FIELD(larg);
1284 WRITE_NODE_FIELD(rarg);
1285 WRITE_OIDLIST_FIELD(colTypes);
1289 _outRangeTblEntry(StringInfo str, RangeTblEntry *node)
1291 WRITE_NODE_TYPE("RTE");
1293 /* put alias + eref first to make dump more legible */
1294 WRITE_NODE_FIELD(alias);
1295 WRITE_NODE_FIELD(eref);
1296 WRITE_ENUM_FIELD(rtekind, RTEKind);
1298 switch (node->rtekind)
1302 WRITE_OID_FIELD(relid);
1305 WRITE_NODE_FIELD(subquery);
1308 WRITE_NODE_FIELD(funcexpr);
1309 WRITE_NODE_FIELD(coldeflist);
1312 WRITE_ENUM_FIELD(jointype, JoinType);
1313 WRITE_NODE_FIELD(joinaliasvars);
1316 elog(ERROR, "bogus rte kind %d", (int) node->rtekind);
1320 WRITE_BOOL_FIELD(inh);
1321 WRITE_BOOL_FIELD(inFromCl);
1322 WRITE_BOOL_FIELD(checkForRead);
1323 WRITE_BOOL_FIELD(checkForWrite);
1324 WRITE_OID_FIELD(checkAsUser);
1328 _outAExpr(StringInfo str, A_Expr *node)
1330 WRITE_NODE_TYPE("AEXPR");
1335 appendStringInfo(str, " ");
1336 WRITE_NODE_FIELD(name);
1339 appendStringInfo(str, " AND");
1342 appendStringInfo(str, " OR");
1345 appendStringInfo(str, " NOT");
1348 appendStringInfo(str, " ");
1349 WRITE_NODE_FIELD(name);
1350 appendStringInfo(str, " ANY ");
1353 appendStringInfo(str, " ");
1354 WRITE_NODE_FIELD(name);
1355 appendStringInfo(str, " ALL ");
1357 case AEXPR_DISTINCT:
1358 appendStringInfo(str, " DISTINCT ");
1359 WRITE_NODE_FIELD(name);
1362 appendStringInfo(str, " NULLIF ");
1363 WRITE_NODE_FIELD(name);
1366 appendStringInfo(str, " OF ");
1367 WRITE_NODE_FIELD(name);
1370 appendStringInfo(str, " ??");
1374 WRITE_NODE_FIELD(lexpr);
1375 WRITE_NODE_FIELD(rexpr);
1379 _outValue(StringInfo str, Value *value)
1381 switch (value->type)
1384 appendStringInfo(str, "%ld", value->val.ival);
1389 * We assume the value is a valid numeric literal and so does
1392 appendStringInfo(str, "%s", value->val.str);
1395 appendStringInfoChar(str, '"');
1396 _outToken(str, value->val.str);
1397 appendStringInfoChar(str, '"');
1400 /* internal representation already has leading 'b' */
1401 appendStringInfo(str, "%s", value->val.str);
1404 elog(WARNING, "_outValue: don't know how to print type %d",
1411 _outColumnRef(StringInfo str, ColumnRef *node)
1413 WRITE_NODE_TYPE("COLUMNREF");
1415 WRITE_NODE_FIELD(fields);
1416 WRITE_NODE_FIELD(indirection);
1420 _outParamRef(StringInfo str, ParamRef *node)
1422 WRITE_NODE_TYPE("PARAMREF");
1424 WRITE_INT_FIELD(number);
1425 WRITE_NODE_FIELD(fields);
1426 WRITE_NODE_FIELD(indirection);
1430 _outAConst(StringInfo str, A_Const *node)
1432 WRITE_NODE_TYPE("CONST ");
1434 _outValue(str, &(node->val));
1435 WRITE_NODE_FIELD(typename);
1439 _outExprFieldSelect(StringInfo str, ExprFieldSelect *node)
1441 WRITE_NODE_TYPE("EXPRFIELDSELECT");
1443 WRITE_NODE_FIELD(arg);
1444 WRITE_NODE_FIELD(fields);
1445 WRITE_NODE_FIELD(indirection);
1449 _outConstraint(StringInfo str, Constraint *node)
1451 WRITE_NODE_TYPE("CONSTRAINT");
1453 WRITE_STRING_FIELD(name);
1455 appendStringInfo(str, " :contype ");
1456 switch (node->contype)
1458 case CONSTR_PRIMARY:
1459 appendStringInfo(str, "PRIMARY_KEY");
1460 WRITE_NODE_FIELD(keys);
1464 appendStringInfo(str, "CHECK");
1465 WRITE_NODE_FIELD(raw_expr);
1466 WRITE_STRING_FIELD(cooked_expr);
1469 case CONSTR_DEFAULT:
1470 appendStringInfo(str, "DEFAULT");
1471 WRITE_NODE_FIELD(raw_expr);
1472 WRITE_STRING_FIELD(cooked_expr);
1475 case CONSTR_NOTNULL:
1476 appendStringInfo(str, "NOT_NULL");
1480 appendStringInfo(str, "UNIQUE");
1481 WRITE_NODE_FIELD(keys);
1485 appendStringInfo(str, "<unrecognized_constraint>");
1491 _outFkConstraint(StringInfo str, FkConstraint *node)
1493 WRITE_NODE_TYPE("FKCONSTRAINT");
1495 WRITE_STRING_FIELD(constr_name);
1496 WRITE_NODE_FIELD(pktable);
1497 WRITE_NODE_FIELD(fk_attrs);
1498 WRITE_NODE_FIELD(pk_attrs);
1499 WRITE_CHAR_FIELD(fk_matchtype);
1500 WRITE_CHAR_FIELD(fk_upd_action);
1501 WRITE_CHAR_FIELD(fk_del_action);
1502 WRITE_BOOL_FIELD(deferrable);
1503 WRITE_BOOL_FIELD(initdeferred);
1504 WRITE_BOOL_FIELD(skip_validation);
1510 * converts a Node into ascii string and append it to 'str'
1513 _outNode(StringInfo str, void *obj)
1517 appendStringInfo(str, "<>");
1525 appendStringInfoChar(str, '(');
1526 foreach(l, (List *) obj)
1528 _outNode(str, lfirst(l));
1530 appendStringInfoChar(str, ' ');
1532 appendStringInfoChar(str, ')');
1534 else if (IsA(obj, Integer) ||
1537 IsA(obj, BitString))
1539 /* nodeRead does not want to see { } around these! */
1540 _outValue(str, obj);
1544 appendStringInfoChar(str, '{');
1545 switch (nodeTag(obj))
1551 _outResult(str, obj);
1554 _outAppend(str, obj);
1560 _outSeqScan(str, obj);
1563 _outIndexScan(str, obj);
1566 _outTidScan(str, obj);
1568 case T_SubqueryScan:
1569 _outSubqueryScan(str, obj);
1571 case T_FunctionScan:
1572 _outFunctionScan(str, obj);
1578 _outNestLoop(str, obj);
1581 _outMergeJoin(str, obj);
1584 _outHashJoin(str, obj);
1590 _outGroup(str, obj);
1593 _outMaterial(str, obj);
1599 _outUnique(str, obj);
1602 _outSetOp(str, obj);
1605 _outLimit(str, obj);
1611 _outResdom(str, obj);
1614 _outAlias(str, obj);
1617 _outRangeVar(str, obj);
1623 _outConst(str, obj);
1626 _outParam(str, obj);
1629 _outAggref(str, obj);
1632 _outArrayRef(str, obj);
1635 _outFuncExpr(str, obj);
1638 _outOpExpr(str, obj);
1640 case T_DistinctExpr:
1641 _outDistinctExpr(str, obj);
1643 case T_ScalarArrayOpExpr:
1644 _outScalarArrayOpExpr(str, obj);
1647 _outBoolExpr(str, obj);
1650 _outSubLink(str, obj);
1653 _outSubPlan(str, obj);
1656 _outFieldSelect(str, obj);
1659 _outRelabelType(str, obj);
1662 _outCaseExpr(str, obj);
1665 _outCaseWhen(str, obj);
1668 _outArrayExpr(str, obj);
1670 case T_CoalesceExpr:
1671 _outCoalesceExpr(str, obj);
1674 _outNullIfExpr(str, obj);
1677 _outNullTest(str, obj);
1680 _outBooleanTest(str, obj);
1682 case T_CoerceToDomain:
1683 _outCoerceToDomain(str, obj);
1685 case T_CoerceToDomainValue:
1686 _outCoerceToDomainValue(str, obj);
1689 _outTargetEntry(str, obj);
1692 _outRangeTblRef(str, obj);
1695 _outJoinExpr(str, obj);
1698 _outFromExpr(str, obj);
1705 _outIndexPath(str, obj);
1708 _outTidPath(str, obj);
1711 _outAppendPath(str, obj);
1714 _outResultPath(str, obj);
1716 case T_MaterialPath:
1717 _outMaterialPath(str, obj);
1720 _outUniquePath(str, obj);
1723 _outNestPath(str, obj);
1726 _outMergePath(str, obj);
1729 _outHashPath(str, obj);
1732 _outPathKeyItem(str, obj);
1734 case T_RestrictInfo:
1735 _outRestrictInfo(str, obj);
1738 _outJoinInfo(str, obj);
1740 case T_InClauseInfo:
1741 _outInClauseInfo(str, obj);
1745 _outCreateStmt(str, obj);
1748 _outIndexStmt(str, obj);
1751 _outNotifyStmt(str, obj);
1753 case T_DeclareCursorStmt:
1754 _outDeclareCursorStmt(str, obj);
1757 _outSelectStmt(str, obj);
1760 _outColumnDef(str, obj);
1763 _outTypeName(str, obj);
1766 _outTypeCast(str, obj);
1769 _outIndexElem(str, obj);
1772 _outQuery(str, obj);
1775 _outSortClause(str, obj);
1778 _outGroupClause(str, obj);
1780 case T_SetOperationStmt:
1781 _outSetOperationStmt(str, obj);
1783 case T_RangeTblEntry:
1784 _outRangeTblEntry(str, obj);
1787 _outAExpr(str, obj);
1790 _outColumnRef(str, obj);
1793 _outParamRef(str, obj);
1796 _outAConst(str, obj);
1798 case T_ExprFieldSelect:
1799 _outExprFieldSelect(str, obj);
1802 _outConstraint(str, obj);
1804 case T_FkConstraint:
1805 _outFkConstraint(str, obj);
1808 _outFuncCall(str, obj);
1812 elog(WARNING, "_outNode: don't know how to print type %d",
1816 appendStringInfoChar(str, '}');
1822 * returns the ascii representation of the Node as a palloc'd string
1825 nodeToString(void *obj)
1829 /* see stringinfo.h for an explanation of this maneuver */
1830 initStringInfo(&str);
1831 _outNode(&str, obj);