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