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