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.237 2004/05/26 04:41:19 neilc 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 *-------------------------------------------------------------------------
22 #define DISABLE_LIST_COMPAT
28 #include "lib/stringinfo.h"
29 #include "nodes/parsenodes.h"
30 #include "nodes/plannodes.h"
31 #include "nodes/relation.h"
32 #include "utils/datum.h"
36 * Macros to simplify output of different kinds of fields. Use these
37 * wherever possible to reduce the chance for silly typos. Note that these
38 * hard-wire conventions about the names of the local variables in an Out
42 /* Write the label for the node type */
43 #define WRITE_NODE_TYPE(nodelabel) \
44 appendStringInfoString(str, nodelabel)
46 /* Write an integer field (anything written as ":fldname %d") */
47 #define WRITE_INT_FIELD(fldname) \
48 appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname)
50 /* Write an unsigned integer field (anything written as ":fldname %u") */
51 #define WRITE_UINT_FIELD(fldname) \
52 appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
54 /* Write an OID field (don't hard-wire assumption that OID is same as uint) */
55 #define WRITE_OID_FIELD(fldname) \
56 appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
58 /* Write a long-integer field */
59 #define WRITE_LONG_FIELD(fldname) \
60 appendStringInfo(str, " :" CppAsString(fldname) " %ld", node->fldname)
62 /* Write a char field (ie, one ascii character) */
63 #define WRITE_CHAR_FIELD(fldname) \
64 appendStringInfo(str, " :" CppAsString(fldname) " %c", node->fldname)
66 /* Write an enumerated-type field as an integer code */
67 #define WRITE_ENUM_FIELD(fldname, enumtype) \
68 appendStringInfo(str, " :" CppAsString(fldname) " %d", \
71 /* Write a float field --- caller must give format to define precision */
72 #define WRITE_FLOAT_FIELD(fldname,format) \
73 appendStringInfo(str, " :" CppAsString(fldname) " " format, node->fldname)
75 /* Write a boolean field */
76 #define WRITE_BOOL_FIELD(fldname) \
77 appendStringInfo(str, " :" CppAsString(fldname) " %s", \
78 booltostr(node->fldname))
80 /* Write a character-string (possibly NULL) field */
81 #define WRITE_STRING_FIELD(fldname) \
82 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
83 _outToken(str, node->fldname))
85 /* Write a Node field */
86 #define WRITE_NODE_FIELD(fldname) \
87 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
88 _outNode(str, node->fldname))
90 /* Write a bitmapset field */
91 #define WRITE_BITMAPSET_FIELD(fldname) \
92 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
93 _outBitmapset(str, node->fldname))
96 #define booltostr(x) ((x) ? "true" : "false")
98 static void _outNode(StringInfo str, void *obj);
103 * Convert an ordinary string (eg, an identifier) into a form that
104 * will be decoded back to a plain token by read.c's functions.
106 * If a null or empty string is given, it is encoded as "<>".
109 _outToken(StringInfo str, char *s)
111 if (s == NULL || *s == '\0')
113 appendStringInfo(str, "<>");
118 * Look for characters or patterns that are treated specially by
119 * read.c (either in pg_strtok() or in nodeRead()), and therefore need
120 * a protective backslash.
122 /* These characters only need to be quoted at the start of the string */
125 isdigit((unsigned char) *s) ||
126 ((*s == '+' || *s == '-') &&
127 (isdigit((unsigned char) s[1]) || s[1] == '.')))
128 appendStringInfoChar(str, '\\');
131 /* These chars must be backslashed anywhere in the string */
132 if (*s == ' ' || *s == '\n' || *s == '\t' ||
133 *s == '(' || *s == ')' || *s == '{' || *s == '}' ||
135 appendStringInfoChar(str, '\\');
136 appendStringInfoChar(str, *s++);
141 _outList(StringInfo str, List *node)
145 appendStringInfoChar(str, '(');
147 if (IsA(node, IntList))
148 appendStringInfoChar(str, 'i');
149 else if (IsA(node, OidList))
150 appendStringInfoChar(str, 'o');
155 * For the sake of backward compatibility, we emit a slightly
156 * different whitespace format for lists of nodes vs. other
157 * types of lists. XXX: is this necessary?
161 _outNode(str, lfirst(lc));
163 appendStringInfoChar(str, ' ');
165 else if (IsA(node, IntList))
166 appendStringInfo(str, " %d", lfirst_int(lc));
167 else if (IsA(node, OidList))
168 appendStringInfo(str, " %u", lfirst_oid(lc));
170 elog(ERROR, "unrecognized list node type: %d",
174 appendStringInfoChar(str, ')');
179 * converts a bitmap set of integers
181 * Note: the output format is "(b int int ...)", similar to an integer List.
182 * Currently bitmapsets do not appear in any node type that is stored in
183 * rules, so there is no support in readfuncs.c for reading this format.
186 _outBitmapset(StringInfo str, Bitmapset *bms)
191 appendStringInfoChar(str, '(');
192 appendStringInfoChar(str, 'b');
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_NODE_FIELD(indxid);
337 WRITE_NODE_FIELD(indxqual);
338 WRITE_NODE_FIELD(indxqualorig);
339 WRITE_NODE_FIELD(indxstrategy);
340 WRITE_NODE_FIELD(indxsubtype);
341 WRITE_NODE_FIELD(indxlossy);
342 WRITE_ENUM_FIELD(indxorderdir, ScanDirection);
346 _outTidScan(StringInfo str, TidScan *node)
348 WRITE_NODE_TYPE("TIDSCAN");
350 _outScanInfo(str, (Scan *) node);
352 WRITE_NODE_FIELD(tideval);
356 _outSubqueryScan(StringInfo str, SubqueryScan *node)
358 WRITE_NODE_TYPE("SUBQUERYSCAN");
360 _outScanInfo(str, (Scan *) node);
362 WRITE_NODE_FIELD(subplan);
366 _outFunctionScan(StringInfo str, FunctionScan *node)
368 WRITE_NODE_TYPE("FUNCTIONSCAN");
370 _outScanInfo(str, (Scan *) node);
374 _outJoin(StringInfo str, Join *node)
376 WRITE_NODE_TYPE("JOIN");
378 _outJoinPlanInfo(str, (Join *) node);
382 _outNestLoop(StringInfo str, NestLoop *node)
384 WRITE_NODE_TYPE("NESTLOOP");
386 _outJoinPlanInfo(str, (Join *) node);
390 _outMergeJoin(StringInfo str, MergeJoin *node)
392 WRITE_NODE_TYPE("MERGEJOIN");
394 _outJoinPlanInfo(str, (Join *) node);
396 WRITE_NODE_FIELD(mergeclauses);
400 _outHashJoin(StringInfo str, HashJoin *node)
402 WRITE_NODE_TYPE("HASHJOIN");
404 _outJoinPlanInfo(str, (Join *) node);
406 WRITE_NODE_FIELD(hashclauses);
410 _outAgg(StringInfo str, Agg *node)
412 WRITE_NODE_TYPE("AGG");
414 _outPlanInfo(str, (Plan *) node);
416 WRITE_ENUM_FIELD(aggstrategy, AggStrategy);
417 WRITE_INT_FIELD(numCols);
418 WRITE_LONG_FIELD(numGroups);
422 _outGroup(StringInfo str, Group *node)
426 WRITE_NODE_TYPE("GROUP");
428 _outPlanInfo(str, (Plan *) node);
430 WRITE_INT_FIELD(numCols);
432 appendStringInfo(str, " :grpColIdx");
433 for (i = 0; i < node->numCols; i++)
434 appendStringInfo(str, " %d", node->grpColIdx[i]);
438 _outMaterial(StringInfo str, Material *node)
440 WRITE_NODE_TYPE("MATERIAL");
442 _outPlanInfo(str, (Plan *) node);
446 _outSort(StringInfo str, Sort *node)
450 WRITE_NODE_TYPE("SORT");
452 _outPlanInfo(str, (Plan *) node);
454 WRITE_INT_FIELD(numCols);
456 appendStringInfo(str, " :sortColIdx");
457 for (i = 0; i < node->numCols; i++)
458 appendStringInfo(str, " %d", node->sortColIdx[i]);
460 appendStringInfo(str, " :sortOperators");
461 for (i = 0; i < node->numCols; i++)
462 appendStringInfo(str, " %u", node->sortOperators[i]);
466 _outUnique(StringInfo str, Unique *node)
470 WRITE_NODE_TYPE("UNIQUE");
472 _outPlanInfo(str, (Plan *) node);
474 WRITE_INT_FIELD(numCols);
476 appendStringInfo(str, " :uniqColIdx");
477 for (i = 0; i < node->numCols; i++)
478 appendStringInfo(str, " %d", node->uniqColIdx[i]);
482 _outSetOp(StringInfo str, SetOp *node)
486 WRITE_NODE_TYPE("SETOP");
488 _outPlanInfo(str, (Plan *) node);
490 WRITE_ENUM_FIELD(cmd, SetOpCmd);
491 WRITE_INT_FIELD(numCols);
493 appendStringInfo(str, " :dupColIdx");
494 for (i = 0; i < node->numCols; i++)
495 appendStringInfo(str, " %d", node->dupColIdx[i]);
497 WRITE_INT_FIELD(flagColIdx);
501 _outLimit(StringInfo str, Limit *node)
503 WRITE_NODE_TYPE("LIMIT");
505 _outPlanInfo(str, (Plan *) node);
507 WRITE_NODE_FIELD(limitOffset);
508 WRITE_NODE_FIELD(limitCount);
512 _outHash(StringInfo str, Hash *node)
514 WRITE_NODE_TYPE("HASH");
516 _outPlanInfo(str, (Plan *) node);
519 /*****************************************************************************
521 * Stuff from primnodes.h.
523 *****************************************************************************/
526 _outResdom(StringInfo str, Resdom *node)
528 WRITE_NODE_TYPE("RESDOM");
530 WRITE_INT_FIELD(resno);
531 WRITE_OID_FIELD(restype);
532 WRITE_INT_FIELD(restypmod);
533 WRITE_STRING_FIELD(resname);
534 WRITE_UINT_FIELD(ressortgroupref);
535 WRITE_OID_FIELD(resorigtbl);
536 WRITE_INT_FIELD(resorigcol);
537 WRITE_BOOL_FIELD(resjunk);
541 _outAlias(StringInfo str, Alias *node)
543 WRITE_NODE_TYPE("ALIAS");
545 WRITE_STRING_FIELD(aliasname);
546 WRITE_NODE_FIELD(colnames);
550 _outRangeVar(StringInfo str, RangeVar *node)
552 WRITE_NODE_TYPE("RANGEVAR");
555 * we deliberately ignore catalogname here, since it is presently not
556 * semantically meaningful
558 WRITE_STRING_FIELD(schemaname);
559 WRITE_STRING_FIELD(relname);
560 WRITE_ENUM_FIELD(inhOpt, InhOption);
561 WRITE_BOOL_FIELD(istemp);
562 WRITE_NODE_FIELD(alias);
566 _outVar(StringInfo str, Var *node)
568 WRITE_NODE_TYPE("VAR");
570 WRITE_UINT_FIELD(varno);
571 WRITE_INT_FIELD(varattno);
572 WRITE_OID_FIELD(vartype);
573 WRITE_INT_FIELD(vartypmod);
574 WRITE_UINT_FIELD(varlevelsup);
575 WRITE_UINT_FIELD(varnoold);
576 WRITE_INT_FIELD(varoattno);
580 _outConst(StringInfo str, Const *node)
582 WRITE_NODE_TYPE("CONST");
584 WRITE_OID_FIELD(consttype);
585 WRITE_INT_FIELD(constlen);
586 WRITE_BOOL_FIELD(constbyval);
587 WRITE_BOOL_FIELD(constisnull);
589 appendStringInfo(str, " :constvalue ");
590 if (node->constisnull)
591 appendStringInfo(str, "<>");
593 _outDatum(str, node->constvalue, node->constlen, node->constbyval);
597 _outParam(StringInfo str, Param *node)
599 WRITE_NODE_TYPE("PARAM");
601 WRITE_INT_FIELD(paramkind);
602 WRITE_INT_FIELD(paramid);
603 WRITE_STRING_FIELD(paramname);
604 WRITE_OID_FIELD(paramtype);
608 _outAggref(StringInfo str, Aggref *node)
610 WRITE_NODE_TYPE("AGGREF");
612 WRITE_OID_FIELD(aggfnoid);
613 WRITE_OID_FIELD(aggtype);
614 WRITE_NODE_FIELD(target);
615 WRITE_UINT_FIELD(agglevelsup);
616 WRITE_BOOL_FIELD(aggstar);
617 WRITE_BOOL_FIELD(aggdistinct);
621 _outArrayRef(StringInfo str, ArrayRef *node)
623 WRITE_NODE_TYPE("ARRAYREF");
625 WRITE_OID_FIELD(refrestype);
626 WRITE_OID_FIELD(refarraytype);
627 WRITE_OID_FIELD(refelemtype);
628 WRITE_NODE_FIELD(refupperindexpr);
629 WRITE_NODE_FIELD(reflowerindexpr);
630 WRITE_NODE_FIELD(refexpr);
631 WRITE_NODE_FIELD(refassgnexpr);
635 _outFuncExpr(StringInfo str, FuncExpr *node)
637 WRITE_NODE_TYPE("FUNCEXPR");
639 WRITE_OID_FIELD(funcid);
640 WRITE_OID_FIELD(funcresulttype);
641 WRITE_BOOL_FIELD(funcretset);
642 WRITE_ENUM_FIELD(funcformat, CoercionForm);
643 WRITE_NODE_FIELD(args);
647 _outOpExpr(StringInfo str, OpExpr *node)
649 WRITE_NODE_TYPE("OPEXPR");
651 WRITE_OID_FIELD(opno);
652 WRITE_OID_FIELD(opfuncid);
653 WRITE_OID_FIELD(opresulttype);
654 WRITE_BOOL_FIELD(opretset);
655 WRITE_NODE_FIELD(args);
659 _outDistinctExpr(StringInfo str, DistinctExpr *node)
661 WRITE_NODE_TYPE("DISTINCTEXPR");
663 WRITE_OID_FIELD(opno);
664 WRITE_OID_FIELD(opfuncid);
665 WRITE_OID_FIELD(opresulttype);
666 WRITE_BOOL_FIELD(opretset);
667 WRITE_NODE_FIELD(args);
671 _outScalarArrayOpExpr(StringInfo str, ScalarArrayOpExpr *node)
673 WRITE_NODE_TYPE("SCALARARRAYOPEXPR");
675 WRITE_OID_FIELD(opno);
676 WRITE_OID_FIELD(opfuncid);
677 WRITE_BOOL_FIELD(useOr);
678 WRITE_NODE_FIELD(args);
682 _outBoolExpr(StringInfo str, BoolExpr *node)
686 WRITE_NODE_TYPE("BOOLEXPR");
688 /* do-it-yourself enum representation */
689 switch (node->boolop)
701 appendStringInfo(str, " :boolop ");
702 _outToken(str, opstr);
704 WRITE_NODE_FIELD(args);
708 _outSubLink(StringInfo str, SubLink *node)
710 WRITE_NODE_TYPE("SUBLINK");
712 WRITE_ENUM_FIELD(subLinkType, SubLinkType);
713 WRITE_BOOL_FIELD(useOr);
714 WRITE_NODE_FIELD(lefthand);
715 WRITE_NODE_FIELD(operName);
716 WRITE_NODE_FIELD(operOids);
717 WRITE_NODE_FIELD(subselect);
721 _outSubPlan(StringInfo str, SubPlan *node)
723 WRITE_NODE_TYPE("SUBPLAN");
725 WRITE_ENUM_FIELD(subLinkType, SubLinkType);
726 WRITE_BOOL_FIELD(useOr);
727 WRITE_NODE_FIELD(exprs);
728 WRITE_NODE_FIELD(paramIds);
729 WRITE_NODE_FIELD(plan);
730 WRITE_INT_FIELD(plan_id);
731 WRITE_NODE_FIELD(rtable);
732 WRITE_BOOL_FIELD(useHashTable);
733 WRITE_BOOL_FIELD(unknownEqFalse);
734 WRITE_NODE_FIELD(setParam);
735 WRITE_NODE_FIELD(parParam);
736 WRITE_NODE_FIELD(args);
740 _outFieldSelect(StringInfo str, FieldSelect *node)
742 WRITE_NODE_TYPE("FIELDSELECT");
744 WRITE_NODE_FIELD(arg);
745 WRITE_INT_FIELD(fieldnum);
746 WRITE_OID_FIELD(resulttype);
747 WRITE_INT_FIELD(resulttypmod);
751 _outRelabelType(StringInfo str, RelabelType *node)
753 WRITE_NODE_TYPE("RELABELTYPE");
755 WRITE_NODE_FIELD(arg);
756 WRITE_OID_FIELD(resulttype);
757 WRITE_INT_FIELD(resulttypmod);
758 WRITE_ENUM_FIELD(relabelformat, CoercionForm);
762 _outCaseExpr(StringInfo str, CaseExpr *node)
764 WRITE_NODE_TYPE("CASE");
766 WRITE_OID_FIELD(casetype);
767 WRITE_NODE_FIELD(arg);
768 WRITE_NODE_FIELD(args);
769 WRITE_NODE_FIELD(defresult);
773 _outCaseWhen(StringInfo str, CaseWhen *node)
775 WRITE_NODE_TYPE("WHEN");
777 WRITE_NODE_FIELD(expr);
778 WRITE_NODE_FIELD(result);
782 _outCaseTestExpr(StringInfo str, CaseTestExpr *node)
784 WRITE_NODE_TYPE("CASETESTEXPR");
786 WRITE_OID_FIELD(typeId);
787 WRITE_INT_FIELD(typeMod);
791 _outArrayExpr(StringInfo str, ArrayExpr *node)
793 WRITE_NODE_TYPE("ARRAY");
795 WRITE_OID_FIELD(array_typeid);
796 WRITE_OID_FIELD(element_typeid);
797 WRITE_NODE_FIELD(elements);
798 WRITE_BOOL_FIELD(multidims);
802 _outRowExpr(StringInfo str, RowExpr *node)
804 WRITE_NODE_TYPE("ROW");
806 WRITE_NODE_FIELD(args);
807 WRITE_OID_FIELD(row_typeid);
808 WRITE_ENUM_FIELD(row_format, CoercionForm);
812 _outCoalesceExpr(StringInfo str, CoalesceExpr *node)
814 WRITE_NODE_TYPE("COALESCE");
816 WRITE_OID_FIELD(coalescetype);
817 WRITE_NODE_FIELD(args);
821 _outNullIfExpr(StringInfo str, NullIfExpr *node)
823 WRITE_NODE_TYPE("NULLIFEXPR");
825 WRITE_OID_FIELD(opno);
826 WRITE_OID_FIELD(opfuncid);
827 WRITE_OID_FIELD(opresulttype);
828 WRITE_BOOL_FIELD(opretset);
829 WRITE_NODE_FIELD(args);
833 _outNullTest(StringInfo str, NullTest *node)
835 WRITE_NODE_TYPE("NULLTEST");
837 WRITE_NODE_FIELD(arg);
838 WRITE_ENUM_FIELD(nulltesttype, NullTestType);
842 _outBooleanTest(StringInfo str, BooleanTest *node)
844 WRITE_NODE_TYPE("BOOLEANTEST");
846 WRITE_NODE_FIELD(arg);
847 WRITE_ENUM_FIELD(booltesttype, BoolTestType);
851 _outCoerceToDomain(StringInfo str, CoerceToDomain *node)
853 WRITE_NODE_TYPE("COERCETODOMAIN");
855 WRITE_NODE_FIELD(arg);
856 WRITE_OID_FIELD(resulttype);
857 WRITE_INT_FIELD(resulttypmod);
858 WRITE_ENUM_FIELD(coercionformat, CoercionForm);
862 _outCoerceToDomainValue(StringInfo str, CoerceToDomainValue *node)
864 WRITE_NODE_TYPE("COERCETODOMAINVALUE");
866 WRITE_OID_FIELD(typeId);
867 WRITE_INT_FIELD(typeMod);
871 _outSetToDefault(StringInfo str, SetToDefault *node)
873 WRITE_NODE_TYPE("SETTODEFAULT");
875 WRITE_OID_FIELD(typeId);
876 WRITE_INT_FIELD(typeMod);
880 _outTargetEntry(StringInfo str, TargetEntry *node)
882 WRITE_NODE_TYPE("TARGETENTRY");
884 WRITE_NODE_FIELD(resdom);
885 WRITE_NODE_FIELD(expr);
889 _outRangeTblRef(StringInfo str, RangeTblRef *node)
891 WRITE_NODE_TYPE("RANGETBLREF");
893 WRITE_INT_FIELD(rtindex);
897 _outJoinExpr(StringInfo str, JoinExpr *node)
899 WRITE_NODE_TYPE("JOINEXPR");
901 WRITE_ENUM_FIELD(jointype, JoinType);
902 WRITE_BOOL_FIELD(isNatural);
903 WRITE_NODE_FIELD(larg);
904 WRITE_NODE_FIELD(rarg);
905 WRITE_NODE_FIELD(using);
906 WRITE_NODE_FIELD(quals);
907 WRITE_NODE_FIELD(alias);
908 WRITE_INT_FIELD(rtindex);
912 _outFromExpr(StringInfo str, FromExpr *node)
914 WRITE_NODE_TYPE("FROMEXPR");
916 WRITE_NODE_FIELD(fromlist);
917 WRITE_NODE_FIELD(quals);
920 /*****************************************************************************
922 * Stuff from relation.h.
924 *****************************************************************************/
927 * print the basic stuff of all nodes that inherit from Path
929 * Note we do NOT print the parent, else we'd be in infinite recursion
932 _outPathInfo(StringInfo str, Path *node)
934 WRITE_ENUM_FIELD(pathtype, NodeTag);
935 WRITE_FLOAT_FIELD(startup_cost, "%.2f");
936 WRITE_FLOAT_FIELD(total_cost, "%.2f");
937 WRITE_NODE_FIELD(pathkeys);
941 * print the basic stuff of all nodes that inherit from JoinPath
944 _outJoinPathInfo(StringInfo str, JoinPath *node)
946 _outPathInfo(str, (Path *) node);
948 WRITE_ENUM_FIELD(jointype, JoinType);
949 WRITE_NODE_FIELD(outerjoinpath);
950 WRITE_NODE_FIELD(innerjoinpath);
951 WRITE_NODE_FIELD(joinrestrictinfo);
955 _outPath(StringInfo str, Path *node)
957 WRITE_NODE_TYPE("PATH");
959 _outPathInfo(str, (Path *) node);
963 * IndexPath is a subclass of Path.
966 _outIndexPath(StringInfo str, IndexPath *node)
968 WRITE_NODE_TYPE("INDEXPATH");
970 _outPathInfo(str, (Path *) node);
972 WRITE_NODE_FIELD(indexinfo);
973 WRITE_NODE_FIELD(indexclauses);
974 WRITE_NODE_FIELD(indexquals);
975 WRITE_BOOL_FIELD(isjoininner);
976 WRITE_ENUM_FIELD(indexscandir, ScanDirection);
977 WRITE_FLOAT_FIELD(rows, "%.0f");
981 _outTidPath(StringInfo str, TidPath *node)
983 WRITE_NODE_TYPE("TIDPATH");
985 _outPathInfo(str, (Path *) node);
987 WRITE_NODE_FIELD(tideval);
991 _outAppendPath(StringInfo str, AppendPath *node)
993 WRITE_NODE_TYPE("APPENDPATH");
995 _outPathInfo(str, (Path *) node);
997 WRITE_NODE_FIELD(subpaths);
1001 _outResultPath(StringInfo str, ResultPath *node)
1003 WRITE_NODE_TYPE("RESULTPATH");
1005 _outPathInfo(str, (Path *) node);
1007 WRITE_NODE_FIELD(subpath);
1008 WRITE_NODE_FIELD(constantqual);
1012 _outMaterialPath(StringInfo str, MaterialPath *node)
1014 WRITE_NODE_TYPE("MATERIALPATH");
1016 _outPathInfo(str, (Path *) node);
1018 WRITE_NODE_FIELD(subpath);
1022 _outUniquePath(StringInfo str, UniquePath *node)
1024 WRITE_NODE_TYPE("UNIQUEPATH");
1026 _outPathInfo(str, (Path *) node);
1028 WRITE_NODE_FIELD(subpath);
1029 WRITE_ENUM_FIELD(umethod, UniquePathMethod);
1030 WRITE_FLOAT_FIELD(rows, "%.0f");
1034 _outNestPath(StringInfo str, NestPath *node)
1036 WRITE_NODE_TYPE("NESTPATH");
1038 _outJoinPathInfo(str, (JoinPath *) node);
1042 _outMergePath(StringInfo str, MergePath *node)
1044 WRITE_NODE_TYPE("MERGEPATH");
1046 _outJoinPathInfo(str, (JoinPath *) node);
1048 WRITE_NODE_FIELD(path_mergeclauses);
1049 WRITE_NODE_FIELD(outersortkeys);
1050 WRITE_NODE_FIELD(innersortkeys);
1054 _outHashPath(StringInfo str, HashPath *node)
1056 WRITE_NODE_TYPE("HASHPATH");
1058 _outJoinPathInfo(str, (JoinPath *) node);
1060 WRITE_NODE_FIELD(path_hashclauses);
1064 _outPathKeyItem(StringInfo str, PathKeyItem *node)
1066 WRITE_NODE_TYPE("PATHKEYITEM");
1068 WRITE_NODE_FIELD(key);
1069 WRITE_OID_FIELD(sortop);
1073 _outRestrictInfo(StringInfo str, RestrictInfo *node)
1075 WRITE_NODE_TYPE("RESTRICTINFO");
1077 /* NB: this isn't a complete set of fields */
1078 WRITE_NODE_FIELD(clause);
1079 WRITE_BOOL_FIELD(is_pushed_down);
1080 WRITE_BOOL_FIELD(valid_everywhere);
1081 WRITE_BOOL_FIELD(can_join);
1082 WRITE_BITMAPSET_FIELD(clause_relids);
1083 WRITE_BITMAPSET_FIELD(left_relids);
1084 WRITE_BITMAPSET_FIELD(right_relids);
1085 WRITE_NODE_FIELD(orclause);
1086 WRITE_OID_FIELD(mergejoinoperator);
1087 WRITE_OID_FIELD(left_sortop);
1088 WRITE_OID_FIELD(right_sortop);
1089 WRITE_NODE_FIELD(left_pathkey);
1090 WRITE_NODE_FIELD(right_pathkey);
1091 WRITE_OID_FIELD(hashjoinoperator);
1095 _outJoinInfo(StringInfo str, JoinInfo *node)
1097 WRITE_NODE_TYPE("JOININFO");
1099 WRITE_BITMAPSET_FIELD(unjoined_relids);
1100 WRITE_NODE_FIELD(jinfo_restrictinfo);
1104 _outInClauseInfo(StringInfo str, InClauseInfo *node)
1106 WRITE_NODE_TYPE("INCLAUSEINFO");
1108 WRITE_BITMAPSET_FIELD(lefthand);
1109 WRITE_BITMAPSET_FIELD(righthand);
1110 WRITE_NODE_FIELD(sub_targetlist);
1113 /*****************************************************************************
1115 * Stuff from parsenodes.h.
1117 *****************************************************************************/
1120 _outCreateStmt(StringInfo str, CreateStmt *node)
1122 WRITE_NODE_TYPE("CREATE");
1124 WRITE_NODE_FIELD(relation);
1125 WRITE_NODE_FIELD(tableElts);
1126 WRITE_NODE_FIELD(inhRelations);
1127 WRITE_NODE_FIELD(constraints);
1128 WRITE_ENUM_FIELD(hasoids, ContainsOids);
1129 WRITE_ENUM_FIELD(oncommit, OnCommitAction);
1133 _outIndexStmt(StringInfo str, IndexStmt *node)
1135 WRITE_NODE_TYPE("INDEX");
1137 WRITE_STRING_FIELD(idxname);
1138 WRITE_NODE_FIELD(relation);
1139 WRITE_STRING_FIELD(accessMethod);
1140 WRITE_NODE_FIELD(indexParams);
1141 WRITE_NODE_FIELD(whereClause);
1142 WRITE_NODE_FIELD(rangetable);
1143 WRITE_BOOL_FIELD(unique);
1144 WRITE_BOOL_FIELD(primary);
1145 WRITE_BOOL_FIELD(isconstraint);
1149 _outNotifyStmt(StringInfo str, NotifyStmt *node)
1151 WRITE_NODE_TYPE("NOTIFY");
1153 WRITE_NODE_FIELD(relation);
1157 _outDeclareCursorStmt(StringInfo str, DeclareCursorStmt *node)
1159 WRITE_NODE_TYPE("DECLARECURSOR");
1161 WRITE_STRING_FIELD(portalname);
1162 WRITE_INT_FIELD(options);
1163 WRITE_NODE_FIELD(query);
1167 _outSelectStmt(StringInfo str, SelectStmt *node)
1169 WRITE_NODE_TYPE("SELECT");
1171 /* XXX this is pretty durn incomplete */
1172 WRITE_NODE_FIELD(whereClause);
1176 _outFuncCall(StringInfo str, FuncCall *node)
1178 WRITE_NODE_TYPE("FUNCCALL");
1180 WRITE_NODE_FIELD(funcname);
1181 WRITE_NODE_FIELD(args);
1182 WRITE_BOOL_FIELD(agg_star);
1183 WRITE_BOOL_FIELD(agg_distinct);
1187 _outColumnDef(StringInfo str, ColumnDef *node)
1189 WRITE_NODE_TYPE("COLUMNDEF");
1191 WRITE_STRING_FIELD(colname);
1192 WRITE_NODE_FIELD(typename);
1193 WRITE_INT_FIELD(inhcount);
1194 WRITE_BOOL_FIELD(is_local);
1195 WRITE_BOOL_FIELD(is_not_null);
1196 WRITE_NODE_FIELD(raw_default);
1197 WRITE_STRING_FIELD(cooked_default);
1198 WRITE_NODE_FIELD(constraints);
1199 WRITE_NODE_FIELD(support);
1203 _outTypeName(StringInfo str, TypeName *node)
1205 WRITE_NODE_TYPE("TYPENAME");
1207 WRITE_NODE_FIELD(names);
1208 WRITE_OID_FIELD(typeid);
1209 WRITE_BOOL_FIELD(timezone);
1210 WRITE_BOOL_FIELD(setof);
1211 WRITE_BOOL_FIELD(pct_type);
1212 WRITE_INT_FIELD(typmod);
1213 WRITE_NODE_FIELD(arrayBounds);
1217 _outTypeCast(StringInfo str, TypeCast *node)
1219 WRITE_NODE_TYPE("TYPECAST");
1221 WRITE_NODE_FIELD(arg);
1222 WRITE_NODE_FIELD(typename);
1226 _outIndexElem(StringInfo str, IndexElem *node)
1228 WRITE_NODE_TYPE("INDEXELEM");
1230 WRITE_STRING_FIELD(name);
1231 WRITE_NODE_FIELD(expr);
1232 WRITE_NODE_FIELD(opclass);
1236 _outQuery(StringInfo str, Query *node)
1238 WRITE_NODE_TYPE("QUERY");
1240 WRITE_ENUM_FIELD(commandType, CmdType);
1241 WRITE_ENUM_FIELD(querySource, QuerySource);
1242 WRITE_BOOL_FIELD(canSetTag);
1245 * Hack to work around missing outfuncs routines for a lot of the
1246 * utility-statement node types. (The only one we actually *need* for
1247 * rules support is NotifyStmt.) Someday we ought to support 'em all,
1248 * but for the meantime do this to avoid getting lots of warnings when
1249 * running with debug_print_parse on.
1251 if (node->utilityStmt)
1253 switch (nodeTag(node->utilityStmt))
1258 case T_DeclareCursorStmt:
1259 WRITE_NODE_FIELD(utilityStmt);
1262 appendStringInfo(str, " :utilityStmt ?");
1267 appendStringInfo(str, " :utilityStmt <>");
1269 WRITE_INT_FIELD(resultRelation);
1270 WRITE_NODE_FIELD(into);
1271 WRITE_BOOL_FIELD(hasAggs);
1272 WRITE_BOOL_FIELD(hasSubLinks);
1273 WRITE_NODE_FIELD(rtable);
1274 WRITE_NODE_FIELD(jointree);
1275 WRITE_NODE_FIELD(rowMarks);
1276 WRITE_NODE_FIELD(targetList);
1277 WRITE_NODE_FIELD(groupClause);
1278 WRITE_NODE_FIELD(havingQual);
1279 WRITE_NODE_FIELD(distinctClause);
1280 WRITE_NODE_FIELD(sortClause);
1281 WRITE_NODE_FIELD(limitOffset);
1282 WRITE_NODE_FIELD(limitCount);
1283 WRITE_NODE_FIELD(setOperations);
1284 WRITE_NODE_FIELD(resultRelations);
1286 /* planner-internal fields are not written out */
1290 _outSortClause(StringInfo str, SortClause *node)
1292 WRITE_NODE_TYPE("SORTCLAUSE");
1294 WRITE_UINT_FIELD(tleSortGroupRef);
1295 WRITE_OID_FIELD(sortop);
1299 _outGroupClause(StringInfo str, GroupClause *node)
1301 WRITE_NODE_TYPE("GROUPCLAUSE");
1303 WRITE_UINT_FIELD(tleSortGroupRef);
1304 WRITE_OID_FIELD(sortop);
1308 _outSetOperationStmt(StringInfo str, SetOperationStmt *node)
1310 WRITE_NODE_TYPE("SETOPERATIONSTMT");
1312 WRITE_ENUM_FIELD(op, SetOperation);
1313 WRITE_BOOL_FIELD(all);
1314 WRITE_NODE_FIELD(larg);
1315 WRITE_NODE_FIELD(rarg);
1316 WRITE_NODE_FIELD(colTypes);
1320 _outRangeTblEntry(StringInfo str, RangeTblEntry *node)
1322 WRITE_NODE_TYPE("RTE");
1324 /* put alias + eref first to make dump more legible */
1325 WRITE_NODE_FIELD(alias);
1326 WRITE_NODE_FIELD(eref);
1327 WRITE_ENUM_FIELD(rtekind, RTEKind);
1329 switch (node->rtekind)
1333 WRITE_OID_FIELD(relid);
1336 WRITE_NODE_FIELD(subquery);
1339 WRITE_NODE_FIELD(funcexpr);
1340 WRITE_NODE_FIELD(coldeflist);
1343 WRITE_ENUM_FIELD(jointype, JoinType);
1344 WRITE_NODE_FIELD(joinaliasvars);
1347 elog(ERROR, "unrecognized RTE kind: %d", (int) node->rtekind);
1351 WRITE_BOOL_FIELD(inh);
1352 WRITE_BOOL_FIELD(inFromCl);
1353 WRITE_UINT_FIELD(requiredPerms);
1354 WRITE_UINT_FIELD(checkAsUser);
1358 _outAExpr(StringInfo str, A_Expr *node)
1360 WRITE_NODE_TYPE("AEXPR");
1365 appendStringInfo(str, " ");
1366 WRITE_NODE_FIELD(name);
1369 appendStringInfo(str, " AND");
1372 appendStringInfo(str, " OR");
1375 appendStringInfo(str, " NOT");
1378 appendStringInfo(str, " ");
1379 WRITE_NODE_FIELD(name);
1380 appendStringInfo(str, " ANY ");
1383 appendStringInfo(str, " ");
1384 WRITE_NODE_FIELD(name);
1385 appendStringInfo(str, " ALL ");
1387 case AEXPR_DISTINCT:
1388 appendStringInfo(str, " DISTINCT ");
1389 WRITE_NODE_FIELD(name);
1392 appendStringInfo(str, " NULLIF ");
1393 WRITE_NODE_FIELD(name);
1396 appendStringInfo(str, " OF ");
1397 WRITE_NODE_FIELD(name);
1400 appendStringInfo(str, " ??");
1404 WRITE_NODE_FIELD(lexpr);
1405 WRITE_NODE_FIELD(rexpr);
1409 _outValue(StringInfo str, Value *value)
1411 switch (value->type)
1414 appendStringInfo(str, "%ld", value->val.ival);
1418 * We assume the value is a valid numeric literal and so does
1421 appendStringInfoString(str, value->val.str);
1424 appendStringInfoChar(str, '"');
1425 _outToken(str, value->val.str);
1426 appendStringInfoChar(str, '"');
1429 /* internal representation already has leading 'b' */
1430 appendStringInfoString(str, value->val.str);
1433 elog(ERROR, "unrecognized node type: %d", (int) value->type);
1439 _outColumnRef(StringInfo str, ColumnRef *node)
1441 WRITE_NODE_TYPE("COLUMNREF");
1443 WRITE_NODE_FIELD(fields);
1444 WRITE_NODE_FIELD(indirection);
1448 _outParamRef(StringInfo str, ParamRef *node)
1450 WRITE_NODE_TYPE("PARAMREF");
1452 WRITE_INT_FIELD(number);
1453 WRITE_NODE_FIELD(fields);
1454 WRITE_NODE_FIELD(indirection);
1458 _outAConst(StringInfo str, A_Const *node)
1460 WRITE_NODE_TYPE("CONST ");
1462 _outValue(str, &(node->val));
1463 WRITE_NODE_FIELD(typename);
1467 _outExprFieldSelect(StringInfo str, ExprFieldSelect *node)
1469 WRITE_NODE_TYPE("EXPRFIELDSELECT");
1471 WRITE_NODE_FIELD(arg);
1472 WRITE_NODE_FIELD(fields);
1473 WRITE_NODE_FIELD(indirection);
1477 _outConstraint(StringInfo str, Constraint *node)
1479 WRITE_NODE_TYPE("CONSTRAINT");
1481 WRITE_STRING_FIELD(name);
1483 appendStringInfo(str, " :contype ");
1484 switch (node->contype)
1486 case CONSTR_PRIMARY:
1487 appendStringInfo(str, "PRIMARY_KEY");
1488 WRITE_NODE_FIELD(keys);
1492 appendStringInfo(str, "CHECK");
1493 WRITE_NODE_FIELD(raw_expr);
1494 WRITE_STRING_FIELD(cooked_expr);
1497 case CONSTR_DEFAULT:
1498 appendStringInfo(str, "DEFAULT");
1499 WRITE_NODE_FIELD(raw_expr);
1500 WRITE_STRING_FIELD(cooked_expr);
1503 case CONSTR_NOTNULL:
1504 appendStringInfo(str, "NOT_NULL");
1508 appendStringInfo(str, "UNIQUE");
1509 WRITE_NODE_FIELD(keys);
1513 appendStringInfo(str, "<unrecognized_constraint>");
1519 _outFkConstraint(StringInfo str, FkConstraint *node)
1521 WRITE_NODE_TYPE("FKCONSTRAINT");
1523 WRITE_STRING_FIELD(constr_name);
1524 WRITE_NODE_FIELD(pktable);
1525 WRITE_NODE_FIELD(fk_attrs);
1526 WRITE_NODE_FIELD(pk_attrs);
1527 WRITE_CHAR_FIELD(fk_matchtype);
1528 WRITE_CHAR_FIELD(fk_upd_action);
1529 WRITE_CHAR_FIELD(fk_del_action);
1530 WRITE_BOOL_FIELD(deferrable);
1531 WRITE_BOOL_FIELD(initdeferred);
1532 WRITE_BOOL_FIELD(skip_validation);
1538 * converts a Node into ascii string and append it to 'str'
1541 _outNode(StringInfo str, void *obj)
1544 appendStringInfo(str, "<>");
1545 else if (IsA(obj, List) || IsA(obj, IntList) || IsA(obj, OidList))
1547 else if (IsA(obj, Integer) ||
1550 IsA(obj, BitString))
1552 /* nodeRead does not want to see { } around these! */
1553 _outValue(str, obj);
1557 appendStringInfoChar(str, '{');
1558 switch (nodeTag(obj))
1564 _outResult(str, obj);
1567 _outAppend(str, obj);
1573 _outSeqScan(str, obj);
1576 _outIndexScan(str, obj);
1579 _outTidScan(str, obj);
1581 case T_SubqueryScan:
1582 _outSubqueryScan(str, obj);
1584 case T_FunctionScan:
1585 _outFunctionScan(str, obj);
1591 _outNestLoop(str, obj);
1594 _outMergeJoin(str, obj);
1597 _outHashJoin(str, obj);
1603 _outGroup(str, obj);
1606 _outMaterial(str, obj);
1612 _outUnique(str, obj);
1615 _outSetOp(str, obj);
1618 _outLimit(str, obj);
1624 _outResdom(str, obj);
1627 _outAlias(str, obj);
1630 _outRangeVar(str, obj);
1636 _outConst(str, obj);
1639 _outParam(str, obj);
1642 _outAggref(str, obj);
1645 _outArrayRef(str, obj);
1648 _outFuncExpr(str, obj);
1651 _outOpExpr(str, obj);
1653 case T_DistinctExpr:
1654 _outDistinctExpr(str, obj);
1656 case T_ScalarArrayOpExpr:
1657 _outScalarArrayOpExpr(str, obj);
1660 _outBoolExpr(str, obj);
1663 _outSubLink(str, obj);
1666 _outSubPlan(str, obj);
1669 _outFieldSelect(str, obj);
1672 _outRelabelType(str, obj);
1675 _outCaseExpr(str, obj);
1678 _outCaseWhen(str, obj);
1680 case T_CaseTestExpr:
1681 _outCaseTestExpr(str, obj);
1684 _outArrayExpr(str, obj);
1687 _outRowExpr(str, obj);
1689 case T_CoalesceExpr:
1690 _outCoalesceExpr(str, obj);
1693 _outNullIfExpr(str, obj);
1696 _outNullTest(str, obj);
1699 _outBooleanTest(str, obj);
1701 case T_CoerceToDomain:
1702 _outCoerceToDomain(str, obj);
1704 case T_CoerceToDomainValue:
1705 _outCoerceToDomainValue(str, obj);
1707 case T_SetToDefault:
1708 _outSetToDefault(str, obj);
1711 _outTargetEntry(str, obj);
1714 _outRangeTblRef(str, obj);
1717 _outJoinExpr(str, obj);
1720 _outFromExpr(str, obj);
1727 _outIndexPath(str, obj);
1730 _outTidPath(str, obj);
1733 _outAppendPath(str, obj);
1736 _outResultPath(str, obj);
1738 case T_MaterialPath:
1739 _outMaterialPath(str, obj);
1742 _outUniquePath(str, obj);
1745 _outNestPath(str, obj);
1748 _outMergePath(str, obj);
1751 _outHashPath(str, obj);
1754 _outPathKeyItem(str, obj);
1756 case T_RestrictInfo:
1757 _outRestrictInfo(str, obj);
1760 _outJoinInfo(str, obj);
1762 case T_InClauseInfo:
1763 _outInClauseInfo(str, obj);
1767 _outCreateStmt(str, obj);
1770 _outIndexStmt(str, obj);
1773 _outNotifyStmt(str, obj);
1775 case T_DeclareCursorStmt:
1776 _outDeclareCursorStmt(str, obj);
1779 _outSelectStmt(str, obj);
1782 _outColumnDef(str, obj);
1785 _outTypeName(str, obj);
1788 _outTypeCast(str, obj);
1791 _outIndexElem(str, obj);
1794 _outQuery(str, obj);
1797 _outSortClause(str, obj);
1800 _outGroupClause(str, obj);
1802 case T_SetOperationStmt:
1803 _outSetOperationStmt(str, obj);
1805 case T_RangeTblEntry:
1806 _outRangeTblEntry(str, obj);
1809 _outAExpr(str, obj);
1812 _outColumnRef(str, obj);
1815 _outParamRef(str, obj);
1818 _outAConst(str, obj);
1820 case T_ExprFieldSelect:
1821 _outExprFieldSelect(str, obj);
1824 _outConstraint(str, obj);
1826 case T_FkConstraint:
1827 _outFkConstraint(str, obj);
1830 _outFuncCall(str, obj);
1836 * This should be an ERROR, but it's too useful to be able
1837 * to dump structures that _outNode only understands part
1840 elog(WARNING, "could not dump unrecognized node type: %d",
1841 (int) nodeTag(obj));
1844 appendStringInfoChar(str, '}');
1850 * returns the ascii representation of the Node as a palloc'd string
1853 nodeToString(void *obj)
1857 /* see stringinfo.h for an explanation of this maneuver */
1858 initStringInfo(&str);
1859 _outNode(&str, obj);