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