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