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 /* avoid overhead of calling debackslash() for one char */ \
90 local_node->fldname = (length == 0) ? '\0' : (token[0] == '\\' ? token[1] : token[0])
92 /* Read an enumerated-type field that was written as an integer code */
93 #define READ_ENUM_FIELD(fldname, enumtype) \
94 token = pg_strtok(&length); /* skip :fldname */ \
95 token = pg_strtok(&length); /* get field value */ \
96 local_node->fldname = (enumtype) atoi(token)
98 /* Read a float field */
99 #define READ_FLOAT_FIELD(fldname) \
100 token = pg_strtok(&length); /* skip :fldname */ \
101 token = pg_strtok(&length); /* get field value */ \
102 local_node->fldname = atof(token)
104 /* Read a boolean field */
105 #define READ_BOOL_FIELD(fldname) \
106 token = pg_strtok(&length); /* skip :fldname */ \
107 token = pg_strtok(&length); /* get field value */ \
108 local_node->fldname = strtobool(token)
110 /* Read a character-string field */
111 #define READ_STRING_FIELD(fldname) \
112 token = pg_strtok(&length); /* skip :fldname */ \
113 token = pg_strtok(&length); /* get field value */ \
114 local_node->fldname = nullable_string(token, length)
116 /* Read a parse location field (and throw away the value, per notes above) */
117 #define READ_LOCATION_FIELD(fldname) \
118 token = pg_strtok(&length); /* skip :fldname */ \
119 token = pg_strtok(&length); /* get field value */ \
120 (void) token; /* in case not used elsewhere */ \
121 local_node->fldname = -1 /* set field to "unknown" */
123 /* Read a Node field */
124 #define READ_NODE_FIELD(fldname) \
125 token = pg_strtok(&length); /* skip :fldname */ \
126 (void) token; /* in case not used elsewhere */ \
127 local_node->fldname = nodeRead(NULL, 0)
129 /* Read a bitmapset field */
130 #define READ_BITMAPSET_FIELD(fldname) \
131 token = pg_strtok(&length); /* skip :fldname */ \
132 (void) token; /* in case not used elsewhere */ \
133 local_node->fldname = _readBitmapset()
135 /* Read an attribute number array */
136 #define READ_ATTRNUMBER_ARRAY(fldname, len) \
137 token = pg_strtok(&length); /* skip :fldname */ \
138 local_node->fldname = readAttrNumberCols(len);
140 /* Read an oid array */
141 #define READ_OID_ARRAY(fldname, len) \
142 token = pg_strtok(&length); /* skip :fldname */ \
143 local_node->fldname = readOidCols(len);
145 /* Read an int array */
146 #define READ_INT_ARRAY(fldname, len) \
147 token = pg_strtok(&length); /* skip :fldname */ \
148 local_node->fldname = readIntCols(len);
150 /* Read a bool array */
151 #define READ_BOOL_ARRAY(fldname, len) \
152 token = pg_strtok(&length); /* skip :fldname */ \
153 local_node->fldname = readBoolCols(len);
156 #define READ_DONE() \
161 * NOTE: use atoi() to read values written with %d, or atoui() to read
162 * values written with %u in outfuncs.c. An exception is OID values,
163 * for which use atooid(). (As of 7.1, outfuncs.c writes OIDs as %u,
164 * but this will probably change in the future.)
166 #define atoui(x) ((unsigned int) strtoul((x), NULL, 10))
168 #define strtobool(x) ((*(x) == 't') ? true : false)
170 #define nullable_string(token,length) \
171 ((length) == 0 ? NULL : debackslash(token, length))
180 Bitmapset *result = NULL;
184 token = pg_strtok(&length);
186 elog(ERROR, "incomplete Bitmapset structure");
187 if (length != 1 || token[0] != '(')
188 elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
190 token = pg_strtok(&length);
192 elog(ERROR, "incomplete Bitmapset structure");
193 if (length != 1 || token[0] != 'b')
194 elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
201 token = pg_strtok(&length);
203 elog(ERROR, "unterminated Bitmapset structure");
204 if (length == 1 && token[0] == ')')
206 val = (int) strtol(token, &endptr, 10);
207 if (endptr != token + length)
208 elog(ERROR, "unrecognized integer: \"%.*s\"", length, token);
209 result = bms_add_member(result, val);
216 * for use by extensions which define extensible nodes
221 return _readBitmapset();
232 READ_ENUM_FIELD(commandType, CmdType);
233 READ_ENUM_FIELD(querySource, QuerySource);
234 local_node->queryId = 0; /* not saved in output format */
235 READ_BOOL_FIELD(canSetTag);
236 READ_NODE_FIELD(utilityStmt);
237 READ_INT_FIELD(resultRelation);
238 READ_BOOL_FIELD(hasAggs);
239 READ_BOOL_FIELD(hasWindowFuncs);
240 READ_BOOL_FIELD(hasTargetSRFs);
241 READ_BOOL_FIELD(hasSubLinks);
242 READ_BOOL_FIELD(hasDistinctOn);
243 READ_BOOL_FIELD(hasRecursive);
244 READ_BOOL_FIELD(hasModifyingCTE);
245 READ_BOOL_FIELD(hasForUpdate);
246 READ_BOOL_FIELD(hasRowSecurity);
247 READ_NODE_FIELD(cteList);
248 READ_NODE_FIELD(rtable);
249 READ_NODE_FIELD(jointree);
250 READ_NODE_FIELD(targetList);
251 READ_ENUM_FIELD(override, OverridingKind);
252 READ_NODE_FIELD(onConflict);
253 READ_NODE_FIELD(returningList);
254 READ_NODE_FIELD(groupClause);
255 READ_NODE_FIELD(groupingSets);
256 READ_NODE_FIELD(havingQual);
257 READ_NODE_FIELD(windowClause);
258 READ_NODE_FIELD(distinctClause);
259 READ_NODE_FIELD(sortClause);
260 READ_NODE_FIELD(limitOffset);
261 READ_NODE_FIELD(limitCount);
262 READ_NODE_FIELD(rowMarks);
263 READ_NODE_FIELD(setOperations);
264 READ_NODE_FIELD(constraintDeps);
265 /* withCheckOptions intentionally omitted, see comment in parsenodes.h */
266 READ_LOCATION_FIELD(stmt_location);
267 READ_LOCATION_FIELD(stmt_len);
276 _readNotifyStmt(void)
278 READ_LOCALS(NotifyStmt);
280 READ_STRING_FIELD(conditionname);
281 READ_STRING_FIELD(payload);
287 * _readDeclareCursorStmt
289 static DeclareCursorStmt *
290 _readDeclareCursorStmt(void)
292 READ_LOCALS(DeclareCursorStmt);
294 READ_STRING_FIELD(portalname);
295 READ_INT_FIELD(options);
296 READ_NODE_FIELD(query);
302 * _readWithCheckOption
304 static WithCheckOption *
305 _readWithCheckOption(void)
307 READ_LOCALS(WithCheckOption);
309 READ_ENUM_FIELD(kind, WCOKind);
310 READ_STRING_FIELD(relname);
311 READ_STRING_FIELD(polname);
312 READ_NODE_FIELD(qual);
313 READ_BOOL_FIELD(cascaded);
319 * _readSortGroupClause
321 static SortGroupClause *
322 _readSortGroupClause(void)
324 READ_LOCALS(SortGroupClause);
326 READ_UINT_FIELD(tleSortGroupRef);
327 READ_OID_FIELD(eqop);
328 READ_OID_FIELD(sortop);
329 READ_BOOL_FIELD(nulls_first);
330 READ_BOOL_FIELD(hashable);
339 _readGroupingSet(void)
341 READ_LOCALS(GroupingSet);
343 READ_ENUM_FIELD(kind, GroupingSetKind);
344 READ_NODE_FIELD(content);
345 READ_LOCATION_FIELD(location);
353 static WindowClause *
354 _readWindowClause(void)
356 READ_LOCALS(WindowClause);
358 READ_STRING_FIELD(name);
359 READ_STRING_FIELD(refname);
360 READ_NODE_FIELD(partitionClause);
361 READ_NODE_FIELD(orderClause);
362 READ_INT_FIELD(frameOptions);
363 READ_NODE_FIELD(startOffset);
364 READ_NODE_FIELD(endOffset);
365 READ_UINT_FIELD(winref);
366 READ_BOOL_FIELD(copiedOrder);
374 static RowMarkClause *
375 _readRowMarkClause(void)
377 READ_LOCALS(RowMarkClause);
379 READ_UINT_FIELD(rti);
380 READ_ENUM_FIELD(strength, LockClauseStrength);
381 READ_ENUM_FIELD(waitPolicy, LockWaitPolicy);
382 READ_BOOL_FIELD(pushedDown);
388 * _readCommonTableExpr
390 static CommonTableExpr *
391 _readCommonTableExpr(void)
393 READ_LOCALS(CommonTableExpr);
395 READ_STRING_FIELD(ctename);
396 READ_NODE_FIELD(aliascolnames);
397 READ_NODE_FIELD(ctequery);
398 READ_LOCATION_FIELD(location);
399 READ_BOOL_FIELD(cterecursive);
400 READ_INT_FIELD(cterefcount);
401 READ_NODE_FIELD(ctecolnames);
402 READ_NODE_FIELD(ctecoltypes);
403 READ_NODE_FIELD(ctecoltypmods);
404 READ_NODE_FIELD(ctecolcollations);
410 * _readSetOperationStmt
412 static SetOperationStmt *
413 _readSetOperationStmt(void)
415 READ_LOCALS(SetOperationStmt);
417 READ_ENUM_FIELD(op, SetOperation);
418 READ_BOOL_FIELD(all);
419 READ_NODE_FIELD(larg);
420 READ_NODE_FIELD(rarg);
421 READ_NODE_FIELD(colTypes);
422 READ_NODE_FIELD(colTypmods);
423 READ_NODE_FIELD(colCollations);
424 READ_NODE_FIELD(groupClauses);
431 * Stuff from primnodes.h.
439 READ_STRING_FIELD(aliasname);
440 READ_NODE_FIELD(colnames);
448 READ_LOCALS(RangeVar);
450 local_node->catalogname = NULL; /* not currently saved in output format */
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_uris);
471 READ_NODE_FIELD(ns_names);
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 * _readNextValueExpr
1208 static NextValueExpr *
1209 _readNextValueExpr(void)
1211 READ_LOCALS(NextValueExpr);
1213 READ_OID_FIELD(seqid);
1214 READ_OID_FIELD(typeId);
1220 * _readInferenceElem
1222 static InferenceElem *
1223 _readInferenceElem(void)
1225 READ_LOCALS(InferenceElem);
1227 READ_NODE_FIELD(expr);
1228 READ_OID_FIELD(infercollid);
1229 READ_OID_FIELD(inferopclass);
1237 static TargetEntry *
1238 _readTargetEntry(void)
1240 READ_LOCALS(TargetEntry);
1242 READ_NODE_FIELD(expr);
1243 READ_INT_FIELD(resno);
1244 READ_STRING_FIELD(resname);
1245 READ_UINT_FIELD(ressortgroupref);
1246 READ_OID_FIELD(resorigtbl);
1247 READ_INT_FIELD(resorigcol);
1248 READ_BOOL_FIELD(resjunk);
1256 static RangeTblRef *
1257 _readRangeTblRef(void)
1259 READ_LOCALS(RangeTblRef);
1261 READ_INT_FIELD(rtindex);
1272 READ_LOCALS(JoinExpr);
1274 READ_ENUM_FIELD(jointype, JoinType);
1275 READ_BOOL_FIELD(isNatural);
1276 READ_NODE_FIELD(larg);
1277 READ_NODE_FIELD(rarg);
1278 READ_NODE_FIELD(usingClause);
1279 READ_NODE_FIELD(quals);
1280 READ_NODE_FIELD(alias);
1281 READ_INT_FIELD(rtindex);
1292 READ_LOCALS(FromExpr);
1294 READ_NODE_FIELD(fromlist);
1295 READ_NODE_FIELD(quals);
1301 * _readOnConflictExpr
1303 static OnConflictExpr *
1304 _readOnConflictExpr(void)
1306 READ_LOCALS(OnConflictExpr);
1308 READ_ENUM_FIELD(action, OnConflictAction);
1309 READ_NODE_FIELD(arbiterElems);
1310 READ_NODE_FIELD(arbiterWhere);
1311 READ_OID_FIELD(constraint);
1312 READ_NODE_FIELD(onConflictSet);
1313 READ_NODE_FIELD(onConflictWhere);
1314 READ_INT_FIELD(exclRelIndex);
1315 READ_NODE_FIELD(exclRelTlist);
1321 * Stuff from parsenodes.h.
1325 * _readRangeTblEntry
1327 static RangeTblEntry *
1328 _readRangeTblEntry(void)
1330 READ_LOCALS(RangeTblEntry);
1332 /* put alias + eref first to make dump more legible */
1333 READ_NODE_FIELD(alias);
1334 READ_NODE_FIELD(eref);
1335 READ_ENUM_FIELD(rtekind, RTEKind);
1337 switch (local_node->rtekind)
1340 READ_OID_FIELD(relid);
1341 READ_CHAR_FIELD(relkind);
1342 READ_NODE_FIELD(tablesample);
1345 READ_NODE_FIELD(subquery);
1346 READ_BOOL_FIELD(security_barrier);
1349 READ_ENUM_FIELD(jointype, JoinType);
1350 READ_NODE_FIELD(joinaliasvars);
1353 READ_NODE_FIELD(functions);
1354 READ_BOOL_FIELD(funcordinality);
1357 READ_NODE_FIELD(tablefunc);
1360 READ_NODE_FIELD(values_lists);
1361 READ_NODE_FIELD(coltypes);
1362 READ_NODE_FIELD(coltypmods);
1363 READ_NODE_FIELD(colcollations);
1366 READ_STRING_FIELD(ctename);
1367 READ_UINT_FIELD(ctelevelsup);
1368 READ_BOOL_FIELD(self_reference);
1369 READ_NODE_FIELD(coltypes);
1370 READ_NODE_FIELD(coltypmods);
1371 READ_NODE_FIELD(colcollations);
1373 case RTE_NAMEDTUPLESTORE:
1374 READ_STRING_FIELD(enrname);
1375 READ_FLOAT_FIELD(enrtuples);
1376 READ_OID_FIELD(relid);
1377 READ_NODE_FIELD(coltypes);
1378 READ_NODE_FIELD(coltypmods);
1379 READ_NODE_FIELD(colcollations);
1382 elog(ERROR, "unrecognized RTE kind: %d",
1383 (int) local_node->rtekind);
1387 READ_BOOL_FIELD(lateral);
1388 READ_BOOL_FIELD(inh);
1389 READ_BOOL_FIELD(inFromCl);
1390 READ_UINT_FIELD(requiredPerms);
1391 READ_OID_FIELD(checkAsUser);
1392 READ_BITMAPSET_FIELD(selectedCols);
1393 READ_BITMAPSET_FIELD(insertedCols);
1394 READ_BITMAPSET_FIELD(updatedCols);
1395 READ_NODE_FIELD(securityQuals);
1401 * _readRangeTblFunction
1403 static RangeTblFunction *
1404 _readRangeTblFunction(void)
1406 READ_LOCALS(RangeTblFunction);
1408 READ_NODE_FIELD(funcexpr);
1409 READ_INT_FIELD(funccolcount);
1410 READ_NODE_FIELD(funccolnames);
1411 READ_NODE_FIELD(funccoltypes);
1412 READ_NODE_FIELD(funccoltypmods);
1413 READ_NODE_FIELD(funccolcollations);
1414 READ_BITMAPSET_FIELD(funcparams);
1420 * _readTableSampleClause
1422 static TableSampleClause *
1423 _readTableSampleClause(void)
1425 READ_LOCALS(TableSampleClause);
1427 READ_OID_FIELD(tsmhandler);
1428 READ_NODE_FIELD(args);
1429 READ_NODE_FIELD(repeatable);
1440 READ_LOCALS(DefElem);
1442 READ_STRING_FIELD(defnamespace);
1443 READ_STRING_FIELD(defname);
1444 READ_NODE_FIELD(arg);
1445 READ_ENUM_FIELD(defaction, DefElemAction);
1446 READ_LOCATION_FIELD(location);
1454 static PlannedStmt *
1455 _readPlannedStmt(void)
1457 READ_LOCALS(PlannedStmt);
1459 READ_ENUM_FIELD(commandType, CmdType);
1460 READ_UINT_FIELD(queryId);
1461 READ_BOOL_FIELD(hasReturning);
1462 READ_BOOL_FIELD(hasModifyingCTE);
1463 READ_BOOL_FIELD(canSetTag);
1464 READ_BOOL_FIELD(transientPlan);
1465 READ_BOOL_FIELD(dependsOnRole);
1466 READ_BOOL_FIELD(parallelModeNeeded);
1467 READ_NODE_FIELD(planTree);
1468 READ_NODE_FIELD(rtable);
1469 READ_NODE_FIELD(resultRelations);
1470 READ_NODE_FIELD(nonleafResultRelations);
1471 READ_NODE_FIELD(rootResultRelations);
1472 READ_NODE_FIELD(subplans);
1473 READ_BITMAPSET_FIELD(rewindPlanIDs);
1474 READ_NODE_FIELD(rowMarks);
1475 READ_NODE_FIELD(relationOids);
1476 READ_NODE_FIELD(invalItems);
1477 READ_INT_FIELD(nParamExec);
1478 READ_NODE_FIELD(utilityStmt);
1479 READ_LOCATION_FIELD(stmt_location);
1480 READ_LOCATION_FIELD(stmt_len);
1487 * Assign the basic stuff of all nodes that inherit from Plan
1490 ReadCommonPlan(Plan *local_node)
1494 READ_FLOAT_FIELD(startup_cost);
1495 READ_FLOAT_FIELD(total_cost);
1496 READ_FLOAT_FIELD(plan_rows);
1497 READ_INT_FIELD(plan_width);
1498 READ_BOOL_FIELD(parallel_aware);
1499 READ_BOOL_FIELD(parallel_safe);
1500 READ_INT_FIELD(plan_node_id);
1501 READ_NODE_FIELD(targetlist);
1502 READ_NODE_FIELD(qual);
1503 READ_NODE_FIELD(lefttree);
1504 READ_NODE_FIELD(righttree);
1505 READ_NODE_FIELD(initPlan);
1506 READ_BITMAPSET_FIELD(extParam);
1507 READ_BITMAPSET_FIELD(allParam);
1516 READ_LOCALS_NO_FIELDS(Plan);
1518 ReadCommonPlan(local_node);
1529 READ_LOCALS(Result);
1531 ReadCommonPlan(&local_node->plan);
1533 READ_NODE_FIELD(resconstantqual);
1542 _readProjectSet(void)
1544 READ_LOCALS_NO_FIELDS(ProjectSet);
1546 ReadCommonPlan(&local_node->plan);
1554 static ModifyTable *
1555 _readModifyTable(void)
1557 READ_LOCALS(ModifyTable);
1559 ReadCommonPlan(&local_node->plan);
1561 READ_ENUM_FIELD(operation, CmdType);
1562 READ_BOOL_FIELD(canSetTag);
1563 READ_UINT_FIELD(nominalRelation);
1564 READ_NODE_FIELD(partitioned_rels);
1565 READ_NODE_FIELD(resultRelations);
1566 READ_INT_FIELD(resultRelIndex);
1567 READ_INT_FIELD(rootResultRelIndex);
1568 READ_NODE_FIELD(plans);
1569 READ_NODE_FIELD(withCheckOptionLists);
1570 READ_NODE_FIELD(returningLists);
1571 READ_NODE_FIELD(fdwPrivLists);
1572 READ_BITMAPSET_FIELD(fdwDirectModifyPlans);
1573 READ_NODE_FIELD(rowMarks);
1574 READ_INT_FIELD(epqParam);
1575 READ_ENUM_FIELD(onConflictAction, OnConflictAction);
1576 READ_NODE_FIELD(arbiterIndexes);
1577 READ_NODE_FIELD(onConflictSet);
1578 READ_NODE_FIELD(onConflictWhere);
1579 READ_UINT_FIELD(exclRelRTI);
1580 READ_NODE_FIELD(exclRelTlist);
1591 READ_LOCALS(Append);
1593 ReadCommonPlan(&local_node->plan);
1595 READ_NODE_FIELD(partitioned_rels);
1596 READ_NODE_FIELD(appendplans);
1604 static MergeAppend *
1605 _readMergeAppend(void)
1607 READ_LOCALS(MergeAppend);
1609 ReadCommonPlan(&local_node->plan);
1611 READ_NODE_FIELD(partitioned_rels);
1612 READ_NODE_FIELD(mergeplans);
1613 READ_INT_FIELD(numCols);
1614 READ_ATTRNUMBER_ARRAY(sortColIdx, local_node->numCols);
1615 READ_OID_ARRAY(sortOperators, local_node->numCols);
1616 READ_OID_ARRAY(collations, local_node->numCols);
1617 READ_BOOL_ARRAY(nullsFirst, local_node->numCols);
1623 * _readRecursiveUnion
1625 static RecursiveUnion *
1626 _readRecursiveUnion(void)
1628 READ_LOCALS(RecursiveUnion);
1630 ReadCommonPlan(&local_node->plan);
1632 READ_INT_FIELD(wtParam);
1633 READ_INT_FIELD(numCols);
1634 READ_ATTRNUMBER_ARRAY(dupColIdx, local_node->numCols);
1635 READ_OID_ARRAY(dupOperators, local_node->numCols);
1636 READ_LONG_FIELD(numGroups);
1645 _readBitmapAnd(void)
1647 READ_LOCALS(BitmapAnd);
1649 ReadCommonPlan(&local_node->plan);
1651 READ_NODE_FIELD(bitmapplans);
1662 READ_LOCALS(BitmapOr);
1664 ReadCommonPlan(&local_node->plan);
1666 READ_BOOL_FIELD(isshared);
1667 READ_NODE_FIELD(bitmapplans);
1674 * Assign the basic stuff of all nodes that inherit from Scan
1677 ReadCommonScan(Scan *local_node)
1681 ReadCommonPlan(&local_node->plan);
1683 READ_UINT_FIELD(scanrelid);
1692 READ_LOCALS_NO_FIELDS(Scan);
1694 ReadCommonScan(local_node);
1705 READ_LOCALS_NO_FIELDS(SeqScan);
1707 ReadCommonScan(local_node);
1716 _readSampleScan(void)
1718 READ_LOCALS(SampleScan);
1720 ReadCommonScan(&local_node->scan);
1722 READ_NODE_FIELD(tablesample);
1731 _readIndexScan(void)
1733 READ_LOCALS(IndexScan);
1735 ReadCommonScan(&local_node->scan);
1737 READ_OID_FIELD(indexid);
1738 READ_NODE_FIELD(indexqual);
1739 READ_NODE_FIELD(indexqualorig);
1740 READ_NODE_FIELD(indexorderby);
1741 READ_NODE_FIELD(indexorderbyorig);
1742 READ_NODE_FIELD(indexorderbyops);
1743 READ_ENUM_FIELD(indexorderdir, ScanDirection);
1749 * _readIndexOnlyScan
1751 static IndexOnlyScan *
1752 _readIndexOnlyScan(void)
1754 READ_LOCALS(IndexOnlyScan);
1756 ReadCommonScan(&local_node->scan);
1758 READ_OID_FIELD(indexid);
1759 READ_NODE_FIELD(indexqual);
1760 READ_NODE_FIELD(indexorderby);
1761 READ_NODE_FIELD(indextlist);
1762 READ_ENUM_FIELD(indexorderdir, ScanDirection);
1768 * _readBitmapIndexScan
1770 static BitmapIndexScan *
1771 _readBitmapIndexScan(void)
1773 READ_LOCALS(BitmapIndexScan);
1775 ReadCommonScan(&local_node->scan);
1777 READ_OID_FIELD(indexid);
1778 READ_BOOL_FIELD(isshared);
1779 READ_NODE_FIELD(indexqual);
1780 READ_NODE_FIELD(indexqualorig);
1786 * _readBitmapHeapScan
1788 static BitmapHeapScan *
1789 _readBitmapHeapScan(void)
1791 READ_LOCALS(BitmapHeapScan);
1793 ReadCommonScan(&local_node->scan);
1795 READ_NODE_FIELD(bitmapqualorig);
1806 READ_LOCALS(TidScan);
1808 ReadCommonScan(&local_node->scan);
1810 READ_NODE_FIELD(tidquals);
1818 static SubqueryScan *
1819 _readSubqueryScan(void)
1821 READ_LOCALS(SubqueryScan);
1823 ReadCommonScan(&local_node->scan);
1825 READ_NODE_FIELD(subplan);
1833 static FunctionScan *
1834 _readFunctionScan(void)
1836 READ_LOCALS(FunctionScan);
1838 ReadCommonScan(&local_node->scan);
1840 READ_NODE_FIELD(functions);
1841 READ_BOOL_FIELD(funcordinality);
1850 _readValuesScan(void)
1852 READ_LOCALS(ValuesScan);
1854 ReadCommonScan(&local_node->scan);
1856 READ_NODE_FIELD(values_lists);
1862 * _readTableFuncScan
1864 static TableFuncScan *
1865 _readTableFuncScan(void)
1867 READ_LOCALS(TableFuncScan);
1869 ReadCommonScan(&local_node->scan);
1871 READ_NODE_FIELD(tablefunc);
1882 READ_LOCALS(CteScan);
1884 ReadCommonScan(&local_node->scan);
1886 READ_INT_FIELD(ctePlanId);
1887 READ_INT_FIELD(cteParam);
1893 * _readWorkTableScan
1895 static WorkTableScan *
1896 _readWorkTableScan(void)
1898 READ_LOCALS(WorkTableScan);
1900 ReadCommonScan(&local_node->scan);
1902 READ_INT_FIELD(wtParam);
1910 static ForeignScan *
1911 _readForeignScan(void)
1913 READ_LOCALS(ForeignScan);
1915 ReadCommonScan(&local_node->scan);
1917 READ_ENUM_FIELD(operation, CmdType);
1918 READ_OID_FIELD(fs_server);
1919 READ_NODE_FIELD(fdw_exprs);
1920 READ_NODE_FIELD(fdw_private);
1921 READ_NODE_FIELD(fdw_scan_tlist);
1922 READ_NODE_FIELD(fdw_recheck_quals);
1923 READ_BITMAPSET_FIELD(fs_relids);
1924 READ_BOOL_FIELD(fsSystemCol);
1933 _readCustomScan(void)
1935 READ_LOCALS(CustomScan);
1937 const CustomScanMethods *methods;
1939 ReadCommonScan(&local_node->scan);
1941 READ_UINT_FIELD(flags);
1942 READ_NODE_FIELD(custom_plans);
1943 READ_NODE_FIELD(custom_exprs);
1944 READ_NODE_FIELD(custom_private);
1945 READ_NODE_FIELD(custom_scan_tlist);
1946 READ_BITMAPSET_FIELD(custom_relids);
1948 /* Lookup CustomScanMethods by CustomName */
1949 token = pg_strtok(&length); /* skip methods: */
1950 token = pg_strtok(&length); /* CustomName */
1951 custom_name = nullable_string(token, length);
1952 methods = GetCustomScanMethods(custom_name, false);
1953 local_node->methods = methods;
1960 * Assign the basic stuff of all nodes that inherit from Join
1963 ReadCommonJoin(Join *local_node)
1967 ReadCommonPlan(&local_node->plan);
1969 READ_ENUM_FIELD(jointype, JoinType);
1970 READ_BOOL_FIELD(inner_unique);
1971 READ_NODE_FIELD(joinqual);
1980 READ_LOCALS_NO_FIELDS(Join);
1982 ReadCommonJoin(local_node);
1993 READ_LOCALS(NestLoop);
1995 ReadCommonJoin(&local_node->join);
1997 READ_NODE_FIELD(nestParams);
2006 _readMergeJoin(void)
2010 READ_LOCALS(MergeJoin);
2012 ReadCommonJoin(&local_node->join);
2014 READ_BOOL_FIELD(skip_mark_restore);
2015 READ_NODE_FIELD(mergeclauses);
2017 numCols = list_length(local_node->mergeclauses);
2019 READ_OID_ARRAY(mergeFamilies, numCols);
2020 READ_OID_ARRAY(mergeCollations, numCols);
2021 READ_INT_ARRAY(mergeStrategies, numCols);
2022 READ_BOOL_ARRAY(mergeNullsFirst, numCols);
2033 READ_LOCALS(HashJoin);
2035 ReadCommonJoin(&local_node->join);
2037 READ_NODE_FIELD(hashclauses);
2048 READ_LOCALS_NO_FIELDS(Material);
2050 ReadCommonPlan(&local_node->plan);
2063 ReadCommonPlan(&local_node->plan);
2065 READ_INT_FIELD(numCols);
2066 READ_ATTRNUMBER_ARRAY(sortColIdx, local_node->numCols);
2067 READ_OID_ARRAY(sortOperators, local_node->numCols);
2068 READ_OID_ARRAY(collations, local_node->numCols);
2069 READ_BOOL_ARRAY(nullsFirst, local_node->numCols);
2082 ReadCommonPlan(&local_node->plan);
2084 READ_INT_FIELD(numCols);
2085 READ_ATTRNUMBER_ARRAY(grpColIdx, local_node->numCols);
2086 READ_OID_ARRAY(grpOperators, local_node->numCols);
2099 ReadCommonPlan(&local_node->plan);
2101 READ_ENUM_FIELD(aggstrategy, AggStrategy);
2102 READ_ENUM_FIELD(aggsplit, AggSplit);
2103 READ_INT_FIELD(numCols);
2104 READ_ATTRNUMBER_ARRAY(grpColIdx, local_node->numCols);
2105 READ_OID_ARRAY(grpOperators, local_node->numCols);
2106 READ_LONG_FIELD(numGroups);
2107 READ_BITMAPSET_FIELD(aggParams);
2108 READ_NODE_FIELD(groupingSets);
2109 READ_NODE_FIELD(chain);
2118 _readWindowAgg(void)
2120 READ_LOCALS(WindowAgg);
2122 ReadCommonPlan(&local_node->plan);
2124 READ_UINT_FIELD(winref);
2125 READ_INT_FIELD(partNumCols);
2126 READ_ATTRNUMBER_ARRAY(partColIdx, local_node->partNumCols);
2127 READ_OID_ARRAY(partOperators, local_node->partNumCols);
2128 READ_INT_FIELD(ordNumCols);
2129 READ_ATTRNUMBER_ARRAY(ordColIdx, local_node->ordNumCols);
2130 READ_OID_ARRAY(ordOperators, local_node->ordNumCols);
2131 READ_INT_FIELD(frameOptions);
2132 READ_NODE_FIELD(startOffset);
2133 READ_NODE_FIELD(endOffset);
2144 READ_LOCALS(Unique);
2146 ReadCommonPlan(&local_node->plan);
2148 READ_INT_FIELD(numCols);
2149 READ_ATTRNUMBER_ARRAY(uniqColIdx, local_node->numCols);
2150 READ_OID_ARRAY(uniqOperators, local_node->numCols);
2161 READ_LOCALS(Gather);
2163 ReadCommonPlan(&local_node->plan);
2165 READ_INT_FIELD(num_workers);
2166 READ_INT_FIELD(rescan_param);
2167 READ_BOOL_FIELD(single_copy);
2168 READ_BOOL_FIELD(invisible);
2176 static GatherMerge *
2177 _readGatherMerge(void)
2179 READ_LOCALS(GatherMerge);
2181 ReadCommonPlan(&local_node->plan);
2183 READ_INT_FIELD(num_workers);
2184 READ_INT_FIELD(rescan_param);
2185 READ_INT_FIELD(numCols);
2186 READ_ATTRNUMBER_ARRAY(sortColIdx, local_node->numCols);
2187 READ_OID_ARRAY(sortOperators, local_node->numCols);
2188 READ_OID_ARRAY(collations, local_node->numCols);
2189 READ_BOOL_ARRAY(nullsFirst, local_node->numCols);
2202 ReadCommonPlan(&local_node->plan);
2204 READ_OID_FIELD(skewTable);
2205 READ_INT_FIELD(skewColumn);
2206 READ_BOOL_FIELD(skewInherit);
2219 ReadCommonPlan(&local_node->plan);
2221 READ_ENUM_FIELD(cmd, SetOpCmd);
2222 READ_ENUM_FIELD(strategy, SetOpStrategy);
2223 READ_INT_FIELD(numCols);
2224 READ_ATTRNUMBER_ARRAY(dupColIdx, local_node->numCols);
2225 READ_OID_ARRAY(dupOperators, local_node->numCols);
2226 READ_INT_FIELD(flagColIdx);
2227 READ_INT_FIELD(firstFlag);
2228 READ_LONG_FIELD(numGroups);
2239 READ_LOCALS(LockRows);
2241 ReadCommonPlan(&local_node->plan);
2243 READ_NODE_FIELD(rowMarks);
2244 READ_INT_FIELD(epqParam);
2257 ReadCommonPlan(&local_node->plan);
2259 READ_NODE_FIELD(limitOffset);
2260 READ_NODE_FIELD(limitCount);
2266 * _readNestLoopParam
2268 static NestLoopParam *
2269 _readNestLoopParam(void)
2271 READ_LOCALS(NestLoopParam);
2273 READ_INT_FIELD(paramno);
2274 READ_NODE_FIELD(paramval);
2282 static PlanRowMark *
2283 _readPlanRowMark(void)
2285 READ_LOCALS(PlanRowMark);
2287 READ_UINT_FIELD(rti);
2288 READ_UINT_FIELD(prti);
2289 READ_UINT_FIELD(rowmarkId);
2290 READ_ENUM_FIELD(markType, RowMarkType);
2291 READ_INT_FIELD(allMarkTypes);
2292 READ_ENUM_FIELD(strength, LockClauseStrength);
2293 READ_ENUM_FIELD(waitPolicy, LockWaitPolicy);
2294 READ_BOOL_FIELD(isParent);
2300 * _readPlanInvalItem
2302 static PlanInvalItem *
2303 _readPlanInvalItem(void)
2305 READ_LOCALS(PlanInvalItem);
2307 READ_INT_FIELD(cacheId);
2308 READ_UINT_FIELD(hashValue);
2319 READ_LOCALS(SubPlan);
2321 READ_ENUM_FIELD(subLinkType, SubLinkType);
2322 READ_NODE_FIELD(testexpr);
2323 READ_NODE_FIELD(paramIds);
2324 READ_INT_FIELD(plan_id);
2325 READ_STRING_FIELD(plan_name);
2326 READ_OID_FIELD(firstColType);
2327 READ_INT_FIELD(firstColTypmod);
2328 READ_OID_FIELD(firstColCollation);
2329 READ_BOOL_FIELD(useHashTable);
2330 READ_BOOL_FIELD(unknownEqFalse);
2331 READ_BOOL_FIELD(parallel_safe);
2332 READ_NODE_FIELD(setParam);
2333 READ_NODE_FIELD(parParam);
2334 READ_NODE_FIELD(args);
2335 READ_FLOAT_FIELD(startup_cost);
2336 READ_FLOAT_FIELD(per_call_cost);
2342 * _readAlternativeSubPlan
2344 static AlternativeSubPlan *
2345 _readAlternativeSubPlan(void)
2347 READ_LOCALS(AlternativeSubPlan);
2349 READ_NODE_FIELD(subplans);
2355 * _readExtensibleNode
2357 static ExtensibleNode *
2358 _readExtensibleNode(void)
2360 const ExtensibleNodeMethods *methods;
2361 ExtensibleNode *local_node;
2362 const char *extnodename;
2366 token = pg_strtok(&length); /* skip :extnodename */
2367 token = pg_strtok(&length); /* get extnodename */
2369 extnodename = nullable_string(token, length);
2371 elog(ERROR, "extnodename has to be supplied");
2372 methods = GetExtensibleNodeMethods(extnodename, false);
2374 local_node = (ExtensibleNode *) newNode(methods->node_size,
2376 local_node->extnodename = extnodename;
2378 /* deserialize the private fields */
2379 methods->nodeRead(local_node);
2385 * _readPartitionBoundSpec
2387 static PartitionBoundSpec *
2388 _readPartitionBoundSpec(void)
2390 READ_LOCALS(PartitionBoundSpec);
2392 READ_CHAR_FIELD(strategy);
2393 READ_BOOL_FIELD(is_default);
2394 READ_NODE_FIELD(listdatums);
2395 READ_NODE_FIELD(lowerdatums);
2396 READ_NODE_FIELD(upperdatums);
2397 READ_LOCATION_FIELD(location);
2403 * _readPartitionRangeDatum
2405 static PartitionRangeDatum *
2406 _readPartitionRangeDatum(void)
2408 READ_LOCALS(PartitionRangeDatum);
2410 READ_ENUM_FIELD(kind, PartitionRangeDatumKind);
2411 READ_NODE_FIELD(value);
2412 READ_LOCATION_FIELD(location);
2420 * Given a character string representing a node tree, parseNodeString creates
2421 * the internal node structure.
2423 * The string to be read must already have been loaded into pg_strtok().
2426 parseNodeString(void)
2432 token = pg_strtok(&length);
2434 #define MATCH(tokname, namelen) \
2435 (length == namelen && memcmp(token, tokname, namelen) == 0)
2437 if (MATCH("QUERY", 5))
2438 return_value = _readQuery();
2439 else if (MATCH("WITHCHECKOPTION", 15))
2440 return_value = _readWithCheckOption();
2441 else if (MATCH("SORTGROUPCLAUSE", 15))
2442 return_value = _readSortGroupClause();
2443 else if (MATCH("GROUPINGSET", 11))
2444 return_value = _readGroupingSet();
2445 else if (MATCH("WINDOWCLAUSE", 12))
2446 return_value = _readWindowClause();
2447 else if (MATCH("ROWMARKCLAUSE", 13))
2448 return_value = _readRowMarkClause();
2449 else if (MATCH("COMMONTABLEEXPR", 15))
2450 return_value = _readCommonTableExpr();
2451 else if (MATCH("SETOPERATIONSTMT", 16))
2452 return_value = _readSetOperationStmt();
2453 else if (MATCH("ALIAS", 5))
2454 return_value = _readAlias();
2455 else if (MATCH("RANGEVAR", 8))
2456 return_value = _readRangeVar();
2457 else if (MATCH("INTOCLAUSE", 10))
2458 return_value = _readIntoClause();
2459 else if (MATCH("TABLEFUNC", 9))
2460 return_value = _readTableFunc();
2461 else if (MATCH("VAR", 3))
2462 return_value = _readVar();
2463 else if (MATCH("CONST", 5))
2464 return_value = _readConst();
2465 else if (MATCH("PARAM", 5))
2466 return_value = _readParam();
2467 else if (MATCH("AGGREF", 6))
2468 return_value = _readAggref();
2469 else if (MATCH("GROUPINGFUNC", 12))
2470 return_value = _readGroupingFunc();
2471 else if (MATCH("WINDOWFUNC", 10))
2472 return_value = _readWindowFunc();
2473 else if (MATCH("ARRAYREF", 8))
2474 return_value = _readArrayRef();
2475 else if (MATCH("FUNCEXPR", 8))
2476 return_value = _readFuncExpr();
2477 else if (MATCH("NAMEDARGEXPR", 12))
2478 return_value = _readNamedArgExpr();
2479 else if (MATCH("OPEXPR", 6))
2480 return_value = _readOpExpr();
2481 else if (MATCH("DISTINCTEXPR", 12))
2482 return_value = _readDistinctExpr();
2483 else if (MATCH("NULLIFEXPR", 10))
2484 return_value = _readNullIfExpr();
2485 else if (MATCH("SCALARARRAYOPEXPR", 17))
2486 return_value = _readScalarArrayOpExpr();
2487 else if (MATCH("BOOLEXPR", 8))
2488 return_value = _readBoolExpr();
2489 else if (MATCH("SUBLINK", 7))
2490 return_value = _readSubLink();
2491 else if (MATCH("FIELDSELECT", 11))
2492 return_value = _readFieldSelect();
2493 else if (MATCH("FIELDSTORE", 10))
2494 return_value = _readFieldStore();
2495 else if (MATCH("RELABELTYPE", 11))
2496 return_value = _readRelabelType();
2497 else if (MATCH("COERCEVIAIO", 11))
2498 return_value = _readCoerceViaIO();
2499 else if (MATCH("ARRAYCOERCEEXPR", 15))
2500 return_value = _readArrayCoerceExpr();
2501 else if (MATCH("CONVERTROWTYPEEXPR", 18))
2502 return_value = _readConvertRowtypeExpr();
2503 else if (MATCH("COLLATE", 7))
2504 return_value = _readCollateExpr();
2505 else if (MATCH("CASE", 4))
2506 return_value = _readCaseExpr();
2507 else if (MATCH("WHEN", 4))
2508 return_value = _readCaseWhen();
2509 else if (MATCH("CASETESTEXPR", 12))
2510 return_value = _readCaseTestExpr();
2511 else if (MATCH("ARRAY", 5))
2512 return_value = _readArrayExpr();
2513 else if (MATCH("ROW", 3))
2514 return_value = _readRowExpr();
2515 else if (MATCH("ROWCOMPARE", 10))
2516 return_value = _readRowCompareExpr();
2517 else if (MATCH("COALESCE", 8))
2518 return_value = _readCoalesceExpr();
2519 else if (MATCH("MINMAX", 6))
2520 return_value = _readMinMaxExpr();
2521 else if (MATCH("SQLVALUEFUNCTION", 16))
2522 return_value = _readSQLValueFunction();
2523 else if (MATCH("XMLEXPR", 7))
2524 return_value = _readXmlExpr();
2525 else if (MATCH("NULLTEST", 8))
2526 return_value = _readNullTest();
2527 else if (MATCH("BOOLEANTEST", 11))
2528 return_value = _readBooleanTest();
2529 else if (MATCH("COERCETODOMAIN", 14))
2530 return_value = _readCoerceToDomain();
2531 else if (MATCH("COERCETODOMAINVALUE", 19))
2532 return_value = _readCoerceToDomainValue();
2533 else if (MATCH("SETTODEFAULT", 12))
2534 return_value = _readSetToDefault();
2535 else if (MATCH("CURRENTOFEXPR", 13))
2536 return_value = _readCurrentOfExpr();
2537 else if (MATCH("NEXTVALUEEXPR", 13))
2538 return_value = _readNextValueExpr();
2539 else if (MATCH("INFERENCEELEM", 13))
2540 return_value = _readInferenceElem();
2541 else if (MATCH("TARGETENTRY", 11))
2542 return_value = _readTargetEntry();
2543 else if (MATCH("RANGETBLREF", 11))
2544 return_value = _readRangeTblRef();
2545 else if (MATCH("JOINEXPR", 8))
2546 return_value = _readJoinExpr();
2547 else if (MATCH("FROMEXPR", 8))
2548 return_value = _readFromExpr();
2549 else if (MATCH("ONCONFLICTEXPR", 14))
2550 return_value = _readOnConflictExpr();
2551 else if (MATCH("RTE", 3))
2552 return_value = _readRangeTblEntry();
2553 else if (MATCH("RANGETBLFUNCTION", 16))
2554 return_value = _readRangeTblFunction();
2555 else if (MATCH("TABLESAMPLECLAUSE", 17))
2556 return_value = _readTableSampleClause();
2557 else if (MATCH("NOTIFY", 6))
2558 return_value = _readNotifyStmt();
2559 else if (MATCH("DEFELEM", 7))
2560 return_value = _readDefElem();
2561 else if (MATCH("DECLARECURSOR", 13))
2562 return_value = _readDeclareCursorStmt();
2563 else if (MATCH("PLANNEDSTMT", 11))
2564 return_value = _readPlannedStmt();
2565 else if (MATCH("PLAN", 4))
2566 return_value = _readPlan();
2567 else if (MATCH("RESULT", 6))
2568 return_value = _readResult();
2569 else if (MATCH("PROJECTSET", 10))
2570 return_value = _readProjectSet();
2571 else if (MATCH("MODIFYTABLE", 11))
2572 return_value = _readModifyTable();
2573 else if (MATCH("APPEND", 6))
2574 return_value = _readAppend();
2575 else if (MATCH("MERGEAPPEND", 11))
2576 return_value = _readMergeAppend();
2577 else if (MATCH("RECURSIVEUNION", 14))
2578 return_value = _readRecursiveUnion();
2579 else if (MATCH("BITMAPAND", 9))
2580 return_value = _readBitmapAnd();
2581 else if (MATCH("BITMAPOR", 8))
2582 return_value = _readBitmapOr();
2583 else if (MATCH("SCAN", 4))
2584 return_value = _readScan();
2585 else if (MATCH("SEQSCAN", 7))
2586 return_value = _readSeqScan();
2587 else if (MATCH("SAMPLESCAN", 10))
2588 return_value = _readSampleScan();
2589 else if (MATCH("INDEXSCAN", 9))
2590 return_value = _readIndexScan();
2591 else if (MATCH("INDEXONLYSCAN", 13))
2592 return_value = _readIndexOnlyScan();
2593 else if (MATCH("BITMAPINDEXSCAN", 15))
2594 return_value = _readBitmapIndexScan();
2595 else if (MATCH("BITMAPHEAPSCAN", 14))
2596 return_value = _readBitmapHeapScan();
2597 else if (MATCH("TIDSCAN", 7))
2598 return_value = _readTidScan();
2599 else if (MATCH("SUBQUERYSCAN", 12))
2600 return_value = _readSubqueryScan();
2601 else if (MATCH("FUNCTIONSCAN", 12))
2602 return_value = _readFunctionScan();
2603 else if (MATCH("VALUESSCAN", 10))
2604 return_value = _readValuesScan();
2605 else if (MATCH("TABLEFUNCSCAN", 13))
2606 return_value = _readTableFuncScan();
2607 else if (MATCH("CTESCAN", 7))
2608 return_value = _readCteScan();
2609 else if (MATCH("WORKTABLESCAN", 13))
2610 return_value = _readWorkTableScan();
2611 else if (MATCH("FOREIGNSCAN", 11))
2612 return_value = _readForeignScan();
2613 else if (MATCH("CUSTOMSCAN", 10))
2614 return_value = _readCustomScan();
2615 else if (MATCH("JOIN", 4))
2616 return_value = _readJoin();
2617 else if (MATCH("NESTLOOP", 8))
2618 return_value = _readNestLoop();
2619 else if (MATCH("MERGEJOIN", 9))
2620 return_value = _readMergeJoin();
2621 else if (MATCH("HASHJOIN", 8))
2622 return_value = _readHashJoin();
2623 else if (MATCH("MATERIAL", 8))
2624 return_value = _readMaterial();
2625 else if (MATCH("SORT", 4))
2626 return_value = _readSort();
2627 else if (MATCH("GROUP", 5))
2628 return_value = _readGroup();
2629 else if (MATCH("AGG", 3))
2630 return_value = _readAgg();
2631 else if (MATCH("WINDOWAGG", 9))
2632 return_value = _readWindowAgg();
2633 else if (MATCH("UNIQUE", 6))
2634 return_value = _readUnique();
2635 else if (MATCH("GATHER", 6))
2636 return_value = _readGather();
2637 else if (MATCH("GATHERMERGE", 11))
2638 return_value = _readGatherMerge();
2639 else if (MATCH("HASH", 4))
2640 return_value = _readHash();
2641 else if (MATCH("SETOP", 5))
2642 return_value = _readSetOp();
2643 else if (MATCH("LOCKROWS", 8))
2644 return_value = _readLockRows();
2645 else if (MATCH("LIMIT", 5))
2646 return_value = _readLimit();
2647 else if (MATCH("NESTLOOPPARAM", 13))
2648 return_value = _readNestLoopParam();
2649 else if (MATCH("PLANROWMARK", 11))
2650 return_value = _readPlanRowMark();
2651 else if (MATCH("PLANINVALITEM", 13))
2652 return_value = _readPlanInvalItem();
2653 else if (MATCH("SUBPLAN", 7))
2654 return_value = _readSubPlan();
2655 else if (MATCH("ALTERNATIVESUBPLAN", 18))
2656 return_value = _readAlternativeSubPlan();
2657 else if (MATCH("EXTENSIBLENODE", 14))
2658 return_value = _readExtensibleNode();
2659 else if (MATCH("PARTITIONBOUNDSPEC", 18))
2660 return_value = _readPartitionBoundSpec();
2661 else if (MATCH("PARTITIONRANGEDATUM", 19))
2662 return_value = _readPartitionRangeDatum();
2665 elog(ERROR, "badly formatted node string \"%.32s\"...", token);
2666 return_value = NULL; /* keep compiler quiet */
2669 return (Node *) return_value;
2676 * Given a string representation of a constant, recreate the appropriate
2677 * Datum. The string representation embeds length info, but not byValue,
2678 * so we must be told that.
2681 readDatum(bool typbyval)
2691 * read the actual length of the value
2693 token = pg_strtok(&tokenLength);
2694 length = atoui(token);
2696 token = pg_strtok(&tokenLength); /* read the '[' */
2697 if (token == NULL || token[0] != '[')
2698 elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %zu",
2699 token ? (const char *) token : "[NULL]", length);
2703 if (length > (Size) sizeof(Datum))
2704 elog(ERROR, "byval datum but length = %zu", length);
2706 s = (char *) (&res);
2707 for (i = 0; i < (Size) sizeof(Datum); i++)
2709 token = pg_strtok(&tokenLength);
2710 s[i] = (char) atoi(token);
2713 else if (length <= 0)
2717 s = (char *) palloc(length);
2718 for (i = 0; i < length; i++)
2720 token = pg_strtok(&tokenLength);
2721 s[i] = (char) atoi(token);
2723 res = PointerGetDatum(s);
2726 token = pg_strtok(&tokenLength); /* read the ']' */
2727 if (token == NULL || token[0] != ']')
2728 elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %zu",
2729 token ? (const char *) token : "[NULL]", length);
2735 * readAttrNumberCols
2738 readAttrNumberCols(int numCols)
2743 AttrNumber *attr_vals;
2748 attr_vals = (AttrNumber *) palloc(numCols * sizeof(AttrNumber));
2749 for (i = 0; i < numCols; i++)
2751 token = pg_strtok(&tokenLength);
2752 attr_vals[i] = atoi(token);
2762 readOidCols(int numCols)
2772 oid_vals = (Oid *) palloc(numCols * sizeof(Oid));
2773 for (i = 0; i < numCols; i++)
2775 token = pg_strtok(&tokenLength);
2776 oid_vals[i] = atooid(token);
2786 readIntCols(int numCols)
2796 int_vals = (int *) palloc(numCols * sizeof(int));
2797 for (i = 0; i < numCols; i++)
2799 token = pg_strtok(&tokenLength);
2800 int_vals[i] = atoi(token);
2810 readBoolCols(int numCols)
2820 bool_vals = (bool *) palloc(numCols * sizeof(bool));
2821 for (i = 0; i < numCols; i++)
2823 token = pg_strtok(&tokenLength);
2824 bool_vals[i] = strtobool(token);