1 /*-------------------------------------------------------------------------
4 * Output functions for Postgres tree nodes.
6 * Portions Copyright (c) 1996-2007, 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.298 2007/02/19 02:23:12 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/plannodes.h"
28 #include "nodes/relation.h"
29 #include "utils/datum.h"
33 * Macros to simplify output of different kinds of fields. Use these
34 * wherever possible to reduce the chance for silly typos. Note that these
35 * hard-wire conventions about the names of the local variables in an Out
39 /* Write the label for the node type */
40 #define WRITE_NODE_TYPE(nodelabel) \
41 appendStringInfoString(str, nodelabel)
43 /* Write an integer field (anything written as ":fldname %d") */
44 #define WRITE_INT_FIELD(fldname) \
45 appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname)
47 /* Write an unsigned integer field (anything written as ":fldname %u") */
48 #define WRITE_UINT_FIELD(fldname) \
49 appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
51 /* Write an OID field (don't hard-wire assumption that OID is same as uint) */
52 #define WRITE_OID_FIELD(fldname) \
53 appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
55 /* Write a long-integer field */
56 #define WRITE_LONG_FIELD(fldname) \
57 appendStringInfo(str, " :" CppAsString(fldname) " %ld", node->fldname)
59 /* Write a char field (ie, one ascii character) */
60 #define WRITE_CHAR_FIELD(fldname) \
61 appendStringInfo(str, " :" CppAsString(fldname) " %c", node->fldname)
63 /* Write an enumerated-type field as an integer code */
64 #define WRITE_ENUM_FIELD(fldname, enumtype) \
65 appendStringInfo(str, " :" CppAsString(fldname) " %d", \
68 /* Write a float field --- caller must give format to define precision */
69 #define WRITE_FLOAT_FIELD(fldname,format) \
70 appendStringInfo(str, " :" CppAsString(fldname) " " format, node->fldname)
72 /* Write a boolean field */
73 #define WRITE_BOOL_FIELD(fldname) \
74 appendStringInfo(str, " :" CppAsString(fldname) " %s", \
75 booltostr(node->fldname))
77 /* Write a character-string (possibly NULL) field */
78 #define WRITE_STRING_FIELD(fldname) \
79 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
80 _outToken(str, node->fldname))
82 /* Write a Node field */
83 #define WRITE_NODE_FIELD(fldname) \
84 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
85 _outNode(str, node->fldname))
87 /* Write a bitmapset field */
88 #define WRITE_BITMAPSET_FIELD(fldname) \
89 (appendStringInfo(str, " :" CppAsString(fldname) " "), \
90 _outBitmapset(str, node->fldname))
93 #define booltostr(x) ((x) ? "true" : "false")
95 static void _outNode(StringInfo str, void *obj);
100 * Convert an ordinary string (eg, an identifier) into a form that
101 * will be decoded back to a plain token by read.c's functions.
103 * If a null or empty string is given, it is encoded as "<>".
106 _outToken(StringInfo str, char *s)
108 if (s == NULL || *s == '\0')
110 appendStringInfo(str, "<>");
115 * Look for characters or patterns that are treated specially by read.c
116 * (either in pg_strtok() or in nodeRead()), and therefore need a
117 * protective backslash.
119 /* These characters only need to be quoted at the start of the string */
122 isdigit((unsigned char) *s) ||
123 ((*s == '+' || *s == '-') &&
124 (isdigit((unsigned char) s[1]) || s[1] == '.')))
125 appendStringInfoChar(str, '\\');
128 /* These chars must be backslashed anywhere in the string */
129 if (*s == ' ' || *s == '\n' || *s == '\t' ||
130 *s == '(' || *s == ')' || *s == '{' || *s == '}' ||
132 appendStringInfoChar(str, '\\');
133 appendStringInfoChar(str, *s++);
138 _outList(StringInfo str, List *node)
142 appendStringInfoChar(str, '(');
144 if (IsA(node, IntList))
145 appendStringInfoChar(str, 'i');
146 else if (IsA(node, OidList))
147 appendStringInfoChar(str, 'o');
152 * For the sake of backward compatibility, we emit a slightly
153 * different whitespace format for lists of nodes vs. other types of
154 * lists. XXX: is this necessary?
158 _outNode(str, lfirst(lc));
160 appendStringInfoChar(str, ' ');
162 else if (IsA(node, IntList))
163 appendStringInfo(str, " %d", lfirst_int(lc));
164 else if (IsA(node, OidList))
165 appendStringInfo(str, " %u", lfirst_oid(lc));
167 elog(ERROR, "unrecognized list node type: %d",
171 appendStringInfoChar(str, ')');
176 * converts a bitmap set of integers
178 * Note: the output format is "(b int int ...)", similar to an integer List.
179 * Currently bitmapsets do not appear in any node type that is stored in
180 * rules, so there is no support in readfuncs.c for reading this format.
183 _outBitmapset(StringInfo str, Bitmapset *bms)
188 appendStringInfoChar(str, '(');
189 appendStringInfoChar(str, 'b');
190 tmpset = bms_copy(bms);
191 while ((x = bms_first_member(tmpset)) >= 0)
192 appendStringInfo(str, " %d", x);
194 appendStringInfoChar(str, ')');
198 * Print the value of a Datum given its type.
201 _outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
207 length = datumGetSize(value, typbyval, typlen);
211 s = (char *) (&value);
212 appendStringInfo(str, "%u [ ", (unsigned int) length);
213 for (i = 0; i < (Size) sizeof(Datum); i++)
214 appendStringInfo(str, "%d ", (int) (s[i]));
215 appendStringInfo(str, "]");
219 s = (char *) DatumGetPointer(value);
220 if (!PointerIsValid(s))
221 appendStringInfo(str, "0 [ ]");
224 appendStringInfo(str, "%u [ ", (unsigned int) length);
225 for (i = 0; i < length; i++)
226 appendStringInfo(str, "%d ", (int) (s[i]));
227 appendStringInfo(str, "]");
234 * Stuff from plannodes.h
238 * print the basic stuff of all nodes that inherit from Plan
241 _outPlanInfo(StringInfo str, Plan *node)
243 WRITE_FLOAT_FIELD(startup_cost, "%.2f");
244 WRITE_FLOAT_FIELD(total_cost, "%.2f");
245 WRITE_FLOAT_FIELD(plan_rows, "%.0f");
246 WRITE_INT_FIELD(plan_width);
247 WRITE_NODE_FIELD(targetlist);
248 WRITE_NODE_FIELD(qual);
249 WRITE_NODE_FIELD(lefttree);
250 WRITE_NODE_FIELD(righttree);
251 WRITE_NODE_FIELD(initPlan);
252 WRITE_BITMAPSET_FIELD(extParam);
253 WRITE_BITMAPSET_FIELD(allParam);
254 WRITE_INT_FIELD(nParamExec);
258 * print the basic stuff of all nodes that inherit from Scan
261 _outScanInfo(StringInfo str, Scan *node)
263 _outPlanInfo(str, (Plan *) node);
265 WRITE_UINT_FIELD(scanrelid);
269 * print the basic stuff of all nodes that inherit from Join
272 _outJoinPlanInfo(StringInfo str, Join *node)
274 _outPlanInfo(str, (Plan *) node);
276 WRITE_ENUM_FIELD(jointype, JoinType);
277 WRITE_NODE_FIELD(joinqual);
282 _outPlan(StringInfo str, Plan *node)
284 WRITE_NODE_TYPE("PLAN");
286 _outPlanInfo(str, (Plan *) node);
290 _outResult(StringInfo str, Result *node)
292 WRITE_NODE_TYPE("RESULT");
294 _outPlanInfo(str, (Plan *) node);
296 WRITE_NODE_FIELD(resconstantqual);
300 _outAppend(StringInfo str, Append *node)
302 WRITE_NODE_TYPE("APPEND");
304 _outPlanInfo(str, (Plan *) node);
306 WRITE_NODE_FIELD(appendplans);
307 WRITE_BOOL_FIELD(isTarget);
311 _outBitmapAnd(StringInfo str, BitmapAnd *node)
313 WRITE_NODE_TYPE("BITMAPAND");
315 _outPlanInfo(str, (Plan *) node);
317 WRITE_NODE_FIELD(bitmapplans);
321 _outBitmapOr(StringInfo str, BitmapOr *node)
323 WRITE_NODE_TYPE("BITMAPOR");
325 _outPlanInfo(str, (Plan *) node);
327 WRITE_NODE_FIELD(bitmapplans);
331 _outScan(StringInfo str, Scan *node)
333 WRITE_NODE_TYPE("SCAN");
335 _outScanInfo(str, (Scan *) node);
339 _outSeqScan(StringInfo str, SeqScan *node)
341 WRITE_NODE_TYPE("SEQSCAN");
343 _outScanInfo(str, (Scan *) node);
347 _outIndexScan(StringInfo str, IndexScan *node)
349 WRITE_NODE_TYPE("INDEXSCAN");
351 _outScanInfo(str, (Scan *) node);
353 WRITE_OID_FIELD(indexid);
354 WRITE_NODE_FIELD(indexqual);
355 WRITE_NODE_FIELD(indexqualorig);
356 WRITE_NODE_FIELD(indexstrategy);
357 WRITE_NODE_FIELD(indexsubtype);
358 WRITE_ENUM_FIELD(indexorderdir, ScanDirection);
362 _outBitmapIndexScan(StringInfo str, BitmapIndexScan *node)
364 WRITE_NODE_TYPE("BITMAPINDEXSCAN");
366 _outScanInfo(str, (Scan *) node);
368 WRITE_OID_FIELD(indexid);
369 WRITE_NODE_FIELD(indexqual);
370 WRITE_NODE_FIELD(indexqualorig);
371 WRITE_NODE_FIELD(indexstrategy);
372 WRITE_NODE_FIELD(indexsubtype);
376 _outBitmapHeapScan(StringInfo str, BitmapHeapScan *node)
378 WRITE_NODE_TYPE("BITMAPHEAPSCAN");
380 _outScanInfo(str, (Scan *) node);
382 WRITE_NODE_FIELD(bitmapqualorig);
386 _outTidScan(StringInfo str, TidScan *node)
388 WRITE_NODE_TYPE("TIDSCAN");
390 _outScanInfo(str, (Scan *) node);
392 WRITE_NODE_FIELD(tidquals);
396 _outSubqueryScan(StringInfo str, SubqueryScan *node)
398 WRITE_NODE_TYPE("SUBQUERYSCAN");
400 _outScanInfo(str, (Scan *) node);
402 WRITE_NODE_FIELD(subplan);
406 _outFunctionScan(StringInfo str, FunctionScan *node)
408 WRITE_NODE_TYPE("FUNCTIONSCAN");
410 _outScanInfo(str, (Scan *) node);
412 WRITE_NODE_FIELD(funcexpr);
413 WRITE_NODE_FIELD(funccolnames);
414 WRITE_NODE_FIELD(funccoltypes);
415 WRITE_NODE_FIELD(funccoltypmods);
419 _outValuesScan(StringInfo str, ValuesScan *node)
421 WRITE_NODE_TYPE("VALUESSCAN");
423 _outScanInfo(str, (Scan *) node);
425 WRITE_NODE_FIELD(values_lists);
429 _outJoin(StringInfo str, Join *node)
431 WRITE_NODE_TYPE("JOIN");
433 _outJoinPlanInfo(str, (Join *) node);
437 _outNestLoop(StringInfo str, NestLoop *node)
439 WRITE_NODE_TYPE("NESTLOOP");
441 _outJoinPlanInfo(str, (Join *) node);
445 _outMergeJoin(StringInfo str, MergeJoin *node)
450 WRITE_NODE_TYPE("MERGEJOIN");
452 _outJoinPlanInfo(str, (Join *) node);
454 WRITE_NODE_FIELD(mergeclauses);
456 numCols = list_length(node->mergeclauses);
458 appendStringInfo(str, " :mergeFamilies");
459 for (i = 0; i < numCols; i++)
460 appendStringInfo(str, " %u", node->mergeFamilies[i]);
462 appendStringInfo(str, " :mergeStrategies");
463 for (i = 0; i < numCols; i++)
464 appendStringInfo(str, " %d", node->mergeStrategies[i]);
466 appendStringInfo(str, " :mergeNullsFirst");
467 for (i = 0; i < numCols; i++)
468 appendStringInfo(str, " %d", (int) node->mergeNullsFirst[i]);
472 _outHashJoin(StringInfo str, HashJoin *node)
474 WRITE_NODE_TYPE("HASHJOIN");
476 _outJoinPlanInfo(str, (Join *) node);
478 WRITE_NODE_FIELD(hashclauses);
482 _outAgg(StringInfo str, Agg *node)
484 WRITE_NODE_TYPE("AGG");
486 _outPlanInfo(str, (Plan *) node);
488 WRITE_ENUM_FIELD(aggstrategy, AggStrategy);
489 WRITE_INT_FIELD(numCols);
490 WRITE_LONG_FIELD(numGroups);
494 _outGroup(StringInfo str, Group *node)
498 WRITE_NODE_TYPE("GROUP");
500 _outPlanInfo(str, (Plan *) node);
502 WRITE_INT_FIELD(numCols);
504 appendStringInfo(str, " :grpColIdx");
505 for (i = 0; i < node->numCols; i++)
506 appendStringInfo(str, " %d", node->grpColIdx[i]);
508 appendStringInfo(str, " :grpOperators");
509 for (i = 0; i < node->numCols; i++)
510 appendStringInfo(str, " %u", node->grpOperators[i]);
514 _outMaterial(StringInfo str, Material *node)
516 WRITE_NODE_TYPE("MATERIAL");
518 _outPlanInfo(str, (Plan *) node);
522 _outSort(StringInfo str, Sort *node)
526 WRITE_NODE_TYPE("SORT");
528 _outPlanInfo(str, (Plan *) node);
530 WRITE_INT_FIELD(numCols);
532 appendStringInfo(str, " :sortColIdx");
533 for (i = 0; i < node->numCols; i++)
534 appendStringInfo(str, " %d", node->sortColIdx[i]);
536 appendStringInfo(str, " :sortOperators");
537 for (i = 0; i < node->numCols; i++)
538 appendStringInfo(str, " %u", node->sortOperators[i]);
540 appendStringInfo(str, " :nullsFirst");
541 for (i = 0; i < node->numCols; i++)
542 appendStringInfo(str, " %s", booltostr(node->nullsFirst[i]));
546 _outUnique(StringInfo str, Unique *node)
550 WRITE_NODE_TYPE("UNIQUE");
552 _outPlanInfo(str, (Plan *) node);
554 WRITE_INT_FIELD(numCols);
556 appendStringInfo(str, " :uniqColIdx");
557 for (i = 0; i < node->numCols; i++)
558 appendStringInfo(str, " %d", node->uniqColIdx[i]);
560 appendStringInfo(str, " :uniqOperators");
561 for (i = 0; i < node->numCols; i++)
562 appendStringInfo(str, " %u", node->uniqOperators[i]);
566 _outSetOp(StringInfo str, SetOp *node)
570 WRITE_NODE_TYPE("SETOP");
572 _outPlanInfo(str, (Plan *) node);
574 WRITE_ENUM_FIELD(cmd, SetOpCmd);
575 WRITE_INT_FIELD(numCols);
577 appendStringInfo(str, " :dupColIdx");
578 for (i = 0; i < node->numCols; i++)
579 appendStringInfo(str, " %d", node->dupColIdx[i]);
581 appendStringInfo(str, " :dupOperators");
582 for (i = 0; i < node->numCols; i++)
583 appendStringInfo(str, " %d", node->dupOperators[i]);
585 WRITE_INT_FIELD(flagColIdx);
589 _outLimit(StringInfo str, Limit *node)
591 WRITE_NODE_TYPE("LIMIT");
593 _outPlanInfo(str, (Plan *) node);
595 WRITE_NODE_FIELD(limitOffset);
596 WRITE_NODE_FIELD(limitCount);
600 _outHash(StringInfo str, Hash *node)
602 WRITE_NODE_TYPE("HASH");
604 _outPlanInfo(str, (Plan *) node);
607 /*****************************************************************************
609 * Stuff from primnodes.h.
611 *****************************************************************************/
614 _outAlias(StringInfo str, Alias *node)
616 WRITE_NODE_TYPE("ALIAS");
618 WRITE_STRING_FIELD(aliasname);
619 WRITE_NODE_FIELD(colnames);
623 _outRangeVar(StringInfo str, RangeVar *node)
625 WRITE_NODE_TYPE("RANGEVAR");
628 * we deliberately ignore catalogname here, since it is presently not
629 * semantically meaningful
631 WRITE_STRING_FIELD(schemaname);
632 WRITE_STRING_FIELD(relname);
633 WRITE_ENUM_FIELD(inhOpt, InhOption);
634 WRITE_BOOL_FIELD(istemp);
635 WRITE_NODE_FIELD(alias);
639 _outVar(StringInfo str, Var *node)
641 WRITE_NODE_TYPE("VAR");
643 WRITE_UINT_FIELD(varno);
644 WRITE_INT_FIELD(varattno);
645 WRITE_OID_FIELD(vartype);
646 WRITE_INT_FIELD(vartypmod);
647 WRITE_UINT_FIELD(varlevelsup);
648 WRITE_UINT_FIELD(varnoold);
649 WRITE_INT_FIELD(varoattno);
653 _outConst(StringInfo str, Const *node)
655 WRITE_NODE_TYPE("CONST");
657 WRITE_OID_FIELD(consttype);
658 WRITE_INT_FIELD(constlen);
659 WRITE_BOOL_FIELD(constbyval);
660 WRITE_BOOL_FIELD(constisnull);
662 appendStringInfo(str, " :constvalue ");
663 if (node->constisnull)
664 appendStringInfo(str, "<>");
666 _outDatum(str, node->constvalue, node->constlen, node->constbyval);
670 _outParam(StringInfo str, Param *node)
672 WRITE_NODE_TYPE("PARAM");
674 WRITE_ENUM_FIELD(paramkind, ParamKind);
675 WRITE_INT_FIELD(paramid);
676 WRITE_OID_FIELD(paramtype);
677 WRITE_INT_FIELD(paramtypmod);
681 _outAggref(StringInfo str, Aggref *node)
683 WRITE_NODE_TYPE("AGGREF");
685 WRITE_OID_FIELD(aggfnoid);
686 WRITE_OID_FIELD(aggtype);
687 WRITE_NODE_FIELD(args);
688 WRITE_UINT_FIELD(agglevelsup);
689 WRITE_BOOL_FIELD(aggstar);
690 WRITE_BOOL_FIELD(aggdistinct);
694 _outArrayRef(StringInfo str, ArrayRef *node)
696 WRITE_NODE_TYPE("ARRAYREF");
698 WRITE_OID_FIELD(refrestype);
699 WRITE_OID_FIELD(refarraytype);
700 WRITE_OID_FIELD(refelemtype);
701 WRITE_NODE_FIELD(refupperindexpr);
702 WRITE_NODE_FIELD(reflowerindexpr);
703 WRITE_NODE_FIELD(refexpr);
704 WRITE_NODE_FIELD(refassgnexpr);
708 _outFuncExpr(StringInfo str, FuncExpr *node)
710 WRITE_NODE_TYPE("FUNCEXPR");
712 WRITE_OID_FIELD(funcid);
713 WRITE_OID_FIELD(funcresulttype);
714 WRITE_BOOL_FIELD(funcretset);
715 WRITE_ENUM_FIELD(funcformat, CoercionForm);
716 WRITE_NODE_FIELD(args);
720 _outOpExpr(StringInfo str, OpExpr *node)
722 WRITE_NODE_TYPE("OPEXPR");
724 WRITE_OID_FIELD(opno);
725 WRITE_OID_FIELD(opfuncid);
726 WRITE_OID_FIELD(opresulttype);
727 WRITE_BOOL_FIELD(opretset);
728 WRITE_NODE_FIELD(args);
732 _outDistinctExpr(StringInfo str, DistinctExpr *node)
734 WRITE_NODE_TYPE("DISTINCTEXPR");
736 WRITE_OID_FIELD(opno);
737 WRITE_OID_FIELD(opfuncid);
738 WRITE_OID_FIELD(opresulttype);
739 WRITE_BOOL_FIELD(opretset);
740 WRITE_NODE_FIELD(args);
744 _outScalarArrayOpExpr(StringInfo str, ScalarArrayOpExpr *node)
746 WRITE_NODE_TYPE("SCALARARRAYOPEXPR");
748 WRITE_OID_FIELD(opno);
749 WRITE_OID_FIELD(opfuncid);
750 WRITE_BOOL_FIELD(useOr);
751 WRITE_NODE_FIELD(args);
755 _outBoolExpr(StringInfo str, BoolExpr *node)
759 WRITE_NODE_TYPE("BOOLEXPR");
761 /* do-it-yourself enum representation */
762 switch (node->boolop)
774 appendStringInfo(str, " :boolop ");
775 _outToken(str, opstr);
777 WRITE_NODE_FIELD(args);
781 _outSubLink(StringInfo str, SubLink *node)
783 WRITE_NODE_TYPE("SUBLINK");
785 WRITE_ENUM_FIELD(subLinkType, SubLinkType);
786 WRITE_NODE_FIELD(testexpr);
787 WRITE_NODE_FIELD(operName);
788 WRITE_NODE_FIELD(subselect);
792 _outSubPlan(StringInfo str, SubPlan *node)
794 WRITE_NODE_TYPE("SUBPLAN");
796 WRITE_ENUM_FIELD(subLinkType, SubLinkType);
797 WRITE_NODE_FIELD(testexpr);
798 WRITE_NODE_FIELD(paramIds);
799 WRITE_NODE_FIELD(plan);
800 WRITE_INT_FIELD(plan_id);
801 WRITE_NODE_FIELD(rtable);
802 WRITE_BOOL_FIELD(useHashTable);
803 WRITE_BOOL_FIELD(unknownEqFalse);
804 WRITE_NODE_FIELD(setParam);
805 WRITE_NODE_FIELD(parParam);
806 WRITE_NODE_FIELD(args);
810 _outFieldSelect(StringInfo str, FieldSelect *node)
812 WRITE_NODE_TYPE("FIELDSELECT");
814 WRITE_NODE_FIELD(arg);
815 WRITE_INT_FIELD(fieldnum);
816 WRITE_OID_FIELD(resulttype);
817 WRITE_INT_FIELD(resulttypmod);
821 _outFieldStore(StringInfo str, FieldStore *node)
823 WRITE_NODE_TYPE("FIELDSTORE");
825 WRITE_NODE_FIELD(arg);
826 WRITE_NODE_FIELD(newvals);
827 WRITE_NODE_FIELD(fieldnums);
828 WRITE_OID_FIELD(resulttype);
832 _outRelabelType(StringInfo str, RelabelType *node)
834 WRITE_NODE_TYPE("RELABELTYPE");
836 WRITE_NODE_FIELD(arg);
837 WRITE_OID_FIELD(resulttype);
838 WRITE_INT_FIELD(resulttypmod);
839 WRITE_ENUM_FIELD(relabelformat, CoercionForm);
843 _outConvertRowtypeExpr(StringInfo str, ConvertRowtypeExpr *node)
845 WRITE_NODE_TYPE("CONVERTROWTYPEEXPR");
847 WRITE_NODE_FIELD(arg);
848 WRITE_OID_FIELD(resulttype);
849 WRITE_ENUM_FIELD(convertformat, CoercionForm);
853 _outCaseExpr(StringInfo str, CaseExpr *node)
855 WRITE_NODE_TYPE("CASE");
857 WRITE_OID_FIELD(casetype);
858 WRITE_NODE_FIELD(arg);
859 WRITE_NODE_FIELD(args);
860 WRITE_NODE_FIELD(defresult);
864 _outCaseWhen(StringInfo str, CaseWhen *node)
866 WRITE_NODE_TYPE("WHEN");
868 WRITE_NODE_FIELD(expr);
869 WRITE_NODE_FIELD(result);
873 _outCaseTestExpr(StringInfo str, CaseTestExpr *node)
875 WRITE_NODE_TYPE("CASETESTEXPR");
877 WRITE_OID_FIELD(typeId);
878 WRITE_INT_FIELD(typeMod);
882 _outArrayExpr(StringInfo str, ArrayExpr *node)
884 WRITE_NODE_TYPE("ARRAY");
886 WRITE_OID_FIELD(array_typeid);
887 WRITE_OID_FIELD(element_typeid);
888 WRITE_NODE_FIELD(elements);
889 WRITE_BOOL_FIELD(multidims);
893 _outRowExpr(StringInfo str, RowExpr *node)
895 WRITE_NODE_TYPE("ROW");
897 WRITE_NODE_FIELD(args);
898 WRITE_OID_FIELD(row_typeid);
899 WRITE_ENUM_FIELD(row_format, CoercionForm);
903 _outRowCompareExpr(StringInfo str, RowCompareExpr *node)
905 WRITE_NODE_TYPE("ROWCOMPARE");
907 WRITE_ENUM_FIELD(rctype, RowCompareType);
908 WRITE_NODE_FIELD(opnos);
909 WRITE_NODE_FIELD(opfamilies);
910 WRITE_NODE_FIELD(largs);
911 WRITE_NODE_FIELD(rargs);
915 _outCoalesceExpr(StringInfo str, CoalesceExpr *node)
917 WRITE_NODE_TYPE("COALESCE");
919 WRITE_OID_FIELD(coalescetype);
920 WRITE_NODE_FIELD(args);
924 _outMinMaxExpr(StringInfo str, MinMaxExpr *node)
926 WRITE_NODE_TYPE("MINMAX");
928 WRITE_OID_FIELD(minmaxtype);
929 WRITE_ENUM_FIELD(op, MinMaxOp);
930 WRITE_NODE_FIELD(args);
934 _outXmlExpr(StringInfo str, XmlExpr *node)
936 WRITE_NODE_TYPE("XMLEXPR");
938 WRITE_ENUM_FIELD(op, XmlExprOp);
939 WRITE_STRING_FIELD(name);
940 WRITE_NODE_FIELD(named_args);
941 WRITE_NODE_FIELD(arg_names);
942 WRITE_NODE_FIELD(args);
943 WRITE_ENUM_FIELD(xmloption, XmlOptionType);
944 WRITE_OID_FIELD(type);
945 WRITE_INT_FIELD(typmod);
949 _outNullIfExpr(StringInfo str, NullIfExpr *node)
951 WRITE_NODE_TYPE("NULLIFEXPR");
953 WRITE_OID_FIELD(opno);
954 WRITE_OID_FIELD(opfuncid);
955 WRITE_OID_FIELD(opresulttype);
956 WRITE_BOOL_FIELD(opretset);
957 WRITE_NODE_FIELD(args);
961 _outNullTest(StringInfo str, NullTest *node)
963 WRITE_NODE_TYPE("NULLTEST");
965 WRITE_NODE_FIELD(arg);
966 WRITE_ENUM_FIELD(nulltesttype, NullTestType);
970 _outBooleanTest(StringInfo str, BooleanTest *node)
972 WRITE_NODE_TYPE("BOOLEANTEST");
974 WRITE_NODE_FIELD(arg);
975 WRITE_ENUM_FIELD(booltesttype, BoolTestType);
979 _outCoerceToDomain(StringInfo str, CoerceToDomain *node)
981 WRITE_NODE_TYPE("COERCETODOMAIN");
983 WRITE_NODE_FIELD(arg);
984 WRITE_OID_FIELD(resulttype);
985 WRITE_INT_FIELD(resulttypmod);
986 WRITE_ENUM_FIELD(coercionformat, CoercionForm);
990 _outCoerceToDomainValue(StringInfo str, CoerceToDomainValue *node)
992 WRITE_NODE_TYPE("COERCETODOMAINVALUE");
994 WRITE_OID_FIELD(typeId);
995 WRITE_INT_FIELD(typeMod);
999 _outSetToDefault(StringInfo str, SetToDefault *node)
1001 WRITE_NODE_TYPE("SETTODEFAULT");
1003 WRITE_OID_FIELD(typeId);
1004 WRITE_INT_FIELD(typeMod);
1008 _outTargetEntry(StringInfo str, TargetEntry *node)
1010 WRITE_NODE_TYPE("TARGETENTRY");
1012 WRITE_NODE_FIELD(expr);
1013 WRITE_INT_FIELD(resno);
1014 WRITE_STRING_FIELD(resname);
1015 WRITE_UINT_FIELD(ressortgroupref);
1016 WRITE_OID_FIELD(resorigtbl);
1017 WRITE_INT_FIELD(resorigcol);
1018 WRITE_BOOL_FIELD(resjunk);
1022 _outRangeTblRef(StringInfo str, RangeTblRef *node)
1024 WRITE_NODE_TYPE("RANGETBLREF");
1026 WRITE_INT_FIELD(rtindex);
1030 _outJoinExpr(StringInfo str, JoinExpr *node)
1032 WRITE_NODE_TYPE("JOINEXPR");
1034 WRITE_ENUM_FIELD(jointype, JoinType);
1035 WRITE_BOOL_FIELD(isNatural);
1036 WRITE_NODE_FIELD(larg);
1037 WRITE_NODE_FIELD(rarg);
1038 WRITE_NODE_FIELD(using);
1039 WRITE_NODE_FIELD(quals);
1040 WRITE_NODE_FIELD(alias);
1041 WRITE_INT_FIELD(rtindex);
1045 _outFromExpr(StringInfo str, FromExpr *node)
1047 WRITE_NODE_TYPE("FROMEXPR");
1049 WRITE_NODE_FIELD(fromlist);
1050 WRITE_NODE_FIELD(quals);
1053 /*****************************************************************************
1055 * Stuff from relation.h.
1057 *****************************************************************************/
1060 * print the basic stuff of all nodes that inherit from Path
1062 * Note we do NOT print the parent, else we'd be in infinite recursion
1065 _outPathInfo(StringInfo str, Path *node)
1067 WRITE_ENUM_FIELD(pathtype, NodeTag);
1068 WRITE_FLOAT_FIELD(startup_cost, "%.2f");
1069 WRITE_FLOAT_FIELD(total_cost, "%.2f");
1070 WRITE_NODE_FIELD(pathkeys);
1074 * print the basic stuff of all nodes that inherit from JoinPath
1077 _outJoinPathInfo(StringInfo str, JoinPath *node)
1079 _outPathInfo(str, (Path *) node);
1081 WRITE_ENUM_FIELD(jointype, JoinType);
1082 WRITE_NODE_FIELD(outerjoinpath);
1083 WRITE_NODE_FIELD(innerjoinpath);
1084 WRITE_NODE_FIELD(joinrestrictinfo);
1088 _outPath(StringInfo str, Path *node)
1090 WRITE_NODE_TYPE("PATH");
1092 _outPathInfo(str, (Path *) node);
1096 _outIndexPath(StringInfo str, IndexPath *node)
1098 WRITE_NODE_TYPE("INDEXPATH");
1100 _outPathInfo(str, (Path *) node);
1102 WRITE_NODE_FIELD(indexinfo);
1103 WRITE_NODE_FIELD(indexclauses);
1104 WRITE_NODE_FIELD(indexquals);
1105 WRITE_BOOL_FIELD(isjoininner);
1106 WRITE_ENUM_FIELD(indexscandir, ScanDirection);
1107 WRITE_FLOAT_FIELD(indextotalcost, "%.2f");
1108 WRITE_FLOAT_FIELD(indexselectivity, "%.4f");
1109 WRITE_FLOAT_FIELD(rows, "%.0f");
1113 _outBitmapHeapPath(StringInfo str, BitmapHeapPath *node)
1115 WRITE_NODE_TYPE("BITMAPHEAPPATH");
1117 _outPathInfo(str, (Path *) node);
1119 WRITE_NODE_FIELD(bitmapqual);
1120 WRITE_BOOL_FIELD(isjoininner);
1121 WRITE_FLOAT_FIELD(rows, "%.0f");
1125 _outBitmapAndPath(StringInfo str, BitmapAndPath *node)
1127 WRITE_NODE_TYPE("BITMAPANDPATH");
1129 _outPathInfo(str, (Path *) node);
1131 WRITE_NODE_FIELD(bitmapquals);
1132 WRITE_FLOAT_FIELD(bitmapselectivity, "%.4f");
1136 _outBitmapOrPath(StringInfo str, BitmapOrPath *node)
1138 WRITE_NODE_TYPE("BITMAPORPATH");
1140 _outPathInfo(str, (Path *) node);
1142 WRITE_NODE_FIELD(bitmapquals);
1143 WRITE_FLOAT_FIELD(bitmapselectivity, "%.4f");
1147 _outTidPath(StringInfo str, TidPath *node)
1149 WRITE_NODE_TYPE("TIDPATH");
1151 _outPathInfo(str, (Path *) node);
1153 WRITE_NODE_FIELD(tidquals);
1157 _outAppendPath(StringInfo str, AppendPath *node)
1159 WRITE_NODE_TYPE("APPENDPATH");
1161 _outPathInfo(str, (Path *) node);
1163 WRITE_NODE_FIELD(subpaths);
1167 _outResultPath(StringInfo str, ResultPath *node)
1169 WRITE_NODE_TYPE("RESULTPATH");
1171 _outPathInfo(str, (Path *) node);
1173 WRITE_NODE_FIELD(quals);
1177 _outMaterialPath(StringInfo str, MaterialPath *node)
1179 WRITE_NODE_TYPE("MATERIALPATH");
1181 _outPathInfo(str, (Path *) node);
1183 WRITE_NODE_FIELD(subpath);
1187 _outUniquePath(StringInfo str, UniquePath *node)
1189 WRITE_NODE_TYPE("UNIQUEPATH");
1191 _outPathInfo(str, (Path *) node);
1193 WRITE_NODE_FIELD(subpath);
1194 WRITE_ENUM_FIELD(umethod, UniquePathMethod);
1195 WRITE_FLOAT_FIELD(rows, "%.0f");
1199 _outNestPath(StringInfo str, NestPath *node)
1201 WRITE_NODE_TYPE("NESTPATH");
1203 _outJoinPathInfo(str, (JoinPath *) node);
1207 _outMergePath(StringInfo str, MergePath *node)
1209 WRITE_NODE_TYPE("MERGEPATH");
1211 _outJoinPathInfo(str, (JoinPath *) node);
1213 WRITE_NODE_FIELD(path_mergeclauses);
1214 WRITE_NODE_FIELD(outersortkeys);
1215 WRITE_NODE_FIELD(innersortkeys);
1219 _outHashPath(StringInfo str, HashPath *node)
1221 WRITE_NODE_TYPE("HASHPATH");
1223 _outJoinPathInfo(str, (JoinPath *) node);
1225 WRITE_NODE_FIELD(path_hashclauses);
1229 _outPlannerInfo(StringInfo str, PlannerInfo *node)
1231 WRITE_NODE_TYPE("PLANNERINFO");
1233 /* NB: this isn't a complete set of fields */
1234 WRITE_NODE_FIELD(parse);
1235 WRITE_NODE_FIELD(join_rel_list);
1236 WRITE_NODE_FIELD(eq_classes);
1237 WRITE_NODE_FIELD(canon_pathkeys);
1238 WRITE_NODE_FIELD(left_join_clauses);
1239 WRITE_NODE_FIELD(right_join_clauses);
1240 WRITE_NODE_FIELD(full_join_clauses);
1241 WRITE_NODE_FIELD(oj_info_list);
1242 WRITE_NODE_FIELD(in_info_list);
1243 WRITE_NODE_FIELD(append_rel_list);
1244 WRITE_NODE_FIELD(query_pathkeys);
1245 WRITE_NODE_FIELD(group_pathkeys);
1246 WRITE_NODE_FIELD(sort_pathkeys);
1247 WRITE_FLOAT_FIELD(total_table_pages, "%.0f");
1248 WRITE_FLOAT_FIELD(tuple_fraction, "%.4f");
1249 WRITE_BOOL_FIELD(hasJoinRTEs);
1250 WRITE_BOOL_FIELD(hasOuterJoins);
1251 WRITE_BOOL_FIELD(hasHavingQual);
1252 WRITE_BOOL_FIELD(hasPseudoConstantQuals);
1256 _outRelOptInfo(StringInfo str, RelOptInfo *node)
1258 WRITE_NODE_TYPE("RELOPTINFO");
1260 /* NB: this isn't a complete set of fields */
1261 WRITE_ENUM_FIELD(reloptkind, RelOptKind);
1262 WRITE_BITMAPSET_FIELD(relids);
1263 WRITE_FLOAT_FIELD(rows, "%.0f");
1264 WRITE_INT_FIELD(width);
1265 WRITE_NODE_FIELD(reltargetlist);
1266 WRITE_NODE_FIELD(pathlist);
1267 WRITE_NODE_FIELD(cheapest_startup_path);
1268 WRITE_NODE_FIELD(cheapest_total_path);
1269 WRITE_NODE_FIELD(cheapest_unique_path);
1270 WRITE_UINT_FIELD(relid);
1271 WRITE_ENUM_FIELD(rtekind, RTEKind);
1272 WRITE_INT_FIELD(min_attr);
1273 WRITE_INT_FIELD(max_attr);
1274 WRITE_NODE_FIELD(indexlist);
1275 WRITE_UINT_FIELD(pages);
1276 WRITE_FLOAT_FIELD(tuples, "%.0f");
1277 WRITE_NODE_FIELD(subplan);
1278 WRITE_NODE_FIELD(baserestrictinfo);
1279 WRITE_NODE_FIELD(joininfo);
1280 WRITE_BOOL_FIELD(has_eclass_joins);
1281 WRITE_BITMAPSET_FIELD(index_outer_relids);
1282 WRITE_NODE_FIELD(index_inner_paths);
1286 _outIndexOptInfo(StringInfo str, IndexOptInfo *node)
1288 WRITE_NODE_TYPE("INDEXOPTINFO");
1290 /* NB: this isn't a complete set of fields */
1291 WRITE_OID_FIELD(indexoid);
1292 /* Do NOT print rel field, else infinite recursion */
1293 WRITE_UINT_FIELD(pages);
1294 WRITE_FLOAT_FIELD(tuples, "%.0f");
1295 WRITE_INT_FIELD(ncolumns);
1296 WRITE_NODE_FIELD(indexprs);
1297 WRITE_NODE_FIELD(indpred);
1298 WRITE_BOOL_FIELD(predOK);
1299 WRITE_BOOL_FIELD(unique);
1303 _outEquivalenceClass(StringInfo str, EquivalenceClass *node)
1306 * To simplify reading, we just chase up to the topmost merged EC and
1307 * print that, without bothering to show the merge-ees separately.
1309 while (node->ec_merged)
1310 node = node->ec_merged;
1312 WRITE_NODE_TYPE("EQUIVALENCECLASS");
1314 WRITE_NODE_FIELD(ec_opfamilies);
1315 WRITE_NODE_FIELD(ec_members);
1316 WRITE_NODE_FIELD(ec_sources);
1317 WRITE_NODE_FIELD(ec_derives);
1318 WRITE_BITMAPSET_FIELD(ec_relids);
1319 WRITE_BOOL_FIELD(ec_has_const);
1320 WRITE_BOOL_FIELD(ec_has_volatile);
1321 WRITE_BOOL_FIELD(ec_below_outer_join);
1322 WRITE_BOOL_FIELD(ec_broken);
1326 _outEquivalenceMember(StringInfo str, EquivalenceMember *node)
1328 WRITE_NODE_TYPE("EQUIVALENCEMEMBER");
1330 WRITE_NODE_FIELD(em_expr);
1331 WRITE_BITMAPSET_FIELD(em_relids);
1332 WRITE_BOOL_FIELD(em_is_const);
1333 WRITE_BOOL_FIELD(em_is_child);
1334 WRITE_OID_FIELD(em_datatype);
1338 _outPathKey(StringInfo str, PathKey *node)
1340 WRITE_NODE_TYPE("PATHKEY");
1342 WRITE_NODE_FIELD(pk_eclass);
1343 WRITE_OID_FIELD(pk_opfamily);
1344 WRITE_INT_FIELD(pk_strategy);
1345 WRITE_BOOL_FIELD(pk_nulls_first);
1349 _outRestrictInfo(StringInfo str, RestrictInfo *node)
1351 WRITE_NODE_TYPE("RESTRICTINFO");
1353 /* NB: this isn't a complete set of fields */
1354 WRITE_NODE_FIELD(clause);
1355 WRITE_BOOL_FIELD(is_pushed_down);
1356 WRITE_BOOL_FIELD(outerjoin_delayed);
1357 WRITE_BOOL_FIELD(can_join);
1358 WRITE_BOOL_FIELD(pseudoconstant);
1359 WRITE_BITMAPSET_FIELD(clause_relids);
1360 WRITE_BITMAPSET_FIELD(required_relids);
1361 WRITE_BITMAPSET_FIELD(left_relids);
1362 WRITE_BITMAPSET_FIELD(right_relids);
1363 WRITE_NODE_FIELD(orclause);
1364 /* don't write parent_ec, leads to infinite recursion in plan tree dump */
1365 WRITE_NODE_FIELD(mergeopfamilies);
1366 /* don't write left_ec, leads to infinite recursion in plan tree dump */
1367 /* don't write right_ec, leads to infinite recursion in plan tree dump */
1368 WRITE_NODE_FIELD(left_em);
1369 WRITE_NODE_FIELD(right_em);
1370 WRITE_BOOL_FIELD(outer_is_left);
1371 WRITE_OID_FIELD(hashjoinoperator);
1375 _outInnerIndexscanInfo(StringInfo str, InnerIndexscanInfo *node)
1377 WRITE_NODE_TYPE("INNERINDEXSCANINFO");
1378 WRITE_BITMAPSET_FIELD(other_relids);
1379 WRITE_BOOL_FIELD(isouterjoin);
1380 WRITE_NODE_FIELD(best_innerpath);
1384 _outOuterJoinInfo(StringInfo str, OuterJoinInfo *node)
1386 WRITE_NODE_TYPE("OUTERJOININFO");
1388 WRITE_BITMAPSET_FIELD(min_lefthand);
1389 WRITE_BITMAPSET_FIELD(min_righthand);
1390 WRITE_BOOL_FIELD(is_full_join);
1391 WRITE_BOOL_FIELD(lhs_strict);
1395 _outInClauseInfo(StringInfo str, InClauseInfo *node)
1397 WRITE_NODE_TYPE("INCLAUSEINFO");
1399 WRITE_BITMAPSET_FIELD(lefthand);
1400 WRITE_BITMAPSET_FIELD(righthand);
1401 WRITE_NODE_FIELD(sub_targetlist);
1402 WRITE_NODE_FIELD(in_operators);
1406 _outAppendRelInfo(StringInfo str, AppendRelInfo *node)
1408 WRITE_NODE_TYPE("APPENDRELINFO");
1410 WRITE_UINT_FIELD(parent_relid);
1411 WRITE_UINT_FIELD(child_relid);
1412 WRITE_OID_FIELD(parent_reltype);
1413 WRITE_OID_FIELD(child_reltype);
1414 WRITE_NODE_FIELD(col_mappings);
1415 WRITE_NODE_FIELD(translated_vars);
1416 WRITE_OID_FIELD(parent_reloid);
1419 /*****************************************************************************
1421 * Stuff from parsenodes.h.
1423 *****************************************************************************/
1426 _outCreateStmt(StringInfo str, CreateStmt *node)
1428 WRITE_NODE_TYPE("CREATESTMT");
1430 WRITE_NODE_FIELD(relation);
1431 WRITE_NODE_FIELD(tableElts);
1432 WRITE_NODE_FIELD(inhRelations);
1433 WRITE_NODE_FIELD(constraints);
1434 WRITE_NODE_FIELD(options);
1435 WRITE_ENUM_FIELD(oncommit, OnCommitAction);
1436 WRITE_STRING_FIELD(tablespacename);
1440 _outIndexStmt(StringInfo str, IndexStmt *node)
1442 WRITE_NODE_TYPE("INDEXSTMT");
1444 WRITE_STRING_FIELD(idxname);
1445 WRITE_NODE_FIELD(relation);
1446 WRITE_STRING_FIELD(accessMethod);
1447 WRITE_STRING_FIELD(tableSpace);
1448 WRITE_NODE_FIELD(indexParams);
1449 WRITE_NODE_FIELD(options);
1450 WRITE_NODE_FIELD(whereClause);
1451 WRITE_NODE_FIELD(rangetable);
1452 WRITE_BOOL_FIELD(unique);
1453 WRITE_BOOL_FIELD(primary);
1454 WRITE_BOOL_FIELD(isconstraint);
1455 WRITE_BOOL_FIELD(concurrent);
1459 _outNotifyStmt(StringInfo str, NotifyStmt *node)
1461 WRITE_NODE_TYPE("NOTIFY");
1463 WRITE_NODE_FIELD(relation);
1467 _outDeclareCursorStmt(StringInfo str, DeclareCursorStmt *node)
1469 WRITE_NODE_TYPE("DECLARECURSOR");
1471 WRITE_STRING_FIELD(portalname);
1472 WRITE_INT_FIELD(options);
1473 WRITE_NODE_FIELD(query);
1477 _outSelectStmt(StringInfo str, SelectStmt *node)
1479 WRITE_NODE_TYPE("SELECT");
1481 WRITE_NODE_FIELD(distinctClause);
1482 WRITE_NODE_FIELD(into);
1483 WRITE_NODE_FIELD(intoColNames);
1484 WRITE_NODE_FIELD(intoOptions);
1485 WRITE_ENUM_FIELD(intoOnCommit, OnCommitAction);
1486 WRITE_STRING_FIELD(intoTableSpaceName);
1487 WRITE_NODE_FIELD(targetList);
1488 WRITE_NODE_FIELD(fromClause);
1489 WRITE_NODE_FIELD(whereClause);
1490 WRITE_NODE_FIELD(groupClause);
1491 WRITE_NODE_FIELD(havingClause);
1492 WRITE_NODE_FIELD(valuesLists);
1493 WRITE_NODE_FIELD(sortClause);
1494 WRITE_NODE_FIELD(limitOffset);
1495 WRITE_NODE_FIELD(limitCount);
1496 WRITE_NODE_FIELD(lockingClause);
1497 WRITE_ENUM_FIELD(op, SetOperation);
1498 WRITE_BOOL_FIELD(all);
1499 WRITE_NODE_FIELD(larg);
1500 WRITE_NODE_FIELD(rarg);
1504 _outFuncCall(StringInfo str, FuncCall *node)
1506 WRITE_NODE_TYPE("FUNCCALL");
1508 WRITE_NODE_FIELD(funcname);
1509 WRITE_NODE_FIELD(args);
1510 WRITE_BOOL_FIELD(agg_star);
1511 WRITE_BOOL_FIELD(agg_distinct);
1512 WRITE_INT_FIELD(location);
1516 _outDefElem(StringInfo str, DefElem *node)
1518 WRITE_NODE_TYPE("DEFELEM");
1520 WRITE_STRING_FIELD(defname);
1521 WRITE_NODE_FIELD(arg);
1525 _outLockingClause(StringInfo str, LockingClause *node)
1527 WRITE_NODE_TYPE("LOCKINGCLAUSE");
1529 WRITE_NODE_FIELD(lockedRels);
1530 WRITE_BOOL_FIELD(forUpdate);
1531 WRITE_BOOL_FIELD(noWait);
1535 _outXmlSerialize(StringInfo str, XmlSerialize *node)
1537 WRITE_NODE_TYPE("XMLSERIALIZE");
1539 WRITE_ENUM_FIELD(xmloption, XmlOptionType);
1540 WRITE_NODE_FIELD(expr);
1541 WRITE_NODE_FIELD(typename);
1545 _outColumnDef(StringInfo str, ColumnDef *node)
1547 WRITE_NODE_TYPE("COLUMNDEF");
1549 WRITE_STRING_FIELD(colname);
1550 WRITE_NODE_FIELD(typename);
1551 WRITE_INT_FIELD(inhcount);
1552 WRITE_BOOL_FIELD(is_local);
1553 WRITE_BOOL_FIELD(is_not_null);
1554 WRITE_NODE_FIELD(raw_default);
1555 WRITE_STRING_FIELD(cooked_default);
1556 WRITE_NODE_FIELD(constraints);
1560 _outTypeName(StringInfo str, TypeName *node)
1562 WRITE_NODE_TYPE("TYPENAME");
1564 WRITE_NODE_FIELD(names);
1565 WRITE_OID_FIELD(typeid);
1566 WRITE_BOOL_FIELD(timezone);
1567 WRITE_BOOL_FIELD(setof);
1568 WRITE_BOOL_FIELD(pct_type);
1569 WRITE_NODE_FIELD(typmods);
1570 WRITE_INT_FIELD(typemod);
1571 WRITE_NODE_FIELD(arrayBounds);
1572 WRITE_INT_FIELD(location);
1576 _outTypeCast(StringInfo str, TypeCast *node)
1578 WRITE_NODE_TYPE("TYPECAST");
1580 WRITE_NODE_FIELD(arg);
1581 WRITE_NODE_FIELD(typename);
1585 _outIndexElem(StringInfo str, IndexElem *node)
1587 WRITE_NODE_TYPE("INDEXELEM");
1589 WRITE_STRING_FIELD(name);
1590 WRITE_NODE_FIELD(expr);
1591 WRITE_NODE_FIELD(opclass);
1592 WRITE_ENUM_FIELD(ordering, SortByDir);
1593 WRITE_ENUM_FIELD(nulls_ordering, SortByNulls);
1597 _outQuery(StringInfo str, Query *node)
1599 WRITE_NODE_TYPE("QUERY");
1601 WRITE_ENUM_FIELD(commandType, CmdType);
1602 WRITE_ENUM_FIELD(querySource, QuerySource);
1603 WRITE_BOOL_FIELD(canSetTag);
1606 * Hack to work around missing outfuncs routines for a lot of the
1607 * utility-statement node types. (The only one we actually *need* for
1608 * rules support is NotifyStmt.) Someday we ought to support 'em all, but
1609 * for the meantime do this to avoid getting lots of warnings when running
1610 * with debug_print_parse on.
1612 if (node->utilityStmt)
1614 switch (nodeTag(node->utilityStmt))
1619 case T_DeclareCursorStmt:
1620 WRITE_NODE_FIELD(utilityStmt);
1623 appendStringInfo(str, " :utilityStmt ?");
1628 appendStringInfo(str, " :utilityStmt <>");
1630 WRITE_INT_FIELD(resultRelation);
1631 WRITE_NODE_FIELD(into);
1632 WRITE_NODE_FIELD(intoOptions);
1633 WRITE_ENUM_FIELD(intoOnCommit, OnCommitAction);
1634 WRITE_STRING_FIELD(intoTableSpaceName);
1635 WRITE_BOOL_FIELD(hasAggs);
1636 WRITE_BOOL_FIELD(hasSubLinks);
1637 WRITE_NODE_FIELD(rtable);
1638 WRITE_NODE_FIELD(jointree);
1639 WRITE_NODE_FIELD(targetList);
1640 WRITE_NODE_FIELD(returningList);
1641 WRITE_NODE_FIELD(groupClause);
1642 WRITE_NODE_FIELD(havingQual);
1643 WRITE_NODE_FIELD(distinctClause);
1644 WRITE_NODE_FIELD(sortClause);
1645 WRITE_NODE_FIELD(limitOffset);
1646 WRITE_NODE_FIELD(limitCount);
1647 WRITE_NODE_FIELD(rowMarks);
1648 WRITE_NODE_FIELD(setOperations);
1649 WRITE_NODE_FIELD(resultRelations);
1650 WRITE_NODE_FIELD(returningLists);
1654 _outSortClause(StringInfo str, SortClause *node)
1656 WRITE_NODE_TYPE("SORTCLAUSE");
1658 WRITE_UINT_FIELD(tleSortGroupRef);
1659 WRITE_OID_FIELD(sortop);
1660 WRITE_BOOL_FIELD(nulls_first);
1664 _outGroupClause(StringInfo str, GroupClause *node)
1666 WRITE_NODE_TYPE("GROUPCLAUSE");
1668 WRITE_UINT_FIELD(tleSortGroupRef);
1669 WRITE_OID_FIELD(sortop);
1670 WRITE_BOOL_FIELD(nulls_first);
1674 _outRowMarkClause(StringInfo str, RowMarkClause *node)
1676 WRITE_NODE_TYPE("ROWMARKCLAUSE");
1678 WRITE_UINT_FIELD(rti);
1679 WRITE_BOOL_FIELD(forUpdate);
1680 WRITE_BOOL_FIELD(noWait);
1684 _outSetOperationStmt(StringInfo str, SetOperationStmt *node)
1686 WRITE_NODE_TYPE("SETOPERATIONSTMT");
1688 WRITE_ENUM_FIELD(op, SetOperation);
1689 WRITE_BOOL_FIELD(all);
1690 WRITE_NODE_FIELD(larg);
1691 WRITE_NODE_FIELD(rarg);
1692 WRITE_NODE_FIELD(colTypes);
1693 WRITE_NODE_FIELD(colTypmods);
1697 _outRangeTblEntry(StringInfo str, RangeTblEntry *node)
1699 WRITE_NODE_TYPE("RTE");
1701 /* put alias + eref first to make dump more legible */
1702 WRITE_NODE_FIELD(alias);
1703 WRITE_NODE_FIELD(eref);
1704 WRITE_ENUM_FIELD(rtekind, RTEKind);
1706 switch (node->rtekind)
1710 WRITE_OID_FIELD(relid);
1713 WRITE_NODE_FIELD(subquery);
1716 WRITE_NODE_FIELD(funcexpr);
1717 WRITE_NODE_FIELD(funccoltypes);
1718 WRITE_NODE_FIELD(funccoltypmods);
1721 WRITE_NODE_FIELD(values_lists);
1724 WRITE_ENUM_FIELD(jointype, JoinType);
1725 WRITE_NODE_FIELD(joinaliasvars);
1728 elog(ERROR, "unrecognized RTE kind: %d", (int) node->rtekind);
1732 WRITE_BOOL_FIELD(inh);
1733 WRITE_BOOL_FIELD(inFromCl);
1734 WRITE_UINT_FIELD(requiredPerms);
1735 WRITE_OID_FIELD(checkAsUser);
1739 _outAExpr(StringInfo str, A_Expr *node)
1741 WRITE_NODE_TYPE("AEXPR");
1746 appendStringInfo(str, " ");
1747 WRITE_NODE_FIELD(name);
1750 appendStringInfo(str, " AND");
1753 appendStringInfo(str, " OR");
1756 appendStringInfo(str, " NOT");
1759 appendStringInfo(str, " ");
1760 WRITE_NODE_FIELD(name);
1761 appendStringInfo(str, " ANY ");
1764 appendStringInfo(str, " ");
1765 WRITE_NODE_FIELD(name);
1766 appendStringInfo(str, " ALL ");
1768 case AEXPR_DISTINCT:
1769 appendStringInfo(str, " DISTINCT ");
1770 WRITE_NODE_FIELD(name);
1773 appendStringInfo(str, " NULLIF ");
1774 WRITE_NODE_FIELD(name);
1777 appendStringInfo(str, " OF ");
1778 WRITE_NODE_FIELD(name);
1781 appendStringInfo(str, " IN ");
1782 WRITE_NODE_FIELD(name);
1785 appendStringInfo(str, " ??");
1789 WRITE_NODE_FIELD(lexpr);
1790 WRITE_NODE_FIELD(rexpr);
1791 WRITE_INT_FIELD(location);
1795 _outValue(StringInfo str, Value *value)
1797 switch (value->type)
1800 appendStringInfo(str, "%ld", value->val.ival);
1805 * We assume the value is a valid numeric literal and so does not
1808 appendStringInfoString(str, value->val.str);
1811 appendStringInfoChar(str, '"');
1812 _outToken(str, value->val.str);
1813 appendStringInfoChar(str, '"');
1816 /* internal representation already has leading 'b' */
1817 appendStringInfoString(str, value->val.str);
1820 elog(ERROR, "unrecognized node type: %d", (int) value->type);
1826 _outColumnRef(StringInfo str, ColumnRef *node)
1828 WRITE_NODE_TYPE("COLUMNREF");
1830 WRITE_NODE_FIELD(fields);
1831 WRITE_INT_FIELD(location);
1835 _outParamRef(StringInfo str, ParamRef *node)
1837 WRITE_NODE_TYPE("PARAMREF");
1839 WRITE_INT_FIELD(number);
1843 _outAConst(StringInfo str, A_Const *node)
1845 WRITE_NODE_TYPE("A_CONST");
1847 appendStringInfo(str, " :val ");
1848 _outValue(str, &(node->val));
1849 WRITE_NODE_FIELD(typename);
1853 _outA_Indices(StringInfo str, A_Indices *node)
1855 WRITE_NODE_TYPE("A_INDICES");
1857 WRITE_NODE_FIELD(lidx);
1858 WRITE_NODE_FIELD(uidx);
1862 _outA_Indirection(StringInfo str, A_Indirection *node)
1864 WRITE_NODE_TYPE("A_INDIRECTION");
1866 WRITE_NODE_FIELD(arg);
1867 WRITE_NODE_FIELD(indirection);
1871 _outResTarget(StringInfo str, ResTarget *node)
1873 WRITE_NODE_TYPE("RESTARGET");
1875 WRITE_STRING_FIELD(name);
1876 WRITE_NODE_FIELD(indirection);
1877 WRITE_NODE_FIELD(val);
1878 WRITE_INT_FIELD(location);
1882 _outConstraint(StringInfo str, Constraint *node)
1884 WRITE_NODE_TYPE("CONSTRAINT");
1886 WRITE_STRING_FIELD(name);
1888 appendStringInfo(str, " :contype ");
1889 switch (node->contype)
1891 case CONSTR_PRIMARY:
1892 appendStringInfo(str, "PRIMARY_KEY");
1893 WRITE_NODE_FIELD(keys);
1894 WRITE_NODE_FIELD(options);
1895 WRITE_STRING_FIELD(indexspace);
1899 appendStringInfo(str, "UNIQUE");
1900 WRITE_NODE_FIELD(keys);
1901 WRITE_NODE_FIELD(options);
1902 WRITE_STRING_FIELD(indexspace);
1906 appendStringInfo(str, "CHECK");
1907 WRITE_NODE_FIELD(raw_expr);
1908 WRITE_STRING_FIELD(cooked_expr);
1911 case CONSTR_DEFAULT:
1912 appendStringInfo(str, "DEFAULT");
1913 WRITE_NODE_FIELD(raw_expr);
1914 WRITE_STRING_FIELD(cooked_expr);
1917 case CONSTR_NOTNULL:
1918 appendStringInfo(str, "NOT_NULL");
1922 appendStringInfo(str, "<unrecognized_constraint>");
1928 _outFkConstraint(StringInfo str, FkConstraint *node)
1930 WRITE_NODE_TYPE("FKCONSTRAINT");
1932 WRITE_STRING_FIELD(constr_name);
1933 WRITE_NODE_FIELD(pktable);
1934 WRITE_NODE_FIELD(fk_attrs);
1935 WRITE_NODE_FIELD(pk_attrs);
1936 WRITE_CHAR_FIELD(fk_matchtype);
1937 WRITE_CHAR_FIELD(fk_upd_action);
1938 WRITE_CHAR_FIELD(fk_del_action);
1939 WRITE_BOOL_FIELD(deferrable);
1940 WRITE_BOOL_FIELD(initdeferred);
1941 WRITE_BOOL_FIELD(skip_validation);
1947 * converts a Node into ascii string and append it to 'str'
1950 _outNode(StringInfo str, void *obj)
1953 appendStringInfo(str, "<>");
1954 else if (IsA(obj, List) ||IsA(obj, IntList) || IsA(obj, OidList))
1956 else if (IsA(obj, Integer) ||
1959 IsA(obj, BitString))
1961 /* nodeRead does not want to see { } around these! */
1962 _outValue(str, obj);
1966 appendStringInfoChar(str, '{');
1967 switch (nodeTag(obj))
1973 _outResult(str, obj);
1976 _outAppend(str, obj);
1979 _outBitmapAnd(str, obj);
1982 _outBitmapOr(str, obj);
1988 _outSeqScan(str, obj);
1991 _outIndexScan(str, obj);
1993 case T_BitmapIndexScan:
1994 _outBitmapIndexScan(str, obj);
1996 case T_BitmapHeapScan:
1997 _outBitmapHeapScan(str, obj);
2000 _outTidScan(str, obj);
2002 case T_SubqueryScan:
2003 _outSubqueryScan(str, obj);
2005 case T_FunctionScan:
2006 _outFunctionScan(str, obj);
2009 _outValuesScan(str, obj);
2015 _outNestLoop(str, obj);
2018 _outMergeJoin(str, obj);
2021 _outHashJoin(str, obj);
2027 _outGroup(str, obj);
2030 _outMaterial(str, obj);
2036 _outUnique(str, obj);
2039 _outSetOp(str, obj);
2042 _outLimit(str, obj);
2048 _outAlias(str, obj);
2051 _outRangeVar(str, obj);
2057 _outConst(str, obj);
2060 _outParam(str, obj);
2063 _outAggref(str, obj);
2066 _outArrayRef(str, obj);
2069 _outFuncExpr(str, obj);
2072 _outOpExpr(str, obj);
2074 case T_DistinctExpr:
2075 _outDistinctExpr(str, obj);
2077 case T_ScalarArrayOpExpr:
2078 _outScalarArrayOpExpr(str, obj);
2081 _outBoolExpr(str, obj);
2084 _outSubLink(str, obj);
2087 _outSubPlan(str, obj);
2090 _outFieldSelect(str, obj);
2093 _outFieldStore(str, obj);
2096 _outRelabelType(str, obj);
2098 case T_ConvertRowtypeExpr:
2099 _outConvertRowtypeExpr(str, obj);
2102 _outCaseExpr(str, obj);
2105 _outCaseWhen(str, obj);
2107 case T_CaseTestExpr:
2108 _outCaseTestExpr(str, obj);
2111 _outArrayExpr(str, obj);
2114 _outRowExpr(str, obj);
2116 case T_RowCompareExpr:
2117 _outRowCompareExpr(str, obj);
2119 case T_CoalesceExpr:
2120 _outCoalesceExpr(str, obj);
2123 _outMinMaxExpr(str, obj);
2126 _outXmlExpr(str, obj);
2129 _outNullIfExpr(str, obj);
2132 _outNullTest(str, obj);
2135 _outBooleanTest(str, obj);
2137 case T_CoerceToDomain:
2138 _outCoerceToDomain(str, obj);
2140 case T_CoerceToDomainValue:
2141 _outCoerceToDomainValue(str, obj);
2143 case T_SetToDefault:
2144 _outSetToDefault(str, obj);
2147 _outTargetEntry(str, obj);
2150 _outRangeTblRef(str, obj);
2153 _outJoinExpr(str, obj);
2156 _outFromExpr(str, obj);
2163 _outIndexPath(str, obj);
2165 case T_BitmapHeapPath:
2166 _outBitmapHeapPath(str, obj);
2168 case T_BitmapAndPath:
2169 _outBitmapAndPath(str, obj);
2171 case T_BitmapOrPath:
2172 _outBitmapOrPath(str, obj);
2175 _outTidPath(str, obj);
2178 _outAppendPath(str, obj);
2181 _outResultPath(str, obj);
2183 case T_MaterialPath:
2184 _outMaterialPath(str, obj);
2187 _outUniquePath(str, obj);
2190 _outNestPath(str, obj);
2193 _outMergePath(str, obj);
2196 _outHashPath(str, obj);
2199 _outPlannerInfo(str, obj);
2202 _outRelOptInfo(str, obj);
2204 case T_IndexOptInfo:
2205 _outIndexOptInfo(str, obj);
2207 case T_EquivalenceClass:
2208 _outEquivalenceClass(str, obj);
2210 case T_EquivalenceMember:
2211 _outEquivalenceMember(str, obj);
2214 _outPathKey(str, obj);
2216 case T_RestrictInfo:
2217 _outRestrictInfo(str, obj);
2219 case T_InnerIndexscanInfo:
2220 _outInnerIndexscanInfo(str, obj);
2222 case T_OuterJoinInfo:
2223 _outOuterJoinInfo(str, obj);
2225 case T_InClauseInfo:
2226 _outInClauseInfo(str, obj);
2228 case T_AppendRelInfo:
2229 _outAppendRelInfo(str, obj);
2233 _outCreateStmt(str, obj);
2236 _outIndexStmt(str, obj);
2239 _outNotifyStmt(str, obj);
2241 case T_DeclareCursorStmt:
2242 _outDeclareCursorStmt(str, obj);
2245 _outSelectStmt(str, obj);
2248 _outColumnDef(str, obj);
2251 _outTypeName(str, obj);
2254 _outTypeCast(str, obj);
2257 _outIndexElem(str, obj);
2260 _outQuery(str, obj);
2263 _outSortClause(str, obj);
2266 _outGroupClause(str, obj);
2268 case T_RowMarkClause:
2269 _outRowMarkClause(str, obj);
2271 case T_SetOperationStmt:
2272 _outSetOperationStmt(str, obj);
2274 case T_RangeTblEntry:
2275 _outRangeTblEntry(str, obj);
2278 _outAExpr(str, obj);
2281 _outColumnRef(str, obj);
2284 _outParamRef(str, obj);
2287 _outAConst(str, obj);
2290 _outA_Indices(str, obj);
2292 case T_A_Indirection:
2293 _outA_Indirection(str, obj);
2296 _outResTarget(str, obj);
2299 _outConstraint(str, obj);
2301 case T_FkConstraint:
2302 _outFkConstraint(str, obj);
2305 _outFuncCall(str, obj);
2308 _outDefElem(str, obj);
2310 case T_LockingClause:
2311 _outLockingClause(str, obj);
2313 case T_XmlSerialize:
2314 _outXmlSerialize(str, obj);
2320 * This should be an ERROR, but it's too useful to be able to
2321 * dump structures that _outNode only understands part of.
2323 elog(WARNING, "could not dump unrecognized node type: %d",
2324 (int) nodeTag(obj));
2327 appendStringInfoChar(str, '}');
2333 * returns the ascii representation of the Node as a palloc'd string
2336 nodeToString(void *obj)
2340 /* see stringinfo.h for an explanation of this maneuver */
2341 initStringInfo(&str);
2342 _outNode(&str, obj);