1 /*-------------------------------------------------------------------------
4 * Reader functions for Postgres tree nodes.
6 * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/nodes/readfuncs.c
14 * Path nodes do not have any readfuncs support, because we never
15 * have occasion to read them in. (There was once code here that
16 * claimed to read them, but it was broken as well as unused.) We
17 * never read executor state trees, either.
19 * Parse location fields are written out by outfuncs.c, but only for
20 * possible debugging use. When reading a location field, we discard
21 * the stored value and set the location field to -1 (ie, "unknown").
22 * This is because nodes coming from a stored rule should not be thought
23 * to have a known location in the current query's text.
25 *-------------------------------------------------------------------------
32 #include "nodes/extensible.h"
33 #include "nodes/parsenodes.h"
34 #include "nodes/plannodes.h"
35 #include "nodes/readfuncs.h"
39 * Macros to simplify reading of different kinds of fields. Use these
40 * wherever possible to reduce the chance for silly typos. Note that these
41 * hard-wire conventions about the names of the local variables in a Read
45 /* Macros for declaring appropriate local variables */
47 /* A few guys need only local_node */
48 #define READ_LOCALS_NO_FIELDS(nodeTypeName) \
49 nodeTypeName *local_node = makeNode(nodeTypeName)
51 /* And a few guys need only the pg_strtok support fields */
52 #define READ_TEMP_LOCALS() \
56 /* ... but most need both */
57 #define READ_LOCALS(nodeTypeName) \
58 READ_LOCALS_NO_FIELDS(nodeTypeName); \
61 /* Read an integer field (anything written as ":fldname %d") */
62 #define READ_INT_FIELD(fldname) \
63 token = pg_strtok(&length); /* skip :fldname */ \
64 token = pg_strtok(&length); /* get field value */ \
65 local_node->fldname = atoi(token)
67 /* Read an unsigned integer field (anything written as ":fldname %u") */
68 #define READ_UINT_FIELD(fldname) \
69 token = pg_strtok(&length); /* skip :fldname */ \
70 token = pg_strtok(&length); /* get field value */ \
71 local_node->fldname = atoui(token)
73 /* Read an long integer field (anything written as ":fldname %ld") */
74 #define READ_LONG_FIELD(fldname) \
75 token = pg_strtok(&length); /* skip :fldname */ \
76 token = pg_strtok(&length); /* get field value */ \
77 local_node->fldname = atol(token)
79 /* Read an OID field (don't hard-wire assumption that OID is same as uint) */
80 #define READ_OID_FIELD(fldname) \
81 token = pg_strtok(&length); /* skip :fldname */ \
82 token = pg_strtok(&length); /* get field value */ \
83 local_node->fldname = atooid(token)
85 /* Read a char field (ie, one ascii character) */
86 #define READ_CHAR_FIELD(fldname) \
87 token = pg_strtok(&length); /* skip :fldname */ \
88 token = pg_strtok(&length); /* get field value */ \
89 local_node->fldname = token[0]
91 /* Read an enumerated-type field that was written as an integer code */
92 #define READ_ENUM_FIELD(fldname, enumtype) \
93 token = pg_strtok(&length); /* skip :fldname */ \
94 token = pg_strtok(&length); /* get field value */ \
95 local_node->fldname = (enumtype) atoi(token)
97 /* Read a float field */
98 #define READ_FLOAT_FIELD(fldname) \
99 token = pg_strtok(&length); /* skip :fldname */ \
100 token = pg_strtok(&length); /* get field value */ \
101 local_node->fldname = atof(token)
103 /* Read a boolean field */
104 #define READ_BOOL_FIELD(fldname) \
105 token = pg_strtok(&length); /* skip :fldname */ \
106 token = pg_strtok(&length); /* get field value */ \
107 local_node->fldname = strtobool(token)
109 /* Read a character-string field */
110 #define READ_STRING_FIELD(fldname) \
111 token = pg_strtok(&length); /* skip :fldname */ \
112 token = pg_strtok(&length); /* get field value */ \
113 local_node->fldname = nullable_string(token, length)
115 /* Read a parse location field (and throw away the value, per notes above) */
116 #define READ_LOCATION_FIELD(fldname) \
117 token = pg_strtok(&length); /* skip :fldname */ \
118 token = pg_strtok(&length); /* get field value */ \
119 (void) token; /* in case not used elsewhere */ \
120 local_node->fldname = -1 /* set field to "unknown" */
122 /* Read a Node field */
123 #define READ_NODE_FIELD(fldname) \
124 token = pg_strtok(&length); /* skip :fldname */ \
125 (void) token; /* in case not used elsewhere */ \
126 local_node->fldname = nodeRead(NULL, 0)
128 /* Read a bitmapset field */
129 #define READ_BITMAPSET_FIELD(fldname) \
130 token = pg_strtok(&length); /* skip :fldname */ \
131 (void) token; /* in case not used elsewhere */ \
132 local_node->fldname = _readBitmapset()
134 /* Read an attribute number array */
135 #define READ_ATTRNUMBER_ARRAY(fldname, len) \
136 token = pg_strtok(&length); /* skip :fldname */ \
137 local_node->fldname = readAttrNumberCols(len);
139 /* Read an oid array */
140 #define READ_OID_ARRAY(fldname, len) \
141 token = pg_strtok(&length); /* skip :fldname */ \
142 local_node->fldname = readOidCols(len);
144 /* Read an int array */
145 #define READ_INT_ARRAY(fldname, len) \
146 token = pg_strtok(&length); /* skip :fldname */ \
147 local_node->fldname = readIntCols(len);
149 /* Read a bool array */
150 #define READ_BOOL_ARRAY(fldname, len) \
151 token = pg_strtok(&length); /* skip :fldname */ \
152 local_node->fldname = readBoolCols(len);
155 #define READ_DONE() \
160 * NOTE: use atoi() to read values written with %d, or atoui() to read
161 * values written with %u in outfuncs.c. An exception is OID values,
162 * for which use atooid(). (As of 7.1, outfuncs.c writes OIDs as %u,
163 * but this will probably change in the future.)
165 #define atoui(x) ((unsigned int) strtoul((x), NULL, 10))
167 #define strtobool(x) ((*(x) == 't') ? true : false)
169 #define nullable_string(token,length) \
170 ((length) == 0 ? NULL : debackslash(token, length))
179 Bitmapset *result = NULL;
183 token = pg_strtok(&length);
185 elog(ERROR, "incomplete Bitmapset structure");
186 if (length != 1 || token[0] != '(')
187 elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
189 token = pg_strtok(&length);
191 elog(ERROR, "incomplete Bitmapset structure");
192 if (length != 1 || token[0] != 'b')
193 elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
200 token = pg_strtok(&length);
202 elog(ERROR, "unterminated Bitmapset structure");
203 if (length == 1 && token[0] == ')')
205 val = (int) strtol(token, &endptr, 10);
206 if (endptr != token + length)
207 elog(ERROR, "unrecognized integer: \"%.*s\"", length, token);
208 result = bms_add_member(result, val);
215 * for use by extensions which define extensible nodes
220 return _readBitmapset();
231 READ_ENUM_FIELD(commandType, CmdType);
232 READ_ENUM_FIELD(querySource, QuerySource);
233 local_node->queryId = 0; /* not saved in output format */
234 READ_BOOL_FIELD(canSetTag);
235 READ_NODE_FIELD(utilityStmt);
236 READ_INT_FIELD(resultRelation);
237 READ_BOOL_FIELD(hasAggs);
238 READ_BOOL_FIELD(hasWindowFuncs);
239 READ_BOOL_FIELD(hasTargetSRFs);
240 READ_BOOL_FIELD(hasSubLinks);
241 READ_BOOL_FIELD(hasDistinctOn);
242 READ_BOOL_FIELD(hasRecursive);
243 READ_BOOL_FIELD(hasModifyingCTE);
244 READ_BOOL_FIELD(hasForUpdate);
245 READ_BOOL_FIELD(hasRowSecurity);
246 READ_NODE_FIELD(cteList);
247 READ_NODE_FIELD(rtable);
248 READ_NODE_FIELD(jointree);
249 READ_NODE_FIELD(targetList);
250 READ_ENUM_FIELD(override, OverridingKind);
251 READ_NODE_FIELD(onConflict);
252 READ_NODE_FIELD(returningList);
253 READ_NODE_FIELD(groupClause);
254 READ_NODE_FIELD(groupingSets);
255 READ_NODE_FIELD(havingQual);
256 READ_NODE_FIELD(windowClause);
257 READ_NODE_FIELD(distinctClause);
258 READ_NODE_FIELD(sortClause);
259 READ_NODE_FIELD(limitOffset);
260 READ_NODE_FIELD(limitCount);
261 READ_NODE_FIELD(rowMarks);
262 READ_NODE_FIELD(setOperations);
263 READ_NODE_FIELD(constraintDeps);
264 /* withCheckOptions intentionally omitted, see comment in parsenodes.h */
265 READ_LOCATION_FIELD(stmt_location);
266 READ_LOCATION_FIELD(stmt_len);
275 _readNotifyStmt(void)
277 READ_LOCALS(NotifyStmt);
279 READ_STRING_FIELD(conditionname);
280 READ_STRING_FIELD(payload);
286 * _readDeclareCursorStmt
288 static DeclareCursorStmt *
289 _readDeclareCursorStmt(void)
291 READ_LOCALS(DeclareCursorStmt);
293 READ_STRING_FIELD(portalname);
294 READ_INT_FIELD(options);
295 READ_NODE_FIELD(query);
301 * _readWithCheckOption
303 static WithCheckOption *
304 _readWithCheckOption(void)
306 READ_LOCALS(WithCheckOption);
308 READ_ENUM_FIELD(kind, WCOKind);
309 READ_STRING_FIELD(relname);
310 READ_STRING_FIELD(polname);
311 READ_NODE_FIELD(qual);
312 READ_BOOL_FIELD(cascaded);
318 * _readSortGroupClause
320 static SortGroupClause *
321 _readSortGroupClause(void)
323 READ_LOCALS(SortGroupClause);
325 READ_UINT_FIELD(tleSortGroupRef);
326 READ_OID_FIELD(eqop);
327 READ_OID_FIELD(sortop);
328 READ_BOOL_FIELD(nulls_first);
329 READ_BOOL_FIELD(hashable);
338 _readGroupingSet(void)
340 READ_LOCALS(GroupingSet);
342 READ_ENUM_FIELD(kind, GroupingSetKind);
343 READ_NODE_FIELD(content);
344 READ_LOCATION_FIELD(location);
352 static WindowClause *
353 _readWindowClause(void)
355 READ_LOCALS(WindowClause);
357 READ_STRING_FIELD(name);
358 READ_STRING_FIELD(refname);
359 READ_NODE_FIELD(partitionClause);
360 READ_NODE_FIELD(orderClause);
361 READ_INT_FIELD(frameOptions);
362 READ_NODE_FIELD(startOffset);
363 READ_NODE_FIELD(endOffset);
364 READ_UINT_FIELD(winref);
365 READ_BOOL_FIELD(copiedOrder);
373 static RowMarkClause *
374 _readRowMarkClause(void)
376 READ_LOCALS(RowMarkClause);
378 READ_UINT_FIELD(rti);
379 READ_ENUM_FIELD(strength, LockClauseStrength);
380 READ_ENUM_FIELD(waitPolicy, LockWaitPolicy);
381 READ_BOOL_FIELD(pushedDown);
387 * _readCommonTableExpr
389 static CommonTableExpr *
390 _readCommonTableExpr(void)
392 READ_LOCALS(CommonTableExpr);
394 READ_STRING_FIELD(ctename);
395 READ_NODE_FIELD(aliascolnames);
396 READ_NODE_FIELD(ctequery);
397 READ_LOCATION_FIELD(location);
398 READ_BOOL_FIELD(cterecursive);
399 READ_INT_FIELD(cterefcount);
400 READ_NODE_FIELD(ctecolnames);
401 READ_NODE_FIELD(ctecoltypes);
402 READ_NODE_FIELD(ctecoltypmods);
403 READ_NODE_FIELD(ctecolcollations);
409 * _readSetOperationStmt
411 static SetOperationStmt *
412 _readSetOperationStmt(void)
414 READ_LOCALS(SetOperationStmt);
416 READ_ENUM_FIELD(op, SetOperation);
417 READ_BOOL_FIELD(all);
418 READ_NODE_FIELD(larg);
419 READ_NODE_FIELD(rarg);
420 READ_NODE_FIELD(colTypes);
421 READ_NODE_FIELD(colTypmods);
422 READ_NODE_FIELD(colCollations);
423 READ_NODE_FIELD(groupClauses);
430 * Stuff from primnodes.h.
438 READ_STRING_FIELD(aliasname);
439 READ_NODE_FIELD(colnames);
447 READ_LOCALS(RangeVar);
449 local_node->catalogname = NULL; /* not currently saved in output
452 READ_STRING_FIELD(schemaname);
453 READ_STRING_FIELD(relname);
454 READ_BOOL_FIELD(inh);
455 READ_CHAR_FIELD(relpersistence);
456 READ_NODE_FIELD(alias);
457 READ_LOCATION_FIELD(location);
468 READ_LOCALS(TableFunc);
470 READ_NODE_FIELD(ns_names);
471 READ_NODE_FIELD(ns_uris);
472 READ_NODE_FIELD(docexpr);
473 READ_NODE_FIELD(rowexpr);
474 READ_NODE_FIELD(colnames);
475 READ_NODE_FIELD(coltypes);
476 READ_NODE_FIELD(coltypmods);
477 READ_NODE_FIELD(colcollations);
478 READ_NODE_FIELD(colexprs);
479 READ_NODE_FIELD(coldefexprs);
480 READ_BITMAPSET_FIELD(notnulls);
481 READ_INT_FIELD(ordinalitycol);
482 READ_LOCATION_FIELD(location);
488 _readIntoClause(void)
490 READ_LOCALS(IntoClause);
492 READ_NODE_FIELD(rel);
493 READ_NODE_FIELD(colNames);
494 READ_NODE_FIELD(options);
495 READ_ENUM_FIELD(onCommit, OnCommitAction);
496 READ_STRING_FIELD(tableSpaceName);
497 READ_NODE_FIELD(viewQuery);
498 READ_BOOL_FIELD(skipData);
511 READ_UINT_FIELD(varno);
512 READ_INT_FIELD(varattno);
513 READ_OID_FIELD(vartype);
514 READ_INT_FIELD(vartypmod);
515 READ_OID_FIELD(varcollid);
516 READ_UINT_FIELD(varlevelsup);
517 READ_UINT_FIELD(varnoold);
518 READ_INT_FIELD(varoattno);
519 READ_LOCATION_FIELD(location);
532 READ_OID_FIELD(consttype);
533 READ_INT_FIELD(consttypmod);
534 READ_OID_FIELD(constcollid);
535 READ_INT_FIELD(constlen);
536 READ_BOOL_FIELD(constbyval);
537 READ_BOOL_FIELD(constisnull);
538 READ_LOCATION_FIELD(location);
540 token = pg_strtok(&length); /* skip :constvalue */
541 if (local_node->constisnull)
542 token = pg_strtok(&length); /* skip "<>" */
544 local_node->constvalue = readDatum(local_node->constbyval);
557 READ_ENUM_FIELD(paramkind, ParamKind);
558 READ_INT_FIELD(paramid);
559 READ_OID_FIELD(paramtype);
560 READ_INT_FIELD(paramtypmod);
561 READ_OID_FIELD(paramcollid);
562 READ_LOCATION_FIELD(location);
575 READ_OID_FIELD(aggfnoid);
576 READ_OID_FIELD(aggtype);
577 READ_OID_FIELD(aggcollid);
578 READ_OID_FIELD(inputcollid);
579 READ_OID_FIELD(aggtranstype);
580 READ_NODE_FIELD(aggargtypes);
581 READ_NODE_FIELD(aggdirectargs);
582 READ_NODE_FIELD(args);
583 READ_NODE_FIELD(aggorder);
584 READ_NODE_FIELD(aggdistinct);
585 READ_NODE_FIELD(aggfilter);
586 READ_BOOL_FIELD(aggstar);
587 READ_BOOL_FIELD(aggvariadic);
588 READ_CHAR_FIELD(aggkind);
589 READ_UINT_FIELD(agglevelsup);
590 READ_ENUM_FIELD(aggsplit, AggSplit);
591 READ_LOCATION_FIELD(location);
599 static GroupingFunc *
600 _readGroupingFunc(void)
602 READ_LOCALS(GroupingFunc);
604 READ_NODE_FIELD(args);
605 READ_NODE_FIELD(refs);
606 READ_NODE_FIELD(cols);
607 READ_UINT_FIELD(agglevelsup);
608 READ_LOCATION_FIELD(location);
617 _readWindowFunc(void)
619 READ_LOCALS(WindowFunc);
621 READ_OID_FIELD(winfnoid);
622 READ_OID_FIELD(wintype);
623 READ_OID_FIELD(wincollid);
624 READ_OID_FIELD(inputcollid);
625 READ_NODE_FIELD(args);
626 READ_NODE_FIELD(aggfilter);
627 READ_UINT_FIELD(winref);
628 READ_BOOL_FIELD(winstar);
629 READ_BOOL_FIELD(winagg);
630 READ_LOCATION_FIELD(location);
641 READ_LOCALS(ArrayRef);
643 READ_OID_FIELD(refarraytype);
644 READ_OID_FIELD(refelemtype);
645 READ_INT_FIELD(reftypmod);
646 READ_OID_FIELD(refcollid);
647 READ_NODE_FIELD(refupperindexpr);
648 READ_NODE_FIELD(reflowerindexpr);
649 READ_NODE_FIELD(refexpr);
650 READ_NODE_FIELD(refassgnexpr);
661 READ_LOCALS(FuncExpr);
663 READ_OID_FIELD(funcid);
664 READ_OID_FIELD(funcresulttype);
665 READ_BOOL_FIELD(funcretset);
666 READ_BOOL_FIELD(funcvariadic);
667 READ_ENUM_FIELD(funcformat, CoercionForm);
668 READ_OID_FIELD(funccollid);
669 READ_OID_FIELD(inputcollid);
670 READ_NODE_FIELD(args);
671 READ_LOCATION_FIELD(location);
679 static NamedArgExpr *
680 _readNamedArgExpr(void)
682 READ_LOCALS(NamedArgExpr);
684 READ_NODE_FIELD(arg);
685 READ_STRING_FIELD(name);
686 READ_INT_FIELD(argnumber);
687 READ_LOCATION_FIELD(location);
700 READ_OID_FIELD(opno);
701 READ_OID_FIELD(opfuncid);
702 READ_OID_FIELD(opresulttype);
703 READ_BOOL_FIELD(opretset);
704 READ_OID_FIELD(opcollid);
705 READ_OID_FIELD(inputcollid);
706 READ_NODE_FIELD(args);
707 READ_LOCATION_FIELD(location);
715 static DistinctExpr *
716 _readDistinctExpr(void)
718 READ_LOCALS(DistinctExpr);
720 READ_OID_FIELD(opno);
721 READ_OID_FIELD(opfuncid);
722 READ_OID_FIELD(opresulttype);
723 READ_BOOL_FIELD(opretset);
724 READ_OID_FIELD(opcollid);
725 READ_OID_FIELD(inputcollid);
726 READ_NODE_FIELD(args);
727 READ_LOCATION_FIELD(location);
736 _readNullIfExpr(void)
738 READ_LOCALS(NullIfExpr);
740 READ_OID_FIELD(opno);
741 READ_OID_FIELD(opfuncid);
742 READ_OID_FIELD(opresulttype);
743 READ_BOOL_FIELD(opretset);
744 READ_OID_FIELD(opcollid);
745 READ_OID_FIELD(inputcollid);
746 READ_NODE_FIELD(args);
747 READ_LOCATION_FIELD(location);
753 * _readScalarArrayOpExpr
755 static ScalarArrayOpExpr *
756 _readScalarArrayOpExpr(void)
758 READ_LOCALS(ScalarArrayOpExpr);
760 READ_OID_FIELD(opno);
761 READ_OID_FIELD(opfuncid);
762 READ_BOOL_FIELD(useOr);
763 READ_OID_FIELD(inputcollid);
764 READ_NODE_FIELD(args);
765 READ_LOCATION_FIELD(location);
776 READ_LOCALS(BoolExpr);
778 /* do-it-yourself enum representation */
779 token = pg_strtok(&length); /* skip :boolop */
780 token = pg_strtok(&length); /* get field value */
781 if (strncmp(token, "and", 3) == 0)
782 local_node->boolop = AND_EXPR;
783 else if (strncmp(token, "or", 2) == 0)
784 local_node->boolop = OR_EXPR;
785 else if (strncmp(token, "not", 3) == 0)
786 local_node->boolop = NOT_EXPR;
788 elog(ERROR, "unrecognized boolop \"%.*s\"", length, token);
790 READ_NODE_FIELD(args);
791 READ_LOCATION_FIELD(location);
802 READ_LOCALS(SubLink);
804 READ_ENUM_FIELD(subLinkType, SubLinkType);
805 READ_INT_FIELD(subLinkId);
806 READ_NODE_FIELD(testexpr);
807 READ_NODE_FIELD(operName);
808 READ_NODE_FIELD(subselect);
809 READ_LOCATION_FIELD(location);
815 * _readSubPlan is not needed since it doesn't appear in stored rules.
822 _readFieldSelect(void)
824 READ_LOCALS(FieldSelect);
826 READ_NODE_FIELD(arg);
827 READ_INT_FIELD(fieldnum);
828 READ_OID_FIELD(resulttype);
829 READ_INT_FIELD(resulttypmod);
830 READ_OID_FIELD(resultcollid);
839 _readFieldStore(void)
841 READ_LOCALS(FieldStore);
843 READ_NODE_FIELD(arg);
844 READ_NODE_FIELD(newvals);
845 READ_NODE_FIELD(fieldnums);
846 READ_OID_FIELD(resulttype);
855 _readRelabelType(void)
857 READ_LOCALS(RelabelType);
859 READ_NODE_FIELD(arg);
860 READ_OID_FIELD(resulttype);
861 READ_INT_FIELD(resulttypmod);
862 READ_OID_FIELD(resultcollid);
863 READ_ENUM_FIELD(relabelformat, CoercionForm);
864 READ_LOCATION_FIELD(location);
873 _readCoerceViaIO(void)
875 READ_LOCALS(CoerceViaIO);
877 READ_NODE_FIELD(arg);
878 READ_OID_FIELD(resulttype);
879 READ_OID_FIELD(resultcollid);
880 READ_ENUM_FIELD(coerceformat, CoercionForm);
881 READ_LOCATION_FIELD(location);
887 * _readArrayCoerceExpr
889 static ArrayCoerceExpr *
890 _readArrayCoerceExpr(void)
892 READ_LOCALS(ArrayCoerceExpr);
894 READ_NODE_FIELD(arg);
895 READ_OID_FIELD(elemfuncid);
896 READ_OID_FIELD(resulttype);
897 READ_INT_FIELD(resulttypmod);
898 READ_OID_FIELD(resultcollid);
899 READ_BOOL_FIELD(isExplicit);
900 READ_ENUM_FIELD(coerceformat, CoercionForm);
901 READ_LOCATION_FIELD(location);
907 * _readConvertRowtypeExpr
909 static ConvertRowtypeExpr *
910 _readConvertRowtypeExpr(void)
912 READ_LOCALS(ConvertRowtypeExpr);
914 READ_NODE_FIELD(arg);
915 READ_OID_FIELD(resulttype);
916 READ_ENUM_FIELD(convertformat, CoercionForm);
917 READ_LOCATION_FIELD(location);
926 _readCollateExpr(void)
928 READ_LOCALS(CollateExpr);
930 READ_NODE_FIELD(arg);
931 READ_OID_FIELD(collOid);
932 READ_LOCATION_FIELD(location);
943 READ_LOCALS(CaseExpr);
945 READ_OID_FIELD(casetype);
946 READ_OID_FIELD(casecollid);
947 READ_NODE_FIELD(arg);
948 READ_NODE_FIELD(args);
949 READ_NODE_FIELD(defresult);
950 READ_LOCATION_FIELD(location);
961 READ_LOCALS(CaseWhen);
963 READ_NODE_FIELD(expr);
964 READ_NODE_FIELD(result);
965 READ_LOCATION_FIELD(location);
973 static CaseTestExpr *
974 _readCaseTestExpr(void)
976 READ_LOCALS(CaseTestExpr);
978 READ_OID_FIELD(typeId);
979 READ_INT_FIELD(typeMod);
980 READ_OID_FIELD(collation);
991 READ_LOCALS(ArrayExpr);
993 READ_OID_FIELD(array_typeid);
994 READ_OID_FIELD(array_collid);
995 READ_OID_FIELD(element_typeid);
996 READ_NODE_FIELD(elements);
997 READ_BOOL_FIELD(multidims);
998 READ_LOCATION_FIELD(location);
1009 READ_LOCALS(RowExpr);
1011 READ_NODE_FIELD(args);
1012 READ_OID_FIELD(row_typeid);
1013 READ_ENUM_FIELD(row_format, CoercionForm);
1014 READ_NODE_FIELD(colnames);
1015 READ_LOCATION_FIELD(location);
1021 * _readRowCompareExpr
1023 static RowCompareExpr *
1024 _readRowCompareExpr(void)
1026 READ_LOCALS(RowCompareExpr);
1028 READ_ENUM_FIELD(rctype, RowCompareType);
1029 READ_NODE_FIELD(opnos);
1030 READ_NODE_FIELD(opfamilies);
1031 READ_NODE_FIELD(inputcollids);
1032 READ_NODE_FIELD(largs);
1033 READ_NODE_FIELD(rargs);
1041 static CoalesceExpr *
1042 _readCoalesceExpr(void)
1044 READ_LOCALS(CoalesceExpr);
1046 READ_OID_FIELD(coalescetype);
1047 READ_OID_FIELD(coalescecollid);
1048 READ_NODE_FIELD(args);
1049 READ_LOCATION_FIELD(location);
1058 _readMinMaxExpr(void)
1060 READ_LOCALS(MinMaxExpr);
1062 READ_OID_FIELD(minmaxtype);
1063 READ_OID_FIELD(minmaxcollid);
1064 READ_OID_FIELD(inputcollid);
1065 READ_ENUM_FIELD(op, MinMaxOp);
1066 READ_NODE_FIELD(args);
1067 READ_LOCATION_FIELD(location);
1073 * _readSQLValueFunction
1075 static SQLValueFunction *
1076 _readSQLValueFunction(void)
1078 READ_LOCALS(SQLValueFunction);
1080 READ_ENUM_FIELD(op, SQLValueFunctionOp);
1081 READ_OID_FIELD(type);
1082 READ_INT_FIELD(typmod);
1083 READ_LOCATION_FIELD(location);
1094 READ_LOCALS(XmlExpr);
1096 READ_ENUM_FIELD(op, XmlExprOp);
1097 READ_STRING_FIELD(name);
1098 READ_NODE_FIELD(named_args);
1099 READ_NODE_FIELD(arg_names);
1100 READ_NODE_FIELD(args);
1101 READ_ENUM_FIELD(xmloption, XmlOptionType);
1102 READ_OID_FIELD(type);
1103 READ_INT_FIELD(typmod);
1104 READ_LOCATION_FIELD(location);
1115 READ_LOCALS(NullTest);
1117 READ_NODE_FIELD(arg);
1118 READ_ENUM_FIELD(nulltesttype, NullTestType);
1119 READ_BOOL_FIELD(argisrow);
1120 READ_LOCATION_FIELD(location);
1128 static BooleanTest *
1129 _readBooleanTest(void)
1131 READ_LOCALS(BooleanTest);
1133 READ_NODE_FIELD(arg);
1134 READ_ENUM_FIELD(booltesttype, BoolTestType);
1135 READ_LOCATION_FIELD(location);
1141 * _readCoerceToDomain
1143 static CoerceToDomain *
1144 _readCoerceToDomain(void)
1146 READ_LOCALS(CoerceToDomain);
1148 READ_NODE_FIELD(arg);
1149 READ_OID_FIELD(resulttype);
1150 READ_INT_FIELD(resulttypmod);
1151 READ_OID_FIELD(resultcollid);
1152 READ_ENUM_FIELD(coercionformat, CoercionForm);
1153 READ_LOCATION_FIELD(location);
1159 * _readCoerceToDomainValue
1161 static CoerceToDomainValue *
1162 _readCoerceToDomainValue(void)
1164 READ_LOCALS(CoerceToDomainValue);
1166 READ_OID_FIELD(typeId);
1167 READ_INT_FIELD(typeMod);
1168 READ_OID_FIELD(collation);
1169 READ_LOCATION_FIELD(location);
1177 static SetToDefault *
1178 _readSetToDefault(void)
1180 READ_LOCALS(SetToDefault);
1182 READ_OID_FIELD(typeId);
1183 READ_INT_FIELD(typeMod);
1184 READ_OID_FIELD(collation);
1185 READ_LOCATION_FIELD(location);
1191 * _readCurrentOfExpr
1193 static CurrentOfExpr *
1194 _readCurrentOfExpr(void)
1196 READ_LOCALS(CurrentOfExpr);
1198 READ_UINT_FIELD(cvarno);
1199 READ_STRING_FIELD(cursor_name);
1200 READ_INT_FIELD(cursor_param);
1206 * _readInferenceElem
1208 static InferenceElem *
1209 _readInferenceElem(void)
1211 READ_LOCALS(InferenceElem);
1213 READ_NODE_FIELD(expr);
1214 READ_OID_FIELD(infercollid);
1215 READ_OID_FIELD(inferopclass);
1223 static TargetEntry *
1224 _readTargetEntry(void)
1226 READ_LOCALS(TargetEntry);
1228 READ_NODE_FIELD(expr);
1229 READ_INT_FIELD(resno);
1230 READ_STRING_FIELD(resname);
1231 READ_UINT_FIELD(ressortgroupref);
1232 READ_OID_FIELD(resorigtbl);
1233 READ_INT_FIELD(resorigcol);
1234 READ_BOOL_FIELD(resjunk);
1242 static RangeTblRef *
1243 _readRangeTblRef(void)
1245 READ_LOCALS(RangeTblRef);
1247 READ_INT_FIELD(rtindex);
1258 READ_LOCALS(JoinExpr);
1260 READ_ENUM_FIELD(jointype, JoinType);
1261 READ_BOOL_FIELD(isNatural);
1262 READ_NODE_FIELD(larg);
1263 READ_NODE_FIELD(rarg);
1264 READ_NODE_FIELD(usingClause);
1265 READ_NODE_FIELD(quals);
1266 READ_NODE_FIELD(alias);
1267 READ_INT_FIELD(rtindex);
1278 READ_LOCALS(FromExpr);
1280 READ_NODE_FIELD(fromlist);
1281 READ_NODE_FIELD(quals);
1287 * _readOnConflictExpr
1289 static OnConflictExpr *
1290 _readOnConflictExpr(void)
1292 READ_LOCALS(OnConflictExpr);
1294 READ_ENUM_FIELD(action, OnConflictAction);
1295 READ_NODE_FIELD(arbiterElems);
1296 READ_NODE_FIELD(arbiterWhere);
1297 READ_OID_FIELD(constraint);
1298 READ_NODE_FIELD(onConflictSet);
1299 READ_NODE_FIELD(onConflictWhere);
1300 READ_INT_FIELD(exclRelIndex);
1301 READ_NODE_FIELD(exclRelTlist);
1307 * Stuff from parsenodes.h.
1311 * _readRangeTblEntry
1313 static RangeTblEntry *
1314 _readRangeTblEntry(void)
1316 READ_LOCALS(RangeTblEntry);
1318 /* put alias + eref first to make dump more legible */
1319 READ_NODE_FIELD(alias);
1320 READ_NODE_FIELD(eref);
1321 READ_ENUM_FIELD(rtekind, RTEKind);
1323 switch (local_node->rtekind)
1326 READ_OID_FIELD(relid);
1327 READ_CHAR_FIELD(relkind);
1328 READ_NODE_FIELD(tablesample);
1331 READ_NODE_FIELD(subquery);
1332 READ_BOOL_FIELD(security_barrier);
1335 READ_ENUM_FIELD(jointype, JoinType);
1336 READ_NODE_FIELD(joinaliasvars);
1339 READ_NODE_FIELD(functions);
1340 READ_BOOL_FIELD(funcordinality);
1343 READ_NODE_FIELD(tablefunc);
1346 READ_NODE_FIELD(values_lists);
1347 READ_NODE_FIELD(coltypes);
1348 READ_NODE_FIELD(coltypmods);
1349 READ_NODE_FIELD(colcollations);
1352 READ_STRING_FIELD(ctename);
1353 READ_UINT_FIELD(ctelevelsup);
1354 READ_BOOL_FIELD(self_reference);
1355 READ_NODE_FIELD(coltypes);
1356 READ_NODE_FIELD(coltypmods);
1357 READ_NODE_FIELD(colcollations);
1359 case RTE_NAMEDTUPLESTORE:
1360 READ_STRING_FIELD(enrname);
1361 READ_OID_FIELD(relid);
1362 READ_NODE_FIELD(coltypes);
1363 READ_NODE_FIELD(coltypmods);
1364 READ_NODE_FIELD(colcollations);
1367 elog(ERROR, "unrecognized RTE kind: %d",
1368 (int) local_node->rtekind);
1372 READ_BOOL_FIELD(lateral);
1373 READ_BOOL_FIELD(inh);
1374 READ_BOOL_FIELD(inFromCl);
1375 READ_UINT_FIELD(requiredPerms);
1376 READ_OID_FIELD(checkAsUser);
1377 READ_BITMAPSET_FIELD(selectedCols);
1378 READ_BITMAPSET_FIELD(insertedCols);
1379 READ_BITMAPSET_FIELD(updatedCols);
1380 READ_NODE_FIELD(securityQuals);
1386 * _readRangeTblFunction
1388 static RangeTblFunction *
1389 _readRangeTblFunction(void)
1391 READ_LOCALS(RangeTblFunction);
1393 READ_NODE_FIELD(funcexpr);
1394 READ_INT_FIELD(funccolcount);
1395 READ_NODE_FIELD(funccolnames);
1396 READ_NODE_FIELD(funccoltypes);
1397 READ_NODE_FIELD(funccoltypmods);
1398 READ_NODE_FIELD(funccolcollations);
1399 READ_BITMAPSET_FIELD(funcparams);
1405 * _readTableSampleClause
1407 static TableSampleClause *
1408 _readTableSampleClause(void)
1410 READ_LOCALS(TableSampleClause);
1412 READ_OID_FIELD(tsmhandler);
1413 READ_NODE_FIELD(args);
1414 READ_NODE_FIELD(repeatable);
1425 READ_LOCALS(DefElem);
1427 READ_STRING_FIELD(defnamespace);
1428 READ_STRING_FIELD(defname);
1429 READ_NODE_FIELD(arg);
1430 READ_ENUM_FIELD(defaction, DefElemAction);
1431 READ_LOCATION_FIELD(location);
1439 static PlannedStmt *
1440 _readPlannedStmt(void)
1442 READ_LOCALS(PlannedStmt);
1444 READ_ENUM_FIELD(commandType, CmdType);
1445 READ_UINT_FIELD(queryId);
1446 READ_BOOL_FIELD(hasReturning);
1447 READ_BOOL_FIELD(hasModifyingCTE);
1448 READ_BOOL_FIELD(canSetTag);
1449 READ_BOOL_FIELD(transientPlan);
1450 READ_BOOL_FIELD(dependsOnRole);
1451 READ_BOOL_FIELD(parallelModeNeeded);
1452 READ_NODE_FIELD(planTree);
1453 READ_NODE_FIELD(rtable);
1454 READ_NODE_FIELD(resultRelations);
1455 READ_NODE_FIELD(nonleafResultRelations);
1456 READ_NODE_FIELD(subplans);
1457 READ_BITMAPSET_FIELD(rewindPlanIDs);
1458 READ_NODE_FIELD(rowMarks);
1459 READ_NODE_FIELD(relationOids);
1460 READ_NODE_FIELD(invalItems);
1461 READ_INT_FIELD(nParamExec);
1462 READ_NODE_FIELD(utilityStmt);
1463 READ_LOCATION_FIELD(stmt_location);
1464 READ_LOCATION_FIELD(stmt_len);
1471 * Assign the basic stuff of all nodes that inherit from Plan
1474 ReadCommonPlan(Plan *local_node)
1478 READ_FLOAT_FIELD(startup_cost);
1479 READ_FLOAT_FIELD(total_cost);
1480 READ_FLOAT_FIELD(plan_rows);
1481 READ_INT_FIELD(plan_width);
1482 READ_BOOL_FIELD(parallel_aware);
1483 READ_INT_FIELD(plan_node_id);
1484 READ_NODE_FIELD(targetlist);
1485 READ_NODE_FIELD(qual);
1486 READ_NODE_FIELD(lefttree);
1487 READ_NODE_FIELD(righttree);
1488 READ_NODE_FIELD(initPlan);
1489 READ_BITMAPSET_FIELD(extParam);
1490 READ_BITMAPSET_FIELD(allParam);
1499 READ_LOCALS_NO_FIELDS(Plan);
1501 ReadCommonPlan(local_node);
1512 READ_LOCALS(Result);
1514 ReadCommonPlan(&local_node->plan);
1516 READ_NODE_FIELD(resconstantqual);
1525 _readProjectSet(void)
1527 READ_LOCALS_NO_FIELDS(ProjectSet);
1529 ReadCommonPlan(&local_node->plan);
1537 static ModifyTable *
1538 _readModifyTable(void)
1540 READ_LOCALS(ModifyTable);
1542 ReadCommonPlan(&local_node->plan);
1544 READ_ENUM_FIELD(operation, CmdType);
1545 READ_BOOL_FIELD(canSetTag);
1546 READ_UINT_FIELD(nominalRelation);
1547 READ_NODE_FIELD(partitioned_rels);
1548 READ_NODE_FIELD(resultRelations);
1549 READ_INT_FIELD(resultRelIndex);
1550 READ_NODE_FIELD(plans);
1551 READ_NODE_FIELD(withCheckOptionLists);
1552 READ_NODE_FIELD(returningLists);
1553 READ_NODE_FIELD(fdwPrivLists);
1554 READ_BITMAPSET_FIELD(fdwDirectModifyPlans);
1555 READ_NODE_FIELD(rowMarks);
1556 READ_INT_FIELD(epqParam);
1557 READ_ENUM_FIELD(onConflictAction, OnConflictAction);
1558 READ_NODE_FIELD(arbiterIndexes);
1559 READ_NODE_FIELD(onConflictSet);
1560 READ_NODE_FIELD(onConflictWhere);
1561 READ_UINT_FIELD(exclRelRTI);
1562 READ_NODE_FIELD(exclRelTlist);
1573 READ_LOCALS(Append);
1575 ReadCommonPlan(&local_node->plan);
1577 READ_NODE_FIELD(partitioned_rels);
1578 READ_NODE_FIELD(appendplans);
1586 static MergeAppend *
1587 _readMergeAppend(void)
1589 READ_LOCALS(MergeAppend);
1591 ReadCommonPlan(&local_node->plan);
1593 READ_NODE_FIELD(partitioned_rels);
1594 READ_NODE_FIELD(mergeplans);
1595 READ_INT_FIELD(numCols);
1596 READ_ATTRNUMBER_ARRAY(sortColIdx, local_node->numCols);
1597 READ_OID_ARRAY(sortOperators, local_node->numCols);
1598 READ_OID_ARRAY(collations, local_node->numCols);
1599 READ_BOOL_ARRAY(nullsFirst, local_node->numCols);
1605 * _readRecursiveUnion
1607 static RecursiveUnion *
1608 _readRecursiveUnion(void)
1610 READ_LOCALS(RecursiveUnion);
1612 ReadCommonPlan(&local_node->plan);
1614 READ_INT_FIELD(wtParam);
1615 READ_INT_FIELD(numCols);
1616 READ_ATTRNUMBER_ARRAY(dupColIdx, local_node->numCols);
1617 READ_OID_ARRAY(dupOperators, local_node->numCols);
1618 READ_LONG_FIELD(numGroups);
1627 _readBitmapAnd(void)
1629 READ_LOCALS(BitmapAnd);
1631 ReadCommonPlan(&local_node->plan);
1633 READ_NODE_FIELD(bitmapplans);
1644 READ_LOCALS(BitmapOr);
1646 ReadCommonPlan(&local_node->plan);
1648 READ_BOOL_FIELD(isshared);
1649 READ_NODE_FIELD(bitmapplans);
1656 * Assign the basic stuff of all nodes that inherit from Scan
1659 ReadCommonScan(Scan *local_node)
1663 ReadCommonPlan(&local_node->plan);
1665 READ_UINT_FIELD(scanrelid);
1674 READ_LOCALS_NO_FIELDS(Scan);
1676 ReadCommonScan(local_node);
1687 READ_LOCALS_NO_FIELDS(SeqScan);
1689 ReadCommonScan(local_node);
1698 _readSampleScan(void)
1700 READ_LOCALS(SampleScan);
1702 ReadCommonScan(&local_node->scan);
1704 READ_NODE_FIELD(tablesample);
1713 _readIndexScan(void)
1715 READ_LOCALS(IndexScan);
1717 ReadCommonScan(&local_node->scan);
1719 READ_OID_FIELD(indexid);
1720 READ_NODE_FIELD(indexqual);
1721 READ_NODE_FIELD(indexqualorig);
1722 READ_NODE_FIELD(indexorderby);
1723 READ_NODE_FIELD(indexorderbyorig);
1724 READ_NODE_FIELD(indexorderbyops);
1725 READ_ENUM_FIELD(indexorderdir, ScanDirection);
1731 * _readIndexOnlyScan
1733 static IndexOnlyScan *
1734 _readIndexOnlyScan(void)
1736 READ_LOCALS(IndexOnlyScan);
1738 ReadCommonScan(&local_node->scan);
1740 READ_OID_FIELD(indexid);
1741 READ_NODE_FIELD(indexqual);
1742 READ_NODE_FIELD(indexorderby);
1743 READ_NODE_FIELD(indextlist);
1744 READ_ENUM_FIELD(indexorderdir, ScanDirection);
1750 * _readBitmapIndexScan
1752 static BitmapIndexScan *
1753 _readBitmapIndexScan(void)
1755 READ_LOCALS(BitmapIndexScan);
1757 ReadCommonScan(&local_node->scan);
1759 READ_OID_FIELD(indexid);
1760 READ_BOOL_FIELD(isshared);
1761 READ_NODE_FIELD(indexqual);
1762 READ_NODE_FIELD(indexqualorig);
1768 * _readBitmapHeapScan
1770 static BitmapHeapScan *
1771 _readBitmapHeapScan(void)
1773 READ_LOCALS(BitmapHeapScan);
1775 ReadCommonScan(&local_node->scan);
1777 READ_NODE_FIELD(bitmapqualorig);
1788 READ_LOCALS(TidScan);
1790 ReadCommonScan(&local_node->scan);
1792 READ_NODE_FIELD(tidquals);
1800 static SubqueryScan *
1801 _readSubqueryScan(void)
1803 READ_LOCALS(SubqueryScan);
1805 ReadCommonScan(&local_node->scan);
1807 READ_NODE_FIELD(subplan);
1815 static FunctionScan *
1816 _readFunctionScan(void)
1818 READ_LOCALS(FunctionScan);
1820 ReadCommonScan(&local_node->scan);
1822 READ_NODE_FIELD(functions);
1823 READ_BOOL_FIELD(funcordinality);
1832 _readValuesScan(void)
1834 READ_LOCALS(ValuesScan);
1836 ReadCommonScan(&local_node->scan);
1838 READ_NODE_FIELD(values_lists);
1844 * _readTableFuncScan
1846 static TableFuncScan *
1847 _readTableFuncScan(void)
1849 READ_LOCALS(TableFuncScan);
1851 ReadCommonScan(&local_node->scan);
1853 READ_NODE_FIELD(tablefunc);
1864 READ_LOCALS(CteScan);
1866 ReadCommonScan(&local_node->scan);
1868 READ_INT_FIELD(ctePlanId);
1869 READ_INT_FIELD(cteParam);
1875 * _readWorkTableScan
1877 static WorkTableScan *
1878 _readWorkTableScan(void)
1880 READ_LOCALS(WorkTableScan);
1882 ReadCommonScan(&local_node->scan);
1884 READ_INT_FIELD(wtParam);
1892 static ForeignScan *
1893 _readForeignScan(void)
1895 READ_LOCALS(ForeignScan);
1897 ReadCommonScan(&local_node->scan);
1899 READ_ENUM_FIELD(operation, CmdType);
1900 READ_OID_FIELD(fs_server);
1901 READ_NODE_FIELD(fdw_exprs);
1902 READ_NODE_FIELD(fdw_private);
1903 READ_NODE_FIELD(fdw_scan_tlist);
1904 READ_NODE_FIELD(fdw_recheck_quals);
1905 READ_BITMAPSET_FIELD(fs_relids);
1906 READ_BOOL_FIELD(fsSystemCol);
1915 _readCustomScan(void)
1917 READ_LOCALS(CustomScan);
1919 const CustomScanMethods *methods;
1921 ReadCommonScan(&local_node->scan);
1923 READ_UINT_FIELD(flags);
1924 READ_NODE_FIELD(custom_plans);
1925 READ_NODE_FIELD(custom_exprs);
1926 READ_NODE_FIELD(custom_private);
1927 READ_NODE_FIELD(custom_scan_tlist);
1928 READ_BITMAPSET_FIELD(custom_relids);
1930 /* Lookup CustomScanMethods by CustomName */
1931 token = pg_strtok(&length); /* skip methods: */
1932 token = pg_strtok(&length); /* CustomName */
1933 custom_name = nullable_string(token, length);
1934 methods = GetCustomScanMethods(custom_name, false);
1935 local_node->methods = methods;
1942 * Assign the basic stuff of all nodes that inherit from Join
1945 ReadCommonJoin(Join *local_node)
1949 ReadCommonPlan(&local_node->plan);
1951 READ_ENUM_FIELD(jointype, JoinType);
1952 READ_BOOL_FIELD(inner_unique);
1953 READ_NODE_FIELD(joinqual);
1962 READ_LOCALS_NO_FIELDS(Join);
1964 ReadCommonJoin(local_node);
1975 READ_LOCALS(NestLoop);
1977 ReadCommonJoin(&local_node->join);
1979 READ_NODE_FIELD(nestParams);
1988 _readMergeJoin(void)
1992 READ_LOCALS(MergeJoin);
1994 ReadCommonJoin(&local_node->join);
1996 READ_BOOL_FIELD(skip_mark_restore);
1997 READ_NODE_FIELD(mergeclauses);
1999 numCols = list_length(local_node->mergeclauses);
2001 READ_OID_ARRAY(mergeFamilies, numCols);
2002 READ_OID_ARRAY(mergeCollations, numCols);
2003 READ_INT_ARRAY(mergeStrategies, numCols);
2004 READ_BOOL_ARRAY(mergeNullsFirst, numCols);
2015 READ_LOCALS(HashJoin);
2017 ReadCommonJoin(&local_node->join);
2019 READ_NODE_FIELD(hashclauses);
2030 READ_LOCALS_NO_FIELDS(Material);
2032 ReadCommonPlan(&local_node->plan);
2045 ReadCommonPlan(&local_node->plan);
2047 READ_INT_FIELD(numCols);
2048 READ_ATTRNUMBER_ARRAY(sortColIdx, local_node->numCols);
2049 READ_OID_ARRAY(sortOperators, local_node->numCols);
2050 READ_OID_ARRAY(collations, local_node->numCols);
2051 READ_BOOL_ARRAY(nullsFirst, local_node->numCols);
2064 ReadCommonPlan(&local_node->plan);
2066 READ_INT_FIELD(numCols);
2067 READ_ATTRNUMBER_ARRAY(grpColIdx, local_node->numCols);
2068 READ_OID_ARRAY(grpOperators, local_node->numCols);
2081 ReadCommonPlan(&local_node->plan);
2083 READ_ENUM_FIELD(aggstrategy, AggStrategy);
2084 READ_ENUM_FIELD(aggsplit, AggSplit);
2085 READ_INT_FIELD(numCols);
2086 READ_ATTRNUMBER_ARRAY(grpColIdx, local_node->numCols);
2087 READ_OID_ARRAY(grpOperators, local_node->numCols);
2088 READ_LONG_FIELD(numGroups);
2089 READ_BITMAPSET_FIELD(aggParams);
2090 READ_NODE_FIELD(groupingSets);
2091 READ_NODE_FIELD(chain);
2100 _readWindowAgg(void)
2102 READ_LOCALS(WindowAgg);
2104 ReadCommonPlan(&local_node->plan);
2106 READ_UINT_FIELD(winref);
2107 READ_INT_FIELD(partNumCols);
2108 READ_ATTRNUMBER_ARRAY(partColIdx, local_node->partNumCols);
2109 READ_OID_ARRAY(partOperators, local_node->partNumCols);
2110 READ_INT_FIELD(ordNumCols);
2111 READ_ATTRNUMBER_ARRAY(ordColIdx, local_node->ordNumCols);
2112 READ_OID_ARRAY(ordOperators, local_node->ordNumCols);
2113 READ_INT_FIELD(frameOptions);
2114 READ_NODE_FIELD(startOffset);
2115 READ_NODE_FIELD(endOffset);
2126 READ_LOCALS(Unique);
2128 ReadCommonPlan(&local_node->plan);
2130 READ_INT_FIELD(numCols);
2131 READ_ATTRNUMBER_ARRAY(uniqColIdx, local_node->numCols);
2132 READ_OID_ARRAY(uniqOperators, local_node->numCols);
2143 READ_LOCALS(Gather);
2145 ReadCommonPlan(&local_node->plan);
2147 READ_INT_FIELD(num_workers);
2148 READ_BOOL_FIELD(single_copy);
2149 READ_BOOL_FIELD(invisible);
2157 static GatherMerge *
2158 _readGatherMerge(void)
2160 READ_LOCALS(GatherMerge);
2162 ReadCommonPlan(&local_node->plan);
2164 READ_INT_FIELD(num_workers);
2165 READ_INT_FIELD(numCols);
2166 READ_ATTRNUMBER_ARRAY(sortColIdx, local_node->numCols);
2167 READ_OID_ARRAY(sortOperators, local_node->numCols);
2168 READ_OID_ARRAY(collations, local_node->numCols);
2169 READ_BOOL_ARRAY(nullsFirst, local_node->numCols);
2182 ReadCommonPlan(&local_node->plan);
2184 READ_OID_FIELD(skewTable);
2185 READ_INT_FIELD(skewColumn);
2186 READ_BOOL_FIELD(skewInherit);
2187 READ_OID_FIELD(skewColType);
2188 READ_INT_FIELD(skewColTypmod);
2201 ReadCommonPlan(&local_node->plan);
2203 READ_ENUM_FIELD(cmd, SetOpCmd);
2204 READ_ENUM_FIELD(strategy, SetOpStrategy);
2205 READ_INT_FIELD(numCols);
2206 READ_ATTRNUMBER_ARRAY(dupColIdx, local_node->numCols);
2207 READ_OID_ARRAY(dupOperators, local_node->numCols);
2208 READ_INT_FIELD(flagColIdx);
2209 READ_INT_FIELD(firstFlag);
2210 READ_LONG_FIELD(numGroups);
2221 READ_LOCALS(LockRows);
2223 ReadCommonPlan(&local_node->plan);
2225 READ_NODE_FIELD(rowMarks);
2226 READ_INT_FIELD(epqParam);
2239 ReadCommonPlan(&local_node->plan);
2241 READ_NODE_FIELD(limitOffset);
2242 READ_NODE_FIELD(limitCount);
2248 * _readNestLoopParam
2250 static NestLoopParam *
2251 _readNestLoopParam(void)
2253 READ_LOCALS(NestLoopParam);
2255 READ_INT_FIELD(paramno);
2256 READ_NODE_FIELD(paramval);
2264 static PlanRowMark *
2265 _readPlanRowMark(void)
2267 READ_LOCALS(PlanRowMark);
2269 READ_UINT_FIELD(rti);
2270 READ_UINT_FIELD(prti);
2271 READ_UINT_FIELD(rowmarkId);
2272 READ_ENUM_FIELD(markType, RowMarkType);
2273 READ_INT_FIELD(allMarkTypes);
2274 READ_ENUM_FIELD(strength, LockClauseStrength);
2275 READ_ENUM_FIELD(waitPolicy, LockWaitPolicy);
2276 READ_BOOL_FIELD(isParent);
2282 * _readPlanInvalItem
2284 static PlanInvalItem *
2285 _readPlanInvalItem(void)
2287 READ_LOCALS(PlanInvalItem);
2289 READ_INT_FIELD(cacheId);
2290 READ_UINT_FIELD(hashValue);
2301 READ_LOCALS(SubPlan);
2303 READ_ENUM_FIELD(subLinkType, SubLinkType);
2304 READ_NODE_FIELD(testexpr);
2305 READ_NODE_FIELD(paramIds);
2306 READ_INT_FIELD(plan_id);
2307 READ_STRING_FIELD(plan_name);
2308 READ_OID_FIELD(firstColType);
2309 READ_INT_FIELD(firstColTypmod);
2310 READ_OID_FIELD(firstColCollation);
2311 READ_BOOL_FIELD(useHashTable);
2312 READ_BOOL_FIELD(unknownEqFalse);
2313 READ_BOOL_FIELD(parallel_safe);
2314 READ_NODE_FIELD(setParam);
2315 READ_NODE_FIELD(parParam);
2316 READ_NODE_FIELD(args);
2317 READ_FLOAT_FIELD(startup_cost);
2318 READ_FLOAT_FIELD(per_call_cost);
2324 * _readAlternativeSubPlan
2326 static AlternativeSubPlan *
2327 _readAlternativeSubPlan(void)
2329 READ_LOCALS(AlternativeSubPlan);
2331 READ_NODE_FIELD(subplans);
2337 * _readExtensibleNode
2339 static ExtensibleNode *
2340 _readExtensibleNode(void)
2342 const ExtensibleNodeMethods *methods;
2343 ExtensibleNode *local_node;
2344 const char *extnodename;
2348 token = pg_strtok(&length); /* skip :extnodename */
2349 token = pg_strtok(&length); /* get extnodename */
2351 extnodename = nullable_string(token, length);
2353 elog(ERROR, "extnodename has to be supplied");
2354 methods = GetExtensibleNodeMethods(extnodename, false);
2356 local_node = (ExtensibleNode *) newNode(methods->node_size,
2358 local_node->extnodename = extnodename;
2360 /* deserialize the private fields */
2361 methods->nodeRead(local_node);
2367 * _readPartitionBoundSpec
2369 static PartitionBoundSpec *
2370 _readPartitionBoundSpec(void)
2372 READ_LOCALS(PartitionBoundSpec);
2374 READ_CHAR_FIELD(strategy);
2375 READ_NODE_FIELD(listdatums);
2376 READ_NODE_FIELD(lowerdatums);
2377 READ_NODE_FIELD(upperdatums);
2383 * _readPartitionRangeDatum
2385 static PartitionRangeDatum *
2386 _readPartitionRangeDatum(void)
2388 READ_LOCALS(PartitionRangeDatum);
2390 READ_BOOL_FIELD(infinite);
2391 READ_NODE_FIELD(value);
2399 * Given a character string representing a node tree, parseNodeString creates
2400 * the internal node structure.
2402 * The string to be read must already have been loaded into pg_strtok().
2405 parseNodeString(void)
2411 token = pg_strtok(&length);
2413 #define MATCH(tokname, namelen) \
2414 (length == namelen && memcmp(token, tokname, namelen) == 0)
2416 if (MATCH("QUERY", 5))
2417 return_value = _readQuery();
2418 else if (MATCH("WITHCHECKOPTION", 15))
2419 return_value = _readWithCheckOption();
2420 else if (MATCH("SORTGROUPCLAUSE", 15))
2421 return_value = _readSortGroupClause();
2422 else if (MATCH("GROUPINGSET", 11))
2423 return_value = _readGroupingSet();
2424 else if (MATCH("WINDOWCLAUSE", 12))
2425 return_value = _readWindowClause();
2426 else if (MATCH("ROWMARKCLAUSE", 13))
2427 return_value = _readRowMarkClause();
2428 else if (MATCH("COMMONTABLEEXPR", 15))
2429 return_value = _readCommonTableExpr();
2430 else if (MATCH("SETOPERATIONSTMT", 16))
2431 return_value = _readSetOperationStmt();
2432 else if (MATCH("ALIAS", 5))
2433 return_value = _readAlias();
2434 else if (MATCH("RANGEVAR", 8))
2435 return_value = _readRangeVar();
2436 else if (MATCH("INTOCLAUSE", 10))
2437 return_value = _readIntoClause();
2438 else if (MATCH("TABLEFUNC", 9))
2439 return_value = _readTableFunc();
2440 else if (MATCH("VAR", 3))
2441 return_value = _readVar();
2442 else if (MATCH("CONST", 5))
2443 return_value = _readConst();
2444 else if (MATCH("PARAM", 5))
2445 return_value = _readParam();
2446 else if (MATCH("AGGREF", 6))
2447 return_value = _readAggref();
2448 else if (MATCH("GROUPINGFUNC", 12))
2449 return_value = _readGroupingFunc();
2450 else if (MATCH("WINDOWFUNC", 10))
2451 return_value = _readWindowFunc();
2452 else if (MATCH("ARRAYREF", 8))
2453 return_value = _readArrayRef();
2454 else if (MATCH("FUNCEXPR", 8))
2455 return_value = _readFuncExpr();
2456 else if (MATCH("NAMEDARGEXPR", 12))
2457 return_value = _readNamedArgExpr();
2458 else if (MATCH("OPEXPR", 6))
2459 return_value = _readOpExpr();
2460 else if (MATCH("DISTINCTEXPR", 12))
2461 return_value = _readDistinctExpr();
2462 else if (MATCH("NULLIFEXPR", 10))
2463 return_value = _readNullIfExpr();
2464 else if (MATCH("SCALARARRAYOPEXPR", 17))
2465 return_value = _readScalarArrayOpExpr();
2466 else if (MATCH("BOOLEXPR", 8))
2467 return_value = _readBoolExpr();
2468 else if (MATCH("SUBLINK", 7))
2469 return_value = _readSubLink();
2470 else if (MATCH("FIELDSELECT", 11))
2471 return_value = _readFieldSelect();
2472 else if (MATCH("FIELDSTORE", 10))
2473 return_value = _readFieldStore();
2474 else if (MATCH("RELABELTYPE", 11))
2475 return_value = _readRelabelType();
2476 else if (MATCH("COERCEVIAIO", 11))
2477 return_value = _readCoerceViaIO();
2478 else if (MATCH("ARRAYCOERCEEXPR", 15))
2479 return_value = _readArrayCoerceExpr();
2480 else if (MATCH("CONVERTROWTYPEEXPR", 18))
2481 return_value = _readConvertRowtypeExpr();
2482 else if (MATCH("COLLATE", 7))
2483 return_value = _readCollateExpr();
2484 else if (MATCH("CASE", 4))
2485 return_value = _readCaseExpr();
2486 else if (MATCH("WHEN", 4))
2487 return_value = _readCaseWhen();
2488 else if (MATCH("CASETESTEXPR", 12))
2489 return_value = _readCaseTestExpr();
2490 else if (MATCH("ARRAY", 5))
2491 return_value = _readArrayExpr();
2492 else if (MATCH("ROW", 3))
2493 return_value = _readRowExpr();
2494 else if (MATCH("ROWCOMPARE", 10))
2495 return_value = _readRowCompareExpr();
2496 else if (MATCH("COALESCE", 8))
2497 return_value = _readCoalesceExpr();
2498 else if (MATCH("MINMAX", 6))
2499 return_value = _readMinMaxExpr();
2500 else if (MATCH("SQLVALUEFUNCTION", 16))
2501 return_value = _readSQLValueFunction();
2502 else if (MATCH("XMLEXPR", 7))
2503 return_value = _readXmlExpr();
2504 else if (MATCH("NULLTEST", 8))
2505 return_value = _readNullTest();
2506 else if (MATCH("BOOLEANTEST", 11))
2507 return_value = _readBooleanTest();
2508 else if (MATCH("COERCETODOMAIN", 14))
2509 return_value = _readCoerceToDomain();
2510 else if (MATCH("COERCETODOMAINVALUE", 19))
2511 return_value = _readCoerceToDomainValue();
2512 else if (MATCH("SETTODEFAULT", 12))
2513 return_value = _readSetToDefault();
2514 else if (MATCH("CURRENTOFEXPR", 13))
2515 return_value = _readCurrentOfExpr();
2516 else if (MATCH("INFERENCEELEM", 13))
2517 return_value = _readInferenceElem();
2518 else if (MATCH("TARGETENTRY", 11))
2519 return_value = _readTargetEntry();
2520 else if (MATCH("RANGETBLREF", 11))
2521 return_value = _readRangeTblRef();
2522 else if (MATCH("JOINEXPR", 8))
2523 return_value = _readJoinExpr();
2524 else if (MATCH("FROMEXPR", 8))
2525 return_value = _readFromExpr();
2526 else if (MATCH("ONCONFLICTEXPR", 14))
2527 return_value = _readOnConflictExpr();
2528 else if (MATCH("RTE", 3))
2529 return_value = _readRangeTblEntry();
2530 else if (MATCH("RANGETBLFUNCTION", 16))
2531 return_value = _readRangeTblFunction();
2532 else if (MATCH("TABLESAMPLECLAUSE", 17))
2533 return_value = _readTableSampleClause();
2534 else if (MATCH("NOTIFY", 6))
2535 return_value = _readNotifyStmt();
2536 else if (MATCH("DEFELEM", 7))
2537 return_value = _readDefElem();
2538 else if (MATCH("DECLARECURSOR", 13))
2539 return_value = _readDeclareCursorStmt();
2540 else if (MATCH("PLANNEDSTMT", 11))
2541 return_value = _readPlannedStmt();
2542 else if (MATCH("PLAN", 4))
2543 return_value = _readPlan();
2544 else if (MATCH("RESULT", 6))
2545 return_value = _readResult();
2546 else if (MATCH("PROJECTSET", 10))
2547 return_value = _readProjectSet();
2548 else if (MATCH("MODIFYTABLE", 11))
2549 return_value = _readModifyTable();
2550 else if (MATCH("APPEND", 6))
2551 return_value = _readAppend();
2552 else if (MATCH("MERGEAPPEND", 11))
2553 return_value = _readMergeAppend();
2554 else if (MATCH("RECURSIVEUNION", 14))
2555 return_value = _readRecursiveUnion();
2556 else if (MATCH("BITMAPAND", 9))
2557 return_value = _readBitmapAnd();
2558 else if (MATCH("BITMAPOR", 8))
2559 return_value = _readBitmapOr();
2560 else if (MATCH("SCAN", 4))
2561 return_value = _readScan();
2562 else if (MATCH("SEQSCAN", 7))
2563 return_value = _readSeqScan();
2564 else if (MATCH("SAMPLESCAN", 10))
2565 return_value = _readSampleScan();
2566 else if (MATCH("INDEXSCAN", 9))
2567 return_value = _readIndexScan();
2568 else if (MATCH("INDEXONLYSCAN", 13))
2569 return_value = _readIndexOnlyScan();
2570 else if (MATCH("BITMAPINDEXSCAN", 15))
2571 return_value = _readBitmapIndexScan();
2572 else if (MATCH("BITMAPHEAPSCAN", 14))
2573 return_value = _readBitmapHeapScan();
2574 else if (MATCH("TIDSCAN", 7))
2575 return_value = _readTidScan();
2576 else if (MATCH("SUBQUERYSCAN", 12))
2577 return_value = _readSubqueryScan();
2578 else if (MATCH("FUNCTIONSCAN", 12))
2579 return_value = _readFunctionScan();
2580 else if (MATCH("VALUESSCAN", 10))
2581 return_value = _readValuesScan();
2582 else if (MATCH("TABLEFUNCSCAN", 13))
2583 return_value = _readTableFuncScan();
2584 else if (MATCH("CTESCAN", 7))
2585 return_value = _readCteScan();
2586 else if (MATCH("WORKTABLESCAN", 13))
2587 return_value = _readWorkTableScan();
2588 else if (MATCH("FOREIGNSCAN", 11))
2589 return_value = _readForeignScan();
2590 else if (MATCH("CUSTOMSCAN", 10))
2591 return_value = _readCustomScan();
2592 else if (MATCH("JOIN", 4))
2593 return_value = _readJoin();
2594 else if (MATCH("NESTLOOP", 8))
2595 return_value = _readNestLoop();
2596 else if (MATCH("MERGEJOIN", 9))
2597 return_value = _readMergeJoin();
2598 else if (MATCH("HASHJOIN", 8))
2599 return_value = _readHashJoin();
2600 else if (MATCH("MATERIAL", 8))
2601 return_value = _readMaterial();
2602 else if (MATCH("SORT", 4))
2603 return_value = _readSort();
2604 else if (MATCH("GROUP", 5))
2605 return_value = _readGroup();
2606 else if (MATCH("AGG", 3))
2607 return_value = _readAgg();
2608 else if (MATCH("WINDOWAGG", 9))
2609 return_value = _readWindowAgg();
2610 else if (MATCH("UNIQUE", 6))
2611 return_value = _readUnique();
2612 else if (MATCH("GATHER", 6))
2613 return_value = _readGather();
2614 else if (MATCH("GATHERMERGE", 11))
2615 return_value = _readGatherMerge();
2616 else if (MATCH("HASH", 4))
2617 return_value = _readHash();
2618 else if (MATCH("SETOP", 5))
2619 return_value = _readSetOp();
2620 else if (MATCH("LOCKROWS", 8))
2621 return_value = _readLockRows();
2622 else if (MATCH("LIMIT", 5))
2623 return_value = _readLimit();
2624 else if (MATCH("NESTLOOPPARAM", 13))
2625 return_value = _readNestLoopParam();
2626 else if (MATCH("PLANROWMARK", 11))
2627 return_value = _readPlanRowMark();
2628 else if (MATCH("PLANINVALITEM", 13))
2629 return_value = _readPlanInvalItem();
2630 else if (MATCH("SUBPLAN", 7))
2631 return_value = _readSubPlan();
2632 else if (MATCH("ALTERNATIVESUBPLAN", 18))
2633 return_value = _readAlternativeSubPlan();
2634 else if (MATCH("EXTENSIBLENODE", 14))
2635 return_value = _readExtensibleNode();
2636 else if (MATCH("PARTITIONBOUND", 14))
2637 return_value = _readPartitionBoundSpec();
2638 else if (MATCH("PARTRANGEDATUM", 14))
2639 return_value = _readPartitionRangeDatum();
2642 elog(ERROR, "badly formatted node string \"%.32s\"...", token);
2643 return_value = NULL; /* keep compiler quiet */
2646 return (Node *) return_value;
2653 * Given a string representation of a constant, recreate the appropriate
2654 * Datum. The string representation embeds length info, but not byValue,
2655 * so we must be told that.
2658 readDatum(bool typbyval)
2668 * read the actual length of the value
2670 token = pg_strtok(&tokenLength);
2671 length = atoui(token);
2673 token = pg_strtok(&tokenLength); /* read the '[' */
2674 if (token == NULL || token[0] != '[')
2675 elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %zu",
2676 token ? (const char *) token : "[NULL]", length);
2680 if (length > (Size) sizeof(Datum))
2681 elog(ERROR, "byval datum but length = %zu", length);
2683 s = (char *) (&res);
2684 for (i = 0; i < (Size) sizeof(Datum); i++)
2686 token = pg_strtok(&tokenLength);
2687 s[i] = (char) atoi(token);
2690 else if (length <= 0)
2694 s = (char *) palloc(length);
2695 for (i = 0; i < length; i++)
2697 token = pg_strtok(&tokenLength);
2698 s[i] = (char) atoi(token);
2700 res = PointerGetDatum(s);
2703 token = pg_strtok(&tokenLength); /* read the ']' */
2704 if (token == NULL || token[0] != ']')
2705 elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %zu",
2706 token ? (const char *) token : "[NULL]", length);
2712 * readAttrNumberCols
2715 readAttrNumberCols(int numCols)
2720 AttrNumber *attr_vals;
2725 attr_vals = (AttrNumber *) palloc(numCols * sizeof(AttrNumber));
2726 for (i = 0; i < numCols; i++)
2728 token = pg_strtok(&tokenLength);
2729 attr_vals[i] = atoi(token);
2739 readOidCols(int numCols)
2749 oid_vals = (Oid *) palloc(numCols * sizeof(Oid));
2750 for (i = 0; i < numCols; i++)
2752 token = pg_strtok(&tokenLength);
2753 oid_vals[i] = atooid(token);
2763 readIntCols(int numCols)
2773 int_vals = (int *) palloc(numCols * sizeof(int));
2774 for (i = 0; i < numCols; i++)
2776 token = pg_strtok(&tokenLength);
2777 int_vals[i] = atoi(token);
2787 readBoolCols(int numCols)
2797 bool_vals = (bool *) palloc(numCols * sizeof(bool));
2798 for (i = 0; i < numCols; i++)
2800 token = pg_strtok(&tokenLength);
2801 bool_vals[i] = strtobool(token);