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