]> granicus.if.org Git - postgresql/blob - src/backend/nodes/readfuncs.c
Provide readfuncs support for custom scans.
[postgresql] / src / backend / nodes / readfuncs.c
1 /*-------------------------------------------------------------------------
2  *
3  * readfuncs.c
4  *        Reader functions for Postgres tree nodes.
5  *
6  * Portions Copyright (c) 1996-2015, 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
1400         READ_DONE();
1401 }
1402
1403 /*
1404  * ReadCommonPlan
1405  *      Assign the basic stuff of all nodes that inherit from Plan
1406  */
1407 static void
1408 ReadCommonPlan(Plan *local_node)
1409 {
1410         READ_TEMP_LOCALS();
1411
1412         READ_FLOAT_FIELD(startup_cost);
1413         READ_FLOAT_FIELD(total_cost);
1414         READ_FLOAT_FIELD(plan_rows);
1415         READ_INT_FIELD(plan_width);
1416         READ_BOOL_FIELD(parallel_aware);
1417         READ_INT_FIELD(plan_node_id);
1418         READ_NODE_FIELD(targetlist);
1419         READ_NODE_FIELD(qual);
1420         READ_NODE_FIELD(lefttree);
1421         READ_NODE_FIELD(righttree);
1422         READ_NODE_FIELD(initPlan);
1423         READ_BITMAPSET_FIELD(extParam);
1424         READ_BITMAPSET_FIELD(allParam);
1425 }
1426
1427 /*
1428  * _readPlan
1429  */
1430 static Plan *
1431 _readPlan(void)
1432 {
1433         READ_LOCALS_NO_FIELDS(Plan);
1434
1435         ReadCommonPlan(local_node);
1436
1437         READ_DONE();
1438 }
1439
1440 /*
1441  * _readResult
1442  */
1443 static Result *
1444 _readResult(void)
1445 {
1446         READ_LOCALS(Result);
1447
1448         ReadCommonPlan(&local_node->plan);
1449
1450         READ_NODE_FIELD(resconstantqual);
1451
1452         READ_DONE();
1453 }
1454
1455 /*
1456  * _readModifyTable
1457  */
1458 static ModifyTable *
1459 _readModifyTable(void)
1460 {
1461         READ_LOCALS(ModifyTable);
1462
1463         ReadCommonPlan(&local_node->plan);
1464
1465         READ_ENUM_FIELD(operation, CmdType);
1466         READ_BOOL_FIELD(canSetTag);
1467         READ_UINT_FIELD(nominalRelation);
1468         READ_NODE_FIELD(resultRelations);
1469         READ_INT_FIELD(resultRelIndex);
1470         READ_NODE_FIELD(plans);
1471         READ_NODE_FIELD(withCheckOptionLists);
1472         READ_NODE_FIELD(returningLists);
1473         READ_NODE_FIELD(fdwPrivLists);
1474         READ_NODE_FIELD(rowMarks);
1475         READ_INT_FIELD(epqParam);
1476         READ_ENUM_FIELD(onConflictAction, OnConflictAction);
1477         READ_NODE_FIELD(arbiterIndexes);
1478         READ_NODE_FIELD(onConflictSet);
1479         READ_NODE_FIELD(onConflictWhere);
1480         READ_UINT_FIELD(exclRelRTI);
1481         READ_NODE_FIELD(exclRelTlist);
1482
1483         READ_DONE();
1484 }
1485
1486 /*
1487  * _readAppend
1488  */
1489 static Append *
1490 _readAppend(void)
1491 {
1492         READ_LOCALS(Append);
1493
1494         ReadCommonPlan(&local_node->plan);
1495
1496         READ_NODE_FIELD(appendplans);
1497
1498         READ_DONE();
1499 }
1500
1501 /*
1502  * _readMergeAppend
1503  */
1504 static MergeAppend *
1505 _readMergeAppend(void)
1506 {
1507         READ_LOCALS(MergeAppend);
1508
1509         ReadCommonPlan(&local_node->plan);
1510
1511         READ_NODE_FIELD(mergeplans);
1512         READ_INT_FIELD(numCols);
1513         READ_ATTRNUMBER_ARRAY(sortColIdx, local_node->numCols);
1514         READ_OID_ARRAY(sortOperators, local_node->numCols);
1515         READ_OID_ARRAY(collations, local_node->numCols);
1516         READ_BOOL_ARRAY(nullsFirst, local_node->numCols);
1517
1518         READ_DONE();
1519 }
1520
1521 /*
1522  * _readRecursiveUnion
1523  */
1524 static RecursiveUnion *
1525 _readRecursiveUnion(void)
1526 {
1527         READ_LOCALS(RecursiveUnion);
1528
1529         ReadCommonPlan(&local_node->plan);
1530
1531         READ_INT_FIELD(wtParam);
1532         READ_INT_FIELD(numCols);
1533         READ_ATTRNUMBER_ARRAY(dupColIdx, local_node->numCols);
1534         READ_OID_ARRAY(dupOperators, local_node->numCols);
1535         READ_LONG_FIELD(numGroups);
1536
1537         READ_DONE();
1538 }
1539
1540 /*
1541  * _readBitmapAnd
1542  */
1543 static BitmapAnd *
1544 _readBitmapAnd(void)
1545 {
1546         READ_LOCALS(BitmapAnd);
1547
1548         ReadCommonPlan(&local_node->plan);
1549
1550         READ_NODE_FIELD(bitmapplans);
1551
1552         READ_DONE();
1553 }
1554
1555 /*
1556  * _readBitmapOr
1557  */
1558 static BitmapOr *
1559 _readBitmapOr(void)
1560 {
1561         READ_LOCALS(BitmapOr);
1562
1563         ReadCommonPlan(&local_node->plan);
1564
1565         READ_NODE_FIELD(bitmapplans);
1566
1567         READ_DONE();
1568 }
1569
1570 /*
1571  * ReadCommonScan
1572  *      Assign the basic stuff of all nodes that inherit from Scan
1573  */
1574 static void
1575 ReadCommonScan(Scan *local_node)
1576 {
1577         READ_TEMP_LOCALS();
1578
1579         ReadCommonPlan(&local_node->plan);
1580
1581         READ_UINT_FIELD(scanrelid);
1582 }
1583
1584 /*
1585  * _readScan
1586  */
1587 static Scan *
1588 _readScan(void)
1589 {
1590         READ_LOCALS_NO_FIELDS(Scan);
1591
1592         ReadCommonScan(local_node);
1593
1594         READ_DONE();
1595 }
1596
1597 /*
1598  * _readSeqScan
1599  */
1600 static SeqScan *
1601 _readSeqScan(void)
1602 {
1603         READ_LOCALS_NO_FIELDS(SeqScan);
1604
1605         ReadCommonScan(local_node);
1606
1607         READ_DONE();
1608 }
1609
1610 /*
1611  * _readSampleScan
1612  */
1613 static SampleScan *
1614 _readSampleScan(void)
1615 {
1616         READ_LOCALS(SampleScan);
1617
1618         ReadCommonScan(&local_node->scan);
1619
1620         READ_NODE_FIELD(tablesample);
1621
1622         READ_DONE();
1623 }
1624
1625 /*
1626  * _readIndexScan
1627  */
1628 static IndexScan *
1629 _readIndexScan(void)
1630 {
1631         READ_LOCALS(IndexScan);
1632
1633         ReadCommonScan(&local_node->scan);
1634
1635         READ_OID_FIELD(indexid);
1636         READ_NODE_FIELD(indexqual);
1637         READ_NODE_FIELD(indexqualorig);
1638         READ_NODE_FIELD(indexorderby);
1639         READ_NODE_FIELD(indexorderbyorig);
1640         READ_NODE_FIELD(indexorderbyops);
1641         READ_ENUM_FIELD(indexorderdir, ScanDirection);
1642
1643         READ_DONE();
1644 }
1645
1646 /*
1647  * _readIndexOnlyScan
1648  */
1649 static IndexOnlyScan *
1650 _readIndexOnlyScan(void)
1651 {
1652         READ_LOCALS(IndexOnlyScan);
1653
1654         ReadCommonScan(&local_node->scan);
1655
1656         READ_OID_FIELD(indexid);
1657         READ_NODE_FIELD(indexqual);
1658         READ_NODE_FIELD(indexorderby);
1659         READ_NODE_FIELD(indextlist);
1660         READ_ENUM_FIELD(indexorderdir, ScanDirection);
1661
1662         READ_DONE();
1663 }
1664
1665 /*
1666  * _readBitmapIndexScan
1667  */
1668 static BitmapIndexScan *
1669 _readBitmapIndexScan(void)
1670 {
1671         READ_LOCALS(BitmapIndexScan);
1672
1673         ReadCommonScan(&local_node->scan);
1674
1675         READ_OID_FIELD(indexid);
1676         READ_NODE_FIELD(indexqual);
1677         READ_NODE_FIELD(indexqualorig);
1678
1679         READ_DONE();
1680 }
1681
1682 /*
1683  * _readBitmapHeapScan
1684  */
1685 static BitmapHeapScan *
1686 _readBitmapHeapScan(void)
1687 {
1688         READ_LOCALS(BitmapHeapScan);
1689
1690         ReadCommonScan(&local_node->scan);
1691
1692         READ_NODE_FIELD(bitmapqualorig);
1693
1694         READ_DONE();
1695 }
1696
1697 /*
1698  * _readTidScan
1699  */
1700 static TidScan *
1701 _readTidScan(void)
1702 {
1703         READ_LOCALS(TidScan);
1704
1705         ReadCommonScan(&local_node->scan);
1706
1707         READ_NODE_FIELD(tidquals);
1708
1709         READ_DONE();
1710 }
1711
1712 /*
1713  * _readSubqueryScan
1714  */
1715 static SubqueryScan *
1716 _readSubqueryScan(void)
1717 {
1718         READ_LOCALS(SubqueryScan);
1719
1720         ReadCommonScan(&local_node->scan);
1721
1722         READ_NODE_FIELD(subplan);
1723
1724         READ_DONE();
1725 }
1726
1727 /*
1728  * _readFunctionScan
1729  */
1730 static FunctionScan *
1731 _readFunctionScan(void)
1732 {
1733         READ_LOCALS(FunctionScan);
1734
1735         ReadCommonScan(&local_node->scan);
1736
1737         READ_NODE_FIELD(functions);
1738         READ_BOOL_FIELD(funcordinality);
1739
1740         READ_DONE();
1741 }
1742
1743 /*
1744  * _readValuesScan
1745  */
1746 static ValuesScan *
1747 _readValuesScan(void)
1748 {
1749         READ_LOCALS(ValuesScan);
1750
1751         ReadCommonScan(&local_node->scan);
1752
1753         READ_NODE_FIELD(values_lists);
1754
1755         READ_DONE();
1756 }
1757
1758 /*
1759  * _readCteScan
1760  */
1761 static CteScan *
1762 _readCteScan(void)
1763 {
1764         READ_LOCALS(CteScan);
1765
1766         ReadCommonScan(&local_node->scan);
1767
1768         READ_INT_FIELD(ctePlanId);
1769         READ_INT_FIELD(cteParam);
1770
1771         READ_DONE();
1772 }
1773
1774 /*
1775  * _readWorkTableScan
1776  */
1777 static WorkTableScan *
1778 _readWorkTableScan(void)
1779 {
1780         READ_LOCALS(WorkTableScan);
1781
1782         ReadCommonScan(&local_node->scan);
1783
1784         READ_INT_FIELD(wtParam);
1785
1786         READ_DONE();
1787 }
1788
1789 /*
1790  * _readForeignScan
1791  */
1792 static ForeignScan *
1793 _readForeignScan(void)
1794 {
1795         READ_LOCALS(ForeignScan);
1796
1797         ReadCommonScan(&local_node->scan);
1798
1799         READ_OID_FIELD(fs_server);
1800         READ_NODE_FIELD(fdw_exprs);
1801         READ_NODE_FIELD(fdw_private);
1802         READ_NODE_FIELD(fdw_scan_tlist);
1803         READ_NODE_FIELD(fdw_recheck_quals);
1804         READ_BITMAPSET_FIELD(fs_relids);
1805         READ_BOOL_FIELD(fsSystemCol);
1806
1807         READ_DONE();
1808 }
1809
1810 /*
1811  * _readCustomScan
1812  */
1813 static CustomScan *
1814 _readCustomScan(void)
1815 {
1816         READ_LOCALS(CustomScan);
1817         char       *library_name;
1818         char       *symbol_name;
1819         const CustomScanMethods *methods;
1820
1821         ReadCommonScan(&local_node->scan);
1822
1823         READ_UINT_FIELD(flags);
1824         READ_NODE_FIELD(custom_plans);
1825         READ_NODE_FIELD(custom_exprs);
1826         READ_NODE_FIELD(custom_private);
1827         READ_NODE_FIELD(custom_scan_tlist);
1828         READ_BITMAPSET_FIELD(custom_relids);
1829
1830         /*
1831          * Reconstruction of methods using library and symbol name
1832          */
1833         token = pg_strtok(&length);             /* skip methods: */
1834         token = pg_strtok(&length);             /* LibraryName */
1835         library_name = nullable_string(token, length);
1836         token = pg_strtok(&length);             /* SymbolName */
1837         symbol_name = nullable_string(token, length);
1838
1839         methods = (const CustomScanMethods *)
1840                 load_external_function(library_name, symbol_name, true, NULL);
1841         Assert(strcmp(methods->LibraryName, library_name) == 0 &&
1842                    strcmp(methods->SymbolName, symbol_name) == 0);
1843         local_node->methods = methods;
1844
1845         READ_DONE();
1846 }
1847
1848 /*
1849  * ReadCommonJoin
1850  *      Assign the basic stuff of all nodes that inherit from Join
1851  */
1852 static void
1853 ReadCommonJoin(Join *local_node)
1854 {
1855         READ_TEMP_LOCALS();
1856
1857         ReadCommonPlan(&local_node->plan);
1858
1859         READ_ENUM_FIELD(jointype, JoinType);
1860         READ_NODE_FIELD(joinqual);
1861 }
1862
1863 /*
1864  * _readJoin
1865  */
1866 static Join *
1867 _readJoin(void)
1868 {
1869         READ_LOCALS_NO_FIELDS(Join);
1870
1871         ReadCommonJoin(local_node);
1872
1873         READ_DONE();
1874 }
1875
1876 /*
1877  * _readNestLoop
1878  */
1879 static NestLoop *
1880 _readNestLoop(void)
1881 {
1882         READ_LOCALS(NestLoop);
1883
1884         ReadCommonJoin(&local_node->join);
1885
1886         READ_NODE_FIELD(nestParams);
1887
1888         READ_DONE();
1889 }
1890
1891 /*
1892  * _readMergeJoin
1893  */
1894 static MergeJoin *
1895 _readMergeJoin(void)
1896 {
1897         int                     numCols;
1898
1899         READ_LOCALS(MergeJoin);
1900
1901         ReadCommonJoin(&local_node->join);
1902
1903         READ_NODE_FIELD(mergeclauses);
1904
1905         numCols = list_length(local_node->mergeclauses);
1906
1907         READ_OID_ARRAY(mergeFamilies, numCols);
1908         READ_OID_ARRAY(mergeCollations, numCols);
1909         READ_INT_ARRAY(mergeStrategies, numCols);
1910         READ_BOOL_ARRAY(mergeNullsFirst, numCols);
1911
1912         READ_DONE();
1913 }
1914
1915 /*
1916  * _readHashJoin
1917  */
1918 static HashJoin *
1919 _readHashJoin(void)
1920 {
1921         READ_LOCALS(HashJoin);
1922
1923         ReadCommonJoin(&local_node->join);
1924
1925         READ_NODE_FIELD(hashclauses);
1926
1927         READ_DONE();
1928 }
1929
1930 /*
1931  * _readMaterial
1932  */
1933 static Material *
1934 _readMaterial(void)
1935 {
1936         READ_LOCALS_NO_FIELDS(Material);
1937
1938         ReadCommonPlan(&local_node->plan);
1939
1940         READ_DONE();
1941 }
1942
1943 /*
1944  * _readSort
1945  */
1946 static Sort *
1947 _readSort(void)
1948 {
1949         READ_LOCALS(Sort);
1950
1951         ReadCommonPlan(&local_node->plan);
1952
1953         READ_INT_FIELD(numCols);
1954         READ_ATTRNUMBER_ARRAY(sortColIdx, local_node->numCols);
1955         READ_OID_ARRAY(sortOperators, local_node->numCols);
1956         READ_OID_ARRAY(collations, local_node->numCols);
1957         READ_BOOL_ARRAY(nullsFirst, local_node->numCols);
1958
1959         READ_DONE();
1960 }
1961
1962 /*
1963  * _readGroup
1964  */
1965 static Group *
1966 _readGroup(void)
1967 {
1968         READ_LOCALS(Group);
1969
1970         ReadCommonPlan(&local_node->plan);
1971
1972         READ_INT_FIELD(numCols);
1973         READ_ATTRNUMBER_ARRAY(grpColIdx, local_node->numCols);
1974         READ_OID_ARRAY(grpOperators, local_node->numCols);
1975
1976         READ_DONE();
1977 }
1978
1979 /*
1980  * _readAgg
1981  */
1982 static Agg *
1983 _readAgg(void)
1984 {
1985         READ_LOCALS(Agg);
1986
1987         ReadCommonPlan(&local_node->plan);
1988
1989         READ_ENUM_FIELD(aggstrategy, AggStrategy);
1990         READ_INT_FIELD(numCols);
1991         READ_ATTRNUMBER_ARRAY(grpColIdx, local_node->numCols);
1992         READ_OID_ARRAY(grpOperators, local_node->numCols);
1993         READ_LONG_FIELD(numGroups);
1994         READ_NODE_FIELD(groupingSets);
1995         READ_NODE_FIELD(chain);
1996
1997         READ_DONE();
1998 }
1999
2000 /*
2001  * _readWindowAgg
2002  */
2003 static WindowAgg *
2004 _readWindowAgg(void)
2005 {
2006         READ_LOCALS(WindowAgg);
2007
2008         ReadCommonPlan(&local_node->plan);
2009
2010         READ_UINT_FIELD(winref);
2011         READ_INT_FIELD(partNumCols);
2012         READ_ATTRNUMBER_ARRAY(partColIdx, local_node->partNumCols);
2013         READ_OID_ARRAY(partOperators, local_node->partNumCols);
2014         READ_INT_FIELD(ordNumCols);
2015         READ_ATTRNUMBER_ARRAY(ordColIdx, local_node->ordNumCols);
2016         READ_OID_ARRAY(ordOperators, local_node->ordNumCols);
2017         READ_INT_FIELD(frameOptions);
2018         READ_NODE_FIELD(startOffset);
2019         READ_NODE_FIELD(endOffset);
2020
2021         READ_DONE();
2022 }
2023
2024 /*
2025  * _readUnique
2026  */
2027 static Unique *
2028 _readUnique(void)
2029 {
2030         READ_LOCALS(Unique);
2031
2032         ReadCommonPlan(&local_node->plan);
2033
2034         READ_INT_FIELD(numCols);
2035         READ_ATTRNUMBER_ARRAY(uniqColIdx, local_node->numCols);
2036         READ_OID_ARRAY(uniqOperators, local_node->numCols);
2037
2038         READ_DONE();
2039 }
2040
2041 /*
2042  * _readGather
2043  */
2044 static Gather *
2045 _readGather(void)
2046 {
2047         READ_LOCALS(Gather);
2048
2049         ReadCommonPlan(&local_node->plan);
2050
2051         READ_INT_FIELD(num_workers);
2052         READ_BOOL_FIELD(single_copy);
2053
2054         READ_DONE();
2055 }
2056
2057 /*
2058  * _readHash
2059  */
2060 static Hash *
2061 _readHash(void)
2062 {
2063         READ_LOCALS(Hash);
2064
2065         ReadCommonPlan(&local_node->plan);
2066
2067         READ_OID_FIELD(skewTable);
2068         READ_INT_FIELD(skewColumn);
2069         READ_BOOL_FIELD(skewInherit);
2070         READ_OID_FIELD(skewColType);
2071         READ_INT_FIELD(skewColTypmod);
2072
2073         READ_DONE();
2074 }
2075
2076 /*
2077  * _readSetOp
2078  */
2079 static SetOp *
2080 _readSetOp(void)
2081 {
2082         READ_LOCALS(SetOp);
2083
2084         ReadCommonPlan(&local_node->plan);
2085
2086         READ_ENUM_FIELD(cmd, SetOpCmd);
2087         READ_ENUM_FIELD(strategy, SetOpStrategy);
2088         READ_INT_FIELD(numCols);
2089         READ_ATTRNUMBER_ARRAY(dupColIdx, local_node->numCols);
2090         READ_OID_ARRAY(dupOperators, local_node->numCols);
2091         READ_INT_FIELD(flagColIdx);
2092         READ_INT_FIELD(firstFlag);
2093         READ_LONG_FIELD(numGroups);
2094
2095         READ_DONE();
2096 }
2097
2098 /*
2099  * _readLockRows
2100  */
2101 static LockRows *
2102 _readLockRows(void)
2103 {
2104         READ_LOCALS(LockRows);
2105
2106         ReadCommonPlan(&local_node->plan);
2107
2108         READ_NODE_FIELD(rowMarks);
2109         READ_INT_FIELD(epqParam);
2110
2111         READ_DONE();
2112 }
2113
2114 /*
2115  * _readLimit
2116  */
2117 static Limit *
2118 _readLimit(void)
2119 {
2120         READ_LOCALS(Limit);
2121
2122         ReadCommonPlan(&local_node->plan);
2123
2124         READ_NODE_FIELD(limitOffset);
2125         READ_NODE_FIELD(limitCount);
2126
2127         READ_DONE();
2128 }
2129
2130 /*
2131  * _readNestLoopParam
2132  */
2133 static NestLoopParam *
2134 _readNestLoopParam(void)
2135 {
2136         READ_LOCALS(NestLoopParam);
2137
2138         READ_INT_FIELD(paramno);
2139         READ_NODE_FIELD(paramval);
2140
2141         READ_DONE();
2142 }
2143
2144 /*
2145  * _readPlanRowMark
2146  */
2147 static PlanRowMark *
2148 _readPlanRowMark(void)
2149 {
2150         READ_LOCALS(PlanRowMark);
2151
2152         READ_UINT_FIELD(rti);
2153         READ_UINT_FIELD(prti);
2154         READ_UINT_FIELD(rowmarkId);
2155         READ_ENUM_FIELD(markType, RowMarkType);
2156         READ_INT_FIELD(allMarkTypes);
2157         READ_ENUM_FIELD(strength, LockClauseStrength);
2158         READ_ENUM_FIELD(waitPolicy, LockWaitPolicy);
2159         READ_BOOL_FIELD(isParent);
2160
2161         READ_DONE();
2162 }
2163
2164 /*
2165  * _readPlanInvalItem
2166  */
2167 static PlanInvalItem *
2168 _readPlanInvalItem(void)
2169 {
2170         READ_LOCALS(PlanInvalItem);
2171
2172         READ_INT_FIELD(cacheId);
2173         READ_UINT_FIELD(hashValue);
2174
2175         READ_DONE();
2176 }
2177
2178 /*
2179  * _readSubPlan
2180  */
2181 static SubPlan *
2182 _readSubPlan(void)
2183 {
2184         READ_LOCALS(SubPlan);
2185
2186         READ_ENUM_FIELD(subLinkType, SubLinkType);
2187         READ_NODE_FIELD(testexpr);
2188         READ_NODE_FIELD(paramIds);
2189         READ_INT_FIELD(plan_id);
2190         READ_STRING_FIELD(plan_name);
2191         READ_OID_FIELD(firstColType);
2192         READ_INT_FIELD(firstColTypmod);
2193         READ_OID_FIELD(firstColCollation);
2194         READ_BOOL_FIELD(useHashTable);
2195         READ_BOOL_FIELD(unknownEqFalse);
2196         READ_NODE_FIELD(setParam);
2197         READ_NODE_FIELD(parParam);
2198         READ_NODE_FIELD(args);
2199         READ_FLOAT_FIELD(startup_cost);
2200         READ_FLOAT_FIELD(per_call_cost);
2201
2202         READ_DONE();
2203 }
2204
2205 /*
2206  * _readAlternativeSubPlan
2207  */
2208 static AlternativeSubPlan *
2209 _readAlternativeSubPlan(void)
2210 {
2211         READ_LOCALS(AlternativeSubPlan);
2212
2213         READ_NODE_FIELD(subplans);
2214
2215         READ_DONE();
2216 }
2217
2218 /*
2219  * parseNodeString
2220  *
2221  * Given a character string representing a node tree, parseNodeString creates
2222  * the internal node structure.
2223  *
2224  * The string to be read must already have been loaded into pg_strtok().
2225  */
2226 Node *
2227 parseNodeString(void)
2228 {
2229         void       *return_value;
2230
2231         READ_TEMP_LOCALS();
2232
2233         token = pg_strtok(&length);
2234
2235 #define MATCH(tokname, namelen) \
2236         (length == namelen && memcmp(token, tokname, namelen) == 0)
2237
2238         if (MATCH("QUERY", 5))
2239                 return_value = _readQuery();
2240         else if (MATCH("WITHCHECKOPTION", 15))
2241                 return_value = _readWithCheckOption();
2242         else if (MATCH("SORTGROUPCLAUSE", 15))
2243                 return_value = _readSortGroupClause();
2244         else if (MATCH("GROUPINGSET", 11))
2245                 return_value = _readGroupingSet();
2246         else if (MATCH("WINDOWCLAUSE", 12))
2247                 return_value = _readWindowClause();
2248         else if (MATCH("ROWMARKCLAUSE", 13))
2249                 return_value = _readRowMarkClause();
2250         else if (MATCH("COMMONTABLEEXPR", 15))
2251                 return_value = _readCommonTableExpr();
2252         else if (MATCH("SETOPERATIONSTMT", 16))
2253                 return_value = _readSetOperationStmt();
2254         else if (MATCH("ALIAS", 5))
2255                 return_value = _readAlias();
2256         else if (MATCH("RANGEVAR", 8))
2257                 return_value = _readRangeVar();
2258         else if (MATCH("INTOCLAUSE", 10))
2259                 return_value = _readIntoClause();
2260         else if (MATCH("VAR", 3))
2261                 return_value = _readVar();
2262         else if (MATCH("CONST", 5))
2263                 return_value = _readConst();
2264         else if (MATCH("PARAM", 5))
2265                 return_value = _readParam();
2266         else if (MATCH("AGGREF", 6))
2267                 return_value = _readAggref();
2268         else if (MATCH("GROUPINGFUNC", 12))
2269                 return_value = _readGroupingFunc();
2270         else if (MATCH("WINDOWFUNC", 10))
2271                 return_value = _readWindowFunc();
2272         else if (MATCH("ARRAYREF", 8))
2273                 return_value = _readArrayRef();
2274         else if (MATCH("FUNCEXPR", 8))
2275                 return_value = _readFuncExpr();
2276         else if (MATCH("NAMEDARGEXPR", 12))
2277                 return_value = _readNamedArgExpr();
2278         else if (MATCH("OPEXPR", 6))
2279                 return_value = _readOpExpr();
2280         else if (MATCH("DISTINCTEXPR", 12))
2281                 return_value = _readDistinctExpr();
2282         else if (MATCH("NULLIFEXPR", 10))
2283                 return_value = _readNullIfExpr();
2284         else if (MATCH("SCALARARRAYOPEXPR", 17))
2285                 return_value = _readScalarArrayOpExpr();
2286         else if (MATCH("BOOLEXPR", 8))
2287                 return_value = _readBoolExpr();
2288         else if (MATCH("SUBLINK", 7))
2289                 return_value = _readSubLink();
2290         else if (MATCH("FIELDSELECT", 11))
2291                 return_value = _readFieldSelect();
2292         else if (MATCH("FIELDSTORE", 10))
2293                 return_value = _readFieldStore();
2294         else if (MATCH("RELABELTYPE", 11))
2295                 return_value = _readRelabelType();
2296         else if (MATCH("COERCEVIAIO", 11))
2297                 return_value = _readCoerceViaIO();
2298         else if (MATCH("ARRAYCOERCEEXPR", 15))
2299                 return_value = _readArrayCoerceExpr();
2300         else if (MATCH("CONVERTROWTYPEEXPR", 18))
2301                 return_value = _readConvertRowtypeExpr();
2302         else if (MATCH("COLLATE", 7))
2303                 return_value = _readCollateExpr();
2304         else if (MATCH("CASE", 4))
2305                 return_value = _readCaseExpr();
2306         else if (MATCH("WHEN", 4))
2307                 return_value = _readCaseWhen();
2308         else if (MATCH("CASETESTEXPR", 12))
2309                 return_value = _readCaseTestExpr();
2310         else if (MATCH("ARRAY", 5))
2311                 return_value = _readArrayExpr();
2312         else if (MATCH("ROW", 3))
2313                 return_value = _readRowExpr();
2314         else if (MATCH("ROWCOMPARE", 10))
2315                 return_value = _readRowCompareExpr();
2316         else if (MATCH("COALESCE", 8))
2317                 return_value = _readCoalesceExpr();
2318         else if (MATCH("MINMAX", 6))
2319                 return_value = _readMinMaxExpr();
2320         else if (MATCH("XMLEXPR", 7))
2321                 return_value = _readXmlExpr();
2322         else if (MATCH("NULLTEST", 8))
2323                 return_value = _readNullTest();
2324         else if (MATCH("BOOLEANTEST", 11))
2325                 return_value = _readBooleanTest();
2326         else if (MATCH("COERCETODOMAIN", 14))
2327                 return_value = _readCoerceToDomain();
2328         else if (MATCH("COERCETODOMAINVALUE", 19))
2329                 return_value = _readCoerceToDomainValue();
2330         else if (MATCH("SETTODEFAULT", 12))
2331                 return_value = _readSetToDefault();
2332         else if (MATCH("CURRENTOFEXPR", 13))
2333                 return_value = _readCurrentOfExpr();
2334         else if (MATCH("INFERENCEELEM", 13))
2335                 return_value = _readInferenceElem();
2336         else if (MATCH("TARGETENTRY", 11))
2337                 return_value = _readTargetEntry();
2338         else if (MATCH("RANGETBLREF", 11))
2339                 return_value = _readRangeTblRef();
2340         else if (MATCH("JOINEXPR", 8))
2341                 return_value = _readJoinExpr();
2342         else if (MATCH("FROMEXPR", 8))
2343                 return_value = _readFromExpr();
2344         else if (MATCH("ONCONFLICTEXPR", 14))
2345                 return_value = _readOnConflictExpr();
2346         else if (MATCH("RTE", 3))
2347                 return_value = _readRangeTblEntry();
2348         else if (MATCH("RANGETBLFUNCTION", 16))
2349                 return_value = _readRangeTblFunction();
2350         else if (MATCH("TABLESAMPLECLAUSE", 17))
2351                 return_value = _readTableSampleClause();
2352         else if (MATCH("NOTIFY", 6))
2353                 return_value = _readNotifyStmt();
2354         else if (MATCH("DEFELEM", 7))
2355                 return_value = _readDefElem();
2356         else if (MATCH("DECLARECURSOR", 13))
2357                 return_value = _readDeclareCursorStmt();
2358         else if (MATCH("PLANNEDSTMT", 11))
2359                 return_value = _readPlannedStmt();
2360         else if (MATCH("PLAN", 4))
2361                 return_value = _readPlan();
2362         else if (MATCH("RESULT", 6))
2363                 return_value = _readResult();
2364         else if (MATCH("MODIFYTABLE", 11))
2365                 return_value = _readModifyTable();
2366         else if (MATCH("APPEND", 6))
2367                 return_value = _readAppend();
2368         else if (MATCH("MERGEAPPEND", 11))
2369                 return_value = _readMergeAppend();
2370         else if (MATCH("RECURSIVEUNION", 14))
2371                 return_value = _readRecursiveUnion();
2372         else if (MATCH("BITMAPAND", 9))
2373                 return_value = _readBitmapAnd();
2374         else if (MATCH("BITMAPOR", 8))
2375                 return_value = _readBitmapOr();
2376         else if (MATCH("SCAN", 4))
2377                 return_value = _readScan();
2378         else if (MATCH("SEQSCAN", 7))
2379                 return_value = _readSeqScan();
2380         else if (MATCH("SAMPLESCAN", 10))
2381                 return_value = _readSampleScan();
2382         else if (MATCH("INDEXSCAN", 9))
2383                 return_value = _readIndexScan();
2384         else if (MATCH("INDEXONLYSCAN", 13))
2385                 return_value = _readIndexOnlyScan();
2386         else if (MATCH("BITMAPINDEXSCAN", 15))
2387                 return_value = _readBitmapIndexScan();
2388         else if (MATCH("BITMAPHEAPSCAN", 14))
2389                 return_value = _readBitmapHeapScan();
2390         else if (MATCH("TIDSCAN", 7))
2391                 return_value = _readTidScan();
2392         else if (MATCH("SUBQUERYSCAN", 12))
2393                 return_value = _readSubqueryScan();
2394         else if (MATCH("FUNCTIONSCAN", 12))
2395                 return_value = _readFunctionScan();
2396         else if (MATCH("VALUESSCAN", 10))
2397                 return_value = _readValuesScan();
2398         else if (MATCH("CTESCAN", 7))
2399                 return_value = _readCteScan();
2400         else if (MATCH("WORKTABLESCAN", 13))
2401                 return_value = _readWorkTableScan();
2402         else if (MATCH("FOREIGNSCAN", 11))
2403                 return_value = _readForeignScan();
2404         else if (MATCH("CUSTOMSCAN", 10))
2405                 return_value = _readCustomScan();
2406         else if (MATCH("JOIN", 4))
2407                 return_value = _readJoin();
2408         else if (MATCH("NESTLOOP", 8))
2409                 return_value = _readNestLoop();
2410         else if (MATCH("MERGEJOIN", 9))
2411                 return_value = _readMergeJoin();
2412         else if (MATCH("HASHJOIN", 8))
2413                 return_value = _readHashJoin();
2414         else if (MATCH("MATERIAL", 8))
2415                 return_value = _readMaterial();
2416         else if (MATCH("SORT", 4))
2417                 return_value = _readSort();
2418         else if (MATCH("GROUP", 5))
2419                 return_value = _readGroup();
2420         else if (MATCH("AGG", 3))
2421                 return_value = _readAgg();
2422         else if (MATCH("WINDOWAGG", 9))
2423                 return_value = _readWindowAgg();
2424         else if (MATCH("UNIQUE", 6))
2425                 return_value = _readUnique();
2426         else if (MATCH("GATHER", 6))
2427                 return_value = _readGather();
2428         else if (MATCH("HASH", 4))
2429                 return_value = _readHash();
2430         else if (MATCH("SETOP", 5))
2431                 return_value = _readSetOp();
2432         else if (MATCH("LOCKROWS", 8))
2433                 return_value = _readLockRows();
2434         else if (MATCH("LIMIT", 5))
2435                 return_value = _readLimit();
2436         else if (MATCH("NESTLOOPPARAM", 13))
2437                 return_value = _readNestLoopParam();
2438         else if (MATCH("PLANROWMARK", 11))
2439                 return_value = _readPlanRowMark();
2440         else if (MATCH("PLANINVALITEM", 13))
2441                 return_value = _readPlanInvalItem();
2442         else if (MATCH("SUBPLAN", 7))
2443                 return_value = _readSubPlan();
2444         else if (MATCH("ALTERNATIVESUBPLAN", 18))
2445                 return_value = _readAlternativeSubPlan();
2446         else
2447         {
2448                 elog(ERROR, "badly formatted node string \"%.32s\"...", token);
2449                 return_value = NULL;    /* keep compiler quiet */
2450         }
2451
2452         return (Node *) return_value;
2453 }
2454
2455
2456 /*
2457  * readDatum
2458  *
2459  * Given a string representation of a constant, recreate the appropriate
2460  * Datum.  The string representation embeds length info, but not byValue,
2461  * so we must be told that.
2462  */
2463 static Datum
2464 readDatum(bool typbyval)
2465 {
2466         Size            length,
2467                                 i;
2468         int                     tokenLength;
2469         char       *token;
2470         Datum           res;
2471         char       *s;
2472
2473         /*
2474          * read the actual length of the value
2475          */
2476         token = pg_strtok(&tokenLength);
2477         length = atoui(token);
2478
2479         token = pg_strtok(&tokenLength);        /* read the '[' */
2480         if (token == NULL || token[0] != '[')
2481                 elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %zu",
2482                          token ? (const char *) token : "[NULL]", length);
2483
2484         if (typbyval)
2485         {
2486                 if (length > (Size) sizeof(Datum))
2487                         elog(ERROR, "byval datum but length = %zu", length);
2488                 res = (Datum) 0;
2489                 s = (char *) (&res);
2490                 for (i = 0; i < (Size) sizeof(Datum); i++)
2491                 {
2492                         token = pg_strtok(&tokenLength);
2493                         s[i] = (char) atoi(token);
2494                 }
2495         }
2496         else if (length <= 0)
2497                 res = (Datum) NULL;
2498         else
2499         {
2500                 s = (char *) palloc(length);
2501                 for (i = 0; i < length; i++)
2502                 {
2503                         token = pg_strtok(&tokenLength);
2504                         s[i] = (char) atoi(token);
2505                 }
2506                 res = PointerGetDatum(s);
2507         }
2508
2509         token = pg_strtok(&tokenLength);        /* read the ']' */
2510         if (token == NULL || token[0] != ']')
2511                 elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %zu",
2512                          token ? (const char *) token : "[NULL]", length);
2513
2514         return res;
2515 }
2516
2517 /*
2518  * readAttrNumberCols
2519  */
2520 static AttrNumber *
2521 readAttrNumberCols(int numCols)
2522 {
2523         int                     tokenLength,
2524                                 i;
2525         char       *token;
2526         AttrNumber *attr_vals;
2527
2528         if (numCols <= 0)
2529                 return NULL;
2530
2531         attr_vals = (AttrNumber *) palloc(numCols * sizeof(AttrNumber));
2532         for (i = 0; i < numCols; i++)
2533         {
2534                 token = pg_strtok(&tokenLength);
2535                 attr_vals[i] = atoi(token);
2536         }
2537
2538         return attr_vals;
2539 }
2540
2541 /*
2542  * readOidCols
2543  */
2544 static Oid *
2545 readOidCols(int numCols)
2546 {
2547         int                     tokenLength,
2548                                 i;
2549         char       *token;
2550         Oid                *oid_vals;
2551
2552         if (numCols <= 0)
2553                 return NULL;
2554
2555         oid_vals = (Oid *) palloc(numCols * sizeof(Oid));
2556         for (i = 0; i < numCols; i++)
2557         {
2558                 token = pg_strtok(&tokenLength);
2559                 oid_vals[i] = atooid(token);
2560         }
2561
2562         return oid_vals;
2563 }
2564
2565 /*
2566  * readIntCols
2567  */
2568 static int *
2569 readIntCols(int numCols)
2570 {
2571         int                     tokenLength,
2572                                 i;
2573         char       *token;
2574         int                *int_vals;
2575
2576         if (numCols <= 0)
2577                 return NULL;
2578
2579         int_vals = (int *) palloc(numCols * sizeof(int));
2580         for (i = 0; i < numCols; i++)
2581         {
2582                 token = pg_strtok(&tokenLength);
2583                 int_vals[i] = atoi(token);
2584         }
2585
2586         return int_vals;
2587 }
2588
2589 /*
2590  * readBoolCols
2591  */
2592 static bool *
2593 readBoolCols(int numCols)
2594 {
2595         int                     tokenLength,
2596                                 i;
2597         char       *token;
2598         bool       *bool_vals;
2599
2600         if (numCols <= 0)
2601                 return NULL;
2602
2603         bool_vals = (bool *) palloc(numCols * sizeof(bool));
2604         for (i = 0; i < numCols; i++)
2605         {
2606                 token = pg_strtok(&tokenLength);
2607                 bool_vals[i] = strtobool(token);
2608         }
2609
2610         return bool_vals;
2611 }