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