1 /*-------------------------------------------------------------------------
4 * Copy functions for Postgres tree nodes.
6 * NOTE: we currently support copying all node types found in parse and
7 * plan trees. We do not support copying executor state trees; there
8 * is no need for that, and no point in maintaining all the code that
9 * would be needed. We also do not support copying Path trees, mainly
10 * because the circular linkages between RelOptInfo and Path nodes can't
11 * be handled easily in a simple depth-first traversal.
14 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
15 * Portions Copyright (c) 1994, Regents of the University of California
18 * src/backend/nodes/copyfuncs.c
20 *-------------------------------------------------------------------------
25 #include "miscadmin.h"
26 #include "nodes/plannodes.h"
27 #include "nodes/relation.h"
28 #include "utils/datum.h"
32 * Macros to simplify copying of different kinds of fields. Use these
33 * wherever possible to reduce the chance for silly typos. Note that these
34 * hard-wire the convention that the local variables in a Copy routine are
35 * named 'newnode' and 'from'.
38 /* Copy a simple scalar field (int, float, bool, enum, etc) */
39 #define COPY_SCALAR_FIELD(fldname) \
40 (newnode->fldname = from->fldname)
42 /* Copy a field that is a pointer to some kind of Node or Node tree */
43 #define COPY_NODE_FIELD(fldname) \
44 (newnode->fldname = copyObject(from->fldname))
46 /* Copy a field that is a pointer to a Bitmapset */
47 #define COPY_BITMAPSET_FIELD(fldname) \
48 (newnode->fldname = bms_copy(from->fldname))
50 /* Copy a field that is a pointer to a C string, or perhaps NULL */
51 #define COPY_STRING_FIELD(fldname) \
52 (newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)
54 /* Copy a field that is a pointer to a simple palloc'd object of size sz */
55 #define COPY_POINTER_FIELD(fldname, sz) \
58 newnode->fldname = palloc(_size); \
59 memcpy(newnode->fldname, from->fldname, _size); \
62 /* Copy a parse location field (for Copy, this is same as scalar case) */
63 #define COPY_LOCATION_FIELD(fldname) \
64 (newnode->fldname = from->fldname)
67 /* ****************************************************************
68 * plannodes.h copy functions
69 * ****************************************************************
76 _copyPlannedStmt(const PlannedStmt *from)
78 PlannedStmt *newnode = makeNode(PlannedStmt);
80 COPY_SCALAR_FIELD(commandType);
81 COPY_SCALAR_FIELD(queryId);
82 COPY_SCALAR_FIELD(hasReturning);
83 COPY_SCALAR_FIELD(hasModifyingCTE);
84 COPY_SCALAR_FIELD(canSetTag);
85 COPY_SCALAR_FIELD(transientPlan);
86 COPY_NODE_FIELD(planTree);
87 COPY_NODE_FIELD(rtable);
88 COPY_NODE_FIELD(resultRelations);
89 COPY_NODE_FIELD(utilityStmt);
90 COPY_NODE_FIELD(subplans);
91 COPY_BITMAPSET_FIELD(rewindPlanIDs);
92 COPY_NODE_FIELD(rowMarks);
93 COPY_NODE_FIELD(relationOids);
94 COPY_NODE_FIELD(invalItems);
95 COPY_SCALAR_FIELD(nParamExec);
103 * This function copies the fields of the Plan node. It is used by
104 * all the copy functions for classes which inherit from Plan.
107 CopyPlanFields(const Plan *from, Plan *newnode)
109 COPY_SCALAR_FIELD(startup_cost);
110 COPY_SCALAR_FIELD(total_cost);
111 COPY_SCALAR_FIELD(plan_rows);
112 COPY_SCALAR_FIELD(plan_width);
113 COPY_NODE_FIELD(targetlist);
114 COPY_NODE_FIELD(qual);
115 COPY_NODE_FIELD(lefttree);
116 COPY_NODE_FIELD(righttree);
117 COPY_NODE_FIELD(initPlan);
118 COPY_BITMAPSET_FIELD(extParam);
119 COPY_BITMAPSET_FIELD(allParam);
126 _copyPlan(const Plan *from)
128 Plan *newnode = makeNode(Plan);
131 * copy node superclass fields
133 CopyPlanFields(from, newnode);
143 _copyResult(const Result *from)
145 Result *newnode = makeNode(Result);
148 * copy node superclass fields
150 CopyPlanFields((const Plan *) from, (Plan *) newnode);
153 * copy remainder of node
155 COPY_NODE_FIELD(resconstantqual);
164 _copyModifyTable(const ModifyTable *from)
166 ModifyTable *newnode = makeNode(ModifyTable);
169 * copy node superclass fields
171 CopyPlanFields((const Plan *) from, (Plan *) newnode);
174 * copy remainder of node
176 COPY_SCALAR_FIELD(operation);
177 COPY_SCALAR_FIELD(canSetTag);
178 COPY_NODE_FIELD(resultRelations);
179 COPY_SCALAR_FIELD(resultRelIndex);
180 COPY_NODE_FIELD(plans);
181 COPY_NODE_FIELD(returningLists);
182 COPY_NODE_FIELD(fdwPrivLists);
183 COPY_NODE_FIELD(rowMarks);
184 COPY_SCALAR_FIELD(epqParam);
193 _copyAppend(const Append *from)
195 Append *newnode = makeNode(Append);
198 * copy node superclass fields
200 CopyPlanFields((const Plan *) from, (Plan *) newnode);
203 * copy remainder of node
205 COPY_NODE_FIELD(appendplans);
214 _copyMergeAppend(const MergeAppend *from)
216 MergeAppend *newnode = makeNode(MergeAppend);
219 * copy node superclass fields
221 CopyPlanFields((const Plan *) from, (Plan *) newnode);
224 * copy remainder of node
226 COPY_NODE_FIELD(mergeplans);
227 COPY_SCALAR_FIELD(numCols);
228 COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
229 COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
230 COPY_POINTER_FIELD(collations, from->numCols * sizeof(Oid));
231 COPY_POINTER_FIELD(nullsFirst, from->numCols * sizeof(bool));
237 * _copyRecursiveUnion
239 static RecursiveUnion *
240 _copyRecursiveUnion(const RecursiveUnion *from)
242 RecursiveUnion *newnode = makeNode(RecursiveUnion);
245 * copy node superclass fields
247 CopyPlanFields((const Plan *) from, (Plan *) newnode);
250 * copy remainder of node
252 COPY_SCALAR_FIELD(wtParam);
253 COPY_SCALAR_FIELD(numCols);
254 if (from->numCols > 0)
256 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
257 COPY_POINTER_FIELD(dupOperators, from->numCols * sizeof(Oid));
259 COPY_SCALAR_FIELD(numGroups);
268 _copyBitmapAnd(const BitmapAnd *from)
270 BitmapAnd *newnode = makeNode(BitmapAnd);
273 * copy node superclass fields
275 CopyPlanFields((const Plan *) from, (Plan *) newnode);
278 * copy remainder of node
280 COPY_NODE_FIELD(bitmapplans);
289 _copyBitmapOr(const BitmapOr *from)
291 BitmapOr *newnode = makeNode(BitmapOr);
294 * copy node superclass fields
296 CopyPlanFields((const Plan *) from, (Plan *) newnode);
299 * copy remainder of node
301 COPY_NODE_FIELD(bitmapplans);
310 * This function copies the fields of the Scan node. It is used by
311 * all the copy functions for classes which inherit from Scan.
314 CopyScanFields(const Scan *from, Scan *newnode)
316 CopyPlanFields((const Plan *) from, (Plan *) newnode);
318 COPY_SCALAR_FIELD(scanrelid);
325 _copyScan(const Scan *from)
327 Scan *newnode = makeNode(Scan);
330 * copy node superclass fields
332 CopyScanFields((const Scan *) from, (Scan *) newnode);
341 _copySeqScan(const SeqScan *from)
343 SeqScan *newnode = makeNode(SeqScan);
346 * copy node superclass fields
348 CopyScanFields((const Scan *) from, (Scan *) newnode);
357 _copyIndexScan(const IndexScan *from)
359 IndexScan *newnode = makeNode(IndexScan);
362 * copy node superclass fields
364 CopyScanFields((const Scan *) from, (Scan *) newnode);
367 * copy remainder of node
369 COPY_SCALAR_FIELD(indexid);
370 COPY_NODE_FIELD(indexqual);
371 COPY_NODE_FIELD(indexqualorig);
372 COPY_NODE_FIELD(indexorderby);
373 COPY_NODE_FIELD(indexorderbyorig);
374 COPY_SCALAR_FIELD(indexorderdir);
382 static IndexOnlyScan *
383 _copyIndexOnlyScan(const IndexOnlyScan *from)
385 IndexOnlyScan *newnode = makeNode(IndexOnlyScan);
388 * copy node superclass fields
390 CopyScanFields((const Scan *) from, (Scan *) newnode);
393 * copy remainder of node
395 COPY_SCALAR_FIELD(indexid);
396 COPY_NODE_FIELD(indexqual);
397 COPY_NODE_FIELD(indexorderby);
398 COPY_NODE_FIELD(indextlist);
399 COPY_SCALAR_FIELD(indexorderdir);
405 * _copyBitmapIndexScan
407 static BitmapIndexScan *
408 _copyBitmapIndexScan(const BitmapIndexScan *from)
410 BitmapIndexScan *newnode = makeNode(BitmapIndexScan);
413 * copy node superclass fields
415 CopyScanFields((const Scan *) from, (Scan *) newnode);
418 * copy remainder of node
420 COPY_SCALAR_FIELD(indexid);
421 COPY_NODE_FIELD(indexqual);
422 COPY_NODE_FIELD(indexqualorig);
428 * _copyBitmapHeapScan
430 static BitmapHeapScan *
431 _copyBitmapHeapScan(const BitmapHeapScan *from)
433 BitmapHeapScan *newnode = makeNode(BitmapHeapScan);
436 * copy node superclass fields
438 CopyScanFields((const Scan *) from, (Scan *) newnode);
441 * copy remainder of node
443 COPY_NODE_FIELD(bitmapqualorig);
452 _copyTidScan(const TidScan *from)
454 TidScan *newnode = makeNode(TidScan);
457 * copy node superclass fields
459 CopyScanFields((const Scan *) from, (Scan *) newnode);
462 * copy remainder of node
464 COPY_NODE_FIELD(tidquals);
472 static SubqueryScan *
473 _copySubqueryScan(const SubqueryScan *from)
475 SubqueryScan *newnode = makeNode(SubqueryScan);
478 * copy node superclass fields
480 CopyScanFields((const Scan *) from, (Scan *) newnode);
483 * copy remainder of node
485 COPY_NODE_FIELD(subplan);
493 static FunctionScan *
494 _copyFunctionScan(const FunctionScan *from)
496 FunctionScan *newnode = makeNode(FunctionScan);
499 * copy node superclass fields
501 CopyScanFields((const Scan *) from, (Scan *) newnode);
504 * copy remainder of node
506 COPY_NODE_FIELD(funcexpr);
507 COPY_NODE_FIELD(funccolnames);
508 COPY_NODE_FIELD(funccoltypes);
509 COPY_NODE_FIELD(funccoltypmods);
510 COPY_NODE_FIELD(funccolcollations);
519 _copyValuesScan(const ValuesScan *from)
521 ValuesScan *newnode = makeNode(ValuesScan);
524 * copy node superclass fields
526 CopyScanFields((const Scan *) from, (Scan *) newnode);
529 * copy remainder of node
531 COPY_NODE_FIELD(values_lists);
540 _copyCteScan(const CteScan *from)
542 CteScan *newnode = makeNode(CteScan);
545 * copy node superclass fields
547 CopyScanFields((const Scan *) from, (Scan *) newnode);
550 * copy remainder of node
552 COPY_SCALAR_FIELD(ctePlanId);
553 COPY_SCALAR_FIELD(cteParam);
561 static WorkTableScan *
562 _copyWorkTableScan(const WorkTableScan *from)
564 WorkTableScan *newnode = makeNode(WorkTableScan);
567 * copy node superclass fields
569 CopyScanFields((const Scan *) from, (Scan *) newnode);
572 * copy remainder of node
574 COPY_SCALAR_FIELD(wtParam);
583 _copyForeignScan(const ForeignScan *from)
585 ForeignScan *newnode = makeNode(ForeignScan);
588 * copy node superclass fields
590 CopyScanFields((const Scan *) from, (Scan *) newnode);
593 * copy remainder of node
595 COPY_NODE_FIELD(fdw_exprs);
596 COPY_NODE_FIELD(fdw_private);
597 COPY_SCALAR_FIELD(fsSystemCol);
605 * This function copies the fields of the Join node. It is used by
606 * all the copy functions for classes which inherit from Join.
609 CopyJoinFields(const Join *from, Join *newnode)
611 CopyPlanFields((const Plan *) from, (Plan *) newnode);
613 COPY_SCALAR_FIELD(jointype);
614 COPY_NODE_FIELD(joinqual);
622 _copyJoin(const Join *from)
624 Join *newnode = makeNode(Join);
627 * copy node superclass fields
629 CopyJoinFields(from, newnode);
639 _copyNestLoop(const NestLoop *from)
641 NestLoop *newnode = makeNode(NestLoop);
644 * copy node superclass fields
646 CopyJoinFields((const Join *) from, (Join *) newnode);
649 * copy remainder of node
651 COPY_NODE_FIELD(nestParams);
661 _copyMergeJoin(const MergeJoin *from)
663 MergeJoin *newnode = makeNode(MergeJoin);
667 * copy node superclass fields
669 CopyJoinFields((const Join *) from, (Join *) newnode);
672 * copy remainder of node
674 COPY_NODE_FIELD(mergeclauses);
675 numCols = list_length(from->mergeclauses);
678 COPY_POINTER_FIELD(mergeFamilies, numCols * sizeof(Oid));
679 COPY_POINTER_FIELD(mergeCollations, numCols * sizeof(Oid));
680 COPY_POINTER_FIELD(mergeStrategies, numCols * sizeof(int));
681 COPY_POINTER_FIELD(mergeNullsFirst, numCols * sizeof(bool));
691 _copyHashJoin(const HashJoin *from)
693 HashJoin *newnode = makeNode(HashJoin);
696 * copy node superclass fields
698 CopyJoinFields((const Join *) from, (Join *) newnode);
701 * copy remainder of node
703 COPY_NODE_FIELD(hashclauses);
713 _copyMaterial(const Material *from)
715 Material *newnode = makeNode(Material);
718 * copy node superclass fields
720 CopyPlanFields((const Plan *) from, (Plan *) newnode);
730 _copySort(const Sort *from)
732 Sort *newnode = makeNode(Sort);
735 * copy node superclass fields
737 CopyPlanFields((const Plan *) from, (Plan *) newnode);
739 COPY_SCALAR_FIELD(numCols);
740 COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
741 COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
742 COPY_POINTER_FIELD(collations, from->numCols * sizeof(Oid));
743 COPY_POINTER_FIELD(nullsFirst, from->numCols * sizeof(bool));
753 _copyGroup(const Group *from)
755 Group *newnode = makeNode(Group);
757 CopyPlanFields((const Plan *) from, (Plan *) newnode);
759 COPY_SCALAR_FIELD(numCols);
760 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
761 COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
770 _copyAgg(const Agg *from)
772 Agg *newnode = makeNode(Agg);
774 CopyPlanFields((const Plan *) from, (Plan *) newnode);
776 COPY_SCALAR_FIELD(aggstrategy);
777 COPY_SCALAR_FIELD(numCols);
778 if (from->numCols > 0)
780 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
781 COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
783 COPY_SCALAR_FIELD(numGroups);
792 _copyWindowAgg(const WindowAgg *from)
794 WindowAgg *newnode = makeNode(WindowAgg);
796 CopyPlanFields((const Plan *) from, (Plan *) newnode);
798 COPY_SCALAR_FIELD(winref);
799 COPY_SCALAR_FIELD(partNumCols);
800 if (from->partNumCols > 0)
802 COPY_POINTER_FIELD(partColIdx, from->partNumCols * sizeof(AttrNumber));
803 COPY_POINTER_FIELD(partOperators, from->partNumCols * sizeof(Oid));
805 COPY_SCALAR_FIELD(ordNumCols);
806 if (from->ordNumCols > 0)
808 COPY_POINTER_FIELD(ordColIdx, from->ordNumCols * sizeof(AttrNumber));
809 COPY_POINTER_FIELD(ordOperators, from->ordNumCols * sizeof(Oid));
811 COPY_SCALAR_FIELD(frameOptions);
812 COPY_NODE_FIELD(startOffset);
813 COPY_NODE_FIELD(endOffset);
822 _copyUnique(const Unique *from)
824 Unique *newnode = makeNode(Unique);
827 * copy node superclass fields
829 CopyPlanFields((const Plan *) from, (Plan *) newnode);
832 * copy remainder of node
834 COPY_SCALAR_FIELD(numCols);
835 COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
836 COPY_POINTER_FIELD(uniqOperators, from->numCols * sizeof(Oid));
845 _copyHash(const Hash *from)
847 Hash *newnode = makeNode(Hash);
850 * copy node superclass fields
852 CopyPlanFields((const Plan *) from, (Plan *) newnode);
855 * copy remainder of node
857 COPY_SCALAR_FIELD(skewTable);
858 COPY_SCALAR_FIELD(skewColumn);
859 COPY_SCALAR_FIELD(skewInherit);
860 COPY_SCALAR_FIELD(skewColType);
861 COPY_SCALAR_FIELD(skewColTypmod);
870 _copySetOp(const SetOp *from)
872 SetOp *newnode = makeNode(SetOp);
875 * copy node superclass fields
877 CopyPlanFields((const Plan *) from, (Plan *) newnode);
880 * copy remainder of node
882 COPY_SCALAR_FIELD(cmd);
883 COPY_SCALAR_FIELD(strategy);
884 COPY_SCALAR_FIELD(numCols);
885 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
886 COPY_POINTER_FIELD(dupOperators, from->numCols * sizeof(Oid));
887 COPY_SCALAR_FIELD(flagColIdx);
888 COPY_SCALAR_FIELD(firstFlag);
889 COPY_SCALAR_FIELD(numGroups);
898 _copyLockRows(const LockRows *from)
900 LockRows *newnode = makeNode(LockRows);
903 * copy node superclass fields
905 CopyPlanFields((const Plan *) from, (Plan *) newnode);
908 * copy remainder of node
910 COPY_NODE_FIELD(rowMarks);
911 COPY_SCALAR_FIELD(epqParam);
920 _copyLimit(const Limit *from)
922 Limit *newnode = makeNode(Limit);
925 * copy node superclass fields
927 CopyPlanFields((const Plan *) from, (Plan *) newnode);
930 * copy remainder of node
932 COPY_NODE_FIELD(limitOffset);
933 COPY_NODE_FIELD(limitCount);
941 static NestLoopParam *
942 _copyNestLoopParam(const NestLoopParam *from)
944 NestLoopParam *newnode = makeNode(NestLoopParam);
946 COPY_SCALAR_FIELD(paramno);
947 COPY_NODE_FIELD(paramval);
956 _copyPlanRowMark(const PlanRowMark *from)
958 PlanRowMark *newnode = makeNode(PlanRowMark);
960 COPY_SCALAR_FIELD(rti);
961 COPY_SCALAR_FIELD(prti);
962 COPY_SCALAR_FIELD(rowmarkId);
963 COPY_SCALAR_FIELD(markType);
964 COPY_SCALAR_FIELD(noWait);
965 COPY_SCALAR_FIELD(isParent);
973 static PlanInvalItem *
974 _copyPlanInvalItem(const PlanInvalItem *from)
976 PlanInvalItem *newnode = makeNode(PlanInvalItem);
978 COPY_SCALAR_FIELD(cacheId);
979 COPY_SCALAR_FIELD(hashValue);
984 /* ****************************************************************
985 * primnodes.h copy functions
986 * ****************************************************************
993 _copyAlias(const Alias *from)
995 Alias *newnode = makeNode(Alias);
997 COPY_STRING_FIELD(aliasname);
998 COPY_NODE_FIELD(colnames);
1007 _copyRangeVar(const RangeVar *from)
1009 RangeVar *newnode = makeNode(RangeVar);
1011 COPY_STRING_FIELD(catalogname);
1012 COPY_STRING_FIELD(schemaname);
1013 COPY_STRING_FIELD(relname);
1014 COPY_SCALAR_FIELD(inhOpt);
1015 COPY_SCALAR_FIELD(relpersistence);
1016 COPY_NODE_FIELD(alias);
1017 COPY_LOCATION_FIELD(location);
1026 _copyIntoClause(const IntoClause *from)
1028 IntoClause *newnode = makeNode(IntoClause);
1030 COPY_NODE_FIELD(rel);
1031 COPY_NODE_FIELD(colNames);
1032 COPY_NODE_FIELD(options);
1033 COPY_SCALAR_FIELD(onCommit);
1034 COPY_STRING_FIELD(tableSpaceName);
1035 COPY_NODE_FIELD(viewQuery);
1036 COPY_SCALAR_FIELD(skipData);
1042 * We don't need a _copyExpr because Expr is an abstract supertype which
1043 * should never actually get instantiated. Also, since it has no common
1044 * fields except NodeTag, there's no need for a helper routine to factor
1045 * out copying the common fields...
1052 _copyVar(const Var *from)
1054 Var *newnode = makeNode(Var);
1056 COPY_SCALAR_FIELD(varno);
1057 COPY_SCALAR_FIELD(varattno);
1058 COPY_SCALAR_FIELD(vartype);
1059 COPY_SCALAR_FIELD(vartypmod);
1060 COPY_SCALAR_FIELD(varcollid);
1061 COPY_SCALAR_FIELD(varlevelsup);
1062 COPY_SCALAR_FIELD(varnoold);
1063 COPY_SCALAR_FIELD(varoattno);
1064 COPY_LOCATION_FIELD(location);
1073 _copyConst(const Const *from)
1075 Const *newnode = makeNode(Const);
1077 COPY_SCALAR_FIELD(consttype);
1078 COPY_SCALAR_FIELD(consttypmod);
1079 COPY_SCALAR_FIELD(constcollid);
1080 COPY_SCALAR_FIELD(constlen);
1082 if (from->constbyval || from->constisnull)
1085 * passed by value so just copy the datum. Also, don't try to copy
1086 * struct when value is null!
1088 newnode->constvalue = from->constvalue;
1093 * passed by reference. We need a palloc'd copy.
1095 newnode->constvalue = datumCopy(from->constvalue,
1100 COPY_SCALAR_FIELD(constisnull);
1101 COPY_SCALAR_FIELD(constbyval);
1102 COPY_LOCATION_FIELD(location);
1111 _copyParam(const Param *from)
1113 Param *newnode = makeNode(Param);
1115 COPY_SCALAR_FIELD(paramkind);
1116 COPY_SCALAR_FIELD(paramid);
1117 COPY_SCALAR_FIELD(paramtype);
1118 COPY_SCALAR_FIELD(paramtypmod);
1119 COPY_SCALAR_FIELD(paramcollid);
1120 COPY_LOCATION_FIELD(location);
1129 _copyAggref(const Aggref *from)
1131 Aggref *newnode = makeNode(Aggref);
1133 COPY_SCALAR_FIELD(aggfnoid);
1134 COPY_SCALAR_FIELD(aggtype);
1135 COPY_SCALAR_FIELD(aggcollid);
1136 COPY_SCALAR_FIELD(inputcollid);
1137 COPY_NODE_FIELD(args);
1138 COPY_NODE_FIELD(aggorder);
1139 COPY_NODE_FIELD(aggdistinct);
1140 COPY_SCALAR_FIELD(aggstar);
1141 COPY_SCALAR_FIELD(agglevelsup);
1142 COPY_LOCATION_FIELD(location);
1151 _copyWindowFunc(const WindowFunc *from)
1153 WindowFunc *newnode = makeNode(WindowFunc);
1155 COPY_SCALAR_FIELD(winfnoid);
1156 COPY_SCALAR_FIELD(wintype);
1157 COPY_SCALAR_FIELD(wincollid);
1158 COPY_SCALAR_FIELD(inputcollid);
1159 COPY_NODE_FIELD(args);
1160 COPY_SCALAR_FIELD(winref);
1161 COPY_SCALAR_FIELD(winstar);
1162 COPY_SCALAR_FIELD(winagg);
1163 COPY_LOCATION_FIELD(location);
1172 _copyArrayRef(const ArrayRef *from)
1174 ArrayRef *newnode = makeNode(ArrayRef);
1176 COPY_SCALAR_FIELD(refarraytype);
1177 COPY_SCALAR_FIELD(refelemtype);
1178 COPY_SCALAR_FIELD(reftypmod);
1179 COPY_SCALAR_FIELD(refcollid);
1180 COPY_NODE_FIELD(refupperindexpr);
1181 COPY_NODE_FIELD(reflowerindexpr);
1182 COPY_NODE_FIELD(refexpr);
1183 COPY_NODE_FIELD(refassgnexpr);
1192 _copyFuncExpr(const FuncExpr *from)
1194 FuncExpr *newnode = makeNode(FuncExpr);
1196 COPY_SCALAR_FIELD(funcid);
1197 COPY_SCALAR_FIELD(funcresulttype);
1198 COPY_SCALAR_FIELD(funcretset);
1199 COPY_SCALAR_FIELD(funcvariadic);
1200 COPY_SCALAR_FIELD(funcformat);
1201 COPY_SCALAR_FIELD(funccollid);
1202 COPY_SCALAR_FIELD(inputcollid);
1203 COPY_NODE_FIELD(args);
1204 COPY_LOCATION_FIELD(location);
1210 * _copyNamedArgExpr *
1212 static NamedArgExpr *
1213 _copyNamedArgExpr(const NamedArgExpr *from)
1215 NamedArgExpr *newnode = makeNode(NamedArgExpr);
1217 COPY_NODE_FIELD(arg);
1218 COPY_STRING_FIELD(name);
1219 COPY_SCALAR_FIELD(argnumber);
1220 COPY_LOCATION_FIELD(location);
1229 _copyOpExpr(const OpExpr *from)
1231 OpExpr *newnode = makeNode(OpExpr);
1233 COPY_SCALAR_FIELD(opno);
1234 COPY_SCALAR_FIELD(opfuncid);
1235 COPY_SCALAR_FIELD(opresulttype);
1236 COPY_SCALAR_FIELD(opretset);
1237 COPY_SCALAR_FIELD(opcollid);
1238 COPY_SCALAR_FIELD(inputcollid);
1239 COPY_NODE_FIELD(args);
1240 COPY_LOCATION_FIELD(location);
1246 * _copyDistinctExpr (same as OpExpr)
1248 static DistinctExpr *
1249 _copyDistinctExpr(const DistinctExpr *from)
1251 DistinctExpr *newnode = makeNode(DistinctExpr);
1253 COPY_SCALAR_FIELD(opno);
1254 COPY_SCALAR_FIELD(opfuncid);
1255 COPY_SCALAR_FIELD(opresulttype);
1256 COPY_SCALAR_FIELD(opretset);
1257 COPY_SCALAR_FIELD(opcollid);
1258 COPY_SCALAR_FIELD(inputcollid);
1259 COPY_NODE_FIELD(args);
1260 COPY_LOCATION_FIELD(location);
1266 * _copyNullIfExpr (same as OpExpr)
1269 _copyNullIfExpr(const NullIfExpr *from)
1271 NullIfExpr *newnode = makeNode(NullIfExpr);
1273 COPY_SCALAR_FIELD(opno);
1274 COPY_SCALAR_FIELD(opfuncid);
1275 COPY_SCALAR_FIELD(opresulttype);
1276 COPY_SCALAR_FIELD(opretset);
1277 COPY_SCALAR_FIELD(opcollid);
1278 COPY_SCALAR_FIELD(inputcollid);
1279 COPY_NODE_FIELD(args);
1280 COPY_LOCATION_FIELD(location);
1286 * _copyScalarArrayOpExpr
1288 static ScalarArrayOpExpr *
1289 _copyScalarArrayOpExpr(const ScalarArrayOpExpr *from)
1291 ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
1293 COPY_SCALAR_FIELD(opno);
1294 COPY_SCALAR_FIELD(opfuncid);
1295 COPY_SCALAR_FIELD(useOr);
1296 COPY_SCALAR_FIELD(inputcollid);
1297 COPY_NODE_FIELD(args);
1298 COPY_LOCATION_FIELD(location);
1307 _copyBoolExpr(const BoolExpr *from)
1309 BoolExpr *newnode = makeNode(BoolExpr);
1311 COPY_SCALAR_FIELD(boolop);
1312 COPY_NODE_FIELD(args);
1313 COPY_LOCATION_FIELD(location);
1322 _copySubLink(const SubLink *from)
1324 SubLink *newnode = makeNode(SubLink);
1326 COPY_SCALAR_FIELD(subLinkType);
1327 COPY_NODE_FIELD(testexpr);
1328 COPY_NODE_FIELD(operName);
1329 COPY_NODE_FIELD(subselect);
1330 COPY_LOCATION_FIELD(location);
1339 _copySubPlan(const SubPlan *from)
1341 SubPlan *newnode = makeNode(SubPlan);
1343 COPY_SCALAR_FIELD(subLinkType);
1344 COPY_NODE_FIELD(testexpr);
1345 COPY_NODE_FIELD(paramIds);
1346 COPY_SCALAR_FIELD(plan_id);
1347 COPY_STRING_FIELD(plan_name);
1348 COPY_SCALAR_FIELD(firstColType);
1349 COPY_SCALAR_FIELD(firstColTypmod);
1350 COPY_SCALAR_FIELD(firstColCollation);
1351 COPY_SCALAR_FIELD(useHashTable);
1352 COPY_SCALAR_FIELD(unknownEqFalse);
1353 COPY_NODE_FIELD(setParam);
1354 COPY_NODE_FIELD(parParam);
1355 COPY_NODE_FIELD(args);
1356 COPY_SCALAR_FIELD(startup_cost);
1357 COPY_SCALAR_FIELD(per_call_cost);
1363 * _copyAlternativeSubPlan
1365 static AlternativeSubPlan *
1366 _copyAlternativeSubPlan(const AlternativeSubPlan *from)
1368 AlternativeSubPlan *newnode = makeNode(AlternativeSubPlan);
1370 COPY_NODE_FIELD(subplans);
1378 static FieldSelect *
1379 _copyFieldSelect(const FieldSelect *from)
1381 FieldSelect *newnode = makeNode(FieldSelect);
1383 COPY_NODE_FIELD(arg);
1384 COPY_SCALAR_FIELD(fieldnum);
1385 COPY_SCALAR_FIELD(resulttype);
1386 COPY_SCALAR_FIELD(resulttypmod);
1387 COPY_SCALAR_FIELD(resultcollid);
1396 _copyFieldStore(const FieldStore *from)
1398 FieldStore *newnode = makeNode(FieldStore);
1400 COPY_NODE_FIELD(arg);
1401 COPY_NODE_FIELD(newvals);
1402 COPY_NODE_FIELD(fieldnums);
1403 COPY_SCALAR_FIELD(resulttype);
1411 static RelabelType *
1412 _copyRelabelType(const RelabelType *from)
1414 RelabelType *newnode = makeNode(RelabelType);
1416 COPY_NODE_FIELD(arg);
1417 COPY_SCALAR_FIELD(resulttype);
1418 COPY_SCALAR_FIELD(resulttypmod);
1419 COPY_SCALAR_FIELD(resultcollid);
1420 COPY_SCALAR_FIELD(relabelformat);
1421 COPY_LOCATION_FIELD(location);
1429 static CoerceViaIO *
1430 _copyCoerceViaIO(const CoerceViaIO *from)
1432 CoerceViaIO *newnode = makeNode(CoerceViaIO);
1434 COPY_NODE_FIELD(arg);
1435 COPY_SCALAR_FIELD(resulttype);
1436 COPY_SCALAR_FIELD(resultcollid);
1437 COPY_SCALAR_FIELD(coerceformat);
1438 COPY_LOCATION_FIELD(location);
1444 * _copyArrayCoerceExpr
1446 static ArrayCoerceExpr *
1447 _copyArrayCoerceExpr(const ArrayCoerceExpr *from)
1449 ArrayCoerceExpr *newnode = makeNode(ArrayCoerceExpr);
1451 COPY_NODE_FIELD(arg);
1452 COPY_SCALAR_FIELD(elemfuncid);
1453 COPY_SCALAR_FIELD(resulttype);
1454 COPY_SCALAR_FIELD(resulttypmod);
1455 COPY_SCALAR_FIELD(resultcollid);
1456 COPY_SCALAR_FIELD(isExplicit);
1457 COPY_SCALAR_FIELD(coerceformat);
1458 COPY_LOCATION_FIELD(location);
1464 * _copyConvertRowtypeExpr
1466 static ConvertRowtypeExpr *
1467 _copyConvertRowtypeExpr(const ConvertRowtypeExpr *from)
1469 ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);
1471 COPY_NODE_FIELD(arg);
1472 COPY_SCALAR_FIELD(resulttype);
1473 COPY_SCALAR_FIELD(convertformat);
1474 COPY_LOCATION_FIELD(location);
1482 static CollateExpr *
1483 _copyCollateExpr(const CollateExpr *from)
1485 CollateExpr *newnode = makeNode(CollateExpr);
1487 COPY_NODE_FIELD(arg);
1488 COPY_SCALAR_FIELD(collOid);
1489 COPY_LOCATION_FIELD(location);
1498 _copyCaseExpr(const CaseExpr *from)
1500 CaseExpr *newnode = makeNode(CaseExpr);
1502 COPY_SCALAR_FIELD(casetype);
1503 COPY_SCALAR_FIELD(casecollid);
1504 COPY_NODE_FIELD(arg);
1505 COPY_NODE_FIELD(args);
1506 COPY_NODE_FIELD(defresult);
1507 COPY_LOCATION_FIELD(location);
1516 _copyCaseWhen(const CaseWhen *from)
1518 CaseWhen *newnode = makeNode(CaseWhen);
1520 COPY_NODE_FIELD(expr);
1521 COPY_NODE_FIELD(result);
1522 COPY_LOCATION_FIELD(location);
1530 static CaseTestExpr *
1531 _copyCaseTestExpr(const CaseTestExpr *from)
1533 CaseTestExpr *newnode = makeNode(CaseTestExpr);
1535 COPY_SCALAR_FIELD(typeId);
1536 COPY_SCALAR_FIELD(typeMod);
1537 COPY_SCALAR_FIELD(collation);
1546 _copyArrayExpr(const ArrayExpr *from)
1548 ArrayExpr *newnode = makeNode(ArrayExpr);
1550 COPY_SCALAR_FIELD(array_typeid);
1551 COPY_SCALAR_FIELD(array_collid);
1552 COPY_SCALAR_FIELD(element_typeid);
1553 COPY_NODE_FIELD(elements);
1554 COPY_SCALAR_FIELD(multidims);
1555 COPY_LOCATION_FIELD(location);
1564 _copyRowExpr(const RowExpr *from)
1566 RowExpr *newnode = makeNode(RowExpr);
1568 COPY_NODE_FIELD(args);
1569 COPY_SCALAR_FIELD(row_typeid);
1570 COPY_SCALAR_FIELD(row_format);
1571 COPY_NODE_FIELD(colnames);
1572 COPY_LOCATION_FIELD(location);
1578 * _copyRowCompareExpr
1580 static RowCompareExpr *
1581 _copyRowCompareExpr(const RowCompareExpr *from)
1583 RowCompareExpr *newnode = makeNode(RowCompareExpr);
1585 COPY_SCALAR_FIELD(rctype);
1586 COPY_NODE_FIELD(opnos);
1587 COPY_NODE_FIELD(opfamilies);
1588 COPY_NODE_FIELD(inputcollids);
1589 COPY_NODE_FIELD(largs);
1590 COPY_NODE_FIELD(rargs);
1598 static CoalesceExpr *
1599 _copyCoalesceExpr(const CoalesceExpr *from)
1601 CoalesceExpr *newnode = makeNode(CoalesceExpr);
1603 COPY_SCALAR_FIELD(coalescetype);
1604 COPY_SCALAR_FIELD(coalescecollid);
1605 COPY_NODE_FIELD(args);
1606 COPY_LOCATION_FIELD(location);
1615 _copyMinMaxExpr(const MinMaxExpr *from)
1617 MinMaxExpr *newnode = makeNode(MinMaxExpr);
1619 COPY_SCALAR_FIELD(minmaxtype);
1620 COPY_SCALAR_FIELD(minmaxcollid);
1621 COPY_SCALAR_FIELD(inputcollid);
1622 COPY_SCALAR_FIELD(op);
1623 COPY_NODE_FIELD(args);
1624 COPY_LOCATION_FIELD(location);
1633 _copyXmlExpr(const XmlExpr *from)
1635 XmlExpr *newnode = makeNode(XmlExpr);
1637 COPY_SCALAR_FIELD(op);
1638 COPY_STRING_FIELD(name);
1639 COPY_NODE_FIELD(named_args);
1640 COPY_NODE_FIELD(arg_names);
1641 COPY_NODE_FIELD(args);
1642 COPY_SCALAR_FIELD(xmloption);
1643 COPY_SCALAR_FIELD(type);
1644 COPY_SCALAR_FIELD(typmod);
1645 COPY_LOCATION_FIELD(location);
1654 _copyNullTest(const NullTest *from)
1656 NullTest *newnode = makeNode(NullTest);
1658 COPY_NODE_FIELD(arg);
1659 COPY_SCALAR_FIELD(nulltesttype);
1660 COPY_SCALAR_FIELD(argisrow);
1668 static BooleanTest *
1669 _copyBooleanTest(const BooleanTest *from)
1671 BooleanTest *newnode = makeNode(BooleanTest);
1673 COPY_NODE_FIELD(arg);
1674 COPY_SCALAR_FIELD(booltesttype);
1680 * _copyCoerceToDomain
1682 static CoerceToDomain *
1683 _copyCoerceToDomain(const CoerceToDomain *from)
1685 CoerceToDomain *newnode = makeNode(CoerceToDomain);
1687 COPY_NODE_FIELD(arg);
1688 COPY_SCALAR_FIELD(resulttype);
1689 COPY_SCALAR_FIELD(resulttypmod);
1690 COPY_SCALAR_FIELD(resultcollid);
1691 COPY_SCALAR_FIELD(coercionformat);
1692 COPY_LOCATION_FIELD(location);
1698 * _copyCoerceToDomainValue
1700 static CoerceToDomainValue *
1701 _copyCoerceToDomainValue(const CoerceToDomainValue *from)
1703 CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1705 COPY_SCALAR_FIELD(typeId);
1706 COPY_SCALAR_FIELD(typeMod);
1707 COPY_SCALAR_FIELD(collation);
1708 COPY_LOCATION_FIELD(location);
1716 static SetToDefault *
1717 _copySetToDefault(const SetToDefault *from)
1719 SetToDefault *newnode = makeNode(SetToDefault);
1721 COPY_SCALAR_FIELD(typeId);
1722 COPY_SCALAR_FIELD(typeMod);
1723 COPY_SCALAR_FIELD(collation);
1724 COPY_LOCATION_FIELD(location);
1730 * _copyCurrentOfExpr
1732 static CurrentOfExpr *
1733 _copyCurrentOfExpr(const CurrentOfExpr *from)
1735 CurrentOfExpr *newnode = makeNode(CurrentOfExpr);
1737 COPY_SCALAR_FIELD(cvarno);
1738 COPY_STRING_FIELD(cursor_name);
1739 COPY_SCALAR_FIELD(cursor_param);
1747 static TargetEntry *
1748 _copyTargetEntry(const TargetEntry *from)
1750 TargetEntry *newnode = makeNode(TargetEntry);
1752 COPY_NODE_FIELD(expr);
1753 COPY_SCALAR_FIELD(resno);
1754 COPY_STRING_FIELD(resname);
1755 COPY_SCALAR_FIELD(ressortgroupref);
1756 COPY_SCALAR_FIELD(resorigtbl);
1757 COPY_SCALAR_FIELD(resorigcol);
1758 COPY_SCALAR_FIELD(resjunk);
1766 static RangeTblRef *
1767 _copyRangeTblRef(const RangeTblRef *from)
1769 RangeTblRef *newnode = makeNode(RangeTblRef);
1771 COPY_SCALAR_FIELD(rtindex);
1780 _copyJoinExpr(const JoinExpr *from)
1782 JoinExpr *newnode = makeNode(JoinExpr);
1784 COPY_SCALAR_FIELD(jointype);
1785 COPY_SCALAR_FIELD(isNatural);
1786 COPY_NODE_FIELD(larg);
1787 COPY_NODE_FIELD(rarg);
1788 COPY_NODE_FIELD(usingClause);
1789 COPY_NODE_FIELD(quals);
1790 COPY_NODE_FIELD(alias);
1791 COPY_SCALAR_FIELD(rtindex);
1800 _copyFromExpr(const FromExpr *from)
1802 FromExpr *newnode = makeNode(FromExpr);
1804 COPY_NODE_FIELD(fromlist);
1805 COPY_NODE_FIELD(quals);
1810 /* ****************************************************************
1811 * relation.h copy functions
1813 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1814 * There are some subsidiary structs that are useful to copy, though.
1815 * ****************************************************************
1822 _copyPathKey(const PathKey *from)
1824 PathKey *newnode = makeNode(PathKey);
1826 /* EquivalenceClasses are never moved, so just shallow-copy the pointer */
1827 COPY_SCALAR_FIELD(pk_eclass);
1828 COPY_SCALAR_FIELD(pk_opfamily);
1829 COPY_SCALAR_FIELD(pk_strategy);
1830 COPY_SCALAR_FIELD(pk_nulls_first);
1838 static RestrictInfo *
1839 _copyRestrictInfo(const RestrictInfo *from)
1841 RestrictInfo *newnode = makeNode(RestrictInfo);
1843 COPY_NODE_FIELD(clause);
1844 COPY_SCALAR_FIELD(is_pushed_down);
1845 COPY_SCALAR_FIELD(outerjoin_delayed);
1846 COPY_SCALAR_FIELD(can_join);
1847 COPY_SCALAR_FIELD(pseudoconstant);
1848 COPY_BITMAPSET_FIELD(clause_relids);
1849 COPY_BITMAPSET_FIELD(required_relids);
1850 COPY_BITMAPSET_FIELD(outer_relids);
1851 COPY_BITMAPSET_FIELD(nullable_relids);
1852 COPY_BITMAPSET_FIELD(left_relids);
1853 COPY_BITMAPSET_FIELD(right_relids);
1854 COPY_NODE_FIELD(orclause);
1855 /* EquivalenceClasses are never copied, so shallow-copy the pointers */
1856 COPY_SCALAR_FIELD(parent_ec);
1857 COPY_SCALAR_FIELD(eval_cost);
1858 COPY_SCALAR_FIELD(norm_selec);
1859 COPY_SCALAR_FIELD(outer_selec);
1860 COPY_NODE_FIELD(mergeopfamilies);
1861 /* EquivalenceClasses are never copied, so shallow-copy the pointers */
1862 COPY_SCALAR_FIELD(left_ec);
1863 COPY_SCALAR_FIELD(right_ec);
1864 COPY_SCALAR_FIELD(left_em);
1865 COPY_SCALAR_FIELD(right_em);
1866 /* MergeScanSelCache isn't a Node, so hard to copy; just reset cache */
1867 newnode->scansel_cache = NIL;
1868 COPY_SCALAR_FIELD(outer_is_left);
1869 COPY_SCALAR_FIELD(hashjoinoperator);
1870 COPY_SCALAR_FIELD(left_bucketsize);
1871 COPY_SCALAR_FIELD(right_bucketsize);
1877 * _copyPlaceHolderVar
1879 static PlaceHolderVar *
1880 _copyPlaceHolderVar(const PlaceHolderVar *from)
1882 PlaceHolderVar *newnode = makeNode(PlaceHolderVar);
1884 COPY_NODE_FIELD(phexpr);
1885 COPY_BITMAPSET_FIELD(phrels);
1886 COPY_SCALAR_FIELD(phid);
1887 COPY_SCALAR_FIELD(phlevelsup);
1893 * _copySpecialJoinInfo
1895 static SpecialJoinInfo *
1896 _copySpecialJoinInfo(const SpecialJoinInfo *from)
1898 SpecialJoinInfo *newnode = makeNode(SpecialJoinInfo);
1900 COPY_BITMAPSET_FIELD(min_lefthand);
1901 COPY_BITMAPSET_FIELD(min_righthand);
1902 COPY_BITMAPSET_FIELD(syn_lefthand);
1903 COPY_BITMAPSET_FIELD(syn_righthand);
1904 COPY_SCALAR_FIELD(jointype);
1905 COPY_SCALAR_FIELD(lhs_strict);
1906 COPY_SCALAR_FIELD(delay_upper_joins);
1907 COPY_NODE_FIELD(join_quals);
1913 * _copyLateralJoinInfo
1915 static LateralJoinInfo *
1916 _copyLateralJoinInfo(const LateralJoinInfo *from)
1918 LateralJoinInfo *newnode = makeNode(LateralJoinInfo);
1920 COPY_SCALAR_FIELD(lateral_rhs);
1921 COPY_BITMAPSET_FIELD(lateral_lhs);
1927 * _copyAppendRelInfo
1929 static AppendRelInfo *
1930 _copyAppendRelInfo(const AppendRelInfo *from)
1932 AppendRelInfo *newnode = makeNode(AppendRelInfo);
1934 COPY_SCALAR_FIELD(parent_relid);
1935 COPY_SCALAR_FIELD(child_relid);
1936 COPY_SCALAR_FIELD(parent_reltype);
1937 COPY_SCALAR_FIELD(child_reltype);
1938 COPY_NODE_FIELD(translated_vars);
1939 COPY_SCALAR_FIELD(parent_reloid);
1945 * _copyPlaceHolderInfo
1947 static PlaceHolderInfo *
1948 _copyPlaceHolderInfo(const PlaceHolderInfo *from)
1950 PlaceHolderInfo *newnode = makeNode(PlaceHolderInfo);
1952 COPY_SCALAR_FIELD(phid);
1953 COPY_NODE_FIELD(ph_var);
1954 COPY_BITMAPSET_FIELD(ph_eval_at);
1955 COPY_BITMAPSET_FIELD(ph_needed);
1956 COPY_BITMAPSET_FIELD(ph_may_need);
1957 COPY_SCALAR_FIELD(ph_width);
1962 /* ****************************************************************
1963 * parsenodes.h copy functions
1964 * ****************************************************************
1967 static RangeTblEntry *
1968 _copyRangeTblEntry(const RangeTblEntry *from)
1970 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1972 COPY_SCALAR_FIELD(rtekind);
1973 COPY_SCALAR_FIELD(relid);
1974 COPY_SCALAR_FIELD(relkind);
1975 COPY_NODE_FIELD(subquery);
1976 COPY_SCALAR_FIELD(security_barrier);
1977 COPY_SCALAR_FIELD(jointype);
1978 COPY_NODE_FIELD(joinaliasvars);
1979 COPY_NODE_FIELD(funcexpr);
1980 COPY_NODE_FIELD(funccoltypes);
1981 COPY_NODE_FIELD(funccoltypmods);
1982 COPY_NODE_FIELD(funccolcollations);
1983 COPY_NODE_FIELD(values_lists);
1984 COPY_NODE_FIELD(values_collations);
1985 COPY_STRING_FIELD(ctename);
1986 COPY_SCALAR_FIELD(ctelevelsup);
1987 COPY_SCALAR_FIELD(self_reference);
1988 COPY_NODE_FIELD(ctecoltypes);
1989 COPY_NODE_FIELD(ctecoltypmods);
1990 COPY_NODE_FIELD(ctecolcollations);
1991 COPY_NODE_FIELD(alias);
1992 COPY_NODE_FIELD(eref);
1993 COPY_SCALAR_FIELD(lateral);
1994 COPY_SCALAR_FIELD(inh);
1995 COPY_SCALAR_FIELD(inFromCl);
1996 COPY_SCALAR_FIELD(requiredPerms);
1997 COPY_SCALAR_FIELD(checkAsUser);
1998 COPY_BITMAPSET_FIELD(selectedCols);
1999 COPY_BITMAPSET_FIELD(modifiedCols);
2004 static SortGroupClause *
2005 _copySortGroupClause(const SortGroupClause *from)
2007 SortGroupClause *newnode = makeNode(SortGroupClause);
2009 COPY_SCALAR_FIELD(tleSortGroupRef);
2010 COPY_SCALAR_FIELD(eqop);
2011 COPY_SCALAR_FIELD(sortop);
2012 COPY_SCALAR_FIELD(nulls_first);
2013 COPY_SCALAR_FIELD(hashable);
2018 static WindowClause *
2019 _copyWindowClause(const WindowClause *from)
2021 WindowClause *newnode = makeNode(WindowClause);
2023 COPY_STRING_FIELD(name);
2024 COPY_STRING_FIELD(refname);
2025 COPY_NODE_FIELD(partitionClause);
2026 COPY_NODE_FIELD(orderClause);
2027 COPY_SCALAR_FIELD(frameOptions);
2028 COPY_NODE_FIELD(startOffset);
2029 COPY_NODE_FIELD(endOffset);
2030 COPY_SCALAR_FIELD(winref);
2031 COPY_SCALAR_FIELD(copiedOrder);
2036 static RowMarkClause *
2037 _copyRowMarkClause(const RowMarkClause *from)
2039 RowMarkClause *newnode = makeNode(RowMarkClause);
2041 COPY_SCALAR_FIELD(rti);
2042 COPY_SCALAR_FIELD(strength);
2043 COPY_SCALAR_FIELD(noWait);
2044 COPY_SCALAR_FIELD(pushedDown);
2050 _copyWithClause(const WithClause *from)
2052 WithClause *newnode = makeNode(WithClause);
2054 COPY_NODE_FIELD(ctes);
2055 COPY_SCALAR_FIELD(recursive);
2056 COPY_LOCATION_FIELD(location);
2061 static CommonTableExpr *
2062 _copyCommonTableExpr(const CommonTableExpr *from)
2064 CommonTableExpr *newnode = makeNode(CommonTableExpr);
2066 COPY_STRING_FIELD(ctename);
2067 COPY_NODE_FIELD(aliascolnames);
2068 COPY_NODE_FIELD(ctequery);
2069 COPY_LOCATION_FIELD(location);
2070 COPY_SCALAR_FIELD(cterecursive);
2071 COPY_SCALAR_FIELD(cterefcount);
2072 COPY_NODE_FIELD(ctecolnames);
2073 COPY_NODE_FIELD(ctecoltypes);
2074 COPY_NODE_FIELD(ctecoltypmods);
2075 COPY_NODE_FIELD(ctecolcollations);
2081 _copyAExpr(const A_Expr *from)
2083 A_Expr *newnode = makeNode(A_Expr);
2085 COPY_SCALAR_FIELD(kind);
2086 COPY_NODE_FIELD(name);
2087 COPY_NODE_FIELD(lexpr);
2088 COPY_NODE_FIELD(rexpr);
2089 COPY_LOCATION_FIELD(location);
2095 _copyColumnRef(const ColumnRef *from)
2097 ColumnRef *newnode = makeNode(ColumnRef);
2099 COPY_NODE_FIELD(fields);
2100 COPY_LOCATION_FIELD(location);
2106 _copyParamRef(const ParamRef *from)
2108 ParamRef *newnode = makeNode(ParamRef);
2110 COPY_SCALAR_FIELD(number);
2111 COPY_LOCATION_FIELD(location);
2117 _copyAConst(const A_Const *from)
2119 A_Const *newnode = makeNode(A_Const);
2121 /* This part must duplicate _copyValue */
2122 COPY_SCALAR_FIELD(val.type);
2123 switch (from->val.type)
2126 COPY_SCALAR_FIELD(val.val.ival);
2131 COPY_STRING_FIELD(val.val.str);
2137 elog(ERROR, "unrecognized node type: %d",
2138 (int) from->val.type);
2142 COPY_LOCATION_FIELD(location);
2148 _copyFuncCall(const FuncCall *from)
2150 FuncCall *newnode = makeNode(FuncCall);
2152 COPY_NODE_FIELD(funcname);
2153 COPY_NODE_FIELD(args);
2154 COPY_NODE_FIELD(agg_order);
2155 COPY_SCALAR_FIELD(agg_star);
2156 COPY_SCALAR_FIELD(agg_distinct);
2157 COPY_SCALAR_FIELD(func_variadic);
2158 COPY_NODE_FIELD(over);
2159 COPY_LOCATION_FIELD(location);
2165 _copyAStar(const A_Star *from)
2167 A_Star *newnode = makeNode(A_Star);
2173 _copyAIndices(const A_Indices *from)
2175 A_Indices *newnode = makeNode(A_Indices);
2177 COPY_NODE_FIELD(lidx);
2178 COPY_NODE_FIELD(uidx);
2183 static A_Indirection *
2184 _copyA_Indirection(const A_Indirection *from)
2186 A_Indirection *newnode = makeNode(A_Indirection);
2188 COPY_NODE_FIELD(arg);
2189 COPY_NODE_FIELD(indirection);
2194 static A_ArrayExpr *
2195 _copyA_ArrayExpr(const A_ArrayExpr *from)
2197 A_ArrayExpr *newnode = makeNode(A_ArrayExpr);
2199 COPY_NODE_FIELD(elements);
2200 COPY_LOCATION_FIELD(location);
2206 _copyResTarget(const ResTarget *from)
2208 ResTarget *newnode = makeNode(ResTarget);
2210 COPY_STRING_FIELD(name);
2211 COPY_NODE_FIELD(indirection);
2212 COPY_NODE_FIELD(val);
2213 COPY_LOCATION_FIELD(location);
2219 _copyTypeName(const TypeName *from)
2221 TypeName *newnode = makeNode(TypeName);
2223 COPY_NODE_FIELD(names);
2224 COPY_SCALAR_FIELD(typeOid);
2225 COPY_SCALAR_FIELD(setof);
2226 COPY_SCALAR_FIELD(pct_type);
2227 COPY_NODE_FIELD(typmods);
2228 COPY_SCALAR_FIELD(typemod);
2229 COPY_NODE_FIELD(arrayBounds);
2230 COPY_LOCATION_FIELD(location);
2236 _copySortBy(const SortBy *from)
2238 SortBy *newnode = makeNode(SortBy);
2240 COPY_NODE_FIELD(node);
2241 COPY_SCALAR_FIELD(sortby_dir);
2242 COPY_SCALAR_FIELD(sortby_nulls);
2243 COPY_NODE_FIELD(useOp);
2244 COPY_LOCATION_FIELD(location);
2250 _copyWindowDef(const WindowDef *from)
2252 WindowDef *newnode = makeNode(WindowDef);
2254 COPY_STRING_FIELD(name);
2255 COPY_STRING_FIELD(refname);
2256 COPY_NODE_FIELD(partitionClause);
2257 COPY_NODE_FIELD(orderClause);
2258 COPY_SCALAR_FIELD(frameOptions);
2259 COPY_NODE_FIELD(startOffset);
2260 COPY_NODE_FIELD(endOffset);
2261 COPY_LOCATION_FIELD(location);
2266 static RangeSubselect *
2267 _copyRangeSubselect(const RangeSubselect *from)
2269 RangeSubselect *newnode = makeNode(RangeSubselect);
2271 COPY_SCALAR_FIELD(lateral);
2272 COPY_NODE_FIELD(subquery);
2273 COPY_NODE_FIELD(alias);
2278 static RangeFunction *
2279 _copyRangeFunction(const RangeFunction *from)
2281 RangeFunction *newnode = makeNode(RangeFunction);
2283 COPY_SCALAR_FIELD(lateral);
2284 COPY_NODE_FIELD(funccallnode);
2285 COPY_NODE_FIELD(alias);
2286 COPY_NODE_FIELD(coldeflist);
2292 _copyTypeCast(const TypeCast *from)
2294 TypeCast *newnode = makeNode(TypeCast);
2296 COPY_NODE_FIELD(arg);
2297 COPY_NODE_FIELD(typeName);
2298 COPY_LOCATION_FIELD(location);
2303 static CollateClause *
2304 _copyCollateClause(const CollateClause *from)
2306 CollateClause *newnode = makeNode(CollateClause);
2308 COPY_NODE_FIELD(arg);
2309 COPY_NODE_FIELD(collname);
2310 COPY_LOCATION_FIELD(location);
2316 _copyIndexElem(const IndexElem *from)
2318 IndexElem *newnode = makeNode(IndexElem);
2320 COPY_STRING_FIELD(name);
2321 COPY_NODE_FIELD(expr);
2322 COPY_STRING_FIELD(indexcolname);
2323 COPY_NODE_FIELD(collation);
2324 COPY_NODE_FIELD(opclass);
2325 COPY_SCALAR_FIELD(ordering);
2326 COPY_SCALAR_FIELD(nulls_ordering);
2332 _copyColumnDef(const ColumnDef *from)
2334 ColumnDef *newnode = makeNode(ColumnDef);
2336 COPY_STRING_FIELD(colname);
2337 COPY_NODE_FIELD(typeName);
2338 COPY_SCALAR_FIELD(inhcount);
2339 COPY_SCALAR_FIELD(is_local);
2340 COPY_SCALAR_FIELD(is_not_null);
2341 COPY_SCALAR_FIELD(is_from_type);
2342 COPY_SCALAR_FIELD(storage);
2343 COPY_NODE_FIELD(raw_default);
2344 COPY_NODE_FIELD(cooked_default);
2345 COPY_NODE_FIELD(collClause);
2346 COPY_SCALAR_FIELD(collOid);
2347 COPY_NODE_FIELD(constraints);
2348 COPY_NODE_FIELD(fdwoptions);
2354 _copyConstraint(const Constraint *from)
2356 Constraint *newnode = makeNode(Constraint);
2358 COPY_SCALAR_FIELD(contype);
2359 COPY_STRING_FIELD(conname);
2360 COPY_SCALAR_FIELD(deferrable);
2361 COPY_SCALAR_FIELD(initdeferred);
2362 COPY_LOCATION_FIELD(location);
2363 COPY_SCALAR_FIELD(is_no_inherit);
2364 COPY_NODE_FIELD(raw_expr);
2365 COPY_STRING_FIELD(cooked_expr);
2366 COPY_NODE_FIELD(keys);
2367 COPY_NODE_FIELD(exclusions);
2368 COPY_NODE_FIELD(options);
2369 COPY_STRING_FIELD(indexname);
2370 COPY_STRING_FIELD(indexspace);
2371 COPY_STRING_FIELD(access_method);
2372 COPY_NODE_FIELD(where_clause);
2373 COPY_NODE_FIELD(pktable);
2374 COPY_NODE_FIELD(fk_attrs);
2375 COPY_NODE_FIELD(pk_attrs);
2376 COPY_SCALAR_FIELD(fk_matchtype);
2377 COPY_SCALAR_FIELD(fk_upd_action);
2378 COPY_SCALAR_FIELD(fk_del_action);
2379 COPY_NODE_FIELD(old_conpfeqop);
2380 COPY_SCALAR_FIELD(skip_validation);
2381 COPY_SCALAR_FIELD(initially_valid);
2387 _copyDefElem(const DefElem *from)
2389 DefElem *newnode = makeNode(DefElem);
2391 COPY_STRING_FIELD(defnamespace);
2392 COPY_STRING_FIELD(defname);
2393 COPY_NODE_FIELD(arg);
2394 COPY_SCALAR_FIELD(defaction);
2399 static LockingClause *
2400 _copyLockingClause(const LockingClause *from)
2402 LockingClause *newnode = makeNode(LockingClause);
2404 COPY_NODE_FIELD(lockedRels);
2405 COPY_SCALAR_FIELD(strength);
2406 COPY_SCALAR_FIELD(noWait);
2411 static XmlSerialize *
2412 _copyXmlSerialize(const XmlSerialize *from)
2414 XmlSerialize *newnode = makeNode(XmlSerialize);
2416 COPY_SCALAR_FIELD(xmloption);
2417 COPY_NODE_FIELD(expr);
2418 COPY_NODE_FIELD(typeName);
2419 COPY_LOCATION_FIELD(location);
2425 _copyQuery(const Query *from)
2427 Query *newnode = makeNode(Query);
2429 COPY_SCALAR_FIELD(commandType);
2430 COPY_SCALAR_FIELD(querySource);
2431 COPY_SCALAR_FIELD(queryId);
2432 COPY_SCALAR_FIELD(canSetTag);
2433 COPY_NODE_FIELD(utilityStmt);
2434 COPY_SCALAR_FIELD(resultRelation);
2435 COPY_SCALAR_FIELD(hasAggs);
2436 COPY_SCALAR_FIELD(hasWindowFuncs);
2437 COPY_SCALAR_FIELD(hasSubLinks);
2438 COPY_SCALAR_FIELD(hasDistinctOn);
2439 COPY_SCALAR_FIELD(hasRecursive);
2440 COPY_SCALAR_FIELD(hasModifyingCTE);
2441 COPY_SCALAR_FIELD(hasForUpdate);
2442 COPY_NODE_FIELD(cteList);
2443 COPY_NODE_FIELD(rtable);
2444 COPY_NODE_FIELD(jointree);
2445 COPY_NODE_FIELD(targetList);
2446 COPY_NODE_FIELD(returningList);
2447 COPY_NODE_FIELD(groupClause);
2448 COPY_NODE_FIELD(havingQual);
2449 COPY_NODE_FIELD(windowClause);
2450 COPY_NODE_FIELD(distinctClause);
2451 COPY_NODE_FIELD(sortClause);
2452 COPY_NODE_FIELD(limitOffset);
2453 COPY_NODE_FIELD(limitCount);
2454 COPY_NODE_FIELD(rowMarks);
2455 COPY_NODE_FIELD(setOperations);
2456 COPY_NODE_FIELD(constraintDeps);
2462 _copyInsertStmt(const InsertStmt *from)
2464 InsertStmt *newnode = makeNode(InsertStmt);
2466 COPY_NODE_FIELD(relation);
2467 COPY_NODE_FIELD(cols);
2468 COPY_NODE_FIELD(selectStmt);
2469 COPY_NODE_FIELD(returningList);
2470 COPY_NODE_FIELD(withClause);
2476 _copyDeleteStmt(const DeleteStmt *from)
2478 DeleteStmt *newnode = makeNode(DeleteStmt);
2480 COPY_NODE_FIELD(relation);
2481 COPY_NODE_FIELD(usingClause);
2482 COPY_NODE_FIELD(whereClause);
2483 COPY_NODE_FIELD(returningList);
2484 COPY_NODE_FIELD(withClause);
2490 _copyUpdateStmt(const UpdateStmt *from)
2492 UpdateStmt *newnode = makeNode(UpdateStmt);
2494 COPY_NODE_FIELD(relation);
2495 COPY_NODE_FIELD(targetList);
2496 COPY_NODE_FIELD(whereClause);
2497 COPY_NODE_FIELD(fromClause);
2498 COPY_NODE_FIELD(returningList);
2499 COPY_NODE_FIELD(withClause);
2505 _copySelectStmt(const SelectStmt *from)
2507 SelectStmt *newnode = makeNode(SelectStmt);
2509 COPY_NODE_FIELD(distinctClause);
2510 COPY_NODE_FIELD(intoClause);
2511 COPY_NODE_FIELD(targetList);
2512 COPY_NODE_FIELD(fromClause);
2513 COPY_NODE_FIELD(whereClause);
2514 COPY_NODE_FIELD(groupClause);
2515 COPY_NODE_FIELD(havingClause);
2516 COPY_NODE_FIELD(windowClause);
2517 COPY_NODE_FIELD(valuesLists);
2518 COPY_NODE_FIELD(sortClause);
2519 COPY_NODE_FIELD(limitOffset);
2520 COPY_NODE_FIELD(limitCount);
2521 COPY_NODE_FIELD(lockingClause);
2522 COPY_NODE_FIELD(withClause);
2523 COPY_SCALAR_FIELD(op);
2524 COPY_SCALAR_FIELD(all);
2525 COPY_NODE_FIELD(larg);
2526 COPY_NODE_FIELD(rarg);
2531 static SetOperationStmt *
2532 _copySetOperationStmt(const SetOperationStmt *from)
2534 SetOperationStmt *newnode = makeNode(SetOperationStmt);
2536 COPY_SCALAR_FIELD(op);
2537 COPY_SCALAR_FIELD(all);
2538 COPY_NODE_FIELD(larg);
2539 COPY_NODE_FIELD(rarg);
2540 COPY_NODE_FIELD(colTypes);
2541 COPY_NODE_FIELD(colTypmods);
2542 COPY_NODE_FIELD(colCollations);
2543 COPY_NODE_FIELD(groupClauses);
2548 static AlterTableStmt *
2549 _copyAlterTableStmt(const AlterTableStmt *from)
2551 AlterTableStmt *newnode = makeNode(AlterTableStmt);
2553 COPY_NODE_FIELD(relation);
2554 COPY_NODE_FIELD(cmds);
2555 COPY_SCALAR_FIELD(relkind);
2556 COPY_SCALAR_FIELD(missing_ok);
2561 static AlterTableCmd *
2562 _copyAlterTableCmd(const AlterTableCmd *from)
2564 AlterTableCmd *newnode = makeNode(AlterTableCmd);
2566 COPY_SCALAR_FIELD(subtype);
2567 COPY_STRING_FIELD(name);
2568 COPY_NODE_FIELD(def);
2569 COPY_SCALAR_FIELD(behavior);
2570 COPY_SCALAR_FIELD(missing_ok);
2575 static AlterDomainStmt *
2576 _copyAlterDomainStmt(const AlterDomainStmt *from)
2578 AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
2580 COPY_SCALAR_FIELD(subtype);
2581 COPY_NODE_FIELD(typeName);
2582 COPY_STRING_FIELD(name);
2583 COPY_NODE_FIELD(def);
2584 COPY_SCALAR_FIELD(behavior);
2585 COPY_SCALAR_FIELD(missing_ok);
2591 _copyGrantStmt(const GrantStmt *from)
2593 GrantStmt *newnode = makeNode(GrantStmt);
2595 COPY_SCALAR_FIELD(is_grant);
2596 COPY_SCALAR_FIELD(targtype);
2597 COPY_SCALAR_FIELD(objtype);
2598 COPY_NODE_FIELD(objects);
2599 COPY_NODE_FIELD(privileges);
2600 COPY_NODE_FIELD(grantees);
2601 COPY_SCALAR_FIELD(grant_option);
2602 COPY_SCALAR_FIELD(behavior);
2607 static PrivGrantee *
2608 _copyPrivGrantee(const PrivGrantee *from)
2610 PrivGrantee *newnode = makeNode(PrivGrantee);
2612 COPY_STRING_FIELD(rolname);
2617 static FuncWithArgs *
2618 _copyFuncWithArgs(const FuncWithArgs *from)
2620 FuncWithArgs *newnode = makeNode(FuncWithArgs);
2622 COPY_NODE_FIELD(funcname);
2623 COPY_NODE_FIELD(funcargs);
2629 _copyAccessPriv(const AccessPriv *from)
2631 AccessPriv *newnode = makeNode(AccessPriv);
2633 COPY_STRING_FIELD(priv_name);
2634 COPY_NODE_FIELD(cols);
2639 static GrantRoleStmt *
2640 _copyGrantRoleStmt(const GrantRoleStmt *from)
2642 GrantRoleStmt *newnode = makeNode(GrantRoleStmt);
2644 COPY_NODE_FIELD(granted_roles);
2645 COPY_NODE_FIELD(grantee_roles);
2646 COPY_SCALAR_FIELD(is_grant);
2647 COPY_SCALAR_FIELD(admin_opt);
2648 COPY_STRING_FIELD(grantor);
2649 COPY_SCALAR_FIELD(behavior);
2654 static AlterDefaultPrivilegesStmt *
2655 _copyAlterDefaultPrivilegesStmt(const AlterDefaultPrivilegesStmt *from)
2657 AlterDefaultPrivilegesStmt *newnode = makeNode(AlterDefaultPrivilegesStmt);
2659 COPY_NODE_FIELD(options);
2660 COPY_NODE_FIELD(action);
2665 static DeclareCursorStmt *
2666 _copyDeclareCursorStmt(const DeclareCursorStmt *from)
2668 DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
2670 COPY_STRING_FIELD(portalname);
2671 COPY_SCALAR_FIELD(options);
2672 COPY_NODE_FIELD(query);
2677 static ClosePortalStmt *
2678 _copyClosePortalStmt(const ClosePortalStmt *from)
2680 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
2682 COPY_STRING_FIELD(portalname);
2687 static ClusterStmt *
2688 _copyClusterStmt(const ClusterStmt *from)
2690 ClusterStmt *newnode = makeNode(ClusterStmt);
2692 COPY_NODE_FIELD(relation);
2693 COPY_STRING_FIELD(indexname);
2694 COPY_SCALAR_FIELD(verbose);
2700 _copyCopyStmt(const CopyStmt *from)
2702 CopyStmt *newnode = makeNode(CopyStmt);
2704 COPY_NODE_FIELD(relation);
2705 COPY_NODE_FIELD(query);
2706 COPY_NODE_FIELD(attlist);
2707 COPY_SCALAR_FIELD(is_from);
2708 COPY_SCALAR_FIELD(is_program);
2709 COPY_STRING_FIELD(filename);
2710 COPY_NODE_FIELD(options);
2716 * CopyCreateStmtFields
2718 * This function copies the fields of the CreateStmt node. It is used by
2719 * copy functions for classes which inherit from CreateStmt.
2722 CopyCreateStmtFields(const CreateStmt *from, CreateStmt *newnode)
2724 COPY_NODE_FIELD(relation);
2725 COPY_NODE_FIELD(tableElts);
2726 COPY_NODE_FIELD(inhRelations);
2727 COPY_NODE_FIELD(ofTypename);
2728 COPY_NODE_FIELD(constraints);
2729 COPY_NODE_FIELD(options);
2730 COPY_SCALAR_FIELD(oncommit);
2731 COPY_STRING_FIELD(tablespacename);
2732 COPY_SCALAR_FIELD(if_not_exists);
2736 _copyCreateStmt(const CreateStmt *from)
2738 CreateStmt *newnode = makeNode(CreateStmt);
2740 CopyCreateStmtFields(from, newnode);
2745 static TableLikeClause *
2746 _copyTableLikeClause(const TableLikeClause *from)
2748 TableLikeClause *newnode = makeNode(TableLikeClause);
2750 COPY_NODE_FIELD(relation);
2751 COPY_SCALAR_FIELD(options);
2757 _copyDefineStmt(const DefineStmt *from)
2759 DefineStmt *newnode = makeNode(DefineStmt);
2761 COPY_SCALAR_FIELD(kind);
2762 COPY_SCALAR_FIELD(oldstyle);
2763 COPY_NODE_FIELD(defnames);
2764 COPY_NODE_FIELD(args);
2765 COPY_NODE_FIELD(definition);
2771 _copyDropStmt(const DropStmt *from)
2773 DropStmt *newnode = makeNode(DropStmt);
2775 COPY_NODE_FIELD(objects);
2776 COPY_NODE_FIELD(arguments);
2777 COPY_SCALAR_FIELD(removeType);
2778 COPY_SCALAR_FIELD(behavior);
2779 COPY_SCALAR_FIELD(missing_ok);
2780 COPY_SCALAR_FIELD(concurrent);
2785 static TruncateStmt *
2786 _copyTruncateStmt(const TruncateStmt *from)
2788 TruncateStmt *newnode = makeNode(TruncateStmt);
2790 COPY_NODE_FIELD(relations);
2791 COPY_SCALAR_FIELD(restart_seqs);
2792 COPY_SCALAR_FIELD(behavior);
2797 static CommentStmt *
2798 _copyCommentStmt(const CommentStmt *from)
2800 CommentStmt *newnode = makeNode(CommentStmt);
2802 COPY_SCALAR_FIELD(objtype);
2803 COPY_NODE_FIELD(objname);
2804 COPY_NODE_FIELD(objargs);
2805 COPY_STRING_FIELD(comment);
2810 static SecLabelStmt *
2811 _copySecLabelStmt(const SecLabelStmt *from)
2813 SecLabelStmt *newnode = makeNode(SecLabelStmt);
2815 COPY_SCALAR_FIELD(objtype);
2816 COPY_NODE_FIELD(objname);
2817 COPY_NODE_FIELD(objargs);
2818 COPY_STRING_FIELD(provider);
2819 COPY_STRING_FIELD(label);
2825 _copyFetchStmt(const FetchStmt *from)
2827 FetchStmt *newnode = makeNode(FetchStmt);
2829 COPY_SCALAR_FIELD(direction);
2830 COPY_SCALAR_FIELD(howMany);
2831 COPY_STRING_FIELD(portalname);
2832 COPY_SCALAR_FIELD(ismove);
2838 _copyIndexStmt(const IndexStmt *from)
2840 IndexStmt *newnode = makeNode(IndexStmt);
2842 COPY_STRING_FIELD(idxname);
2843 COPY_NODE_FIELD(relation);
2844 COPY_STRING_FIELD(accessMethod);
2845 COPY_STRING_FIELD(tableSpace);
2846 COPY_NODE_FIELD(indexParams);
2847 COPY_NODE_FIELD(options);
2848 COPY_NODE_FIELD(whereClause);
2849 COPY_NODE_FIELD(excludeOpNames);
2850 COPY_STRING_FIELD(idxcomment);
2851 COPY_SCALAR_FIELD(indexOid);
2852 COPY_SCALAR_FIELD(oldNode);
2853 COPY_SCALAR_FIELD(unique);
2854 COPY_SCALAR_FIELD(primary);
2855 COPY_SCALAR_FIELD(isconstraint);
2856 COPY_SCALAR_FIELD(deferrable);
2857 COPY_SCALAR_FIELD(initdeferred);
2858 COPY_SCALAR_FIELD(concurrent);
2863 static CreateFunctionStmt *
2864 _copyCreateFunctionStmt(const CreateFunctionStmt *from)
2866 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
2868 COPY_SCALAR_FIELD(replace);
2869 COPY_NODE_FIELD(funcname);
2870 COPY_NODE_FIELD(parameters);
2871 COPY_NODE_FIELD(returnType);
2872 COPY_NODE_FIELD(options);
2873 COPY_NODE_FIELD(withClause);
2878 static FunctionParameter *
2879 _copyFunctionParameter(const FunctionParameter *from)
2881 FunctionParameter *newnode = makeNode(FunctionParameter);
2883 COPY_STRING_FIELD(name);
2884 COPY_NODE_FIELD(argType);
2885 COPY_SCALAR_FIELD(mode);
2886 COPY_NODE_FIELD(defexpr);
2891 static AlterFunctionStmt *
2892 _copyAlterFunctionStmt(const AlterFunctionStmt *from)
2894 AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);
2896 COPY_NODE_FIELD(func);
2897 COPY_NODE_FIELD(actions);
2903 _copyDoStmt(const DoStmt *from)
2905 DoStmt *newnode = makeNode(DoStmt);
2907 COPY_NODE_FIELD(args);
2913 _copyRenameStmt(const RenameStmt *from)
2915 RenameStmt *newnode = makeNode(RenameStmt);
2917 COPY_SCALAR_FIELD(renameType);
2918 COPY_SCALAR_FIELD(relationType);
2919 COPY_NODE_FIELD(relation);
2920 COPY_NODE_FIELD(object);
2921 COPY_NODE_FIELD(objarg);
2922 COPY_STRING_FIELD(subname);
2923 COPY_STRING_FIELD(newname);
2924 COPY_SCALAR_FIELD(behavior);
2925 COPY_SCALAR_FIELD(missing_ok);
2930 static AlterObjectSchemaStmt *
2931 _copyAlterObjectSchemaStmt(const AlterObjectSchemaStmt *from)
2933 AlterObjectSchemaStmt *newnode = makeNode(AlterObjectSchemaStmt);
2935 COPY_SCALAR_FIELD(objectType);
2936 COPY_NODE_FIELD(relation);
2937 COPY_NODE_FIELD(object);
2938 COPY_NODE_FIELD(objarg);
2939 COPY_STRING_FIELD(newschema);
2940 COPY_SCALAR_FIELD(missing_ok);
2945 static AlterOwnerStmt *
2946 _copyAlterOwnerStmt(const AlterOwnerStmt *from)
2948 AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);
2950 COPY_SCALAR_FIELD(objectType);
2951 COPY_NODE_FIELD(relation);
2952 COPY_NODE_FIELD(object);
2953 COPY_NODE_FIELD(objarg);
2954 COPY_STRING_FIELD(newowner);
2960 _copyRuleStmt(const RuleStmt *from)
2962 RuleStmt *newnode = makeNode(RuleStmt);
2964 COPY_NODE_FIELD(relation);
2965 COPY_STRING_FIELD(rulename);
2966 COPY_NODE_FIELD(whereClause);
2967 COPY_SCALAR_FIELD(event);
2968 COPY_SCALAR_FIELD(instead);
2969 COPY_NODE_FIELD(actions);
2970 COPY_SCALAR_FIELD(replace);
2976 _copyNotifyStmt(const NotifyStmt *from)
2978 NotifyStmt *newnode = makeNode(NotifyStmt);
2980 COPY_STRING_FIELD(conditionname);
2981 COPY_STRING_FIELD(payload);
2987 _copyListenStmt(const ListenStmt *from)
2989 ListenStmt *newnode = makeNode(ListenStmt);
2991 COPY_STRING_FIELD(conditionname);
2996 static UnlistenStmt *
2997 _copyUnlistenStmt(const UnlistenStmt *from)
2999 UnlistenStmt *newnode = makeNode(UnlistenStmt);
3001 COPY_STRING_FIELD(conditionname);
3006 static TransactionStmt *
3007 _copyTransactionStmt(const TransactionStmt *from)
3009 TransactionStmt *newnode = makeNode(TransactionStmt);
3011 COPY_SCALAR_FIELD(kind);
3012 COPY_NODE_FIELD(options);
3013 COPY_STRING_FIELD(gid);
3018 static CompositeTypeStmt *
3019 _copyCompositeTypeStmt(const CompositeTypeStmt *from)
3021 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
3023 COPY_NODE_FIELD(typevar);
3024 COPY_NODE_FIELD(coldeflist);
3029 static CreateEnumStmt *
3030 _copyCreateEnumStmt(const CreateEnumStmt *from)
3032 CreateEnumStmt *newnode = makeNode(CreateEnumStmt);
3034 COPY_NODE_FIELD(typeName);
3035 COPY_NODE_FIELD(vals);
3040 static CreateRangeStmt *
3041 _copyCreateRangeStmt(const CreateRangeStmt *from)
3043 CreateRangeStmt *newnode = makeNode(CreateRangeStmt);
3045 COPY_NODE_FIELD(typeName);
3046 COPY_NODE_FIELD(params);
3051 static AlterEnumStmt *
3052 _copyAlterEnumStmt(const AlterEnumStmt *from)
3054 AlterEnumStmt *newnode = makeNode(AlterEnumStmt);
3056 COPY_NODE_FIELD(typeName);
3057 COPY_STRING_FIELD(newVal);
3058 COPY_STRING_FIELD(newValNeighbor);
3059 COPY_SCALAR_FIELD(newValIsAfter);
3060 COPY_SCALAR_FIELD(skipIfExists);
3066 _copyViewStmt(const ViewStmt *from)
3068 ViewStmt *newnode = makeNode(ViewStmt);
3070 COPY_NODE_FIELD(view);
3071 COPY_NODE_FIELD(aliases);
3072 COPY_NODE_FIELD(query);
3073 COPY_SCALAR_FIELD(replace);
3074 COPY_NODE_FIELD(options);
3080 _copyLoadStmt(const LoadStmt *from)
3082 LoadStmt *newnode = makeNode(LoadStmt);
3084 COPY_STRING_FIELD(filename);
3089 static CreateDomainStmt *
3090 _copyCreateDomainStmt(const CreateDomainStmt *from)
3092 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
3094 COPY_NODE_FIELD(domainname);
3095 COPY_NODE_FIELD(typeName);
3096 COPY_NODE_FIELD(collClause);
3097 COPY_NODE_FIELD(constraints);
3102 static CreateOpClassStmt *
3103 _copyCreateOpClassStmt(const CreateOpClassStmt *from)
3105 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
3107 COPY_NODE_FIELD(opclassname);
3108 COPY_NODE_FIELD(opfamilyname);
3109 COPY_STRING_FIELD(amname);
3110 COPY_NODE_FIELD(datatype);
3111 COPY_NODE_FIELD(items);
3112 COPY_SCALAR_FIELD(isDefault);
3117 static CreateOpClassItem *
3118 _copyCreateOpClassItem(const CreateOpClassItem *from)
3120 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
3122 COPY_SCALAR_FIELD(itemtype);
3123 COPY_NODE_FIELD(name);
3124 COPY_NODE_FIELD(args);
3125 COPY_SCALAR_FIELD(number);
3126 COPY_NODE_FIELD(order_family);
3127 COPY_NODE_FIELD(class_args);
3128 COPY_NODE_FIELD(storedtype);
3133 static CreateOpFamilyStmt *
3134 _copyCreateOpFamilyStmt(const CreateOpFamilyStmt *from)
3136 CreateOpFamilyStmt *newnode = makeNode(CreateOpFamilyStmt);
3138 COPY_NODE_FIELD(opfamilyname);
3139 COPY_STRING_FIELD(amname);
3144 static AlterOpFamilyStmt *
3145 _copyAlterOpFamilyStmt(const AlterOpFamilyStmt *from)
3147 AlterOpFamilyStmt *newnode = makeNode(AlterOpFamilyStmt);
3149 COPY_NODE_FIELD(opfamilyname);
3150 COPY_STRING_FIELD(amname);
3151 COPY_SCALAR_FIELD(isDrop);
3152 COPY_NODE_FIELD(items);
3157 static CreatedbStmt *
3158 _copyCreatedbStmt(const CreatedbStmt *from)
3160 CreatedbStmt *newnode = makeNode(CreatedbStmt);
3162 COPY_STRING_FIELD(dbname);
3163 COPY_NODE_FIELD(options);
3168 static AlterDatabaseStmt *
3169 _copyAlterDatabaseStmt(const AlterDatabaseStmt *from)
3171 AlterDatabaseStmt *newnode = makeNode(AlterDatabaseStmt);
3173 COPY_STRING_FIELD(dbname);
3174 COPY_NODE_FIELD(options);
3179 static AlterDatabaseSetStmt *
3180 _copyAlterDatabaseSetStmt(const AlterDatabaseSetStmt *from)
3182 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
3184 COPY_STRING_FIELD(dbname);
3185 COPY_NODE_FIELD(setstmt);
3191 _copyDropdbStmt(const DropdbStmt *from)
3193 DropdbStmt *newnode = makeNode(DropdbStmt);
3195 COPY_STRING_FIELD(dbname);
3196 COPY_SCALAR_FIELD(missing_ok);
3202 _copyVacuumStmt(const VacuumStmt *from)
3204 VacuumStmt *newnode = makeNode(VacuumStmt);
3206 COPY_SCALAR_FIELD(options);
3207 COPY_SCALAR_FIELD(freeze_min_age);
3208 COPY_SCALAR_FIELD(freeze_table_age);
3209 COPY_NODE_FIELD(relation);
3210 COPY_NODE_FIELD(va_cols);
3215 static ExplainStmt *
3216 _copyExplainStmt(const ExplainStmt *from)
3218 ExplainStmt *newnode = makeNode(ExplainStmt);
3220 COPY_NODE_FIELD(query);
3221 COPY_NODE_FIELD(options);
3226 static CreateTableAsStmt *
3227 _copyCreateTableAsStmt(const CreateTableAsStmt *from)
3229 CreateTableAsStmt *newnode = makeNode(CreateTableAsStmt);
3231 COPY_NODE_FIELD(query);
3232 COPY_NODE_FIELD(into);
3233 COPY_SCALAR_FIELD(relkind);
3234 COPY_SCALAR_FIELD(is_select_into);
3239 static RefreshMatViewStmt *
3240 _copyRefreshMatViewStmt(const RefreshMatViewStmt *from)
3242 RefreshMatViewStmt *newnode = makeNode(RefreshMatViewStmt);
3244 COPY_SCALAR_FIELD(skipData);
3245 COPY_NODE_FIELD(relation);
3250 static CreateSeqStmt *
3251 _copyCreateSeqStmt(const CreateSeqStmt *from)
3253 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
3255 COPY_NODE_FIELD(sequence);
3256 COPY_NODE_FIELD(options);
3257 COPY_SCALAR_FIELD(ownerId);
3262 static AlterSeqStmt *
3263 _copyAlterSeqStmt(const AlterSeqStmt *from)
3265 AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
3267 COPY_NODE_FIELD(sequence);
3268 COPY_NODE_FIELD(options);
3269 COPY_SCALAR_FIELD(missing_ok);
3274 static VariableSetStmt *
3275 _copyVariableSetStmt(const VariableSetStmt *from)
3277 VariableSetStmt *newnode = makeNode(VariableSetStmt);
3279 COPY_SCALAR_FIELD(kind);
3280 COPY_STRING_FIELD(name);
3281 COPY_NODE_FIELD(args);
3282 COPY_SCALAR_FIELD(is_local);
3287 static VariableShowStmt *
3288 _copyVariableShowStmt(const VariableShowStmt *from)
3290 VariableShowStmt *newnode = makeNode(VariableShowStmt);
3292 COPY_STRING_FIELD(name);
3297 static DiscardStmt *
3298 _copyDiscardStmt(const DiscardStmt *from)
3300 DiscardStmt *newnode = makeNode(DiscardStmt);
3302 COPY_SCALAR_FIELD(target);
3307 static CreateTableSpaceStmt *
3308 _copyCreateTableSpaceStmt(const CreateTableSpaceStmt *from)
3310 CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
3312 COPY_STRING_FIELD(tablespacename);
3313 COPY_STRING_FIELD(owner);
3314 COPY_STRING_FIELD(location);
3319 static DropTableSpaceStmt *
3320 _copyDropTableSpaceStmt(const DropTableSpaceStmt *from)
3322 DropTableSpaceStmt *newnode = makeNode(DropTableSpaceStmt);
3324 COPY_STRING_FIELD(tablespacename);
3325 COPY_SCALAR_FIELD(missing_ok);
3330 static AlterTableSpaceOptionsStmt *
3331 _copyAlterTableSpaceOptionsStmt(const AlterTableSpaceOptionsStmt *from)
3333 AlterTableSpaceOptionsStmt *newnode = makeNode(AlterTableSpaceOptionsStmt);
3335 COPY_STRING_FIELD(tablespacename);
3336 COPY_NODE_FIELD(options);
3337 COPY_SCALAR_FIELD(isReset);
3342 static CreateExtensionStmt *
3343 _copyCreateExtensionStmt(const CreateExtensionStmt *from)
3345 CreateExtensionStmt *newnode = makeNode(CreateExtensionStmt);
3347 COPY_STRING_FIELD(extname);
3348 COPY_SCALAR_FIELD(if_not_exists);
3349 COPY_NODE_FIELD(options);
3354 static AlterExtensionStmt *
3355 _copyAlterExtensionStmt(const AlterExtensionStmt *from)
3357 AlterExtensionStmt *newnode = makeNode(AlterExtensionStmt);
3359 COPY_STRING_FIELD(extname);
3360 COPY_NODE_FIELD(options);
3365 static AlterExtensionContentsStmt *
3366 _copyAlterExtensionContentsStmt(const AlterExtensionContentsStmt *from)
3368 AlterExtensionContentsStmt *newnode = makeNode(AlterExtensionContentsStmt);
3370 COPY_STRING_FIELD(extname);
3371 COPY_SCALAR_FIELD(action);
3372 COPY_SCALAR_FIELD(objtype);
3373 COPY_NODE_FIELD(objname);
3374 COPY_NODE_FIELD(objargs);
3379 static CreateFdwStmt *
3380 _copyCreateFdwStmt(const CreateFdwStmt *from)
3382 CreateFdwStmt *newnode = makeNode(CreateFdwStmt);
3384 COPY_STRING_FIELD(fdwname);
3385 COPY_NODE_FIELD(func_options);
3386 COPY_NODE_FIELD(options);
3391 static AlterFdwStmt *
3392 _copyAlterFdwStmt(const AlterFdwStmt *from)
3394 AlterFdwStmt *newnode = makeNode(AlterFdwStmt);
3396 COPY_STRING_FIELD(fdwname);
3397 COPY_NODE_FIELD(func_options);
3398 COPY_NODE_FIELD(options);
3403 static CreateForeignServerStmt *
3404 _copyCreateForeignServerStmt(const CreateForeignServerStmt *from)
3406 CreateForeignServerStmt *newnode = makeNode(CreateForeignServerStmt);
3408 COPY_STRING_FIELD(servername);
3409 COPY_STRING_FIELD(servertype);
3410 COPY_STRING_FIELD(version);
3411 COPY_STRING_FIELD(fdwname);
3412 COPY_NODE_FIELD(options);
3417 static AlterForeignServerStmt *
3418 _copyAlterForeignServerStmt(const AlterForeignServerStmt *from)
3420 AlterForeignServerStmt *newnode = makeNode(AlterForeignServerStmt);
3422 COPY_STRING_FIELD(servername);
3423 COPY_STRING_FIELD(version);
3424 COPY_NODE_FIELD(options);
3425 COPY_SCALAR_FIELD(has_version);
3430 static CreateUserMappingStmt *
3431 _copyCreateUserMappingStmt(const CreateUserMappingStmt *from)
3433 CreateUserMappingStmt *newnode = makeNode(CreateUserMappingStmt);
3435 COPY_STRING_FIELD(username);
3436 COPY_STRING_FIELD(servername);
3437 COPY_NODE_FIELD(options);
3442 static AlterUserMappingStmt *
3443 _copyAlterUserMappingStmt(const AlterUserMappingStmt *from)
3445 AlterUserMappingStmt *newnode = makeNode(AlterUserMappingStmt);
3447 COPY_STRING_FIELD(username);
3448 COPY_STRING_FIELD(servername);
3449 COPY_NODE_FIELD(options);
3454 static DropUserMappingStmt *
3455 _copyDropUserMappingStmt(const DropUserMappingStmt *from)
3457 DropUserMappingStmt *newnode = makeNode(DropUserMappingStmt);
3459 COPY_STRING_FIELD(username);
3460 COPY_STRING_FIELD(servername);
3461 COPY_SCALAR_FIELD(missing_ok);
3466 static CreateForeignTableStmt *
3467 _copyCreateForeignTableStmt(const CreateForeignTableStmt *from)
3469 CreateForeignTableStmt *newnode = makeNode(CreateForeignTableStmt);
3471 CopyCreateStmtFields((const CreateStmt *) from, (CreateStmt *) newnode);
3473 COPY_STRING_FIELD(servername);
3474 COPY_NODE_FIELD(options);
3479 static CreateTrigStmt *
3480 _copyCreateTrigStmt(const CreateTrigStmt *from)
3482 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
3484 COPY_STRING_FIELD(trigname);
3485 COPY_NODE_FIELD(relation);
3486 COPY_NODE_FIELD(funcname);
3487 COPY_NODE_FIELD(args);
3488 COPY_SCALAR_FIELD(row);
3489 COPY_SCALAR_FIELD(timing);
3490 COPY_SCALAR_FIELD(events);
3491 COPY_NODE_FIELD(columns);
3492 COPY_NODE_FIELD(whenClause);
3493 COPY_SCALAR_FIELD(isconstraint);
3494 COPY_SCALAR_FIELD(deferrable);
3495 COPY_SCALAR_FIELD(initdeferred);
3496 COPY_NODE_FIELD(constrrel);
3501 static CreateEventTrigStmt *
3502 _copyCreateEventTrigStmt(const CreateEventTrigStmt *from)
3504 CreateEventTrigStmt *newnode = makeNode(CreateEventTrigStmt);
3506 COPY_STRING_FIELD(trigname);
3507 COPY_SCALAR_FIELD(eventname);
3508 COPY_NODE_FIELD(whenclause);
3509 COPY_NODE_FIELD(funcname);
3514 static AlterEventTrigStmt *
3515 _copyAlterEventTrigStmt(const AlterEventTrigStmt *from)
3517 AlterEventTrigStmt *newnode = makeNode(AlterEventTrigStmt);
3519 COPY_STRING_FIELD(trigname);
3520 COPY_SCALAR_FIELD(tgenabled);
3525 static CreatePLangStmt *
3526 _copyCreatePLangStmt(const CreatePLangStmt *from)
3528 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
3530 COPY_SCALAR_FIELD(replace);
3531 COPY_STRING_FIELD(plname);
3532 COPY_NODE_FIELD(plhandler);
3533 COPY_NODE_FIELD(plinline);
3534 COPY_NODE_FIELD(plvalidator);
3535 COPY_SCALAR_FIELD(pltrusted);
3540 static CreateRoleStmt *
3541 _copyCreateRoleStmt(const CreateRoleStmt *from)
3543 CreateRoleStmt *newnode = makeNode(CreateRoleStmt);
3545 COPY_SCALAR_FIELD(stmt_type);
3546 COPY_STRING_FIELD(role);
3547 COPY_NODE_FIELD(options);
3552 static AlterRoleStmt *
3553 _copyAlterRoleStmt(const AlterRoleStmt *from)
3555 AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
3557 COPY_STRING_FIELD(role);
3558 COPY_NODE_FIELD(options);
3559 COPY_SCALAR_FIELD(action);
3564 static AlterRoleSetStmt *
3565 _copyAlterRoleSetStmt(const AlterRoleSetStmt *from)
3567 AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
3569 COPY_STRING_FIELD(role);
3570 COPY_STRING_FIELD(database);
3571 COPY_NODE_FIELD(setstmt);
3576 static DropRoleStmt *
3577 _copyDropRoleStmt(const DropRoleStmt *from)
3579 DropRoleStmt *newnode = makeNode(DropRoleStmt);
3581 COPY_NODE_FIELD(roles);
3582 COPY_SCALAR_FIELD(missing_ok);
3588 _copyLockStmt(const LockStmt *from)
3590 LockStmt *newnode = makeNode(LockStmt);
3592 COPY_NODE_FIELD(relations);
3593 COPY_SCALAR_FIELD(mode);
3594 COPY_SCALAR_FIELD(nowait);
3599 static ConstraintsSetStmt *
3600 _copyConstraintsSetStmt(const ConstraintsSetStmt *from)
3602 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
3604 COPY_NODE_FIELD(constraints);
3605 COPY_SCALAR_FIELD(deferred);
3610 static ReindexStmt *
3611 _copyReindexStmt(const ReindexStmt *from)
3613 ReindexStmt *newnode = makeNode(ReindexStmt);
3615 COPY_SCALAR_FIELD(kind);
3616 COPY_NODE_FIELD(relation);
3617 COPY_STRING_FIELD(name);
3618 COPY_SCALAR_FIELD(do_system);
3619 COPY_SCALAR_FIELD(do_user);
3624 static CreateSchemaStmt *
3625 _copyCreateSchemaStmt(const CreateSchemaStmt *from)
3627 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
3629 COPY_STRING_FIELD(schemaname);
3630 COPY_STRING_FIELD(authid);
3631 COPY_NODE_FIELD(schemaElts);
3632 COPY_SCALAR_FIELD(if_not_exists);
3637 static CreateConversionStmt *
3638 _copyCreateConversionStmt(const CreateConversionStmt *from)
3640 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
3642 COPY_NODE_FIELD(conversion_name);
3643 COPY_STRING_FIELD(for_encoding_name);
3644 COPY_STRING_FIELD(to_encoding_name);
3645 COPY_NODE_FIELD(func_name);
3646 COPY_SCALAR_FIELD(def);
3651 static CreateCastStmt *
3652 _copyCreateCastStmt(const CreateCastStmt *from)
3654 CreateCastStmt *newnode = makeNode(CreateCastStmt);
3656 COPY_NODE_FIELD(sourcetype);
3657 COPY_NODE_FIELD(targettype);
3658 COPY_NODE_FIELD(func);
3659 COPY_SCALAR_FIELD(context);
3660 COPY_SCALAR_FIELD(inout);
3665 static PrepareStmt *
3666 _copyPrepareStmt(const PrepareStmt *from)
3668 PrepareStmt *newnode = makeNode(PrepareStmt);
3670 COPY_STRING_FIELD(name);
3671 COPY_NODE_FIELD(argtypes);
3672 COPY_NODE_FIELD(query);
3677 static ExecuteStmt *
3678 _copyExecuteStmt(const ExecuteStmt *from)
3680 ExecuteStmt *newnode = makeNode(ExecuteStmt);
3682 COPY_STRING_FIELD(name);
3683 COPY_NODE_FIELD(params);
3688 static DeallocateStmt *
3689 _copyDeallocateStmt(const DeallocateStmt *from)
3691 DeallocateStmt *newnode = makeNode(DeallocateStmt);
3693 COPY_STRING_FIELD(name);
3698 static DropOwnedStmt *
3699 _copyDropOwnedStmt(const DropOwnedStmt *from)
3701 DropOwnedStmt *newnode = makeNode(DropOwnedStmt);
3703 COPY_NODE_FIELD(roles);
3704 COPY_SCALAR_FIELD(behavior);
3709 static ReassignOwnedStmt *
3710 _copyReassignOwnedStmt(const ReassignOwnedStmt *from)
3712 ReassignOwnedStmt *newnode = makeNode(ReassignOwnedStmt);
3714 COPY_NODE_FIELD(roles);
3715 COPY_STRING_FIELD(newrole);
3720 static AlterTSDictionaryStmt *
3721 _copyAlterTSDictionaryStmt(const AlterTSDictionaryStmt *from)
3723 AlterTSDictionaryStmt *newnode = makeNode(AlterTSDictionaryStmt);
3725 COPY_NODE_FIELD(dictname);
3726 COPY_NODE_FIELD(options);
3731 static AlterTSConfigurationStmt *
3732 _copyAlterTSConfigurationStmt(const AlterTSConfigurationStmt *from)
3734 AlterTSConfigurationStmt *newnode = makeNode(AlterTSConfigurationStmt);
3736 COPY_NODE_FIELD(cfgname);
3737 COPY_NODE_FIELD(tokentype);
3738 COPY_NODE_FIELD(dicts);
3739 COPY_SCALAR_FIELD(override);
3740 COPY_SCALAR_FIELD(replace);
3741 COPY_SCALAR_FIELD(missing_ok);
3746 /* ****************************************************************
3747 * pg_list.h copy functions
3748 * ****************************************************************
3752 * Perform a deep copy of the specified list, using copyObject(). The
3753 * list MUST be of type T_List; T_IntList and T_OidList nodes don't
3754 * need deep copies, so they should be copied via list_copy()
3756 #define COPY_NODE_CELL(new, old) \
3757 (new) = (ListCell *) palloc(sizeof(ListCell)); \
3758 lfirst(new) = copyObject(lfirst(old));
3761 _copyList(const List *from)
3767 Assert(list_length(from) >= 1);
3769 new = makeNode(List);
3770 new->length = from->length;
3772 COPY_NODE_CELL(new->head, from->head);
3773 prev_new = new->head;
3774 curr_old = lnext(from->head);
3778 COPY_NODE_CELL(prev_new->next, curr_old);
3779 prev_new = prev_new->next;
3780 curr_old = curr_old->next;
3782 prev_new->next = NULL;
3783 new->tail = prev_new;
3788 /* ****************************************************************
3789 * value.h copy functions
3790 * ****************************************************************
3793 _copyValue(const Value *from)
3795 Value *newnode = makeNode(Value);
3797 /* See also _copyAConst when changing this code! */
3799 COPY_SCALAR_FIELD(type);
3803 COPY_SCALAR_FIELD(val.ival);
3808 COPY_STRING_FIELD(val.str);
3814 elog(ERROR, "unrecognized node type: %d",
3824 * Create a copy of a Node tree or list. This is a "deep" copy: all
3825 * substructure is copied too, recursively.
3828 copyObject(const void *from)
3835 /* Guard against stack overflow due to overly complex expressions */
3836 check_stack_depth();
3838 switch (nodeTag(from))
3844 retval = _copyPlannedStmt(from);
3847 retval = _copyPlan(from);
3850 retval = _copyResult(from);
3853 retval = _copyModifyTable(from);
3856 retval = _copyAppend(from);
3859 retval = _copyMergeAppend(from);
3861 case T_RecursiveUnion:
3862 retval = _copyRecursiveUnion(from);
3865 retval = _copyBitmapAnd(from);
3868 retval = _copyBitmapOr(from);
3871 retval = _copyScan(from);
3874 retval = _copySeqScan(from);
3877 retval = _copyIndexScan(from);
3879 case T_IndexOnlyScan:
3880 retval = _copyIndexOnlyScan(from);
3882 case T_BitmapIndexScan:
3883 retval = _copyBitmapIndexScan(from);
3885 case T_BitmapHeapScan:
3886 retval = _copyBitmapHeapScan(from);
3889 retval = _copyTidScan(from);
3891 case T_SubqueryScan:
3892 retval = _copySubqueryScan(from);
3894 case T_FunctionScan:
3895 retval = _copyFunctionScan(from);
3898 retval = _copyValuesScan(from);
3901 retval = _copyCteScan(from);
3903 case T_WorkTableScan:
3904 retval = _copyWorkTableScan(from);
3907 retval = _copyForeignScan(from);
3910 retval = _copyJoin(from);
3913 retval = _copyNestLoop(from);
3916 retval = _copyMergeJoin(from);
3919 retval = _copyHashJoin(from);
3922 retval = _copyMaterial(from);
3925 retval = _copySort(from);
3928 retval = _copyGroup(from);
3931 retval = _copyAgg(from);
3934 retval = _copyWindowAgg(from);
3937 retval = _copyUnique(from);
3940 retval = _copyHash(from);
3943 retval = _copySetOp(from);
3946 retval = _copyLockRows(from);
3949 retval = _copyLimit(from);
3951 case T_NestLoopParam:
3952 retval = _copyNestLoopParam(from);
3955 retval = _copyPlanRowMark(from);
3957 case T_PlanInvalItem:
3958 retval = _copyPlanInvalItem(from);
3965 retval = _copyAlias(from);
3968 retval = _copyRangeVar(from);
3971 retval = _copyIntoClause(from);
3974 retval = _copyVar(from);
3977 retval = _copyConst(from);
3980 retval = _copyParam(from);
3983 retval = _copyAggref(from);
3986 retval = _copyWindowFunc(from);
3989 retval = _copyArrayRef(from);
3992 retval = _copyFuncExpr(from);
3994 case T_NamedArgExpr:
3995 retval = _copyNamedArgExpr(from);
3998 retval = _copyOpExpr(from);
4000 case T_DistinctExpr:
4001 retval = _copyDistinctExpr(from);
4004 retval = _copyNullIfExpr(from);
4006 case T_ScalarArrayOpExpr:
4007 retval = _copyScalarArrayOpExpr(from);
4010 retval = _copyBoolExpr(from);
4013 retval = _copySubLink(from);
4016 retval = _copySubPlan(from);
4018 case T_AlternativeSubPlan:
4019 retval = _copyAlternativeSubPlan(from);
4022 retval = _copyFieldSelect(from);
4025 retval = _copyFieldStore(from);
4028 retval = _copyRelabelType(from);
4031 retval = _copyCoerceViaIO(from);
4033 case T_ArrayCoerceExpr:
4034 retval = _copyArrayCoerceExpr(from);
4036 case T_ConvertRowtypeExpr:
4037 retval = _copyConvertRowtypeExpr(from);
4040 retval = _copyCollateExpr(from);
4043 retval = _copyCaseExpr(from);
4046 retval = _copyCaseWhen(from);
4048 case T_CaseTestExpr:
4049 retval = _copyCaseTestExpr(from);
4052 retval = _copyArrayExpr(from);
4055 retval = _copyRowExpr(from);
4057 case T_RowCompareExpr:
4058 retval = _copyRowCompareExpr(from);
4060 case T_CoalesceExpr:
4061 retval = _copyCoalesceExpr(from);
4064 retval = _copyMinMaxExpr(from);
4067 retval = _copyXmlExpr(from);
4070 retval = _copyNullTest(from);
4073 retval = _copyBooleanTest(from);
4075 case T_CoerceToDomain:
4076 retval = _copyCoerceToDomain(from);
4078 case T_CoerceToDomainValue:
4079 retval = _copyCoerceToDomainValue(from);
4081 case T_SetToDefault:
4082 retval = _copySetToDefault(from);
4084 case T_CurrentOfExpr:
4085 retval = _copyCurrentOfExpr(from);
4088 retval = _copyTargetEntry(from);
4091 retval = _copyRangeTblRef(from);
4094 retval = _copyJoinExpr(from);
4097 retval = _copyFromExpr(from);
4104 retval = _copyPathKey(from);
4106 case T_RestrictInfo:
4107 retval = _copyRestrictInfo(from);
4109 case T_PlaceHolderVar:
4110 retval = _copyPlaceHolderVar(from);
4112 case T_SpecialJoinInfo:
4113 retval = _copySpecialJoinInfo(from);
4115 case T_LateralJoinInfo:
4116 retval = _copyLateralJoinInfo(from);
4118 case T_AppendRelInfo:
4119 retval = _copyAppendRelInfo(from);
4121 case T_PlaceHolderInfo:
4122 retval = _copyPlaceHolderInfo(from);
4133 retval = _copyValue(from);
4140 retval = _copyList(from);
4144 * Lists of integers and OIDs don't need to be deep-copied, so we
4145 * perform a shallow copy via list_copy()
4149 retval = list_copy(from);
4156 retval = _copyQuery(from);
4159 retval = _copyInsertStmt(from);
4162 retval = _copyDeleteStmt(from);
4165 retval = _copyUpdateStmt(from);
4168 retval = _copySelectStmt(from);
4170 case T_SetOperationStmt:
4171 retval = _copySetOperationStmt(from);
4173 case T_AlterTableStmt:
4174 retval = _copyAlterTableStmt(from);
4176 case T_AlterTableCmd:
4177 retval = _copyAlterTableCmd(from);
4179 case T_AlterDomainStmt:
4180 retval = _copyAlterDomainStmt(from);
4183 retval = _copyGrantStmt(from);
4185 case T_GrantRoleStmt:
4186 retval = _copyGrantRoleStmt(from);
4188 case T_AlterDefaultPrivilegesStmt:
4189 retval = _copyAlterDefaultPrivilegesStmt(from);
4191 case T_DeclareCursorStmt:
4192 retval = _copyDeclareCursorStmt(from);
4194 case T_ClosePortalStmt:
4195 retval = _copyClosePortalStmt(from);
4198 retval = _copyClusterStmt(from);
4201 retval = _copyCopyStmt(from);
4204 retval = _copyCreateStmt(from);
4206 case T_TableLikeClause:
4207 retval = _copyTableLikeClause(from);
4210 retval = _copyDefineStmt(from);
4213 retval = _copyDropStmt(from);
4215 case T_TruncateStmt:
4216 retval = _copyTruncateStmt(from);
4219 retval = _copyCommentStmt(from);
4221 case T_SecLabelStmt:
4222 retval = _copySecLabelStmt(from);
4225 retval = _copyFetchStmt(from);
4228 retval = _copyIndexStmt(from);
4230 case T_CreateFunctionStmt:
4231 retval = _copyCreateFunctionStmt(from);
4233 case T_FunctionParameter:
4234 retval = _copyFunctionParameter(from);
4236 case T_AlterFunctionStmt:
4237 retval = _copyAlterFunctionStmt(from);
4240 retval = _copyDoStmt(from);
4243 retval = _copyRenameStmt(from);
4245 case T_AlterObjectSchemaStmt:
4246 retval = _copyAlterObjectSchemaStmt(from);
4248 case T_AlterOwnerStmt:
4249 retval = _copyAlterOwnerStmt(from);
4252 retval = _copyRuleStmt(from);
4255 retval = _copyNotifyStmt(from);
4258 retval = _copyListenStmt(from);
4260 case T_UnlistenStmt:
4261 retval = _copyUnlistenStmt(from);
4263 case T_TransactionStmt:
4264 retval = _copyTransactionStmt(from);
4266 case T_CompositeTypeStmt:
4267 retval = _copyCompositeTypeStmt(from);
4269 case T_CreateEnumStmt:
4270 retval = _copyCreateEnumStmt(from);
4272 case T_CreateRangeStmt:
4273 retval = _copyCreateRangeStmt(from);
4275 case T_AlterEnumStmt:
4276 retval = _copyAlterEnumStmt(from);
4279 retval = _copyViewStmt(from);
4282 retval = _copyLoadStmt(from);
4284 case T_CreateDomainStmt:
4285 retval = _copyCreateDomainStmt(from);
4287 case T_CreateOpClassStmt:
4288 retval = _copyCreateOpClassStmt(from);
4290 case T_CreateOpClassItem:
4291 retval = _copyCreateOpClassItem(from);
4293 case T_CreateOpFamilyStmt:
4294 retval = _copyCreateOpFamilyStmt(from);
4296 case T_AlterOpFamilyStmt:
4297 retval = _copyAlterOpFamilyStmt(from);
4299 case T_CreatedbStmt:
4300 retval = _copyCreatedbStmt(from);
4302 case T_AlterDatabaseStmt:
4303 retval = _copyAlterDatabaseStmt(from);
4305 case T_AlterDatabaseSetStmt:
4306 retval = _copyAlterDatabaseSetStmt(from);
4309 retval = _copyDropdbStmt(from);
4312 retval = _copyVacuumStmt(from);
4315 retval = _copyExplainStmt(from);
4317 case T_CreateTableAsStmt:
4318 retval = _copyCreateTableAsStmt(from);
4320 case T_RefreshMatViewStmt:
4321 retval = _copyRefreshMatViewStmt(from);
4323 case T_CreateSeqStmt:
4324 retval = _copyCreateSeqStmt(from);
4326 case T_AlterSeqStmt:
4327 retval = _copyAlterSeqStmt(from);
4329 case T_VariableSetStmt:
4330 retval = _copyVariableSetStmt(from);
4332 case T_VariableShowStmt:
4333 retval = _copyVariableShowStmt(from);
4336 retval = _copyDiscardStmt(from);
4338 case T_CreateTableSpaceStmt:
4339 retval = _copyCreateTableSpaceStmt(from);
4341 case T_DropTableSpaceStmt:
4342 retval = _copyDropTableSpaceStmt(from);
4344 case T_AlterTableSpaceOptionsStmt:
4345 retval = _copyAlterTableSpaceOptionsStmt(from);
4347 case T_CreateExtensionStmt:
4348 retval = _copyCreateExtensionStmt(from);
4350 case T_AlterExtensionStmt:
4351 retval = _copyAlterExtensionStmt(from);
4353 case T_AlterExtensionContentsStmt:
4354 retval = _copyAlterExtensionContentsStmt(from);
4356 case T_CreateFdwStmt:
4357 retval = _copyCreateFdwStmt(from);
4359 case T_AlterFdwStmt:
4360 retval = _copyAlterFdwStmt(from);
4362 case T_CreateForeignServerStmt:
4363 retval = _copyCreateForeignServerStmt(from);
4365 case T_AlterForeignServerStmt:
4366 retval = _copyAlterForeignServerStmt(from);
4368 case T_CreateUserMappingStmt:
4369 retval = _copyCreateUserMappingStmt(from);
4371 case T_AlterUserMappingStmt:
4372 retval = _copyAlterUserMappingStmt(from);
4374 case T_DropUserMappingStmt:
4375 retval = _copyDropUserMappingStmt(from);
4377 case T_CreateForeignTableStmt:
4378 retval = _copyCreateForeignTableStmt(from);
4380 case T_CreateTrigStmt:
4381 retval = _copyCreateTrigStmt(from);
4383 case T_CreateEventTrigStmt:
4384 retval = _copyCreateEventTrigStmt(from);
4386 case T_AlterEventTrigStmt:
4387 retval = _copyAlterEventTrigStmt(from);
4389 case T_CreatePLangStmt:
4390 retval = _copyCreatePLangStmt(from);
4392 case T_CreateRoleStmt:
4393 retval = _copyCreateRoleStmt(from);
4395 case T_AlterRoleStmt:
4396 retval = _copyAlterRoleStmt(from);
4398 case T_AlterRoleSetStmt:
4399 retval = _copyAlterRoleSetStmt(from);
4401 case T_DropRoleStmt:
4402 retval = _copyDropRoleStmt(from);
4405 retval = _copyLockStmt(from);
4407 case T_ConstraintsSetStmt:
4408 retval = _copyConstraintsSetStmt(from);
4411 retval = _copyReindexStmt(from);
4413 case T_CheckPointStmt:
4414 retval = (void *) makeNode(CheckPointStmt);
4416 case T_CreateSchemaStmt:
4417 retval = _copyCreateSchemaStmt(from);
4419 case T_CreateConversionStmt:
4420 retval = _copyCreateConversionStmt(from);
4422 case T_CreateCastStmt:
4423 retval = _copyCreateCastStmt(from);
4426 retval = _copyPrepareStmt(from);
4429 retval = _copyExecuteStmt(from);
4431 case T_DeallocateStmt:
4432 retval = _copyDeallocateStmt(from);
4434 case T_DropOwnedStmt:
4435 retval = _copyDropOwnedStmt(from);
4437 case T_ReassignOwnedStmt:
4438 retval = _copyReassignOwnedStmt(from);
4440 case T_AlterTSDictionaryStmt:
4441 retval = _copyAlterTSDictionaryStmt(from);
4443 case T_AlterTSConfigurationStmt:
4444 retval = _copyAlterTSConfigurationStmt(from);
4448 retval = _copyAExpr(from);
4451 retval = _copyColumnRef(from);
4454 retval = _copyParamRef(from);
4457 retval = _copyAConst(from);
4460 retval = _copyFuncCall(from);
4463 retval = _copyAStar(from);
4466 retval = _copyAIndices(from);
4468 case T_A_Indirection:
4469 retval = _copyA_Indirection(from);
4472 retval = _copyA_ArrayExpr(from);
4475 retval = _copyResTarget(from);
4478 retval = _copyTypeCast(from);
4480 case T_CollateClause:
4481 retval = _copyCollateClause(from);
4484 retval = _copySortBy(from);
4487 retval = _copyWindowDef(from);
4489 case T_RangeSubselect:
4490 retval = _copyRangeSubselect(from);
4492 case T_RangeFunction:
4493 retval = _copyRangeFunction(from);
4496 retval = _copyTypeName(from);
4499 retval = _copyIndexElem(from);
4502 retval = _copyColumnDef(from);
4505 retval = _copyConstraint(from);
4508 retval = _copyDefElem(from);
4510 case T_LockingClause:
4511 retval = _copyLockingClause(from);
4513 case T_RangeTblEntry:
4514 retval = _copyRangeTblEntry(from);
4516 case T_SortGroupClause:
4517 retval = _copySortGroupClause(from);
4519 case T_WindowClause:
4520 retval = _copyWindowClause(from);
4522 case T_RowMarkClause:
4523 retval = _copyRowMarkClause(from);
4526 retval = _copyWithClause(from);
4528 case T_CommonTableExpr:
4529 retval = _copyCommonTableExpr(from);
4532 retval = _copyPrivGrantee(from);
4534 case T_FuncWithArgs:
4535 retval = _copyFuncWithArgs(from);
4538 retval = _copyAccessPriv(from);
4540 case T_XmlSerialize:
4541 retval = _copyXmlSerialize(from);
4545 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
4546 retval = 0; /* keep compiler quiet */