1 /*-------------------------------------------------------------------------
2  *
3  * readfuncs.c
4  *	  Reader functions for Postgres tree nodes.
5  *
6  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  *	  src/backend/nodes/readfuncs.c
12  *
13  * NOTES
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.
18  *
19  *	  Parse location fields are written out by outfuncs.c, but only for
20  *	  debugging use.  When reading a location field, we normally 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.
24  *	  However, if restore_location_fields is true, we do restore location
25  *	  fields from the string.  This is currently intended only for use by the
26  *	  WRITE_READ_PARSE_PLAN_TREES test code, which doesn't want to cause
27  *	  any change in the node contents.
28  *
29  *-------------------------------------------------------------------------
30  */
31 #include "postgres.h"
32 
33 #include <math.h>
34 
35 #include "fmgr.h"
36 #include "miscadmin.h"
37 #include "nodes/extensible.h"
38 #include "nodes/parsenodes.h"
39 #include "nodes/plannodes.h"
40 #include "nodes/readfuncs.h"
41 #include "utils/builtins.h"
42 
43 
44 /*
45  * Macros to simplify reading of different kinds of fields.  Use these
46  * wherever possible to reduce the chance for silly typos.  Note that these
47  * hard-wire conventions about the names of the local variables in a Read
48  * routine.
49  */
50 
51 /* Macros for declaring appropriate local variables */
52 
53 /* A few guys need only local_node */
54 #define READ_LOCALS_NO_FIELDS(nodeTypeName) \
55 	nodeTypeName *local_node = makeNode(nodeTypeName)
56 
57 /* And a few guys need only the pg_strtok support fields */
58 #define READ_TEMP_LOCALS()	\
59 	const char *token;		\
60 	int			length
61 
62 /* ... but most need both */
63 #define READ_LOCALS(nodeTypeName)			\
64 	READ_LOCALS_NO_FIELDS(nodeTypeName);	\
65 	READ_TEMP_LOCALS()
66 
67 /* Read an integer field (anything written as ":fldname %d") */
68 #define READ_INT_FIELD(fldname) \
69 	token = pg_strtok(&length);		/* skip :fldname */ \
70 	token = pg_strtok(&length);		/* get field value */ \
71 	local_node->fldname = atoi(token)
72 
73 /* Read an unsigned integer field (anything written as ":fldname %u") */
74 #define READ_UINT_FIELD(fldname) \
75 	token = pg_strtok(&length);		/* skip :fldname */ \
76 	token = pg_strtok(&length);		/* get field value */ \
77 	local_node->fldname = atoui(token)
78 
79 /* Read an unsigned integer field (anything written using UINT64_FORMAT) */
80 #define READ_UINT64_FIELD(fldname) \
81 	token = pg_strtok(&length);		/* skip :fldname */ \
82 	token = pg_strtok(&length);		/* get field value */ \
83 	local_node->fldname = pg_strtouint64(token, NULL, 10)
84 
85 /* Read a long integer field (anything written as ":fldname %ld") */
86 #define READ_LONG_FIELD(fldname) \
87 	token = pg_strtok(&length);		/* skip :fldname */ \
88 	token = pg_strtok(&length);		/* get field value */ \
89 	local_node->fldname = atol(token)
90 
91 /* Read an OID field (don't hard-wire assumption that OID is same as uint) */
92 #define READ_OID_FIELD(fldname) \
93 	token = pg_strtok(&length);		/* skip :fldname */ \
94 	token = pg_strtok(&length);		/* get field value */ \
95 	local_node->fldname = atooid(token)
96 
97 /* Read a char field (ie, one ascii character) */
98 #define READ_CHAR_FIELD(fldname) \
99 	token = pg_strtok(&length);		/* skip :fldname */ \
100 	token = pg_strtok(&length);		/* get field value */ \
101 	/* avoid overhead of calling debackslash() for one char */ \
102 	local_node->fldname = (length == 0) ? '\0' : (token[0] == '\\' ? token[1] : token[0])
103 
104 /* Read an enumerated-type field that was written as an integer code */
105 #define READ_ENUM_FIELD(fldname, enumtype) \
106 	token = pg_strtok(&length);		/* skip :fldname */ \
107 	token = pg_strtok(&length);		/* get field value */ \
108 	local_node->fldname = (enumtype) atoi(token)
109 
110 /* Read a float field */
111 #define READ_FLOAT_FIELD(fldname) \
112 	token = pg_strtok(&length);		/* skip :fldname */ \
113 	token = pg_strtok(&length);		/* get field value */ \
114 	local_node->fldname = atof(token)
115 
116 /* Read a boolean field */
117 #define READ_BOOL_FIELD(fldname) \
118 	token = pg_strtok(&length);		/* skip :fldname */ \
119 	token = pg_strtok(&length);		/* get field value */ \
120 	local_node->fldname = strtobool(token)
121 
122 /* Read a character-string field */
123 #define READ_STRING_FIELD(fldname) \
124 	token = pg_strtok(&length);		/* skip :fldname */ \
125 	token = pg_strtok(&length);		/* get field value */ \
126 	local_node->fldname = nullable_string(token, length)
127 
128 /* Read a parse location field (and possibly throw away the value) */
129 #ifdef WRITE_READ_PARSE_PLAN_TREES
130 #define READ_LOCATION_FIELD(fldname) \
131 	token = pg_strtok(&length);		/* skip :fldname */ \
132 	token = pg_strtok(&length);		/* get field value */ \
133 	local_node->fldname = restore_location_fields ? atoi(token) : -1
134 #else
135 #define READ_LOCATION_FIELD(fldname) \
136 	token = pg_strtok(&length);		/* skip :fldname */ \
137 	token = pg_strtok(&length);		/* get field value */ \
138 	(void) token;				/* in case not used elsewhere */ \
139 	local_node->fldname = -1	/* set field to "unknown" */
140 #endif
141 
142 /* Read a Node field */
143 #define READ_NODE_FIELD(fldname) \
144 	token = pg_strtok(&length);		/* skip :fldname */ \
145 	(void) token;				/* in case not used elsewhere */ \
146 	local_node->fldname = nodeRead(NULL, 0)
147 
148 /* Read a bitmapset field */
149 #define READ_BITMAPSET_FIELD(fldname) \
150 	token = pg_strtok(&length);		/* skip :fldname */ \
151 	(void) token;				/* in case not used elsewhere */ \
152 	local_node->fldname = _readBitmapset()
153 
154 /* Read an attribute number array */
155 #define READ_ATTRNUMBER_ARRAY(fldname, len) \
156 	token = pg_strtok(&length);		/* skip :fldname */ \
157 	local_node->fldname = readAttrNumberCols(len)
158 
159 /* Read an oid array */
160 #define READ_OID_ARRAY(fldname, len) \
161 	token = pg_strtok(&length);		/* skip :fldname */ \
162 	local_node->fldname = readOidCols(len)
163 
164 /* Read an int array */
165 #define READ_INT_ARRAY(fldname, len) \
166 	token = pg_strtok(&length);		/* skip :fldname */ \
167 	local_node->fldname = readIntCols(len)
168 
169 /* Read a bool array */
170 #define READ_BOOL_ARRAY(fldname, len) \
171 	token = pg_strtok(&length);		/* skip :fldname */ \
172 	local_node->fldname = readBoolCols(len)
173 
174 /* Routine exit */
175 #define READ_DONE() \
176 	return local_node
177 
178 
179 /*
180  * NOTE: use atoi() to read values written with %d, or atoui() to read
181  * values written with %u in outfuncs.c.  An exception is OID values,
182  * for which use atooid().  (As of 7.1, outfuncs.c writes OIDs as %u,
183  * but this will probably change in the future.)
184  */
185 #define atoui(x)  ((unsigned int) strtoul((x), NULL, 10))
186 
187 #define strtobool(x)  ((*(x) == 't') ? true : false)
188 
189 #define nullable_string(token,length)  \
190 	((length) == 0 ? NULL : debackslash(token, length))
191 
192 
193 /*
194  * _readBitmapset
195  */
196 static Bitmapset *
_readBitmapset(void)197 _readBitmapset(void)
198 {
199 	Bitmapset  *result = NULL;
200 
201 	READ_TEMP_LOCALS();
202 
203 	token = pg_strtok(&length);
204 	if (token == NULL)
205 		elog(ERROR, "incomplete Bitmapset structure");
206 	if (length != 1 || token[0] != '(')
207 		elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
208 
209 	token = pg_strtok(&length);
210 	if (token == NULL)
211 		elog(ERROR, "incomplete Bitmapset structure");
212 	if (length != 1 || token[0] != 'b')
213 		elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
214 
215 	for (;;)
216 	{
217 		int			val;
218 		char	   *endptr;
219 
220 		token = pg_strtok(&length);
221 		if (token == NULL)
222 			elog(ERROR, "unterminated Bitmapset structure");
223 		if (length == 1 && token[0] == ')')
224 			break;
225 		val = (int) strtol(token, &endptr, 10);
226 		if (endptr != token + length)
227 			elog(ERROR, "unrecognized integer: \"%.*s\"", length, token);
228 		result = bms_add_member(result, val);
229 	}
230 
231 	return result;
232 }
233 
234 /*
235  * for use by extensions which define extensible nodes
236  */
237 Bitmapset *
readBitmapset(void)238 readBitmapset(void)
239 {
240 	return _readBitmapset();
241 }
242 
243 /*
244  * _readQuery
245  */
246 static Query *
_readQuery(void)247 _readQuery(void)
248 {
249 	READ_LOCALS(Query);
250 
251 	READ_ENUM_FIELD(commandType, CmdType);
252 	READ_ENUM_FIELD(querySource, QuerySource);
253 	local_node->queryId = UINT64CONST(0);	/* not saved in output format */
254 	READ_BOOL_FIELD(canSetTag);
255 	READ_NODE_FIELD(utilityStmt);
256 	READ_INT_FIELD(resultRelation);
257 	READ_BOOL_FIELD(hasAggs);
258 	READ_BOOL_FIELD(hasWindowFuncs);
259 	READ_BOOL_FIELD(hasTargetSRFs);
260 	READ_BOOL_FIELD(hasSubLinks);
261 	READ_BOOL_FIELD(hasDistinctOn);
262 	READ_BOOL_FIELD(hasRecursive);
263 	READ_BOOL_FIELD(hasModifyingCTE);
264 	READ_BOOL_FIELD(hasForUpdate);
265 	READ_BOOL_FIELD(hasRowSecurity);
266 	READ_NODE_FIELD(cteList);
267 	READ_NODE_FIELD(rtable);
268 	READ_NODE_FIELD(jointree);
269 	READ_NODE_FIELD(targetList);
270 	READ_ENUM_FIELD(override, OverridingKind);
271 	READ_NODE_FIELD(onConflict);
272 	READ_NODE_FIELD(returningList);
273 	READ_NODE_FIELD(groupClause);
274 	READ_NODE_FIELD(groupingSets);
275 	READ_NODE_FIELD(havingQual);
276 	READ_NODE_FIELD(windowClause);
277 	READ_NODE_FIELD(distinctClause);
278 	READ_NODE_FIELD(sortClause);
279 	READ_NODE_FIELD(limitOffset);
280 	READ_NODE_FIELD(limitCount);
281 	READ_ENUM_FIELD(limitOption, LimitOption);
282 	READ_NODE_FIELD(rowMarks);
283 	READ_NODE_FIELD(setOperations);
284 	READ_NODE_FIELD(constraintDeps);
285 	READ_NODE_FIELD(withCheckOptions);
286 	READ_LOCATION_FIELD(stmt_location);
287 	READ_INT_FIELD(stmt_len);
288 
289 	READ_DONE();
290 }
291 
292 /*
293  * _readNotifyStmt
294  */
295 static NotifyStmt *
_readNotifyStmt(void)296 _readNotifyStmt(void)
297 {
298 	READ_LOCALS(NotifyStmt);
299 
300 	READ_STRING_FIELD(conditionname);
301 	READ_STRING_FIELD(payload);
302 
303 	READ_DONE();
304 }
305 
306 /*
307  * _readDeclareCursorStmt
308  */
309 static DeclareCursorStmt *
_readDeclareCursorStmt(void)310 _readDeclareCursorStmt(void)
311 {
312 	READ_LOCALS(DeclareCursorStmt);
313 
314 	READ_STRING_FIELD(portalname);
315 	READ_INT_FIELD(options);
316 	READ_NODE_FIELD(query);
317 
318 	READ_DONE();
319 }
320 
321 /*
322  * _readWithCheckOption
323  */
324 static WithCheckOption *
_readWithCheckOption(void)325 _readWithCheckOption(void)
326 {
327 	READ_LOCALS(WithCheckOption);
328 
329 	READ_ENUM_FIELD(kind, WCOKind);
330 	READ_STRING_FIELD(relname);
331 	READ_STRING_FIELD(polname);
332 	READ_NODE_FIELD(qual);
333 	READ_BOOL_FIELD(cascaded);
334 
335 	READ_DONE();
336 }
337 
338 /*
339  * _readSortGroupClause
340  */
341 static SortGroupClause *
_readSortGroupClause(void)342 _readSortGroupClause(void)
343 {
344 	READ_LOCALS(SortGroupClause);
345 
346 	READ_UINT_FIELD(tleSortGroupRef);
347 	READ_OID_FIELD(eqop);
348 	READ_OID_FIELD(sortop);
349 	READ_BOOL_FIELD(nulls_first);
350 	READ_BOOL_FIELD(hashable);
351 
352 	READ_DONE();
353 }
354 
355 /*
356  * _readGroupingSet
357  */
358 static GroupingSet *
_readGroupingSet(void)359 _readGroupingSet(void)
360 {
361 	READ_LOCALS(GroupingSet);
362 
363 	READ_ENUM_FIELD(kind, GroupingSetKind);
364 	READ_NODE_FIELD(content);
365 	READ_LOCATION_FIELD(location);
366 
367 	READ_DONE();
368 }
369 
370 /*
371  * _readWindowClause
372  */
373 static WindowClause *
_readWindowClause(void)374 _readWindowClause(void)
375 {
376 	READ_LOCALS(WindowClause);
377 
378 	READ_STRING_FIELD(name);
379 	READ_STRING_FIELD(refname);
380 	READ_NODE_FIELD(partitionClause);
381 	READ_NODE_FIELD(orderClause);
382 	READ_INT_FIELD(frameOptions);
383 	READ_NODE_FIELD(startOffset);
384 	READ_NODE_FIELD(endOffset);
385 	READ_OID_FIELD(startInRangeFunc);
386 	READ_OID_FIELD(endInRangeFunc);
387 	READ_OID_FIELD(inRangeColl);
388 	READ_BOOL_FIELD(inRangeAsc);
389 	READ_BOOL_FIELD(inRangeNullsFirst);
390 	READ_UINT_FIELD(winref);
391 	READ_BOOL_FIELD(copiedOrder);
392 
393 	READ_DONE();
394 }
395 
396 /*
397  * _readRowMarkClause
398  */
399 static RowMarkClause *
_readRowMarkClause(void)400 _readRowMarkClause(void)
401 {
402 	READ_LOCALS(RowMarkClause);
403 
404 	READ_UINT_FIELD(rti);
405 	READ_ENUM_FIELD(strength, LockClauseStrength);
406 	READ_ENUM_FIELD(waitPolicy, LockWaitPolicy);
407 	READ_BOOL_FIELD(pushedDown);
408 
409 	READ_DONE();
410 }
411 
412 /*
413  * _readCommonTableExpr
414  */
415 static CommonTableExpr *
_readCommonTableExpr(void)416 _readCommonTableExpr(void)
417 {
418 	READ_LOCALS(CommonTableExpr);
419 
420 	READ_STRING_FIELD(ctename);
421 	READ_NODE_FIELD(aliascolnames);
422 	READ_ENUM_FIELD(ctematerialized, CTEMaterialize);
423 	READ_NODE_FIELD(ctequery);
424 	READ_LOCATION_FIELD(location);
425 	READ_BOOL_FIELD(cterecursive);
426 	READ_INT_FIELD(cterefcount);
427 	READ_NODE_FIELD(ctecolnames);
428 	READ_NODE_FIELD(ctecoltypes);
429 	READ_NODE_FIELD(ctecoltypmods);
430 	READ_NODE_FIELD(ctecolcollations);
431 
432 	READ_DONE();
433 }
434 
435 /*
436  * _readSetOperationStmt
437  */
438 static SetOperationStmt *
_readSetOperationStmt(void)439 _readSetOperationStmt(void)
440 {
441 	READ_LOCALS(SetOperationStmt);
442 
443 	READ_ENUM_FIELD(op, SetOperation);
444 	READ_BOOL_FIELD(all);
445 	READ_NODE_FIELD(larg);
446 	READ_NODE_FIELD(rarg);
447 	READ_NODE_FIELD(colTypes);
448 	READ_NODE_FIELD(colTypmods);
449 	READ_NODE_FIELD(colCollations);
450 	READ_NODE_FIELD(groupClauses);
451 
452 	READ_DONE();
453 }
454 
455 
456 /*
457  *	Stuff from primnodes.h.
458  */
459 
460 static Alias *
_readAlias(void)461 _readAlias(void)
462 {
463 	READ_LOCALS(Alias);
464 
465 	READ_STRING_FIELD(aliasname);
466 	READ_NODE_FIELD(colnames);
467 
468 	READ_DONE();
469 }
470 
471 static RangeVar *
_readRangeVar(void)472 _readRangeVar(void)
473 {
474 	READ_LOCALS(RangeVar);
475 
476 	local_node->catalogname = NULL; /* not currently saved in output format */
477 
478 	READ_STRING_FIELD(schemaname);
479 	READ_STRING_FIELD(relname);
480 	READ_BOOL_FIELD(inh);
481 	READ_CHAR_FIELD(relpersistence);
482 	READ_NODE_FIELD(alias);
483 	READ_LOCATION_FIELD(location);
484 
485 	READ_DONE();
486 }
487 
488 /*
489  * _readTableFunc
490  */
491 static TableFunc *
_readTableFunc(void)492 _readTableFunc(void)
493 {
494 	READ_LOCALS(TableFunc);
495 
496 	READ_NODE_FIELD(ns_uris);
497 	READ_NODE_FIELD(ns_names);
498 	READ_NODE_FIELD(docexpr);
499 	READ_NODE_FIELD(rowexpr);
500 	READ_NODE_FIELD(colnames);
501 	READ_NODE_FIELD(coltypes);
502 	READ_NODE_FIELD(coltypmods);
503 	READ_NODE_FIELD(colcollations);
504 	READ_NODE_FIELD(colexprs);
505 	READ_NODE_FIELD(coldefexprs);
506 	READ_BITMAPSET_FIELD(notnulls);
507 	READ_INT_FIELD(ordinalitycol);
508 	READ_LOCATION_FIELD(location);
509 
510 	READ_DONE();
511 }
512 
513 static IntoClause *
_readIntoClause(void)514 _readIntoClause(void)
515 {
516 	READ_LOCALS(IntoClause);
517 
518 	READ_NODE_FIELD(rel);
519 	READ_NODE_FIELD(colNames);
520 	READ_STRING_FIELD(accessMethod);
521 	READ_NODE_FIELD(options);
522 	READ_ENUM_FIELD(onCommit, OnCommitAction);
523 	READ_STRING_FIELD(tableSpaceName);
524 	READ_NODE_FIELD(viewQuery);
525 	READ_BOOL_FIELD(skipData);
526 
527 	READ_DONE();
528 }
529 
530 /*
531  * _readVar
532  */
533 static Var *
_readVar(void)534 _readVar(void)
535 {
536 	READ_LOCALS(Var);
537 
538 	READ_UINT_FIELD(varno);
539 	READ_INT_FIELD(varattno);
540 	READ_OID_FIELD(vartype);
541 	READ_INT_FIELD(vartypmod);
542 	READ_OID_FIELD(varcollid);
543 	READ_UINT_FIELD(varlevelsup);
544 	READ_UINT_FIELD(varnosyn);
545 	READ_INT_FIELD(varattnosyn);
546 	READ_LOCATION_FIELD(location);
547 
548 	READ_DONE();
549 }
550 
551 /*
552  * _readConst
553  */
554 static Const *
_readConst(void)555 _readConst(void)
556 {
557 	READ_LOCALS(Const);
558 
559 	READ_OID_FIELD(consttype);
560 	READ_INT_FIELD(consttypmod);
561 	READ_OID_FIELD(constcollid);
562 	READ_INT_FIELD(constlen);
563 	READ_BOOL_FIELD(constbyval);
564 	READ_BOOL_FIELD(constisnull);
565 	READ_LOCATION_FIELD(location);
566 
567 	token = pg_strtok(&length); /* skip :constvalue */
568 	if (local_node->constisnull)
569 		token = pg_strtok(&length); /* skip "<>" */
570 	else
571 		local_node->constvalue = readDatum(local_node->constbyval);
572 
573 	READ_DONE();
574 }
575 
576 /*
577  * _readParam
578  */
579 static Param *
_readParam(void)580 _readParam(void)
581 {
582 	READ_LOCALS(Param);
583 
584 	READ_ENUM_FIELD(paramkind, ParamKind);
585 	READ_INT_FIELD(paramid);
586 	READ_OID_FIELD(paramtype);
587 	READ_INT_FIELD(paramtypmod);
588 	READ_OID_FIELD(paramcollid);
589 	READ_LOCATION_FIELD(location);
590 
591 	READ_DONE();
592 }
593 
594 /*
595  * _readAggref
596  */
597 static Aggref *
_readAggref(void)598 _readAggref(void)
599 {
600 	READ_LOCALS(Aggref);
601 
602 	READ_OID_FIELD(aggfnoid);
603 	READ_OID_FIELD(aggtype);
604 	READ_OID_FIELD(aggcollid);
605 	READ_OID_FIELD(inputcollid);
606 	READ_OID_FIELD(aggtranstype);
607 	READ_NODE_FIELD(aggargtypes);
608 	READ_NODE_FIELD(aggdirectargs);
609 	READ_NODE_FIELD(args);
610 	READ_NODE_FIELD(aggorder);
611 	READ_NODE_FIELD(aggdistinct);
612 	READ_NODE_FIELD(aggfilter);
613 	READ_BOOL_FIELD(aggstar);
614 	READ_BOOL_FIELD(aggvariadic);
615 	READ_CHAR_FIELD(aggkind);
616 	READ_UINT_FIELD(agglevelsup);
617 	READ_ENUM_FIELD(aggsplit, AggSplit);
618 	READ_LOCATION_FIELD(location);
619 
620 	READ_DONE();
621 }
622 
623 /*
624  * _readGroupingFunc
625  */
626 static GroupingFunc *
_readGroupingFunc(void)627 _readGroupingFunc(void)
628 {
629 	READ_LOCALS(GroupingFunc);
630 
631 	READ_NODE_FIELD(args);
632 	READ_NODE_FIELD(refs);
633 	READ_NODE_FIELD(cols);
634 	READ_UINT_FIELD(agglevelsup);
635 	READ_LOCATION_FIELD(location);
636 
637 	READ_DONE();
638 }
639 
640 /*
641  * _readWindowFunc
642  */
643 static WindowFunc *
_readWindowFunc(void)644 _readWindowFunc(void)
645 {
646 	READ_LOCALS(WindowFunc);
647 
648 	READ_OID_FIELD(winfnoid);
649 	READ_OID_FIELD(wintype);
650 	READ_OID_FIELD(wincollid);
651 	READ_OID_FIELD(inputcollid);
652 	READ_NODE_FIELD(args);
653 	READ_NODE_FIELD(aggfilter);
654 	READ_UINT_FIELD(winref);
655 	READ_BOOL_FIELD(winstar);
656 	READ_BOOL_FIELD(winagg);
657 	READ_LOCATION_FIELD(location);
658 
659 	READ_DONE();
660 }
661 
662 /*
663  * _readSubscriptingRef
664  */
665 static SubscriptingRef *
_readSubscriptingRef(void)666 _readSubscriptingRef(void)
667 {
668 	READ_LOCALS(SubscriptingRef);
669 
670 	READ_OID_FIELD(refcontainertype);
671 	READ_OID_FIELD(refelemtype);
672 	READ_INT_FIELD(reftypmod);
673 	READ_OID_FIELD(refcollid);
674 	READ_NODE_FIELD(refupperindexpr);
675 	READ_NODE_FIELD(reflowerindexpr);
676 	READ_NODE_FIELD(refexpr);
677 	READ_NODE_FIELD(refassgnexpr);
678 
679 	READ_DONE();
680 }
681 
682 /*
683  * _readFuncExpr
684  */
685 static FuncExpr *
_readFuncExpr(void)686 _readFuncExpr(void)
687 {
688 	READ_LOCALS(FuncExpr);
689 
690 	READ_OID_FIELD(funcid);
691 	READ_OID_FIELD(funcresulttype);
692 	READ_BOOL_FIELD(funcretset);
693 	READ_BOOL_FIELD(funcvariadic);
694 	READ_ENUM_FIELD(funcformat, CoercionForm);
695 	READ_OID_FIELD(funccollid);
696 	READ_OID_FIELD(inputcollid);
697 	READ_NODE_FIELD(args);
698 	READ_LOCATION_FIELD(location);
699 
700 	READ_DONE();
701 }
702 
703 /*
704  * _readNamedArgExpr
705  */
706 static NamedArgExpr *
_readNamedArgExpr(void)707 _readNamedArgExpr(void)
708 {
709 	READ_LOCALS(NamedArgExpr);
710 
711 	READ_NODE_FIELD(arg);
712 	READ_STRING_FIELD(name);
713 	READ_INT_FIELD(argnumber);
714 	READ_LOCATION_FIELD(location);
715 
716 	READ_DONE();
717 }
718 
719 /*
720  * _readOpExpr
721  */
722 static OpExpr *
_readOpExpr(void)723 _readOpExpr(void)
724 {
725 	READ_LOCALS(OpExpr);
726 
727 	READ_OID_FIELD(opno);
728 	READ_OID_FIELD(opfuncid);
729 	READ_OID_FIELD(opresulttype);
730 	READ_BOOL_FIELD(opretset);
731 	READ_OID_FIELD(opcollid);
732 	READ_OID_FIELD(inputcollid);
733 	READ_NODE_FIELD(args);
734 	READ_LOCATION_FIELD(location);
735 
736 	READ_DONE();
737 }
738 
739 /*
740  * _readDistinctExpr
741  */
742 static DistinctExpr *
_readDistinctExpr(void)743 _readDistinctExpr(void)
744 {
745 	READ_LOCALS(DistinctExpr);
746 
747 	READ_OID_FIELD(opno);
748 	READ_OID_FIELD(opfuncid);
749 	READ_OID_FIELD(opresulttype);
750 	READ_BOOL_FIELD(opretset);
751 	READ_OID_FIELD(opcollid);
752 	READ_OID_FIELD(inputcollid);
753 	READ_NODE_FIELD(args);
754 	READ_LOCATION_FIELD(location);
755 
756 	READ_DONE();
757 }
758 
759 /*
760  * _readNullIfExpr
761  */
762 static NullIfExpr *
_readNullIfExpr(void)763 _readNullIfExpr(void)
764 {
765 	READ_LOCALS(NullIfExpr);
766 
767 	READ_OID_FIELD(opno);
768 	READ_OID_FIELD(opfuncid);
769 	READ_OID_FIELD(opresulttype);
770 	READ_BOOL_FIELD(opretset);
771 	READ_OID_FIELD(opcollid);
772 	READ_OID_FIELD(inputcollid);
773 	READ_NODE_FIELD(args);
774 	READ_LOCATION_FIELD(location);
775 
776 	READ_DONE();
777 }
778 
779 /*
780  * _readScalarArrayOpExpr
781  */
782 static ScalarArrayOpExpr *
_readScalarArrayOpExpr(void)783 _readScalarArrayOpExpr(void)
784 {
785 	READ_LOCALS(ScalarArrayOpExpr);
786 
787 	READ_OID_FIELD(opno);
788 	READ_OID_FIELD(opfuncid);
789 	READ_BOOL_FIELD(useOr);
790 	READ_OID_FIELD(inputcollid);
791 	READ_NODE_FIELD(args);
792 	READ_LOCATION_FIELD(location);
793 
794 	READ_DONE();
795 }
796 
797 /*
798  * _readBoolExpr
799  */
800 static BoolExpr *
_readBoolExpr(void)801 _readBoolExpr(void)
802 {
803 	READ_LOCALS(BoolExpr);
804 
805 	/* do-it-yourself enum representation */
806 	token = pg_strtok(&length); /* skip :boolop */
807 	token = pg_strtok(&length); /* get field value */
808 	if (strncmp(token, "and", 3) == 0)
809 		local_node->boolop = AND_EXPR;
810 	else if (strncmp(token, "or", 2) == 0)
811 		local_node->boolop = OR_EXPR;
812 	else if (strncmp(token, "not", 3) == 0)
813 		local_node->boolop = NOT_EXPR;
814 	else
815 		elog(ERROR, "unrecognized boolop \"%.*s\"", length, token);
816 
817 	READ_NODE_FIELD(args);
818 	READ_LOCATION_FIELD(location);
819 
820 	READ_DONE();
821 }
822 
823 /*
824  * _readSubLink
825  */
826 static SubLink *
_readSubLink(void)827 _readSubLink(void)
828 {
829 	READ_LOCALS(SubLink);
830 
831 	READ_ENUM_FIELD(subLinkType, SubLinkType);
832 	READ_INT_FIELD(subLinkId);
833 	READ_NODE_FIELD(testexpr);
834 	READ_NODE_FIELD(operName);
835 	READ_NODE_FIELD(subselect);
836 	READ_LOCATION_FIELD(location);
837 
838 	READ_DONE();
839 }
840 
841 /*
842  * _readSubPlan is not needed since it doesn't appear in stored rules.
843  */
844 
845 /*
846  * _readFieldSelect
847  */
848 static FieldSelect *
_readFieldSelect(void)849 _readFieldSelect(void)
850 {
851 	READ_LOCALS(FieldSelect);
852 
853 	READ_NODE_FIELD(arg);
854 	READ_INT_FIELD(fieldnum);
855 	READ_OID_FIELD(resulttype);
856 	READ_INT_FIELD(resulttypmod);
857 	READ_OID_FIELD(resultcollid);
858 
859 	READ_DONE();
860 }
861 
862 /*
863  * _readFieldStore
864  */
865 static FieldStore *
_readFieldStore(void)866 _readFieldStore(void)
867 {
868 	READ_LOCALS(FieldStore);
869 
870 	READ_NODE_FIELD(arg);
871 	READ_NODE_FIELD(newvals);
872 	READ_NODE_FIELD(fieldnums);
873 	READ_OID_FIELD(resulttype);
874 
875 	READ_DONE();
876 }
877 
878 /*
879  * _readRelabelType
880  */
881 static RelabelType *
_readRelabelType(void)882 _readRelabelType(void)
883 {
884 	READ_LOCALS(RelabelType);
885 
886 	READ_NODE_FIELD(arg);
887 	READ_OID_FIELD(resulttype);
888 	READ_INT_FIELD(resulttypmod);
889 	READ_OID_FIELD(resultcollid);
890 	READ_ENUM_FIELD(relabelformat, CoercionForm);
891 	READ_LOCATION_FIELD(location);
892 
893 	READ_DONE();
894 }
895 
896 /*
897  * _readCoerceViaIO
898  */
899 static CoerceViaIO *
_readCoerceViaIO(void)900 _readCoerceViaIO(void)
901 {
902 	READ_LOCALS(CoerceViaIO);
903 
904 	READ_NODE_FIELD(arg);
905 	READ_OID_FIELD(resulttype);
906 	READ_OID_FIELD(resultcollid);
907 	READ_ENUM_FIELD(coerceformat, CoercionForm);
908 	READ_LOCATION_FIELD(location);
909 
910 	READ_DONE();
911 }
912 
913 /*
914  * _readArrayCoerceExpr
915  */
916 static ArrayCoerceExpr *
_readArrayCoerceExpr(void)917 _readArrayCoerceExpr(void)
918 {
919 	READ_LOCALS(ArrayCoerceExpr);
920 
921 	READ_NODE_FIELD(arg);
922 	READ_NODE_FIELD(elemexpr);
923 	READ_OID_FIELD(resulttype);
924 	READ_INT_FIELD(resulttypmod);
925 	READ_OID_FIELD(resultcollid);
926 	READ_ENUM_FIELD(coerceformat, CoercionForm);
927 	READ_LOCATION_FIELD(location);
928 
929 	READ_DONE();
930 }
931 
932 /*
933  * _readConvertRowtypeExpr
934  */
935 static ConvertRowtypeExpr *
_readConvertRowtypeExpr(void)936 _readConvertRowtypeExpr(void)
937 {
938 	READ_LOCALS(ConvertRowtypeExpr);
939 
940 	READ_NODE_FIELD(arg);
941 	READ_OID_FIELD(resulttype);
942 	READ_ENUM_FIELD(convertformat, CoercionForm);
943 	READ_LOCATION_FIELD(location);
944 
945 	READ_DONE();
946 }
947 
948 /*
949  * _readCollateExpr
950  */
951 static CollateExpr *
_readCollateExpr(void)952 _readCollateExpr(void)
953 {
954 	READ_LOCALS(CollateExpr);
955 
956 	READ_NODE_FIELD(arg);
957 	READ_OID_FIELD(collOid);
958 	READ_LOCATION_FIELD(location);
959 
960 	READ_DONE();
961 }
962 
963 /*
964  * _readCaseExpr
965  */
966 static CaseExpr *
_readCaseExpr(void)967 _readCaseExpr(void)
968 {
969 	READ_LOCALS(CaseExpr);
970 
971 	READ_OID_FIELD(casetype);
972 	READ_OID_FIELD(casecollid);
973 	READ_NODE_FIELD(arg);
974 	READ_NODE_FIELD(args);
975 	READ_NODE_FIELD(defresult);
976 	READ_LOCATION_FIELD(location);
977 
978 	READ_DONE();
979 }
980 
981 /*
982  * _readCaseWhen
983  */
984 static CaseWhen *
_readCaseWhen(void)985 _readCaseWhen(void)
986 {
987 	READ_LOCALS(CaseWhen);
988 
989 	READ_NODE_FIELD(expr);
990 	READ_NODE_FIELD(result);
991 	READ_LOCATION_FIELD(location);
992 
993 	READ_DONE();
994 }
995 
996 /*
997  * _readCaseTestExpr
998  */
999 static CaseTestExpr *
_readCaseTestExpr(void)1000 _readCaseTestExpr(void)
1001 {
1002 	READ_LOCALS(CaseTestExpr);
1003 
1004 	READ_OID_FIELD(typeId);
1005 	READ_INT_FIELD(typeMod);
1006 	READ_OID_FIELD(collation);
1007 
1008 	READ_DONE();
1009 }
1010 
1011 /*
1012  * _readArrayExpr
1013  */
1014 static ArrayExpr *
_readArrayExpr(void)1015 _readArrayExpr(void)
1016 {
1017 	READ_LOCALS(ArrayExpr);
1018 
1019 	READ_OID_FIELD(array_typeid);
1020 	READ_OID_FIELD(array_collid);
1021 	READ_OID_FIELD(element_typeid);
1022 	READ_NODE_FIELD(elements);
1023 	READ_BOOL_FIELD(multidims);
1024 	READ_LOCATION_FIELD(location);
1025 
1026 	READ_DONE();
1027 }
1028 
1029 /*
1030  * _readRowExpr
1031  */
1032 static RowExpr *
_readRowExpr(void)1033 _readRowExpr(void)
1034 {
1035 	READ_LOCALS(RowExpr);
1036 
1037 	READ_NODE_FIELD(args);
1038 	READ_OID_FIELD(row_typeid);
1039 	READ_ENUM_FIELD(row_format, CoercionForm);
1040 	READ_NODE_FIELD(colnames);
1041 	READ_LOCATION_FIELD(location);
1042 
1043 	READ_DONE();
1044 }
1045 
1046 /*
1047  * _readRowCompareExpr
1048  */
1049 static RowCompareExpr *
_readRowCompareExpr(void)1050 _readRowCompareExpr(void)
1051 {
1052 	READ_LOCALS(RowCompareExpr);
1053 
1054 	READ_ENUM_FIELD(rctype, RowCompareType);
1055 	READ_NODE_FIELD(opnos);
1056 	READ_NODE_FIELD(opfamilies);
1057 	READ_NODE_FIELD(inputcollids);
1058 	READ_NODE_FIELD(largs);
1059 	READ_NODE_FIELD(rargs);
1060 
1061 	READ_DONE();
1062 }
1063 
1064 /*
1065  * _readCoalesceExpr
1066  */
1067 static CoalesceExpr *
_readCoalesceExpr(void)1068 _readCoalesceExpr(void)
1069 {
1070 	READ_LOCALS(CoalesceExpr);
1071 
1072 	READ_OID_FIELD(coalescetype);
1073 	READ_OID_FIELD(coalescecollid);
1074 	READ_NODE_FIELD(args);
1075 	READ_LOCATION_FIELD(location);
1076 
1077 	READ_DONE();
1078 }
1079 
1080 /*
1081  * _readMinMaxExpr
1082  */
1083 static MinMaxExpr *
_readMinMaxExpr(void)1084 _readMinMaxExpr(void)
1085 {
1086 	READ_LOCALS(MinMaxExpr);
1087 
1088 	READ_OID_FIELD(minmaxtype);
1089 	READ_OID_FIELD(minmaxcollid);
1090 	READ_OID_FIELD(inputcollid);
1091 	READ_ENUM_FIELD(op, MinMaxOp);
1092 	READ_NODE_FIELD(args);
1093 	READ_LOCATION_FIELD(location);
1094 
1095 	READ_DONE();
1096 }
1097 
1098 /*
1099  * _readSQLValueFunction
1100  */
1101 static SQLValueFunction *
_readSQLValueFunction(void)1102 _readSQLValueFunction(void)
1103 {
1104 	READ_LOCALS(SQLValueFunction);
1105 
1106 	READ_ENUM_FIELD(op, SQLValueFunctionOp);
1107 	READ_OID_FIELD(type);
1108 	READ_INT_FIELD(typmod);
1109 	READ_LOCATION_FIELD(location);
1110 
1111 	READ_DONE();
1112 }
1113 
1114 /*
1115  * _readXmlExpr
1116  */
1117 static XmlExpr *
_readXmlExpr(void)1118 _readXmlExpr(void)
1119 {
1120 	READ_LOCALS(XmlExpr);
1121 
1122 	READ_ENUM_FIELD(op, XmlExprOp);
1123 	READ_STRING_FIELD(name);
1124 	READ_NODE_FIELD(named_args);
1125 	READ_NODE_FIELD(arg_names);
1126 	READ_NODE_FIELD(args);
1127 	READ_ENUM_FIELD(xmloption, XmlOptionType);
1128 	READ_OID_FIELD(type);
1129 	READ_INT_FIELD(typmod);
1130 	READ_LOCATION_FIELD(location);
1131 
1132 	READ_DONE();
1133 }
1134 
1135 /*
1136  * _readNullTest
1137  */
1138 static NullTest *
_readNullTest(void)1139 _readNullTest(void)
1140 {
1141 	READ_LOCALS(NullTest);
1142 
1143 	READ_NODE_FIELD(arg);
1144 	READ_ENUM_FIELD(nulltesttype, NullTestType);
1145 	READ_BOOL_FIELD(argisrow);
1146 	READ_LOCATION_FIELD(location);
1147 
1148 	READ_DONE();
1149 }
1150 
1151 /*
1152  * _readBooleanTest
1153  */
1154 static BooleanTest *
_readBooleanTest(void)1155 _readBooleanTest(void)
1156 {
1157 	READ_LOCALS(BooleanTest);
1158 
1159 	READ_NODE_FIELD(arg);
1160 	READ_ENUM_FIELD(booltesttype, BoolTestType);
1161 	READ_LOCATION_FIELD(location);
1162 
1163 	READ_DONE();
1164 }
1165 
1166 /*
1167  * _readCoerceToDomain
1168  */
1169 static CoerceToDomain *
_readCoerceToDomain(void)1170 _readCoerceToDomain(void)
1171 {
1172 	READ_LOCALS(CoerceToDomain);
1173 
1174 	READ_NODE_FIELD(arg);
1175 	READ_OID_FIELD(resulttype);
1176 	READ_INT_FIELD(resulttypmod);
1177 	READ_OID_FIELD(resultcollid);
1178 	READ_ENUM_FIELD(coercionformat, CoercionForm);
1179 	READ_LOCATION_FIELD(location);
1180 
1181 	READ_DONE();
1182 }
1183 
1184 /*
1185  * _readCoerceToDomainValue
1186  */
1187 static CoerceToDomainValue *
_readCoerceToDomainValue(void)1188 _readCoerceToDomainValue(void)
1189 {
1190 	READ_LOCALS(CoerceToDomainValue);
1191 
1192 	READ_OID_FIELD(typeId);
1193 	READ_INT_FIELD(typeMod);
1194 	READ_OID_FIELD(collation);
1195 	READ_LOCATION_FIELD(location);
1196 
1197 	READ_DONE();
1198 }
1199 
1200 /*
1201  * _readSetToDefault
1202  */
1203 static SetToDefault *
_readSetToDefault(void)1204 _readSetToDefault(void)
1205 {
1206 	READ_LOCALS(SetToDefault);
1207 
1208 	READ_OID_FIELD(typeId);
1209 	READ_INT_FIELD(typeMod);
1210 	READ_OID_FIELD(collation);
1211 	READ_LOCATION_FIELD(location);
1212 
1213 	READ_DONE();
1214 }
1215 
1216 /*
1217  * _readCurrentOfExpr
1218  */
1219 static CurrentOfExpr *
_readCurrentOfExpr(void)1220 _readCurrentOfExpr(void)
1221 {
1222 	READ_LOCALS(CurrentOfExpr);
1223 
1224 	READ_UINT_FIELD(cvarno);
1225 	READ_STRING_FIELD(cursor_name);
1226 	READ_INT_FIELD(cursor_param);
1227 
1228 	READ_DONE();
1229 }
1230 
1231 /*
1232  * _readNextValueExpr
1233  */
1234 static NextValueExpr *
_readNextValueExpr(void)1235 _readNextValueExpr(void)
1236 {
1237 	READ_LOCALS(NextValueExpr);
1238 
1239 	READ_OID_FIELD(seqid);
1240 	READ_OID_FIELD(typeId);
1241 
1242 	READ_DONE();
1243 }
1244 
1245 /*
1246  * _readInferenceElem
1247  */
1248 static InferenceElem *
_readInferenceElem(void)1249 _readInferenceElem(void)
1250 {
1251 	READ_LOCALS(InferenceElem);
1252 
1253 	READ_NODE_FIELD(expr);
1254 	READ_OID_FIELD(infercollid);
1255 	READ_OID_FIELD(inferopclass);
1256 
1257 	READ_DONE();
1258 }
1259 
1260 /*
1261  * _readTargetEntry
1262  */
1263 static TargetEntry *
_readTargetEntry(void)1264 _readTargetEntry(void)
1265 {
1266 	READ_LOCALS(TargetEntry);
1267 
1268 	READ_NODE_FIELD(expr);
1269 	READ_INT_FIELD(resno);
1270 	READ_STRING_FIELD(resname);
1271 	READ_UINT_FIELD(ressortgroupref);
1272 	READ_OID_FIELD(resorigtbl);
1273 	READ_INT_FIELD(resorigcol);
1274 	READ_BOOL_FIELD(resjunk);
1275 
1276 	READ_DONE();
1277 }
1278 
1279 /*
1280  * _readRangeTblRef
1281  */
1282 static RangeTblRef *
_readRangeTblRef(void)1283 _readRangeTblRef(void)
1284 {
1285 	READ_LOCALS(RangeTblRef);
1286 
1287 	READ_INT_FIELD(rtindex);
1288 
1289 	READ_DONE();
1290 }
1291 
1292 /*
1293  * _readJoinExpr
1294  */
1295 static JoinExpr *
_readJoinExpr(void)1296 _readJoinExpr(void)
1297 {
1298 	READ_LOCALS(JoinExpr);
1299 
1300 	READ_ENUM_FIELD(jointype, JoinType);
1301 	READ_BOOL_FIELD(isNatural);
1302 	READ_NODE_FIELD(larg);
1303 	READ_NODE_FIELD(rarg);
1304 	READ_NODE_FIELD(usingClause);
1305 	READ_NODE_FIELD(quals);
1306 	READ_NODE_FIELD(alias);
1307 	READ_INT_FIELD(rtindex);
1308 
1309 	READ_DONE();
1310 }
1311 
1312 /*
1313  * _readFromExpr
1314  */
1315 static FromExpr *
_readFromExpr(void)1316 _readFromExpr(void)
1317 {
1318 	READ_LOCALS(FromExpr);
1319 
1320 	READ_NODE_FIELD(fromlist);
1321 	READ_NODE_FIELD(quals);
1322 
1323 	READ_DONE();
1324 }
1325 
1326 /*
1327  * _readOnConflictExpr
1328  */
1329 static OnConflictExpr *
_readOnConflictExpr(void)1330 _readOnConflictExpr(void)
1331 {
1332 	READ_LOCALS(OnConflictExpr);
1333 
1334 	READ_ENUM_FIELD(action, OnConflictAction);
1335 	READ_NODE_FIELD(arbiterElems);
1336 	READ_NODE_FIELD(arbiterWhere);
1337 	READ_OID_FIELD(constraint);
1338 	READ_NODE_FIELD(onConflictSet);
1339 	READ_NODE_FIELD(onConflictWhere);
1340 	READ_INT_FIELD(exclRelIndex);
1341 	READ_NODE_FIELD(exclRelTlist);
1342 
1343 	READ_DONE();
1344 }
1345 
1346 /*
1347  *	Stuff from pathnodes.h.
1348  *
1349  * Mostly we don't need to read planner nodes back in again, but some
1350  * of these also end up in plan trees.
1351  */
1352 
1353 /*
1354  * _readAppendRelInfo
1355  */
1356 static AppendRelInfo *
_readAppendRelInfo(void)1357 _readAppendRelInfo(void)
1358 {
1359 	READ_LOCALS(AppendRelInfo);
1360 
1361 	READ_UINT_FIELD(parent_relid);
1362 	READ_UINT_FIELD(child_relid);
1363 	READ_OID_FIELD(parent_reltype);
1364 	READ_OID_FIELD(child_reltype);
1365 	READ_NODE_FIELD(translated_vars);
1366 	READ_INT_FIELD(num_child_cols);
1367 	READ_ATTRNUMBER_ARRAY(parent_colnos, local_node->num_child_cols);
1368 	READ_OID_FIELD(parent_reloid);
1369 
1370 	READ_DONE();
1371 }
1372 
1373 /*
1374  *	Stuff from parsenodes.h.
1375  */
1376 
1377 /*
1378  * _readRangeTblEntry
1379  */
1380 static RangeTblEntry *
_readRangeTblEntry(void)1381 _readRangeTblEntry(void)
1382 {
1383 	READ_LOCALS(RangeTblEntry);
1384 
1385 	/* put alias + eref first to make dump more legible */
1386 	READ_NODE_FIELD(alias);
1387 	READ_NODE_FIELD(eref);
1388 	READ_ENUM_FIELD(rtekind, RTEKind);
1389 
1390 	switch (local_node->rtekind)
1391 	{
1392 		case RTE_RELATION:
1393 			READ_OID_FIELD(relid);
1394 			READ_CHAR_FIELD(relkind);
1395 			READ_INT_FIELD(rellockmode);
1396 			READ_NODE_FIELD(tablesample);
1397 			break;
1398 		case RTE_SUBQUERY:
1399 			READ_NODE_FIELD(subquery);
1400 			READ_BOOL_FIELD(security_barrier);
1401 			break;
1402 		case RTE_JOIN:
1403 			READ_ENUM_FIELD(jointype, JoinType);
1404 			READ_INT_FIELD(joinmergedcols);
1405 			READ_NODE_FIELD(joinaliasvars);
1406 			READ_NODE_FIELD(joinleftcols);
1407 			READ_NODE_FIELD(joinrightcols);
1408 			break;
1409 		case RTE_FUNCTION:
1410 			READ_NODE_FIELD(functions);
1411 			READ_BOOL_FIELD(funcordinality);
1412 			break;
1413 		case RTE_TABLEFUNC:
1414 			READ_NODE_FIELD(tablefunc);
1415 			/* The RTE must have a copy of the column type info, if any */
1416 			if (local_node->tablefunc)
1417 			{
1418 				TableFunc  *tf = local_node->tablefunc;
1419 
1420 				local_node->coltypes = tf->coltypes;
1421 				local_node->coltypmods = tf->coltypmods;
1422 				local_node->colcollations = tf->colcollations;
1423 			}
1424 			break;
1425 		case RTE_VALUES:
1426 			READ_NODE_FIELD(values_lists);
1427 			READ_NODE_FIELD(coltypes);
1428 			READ_NODE_FIELD(coltypmods);
1429 			READ_NODE_FIELD(colcollations);
1430 			break;
1431 		case RTE_CTE:
1432 			READ_STRING_FIELD(ctename);
1433 			READ_UINT_FIELD(ctelevelsup);
1434 			READ_BOOL_FIELD(self_reference);
1435 			READ_NODE_FIELD(coltypes);
1436 			READ_NODE_FIELD(coltypmods);
1437 			READ_NODE_FIELD(colcollations);
1438 			break;
1439 		case RTE_NAMEDTUPLESTORE:
1440 			READ_STRING_FIELD(enrname);
1441 			READ_FLOAT_FIELD(enrtuples);
1442 			READ_OID_FIELD(relid);
1443 			READ_NODE_FIELD(coltypes);
1444 			READ_NODE_FIELD(coltypmods);
1445 			READ_NODE_FIELD(colcollations);
1446 			break;
1447 		case RTE_RESULT:
1448 			/* no extra fields */
1449 			break;
1450 		default:
1451 			elog(ERROR, "unrecognized RTE kind: %d",
1452 				 (int) local_node->rtekind);
1453 			break;
1454 	}
1455 
1456 	READ_BOOL_FIELD(lateral);
1457 	READ_BOOL_FIELD(inh);
1458 	READ_BOOL_FIELD(inFromCl);
1459 	READ_UINT_FIELD(requiredPerms);
1460 	READ_OID_FIELD(checkAsUser);
1461 	READ_BITMAPSET_FIELD(selectedCols);
1462 	READ_BITMAPSET_FIELD(insertedCols);
1463 	READ_BITMAPSET_FIELD(updatedCols);
1464 	READ_BITMAPSET_FIELD(extraUpdatedCols);
1465 	READ_NODE_FIELD(securityQuals);
1466 
1467 	READ_DONE();
1468 }
1469 
1470 /*
1471  * _readRangeTblFunction
1472  */
1473 static RangeTblFunction *
_readRangeTblFunction(void)1474 _readRangeTblFunction(void)
1475 {
1476 	READ_LOCALS(RangeTblFunction);
1477 
1478 	READ_NODE_FIELD(funcexpr);
1479 	READ_INT_FIELD(funccolcount);
1480 	READ_NODE_FIELD(funccolnames);
1481 	READ_NODE_FIELD(funccoltypes);
1482 	READ_NODE_FIELD(funccoltypmods);
1483 	READ_NODE_FIELD(funccolcollations);
1484 	READ_BITMAPSET_FIELD(funcparams);
1485 
1486 	READ_DONE();
1487 }
1488 
1489 /*
1490  * _readTableSampleClause
1491  */
1492 static TableSampleClause *
_readTableSampleClause(void)1493 _readTableSampleClause(void)
1494 {
1495 	READ_LOCALS(TableSampleClause);
1496 
1497 	READ_OID_FIELD(tsmhandler);
1498 	READ_NODE_FIELD(args);
1499 	READ_NODE_FIELD(repeatable);
1500 
1501 	READ_DONE();
1502 }
1503 
1504 /*
1505  * _readDefElem
1506  */
1507 static DefElem *
_readDefElem(void)1508 _readDefElem(void)
1509 {
1510 	READ_LOCALS(DefElem);
1511 
1512 	READ_STRING_FIELD(defnamespace);
1513 	READ_STRING_FIELD(defname);
1514 	READ_NODE_FIELD(arg);
1515 	READ_ENUM_FIELD(defaction, DefElemAction);
1516 	READ_LOCATION_FIELD(location);
1517 
1518 	READ_DONE();
1519 }
1520 
1521 /*
1522  *	Stuff from plannodes.h.
1523  */
1524 
1525 /*
1526  * _readPlannedStmt
1527  */
1528 static PlannedStmt *
_readPlannedStmt(void)1529 _readPlannedStmt(void)
1530 {
1531 	READ_LOCALS(PlannedStmt);
1532 
1533 	READ_ENUM_FIELD(commandType, CmdType);
1534 	READ_UINT64_FIELD(queryId);
1535 	READ_BOOL_FIELD(hasReturning);
1536 	READ_BOOL_FIELD(hasModifyingCTE);
1537 	READ_BOOL_FIELD(canSetTag);
1538 	READ_BOOL_FIELD(transientPlan);
1539 	READ_BOOL_FIELD(dependsOnRole);
1540 	READ_BOOL_FIELD(parallelModeNeeded);
1541 	READ_INT_FIELD(jitFlags);
1542 	READ_NODE_FIELD(planTree);
1543 	READ_NODE_FIELD(rtable);
1544 	READ_NODE_FIELD(resultRelations);
1545 	READ_NODE_FIELD(rootResultRelations);
1546 	READ_NODE_FIELD(appendRelations);
1547 	READ_NODE_FIELD(subplans);
1548 	READ_BITMAPSET_FIELD(rewindPlanIDs);
1549 	READ_NODE_FIELD(rowMarks);
1550 	READ_NODE_FIELD(relationOids);
1551 	READ_NODE_FIELD(invalItems);
1552 	READ_NODE_FIELD(paramExecTypes);
1553 	READ_NODE_FIELD(utilityStmt);
1554 	READ_LOCATION_FIELD(stmt_location);
1555 	READ_INT_FIELD(stmt_len);
1556 
1557 	READ_DONE();
1558 }
1559 
1560 /*
1561  * ReadCommonPlan
1562  *	Assign the basic stuff of all nodes that inherit from Plan
1563  */
1564 static void
ReadCommonPlan(Plan * local_node)1565 ReadCommonPlan(Plan *local_node)
1566 {
1567 	READ_TEMP_LOCALS();
1568 
1569 	READ_FLOAT_FIELD(startup_cost);
1570 	READ_FLOAT_FIELD(total_cost);
1571 	READ_FLOAT_FIELD(plan_rows);
1572 	READ_INT_FIELD(plan_width);
1573 	READ_BOOL_FIELD(parallel_aware);
1574 	READ_BOOL_FIELD(parallel_safe);
1575 	READ_INT_FIELD(plan_node_id);
1576 	READ_NODE_FIELD(targetlist);
1577 	READ_NODE_FIELD(qual);
1578 	READ_NODE_FIELD(lefttree);
1579 	READ_NODE_FIELD(righttree);
1580 	READ_NODE_FIELD(initPlan);
1581 	READ_BITMAPSET_FIELD(extParam);
1582 	READ_BITMAPSET_FIELD(allParam);
1583 }
1584 
1585 /*
1586  * _readPlan
1587  */
1588 static Plan *
_readPlan(void)1589 _readPlan(void)
1590 {
1591 	READ_LOCALS_NO_FIELDS(Plan);
1592 
1593 	ReadCommonPlan(local_node);
1594 
1595 	READ_DONE();
1596 }
1597 
1598 /*
1599  * _readResult
1600  */
1601 static Result *
_readResult(void)1602 _readResult(void)
1603 {
1604 	READ_LOCALS(Result);
1605 
1606 	ReadCommonPlan(&local_node->plan);
1607 
1608 	READ_NODE_FIELD(resconstantqual);
1609 
1610 	READ_DONE();
1611 }
1612 
1613 /*
1614  * _readProjectSet
1615  */
1616 static ProjectSet *
_readProjectSet(void)1617 _readProjectSet(void)
1618 {
1619 	READ_LOCALS_NO_FIELDS(ProjectSet);
1620 
1621 	ReadCommonPlan(&local_node->plan);
1622 
1623 	READ_DONE();
1624 }
1625 
1626 /*
1627  * _readModifyTable
1628  */
1629 static ModifyTable *
_readModifyTable(void)1630 _readModifyTable(void)
1631 {
1632 	READ_LOCALS(ModifyTable);
1633 
1634 	ReadCommonPlan(&local_node->plan);
1635 
1636 	READ_ENUM_FIELD(operation, CmdType);
1637 	READ_BOOL_FIELD(canSetTag);
1638 	READ_UINT_FIELD(nominalRelation);
1639 	READ_UINT_FIELD(rootRelation);
1640 	READ_BOOL_FIELD(partColsUpdated);
1641 	READ_NODE_FIELD(resultRelations);
1642 	READ_INT_FIELD(resultRelIndex);
1643 	READ_INT_FIELD(rootResultRelIndex);
1644 	READ_NODE_FIELD(plans);
1645 	READ_NODE_FIELD(withCheckOptionLists);
1646 	READ_NODE_FIELD(returningLists);
1647 	READ_NODE_FIELD(fdwPrivLists);
1648 	READ_BITMAPSET_FIELD(fdwDirectModifyPlans);
1649 	READ_NODE_FIELD(rowMarks);
1650 	READ_INT_FIELD(epqParam);
1651 	READ_ENUM_FIELD(onConflictAction, OnConflictAction);
1652 	READ_NODE_FIELD(arbiterIndexes);
1653 	READ_NODE_FIELD(onConflictSet);
1654 	READ_NODE_FIELD(onConflictWhere);
1655 	READ_UINT_FIELD(exclRelRTI);
1656 	READ_NODE_FIELD(exclRelTlist);
1657 
1658 	READ_DONE();
1659 }
1660 
1661 /*
1662  * _readAppend
1663  */
1664 static Append *
_readAppend(void)1665 _readAppend(void)
1666 {
1667 	READ_LOCALS(Append);
1668 
1669 	ReadCommonPlan(&local_node->plan);
1670 
1671 	READ_BITMAPSET_FIELD(apprelids);
1672 	READ_NODE_FIELD(appendplans);
1673 	READ_INT_FIELD(first_partial_plan);
1674 	READ_NODE_FIELD(part_prune_info);
1675 
1676 	READ_DONE();
1677 }
1678 
1679 /*
1680  * _readMergeAppend
1681  */
1682 static MergeAppend *
_readMergeAppend(void)1683 _readMergeAppend(void)
1684 {
1685 	READ_LOCALS(MergeAppend);
1686 
1687 	ReadCommonPlan(&local_node->plan);
1688 
1689 	READ_BITMAPSET_FIELD(apprelids);
1690 	READ_NODE_FIELD(mergeplans);
1691 	READ_INT_FIELD(numCols);
1692 	READ_ATTRNUMBER_ARRAY(sortColIdx, local_node->numCols);
1693 	READ_OID_ARRAY(sortOperators, local_node->numCols);
1694 	READ_OID_ARRAY(collations, local_node->numCols);
1695 	READ_BOOL_ARRAY(nullsFirst, local_node->numCols);
1696 	READ_NODE_FIELD(part_prune_info);
1697 
1698 	READ_DONE();
1699 }
1700 
1701 /*
1702  * _readRecursiveUnion
1703  */
1704 static RecursiveUnion *
_readRecursiveUnion(void)1705 _readRecursiveUnion(void)
1706 {
1707 	READ_LOCALS(RecursiveUnion);
1708 
1709 	ReadCommonPlan(&local_node->plan);
1710 
1711 	READ_INT_FIELD(wtParam);
1712 	READ_INT_FIELD(numCols);
1713 	READ_ATTRNUMBER_ARRAY(dupColIdx, local_node->numCols);
1714 	READ_OID_ARRAY(dupOperators, local_node->numCols);
1715 	READ_OID_ARRAY(dupCollations, local_node->numCols);
1716 	READ_LONG_FIELD(numGroups);
1717 
1718 	READ_DONE();
1719 }
1720 
1721 /*
1722  * _readBitmapAnd
1723  */
1724 static BitmapAnd *
_readBitmapAnd(void)1725 _readBitmapAnd(void)
1726 {
1727 	READ_LOCALS(BitmapAnd);
1728 
1729 	ReadCommonPlan(&local_node->plan);
1730 
1731 	READ_NODE_FIELD(bitmapplans);
1732 
1733 	READ_DONE();
1734 }
1735 
1736 /*
1737  * _readBitmapOr
1738  */
1739 static BitmapOr *
_readBitmapOr(void)1740 _readBitmapOr(void)
1741 {
1742 	READ_LOCALS(BitmapOr);
1743 
1744 	ReadCommonPlan(&local_node->plan);
1745 
1746 	READ_BOOL_FIELD(isshared);
1747 	READ_NODE_FIELD(bitmapplans);
1748 
1749 	READ_DONE();
1750 }
1751 
1752 /*
1753  * ReadCommonScan
1754  *	Assign the basic stuff of all nodes that inherit from Scan
1755  */
1756 static void
ReadCommonScan(Scan * local_node)1757 ReadCommonScan(Scan *local_node)
1758 {
1759 	READ_TEMP_LOCALS();
1760 
1761 	ReadCommonPlan(&local_node->plan);
1762 
1763 	READ_UINT_FIELD(scanrelid);
1764 }
1765 
1766 /*
1767  * _readScan
1768  */
1769 static Scan *
_readScan(void)1770 _readScan(void)
1771 {
1772 	READ_LOCALS_NO_FIELDS(Scan);
1773 
1774 	ReadCommonScan(local_node);
1775 
1776 	READ_DONE();
1777 }
1778 
1779 /*
1780  * _readSeqScan
1781  */
1782 static SeqScan *
_readSeqScan(void)1783 _readSeqScan(void)
1784 {
1785 	READ_LOCALS_NO_FIELDS(SeqScan);
1786 
1787 	ReadCommonScan(local_node);
1788 
1789 	READ_DONE();
1790 }
1791 
1792 /*
1793  * _readSampleScan
1794  */
1795 static SampleScan *
_readSampleScan(void)1796 _readSampleScan(void)
1797 {
1798 	READ_LOCALS(SampleScan);
1799 
1800 	ReadCommonScan(&local_node->scan);
1801 
1802 	READ_NODE_FIELD(tablesample);
1803 
1804 	READ_DONE();
1805 }
1806 
1807 /*
1808  * _readIndexScan
1809  */
1810 static IndexScan *
_readIndexScan(void)1811 _readIndexScan(void)
1812 {
1813 	READ_LOCALS(IndexScan);
1814 
1815 	ReadCommonScan(&local_node->scan);
1816 
1817 	READ_OID_FIELD(indexid);
1818 	READ_NODE_FIELD(indexqual);
1819 	READ_NODE_FIELD(indexqualorig);
1820 	READ_NODE_FIELD(indexorderby);
1821 	READ_NODE_FIELD(indexorderbyorig);
1822 	READ_NODE_FIELD(indexorderbyops);
1823 	READ_ENUM_FIELD(indexorderdir, ScanDirection);
1824 
1825 	READ_DONE();
1826 }
1827 
1828 /*
1829  * _readIndexOnlyScan
1830  */
1831 static IndexOnlyScan *
_readIndexOnlyScan(void)1832 _readIndexOnlyScan(void)
1833 {
1834 	READ_LOCALS(IndexOnlyScan);
1835 
1836 	ReadCommonScan(&local_node->scan);
1837 
1838 	READ_OID_FIELD(indexid);
1839 	READ_NODE_FIELD(indexqual);
1840 	READ_NODE_FIELD(indexorderby);
1841 	READ_NODE_FIELD(indextlist);
1842 	READ_ENUM_FIELD(indexorderdir, ScanDirection);
1843 
1844 	READ_DONE();
1845 }
1846 
1847 /*
1848  * _readBitmapIndexScan
1849  */
1850 static BitmapIndexScan *
_readBitmapIndexScan(void)1851 _readBitmapIndexScan(void)
1852 {
1853 	READ_LOCALS(BitmapIndexScan);
1854 
1855 	ReadCommonScan(&local_node->scan);
1856 
1857 	READ_OID_FIELD(indexid);
1858 	READ_BOOL_FIELD(isshared);
1859 	READ_NODE_FIELD(indexqual);
1860 	READ_NODE_FIELD(indexqualorig);
1861 
1862 	READ_DONE();
1863 }
1864 
1865 /*
1866  * _readBitmapHeapScan
1867  */
1868 static BitmapHeapScan *
_readBitmapHeapScan(void)1869 _readBitmapHeapScan(void)
1870 {
1871 	READ_LOCALS(BitmapHeapScan);
1872 
1873 	ReadCommonScan(&local_node->scan);
1874 
1875 	READ_NODE_FIELD(bitmapqualorig);
1876 
1877 	READ_DONE();
1878 }
1879 
1880 /*
1881  * _readTidScan
1882  */
1883 static TidScan *
_readTidScan(void)1884 _readTidScan(void)
1885 {
1886 	READ_LOCALS(TidScan);
1887 
1888 	ReadCommonScan(&local_node->scan);
1889 
1890 	READ_NODE_FIELD(tidquals);
1891 
1892 	READ_DONE();
1893 }
1894 
1895 /*
1896  * _readSubqueryScan
1897  */
1898 static SubqueryScan *
_readSubqueryScan(void)1899 _readSubqueryScan(void)
1900 {
1901 	READ_LOCALS(SubqueryScan);
1902 
1903 	ReadCommonScan(&local_node->scan);
1904 
1905 	READ_NODE_FIELD(subplan);
1906 
1907 	READ_DONE();
1908 }
1909 
1910 /*
1911  * _readFunctionScan
1912  */
1913 static FunctionScan *
_readFunctionScan(void)1914 _readFunctionScan(void)
1915 {
1916 	READ_LOCALS(FunctionScan);
1917 
1918 	ReadCommonScan(&local_node->scan);
1919 
1920 	READ_NODE_FIELD(functions);
1921 	READ_BOOL_FIELD(funcordinality);
1922 
1923 	READ_DONE();
1924 }
1925 
1926 /*
1927  * _readValuesScan
1928  */
1929 static ValuesScan *
_readValuesScan(void)1930 _readValuesScan(void)
1931 {
1932 	READ_LOCALS(ValuesScan);
1933 
1934 	ReadCommonScan(&local_node->scan);
1935 
1936 	READ_NODE_FIELD(values_lists);
1937 
1938 	READ_DONE();
1939 }
1940 
1941 /*
1942  * _readTableFuncScan
1943  */
1944 static TableFuncScan *
_readTableFuncScan(void)1945 _readTableFuncScan(void)
1946 {
1947 	READ_LOCALS(TableFuncScan);
1948 
1949 	ReadCommonScan(&local_node->scan);
1950 
1951 	READ_NODE_FIELD(tablefunc);
1952 
1953 	READ_DONE();
1954 }
1955 
1956 /*
1957  * _readCteScan
1958  */
1959 static CteScan *
_readCteScan(void)1960 _readCteScan(void)
1961 {
1962 	READ_LOCALS(CteScan);
1963 
1964 	ReadCommonScan(&local_node->scan);
1965 
1966 	READ_INT_FIELD(ctePlanId);
1967 	READ_INT_FIELD(cteParam);
1968 
1969 	READ_DONE();
1970 }
1971 
1972 /*
1973  * _readNamedTuplestoreScan
1974  */
1975 static NamedTuplestoreScan *
_readNamedTuplestoreScan(void)1976 _readNamedTuplestoreScan(void)
1977 {
1978 	READ_LOCALS(NamedTuplestoreScan);
1979 
1980 	ReadCommonScan(&local_node->scan);
1981 
1982 	READ_STRING_FIELD(enrname);
1983 
1984 	READ_DONE();
1985 }
1986 
1987 /*
1988  * _readWorkTableScan
1989  */
1990 static WorkTableScan *
_readWorkTableScan(void)1991 _readWorkTableScan(void)
1992 {
1993 	READ_LOCALS(WorkTableScan);
1994 
1995 	ReadCommonScan(&local_node->scan);
1996 
1997 	READ_INT_FIELD(wtParam);
1998 
1999 	READ_DONE();
2000 }
2001 
2002 /*
2003  * _readForeignScan
2004  */
2005 static ForeignScan *
_readForeignScan(void)2006 _readForeignScan(void)
2007 {
2008 	READ_LOCALS(ForeignScan);
2009 
2010 	ReadCommonScan(&local_node->scan);
2011 
2012 	READ_ENUM_FIELD(operation, CmdType);
2013 	READ_OID_FIELD(fs_server);
2014 	READ_NODE_FIELD(fdw_exprs);
2015 	READ_NODE_FIELD(fdw_private);
2016 	READ_NODE_FIELD(fdw_scan_tlist);
2017 	READ_NODE_FIELD(fdw_recheck_quals);
2018 	READ_BITMAPSET_FIELD(fs_relids);
2019 	READ_BOOL_FIELD(fsSystemCol);
2020 
2021 	READ_DONE();
2022 }
2023 
2024 /*
2025  * _readCustomScan
2026  */
2027 static CustomScan *
_readCustomScan(void)2028 _readCustomScan(void)
2029 {
2030 	READ_LOCALS(CustomScan);
2031 	char	   *custom_name;
2032 	const CustomScanMethods *methods;
2033 
2034 	ReadCommonScan(&local_node->scan);
2035 
2036 	READ_UINT_FIELD(flags);
2037 	READ_NODE_FIELD(custom_plans);
2038 	READ_NODE_FIELD(custom_exprs);
2039 	READ_NODE_FIELD(custom_private);
2040 	READ_NODE_FIELD(custom_scan_tlist);
2041 	READ_BITMAPSET_FIELD(custom_relids);
2042 
2043 	/* Lookup CustomScanMethods by CustomName */
2044 	token = pg_strtok(&length); /* skip methods: */
2045 	token = pg_strtok(&length); /* CustomName */
2046 	custom_name = nullable_string(token, length);
2047 	methods = GetCustomScanMethods(custom_name, false);
2048 	local_node->methods = methods;
2049 
2050 	READ_DONE();
2051 }
2052 
2053 /*
2054  * ReadCommonJoin
2055  *	Assign the basic stuff of all nodes that inherit from Join
2056  */
2057 static void
ReadCommonJoin(Join * local_node)2058 ReadCommonJoin(Join *local_node)
2059 {
2060 	READ_TEMP_LOCALS();
2061 
2062 	ReadCommonPlan(&local_node->plan);
2063 
2064 	READ_ENUM_FIELD(jointype, JoinType);
2065 	READ_BOOL_FIELD(inner_unique);
2066 	READ_NODE_FIELD(joinqual);
2067 }
2068 
2069 /*
2070  * _readJoin
2071  */
2072 static Join *
_readJoin(void)2073 _readJoin(void)
2074 {
2075 	READ_LOCALS_NO_FIELDS(Join);
2076 
2077 	ReadCommonJoin(local_node);
2078 
2079 	READ_DONE();
2080 }
2081 
2082 /*
2083  * _readNestLoop
2084  */
2085 static NestLoop *
_readNestLoop(void)2086 _readNestLoop(void)
2087 {
2088 	READ_LOCALS(NestLoop);
2089 
2090 	ReadCommonJoin(&local_node->join);
2091 
2092 	READ_NODE_FIELD(nestParams);
2093 
2094 	READ_DONE();
2095 }
2096 
2097 /*
2098  * _readMergeJoin
2099  */
2100 static MergeJoin *
_readMergeJoin(void)2101 _readMergeJoin(void)
2102 {
2103 	int			numCols;
2104 
2105 	READ_LOCALS(MergeJoin);
2106 
2107 	ReadCommonJoin(&local_node->join);
2108 
2109 	READ_BOOL_FIELD(skip_mark_restore);
2110 	READ_NODE_FIELD(mergeclauses);
2111 
2112 	numCols = list_length(local_node->mergeclauses);
2113 
2114 	READ_OID_ARRAY(mergeFamilies, numCols);
2115 	READ_OID_ARRAY(mergeCollations, numCols);
2116 	READ_INT_ARRAY(mergeStrategies, numCols);
2117 	READ_BOOL_ARRAY(mergeNullsFirst, numCols);
2118 
2119 	READ_DONE();
2120 }
2121 
2122 /*
2123  * _readHashJoin
2124  */
2125 static HashJoin *
_readHashJoin(void)2126 _readHashJoin(void)
2127 {
2128 	READ_LOCALS(HashJoin);
2129 
2130 	ReadCommonJoin(&local_node->join);
2131 
2132 	READ_NODE_FIELD(hashclauses);
2133 	READ_NODE_FIELD(hashoperators);
2134 	READ_NODE_FIELD(hashcollations);
2135 	READ_NODE_FIELD(hashkeys);
2136 
2137 	READ_DONE();
2138 }
2139 
2140 /*
2141  * _readMaterial
2142  */
2143 static Material *
_readMaterial(void)2144 _readMaterial(void)
2145 {
2146 	READ_LOCALS_NO_FIELDS(Material);
2147 
2148 	ReadCommonPlan(&local_node->plan);
2149 
2150 	READ_DONE();
2151 }
2152 
2153 /*
2154  * ReadCommonSort
2155  *	Assign the basic stuff of all nodes that inherit from Sort
2156  */
2157 static void
ReadCommonSort(Sort * local_node)2158 ReadCommonSort(Sort *local_node)
2159 {
2160 	READ_TEMP_LOCALS();
2161 
2162 	ReadCommonPlan(&local_node->plan);
2163 
2164 	READ_INT_FIELD(numCols);
2165 	READ_ATTRNUMBER_ARRAY(sortColIdx, local_node->numCols);
2166 	READ_OID_ARRAY(sortOperators, local_node->numCols);
2167 	READ_OID_ARRAY(collations, local_node->numCols);
2168 	READ_BOOL_ARRAY(nullsFirst, local_node->numCols);
2169 }
2170 
2171 /*
2172  * _readSort
2173  */
2174 static Sort *
_readSort(void)2175 _readSort(void)
2176 {
2177 	READ_LOCALS_NO_FIELDS(Sort);
2178 
2179 	ReadCommonSort(local_node);
2180 
2181 	READ_DONE();
2182 }
2183 
2184 /*
2185  * _readIncrementalSort
2186  */
2187 static IncrementalSort *
_readIncrementalSort(void)2188 _readIncrementalSort(void)
2189 {
2190 	READ_LOCALS(IncrementalSort);
2191 
2192 	ReadCommonSort(&local_node->sort);
2193 
2194 	READ_INT_FIELD(nPresortedCols);
2195 
2196 	READ_DONE();
2197 }
2198 
2199 /*
2200  * _readGroup
2201  */
2202 static Group *
_readGroup(void)2203 _readGroup(void)
2204 {
2205 	READ_LOCALS(Group);
2206 
2207 	ReadCommonPlan(&local_node->plan);
2208 
2209 	READ_INT_FIELD(numCols);
2210 	READ_ATTRNUMBER_ARRAY(grpColIdx, local_node->numCols);
2211 	READ_OID_ARRAY(grpOperators, local_node->numCols);
2212 	READ_OID_ARRAY(grpCollations, local_node->numCols);
2213 
2214 	READ_DONE();
2215 }
2216 
2217 /*
2218  * _readAgg
2219  */
2220 static Agg *
_readAgg(void)2221 _readAgg(void)
2222 {
2223 	READ_LOCALS(Agg);
2224 
2225 	ReadCommonPlan(&local_node->plan);
2226 
2227 	READ_ENUM_FIELD(aggstrategy, AggStrategy);
2228 	READ_ENUM_FIELD(aggsplit, AggSplit);
2229 	READ_INT_FIELD(numCols);
2230 	READ_ATTRNUMBER_ARRAY(grpColIdx, local_node->numCols);
2231 	READ_OID_ARRAY(grpOperators, local_node->numCols);
2232 	READ_OID_ARRAY(grpCollations, local_node->numCols);
2233 	READ_LONG_FIELD(numGroups);
2234 	READ_UINT64_FIELD(transitionSpace);
2235 	READ_BITMAPSET_FIELD(aggParams);
2236 	READ_NODE_FIELD(groupingSets);
2237 	READ_NODE_FIELD(chain);
2238 
2239 	READ_DONE();
2240 }
2241 
2242 /*
2243  * _readWindowAgg
2244  */
2245 static WindowAgg *
_readWindowAgg(void)2246 _readWindowAgg(void)
2247 {
2248 	READ_LOCALS(WindowAgg);
2249 
2250 	ReadCommonPlan(&local_node->plan);
2251 
2252 	READ_UINT_FIELD(winref);
2253 	READ_INT_FIELD(partNumCols);
2254 	READ_ATTRNUMBER_ARRAY(partColIdx, local_node->partNumCols);
2255 	READ_OID_ARRAY(partOperators, local_node->partNumCols);
2256 	READ_OID_ARRAY(partCollations, local_node->partNumCols);
2257 	READ_INT_FIELD(ordNumCols);
2258 	READ_ATTRNUMBER_ARRAY(ordColIdx, local_node->ordNumCols);
2259 	READ_OID_ARRAY(ordOperators, local_node->ordNumCols);
2260 	READ_OID_ARRAY(ordCollations, local_node->ordNumCols);
2261 	READ_INT_FIELD(frameOptions);
2262 	READ_NODE_FIELD(startOffset);
2263 	READ_NODE_FIELD(endOffset);
2264 	READ_OID_FIELD(startInRangeFunc);
2265 	READ_OID_FIELD(endInRangeFunc);
2266 	READ_OID_FIELD(inRangeColl);
2267 	READ_BOOL_FIELD(inRangeAsc);
2268 	READ_BOOL_FIELD(inRangeNullsFirst);
2269 
2270 	READ_DONE();
2271 }
2272 
2273 /*
2274  * _readUnique
2275  */
2276 static Unique *
_readUnique(void)2277 _readUnique(void)
2278 {
2279 	READ_LOCALS(Unique);
2280 
2281 	ReadCommonPlan(&local_node->plan);
2282 
2283 	READ_INT_FIELD(numCols);
2284 	READ_ATTRNUMBER_ARRAY(uniqColIdx, local_node->numCols);
2285 	READ_OID_ARRAY(uniqOperators, local_node->numCols);
2286 	READ_OID_ARRAY(uniqCollations, local_node->numCols);
2287 
2288 	READ_DONE();
2289 }
2290 
2291 /*
2292  * _readGather
2293  */
2294 static Gather *
_readGather(void)2295 _readGather(void)
2296 {
2297 	READ_LOCALS(Gather);
2298 
2299 	ReadCommonPlan(&local_node->plan);
2300 
2301 	READ_INT_FIELD(num_workers);
2302 	READ_INT_FIELD(rescan_param);
2303 	READ_BOOL_FIELD(single_copy);
2304 	READ_BOOL_FIELD(invisible);
2305 	READ_BITMAPSET_FIELD(initParam);
2306 
2307 	READ_DONE();
2308 }
2309 
2310 /*
2311  * _readGatherMerge
2312  */
2313 static GatherMerge *
_readGatherMerge(void)2314 _readGatherMerge(void)
2315 {
2316 	READ_LOCALS(GatherMerge);
2317 
2318 	ReadCommonPlan(&local_node->plan);
2319 
2320 	READ_INT_FIELD(num_workers);
2321 	READ_INT_FIELD(rescan_param);
2322 	READ_INT_FIELD(numCols);
2323 	READ_ATTRNUMBER_ARRAY(sortColIdx, local_node->numCols);
2324 	READ_OID_ARRAY(sortOperators, local_node->numCols);
2325 	READ_OID_ARRAY(collations, local_node->numCols);
2326 	READ_BOOL_ARRAY(nullsFirst, local_node->numCols);
2327 	READ_BITMAPSET_FIELD(initParam);
2328 
2329 	READ_DONE();
2330 }
2331 
2332 /*
2333  * _readHash
2334  */
2335 static Hash *
_readHash(void)2336 _readHash(void)
2337 {
2338 	READ_LOCALS(Hash);
2339 
2340 	ReadCommonPlan(&local_node->plan);
2341 
2342 	READ_NODE_FIELD(hashkeys);
2343 	READ_OID_FIELD(skewTable);
2344 	READ_INT_FIELD(skewColumn);
2345 	READ_BOOL_FIELD(skewInherit);
2346 	READ_FLOAT_FIELD(rows_total);
2347 
2348 	READ_DONE();
2349 }
2350 
2351 /*
2352  * _readSetOp
2353  */
2354 static SetOp *
_readSetOp(void)2355 _readSetOp(void)
2356 {
2357 	READ_LOCALS(SetOp);
2358 
2359 	ReadCommonPlan(&local_node->plan);
2360 
2361 	READ_ENUM_FIELD(cmd, SetOpCmd);
2362 	READ_ENUM_FIELD(strategy, SetOpStrategy);
2363 	READ_INT_FIELD(numCols);
2364 	READ_ATTRNUMBER_ARRAY(dupColIdx, local_node->numCols);
2365 	READ_OID_ARRAY(dupOperators, local_node->numCols);
2366 	READ_OID_ARRAY(dupCollations, local_node->numCols);
2367 	READ_INT_FIELD(flagColIdx);
2368 	READ_INT_FIELD(firstFlag);
2369 	READ_LONG_FIELD(numGroups);
2370 
2371 	READ_DONE();
2372 }
2373 
2374 /*
2375  * _readLockRows
2376  */
2377 static LockRows *
_readLockRows(void)2378 _readLockRows(void)
2379 {
2380 	READ_LOCALS(LockRows);
2381 
2382 	ReadCommonPlan(&local_node->plan);
2383 
2384 	READ_NODE_FIELD(rowMarks);
2385 	READ_INT_FIELD(epqParam);
2386 
2387 	READ_DONE();
2388 }
2389 
2390 /*
2391  * _readLimit
2392  */
2393 static Limit *
_readLimit(void)2394 _readLimit(void)
2395 {
2396 	READ_LOCALS(Limit);
2397 
2398 	ReadCommonPlan(&local_node->plan);
2399 
2400 	READ_NODE_FIELD(limitOffset);
2401 	READ_NODE_FIELD(limitCount);
2402 	READ_ENUM_FIELD(limitOption, LimitOption);
2403 	READ_INT_FIELD(uniqNumCols);
2404 	READ_ATTRNUMBER_ARRAY(uniqColIdx, local_node->uniqNumCols);
2405 	READ_OID_ARRAY(uniqOperators, local_node->uniqNumCols);
2406 	READ_OID_ARRAY(uniqCollations, local_node->uniqNumCols);
2407 
2408 	READ_DONE();
2409 }
2410 
2411 /*
2412  * _readNestLoopParam
2413  */
2414 static NestLoopParam *
_readNestLoopParam(void)2415 _readNestLoopParam(void)
2416 {
2417 	READ_LOCALS(NestLoopParam);
2418 
2419 	READ_INT_FIELD(paramno);
2420 	READ_NODE_FIELD(paramval);
2421 
2422 	READ_DONE();
2423 }
2424 
2425 /*
2426  * _readPlanRowMark
2427  */
2428 static PlanRowMark *
_readPlanRowMark(void)2429 _readPlanRowMark(void)
2430 {
2431 	READ_LOCALS(PlanRowMark);
2432 
2433 	READ_UINT_FIELD(rti);
2434 	READ_UINT_FIELD(prti);
2435 	READ_UINT_FIELD(rowmarkId);
2436 	READ_ENUM_FIELD(markType, RowMarkType);
2437 	READ_INT_FIELD(allMarkTypes);
2438 	READ_ENUM_FIELD(strength, LockClauseStrength);
2439 	READ_ENUM_FIELD(waitPolicy, LockWaitPolicy);
2440 	READ_BOOL_FIELD(isParent);
2441 
2442 	READ_DONE();
2443 }
2444 
2445 static PartitionPruneInfo *
_readPartitionPruneInfo(void)2446 _readPartitionPruneInfo(void)
2447 {
2448 	READ_LOCALS(PartitionPruneInfo);
2449 
2450 	READ_NODE_FIELD(prune_infos);
2451 	READ_BITMAPSET_FIELD(other_subplans);
2452 
2453 	READ_DONE();
2454 }
2455 
2456 static PartitionedRelPruneInfo *
_readPartitionedRelPruneInfo(void)2457 _readPartitionedRelPruneInfo(void)
2458 {
2459 	READ_LOCALS(PartitionedRelPruneInfo);
2460 
2461 	READ_UINT_FIELD(rtindex);
2462 	READ_BITMAPSET_FIELD(present_parts);
2463 	READ_INT_FIELD(nparts);
2464 	READ_INT_ARRAY(subplan_map, local_node->nparts);
2465 	READ_INT_ARRAY(subpart_map, local_node->nparts);
2466 	READ_OID_ARRAY(relid_map, local_node->nparts);
2467 	READ_NODE_FIELD(initial_pruning_steps);
2468 	READ_NODE_FIELD(exec_pruning_steps);
2469 	READ_BITMAPSET_FIELD(execparamids);
2470 
2471 	READ_DONE();
2472 }
2473 
2474 static PartitionPruneStepOp *
_readPartitionPruneStepOp(void)2475 _readPartitionPruneStepOp(void)
2476 {
2477 	READ_LOCALS(PartitionPruneStepOp);
2478 
2479 	READ_INT_FIELD(step.step_id);
2480 	READ_INT_FIELD(opstrategy);
2481 	READ_NODE_FIELD(exprs);
2482 	READ_NODE_FIELD(cmpfns);
2483 	READ_BITMAPSET_FIELD(nullkeys);
2484 
2485 	READ_DONE();
2486 }
2487 
2488 static PartitionPruneStepCombine *
_readPartitionPruneStepCombine(void)2489 _readPartitionPruneStepCombine(void)
2490 {
2491 	READ_LOCALS(PartitionPruneStepCombine);
2492 
2493 	READ_INT_FIELD(step.step_id);
2494 	READ_ENUM_FIELD(combineOp, PartitionPruneCombineOp);
2495 	READ_NODE_FIELD(source_stepids);
2496 
2497 	READ_DONE();
2498 }
2499 
2500 /*
2501  * _readPlanInvalItem
2502  */
2503 static PlanInvalItem *
_readPlanInvalItem(void)2504 _readPlanInvalItem(void)
2505 {
2506 	READ_LOCALS(PlanInvalItem);
2507 
2508 	READ_INT_FIELD(cacheId);
2509 	READ_UINT_FIELD(hashValue);
2510 
2511 	READ_DONE();
2512 }
2513 
2514 /*
2515  * _readSubPlan
2516  */
2517 static SubPlan *
_readSubPlan(void)2518 _readSubPlan(void)
2519 {
2520 	READ_LOCALS(SubPlan);
2521 
2522 	READ_ENUM_FIELD(subLinkType, SubLinkType);
2523 	READ_NODE_FIELD(testexpr);
2524 	READ_NODE_FIELD(paramIds);
2525 	READ_INT_FIELD(plan_id);
2526 	READ_STRING_FIELD(plan_name);
2527 	READ_OID_FIELD(firstColType);
2528 	READ_INT_FIELD(firstColTypmod);
2529 	READ_OID_FIELD(firstColCollation);
2530 	READ_BOOL_FIELD(useHashTable);
2531 	READ_BOOL_FIELD(unknownEqFalse);
2532 	READ_BOOL_FIELD(parallel_safe);
2533 	READ_NODE_FIELD(setParam);
2534 	READ_NODE_FIELD(parParam);
2535 	READ_NODE_FIELD(args);
2536 	READ_FLOAT_FIELD(startup_cost);
2537 	READ_FLOAT_FIELD(per_call_cost);
2538 
2539 	READ_DONE();
2540 }
2541 
2542 /*
2543  * _readAlternativeSubPlan
2544  */
2545 static AlternativeSubPlan *
_readAlternativeSubPlan(void)2546 _readAlternativeSubPlan(void)
2547 {
2548 	READ_LOCALS(AlternativeSubPlan);
2549 
2550 	READ_NODE_FIELD(subplans);
2551 
2552 	READ_DONE();
2553 }
2554 
2555 /*
2556  * _readExtensibleNode
2557  */
2558 static ExtensibleNode *
_readExtensibleNode(void)2559 _readExtensibleNode(void)
2560 {
2561 	const ExtensibleNodeMethods *methods;
2562 	ExtensibleNode *local_node;
2563 	const char *extnodename;
2564 
2565 	READ_TEMP_LOCALS();
2566 
2567 	token = pg_strtok(&length); /* skip :extnodename */
2568 	token = pg_strtok(&length); /* get extnodename */
2569 
2570 	extnodename = nullable_string(token, length);
2571 	if (!extnodename)
2572 		elog(ERROR, "extnodename has to be supplied");
2573 	methods = GetExtensibleNodeMethods(extnodename, false);
2574 
2575 	local_node = (ExtensibleNode *) newNode(methods->node_size,
2576 											T_ExtensibleNode);
2577 	local_node->extnodename = extnodename;
2578 
2579 	/* deserialize the private fields */
2580 	methods->nodeRead(local_node);
2581 
2582 	READ_DONE();
2583 }
2584 
2585 /*
2586  * _readPartitionBoundSpec
2587  */
2588 static PartitionBoundSpec *
_readPartitionBoundSpec(void)2589 _readPartitionBoundSpec(void)
2590 {
2591 	READ_LOCALS(PartitionBoundSpec);
2592 
2593 	READ_CHAR_FIELD(strategy);
2594 	READ_BOOL_FIELD(is_default);
2595 	READ_INT_FIELD(modulus);
2596 	READ_INT_FIELD(remainder);
2597 	READ_NODE_FIELD(listdatums);
2598 	READ_NODE_FIELD(lowerdatums);
2599 	READ_NODE_FIELD(upperdatums);
2600 	READ_LOCATION_FIELD(location);
2601 
2602 	READ_DONE();
2603 }
2604 
2605 /*
2606  * _readPartitionRangeDatum
2607  */
2608 static PartitionRangeDatum *
_readPartitionRangeDatum(void)2609 _readPartitionRangeDatum(void)
2610 {
2611 	READ_LOCALS(PartitionRangeDatum);
2612 
2613 	READ_ENUM_FIELD(kind, PartitionRangeDatumKind);
2614 	READ_NODE_FIELD(value);
2615 	READ_LOCATION_FIELD(location);
2616 
2617 	READ_DONE();
2618 }
2619 
2620 /*
2621  * parseNodeString
2622  *
2623  * Given a character string representing a node tree, parseNodeString creates
2624  * the internal node structure.
2625  *
2626  * The string to be read must already have been loaded into pg_strtok().
2627  */
2628 Node *
parseNodeString(void)2629 parseNodeString(void)
2630 {
2631 	void	   *return_value;
2632 
2633 	READ_TEMP_LOCALS();
2634 
2635 	/* Guard against stack overflow due to overly complex expressions */
2636 	check_stack_depth();
2637 
2638 	token = pg_strtok(&length);
2639 
2640 #define MATCH(tokname, namelen) \
2641 	(length == namelen && memcmp(token, tokname, namelen) == 0)
2642 
2643 	if (MATCH("QUERY", 5))
2644 		return_value = _readQuery();
2645 	else if (MATCH("WITHCHECKOPTION", 15))
2646 		return_value = _readWithCheckOption();
2647 	else if (MATCH("SORTGROUPCLAUSE", 15))
2648 		return_value = _readSortGroupClause();
2649 	else if (MATCH("GROUPINGSET", 11))
2650 		return_value = _readGroupingSet();
2651 	else if (MATCH("WINDOWCLAUSE", 12))
2652 		return_value = _readWindowClause();
2653 	else if (MATCH("ROWMARKCLAUSE", 13))
2654 		return_value = _readRowMarkClause();
2655 	else if (MATCH("COMMONTABLEEXPR", 15))
2656 		return_value = _readCommonTableExpr();
2657 	else if (MATCH("SETOPERATIONSTMT", 16))
2658 		return_value = _readSetOperationStmt();
2659 	else if (MATCH("ALIAS", 5))
2660 		return_value = _readAlias();
2661 	else if (MATCH("RANGEVAR", 8))
2662 		return_value = _readRangeVar();
2663 	else if (MATCH("INTOCLAUSE", 10))
2664 		return_value = _readIntoClause();
2665 	else if (MATCH("TABLEFUNC", 9))
2666 		return_value = _readTableFunc();
2667 	else if (MATCH("VAR", 3))
2668 		return_value = _readVar();
2669 	else if (MATCH("CONST", 5))
2670 		return_value = _readConst();
2671 	else if (MATCH("PARAM", 5))
2672 		return_value = _readParam();
2673 	else if (MATCH("AGGREF", 6))
2674 		return_value = _readAggref();
2675 	else if (MATCH("GROUPINGFUNC", 12))
2676 		return_value = _readGroupingFunc();
2677 	else if (MATCH("WINDOWFUNC", 10))
2678 		return_value = _readWindowFunc();
2679 	else if (MATCH("SUBSCRIPTINGREF", 15))
2680 		return_value = _readSubscriptingRef();
2681 	else if (MATCH("FUNCEXPR", 8))
2682 		return_value = _readFuncExpr();
2683 	else if (MATCH("NAMEDARGEXPR", 12))
2684 		return_value = _readNamedArgExpr();
2685 	else if (MATCH("OPEXPR", 6))
2686 		return_value = _readOpExpr();
2687 	else if (MATCH("DISTINCTEXPR", 12))
2688 		return_value = _readDistinctExpr();
2689 	else if (MATCH("NULLIFEXPR", 10))
2690 		return_value = _readNullIfExpr();
2691 	else if (MATCH("SCALARARRAYOPEXPR", 17))
2692 		return_value = _readScalarArrayOpExpr();
2693 	else if (MATCH("BOOLEXPR", 8))
2694 		return_value = _readBoolExpr();
2695 	else if (MATCH("SUBLINK", 7))
2696 		return_value = _readSubLink();
2697 	else if (MATCH("FIELDSELECT", 11))
2698 		return_value = _readFieldSelect();
2699 	else if (MATCH("FIELDSTORE", 10))
2700 		return_value = _readFieldStore();
2701 	else if (MATCH("RELABELTYPE", 11))
2702 		return_value = _readRelabelType();
2703 	else if (MATCH("COERCEVIAIO", 11))
2704 		return_value = _readCoerceViaIO();
2705 	else if (MATCH("ARRAYCOERCEEXPR", 15))
2706 		return_value = _readArrayCoerceExpr();
2707 	else if (MATCH("CONVERTROWTYPEEXPR", 18))
2708 		return_value = _readConvertRowtypeExpr();
2709 	else if (MATCH("COLLATE", 7))
2710 		return_value = _readCollateExpr();
2711 	else if (MATCH("CASE", 4))
2712 		return_value = _readCaseExpr();
2713 	else if (MATCH("WHEN", 4))
2714 		return_value = _readCaseWhen();
2715 	else if (MATCH("CASETESTEXPR", 12))
2716 		return_value = _readCaseTestExpr();
2717 	else if (MATCH("ARRAY", 5))
2718 		return_value = _readArrayExpr();
2719 	else if (MATCH("ROW", 3))
2720 		return_value = _readRowExpr();
2721 	else if (MATCH("ROWCOMPARE", 10))
2722 		return_value = _readRowCompareExpr();
2723 	else if (MATCH("COALESCE", 8))
2724 		return_value = _readCoalesceExpr();
2725 	else if (MATCH("MINMAX", 6))
2726 		return_value = _readMinMaxExpr();
2727 	else if (MATCH("SQLVALUEFUNCTION", 16))
2728 		return_value = _readSQLValueFunction();
2729 	else if (MATCH("XMLEXPR", 7))
2730 		return_value = _readXmlExpr();
2731 	else if (MATCH("NULLTEST", 8))
2732 		return_value = _readNullTest();
2733 	else if (MATCH("BOOLEANTEST", 11))
2734 		return_value = _readBooleanTest();
2735 	else if (MATCH("COERCETODOMAIN", 14))
2736 		return_value = _readCoerceToDomain();
2737 	else if (MATCH("COERCETODOMAINVALUE", 19))
2738 		return_value = _readCoerceToDomainValue();
2739 	else if (MATCH("SETTODEFAULT", 12))
2740 		return_value = _readSetToDefault();
2741 	else if (MATCH("CURRENTOFEXPR", 13))
2742 		return_value = _readCurrentOfExpr();
2743 	else if (MATCH("NEXTVALUEEXPR", 13))
2744 		return_value = _readNextValueExpr();
2745 	else if (MATCH("INFERENCEELEM", 13))
2746 		return_value = _readInferenceElem();
2747 	else if (MATCH("TARGETENTRY", 11))
2748 		return_value = _readTargetEntry();
2749 	else if (MATCH("RANGETBLREF", 11))
2750 		return_value = _readRangeTblRef();
2751 	else if (MATCH("JOINEXPR", 8))
2752 		return_value = _readJoinExpr();
2753 	else if (MATCH("FROMEXPR", 8))
2754 		return_value = _readFromExpr();
2755 	else if (MATCH("ONCONFLICTEXPR", 14))
2756 		return_value = _readOnConflictExpr();
2757 	else if (MATCH("APPENDRELINFO", 13))
2758 		return_value = _readAppendRelInfo();
2759 	else if (MATCH("RTE", 3))
2760 		return_value = _readRangeTblEntry();
2761 	else if (MATCH("RANGETBLFUNCTION", 16))
2762 		return_value = _readRangeTblFunction();
2763 	else if (MATCH("TABLESAMPLECLAUSE", 17))
2764 		return_value = _readTableSampleClause();
2765 	else if (MATCH("NOTIFY", 6))
2766 		return_value = _readNotifyStmt();
2767 	else if (MATCH("DEFELEM", 7))
2768 		return_value = _readDefElem();
2769 	else if (MATCH("DECLARECURSOR", 13))
2770 		return_value = _readDeclareCursorStmt();
2771 	else if (MATCH("PLANNEDSTMT", 11))
2772 		return_value = _readPlannedStmt();
2773 	else if (MATCH("PLAN", 4))
2774 		return_value = _readPlan();
2775 	else if (MATCH("RESULT", 6))
2776 		return_value = _readResult();
2777 	else if (MATCH("PROJECTSET", 10))
2778 		return_value = _readProjectSet();
2779 	else if (MATCH("MODIFYTABLE", 11))
2780 		return_value = _readModifyTable();
2781 	else if (MATCH("APPEND", 6))
2782 		return_value = _readAppend();
2783 	else if (MATCH("MERGEAPPEND", 11))
2784 		return_value = _readMergeAppend();
2785 	else if (MATCH("RECURSIVEUNION", 14))
2786 		return_value = _readRecursiveUnion();
2787 	else if (MATCH("BITMAPAND", 9))
2788 		return_value = _readBitmapAnd();
2789 	else if (MATCH("BITMAPOR", 8))
2790 		return_value = _readBitmapOr();
2791 	else if (MATCH("SCAN", 4))
2792 		return_value = _readScan();
2793 	else if (MATCH("SEQSCAN", 7))
2794 		return_value = _readSeqScan();
2795 	else if (MATCH("SAMPLESCAN", 10))
2796 		return_value = _readSampleScan();
2797 	else if (MATCH("INDEXSCAN", 9))
2798 		return_value = _readIndexScan();
2799 	else if (MATCH("INDEXONLYSCAN", 13))
2800 		return_value = _readIndexOnlyScan();
2801 	else if (MATCH("BITMAPINDEXSCAN", 15))
2802 		return_value = _readBitmapIndexScan();
2803 	else if (MATCH("BITMAPHEAPSCAN", 14))
2804 		return_value = _readBitmapHeapScan();
2805 	else if (MATCH("TIDSCAN", 7))
2806 		return_value = _readTidScan();
2807 	else if (MATCH("SUBQUERYSCAN", 12))
2808 		return_value = _readSubqueryScan();
2809 	else if (MATCH("FUNCTIONSCAN", 12))
2810 		return_value = _readFunctionScan();
2811 	else if (MATCH("VALUESSCAN", 10))
2812 		return_value = _readValuesScan();
2813 	else if (MATCH("TABLEFUNCSCAN", 13))
2814 		return_value = _readTableFuncScan();
2815 	else if (MATCH("CTESCAN", 7))
2816 		return_value = _readCteScan();
2817 	else if (MATCH("NAMEDTUPLESTORESCAN", 19))
2818 		return_value = _readNamedTuplestoreScan();
2819 	else if (MATCH("WORKTABLESCAN", 13))
2820 		return_value = _readWorkTableScan();
2821 	else if (MATCH("FOREIGNSCAN", 11))
2822 		return_value = _readForeignScan();
2823 	else if (MATCH("CUSTOMSCAN", 10))
2824 		return_value = _readCustomScan();
2825 	else if (MATCH("JOIN", 4))
2826 		return_value = _readJoin();
2827 	else if (MATCH("NESTLOOP", 8))
2828 		return_value = _readNestLoop();
2829 	else if (MATCH("MERGEJOIN", 9))
2830 		return_value = _readMergeJoin();
2831 	else if (MATCH("HASHJOIN", 8))
2832 		return_value = _readHashJoin();
2833 	else if (MATCH("MATERIAL", 8))
2834 		return_value = _readMaterial();
2835 	else if (MATCH("SORT", 4))
2836 		return_value = _readSort();
2837 	else if (MATCH("INCREMENTALSORT", 15))
2838 		return_value = _readIncrementalSort();
2839 	else if (MATCH("GROUP", 5))
2840 		return_value = _readGroup();
2841 	else if (MATCH("AGG", 3))
2842 		return_value = _readAgg();
2843 	else if (MATCH("WINDOWAGG", 9))
2844 		return_value = _readWindowAgg();
2845 	else if (MATCH("UNIQUE", 6))
2846 		return_value = _readUnique();
2847 	else if (MATCH("GATHER", 6))
2848 		return_value = _readGather();
2849 	else if (MATCH("GATHERMERGE", 11))
2850 		return_value = _readGatherMerge();
2851 	else if (MATCH("HASH", 4))
2852 		return_value = _readHash();
2853 	else if (MATCH("SETOP", 5))
2854 		return_value = _readSetOp();
2855 	else if (MATCH("LOCKROWS", 8))
2856 		return_value = _readLockRows();
2857 	else if (MATCH("LIMIT", 5))
2858 		return_value = _readLimit();
2859 	else if (MATCH("NESTLOOPPARAM", 13))
2860 		return_value = _readNestLoopParam();
2861 	else if (MATCH("PLANROWMARK", 11))
2862 		return_value = _readPlanRowMark();
2863 	else if (MATCH("PARTITIONPRUNEINFO", 18))
2864 		return_value = _readPartitionPruneInfo();
2865 	else if (MATCH("PARTITIONEDRELPRUNEINFO", 23))
2866 		return_value = _readPartitionedRelPruneInfo();
2867 	else if (MATCH("PARTITIONPRUNESTEPOP", 20))
2868 		return_value = _readPartitionPruneStepOp();
2869 	else if (MATCH("PARTITIONPRUNESTEPCOMBINE", 25))
2870 		return_value = _readPartitionPruneStepCombine();
2871 	else if (MATCH("PLANINVALITEM", 13))
2872 		return_value = _readPlanInvalItem();
2873 	else if (MATCH("SUBPLAN", 7))
2874 		return_value = _readSubPlan();
2875 	else if (MATCH("ALTERNATIVESUBPLAN", 18))
2876 		return_value = _readAlternativeSubPlan();
2877 	else if (MATCH("EXTENSIBLENODE", 14))
2878 		return_value = _readExtensibleNode();
2879 	else if (MATCH("PARTITIONBOUNDSPEC", 18))
2880 		return_value = _readPartitionBoundSpec();
2881 	else if (MATCH("PARTITIONRANGEDATUM", 19))
2882 		return_value = _readPartitionRangeDatum();
2883 	else
2884 	{
2885 		elog(ERROR, "badly formatted node string \"%.32s\"...", token);
2886 		return_value = NULL;	/* keep compiler quiet */
2887 	}
2888 
2889 	return (Node *) return_value;
2890 }
2891 
2892 
2893 /*
2894  * readDatum
2895  *
2896  * Given a string representation of a constant, recreate the appropriate
2897  * Datum.  The string representation embeds length info, but not byValue,
2898  * so we must be told that.
2899  */
2900 Datum
readDatum(bool typbyval)2901 readDatum(bool typbyval)
2902 {
2903 	Size		length,
2904 				i;
2905 	int			tokenLength;
2906 	const char *token;
2907 	Datum		res;
2908 	char	   *s;
2909 
2910 	/*
2911 	 * read the actual length of the value
2912 	 */
2913 	token = pg_strtok(&tokenLength);
2914 	length = atoui(token);
2915 
2916 	token = pg_strtok(&tokenLength);	/* read the '[' */
2917 	if (token == NULL || token[0] != '[')
2918 		elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %zu",
2919 			 token ? token : "[NULL]", length);
2920 
2921 	if (typbyval)
2922 	{
2923 		if (length > (Size) sizeof(Datum))
2924 			elog(ERROR, "byval datum but length = %zu", length);
2925 		res = (Datum) 0;
2926 		s = (char *) (&res);
2927 		for (i = 0; i < (Size) sizeof(Datum); i++)
2928 		{
2929 			token = pg_strtok(&tokenLength);
2930 			s[i] = (char) atoi(token);
2931 		}
2932 	}
2933 	else if (length <= 0)
2934 		res = (Datum) NULL;
2935 	else
2936 	{
2937 		s = (char *) palloc(length);
2938 		for (i = 0; i < length; i++)
2939 		{
2940 			token = pg_strtok(&tokenLength);
2941 			s[i] = (char) atoi(token);
2942 		}
2943 		res = PointerGetDatum(s);
2944 	}
2945 
2946 	token = pg_strtok(&tokenLength);	/* read the ']' */
2947 	if (token == NULL || token[0] != ']')
2948 		elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %zu",
2949 			 token ? token : "[NULL]", length);
2950 
2951 	return res;
2952 }
2953 
2954 /*
2955  * readAttrNumberCols
2956  */
2957 AttrNumber *
readAttrNumberCols(int numCols)2958 readAttrNumberCols(int numCols)
2959 {
2960 	int			tokenLength,
2961 				i;
2962 	const char *token;
2963 	AttrNumber *attr_vals;
2964 
2965 	if (numCols <= 0)
2966 		return NULL;
2967 
2968 	attr_vals = (AttrNumber *) palloc(numCols * sizeof(AttrNumber));
2969 	for (i = 0; i < numCols; i++)
2970 	{
2971 		token = pg_strtok(&tokenLength);
2972 		attr_vals[i] = atoi(token);
2973 	}
2974 
2975 	return attr_vals;
2976 }
2977 
2978 /*
2979  * readOidCols
2980  */
2981 Oid *
readOidCols(int numCols)2982 readOidCols(int numCols)
2983 {
2984 	int			tokenLength,
2985 				i;
2986 	const char *token;
2987 	Oid		   *oid_vals;
2988 
2989 	if (numCols <= 0)
2990 		return NULL;
2991 
2992 	oid_vals = (Oid *) palloc(numCols * sizeof(Oid));
2993 	for (i = 0; i < numCols; i++)
2994 	{
2995 		token = pg_strtok(&tokenLength);
2996 		oid_vals[i] = atooid(token);
2997 	}
2998 
2999 	return oid_vals;
3000 }
3001 
3002 /*
3003  * readIntCols
3004  */
3005 int *
readIntCols(int numCols)3006 readIntCols(int numCols)
3007 {
3008 	int			tokenLength,
3009 				i;
3010 	const char *token;
3011 	int		   *int_vals;
3012 
3013 	if (numCols <= 0)
3014 		return NULL;
3015 
3016 	int_vals = (int *) palloc(numCols * sizeof(int));
3017 	for (i = 0; i < numCols; i++)
3018 	{
3019 		token = pg_strtok(&tokenLength);
3020 		int_vals[i] = atoi(token);
3021 	}
3022 
3023 	return int_vals;
3024 }
3025 
3026 /*
3027  * readBoolCols
3028  */
3029 bool *
readBoolCols(int numCols)3030 readBoolCols(int numCols)
3031 {
3032 	int			tokenLength,
3033 				i;
3034 	const char *token;
3035 	bool	   *bool_vals;
3036 
3037 	if (numCols <= 0)
3038 		return NULL;
3039 
3040 	bool_vals = (bool *) palloc(numCols * sizeof(bool));
3041 	for (i = 0; i < numCols; i++)
3042 	{
3043 		token = pg_strtok(&tokenLength);
3044 		bool_vals[i] = strtobool(token);
3045 	}
3046 
3047 	return bool_vals;
3048 }
3049