1 /*-------------------------------------------------------------------------
4 * Output functions for Postgres tree nodes.
6 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.226 2004/01/05 05:07: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 "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 /* this can become WRITE_NODE_FIELD when intlists are normal objects: */
343 appendStringInfo(str, " :indxstrategy ");
344 foreach(tmp, node->indxstrategy)
346 _outIntList(str, lfirst(tmp));
349 /* this can become WRITE_NODE_FIELD when OID lists are normal objects: */
353 appendStringInfo(str, " :indxsubtype ");
354 foreach(tmp, node->indxsubtype)
356 _outOidList(str, lfirst(tmp));
359 WRITE_ENUM_FIELD(indxorderdir, ScanDirection);
363 _outTidScan(StringInfo str, TidScan *node)
365 WRITE_NODE_TYPE("TIDSCAN");
367 _outScanInfo(str, (Scan *) node);
369 WRITE_NODE_FIELD(tideval);
373 _outSubqueryScan(StringInfo str, SubqueryScan *node)
375 WRITE_NODE_TYPE("SUBQUERYSCAN");
377 _outScanInfo(str, (Scan *) node);
379 WRITE_NODE_FIELD(subplan);
383 _outFunctionScan(StringInfo str, FunctionScan *node)
385 WRITE_NODE_TYPE("FUNCTIONSCAN");
387 _outScanInfo(str, (Scan *) node);
391 _outJoin(StringInfo str, Join *node)
393 WRITE_NODE_TYPE("JOIN");
395 _outJoinPlanInfo(str, (Join *) node);
399 _outNestLoop(StringInfo str, NestLoop *node)
401 WRITE_NODE_TYPE("NESTLOOP");
403 _outJoinPlanInfo(str, (Join *) node);
407 _outMergeJoin(StringInfo str, MergeJoin *node)
409 WRITE_NODE_TYPE("MERGEJOIN");
411 _outJoinPlanInfo(str, (Join *) node);
413 WRITE_NODE_FIELD(mergeclauses);
417 _outHashJoin(StringInfo str, HashJoin *node)
419 WRITE_NODE_TYPE("HASHJOIN");
421 _outJoinPlanInfo(str, (Join *) node);
423 WRITE_NODE_FIELD(hashclauses);
427 _outAgg(StringInfo str, Agg *node)
429 WRITE_NODE_TYPE("AGG");
431 _outPlanInfo(str, (Plan *) node);
433 WRITE_ENUM_FIELD(aggstrategy, AggStrategy);
434 WRITE_INT_FIELD(numCols);
435 WRITE_LONG_FIELD(numGroups);
439 _outGroup(StringInfo str, Group *node)
443 WRITE_NODE_TYPE("GROUP");
445 _outPlanInfo(str, (Plan *) node);
447 WRITE_INT_FIELD(numCols);
449 appendStringInfo(str, " :grpColIdx");
450 for (i = 0; i < node->numCols; i++)
451 appendStringInfo(str, " %d", node->grpColIdx[i]);
455 _outMaterial(StringInfo str, Material *node)
457 WRITE_NODE_TYPE("MATERIAL");
459 _outPlanInfo(str, (Plan *) node);
463 _outSort(StringInfo str, Sort *node)
467 WRITE_NODE_TYPE("SORT");
469 _outPlanInfo(str, (Plan *) node);
471 WRITE_INT_FIELD(numCols);
473 appendStringInfo(str, " :sortColIdx");
474 for (i = 0; i < node->numCols; i++)
475 appendStringInfo(str, " %d", node->sortColIdx[i]);
477 appendStringInfo(str, " :sortOperators");
478 for (i = 0; i < node->numCols; i++)
479 appendStringInfo(str, " %u", node->sortOperators[i]);
483 _outUnique(StringInfo str, Unique *node)
487 WRITE_NODE_TYPE("UNIQUE");
489 _outPlanInfo(str, (Plan *) node);
491 WRITE_INT_FIELD(numCols);
493 appendStringInfo(str, " :uniqColIdx");
494 for (i = 0; i < node->numCols; i++)
495 appendStringInfo(str, " %d", node->uniqColIdx[i]);
499 _outSetOp(StringInfo str, SetOp *node)
503 WRITE_NODE_TYPE("SETOP");
505 _outPlanInfo(str, (Plan *) node);
507 WRITE_ENUM_FIELD(cmd, SetOpCmd);
508 WRITE_INT_FIELD(numCols);
510 appendStringInfo(str, " :dupColIdx");
511 for (i = 0; i < node->numCols; i++)
512 appendStringInfo(str, " %d", node->dupColIdx[i]);
514 WRITE_INT_FIELD(flagColIdx);
518 _outLimit(StringInfo str, Limit *node)
520 WRITE_NODE_TYPE("LIMIT");
522 _outPlanInfo(str, (Plan *) node);
524 WRITE_NODE_FIELD(limitOffset);
525 WRITE_NODE_FIELD(limitCount);
529 _outHash(StringInfo str, Hash *node)
531 WRITE_NODE_TYPE("HASH");
533 _outPlanInfo(str, (Plan *) node);
536 /*****************************************************************************
538 * Stuff from primnodes.h.
540 *****************************************************************************/
543 _outResdom(StringInfo str, Resdom *node)
545 WRITE_NODE_TYPE("RESDOM");
547 WRITE_INT_FIELD(resno);
548 WRITE_OID_FIELD(restype);
549 WRITE_INT_FIELD(restypmod);
550 WRITE_STRING_FIELD(resname);
551 WRITE_UINT_FIELD(ressortgroupref);
552 WRITE_OID_FIELD(resorigtbl);
553 WRITE_INT_FIELD(resorigcol);
554 WRITE_BOOL_FIELD(resjunk);
558 _outAlias(StringInfo str, Alias *node)
560 WRITE_NODE_TYPE("ALIAS");
562 WRITE_STRING_FIELD(aliasname);
563 WRITE_NODE_FIELD(colnames);
567 _outRangeVar(StringInfo str, RangeVar *node)
569 WRITE_NODE_TYPE("RANGEVAR");
572 * we deliberately ignore catalogname here, since it is presently not
573 * semantically meaningful
575 WRITE_STRING_FIELD(schemaname);
576 WRITE_STRING_FIELD(relname);
577 WRITE_ENUM_FIELD(inhOpt, InhOption);
578 WRITE_BOOL_FIELD(istemp);
579 WRITE_NODE_FIELD(alias);
583 _outVar(StringInfo str, Var *node)
585 WRITE_NODE_TYPE("VAR");
587 WRITE_UINT_FIELD(varno);
588 WRITE_INT_FIELD(varattno);
589 WRITE_OID_FIELD(vartype);
590 WRITE_INT_FIELD(vartypmod);
591 WRITE_UINT_FIELD(varlevelsup);
592 WRITE_UINT_FIELD(varnoold);
593 WRITE_INT_FIELD(varoattno);
597 _outConst(StringInfo str, Const *node)
599 WRITE_NODE_TYPE("CONST");
601 WRITE_OID_FIELD(consttype);
602 WRITE_INT_FIELD(constlen);
603 WRITE_BOOL_FIELD(constbyval);
604 WRITE_BOOL_FIELD(constisnull);
606 appendStringInfo(str, " :constvalue ");
607 if (node->constisnull)
608 appendStringInfo(str, "<>");
610 _outDatum(str, node->constvalue, node->constlen, node->constbyval);
614 _outParam(StringInfo str, Param *node)
616 WRITE_NODE_TYPE("PARAM");
618 WRITE_INT_FIELD(paramkind);
619 WRITE_INT_FIELD(paramid);
620 WRITE_STRING_FIELD(paramname);
621 WRITE_OID_FIELD(paramtype);
625 _outAggref(StringInfo str, Aggref *node)
627 WRITE_NODE_TYPE("AGGREF");
629 WRITE_OID_FIELD(aggfnoid);
630 WRITE_OID_FIELD(aggtype);
631 WRITE_NODE_FIELD(target);
632 WRITE_UINT_FIELD(agglevelsup);
633 WRITE_BOOL_FIELD(aggstar);
634 WRITE_BOOL_FIELD(aggdistinct);
638 _outArrayRef(StringInfo str, ArrayRef *node)
640 WRITE_NODE_TYPE("ARRAYREF");
642 WRITE_OID_FIELD(refrestype);
643 WRITE_OID_FIELD(refarraytype);
644 WRITE_OID_FIELD(refelemtype);
645 WRITE_NODE_FIELD(refupperindexpr);
646 WRITE_NODE_FIELD(reflowerindexpr);
647 WRITE_NODE_FIELD(refexpr);
648 WRITE_NODE_FIELD(refassgnexpr);
652 _outFuncExpr(StringInfo str, FuncExpr *node)
654 WRITE_NODE_TYPE("FUNCEXPR");
656 WRITE_OID_FIELD(funcid);
657 WRITE_OID_FIELD(funcresulttype);
658 WRITE_BOOL_FIELD(funcretset);
659 WRITE_ENUM_FIELD(funcformat, CoercionForm);
660 WRITE_NODE_FIELD(args);
664 _outOpExpr(StringInfo str, OpExpr *node)
666 WRITE_NODE_TYPE("OPEXPR");
668 WRITE_OID_FIELD(opno);
669 WRITE_OID_FIELD(opfuncid);
670 WRITE_OID_FIELD(opresulttype);
671 WRITE_BOOL_FIELD(opretset);
672 WRITE_NODE_FIELD(args);
676 _outDistinctExpr(StringInfo str, DistinctExpr *node)
678 WRITE_NODE_TYPE("DISTINCTEXPR");
680 WRITE_OID_FIELD(opno);
681 WRITE_OID_FIELD(opfuncid);
682 WRITE_OID_FIELD(opresulttype);
683 WRITE_BOOL_FIELD(opretset);
684 WRITE_NODE_FIELD(args);
688 _outScalarArrayOpExpr(StringInfo str, ScalarArrayOpExpr *node)
690 WRITE_NODE_TYPE("SCALARARRAYOPEXPR");
692 WRITE_OID_FIELD(opno);
693 WRITE_OID_FIELD(opfuncid);
694 WRITE_BOOL_FIELD(useOr);
695 WRITE_NODE_FIELD(args);
699 _outBoolExpr(StringInfo str, BoolExpr *node)
703 WRITE_NODE_TYPE("BOOLEXPR");
705 /* do-it-yourself enum representation */
706 switch (node->boolop)
718 appendStringInfo(str, " :boolop ");
719 _outToken(str, opstr);
721 WRITE_NODE_FIELD(args);
725 _outSubLink(StringInfo str, SubLink *node)
727 WRITE_NODE_TYPE("SUBLINK");
729 WRITE_ENUM_FIELD(subLinkType, SubLinkType);
730 WRITE_BOOL_FIELD(useOr);
731 WRITE_NODE_FIELD(lefthand);
732 WRITE_NODE_FIELD(operName);
733 WRITE_OIDLIST_FIELD(operOids);
734 WRITE_NODE_FIELD(subselect);
738 _outSubPlan(StringInfo str, SubPlan *node)
740 WRITE_NODE_TYPE("SUBPLAN");
742 WRITE_ENUM_FIELD(subLinkType, SubLinkType);
743 WRITE_BOOL_FIELD(useOr);
744 WRITE_NODE_FIELD(exprs);
745 WRITE_INTLIST_FIELD(paramIds);
746 WRITE_NODE_FIELD(plan);
747 WRITE_INT_FIELD(plan_id);
748 WRITE_NODE_FIELD(rtable);
749 WRITE_BOOL_FIELD(useHashTable);
750 WRITE_BOOL_FIELD(unknownEqFalse);
751 WRITE_INTLIST_FIELD(setParam);
752 WRITE_INTLIST_FIELD(parParam);
753 WRITE_NODE_FIELD(args);
757 _outFieldSelect(StringInfo str, FieldSelect *node)
759 WRITE_NODE_TYPE("FIELDSELECT");
761 WRITE_NODE_FIELD(arg);
762 WRITE_INT_FIELD(fieldnum);
763 WRITE_OID_FIELD(resulttype);
764 WRITE_INT_FIELD(resulttypmod);
768 _outRelabelType(StringInfo str, RelabelType *node)
770 WRITE_NODE_TYPE("RELABELTYPE");
772 WRITE_NODE_FIELD(arg);
773 WRITE_OID_FIELD(resulttype);
774 WRITE_INT_FIELD(resulttypmod);
775 WRITE_ENUM_FIELD(relabelformat, CoercionForm);
779 _outCaseExpr(StringInfo str, CaseExpr *node)
781 WRITE_NODE_TYPE("CASE");
783 WRITE_OID_FIELD(casetype);
784 WRITE_NODE_FIELD(arg);
785 WRITE_NODE_FIELD(args);
786 WRITE_NODE_FIELD(defresult);
790 _outCaseWhen(StringInfo str, CaseWhen *node)
792 WRITE_NODE_TYPE("WHEN");
794 WRITE_NODE_FIELD(expr);
795 WRITE_NODE_FIELD(result);
799 _outArrayExpr(StringInfo str, ArrayExpr *node)
801 WRITE_NODE_TYPE("ARRAY");
803 WRITE_OID_FIELD(array_typeid);
804 WRITE_OID_FIELD(element_typeid);
805 WRITE_NODE_FIELD(elements);
806 WRITE_BOOL_FIELD(multidims);
810 _outCoalesceExpr(StringInfo str, CoalesceExpr *node)
812 WRITE_NODE_TYPE("COALESCE");
814 WRITE_OID_FIELD(coalescetype);
815 WRITE_NODE_FIELD(args);
819 _outNullIfExpr(StringInfo str, NullIfExpr *node)
821 WRITE_NODE_TYPE("NULLIFEXPR");
823 WRITE_OID_FIELD(opno);
824 WRITE_OID_FIELD(opfuncid);
825 WRITE_OID_FIELD(opresulttype);
826 WRITE_BOOL_FIELD(opretset);
827 WRITE_NODE_FIELD(args);
831 _outNullTest(StringInfo str, NullTest *node)
833 WRITE_NODE_TYPE("NULLTEST");
835 WRITE_NODE_FIELD(arg);
836 WRITE_ENUM_FIELD(nulltesttype, NullTestType);
840 _outBooleanTest(StringInfo str, BooleanTest *node)
842 WRITE_NODE_TYPE("BOOLEANTEST");
844 WRITE_NODE_FIELD(arg);
845 WRITE_ENUM_FIELD(booltesttype, BoolTestType);
849 _outCoerceToDomain(StringInfo str, CoerceToDomain *node)
851 WRITE_NODE_TYPE("COERCETODOMAIN");
853 WRITE_NODE_FIELD(arg);
854 WRITE_OID_FIELD(resulttype);
855 WRITE_INT_FIELD(resulttypmod);
856 WRITE_ENUM_FIELD(coercionformat, CoercionForm);
860 _outCoerceToDomainValue(StringInfo str, CoerceToDomainValue *node)
862 WRITE_NODE_TYPE("COERCETODOMAINVALUE");
864 WRITE_OID_FIELD(typeId);
865 WRITE_INT_FIELD(typeMod);
869 _outSetToDefault(StringInfo str, SetToDefault *node)
871 WRITE_NODE_TYPE("SETTODEFAULT");
873 WRITE_OID_FIELD(typeId);
874 WRITE_INT_FIELD(typeMod);
878 _outTargetEntry(StringInfo str, TargetEntry *node)
880 WRITE_NODE_TYPE("TARGETENTRY");
882 WRITE_NODE_FIELD(resdom);
883 WRITE_NODE_FIELD(expr);
887 _outRangeTblRef(StringInfo str, RangeTblRef *node)
889 WRITE_NODE_TYPE("RANGETBLREF");
891 WRITE_INT_FIELD(rtindex);
895 _outJoinExpr(StringInfo str, JoinExpr *node)
897 WRITE_NODE_TYPE("JOINEXPR");
899 WRITE_ENUM_FIELD(jointype, JoinType);
900 WRITE_BOOL_FIELD(isNatural);
901 WRITE_NODE_FIELD(larg);
902 WRITE_NODE_FIELD(rarg);
903 WRITE_NODE_FIELD(using);
904 WRITE_NODE_FIELD(quals);
905 WRITE_NODE_FIELD(alias);
906 WRITE_INT_FIELD(rtindex);
910 _outFromExpr(StringInfo str, FromExpr *node)
912 WRITE_NODE_TYPE("FROMEXPR");
914 WRITE_NODE_FIELD(fromlist);
915 WRITE_NODE_FIELD(quals);
918 /*****************************************************************************
920 * Stuff from relation.h.
922 *****************************************************************************/
925 * print the basic stuff of all nodes that inherit from Path
927 * Note we do NOT print the parent, else we'd be in infinite recursion
930 _outPathInfo(StringInfo str, Path *node)
932 WRITE_ENUM_FIELD(pathtype, NodeTag);
933 WRITE_FLOAT_FIELD(startup_cost, "%.2f");
934 WRITE_FLOAT_FIELD(total_cost, "%.2f");
935 WRITE_NODE_FIELD(pathkeys);
939 * print the basic stuff of all nodes that inherit from JoinPath
942 _outJoinPathInfo(StringInfo str, JoinPath *node)
944 _outPathInfo(str, (Path *) node);
946 WRITE_ENUM_FIELD(jointype, JoinType);
947 WRITE_NODE_FIELD(outerjoinpath);
948 WRITE_NODE_FIELD(innerjoinpath);
949 WRITE_NODE_FIELD(joinrestrictinfo);
953 _outPath(StringInfo str, Path *node)
955 WRITE_NODE_TYPE("PATH");
957 _outPathInfo(str, (Path *) node);
961 * IndexPath is a subclass of Path.
964 _outIndexPath(StringInfo str, IndexPath *node)
966 WRITE_NODE_TYPE("INDEXPATH");
968 _outPathInfo(str, (Path *) node);
970 WRITE_NODE_FIELD(indexinfo);
971 WRITE_NODE_FIELD(indexqual);
972 WRITE_NODE_FIELD(indexjoinclauses);
973 WRITE_ENUM_FIELD(indexscandir, ScanDirection);
974 WRITE_FLOAT_FIELD(rows, "%.0f");
978 _outTidPath(StringInfo str, TidPath *node)
980 WRITE_NODE_TYPE("TIDPATH");
982 _outPathInfo(str, (Path *) node);
984 WRITE_NODE_FIELD(tideval);
988 _outAppendPath(StringInfo str, AppendPath *node)
990 WRITE_NODE_TYPE("APPENDPATH");
992 _outPathInfo(str, (Path *) node);
994 WRITE_NODE_FIELD(subpaths);
998 _outResultPath(StringInfo str, ResultPath *node)
1000 WRITE_NODE_TYPE("RESULTPATH");
1002 _outPathInfo(str, (Path *) node);
1004 WRITE_NODE_FIELD(subpath);
1005 WRITE_NODE_FIELD(constantqual);
1009 _outMaterialPath(StringInfo str, MaterialPath *node)
1011 WRITE_NODE_TYPE("MATERIALPATH");
1013 _outPathInfo(str, (Path *) node);
1015 WRITE_NODE_FIELD(subpath);
1019 _outUniquePath(StringInfo str, UniquePath *node)
1021 WRITE_NODE_TYPE("UNIQUEPATH");
1023 _outPathInfo(str, (Path *) node);
1025 WRITE_NODE_FIELD(subpath);
1026 WRITE_BOOL_FIELD(use_hash);
1027 WRITE_FLOAT_FIELD(rows, "%.0f");
1031 _outNestPath(StringInfo str, NestPath *node)
1033 WRITE_NODE_TYPE("NESTPATH");
1035 _outJoinPathInfo(str, (JoinPath *) node);
1039 _outMergePath(StringInfo str, MergePath *node)
1041 WRITE_NODE_TYPE("MERGEPATH");
1043 _outJoinPathInfo(str, (JoinPath *) node);
1045 WRITE_NODE_FIELD(path_mergeclauses);
1046 WRITE_NODE_FIELD(outersortkeys);
1047 WRITE_NODE_FIELD(innersortkeys);
1051 _outHashPath(StringInfo str, HashPath *node)
1053 WRITE_NODE_TYPE("HASHPATH");
1055 _outJoinPathInfo(str, (JoinPath *) node);
1057 WRITE_NODE_FIELD(path_hashclauses);
1061 _outPathKeyItem(StringInfo str, PathKeyItem *node)
1063 WRITE_NODE_TYPE("PATHKEYITEM");
1065 WRITE_NODE_FIELD(key);
1066 WRITE_OID_FIELD(sortop);
1070 _outRestrictInfo(StringInfo str, RestrictInfo *node)
1072 WRITE_NODE_TYPE("RESTRICTINFO");
1074 /* NB: this isn't a complete set of fields */
1075 WRITE_NODE_FIELD(clause);
1076 WRITE_BOOL_FIELD(is_pushed_down);
1077 WRITE_BOOL_FIELD(valid_everywhere);
1078 WRITE_BOOL_FIELD(can_join);
1079 WRITE_BITMAPSET_FIELD(clause_relids);
1080 WRITE_BITMAPSET_FIELD(left_relids);
1081 WRITE_BITMAPSET_FIELD(right_relids);
1082 WRITE_NODE_FIELD(orclause);
1083 WRITE_OID_FIELD(mergejoinoperator);
1084 WRITE_OID_FIELD(left_sortop);
1085 WRITE_OID_FIELD(right_sortop);
1086 WRITE_NODE_FIELD(left_pathkey);
1087 WRITE_NODE_FIELD(right_pathkey);
1088 WRITE_OID_FIELD(hashjoinoperator);
1092 _outJoinInfo(StringInfo str, JoinInfo *node)
1094 WRITE_NODE_TYPE("JOININFO");
1096 WRITE_BITMAPSET_FIELD(unjoined_relids);
1097 WRITE_NODE_FIELD(jinfo_restrictinfo);
1101 _outInClauseInfo(StringInfo str, InClauseInfo *node)
1103 WRITE_NODE_TYPE("INCLAUSEINFO");
1105 WRITE_BITMAPSET_FIELD(lefthand);
1106 WRITE_BITMAPSET_FIELD(righthand);
1107 WRITE_NODE_FIELD(sub_targetlist);
1110 /*****************************************************************************
1112 * Stuff from parsenodes.h.
1114 *****************************************************************************/
1117 _outCreateStmt(StringInfo str, CreateStmt *node)
1119 WRITE_NODE_TYPE("CREATE");
1121 WRITE_NODE_FIELD(relation);
1122 WRITE_NODE_FIELD(tableElts);
1123 WRITE_NODE_FIELD(inhRelations);
1124 WRITE_NODE_FIELD(constraints);
1125 WRITE_BOOL_FIELD(hasoids);
1126 WRITE_ENUM_FIELD(oncommit, OnCommitAction);
1130 _outIndexStmt(StringInfo str, IndexStmt *node)
1132 WRITE_NODE_TYPE("INDEX");
1134 WRITE_STRING_FIELD(idxname);
1135 WRITE_NODE_FIELD(relation);
1136 WRITE_STRING_FIELD(accessMethod);
1137 WRITE_NODE_FIELD(indexParams);
1138 WRITE_NODE_FIELD(whereClause);
1139 WRITE_NODE_FIELD(rangetable);
1140 WRITE_BOOL_FIELD(unique);
1141 WRITE_BOOL_FIELD(primary);
1142 WRITE_BOOL_FIELD(isconstraint);
1146 _outNotifyStmt(StringInfo str, NotifyStmt *node)
1148 WRITE_NODE_TYPE("NOTIFY");
1150 WRITE_NODE_FIELD(relation);
1154 _outDeclareCursorStmt(StringInfo str, DeclareCursorStmt *node)
1156 WRITE_NODE_TYPE("DECLARECURSOR");
1158 WRITE_STRING_FIELD(portalname);
1159 WRITE_INT_FIELD(options);
1160 WRITE_NODE_FIELD(query);
1164 _outSelectStmt(StringInfo str, SelectStmt *node)
1166 WRITE_NODE_TYPE("SELECT");
1168 /* XXX this is pretty durn incomplete */
1169 WRITE_NODE_FIELD(whereClause);
1173 _outFuncCall(StringInfo str, FuncCall *node)
1175 WRITE_NODE_TYPE("FUNCCALL");
1177 WRITE_NODE_FIELD(funcname);
1178 WRITE_NODE_FIELD(args);
1179 WRITE_BOOL_FIELD(agg_star);
1180 WRITE_BOOL_FIELD(agg_distinct);
1184 _outColumnDef(StringInfo str, ColumnDef *node)
1186 WRITE_NODE_TYPE("COLUMNDEF");
1188 WRITE_STRING_FIELD(colname);
1189 WRITE_NODE_FIELD(typename);
1190 WRITE_INT_FIELD(inhcount);
1191 WRITE_BOOL_FIELD(is_local);
1192 WRITE_BOOL_FIELD(is_not_null);
1193 WRITE_NODE_FIELD(raw_default);
1194 WRITE_STRING_FIELD(cooked_default);
1195 WRITE_NODE_FIELD(constraints);
1196 WRITE_NODE_FIELD(support);
1200 _outTypeName(StringInfo str, TypeName *node)
1202 WRITE_NODE_TYPE("TYPENAME");
1204 WRITE_NODE_FIELD(names);
1205 WRITE_OID_FIELD(typeid);
1206 WRITE_BOOL_FIELD(timezone);
1207 WRITE_BOOL_FIELD(setof);
1208 WRITE_BOOL_FIELD(pct_type);
1209 WRITE_INT_FIELD(typmod);
1210 WRITE_NODE_FIELD(arrayBounds);
1214 _outTypeCast(StringInfo str, TypeCast *node)
1216 WRITE_NODE_TYPE("TYPECAST");
1218 WRITE_NODE_FIELD(arg);
1219 WRITE_NODE_FIELD(typename);
1223 _outIndexElem(StringInfo str, IndexElem *node)
1225 WRITE_NODE_TYPE("INDEXELEM");
1227 WRITE_STRING_FIELD(name);
1228 WRITE_NODE_FIELD(expr);
1229 WRITE_NODE_FIELD(opclass);
1233 _outQuery(StringInfo str, Query *node)
1235 WRITE_NODE_TYPE("QUERY");
1237 WRITE_ENUM_FIELD(commandType, CmdType);
1238 WRITE_ENUM_FIELD(querySource, QuerySource);
1239 WRITE_BOOL_FIELD(canSetTag);
1242 * Hack to work around missing outfuncs routines for a lot of the
1243 * utility-statement node types. (The only one we actually *need* for
1244 * rules support is NotifyStmt.) Someday we ought to support 'em all,
1245 * but for the meantime do this to avoid getting lots of warnings when
1246 * running with debug_print_parse on.
1248 if (node->utilityStmt)
1250 switch (nodeTag(node->utilityStmt))
1255 case T_DeclareCursorStmt:
1256 WRITE_NODE_FIELD(utilityStmt);
1259 appendStringInfo(str, " :utilityStmt ?");
1264 appendStringInfo(str, " :utilityStmt <>");
1266 WRITE_INT_FIELD(resultRelation);
1267 WRITE_NODE_FIELD(into);
1268 WRITE_BOOL_FIELD(hasAggs);
1269 WRITE_BOOL_FIELD(hasSubLinks);
1270 WRITE_NODE_FIELD(rtable);
1271 WRITE_NODE_FIELD(jointree);
1272 WRITE_INTLIST_FIELD(rowMarks);
1273 WRITE_NODE_FIELD(targetList);
1274 WRITE_NODE_FIELD(groupClause);
1275 WRITE_NODE_FIELD(havingQual);
1276 WRITE_NODE_FIELD(distinctClause);
1277 WRITE_NODE_FIELD(sortClause);
1278 WRITE_NODE_FIELD(limitOffset);
1279 WRITE_NODE_FIELD(limitCount);
1280 WRITE_NODE_FIELD(setOperations);
1281 WRITE_INTLIST_FIELD(resultRelations);
1283 /* planner-internal fields are not written out */
1287 _outSortClause(StringInfo str, SortClause *node)
1289 WRITE_NODE_TYPE("SORTCLAUSE");
1291 WRITE_UINT_FIELD(tleSortGroupRef);
1292 WRITE_OID_FIELD(sortop);
1296 _outGroupClause(StringInfo str, GroupClause *node)
1298 WRITE_NODE_TYPE("GROUPCLAUSE");
1300 WRITE_UINT_FIELD(tleSortGroupRef);
1301 WRITE_OID_FIELD(sortop);
1305 _outSetOperationStmt(StringInfo str, SetOperationStmt *node)
1307 WRITE_NODE_TYPE("SETOPERATIONSTMT");
1309 WRITE_ENUM_FIELD(op, SetOperation);
1310 WRITE_BOOL_FIELD(all);
1311 WRITE_NODE_FIELD(larg);
1312 WRITE_NODE_FIELD(rarg);
1313 WRITE_OIDLIST_FIELD(colTypes);
1317 _outRangeTblEntry(StringInfo str, RangeTblEntry *node)
1319 WRITE_NODE_TYPE("RTE");
1321 /* put alias + eref first to make dump more legible */
1322 WRITE_NODE_FIELD(alias);
1323 WRITE_NODE_FIELD(eref);
1324 WRITE_ENUM_FIELD(rtekind, RTEKind);
1326 switch (node->rtekind)
1330 WRITE_OID_FIELD(relid);
1333 WRITE_NODE_FIELD(subquery);
1336 WRITE_NODE_FIELD(funcexpr);
1337 WRITE_NODE_FIELD(coldeflist);
1340 WRITE_ENUM_FIELD(jointype, JoinType);
1341 WRITE_NODE_FIELD(joinaliasvars);
1344 elog(ERROR, "unrecognized RTE kind: %d", (int) node->rtekind);
1348 WRITE_BOOL_FIELD(inh);
1349 WRITE_BOOL_FIELD(inFromCl);
1350 WRITE_BOOL_FIELD(checkForRead);
1351 WRITE_BOOL_FIELD(checkForWrite);
1352 WRITE_OID_FIELD(checkAsUser);
1356 _outAExpr(StringInfo str, A_Expr *node)
1358 WRITE_NODE_TYPE("AEXPR");
1363 appendStringInfo(str, " ");
1364 WRITE_NODE_FIELD(name);
1367 appendStringInfo(str, " AND");
1370 appendStringInfo(str, " OR");
1373 appendStringInfo(str, " NOT");
1376 appendStringInfo(str, " ");
1377 WRITE_NODE_FIELD(name);
1378 appendStringInfo(str, " ANY ");
1381 appendStringInfo(str, " ");
1382 WRITE_NODE_FIELD(name);
1383 appendStringInfo(str, " ALL ");
1385 case AEXPR_DISTINCT:
1386 appendStringInfo(str, " DISTINCT ");
1387 WRITE_NODE_FIELD(name);
1390 appendStringInfo(str, " NULLIF ");
1391 WRITE_NODE_FIELD(name);
1394 appendStringInfo(str, " OF ");
1395 WRITE_NODE_FIELD(name);
1398 appendStringInfo(str, " ??");
1402 WRITE_NODE_FIELD(lexpr);
1403 WRITE_NODE_FIELD(rexpr);
1407 _outValue(StringInfo str, Value *value)
1409 switch (value->type)
1412 appendStringInfo(str, "%ld", value->val.ival);
1417 * We assume the value is a valid numeric literal and so does
1420 appendStringInfo(str, "%s", value->val.str);
1423 appendStringInfoChar(str, '"');
1424 _outToken(str, value->val.str);
1425 appendStringInfoChar(str, '"');
1428 /* internal representation already has leading 'b' */
1429 appendStringInfo(str, "%s", value->val.str);
1432 elog(ERROR, "unrecognized node type: %d", (int) value->type);
1438 _outColumnRef(StringInfo str, ColumnRef *node)
1440 WRITE_NODE_TYPE("COLUMNREF");
1442 WRITE_NODE_FIELD(fields);
1443 WRITE_NODE_FIELD(indirection);
1447 _outParamRef(StringInfo str, ParamRef *node)
1449 WRITE_NODE_TYPE("PARAMREF");
1451 WRITE_INT_FIELD(number);
1452 WRITE_NODE_FIELD(fields);
1453 WRITE_NODE_FIELD(indirection);
1457 _outAConst(StringInfo str, A_Const *node)
1459 WRITE_NODE_TYPE("CONST ");
1461 _outValue(str, &(node->val));
1462 WRITE_NODE_FIELD(typename);
1466 _outExprFieldSelect(StringInfo str, ExprFieldSelect *node)
1468 WRITE_NODE_TYPE("EXPRFIELDSELECT");
1470 WRITE_NODE_FIELD(arg);
1471 WRITE_NODE_FIELD(fields);
1472 WRITE_NODE_FIELD(indirection);
1476 _outConstraint(StringInfo str, Constraint *node)
1478 WRITE_NODE_TYPE("CONSTRAINT");
1480 WRITE_STRING_FIELD(name);
1482 appendStringInfo(str, " :contype ");
1483 switch (node->contype)
1485 case CONSTR_PRIMARY:
1486 appendStringInfo(str, "PRIMARY_KEY");
1487 WRITE_NODE_FIELD(keys);
1491 appendStringInfo(str, "CHECK");
1492 WRITE_NODE_FIELD(raw_expr);
1493 WRITE_STRING_FIELD(cooked_expr);
1496 case CONSTR_DEFAULT:
1497 appendStringInfo(str, "DEFAULT");
1498 WRITE_NODE_FIELD(raw_expr);
1499 WRITE_STRING_FIELD(cooked_expr);
1502 case CONSTR_NOTNULL:
1503 appendStringInfo(str, "NOT_NULL");
1507 appendStringInfo(str, "UNIQUE");
1508 WRITE_NODE_FIELD(keys);
1512 appendStringInfo(str, "<unrecognized_constraint>");
1518 _outFkConstraint(StringInfo str, FkConstraint *node)
1520 WRITE_NODE_TYPE("FKCONSTRAINT");
1522 WRITE_STRING_FIELD(constr_name);
1523 WRITE_NODE_FIELD(pktable);
1524 WRITE_NODE_FIELD(fk_attrs);
1525 WRITE_NODE_FIELD(pk_attrs);
1526 WRITE_CHAR_FIELD(fk_matchtype);
1527 WRITE_CHAR_FIELD(fk_upd_action);
1528 WRITE_CHAR_FIELD(fk_del_action);
1529 WRITE_BOOL_FIELD(deferrable);
1530 WRITE_BOOL_FIELD(initdeferred);
1531 WRITE_BOOL_FIELD(skip_validation);
1537 * converts a Node into ascii string and append it to 'str'
1540 _outNode(StringInfo str, void *obj)
1544 appendStringInfo(str, "<>");
1552 appendStringInfoChar(str, '(');
1553 foreach(l, (List *) obj)
1555 _outNode(str, lfirst(l));
1557 appendStringInfoChar(str, ' ');
1559 appendStringInfoChar(str, ')');
1561 else if (IsA(obj, Integer) ||
1564 IsA(obj, BitString))
1566 /* nodeRead does not want to see { } around these! */
1567 _outValue(str, obj);
1571 appendStringInfoChar(str, '{');
1572 switch (nodeTag(obj))
1578 _outResult(str, obj);
1581 _outAppend(str, obj);
1587 _outSeqScan(str, obj);
1590 _outIndexScan(str, obj);
1593 _outTidScan(str, obj);
1595 case T_SubqueryScan:
1596 _outSubqueryScan(str, obj);
1598 case T_FunctionScan:
1599 _outFunctionScan(str, obj);
1605 _outNestLoop(str, obj);
1608 _outMergeJoin(str, obj);
1611 _outHashJoin(str, obj);
1617 _outGroup(str, obj);
1620 _outMaterial(str, obj);
1626 _outUnique(str, obj);
1629 _outSetOp(str, obj);
1632 _outLimit(str, obj);
1638 _outResdom(str, obj);
1641 _outAlias(str, obj);
1644 _outRangeVar(str, obj);
1650 _outConst(str, obj);
1653 _outParam(str, obj);
1656 _outAggref(str, obj);
1659 _outArrayRef(str, obj);
1662 _outFuncExpr(str, obj);
1665 _outOpExpr(str, obj);
1667 case T_DistinctExpr:
1668 _outDistinctExpr(str, obj);
1670 case T_ScalarArrayOpExpr:
1671 _outScalarArrayOpExpr(str, obj);
1674 _outBoolExpr(str, obj);
1677 _outSubLink(str, obj);
1680 _outSubPlan(str, obj);
1683 _outFieldSelect(str, obj);
1686 _outRelabelType(str, obj);
1689 _outCaseExpr(str, obj);
1692 _outCaseWhen(str, obj);
1695 _outArrayExpr(str, obj);
1697 case T_CoalesceExpr:
1698 _outCoalesceExpr(str, obj);
1701 _outNullIfExpr(str, obj);
1704 _outNullTest(str, obj);
1707 _outBooleanTest(str, obj);
1709 case T_CoerceToDomain:
1710 _outCoerceToDomain(str, obj);
1712 case T_CoerceToDomainValue:
1713 _outCoerceToDomainValue(str, obj);
1715 case T_SetToDefault:
1716 _outSetToDefault(str, obj);
1719 _outTargetEntry(str, obj);
1722 _outRangeTblRef(str, obj);
1725 _outJoinExpr(str, obj);
1728 _outFromExpr(str, obj);
1735 _outIndexPath(str, obj);
1738 _outTidPath(str, obj);
1741 _outAppendPath(str, obj);
1744 _outResultPath(str, obj);
1746 case T_MaterialPath:
1747 _outMaterialPath(str, obj);
1750 _outUniquePath(str, obj);
1753 _outNestPath(str, obj);
1756 _outMergePath(str, obj);
1759 _outHashPath(str, obj);
1762 _outPathKeyItem(str, obj);
1764 case T_RestrictInfo:
1765 _outRestrictInfo(str, obj);
1768 _outJoinInfo(str, obj);
1770 case T_InClauseInfo:
1771 _outInClauseInfo(str, obj);
1775 _outCreateStmt(str, obj);
1778 _outIndexStmt(str, obj);
1781 _outNotifyStmt(str, obj);
1783 case T_DeclareCursorStmt:
1784 _outDeclareCursorStmt(str, obj);
1787 _outSelectStmt(str, obj);
1790 _outColumnDef(str, obj);
1793 _outTypeName(str, obj);
1796 _outTypeCast(str, obj);
1799 _outIndexElem(str, obj);
1802 _outQuery(str, obj);
1805 _outSortClause(str, obj);
1808 _outGroupClause(str, obj);
1810 case T_SetOperationStmt:
1811 _outSetOperationStmt(str, obj);
1813 case T_RangeTblEntry:
1814 _outRangeTblEntry(str, obj);
1817 _outAExpr(str, obj);
1820 _outColumnRef(str, obj);
1823 _outParamRef(str, obj);
1826 _outAConst(str, obj);
1828 case T_ExprFieldSelect:
1829 _outExprFieldSelect(str, obj);
1832 _outConstraint(str, obj);
1834 case T_FkConstraint:
1835 _outFkConstraint(str, obj);
1838 _outFuncCall(str, obj);
1844 * This should be an ERROR, but it's too useful to be able
1845 * to dump structures that _outNode only understands part
1848 elog(WARNING, "could not dump unrecognized node type: %d",
1849 (int) nodeTag(obj));
1852 appendStringInfoChar(str, '}');
1858 * returns the ascii representation of the Node as a palloc'd string
1861 nodeToString(void *obj)
1865 /* see stringinfo.h for an explanation of this maneuver */
1866 initStringInfo(&str);
1867 _outNode(&str, obj);