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