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