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