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