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.214 2003/07/28 00:09:15 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 _outSetToDefault(StringInfo str, SetToDefault *node)
855 WRITE_NODE_TYPE("SETTODEFAULT");
857 WRITE_OID_FIELD(typeId);
858 WRITE_INT_FIELD(typeMod);
862 _outTargetEntry(StringInfo str, TargetEntry *node)
864 WRITE_NODE_TYPE("TARGETENTRY");
866 WRITE_NODE_FIELD(resdom);
867 WRITE_NODE_FIELD(expr);
871 _outRangeTblRef(StringInfo str, RangeTblRef *node)
873 WRITE_NODE_TYPE("RANGETBLREF");
875 WRITE_INT_FIELD(rtindex);
879 _outJoinExpr(StringInfo str, JoinExpr *node)
881 WRITE_NODE_TYPE("JOINEXPR");
883 WRITE_ENUM_FIELD(jointype, JoinType);
884 WRITE_BOOL_FIELD(isNatural);
885 WRITE_NODE_FIELD(larg);
886 WRITE_NODE_FIELD(rarg);
887 WRITE_NODE_FIELD(using);
888 WRITE_NODE_FIELD(quals);
889 WRITE_NODE_FIELD(alias);
890 WRITE_INT_FIELD(rtindex);
894 _outFromExpr(StringInfo str, FromExpr *node)
896 WRITE_NODE_TYPE("FROMEXPR");
898 WRITE_NODE_FIELD(fromlist);
899 WRITE_NODE_FIELD(quals);
902 /*****************************************************************************
904 * Stuff from relation.h.
906 *****************************************************************************/
909 * print the basic stuff of all nodes that inherit from Path
911 * Note we do NOT print the parent, else we'd be in infinite recursion
914 _outPathInfo(StringInfo str, Path *node)
916 WRITE_ENUM_FIELD(pathtype, NodeTag);
917 WRITE_FLOAT_FIELD(startup_cost, "%.2f");
918 WRITE_FLOAT_FIELD(total_cost, "%.2f");
919 WRITE_NODE_FIELD(pathkeys);
923 * print the basic stuff of all nodes that inherit from JoinPath
926 _outJoinPathInfo(StringInfo str, JoinPath *node)
928 _outPathInfo(str, (Path *) node);
930 WRITE_ENUM_FIELD(jointype, JoinType);
931 WRITE_NODE_FIELD(outerjoinpath);
932 WRITE_NODE_FIELD(innerjoinpath);
933 WRITE_NODE_FIELD(joinrestrictinfo);
937 _outPath(StringInfo str, Path *node)
939 WRITE_NODE_TYPE("PATH");
941 _outPathInfo(str, (Path *) node);
945 * IndexPath is a subclass of Path.
948 _outIndexPath(StringInfo str, IndexPath *node)
950 WRITE_NODE_TYPE("INDEXPATH");
952 _outPathInfo(str, (Path *) node);
954 WRITE_NODE_FIELD(indexinfo);
955 WRITE_NODE_FIELD(indexqual);
956 WRITE_NODE_FIELD(indexjoinclauses);
957 WRITE_ENUM_FIELD(indexscandir, ScanDirection);
958 WRITE_FLOAT_FIELD(rows, "%.2f");
962 _outTidPath(StringInfo str, TidPath *node)
964 WRITE_NODE_TYPE("TIDPATH");
966 _outPathInfo(str, (Path *) node);
968 WRITE_NODE_FIELD(tideval);
972 _outAppendPath(StringInfo str, AppendPath *node)
974 WRITE_NODE_TYPE("APPENDPATH");
976 _outPathInfo(str, (Path *) node);
978 WRITE_NODE_FIELD(subpaths);
982 _outResultPath(StringInfo str, ResultPath *node)
984 WRITE_NODE_TYPE("RESULTPATH");
986 _outPathInfo(str, (Path *) node);
988 WRITE_NODE_FIELD(subpath);
989 WRITE_NODE_FIELD(constantqual);
993 _outMaterialPath(StringInfo str, MaterialPath *node)
995 WRITE_NODE_TYPE("MATERIALPATH");
997 _outPathInfo(str, (Path *) node);
999 WRITE_NODE_FIELD(subpath);
1003 _outUniquePath(StringInfo str, UniquePath *node)
1005 WRITE_NODE_TYPE("UNIQUEPATH");
1007 _outPathInfo(str, (Path *) node);
1009 WRITE_NODE_FIELD(subpath);
1010 WRITE_BOOL_FIELD(use_hash);
1011 WRITE_FLOAT_FIELD(rows, "%.0f");
1015 _outNestPath(StringInfo str, NestPath *node)
1017 WRITE_NODE_TYPE("NESTPATH");
1019 _outJoinPathInfo(str, (JoinPath *) node);
1023 _outMergePath(StringInfo str, MergePath *node)
1025 WRITE_NODE_TYPE("MERGEPATH");
1027 _outJoinPathInfo(str, (JoinPath *) node);
1029 WRITE_NODE_FIELD(path_mergeclauses);
1030 WRITE_NODE_FIELD(outersortkeys);
1031 WRITE_NODE_FIELD(innersortkeys);
1035 _outHashPath(StringInfo str, HashPath *node)
1037 WRITE_NODE_TYPE("HASHPATH");
1039 _outJoinPathInfo(str, (JoinPath *) node);
1041 WRITE_NODE_FIELD(path_hashclauses);
1045 _outPathKeyItem(StringInfo str, PathKeyItem *node)
1047 WRITE_NODE_TYPE("PATHKEYITEM");
1049 WRITE_NODE_FIELD(key);
1050 WRITE_OID_FIELD(sortop);
1054 _outRestrictInfo(StringInfo str, RestrictInfo *node)
1056 WRITE_NODE_TYPE("RESTRICTINFO");
1058 /* NB: this isn't a complete set of fields */
1059 WRITE_NODE_FIELD(clause);
1060 WRITE_BOOL_FIELD(ispusheddown);
1061 WRITE_NODE_FIELD(subclauseindices);
1062 WRITE_BITMAPSET_FIELD(left_relids);
1063 WRITE_BITMAPSET_FIELD(right_relids);
1064 WRITE_OID_FIELD(mergejoinoperator);
1065 WRITE_OID_FIELD(left_sortop);
1066 WRITE_OID_FIELD(right_sortop);
1067 WRITE_NODE_FIELD(left_pathkey);
1068 WRITE_NODE_FIELD(right_pathkey);
1069 WRITE_OID_FIELD(hashjoinoperator);
1073 _outJoinInfo(StringInfo str, JoinInfo *node)
1075 WRITE_NODE_TYPE("JOININFO");
1077 WRITE_BITMAPSET_FIELD(unjoined_relids);
1078 WRITE_NODE_FIELD(jinfo_restrictinfo);
1082 _outInClauseInfo(StringInfo str, InClauseInfo *node)
1084 WRITE_NODE_TYPE("INCLAUSEINFO");
1086 WRITE_BITMAPSET_FIELD(lefthand);
1087 WRITE_BITMAPSET_FIELD(righthand);
1088 WRITE_NODE_FIELD(sub_targetlist);
1091 /*****************************************************************************
1093 * Stuff from parsenodes.h.
1095 *****************************************************************************/
1098 _outCreateStmt(StringInfo str, CreateStmt *node)
1100 WRITE_NODE_TYPE("CREATE");
1102 WRITE_NODE_FIELD(relation);
1103 WRITE_NODE_FIELD(tableElts);
1104 WRITE_NODE_FIELD(inhRelations);
1105 WRITE_NODE_FIELD(constraints);
1106 WRITE_BOOL_FIELD(hasoids);
1107 WRITE_ENUM_FIELD(oncommit, OnCommitAction);
1111 _outIndexStmt(StringInfo str, IndexStmt *node)
1113 WRITE_NODE_TYPE("INDEX");
1115 WRITE_STRING_FIELD(idxname);
1116 WRITE_NODE_FIELD(relation);
1117 WRITE_STRING_FIELD(accessMethod);
1118 WRITE_NODE_FIELD(indexParams);
1119 WRITE_NODE_FIELD(whereClause);
1120 WRITE_NODE_FIELD(rangetable);
1121 WRITE_BOOL_FIELD(unique);
1122 WRITE_BOOL_FIELD(primary);
1123 WRITE_BOOL_FIELD(isconstraint);
1127 _outNotifyStmt(StringInfo str, NotifyStmt *node)
1129 WRITE_NODE_TYPE("NOTIFY");
1131 WRITE_NODE_FIELD(relation);
1135 _outDeclareCursorStmt(StringInfo str, DeclareCursorStmt *node)
1137 WRITE_NODE_TYPE("DECLARECURSOR");
1139 WRITE_STRING_FIELD(portalname);
1140 WRITE_INT_FIELD(options);
1141 WRITE_NODE_FIELD(query);
1145 _outSelectStmt(StringInfo str, SelectStmt *node)
1147 WRITE_NODE_TYPE("SELECT");
1149 /* XXX this is pretty durn incomplete */
1150 WRITE_NODE_FIELD(whereClause);
1154 _outFuncCall(StringInfo str, FuncCall *node)
1156 WRITE_NODE_TYPE("FUNCCALL");
1158 WRITE_NODE_FIELD(funcname);
1159 WRITE_NODE_FIELD(args);
1160 WRITE_BOOL_FIELD(agg_star);
1161 WRITE_BOOL_FIELD(agg_distinct);
1165 _outColumnDef(StringInfo str, ColumnDef *node)
1167 WRITE_NODE_TYPE("COLUMNDEF");
1169 WRITE_STRING_FIELD(colname);
1170 WRITE_NODE_FIELD(typename);
1171 WRITE_INT_FIELD(inhcount);
1172 WRITE_BOOL_FIELD(is_local);
1173 WRITE_BOOL_FIELD(is_not_null);
1174 WRITE_NODE_FIELD(raw_default);
1175 WRITE_STRING_FIELD(cooked_default);
1176 WRITE_NODE_FIELD(constraints);
1177 WRITE_NODE_FIELD(support);
1181 _outTypeName(StringInfo str, TypeName *node)
1183 WRITE_NODE_TYPE("TYPENAME");
1185 WRITE_NODE_FIELD(names);
1186 WRITE_OID_FIELD(typeid);
1187 WRITE_BOOL_FIELD(timezone);
1188 WRITE_BOOL_FIELD(setof);
1189 WRITE_BOOL_FIELD(pct_type);
1190 WRITE_INT_FIELD(typmod);
1191 WRITE_NODE_FIELD(arrayBounds);
1195 _outTypeCast(StringInfo str, TypeCast *node)
1197 WRITE_NODE_TYPE("TYPECAST");
1199 WRITE_NODE_FIELD(arg);
1200 WRITE_NODE_FIELD(typename);
1204 _outIndexElem(StringInfo str, IndexElem *node)
1206 WRITE_NODE_TYPE("INDEXELEM");
1208 WRITE_STRING_FIELD(name);
1209 WRITE_NODE_FIELD(expr);
1210 WRITE_NODE_FIELD(opclass);
1214 _outQuery(StringInfo str, Query *node)
1216 WRITE_NODE_TYPE("QUERY");
1218 WRITE_ENUM_FIELD(commandType, CmdType);
1219 WRITE_ENUM_FIELD(querySource, QuerySource);
1220 WRITE_BOOL_FIELD(canSetTag);
1223 * Hack to work around missing outfuncs routines for a lot of the
1224 * utility-statement node types. (The only one we actually *need* for
1225 * rules support is NotifyStmt.) Someday we ought to support 'em all,
1226 * but for the meantime do this to avoid getting lots of warnings when
1227 * running with debug_print_parse on.
1229 if (node->utilityStmt)
1231 switch (nodeTag(node->utilityStmt))
1236 case T_DeclareCursorStmt:
1237 WRITE_NODE_FIELD(utilityStmt);
1240 appendStringInfo(str, " :utilityStmt ?");
1245 appendStringInfo(str, " :utilityStmt <>");
1247 WRITE_INT_FIELD(resultRelation);
1248 WRITE_NODE_FIELD(into);
1249 WRITE_BOOL_FIELD(hasAggs);
1250 WRITE_BOOL_FIELD(hasSubLinks);
1251 WRITE_NODE_FIELD(rtable);
1252 WRITE_NODE_FIELD(jointree);
1253 WRITE_INTLIST_FIELD(rowMarks);
1254 WRITE_NODE_FIELD(targetList);
1255 WRITE_NODE_FIELD(groupClause);
1256 WRITE_NODE_FIELD(havingQual);
1257 WRITE_NODE_FIELD(distinctClause);
1258 WRITE_NODE_FIELD(sortClause);
1259 WRITE_NODE_FIELD(limitOffset);
1260 WRITE_NODE_FIELD(limitCount);
1261 WRITE_NODE_FIELD(setOperations);
1262 WRITE_INTLIST_FIELD(resultRelations);
1264 /* planner-internal fields are not written out */
1268 _outSortClause(StringInfo str, SortClause *node)
1270 WRITE_NODE_TYPE("SORTCLAUSE");
1272 WRITE_UINT_FIELD(tleSortGroupRef);
1273 WRITE_OID_FIELD(sortop);
1277 _outGroupClause(StringInfo str, GroupClause *node)
1279 WRITE_NODE_TYPE("GROUPCLAUSE");
1281 WRITE_UINT_FIELD(tleSortGroupRef);
1282 WRITE_OID_FIELD(sortop);
1286 _outSetOperationStmt(StringInfo str, SetOperationStmt *node)
1288 WRITE_NODE_TYPE("SETOPERATIONSTMT");
1290 WRITE_ENUM_FIELD(op, SetOperation);
1291 WRITE_BOOL_FIELD(all);
1292 WRITE_NODE_FIELD(larg);
1293 WRITE_NODE_FIELD(rarg);
1294 WRITE_OIDLIST_FIELD(colTypes);
1298 _outRangeTblEntry(StringInfo str, RangeTblEntry *node)
1300 WRITE_NODE_TYPE("RTE");
1302 /* put alias + eref first to make dump more legible */
1303 WRITE_NODE_FIELD(alias);
1304 WRITE_NODE_FIELD(eref);
1305 WRITE_ENUM_FIELD(rtekind, RTEKind);
1307 switch (node->rtekind)
1311 WRITE_OID_FIELD(relid);
1314 WRITE_NODE_FIELD(subquery);
1317 WRITE_NODE_FIELD(funcexpr);
1318 WRITE_NODE_FIELD(coldeflist);
1321 WRITE_ENUM_FIELD(jointype, JoinType);
1322 WRITE_NODE_FIELD(joinaliasvars);
1325 elog(ERROR, "unrecognized RTE kind: %d", (int) node->rtekind);
1329 WRITE_BOOL_FIELD(inh);
1330 WRITE_BOOL_FIELD(inFromCl);
1331 WRITE_BOOL_FIELD(checkForRead);
1332 WRITE_BOOL_FIELD(checkForWrite);
1333 WRITE_OID_FIELD(checkAsUser);
1337 _outAExpr(StringInfo str, A_Expr *node)
1339 WRITE_NODE_TYPE("AEXPR");
1344 appendStringInfo(str, " ");
1345 WRITE_NODE_FIELD(name);
1348 appendStringInfo(str, " AND");
1351 appendStringInfo(str, " OR");
1354 appendStringInfo(str, " NOT");
1357 appendStringInfo(str, " ");
1358 WRITE_NODE_FIELD(name);
1359 appendStringInfo(str, " ANY ");
1362 appendStringInfo(str, " ");
1363 WRITE_NODE_FIELD(name);
1364 appendStringInfo(str, " ALL ");
1366 case AEXPR_DISTINCT:
1367 appendStringInfo(str, " DISTINCT ");
1368 WRITE_NODE_FIELD(name);
1371 appendStringInfo(str, " NULLIF ");
1372 WRITE_NODE_FIELD(name);
1375 appendStringInfo(str, " OF ");
1376 WRITE_NODE_FIELD(name);
1379 appendStringInfo(str, " ??");
1383 WRITE_NODE_FIELD(lexpr);
1384 WRITE_NODE_FIELD(rexpr);
1388 _outValue(StringInfo str, Value *value)
1390 switch (value->type)
1393 appendStringInfo(str, "%ld", value->val.ival);
1398 * We assume the value is a valid numeric literal and so does
1401 appendStringInfo(str, "%s", value->val.str);
1404 appendStringInfoChar(str, '"');
1405 _outToken(str, value->val.str);
1406 appendStringInfoChar(str, '"');
1409 /* internal representation already has leading 'b' */
1410 appendStringInfo(str, "%s", value->val.str);
1413 elog(ERROR, "unrecognized node type: %d", (int) value->type);
1419 _outColumnRef(StringInfo str, ColumnRef *node)
1421 WRITE_NODE_TYPE("COLUMNREF");
1423 WRITE_NODE_FIELD(fields);
1424 WRITE_NODE_FIELD(indirection);
1428 _outParamRef(StringInfo str, ParamRef *node)
1430 WRITE_NODE_TYPE("PARAMREF");
1432 WRITE_INT_FIELD(number);
1433 WRITE_NODE_FIELD(fields);
1434 WRITE_NODE_FIELD(indirection);
1438 _outAConst(StringInfo str, A_Const *node)
1440 WRITE_NODE_TYPE("CONST ");
1442 _outValue(str, &(node->val));
1443 WRITE_NODE_FIELD(typename);
1447 _outExprFieldSelect(StringInfo str, ExprFieldSelect *node)
1449 WRITE_NODE_TYPE("EXPRFIELDSELECT");
1451 WRITE_NODE_FIELD(arg);
1452 WRITE_NODE_FIELD(fields);
1453 WRITE_NODE_FIELD(indirection);
1457 _outConstraint(StringInfo str, Constraint *node)
1459 WRITE_NODE_TYPE("CONSTRAINT");
1461 WRITE_STRING_FIELD(name);
1463 appendStringInfo(str, " :contype ");
1464 switch (node->contype)
1466 case CONSTR_PRIMARY:
1467 appendStringInfo(str, "PRIMARY_KEY");
1468 WRITE_NODE_FIELD(keys);
1472 appendStringInfo(str, "CHECK");
1473 WRITE_NODE_FIELD(raw_expr);
1474 WRITE_STRING_FIELD(cooked_expr);
1477 case CONSTR_DEFAULT:
1478 appendStringInfo(str, "DEFAULT");
1479 WRITE_NODE_FIELD(raw_expr);
1480 WRITE_STRING_FIELD(cooked_expr);
1483 case CONSTR_NOTNULL:
1484 appendStringInfo(str, "NOT_NULL");
1488 appendStringInfo(str, "UNIQUE");
1489 WRITE_NODE_FIELD(keys);
1493 appendStringInfo(str, "<unrecognized_constraint>");
1499 _outFkConstraint(StringInfo str, FkConstraint *node)
1501 WRITE_NODE_TYPE("FKCONSTRAINT");
1503 WRITE_STRING_FIELD(constr_name);
1504 WRITE_NODE_FIELD(pktable);
1505 WRITE_NODE_FIELD(fk_attrs);
1506 WRITE_NODE_FIELD(pk_attrs);
1507 WRITE_CHAR_FIELD(fk_matchtype);
1508 WRITE_CHAR_FIELD(fk_upd_action);
1509 WRITE_CHAR_FIELD(fk_del_action);
1510 WRITE_BOOL_FIELD(deferrable);
1511 WRITE_BOOL_FIELD(initdeferred);
1512 WRITE_BOOL_FIELD(skip_validation);
1518 * converts a Node into ascii string and append it to 'str'
1521 _outNode(StringInfo str, void *obj)
1525 appendStringInfo(str, "<>");
1533 appendStringInfoChar(str, '(');
1534 foreach(l, (List *) obj)
1536 _outNode(str, lfirst(l));
1538 appendStringInfoChar(str, ' ');
1540 appendStringInfoChar(str, ')');
1542 else if (IsA(obj, Integer) ||
1545 IsA(obj, BitString))
1547 /* nodeRead does not want to see { } around these! */
1548 _outValue(str, obj);
1552 appendStringInfoChar(str, '{');
1553 switch (nodeTag(obj))
1559 _outResult(str, obj);
1562 _outAppend(str, obj);
1568 _outSeqScan(str, obj);
1571 _outIndexScan(str, obj);
1574 _outTidScan(str, obj);
1576 case T_SubqueryScan:
1577 _outSubqueryScan(str, obj);
1579 case T_FunctionScan:
1580 _outFunctionScan(str, obj);
1586 _outNestLoop(str, obj);
1589 _outMergeJoin(str, obj);
1592 _outHashJoin(str, obj);
1598 _outGroup(str, obj);
1601 _outMaterial(str, obj);
1607 _outUnique(str, obj);
1610 _outSetOp(str, obj);
1613 _outLimit(str, obj);
1619 _outResdom(str, obj);
1622 _outAlias(str, obj);
1625 _outRangeVar(str, obj);
1631 _outConst(str, obj);
1634 _outParam(str, obj);
1637 _outAggref(str, obj);
1640 _outArrayRef(str, obj);
1643 _outFuncExpr(str, obj);
1646 _outOpExpr(str, obj);
1648 case T_DistinctExpr:
1649 _outDistinctExpr(str, obj);
1651 case T_ScalarArrayOpExpr:
1652 _outScalarArrayOpExpr(str, obj);
1655 _outBoolExpr(str, obj);
1658 _outSubLink(str, obj);
1661 _outSubPlan(str, obj);
1664 _outFieldSelect(str, obj);
1667 _outRelabelType(str, obj);
1670 _outCaseExpr(str, obj);
1673 _outCaseWhen(str, obj);
1676 _outArrayExpr(str, obj);
1678 case T_CoalesceExpr:
1679 _outCoalesceExpr(str, obj);
1682 _outNullIfExpr(str, obj);
1685 _outNullTest(str, obj);
1688 _outBooleanTest(str, obj);
1690 case T_CoerceToDomain:
1691 _outCoerceToDomain(str, obj);
1693 case T_CoerceToDomainValue:
1694 _outCoerceToDomainValue(str, obj);
1696 case T_SetToDefault:
1697 _outSetToDefault(str, obj);
1700 _outTargetEntry(str, obj);
1703 _outRangeTblRef(str, obj);
1706 _outJoinExpr(str, obj);
1709 _outFromExpr(str, obj);
1716 _outIndexPath(str, obj);
1719 _outTidPath(str, obj);
1722 _outAppendPath(str, obj);
1725 _outResultPath(str, obj);
1727 case T_MaterialPath:
1728 _outMaterialPath(str, obj);
1731 _outUniquePath(str, obj);
1734 _outNestPath(str, obj);
1737 _outMergePath(str, obj);
1740 _outHashPath(str, obj);
1743 _outPathKeyItem(str, obj);
1745 case T_RestrictInfo:
1746 _outRestrictInfo(str, obj);
1749 _outJoinInfo(str, obj);
1751 case T_InClauseInfo:
1752 _outInClauseInfo(str, obj);
1756 _outCreateStmt(str, obj);
1759 _outIndexStmt(str, obj);
1762 _outNotifyStmt(str, obj);
1764 case T_DeclareCursorStmt:
1765 _outDeclareCursorStmt(str, obj);
1768 _outSelectStmt(str, obj);
1771 _outColumnDef(str, obj);
1774 _outTypeName(str, obj);
1777 _outTypeCast(str, obj);
1780 _outIndexElem(str, obj);
1783 _outQuery(str, obj);
1786 _outSortClause(str, obj);
1789 _outGroupClause(str, obj);
1791 case T_SetOperationStmt:
1792 _outSetOperationStmt(str, obj);
1794 case T_RangeTblEntry:
1795 _outRangeTblEntry(str, obj);
1798 _outAExpr(str, obj);
1801 _outColumnRef(str, obj);
1804 _outParamRef(str, obj);
1807 _outAConst(str, obj);
1809 case T_ExprFieldSelect:
1810 _outExprFieldSelect(str, obj);
1813 _outConstraint(str, obj);
1815 case T_FkConstraint:
1816 _outFkConstraint(str, obj);
1819 _outFuncCall(str, obj);
1824 * This should be an ERROR, but it's too useful to be able
1825 * to dump structures that _outNode only understands part of.
1827 elog(WARNING, "could not dump unrecognized node type: %d",
1828 (int) nodeTag(obj));
1831 appendStringInfoChar(str, '}');
1837 * returns the ascii representation of the Node as a palloc'd string
1840 nodeToString(void *obj)
1844 /* see stringinfo.h for an explanation of this maneuver */
1845 initStringInfo(&str);
1846 _outNode(&str, obj);