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-2005, PostgreSQL Global Development Group
15 * Portions Copyright (c) 1994, Regents of the University of California
18 * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.305 2005/06/05 22:32:54 tgl Exp $
20 *-------------------------------------------------------------------------
25 #include "nodes/parsenodes.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); \
63 /* ****************************************************************
64 * plannodes.h copy functions
65 * ****************************************************************
71 * This function copies the fields of the Plan node. It is used by
72 * all the copy functions for classes which inherit from Plan.
75 CopyPlanFields(Plan *from, Plan *newnode)
77 COPY_SCALAR_FIELD(startup_cost);
78 COPY_SCALAR_FIELD(total_cost);
79 COPY_SCALAR_FIELD(plan_rows);
80 COPY_SCALAR_FIELD(plan_width);
81 COPY_NODE_FIELD(targetlist);
82 COPY_NODE_FIELD(qual);
83 COPY_NODE_FIELD(lefttree);
84 COPY_NODE_FIELD(righttree);
85 COPY_NODE_FIELD(initPlan);
86 COPY_BITMAPSET_FIELD(extParam);
87 COPY_BITMAPSET_FIELD(allParam);
88 COPY_SCALAR_FIELD(nParamExec);
97 Plan *newnode = makeNode(Plan);
100 * copy node superclass fields
102 CopyPlanFields(from, newnode);
112 _copyResult(Result *from)
114 Result *newnode = makeNode(Result);
117 * copy node superclass fields
119 CopyPlanFields((Plan *) from, (Plan *) newnode);
122 * copy remainder of node
124 COPY_NODE_FIELD(resconstantqual);
133 _copyAppend(Append *from)
135 Append *newnode = makeNode(Append);
138 * copy node superclass fields
140 CopyPlanFields((Plan *) from, (Plan *) newnode);
143 * copy remainder of node
145 COPY_NODE_FIELD(appendplans);
146 COPY_SCALAR_FIELD(isTarget);
155 _copyBitmapAnd(BitmapAnd *from)
157 BitmapAnd *newnode = makeNode(BitmapAnd);
160 * copy node superclass fields
162 CopyPlanFields((Plan *) from, (Plan *) newnode);
165 * copy remainder of node
167 COPY_NODE_FIELD(bitmapplans);
176 _copyBitmapOr(BitmapOr *from)
178 BitmapOr *newnode = makeNode(BitmapOr);
181 * copy node superclass fields
183 CopyPlanFields((Plan *) from, (Plan *) newnode);
186 * copy remainder of node
188 COPY_NODE_FIELD(bitmapplans);
197 * This function copies the fields of the Scan node. It is used by
198 * all the copy functions for classes which inherit from Scan.
201 CopyScanFields(Scan *from, Scan *newnode)
203 CopyPlanFields((Plan *) from, (Plan *) newnode);
205 COPY_SCALAR_FIELD(scanrelid);
212 _copyScan(Scan *from)
214 Scan *newnode = makeNode(Scan);
217 * copy node superclass fields
219 CopyScanFields((Scan *) from, (Scan *) newnode);
228 _copySeqScan(SeqScan *from)
230 SeqScan *newnode = makeNode(SeqScan);
233 * copy node superclass fields
235 CopyScanFields((Scan *) from, (Scan *) newnode);
244 _copyIndexScan(IndexScan *from)
246 IndexScan *newnode = makeNode(IndexScan);
249 * copy node superclass fields
251 CopyScanFields((Scan *) from, (Scan *) newnode);
254 * copy remainder of node
256 COPY_SCALAR_FIELD(indexid);
257 COPY_NODE_FIELD(indexqual);
258 COPY_NODE_FIELD(indexqualorig);
259 COPY_NODE_FIELD(indexstrategy);
260 COPY_NODE_FIELD(indexsubtype);
261 COPY_SCALAR_FIELD(indexorderdir);
267 * _copyBitmapIndexScan
269 static BitmapIndexScan *
270 _copyBitmapIndexScan(BitmapIndexScan *from)
272 BitmapIndexScan *newnode = makeNode(BitmapIndexScan);
275 * copy node superclass fields
277 CopyScanFields((Scan *) from, (Scan *) newnode);
280 * copy remainder of node
282 COPY_SCALAR_FIELD(indexid);
283 COPY_NODE_FIELD(indexqual);
284 COPY_NODE_FIELD(indexqualorig);
285 COPY_NODE_FIELD(indexstrategy);
286 COPY_NODE_FIELD(indexsubtype);
292 * _copyBitmapHeapScan
294 static BitmapHeapScan *
295 _copyBitmapHeapScan(BitmapHeapScan *from)
297 BitmapHeapScan *newnode = makeNode(BitmapHeapScan);
300 * copy node superclass fields
302 CopyScanFields((Scan *) from, (Scan *) newnode);
305 * copy remainder of node
307 COPY_NODE_FIELD(bitmapqualorig);
316 _copyTidScan(TidScan *from)
318 TidScan *newnode = makeNode(TidScan);
321 * copy node superclass fields
323 CopyScanFields((Scan *) from, (Scan *) newnode);
326 * copy remainder of node
328 COPY_NODE_FIELD(tideval);
336 static SubqueryScan *
337 _copySubqueryScan(SubqueryScan *from)
339 SubqueryScan *newnode = makeNode(SubqueryScan);
342 * copy node superclass fields
344 CopyScanFields((Scan *) from, (Scan *) newnode);
347 * copy remainder of node
349 COPY_NODE_FIELD(subplan);
357 static FunctionScan *
358 _copyFunctionScan(FunctionScan *from)
360 FunctionScan *newnode = makeNode(FunctionScan);
363 * copy node superclass fields
365 CopyScanFields((Scan *) from, (Scan *) newnode);
373 * This function copies the fields of the Join node. It is used by
374 * all the copy functions for classes which inherit from Join.
377 CopyJoinFields(Join *from, Join *newnode)
379 CopyPlanFields((Plan *) from, (Plan *) newnode);
381 COPY_SCALAR_FIELD(jointype);
382 COPY_NODE_FIELD(joinqual);
390 _copyJoin(Join *from)
392 Join *newnode = makeNode(Join);
395 * copy node superclass fields
397 CopyJoinFields(from, newnode);
407 _copyNestLoop(NestLoop *from)
409 NestLoop *newnode = makeNode(NestLoop);
412 * copy node superclass fields
414 CopyJoinFields((Join *) from, (Join *) newnode);
424 _copyMergeJoin(MergeJoin *from)
426 MergeJoin *newnode = makeNode(MergeJoin);
429 * copy node superclass fields
431 CopyJoinFields((Join *) from, (Join *) newnode);
434 * copy remainder of node
436 COPY_NODE_FIELD(mergeclauses);
445 _copyHashJoin(HashJoin *from)
447 HashJoin *newnode = makeNode(HashJoin);
450 * copy node superclass fields
452 CopyJoinFields((Join *) from, (Join *) newnode);
455 * copy remainder of node
457 COPY_NODE_FIELD(hashclauses);
467 _copyMaterial(Material *from)
469 Material *newnode = makeNode(Material);
472 * copy node superclass fields
474 CopyPlanFields((Plan *) from, (Plan *) newnode);
484 _copySort(Sort *from)
486 Sort *newnode = makeNode(Sort);
489 * copy node superclass fields
491 CopyPlanFields((Plan *) from, (Plan *) newnode);
493 COPY_SCALAR_FIELD(numCols);
494 COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
495 COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
505 _copyGroup(Group *from)
507 Group *newnode = makeNode(Group);
509 CopyPlanFields((Plan *) from, (Plan *) newnode);
511 COPY_SCALAR_FIELD(numCols);
512 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
523 Agg *newnode = makeNode(Agg);
525 CopyPlanFields((Plan *) from, (Plan *) newnode);
527 COPY_SCALAR_FIELD(aggstrategy);
528 COPY_SCALAR_FIELD(numCols);
529 if (from->numCols > 0)
530 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
531 COPY_SCALAR_FIELD(numGroups);
540 _copyUnique(Unique *from)
542 Unique *newnode = makeNode(Unique);
545 * copy node superclass fields
547 CopyPlanFields((Plan *) from, (Plan *) newnode);
550 * copy remainder of node
552 COPY_SCALAR_FIELD(numCols);
553 COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
562 _copyHash(Hash *from)
564 Hash *newnode = makeNode(Hash);
567 * copy node superclass fields
569 CopyPlanFields((Plan *) from, (Plan *) newnode);
572 * copy remainder of node
582 _copySetOp(SetOp *from)
584 SetOp *newnode = makeNode(SetOp);
587 * copy node superclass fields
589 CopyPlanFields((Plan *) from, (Plan *) newnode);
592 * copy remainder of node
594 COPY_SCALAR_FIELD(cmd);
595 COPY_SCALAR_FIELD(numCols);
596 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
597 COPY_SCALAR_FIELD(flagColIdx);
606 _copyLimit(Limit *from)
608 Limit *newnode = makeNode(Limit);
611 * copy node superclass fields
613 CopyPlanFields((Plan *) from, (Plan *) newnode);
616 * copy remainder of node
618 COPY_NODE_FIELD(limitOffset);
619 COPY_NODE_FIELD(limitCount);
624 /* ****************************************************************
625 * primnodes.h copy functions
626 * ****************************************************************
633 _copyAlias(Alias *from)
635 Alias *newnode = makeNode(Alias);
637 COPY_STRING_FIELD(aliasname);
638 COPY_NODE_FIELD(colnames);
647 _copyRangeVar(RangeVar *from)
649 RangeVar *newnode = makeNode(RangeVar);
651 COPY_STRING_FIELD(catalogname);
652 COPY_STRING_FIELD(schemaname);
653 COPY_STRING_FIELD(relname);
654 COPY_SCALAR_FIELD(inhOpt);
655 COPY_SCALAR_FIELD(istemp);
656 COPY_NODE_FIELD(alias);
662 * We don't need a _copyExpr because Expr is an abstract supertype which
663 * should never actually get instantiated. Also, since it has no common
664 * fields except NodeTag, there's no need for a helper routine to factor
665 * out copying the common fields...
674 Var *newnode = makeNode(Var);
676 COPY_SCALAR_FIELD(varno);
677 COPY_SCALAR_FIELD(varattno);
678 COPY_SCALAR_FIELD(vartype);
679 COPY_SCALAR_FIELD(vartypmod);
680 COPY_SCALAR_FIELD(varlevelsup);
681 COPY_SCALAR_FIELD(varnoold);
682 COPY_SCALAR_FIELD(varoattno);
691 _copyConst(Const *from)
693 Const *newnode = makeNode(Const);
695 COPY_SCALAR_FIELD(consttype);
696 COPY_SCALAR_FIELD(constlen);
698 if (from->constbyval || from->constisnull)
701 * passed by value so just copy the datum. Also, don't try to copy
702 * struct when value is null!
704 newnode->constvalue = from->constvalue;
709 * passed by reference. We need a palloc'd copy.
711 newnode->constvalue = datumCopy(from->constvalue,
716 COPY_SCALAR_FIELD(constisnull);
717 COPY_SCALAR_FIELD(constbyval);
726 _copyParam(Param *from)
728 Param *newnode = makeNode(Param);
730 COPY_SCALAR_FIELD(paramkind);
731 COPY_SCALAR_FIELD(paramid);
732 COPY_STRING_FIELD(paramname);
733 COPY_SCALAR_FIELD(paramtype);
742 _copyAggref(Aggref *from)
744 Aggref *newnode = makeNode(Aggref);
746 COPY_SCALAR_FIELD(aggfnoid);
747 COPY_SCALAR_FIELD(aggtype);
748 COPY_NODE_FIELD(target);
749 COPY_SCALAR_FIELD(agglevelsup);
750 COPY_SCALAR_FIELD(aggstar);
751 COPY_SCALAR_FIELD(aggdistinct);
760 _copyArrayRef(ArrayRef *from)
762 ArrayRef *newnode = makeNode(ArrayRef);
764 COPY_SCALAR_FIELD(refrestype);
765 COPY_SCALAR_FIELD(refarraytype);
766 COPY_SCALAR_FIELD(refelemtype);
767 COPY_NODE_FIELD(refupperindexpr);
768 COPY_NODE_FIELD(reflowerindexpr);
769 COPY_NODE_FIELD(refexpr);
770 COPY_NODE_FIELD(refassgnexpr);
779 _copyFuncExpr(FuncExpr *from)
781 FuncExpr *newnode = makeNode(FuncExpr);
783 COPY_SCALAR_FIELD(funcid);
784 COPY_SCALAR_FIELD(funcresulttype);
785 COPY_SCALAR_FIELD(funcretset);
786 COPY_SCALAR_FIELD(funcformat);
787 COPY_NODE_FIELD(args);
796 _copyOpExpr(OpExpr *from)
798 OpExpr *newnode = makeNode(OpExpr);
800 COPY_SCALAR_FIELD(opno);
801 COPY_SCALAR_FIELD(opfuncid);
802 COPY_SCALAR_FIELD(opresulttype);
803 COPY_SCALAR_FIELD(opretset);
804 COPY_NODE_FIELD(args);
810 * _copyDistinctExpr (same as OpExpr)
812 static DistinctExpr *
813 _copyDistinctExpr(DistinctExpr *from)
815 DistinctExpr *newnode = makeNode(DistinctExpr);
817 COPY_SCALAR_FIELD(opno);
818 COPY_SCALAR_FIELD(opfuncid);
819 COPY_SCALAR_FIELD(opresulttype);
820 COPY_SCALAR_FIELD(opretset);
821 COPY_NODE_FIELD(args);
827 * _copyScalarArrayOpExpr
829 static ScalarArrayOpExpr *
830 _copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
832 ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
834 COPY_SCALAR_FIELD(opno);
835 COPY_SCALAR_FIELD(opfuncid);
836 COPY_SCALAR_FIELD(useOr);
837 COPY_NODE_FIELD(args);
846 _copyBoolExpr(BoolExpr *from)
848 BoolExpr *newnode = makeNode(BoolExpr);
850 COPY_SCALAR_FIELD(boolop);
851 COPY_NODE_FIELD(args);
860 _copySubLink(SubLink *from)
862 SubLink *newnode = makeNode(SubLink);
864 COPY_SCALAR_FIELD(subLinkType);
865 COPY_SCALAR_FIELD(useOr);
866 COPY_NODE_FIELD(lefthand);
867 COPY_NODE_FIELD(operName);
868 COPY_NODE_FIELD(operOids);
869 COPY_NODE_FIELD(subselect);
878 _copySubPlan(SubPlan *from)
880 SubPlan *newnode = makeNode(SubPlan);
882 COPY_SCALAR_FIELD(subLinkType);
883 COPY_SCALAR_FIELD(useOr);
884 COPY_NODE_FIELD(exprs);
885 COPY_NODE_FIELD(paramIds);
886 COPY_NODE_FIELD(plan);
887 COPY_SCALAR_FIELD(plan_id);
888 COPY_NODE_FIELD(rtable);
889 COPY_SCALAR_FIELD(useHashTable);
890 COPY_SCALAR_FIELD(unknownEqFalse);
891 COPY_NODE_FIELD(setParam);
892 COPY_NODE_FIELD(parParam);
893 COPY_NODE_FIELD(args);
902 _copyFieldSelect(FieldSelect *from)
904 FieldSelect *newnode = makeNode(FieldSelect);
906 COPY_NODE_FIELD(arg);
907 COPY_SCALAR_FIELD(fieldnum);
908 COPY_SCALAR_FIELD(resulttype);
909 COPY_SCALAR_FIELD(resulttypmod);
918 _copyFieldStore(FieldStore *from)
920 FieldStore *newnode = makeNode(FieldStore);
922 COPY_NODE_FIELD(arg);
923 COPY_NODE_FIELD(newvals);
924 COPY_NODE_FIELD(fieldnums);
925 COPY_SCALAR_FIELD(resulttype);
934 _copyRelabelType(RelabelType *from)
936 RelabelType *newnode = makeNode(RelabelType);
938 COPY_NODE_FIELD(arg);
939 COPY_SCALAR_FIELD(resulttype);
940 COPY_SCALAR_FIELD(resulttypmod);
941 COPY_SCALAR_FIELD(relabelformat);
947 * _copyConvertRowtypeExpr
949 static ConvertRowtypeExpr *
950 _copyConvertRowtypeExpr(ConvertRowtypeExpr *from)
952 ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);
954 COPY_NODE_FIELD(arg);
955 COPY_SCALAR_FIELD(resulttype);
956 COPY_SCALAR_FIELD(convertformat);
965 _copyCaseExpr(CaseExpr *from)
967 CaseExpr *newnode = makeNode(CaseExpr);
969 COPY_SCALAR_FIELD(casetype);
970 COPY_NODE_FIELD(arg);
971 COPY_NODE_FIELD(args);
972 COPY_NODE_FIELD(defresult);
981 _copyCaseWhen(CaseWhen *from)
983 CaseWhen *newnode = makeNode(CaseWhen);
985 COPY_NODE_FIELD(expr);
986 COPY_NODE_FIELD(result);
994 static CaseTestExpr *
995 _copyCaseTestExpr(CaseTestExpr *from)
997 CaseTestExpr *newnode = makeNode(CaseTestExpr);
999 COPY_SCALAR_FIELD(typeId);
1000 COPY_SCALAR_FIELD(typeMod);
1009 _copyArrayExpr(ArrayExpr *from)
1011 ArrayExpr *newnode = makeNode(ArrayExpr);
1013 COPY_SCALAR_FIELD(array_typeid);
1014 COPY_SCALAR_FIELD(element_typeid);
1015 COPY_NODE_FIELD(elements);
1016 COPY_SCALAR_FIELD(multidims);
1025 _copyRowExpr(RowExpr *from)
1027 RowExpr *newnode = makeNode(RowExpr);
1029 COPY_NODE_FIELD(args);
1030 COPY_SCALAR_FIELD(row_typeid);
1031 COPY_SCALAR_FIELD(row_format);
1039 static CoalesceExpr *
1040 _copyCoalesceExpr(CoalesceExpr *from)
1042 CoalesceExpr *newnode = makeNode(CoalesceExpr);
1044 COPY_SCALAR_FIELD(coalescetype);
1045 COPY_NODE_FIELD(args);
1051 * _copyNullIfExpr (same as OpExpr)
1054 _copyNullIfExpr(NullIfExpr *from)
1056 NullIfExpr *newnode = makeNode(NullIfExpr);
1058 COPY_SCALAR_FIELD(opno);
1059 COPY_SCALAR_FIELD(opfuncid);
1060 COPY_SCALAR_FIELD(opresulttype);
1061 COPY_SCALAR_FIELD(opretset);
1062 COPY_NODE_FIELD(args);
1071 _copyNullTest(NullTest *from)
1073 NullTest *newnode = makeNode(NullTest);
1075 COPY_NODE_FIELD(arg);
1076 COPY_SCALAR_FIELD(nulltesttype);
1084 static BooleanTest *
1085 _copyBooleanTest(BooleanTest *from)
1087 BooleanTest *newnode = makeNode(BooleanTest);
1089 COPY_NODE_FIELD(arg);
1090 COPY_SCALAR_FIELD(booltesttype);
1096 * _copyCoerceToDomain
1098 static CoerceToDomain *
1099 _copyCoerceToDomain(CoerceToDomain *from)
1101 CoerceToDomain *newnode = makeNode(CoerceToDomain);
1103 COPY_NODE_FIELD(arg);
1104 COPY_SCALAR_FIELD(resulttype);
1105 COPY_SCALAR_FIELD(resulttypmod);
1106 COPY_SCALAR_FIELD(coercionformat);
1112 * _copyCoerceToDomainValue
1114 static CoerceToDomainValue *
1115 _copyCoerceToDomainValue(CoerceToDomainValue *from)
1117 CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1119 COPY_SCALAR_FIELD(typeId);
1120 COPY_SCALAR_FIELD(typeMod);
1128 static SetToDefault *
1129 _copySetToDefault(SetToDefault *from)
1131 SetToDefault *newnode = makeNode(SetToDefault);
1133 COPY_SCALAR_FIELD(typeId);
1134 COPY_SCALAR_FIELD(typeMod);
1142 static TargetEntry *
1143 _copyTargetEntry(TargetEntry *from)
1145 TargetEntry *newnode = makeNode(TargetEntry);
1147 COPY_NODE_FIELD(expr);
1148 COPY_SCALAR_FIELD(resno);
1149 COPY_STRING_FIELD(resname);
1150 COPY_SCALAR_FIELD(ressortgroupref);
1151 COPY_SCALAR_FIELD(resorigtbl);
1152 COPY_SCALAR_FIELD(resorigcol);
1153 COPY_SCALAR_FIELD(resjunk);
1161 static RangeTblRef *
1162 _copyRangeTblRef(RangeTblRef *from)
1164 RangeTblRef *newnode = makeNode(RangeTblRef);
1166 COPY_SCALAR_FIELD(rtindex);
1175 _copyJoinExpr(JoinExpr *from)
1177 JoinExpr *newnode = makeNode(JoinExpr);
1179 COPY_SCALAR_FIELD(jointype);
1180 COPY_SCALAR_FIELD(isNatural);
1181 COPY_NODE_FIELD(larg);
1182 COPY_NODE_FIELD(rarg);
1183 COPY_NODE_FIELD(using);
1184 COPY_NODE_FIELD(quals);
1185 COPY_NODE_FIELD(alias);
1186 COPY_SCALAR_FIELD(rtindex);
1195 _copyFromExpr(FromExpr *from)
1197 FromExpr *newnode = makeNode(FromExpr);
1199 COPY_NODE_FIELD(fromlist);
1200 COPY_NODE_FIELD(quals);
1205 /* ****************************************************************
1206 * relation.h copy functions
1208 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1209 * There are some subsidiary structs that are useful to copy, though.
1210 * ****************************************************************
1216 static PathKeyItem *
1217 _copyPathKeyItem(PathKeyItem *from)
1219 PathKeyItem *newnode = makeNode(PathKeyItem);
1221 COPY_NODE_FIELD(key);
1222 COPY_SCALAR_FIELD(sortop);
1230 static RestrictInfo *
1231 _copyRestrictInfo(RestrictInfo *from)
1233 RestrictInfo *newnode = makeNode(RestrictInfo);
1235 COPY_NODE_FIELD(clause);
1236 COPY_SCALAR_FIELD(is_pushed_down);
1237 COPY_SCALAR_FIELD(valid_everywhere);
1238 COPY_SCALAR_FIELD(can_join);
1239 COPY_BITMAPSET_FIELD(clause_relids);
1240 COPY_BITMAPSET_FIELD(left_relids);
1241 COPY_BITMAPSET_FIELD(right_relids);
1242 COPY_NODE_FIELD(orclause);
1243 COPY_SCALAR_FIELD(eval_cost);
1244 COPY_SCALAR_FIELD(this_selec);
1245 COPY_SCALAR_FIELD(mergejoinoperator);
1246 COPY_SCALAR_FIELD(left_sortop);
1247 COPY_SCALAR_FIELD(right_sortop);
1250 * Do not copy pathkeys, since they'd not be canonical in a copied
1253 newnode->left_pathkey = NIL;
1254 newnode->right_pathkey = NIL;
1256 COPY_SCALAR_FIELD(left_mergescansel);
1257 COPY_SCALAR_FIELD(right_mergescansel);
1258 COPY_SCALAR_FIELD(hashjoinoperator);
1259 COPY_SCALAR_FIELD(left_bucketsize);
1260 COPY_SCALAR_FIELD(right_bucketsize);
1269 _copyJoinInfo(JoinInfo *from)
1271 JoinInfo *newnode = makeNode(JoinInfo);
1273 COPY_BITMAPSET_FIELD(unjoined_relids);
1274 COPY_NODE_FIELD(jinfo_restrictinfo);
1282 static InClauseInfo *
1283 _copyInClauseInfo(InClauseInfo *from)
1285 InClauseInfo *newnode = makeNode(InClauseInfo);
1287 COPY_BITMAPSET_FIELD(lefthand);
1288 COPY_BITMAPSET_FIELD(righthand);
1289 COPY_NODE_FIELD(sub_targetlist);
1294 /* ****************************************************************
1295 * parsenodes.h copy functions
1296 * ****************************************************************
1299 static RangeTblEntry *
1300 _copyRangeTblEntry(RangeTblEntry *from)
1302 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1304 COPY_SCALAR_FIELD(rtekind);
1305 COPY_SCALAR_FIELD(relid);
1306 COPY_NODE_FIELD(subquery);
1307 COPY_NODE_FIELD(funcexpr);
1308 COPY_NODE_FIELD(coldeflist);
1309 COPY_SCALAR_FIELD(jointype);
1310 COPY_NODE_FIELD(joinaliasvars);
1311 COPY_NODE_FIELD(alias);
1312 COPY_NODE_FIELD(eref);
1313 COPY_SCALAR_FIELD(inh);
1314 COPY_SCALAR_FIELD(inFromCl);
1315 COPY_SCALAR_FIELD(requiredPerms);
1316 COPY_SCALAR_FIELD(checkAsUser);
1321 static FkConstraint *
1322 _copyFkConstraint(FkConstraint *from)
1324 FkConstraint *newnode = makeNode(FkConstraint);
1326 COPY_STRING_FIELD(constr_name);
1327 COPY_NODE_FIELD(pktable);
1328 COPY_NODE_FIELD(fk_attrs);
1329 COPY_NODE_FIELD(pk_attrs);
1330 COPY_SCALAR_FIELD(fk_matchtype);
1331 COPY_SCALAR_FIELD(fk_upd_action);
1332 COPY_SCALAR_FIELD(fk_del_action);
1333 COPY_SCALAR_FIELD(deferrable);
1334 COPY_SCALAR_FIELD(initdeferred);
1335 COPY_SCALAR_FIELD(skip_validation);
1341 _copySortClause(SortClause *from)
1343 SortClause *newnode = makeNode(SortClause);
1345 COPY_SCALAR_FIELD(tleSortGroupRef);
1346 COPY_SCALAR_FIELD(sortop);
1351 static GroupClause *
1352 _copyGroupClause(GroupClause *from)
1354 GroupClause *newnode = makeNode(GroupClause);
1356 COPY_SCALAR_FIELD(tleSortGroupRef);
1357 COPY_SCALAR_FIELD(sortop);
1363 _copyAExpr(A_Expr *from)
1365 A_Expr *newnode = makeNode(A_Expr);
1367 COPY_SCALAR_FIELD(kind);
1368 COPY_NODE_FIELD(name);
1369 COPY_NODE_FIELD(lexpr);
1370 COPY_NODE_FIELD(rexpr);
1376 _copyColumnRef(ColumnRef *from)
1378 ColumnRef *newnode = makeNode(ColumnRef);
1380 COPY_NODE_FIELD(fields);
1386 _copyParamRef(ParamRef *from)
1388 ParamRef *newnode = makeNode(ParamRef);
1390 COPY_SCALAR_FIELD(number);
1396 _copyAConst(A_Const *from)
1398 A_Const *newnode = makeNode(A_Const);
1400 /* This part must duplicate _copyValue */
1401 COPY_SCALAR_FIELD(val.type);
1402 switch (from->val.type)
1405 COPY_SCALAR_FIELD(val.val.ival);
1410 COPY_STRING_FIELD(val.val.str);
1416 elog(ERROR, "unrecognized node type: %d",
1417 (int) from->val.type);
1421 COPY_NODE_FIELD(typename);
1427 _copyFuncCall(FuncCall *from)
1429 FuncCall *newnode = makeNode(FuncCall);
1431 COPY_NODE_FIELD(funcname);
1432 COPY_NODE_FIELD(args);
1433 COPY_SCALAR_FIELD(agg_star);
1434 COPY_SCALAR_FIELD(agg_distinct);
1440 _copyAIndices(A_Indices *from)
1442 A_Indices *newnode = makeNode(A_Indices);
1444 COPY_NODE_FIELD(lidx);
1445 COPY_NODE_FIELD(uidx);
1450 static A_Indirection *
1451 _copyA_Indirection(A_Indirection *from)
1453 A_Indirection *newnode = makeNode(A_Indirection);
1455 COPY_NODE_FIELD(arg);
1456 COPY_NODE_FIELD(indirection);
1462 _copyResTarget(ResTarget *from)
1464 ResTarget *newnode = makeNode(ResTarget);
1466 COPY_STRING_FIELD(name);
1467 COPY_NODE_FIELD(indirection);
1468 COPY_NODE_FIELD(val);
1474 _copyTypeName(TypeName *from)
1476 TypeName *newnode = makeNode(TypeName);
1478 COPY_NODE_FIELD(names);
1479 COPY_SCALAR_FIELD(typeid);
1480 COPY_SCALAR_FIELD(timezone);
1481 COPY_SCALAR_FIELD(setof);
1482 COPY_SCALAR_FIELD(pct_type);
1483 COPY_SCALAR_FIELD(typmod);
1484 COPY_NODE_FIELD(arrayBounds);
1490 _copySortBy(SortBy *from)
1492 SortBy *newnode = makeNode(SortBy);
1494 COPY_SCALAR_FIELD(sortby_kind);
1495 COPY_NODE_FIELD(useOp);
1496 COPY_NODE_FIELD(node);
1501 static RangeSubselect *
1502 _copyRangeSubselect(RangeSubselect *from)
1504 RangeSubselect *newnode = makeNode(RangeSubselect);
1506 COPY_NODE_FIELD(subquery);
1507 COPY_NODE_FIELD(alias);
1512 static RangeFunction *
1513 _copyRangeFunction(RangeFunction *from)
1515 RangeFunction *newnode = makeNode(RangeFunction);
1517 COPY_NODE_FIELD(funccallnode);
1518 COPY_NODE_FIELD(alias);
1519 COPY_NODE_FIELD(coldeflist);
1525 _copyTypeCast(TypeCast *from)
1527 TypeCast *newnode = makeNode(TypeCast);
1529 COPY_NODE_FIELD(arg);
1530 COPY_NODE_FIELD(typename);
1536 _copyIndexElem(IndexElem *from)
1538 IndexElem *newnode = makeNode(IndexElem);
1540 COPY_STRING_FIELD(name);
1541 COPY_NODE_FIELD(expr);
1542 COPY_NODE_FIELD(opclass);
1548 _copyColumnDef(ColumnDef *from)
1550 ColumnDef *newnode = makeNode(ColumnDef);
1552 COPY_STRING_FIELD(colname);
1553 COPY_NODE_FIELD(typename);
1554 COPY_SCALAR_FIELD(inhcount);
1555 COPY_SCALAR_FIELD(is_local);
1556 COPY_SCALAR_FIELD(is_not_null);
1557 COPY_NODE_FIELD(raw_default);
1558 COPY_STRING_FIELD(cooked_default);
1559 COPY_NODE_FIELD(constraints);
1560 COPY_NODE_FIELD(support);
1566 _copyConstraint(Constraint *from)
1568 Constraint *newnode = makeNode(Constraint);
1570 COPY_SCALAR_FIELD(contype);
1571 COPY_STRING_FIELD(name);
1572 COPY_NODE_FIELD(raw_expr);
1573 COPY_STRING_FIELD(cooked_expr);
1574 COPY_NODE_FIELD(keys);
1575 COPY_STRING_FIELD(indexspace);
1581 _copyDefElem(DefElem *from)
1583 DefElem *newnode = makeNode(DefElem);
1585 COPY_STRING_FIELD(defname);
1586 COPY_NODE_FIELD(arg);
1592 _copyQuery(Query *from)
1594 Query *newnode = makeNode(Query);
1596 COPY_SCALAR_FIELD(commandType);
1597 COPY_SCALAR_FIELD(querySource);
1598 COPY_SCALAR_FIELD(canSetTag);
1599 COPY_NODE_FIELD(utilityStmt);
1600 COPY_SCALAR_FIELD(resultRelation);
1601 COPY_NODE_FIELD(into);
1602 COPY_SCALAR_FIELD(intoHasOids);
1603 COPY_SCALAR_FIELD(hasAggs);
1604 COPY_SCALAR_FIELD(hasSubLinks);
1605 COPY_NODE_FIELD(rtable);
1606 COPY_NODE_FIELD(jointree);
1607 COPY_NODE_FIELD(rowMarks);
1608 COPY_SCALAR_FIELD(forUpdate);
1609 COPY_NODE_FIELD(targetList);
1610 COPY_NODE_FIELD(groupClause);
1611 COPY_NODE_FIELD(havingQual);
1612 COPY_NODE_FIELD(distinctClause);
1613 COPY_NODE_FIELD(sortClause);
1614 COPY_NODE_FIELD(limitOffset);
1615 COPY_NODE_FIELD(limitCount);
1616 COPY_NODE_FIELD(setOperations);
1617 COPY_NODE_FIELD(resultRelations);
1623 _copyInsertStmt(InsertStmt *from)
1625 InsertStmt *newnode = makeNode(InsertStmt);
1627 COPY_NODE_FIELD(relation);
1628 COPY_NODE_FIELD(cols);
1629 COPY_NODE_FIELD(targetList);
1630 COPY_NODE_FIELD(selectStmt);
1636 _copyDeleteStmt(DeleteStmt *from)
1638 DeleteStmt *newnode = makeNode(DeleteStmt);
1640 COPY_NODE_FIELD(relation);
1641 COPY_NODE_FIELD(whereClause);
1642 COPY_NODE_FIELD(usingClause);
1648 _copyUpdateStmt(UpdateStmt *from)
1650 UpdateStmt *newnode = makeNode(UpdateStmt);
1652 COPY_NODE_FIELD(relation);
1653 COPY_NODE_FIELD(targetList);
1654 COPY_NODE_FIELD(whereClause);
1655 COPY_NODE_FIELD(fromClause);
1661 _copySelectStmt(SelectStmt *from)
1663 SelectStmt *newnode = makeNode(SelectStmt);
1665 COPY_NODE_FIELD(distinctClause);
1666 COPY_NODE_FIELD(into);
1667 COPY_NODE_FIELD(intoColNames);
1668 COPY_SCALAR_FIELD(intoHasOids);
1669 COPY_NODE_FIELD(targetList);
1670 COPY_NODE_FIELD(fromClause);
1671 COPY_NODE_FIELD(whereClause);
1672 COPY_NODE_FIELD(groupClause);
1673 COPY_NODE_FIELD(havingClause);
1674 COPY_NODE_FIELD(sortClause);
1675 COPY_NODE_FIELD(limitOffset);
1676 COPY_NODE_FIELD(limitCount);
1677 COPY_NODE_FIELD(lockedRels);
1678 COPY_SCALAR_FIELD(forUpdate);
1679 COPY_SCALAR_FIELD(op);
1680 COPY_SCALAR_FIELD(all);
1681 COPY_NODE_FIELD(larg);
1682 COPY_NODE_FIELD(rarg);
1687 static SetOperationStmt *
1688 _copySetOperationStmt(SetOperationStmt *from)
1690 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1692 COPY_SCALAR_FIELD(op);
1693 COPY_SCALAR_FIELD(all);
1694 COPY_NODE_FIELD(larg);
1695 COPY_NODE_FIELD(rarg);
1696 COPY_NODE_FIELD(colTypes);
1701 static AlterTableStmt *
1702 _copyAlterTableStmt(AlterTableStmt *from)
1704 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1706 COPY_NODE_FIELD(relation);
1707 COPY_NODE_FIELD(cmds);
1708 COPY_SCALAR_FIELD(relkind);
1713 static AlterTableCmd *
1714 _copyAlterTableCmd(AlterTableCmd *from)
1716 AlterTableCmd *newnode = makeNode(AlterTableCmd);
1718 COPY_SCALAR_FIELD(subtype);
1719 COPY_STRING_FIELD(name);
1720 COPY_NODE_FIELD(def);
1721 COPY_NODE_FIELD(transform);
1722 COPY_SCALAR_FIELD(behavior);
1727 static AlterDomainStmt *
1728 _copyAlterDomainStmt(AlterDomainStmt *from)
1730 AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1732 COPY_SCALAR_FIELD(subtype);
1733 COPY_NODE_FIELD(typename);
1734 COPY_STRING_FIELD(name);
1735 COPY_NODE_FIELD(def);
1736 COPY_SCALAR_FIELD(behavior);
1742 _copyGrantStmt(GrantStmt *from)
1744 GrantStmt *newnode = makeNode(GrantStmt);
1746 COPY_SCALAR_FIELD(is_grant);
1747 COPY_SCALAR_FIELD(objtype);
1748 COPY_NODE_FIELD(objects);
1749 COPY_NODE_FIELD(privileges);
1750 COPY_NODE_FIELD(grantees);
1751 COPY_SCALAR_FIELD(grant_option);
1752 COPY_SCALAR_FIELD(behavior);
1757 static PrivGrantee *
1758 _copyPrivGrantee(PrivGrantee *from)
1760 PrivGrantee *newnode = makeNode(PrivGrantee);
1762 COPY_STRING_FIELD(username);
1763 COPY_STRING_FIELD(groupname);
1768 static FuncWithArgs *
1769 _copyFuncWithArgs(FuncWithArgs *from)
1771 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1773 COPY_NODE_FIELD(funcname);
1774 COPY_NODE_FIELD(funcargs);
1779 static DeclareCursorStmt *
1780 _copyDeclareCursorStmt(DeclareCursorStmt *from)
1782 DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
1784 COPY_STRING_FIELD(portalname);
1785 COPY_SCALAR_FIELD(options);
1786 COPY_NODE_FIELD(query);
1791 static ClosePortalStmt *
1792 _copyClosePortalStmt(ClosePortalStmt *from)
1794 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1796 COPY_STRING_FIELD(portalname);
1801 static ClusterStmt *
1802 _copyClusterStmt(ClusterStmt *from)
1804 ClusterStmt *newnode = makeNode(ClusterStmt);
1806 COPY_NODE_FIELD(relation);
1807 COPY_STRING_FIELD(indexname);
1813 _copyCopyStmt(CopyStmt *from)
1815 CopyStmt *newnode = makeNode(CopyStmt);
1817 COPY_NODE_FIELD(relation);
1818 COPY_NODE_FIELD(attlist);
1819 COPY_SCALAR_FIELD(is_from);
1820 COPY_STRING_FIELD(filename);
1821 COPY_NODE_FIELD(options);
1827 _copyCreateStmt(CreateStmt *from)
1829 CreateStmt *newnode = makeNode(CreateStmt);
1831 COPY_NODE_FIELD(relation);
1832 COPY_NODE_FIELD(tableElts);
1833 COPY_NODE_FIELD(inhRelations);
1834 COPY_NODE_FIELD(constraints);
1835 COPY_SCALAR_FIELD(hasoids);
1836 COPY_SCALAR_FIELD(oncommit);
1837 COPY_STRING_FIELD(tablespacename);
1842 static InhRelation *
1843 _copyInhRelation(InhRelation *from)
1845 InhRelation *newnode = makeNode(InhRelation);
1847 COPY_NODE_FIELD(relation);
1848 COPY_SCALAR_FIELD(including_defaults);
1854 _copyDefineStmt(DefineStmt *from)
1856 DefineStmt *newnode = makeNode(DefineStmt);
1858 COPY_SCALAR_FIELD(kind);
1859 COPY_NODE_FIELD(defnames);
1860 COPY_NODE_FIELD(definition);
1866 _copyDropStmt(DropStmt *from)
1868 DropStmt *newnode = makeNode(DropStmt);
1870 COPY_NODE_FIELD(objects);
1871 COPY_SCALAR_FIELD(removeType);
1872 COPY_SCALAR_FIELD(behavior);
1877 static TruncateStmt *
1878 _copyTruncateStmt(TruncateStmt *from)
1880 TruncateStmt *newnode = makeNode(TruncateStmt);
1882 COPY_NODE_FIELD(relations);
1887 static CommentStmt *
1888 _copyCommentStmt(CommentStmt *from)
1890 CommentStmt *newnode = makeNode(CommentStmt);
1892 COPY_SCALAR_FIELD(objtype);
1893 COPY_NODE_FIELD(objname);
1894 COPY_NODE_FIELD(objargs);
1895 COPY_STRING_FIELD(comment);
1901 _copyFetchStmt(FetchStmt *from)
1903 FetchStmt *newnode = makeNode(FetchStmt);
1905 COPY_SCALAR_FIELD(direction);
1906 COPY_SCALAR_FIELD(howMany);
1907 COPY_STRING_FIELD(portalname);
1908 COPY_SCALAR_FIELD(ismove);
1914 _copyIndexStmt(IndexStmt *from)
1916 IndexStmt *newnode = makeNode(IndexStmt);
1918 COPY_STRING_FIELD(idxname);
1919 COPY_NODE_FIELD(relation);
1920 COPY_STRING_FIELD(accessMethod);
1921 COPY_STRING_FIELD(tableSpace);
1922 COPY_NODE_FIELD(indexParams);
1923 COPY_NODE_FIELD(whereClause);
1924 COPY_NODE_FIELD(rangetable);
1925 COPY_SCALAR_FIELD(unique);
1926 COPY_SCALAR_FIELD(primary);
1927 COPY_SCALAR_FIELD(isconstraint);
1932 static CreateFunctionStmt *
1933 _copyCreateFunctionStmt(CreateFunctionStmt *from)
1935 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
1937 COPY_SCALAR_FIELD(replace);
1938 COPY_NODE_FIELD(funcname);
1939 COPY_NODE_FIELD(parameters);
1940 COPY_NODE_FIELD(returnType);
1941 COPY_NODE_FIELD(options);
1942 COPY_NODE_FIELD(withClause);
1947 static FunctionParameter *
1948 _copyFunctionParameter(FunctionParameter *from)
1950 FunctionParameter *newnode = makeNode(FunctionParameter);
1952 COPY_STRING_FIELD(name);
1953 COPY_NODE_FIELD(argType);
1954 COPY_SCALAR_FIELD(mode);
1959 static AlterFunctionStmt *
1960 _copyAlterFunctionStmt(AlterFunctionStmt *from)
1962 AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);
1964 COPY_NODE_FIELD(func);
1965 COPY_NODE_FIELD(actions);
1970 static RemoveAggrStmt *
1971 _copyRemoveAggrStmt(RemoveAggrStmt *from)
1973 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1975 COPY_NODE_FIELD(aggname);
1976 COPY_NODE_FIELD(aggtype);
1977 COPY_SCALAR_FIELD(behavior);
1982 static RemoveFuncStmt *
1983 _copyRemoveFuncStmt(RemoveFuncStmt *from)
1985 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
1987 COPY_NODE_FIELD(funcname);
1988 COPY_NODE_FIELD(args);
1989 COPY_SCALAR_FIELD(behavior);
1994 static RemoveOperStmt *
1995 _copyRemoveOperStmt(RemoveOperStmt *from)
1997 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
1999 COPY_NODE_FIELD(opname);
2000 COPY_NODE_FIELD(args);
2001 COPY_SCALAR_FIELD(behavior);
2006 static RemoveOpClassStmt *
2007 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
2009 RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
2011 COPY_NODE_FIELD(opclassname);
2012 COPY_STRING_FIELD(amname);
2013 COPY_SCALAR_FIELD(behavior);
2019 _copyRenameStmt(RenameStmt *from)
2021 RenameStmt *newnode = makeNode(RenameStmt);
2023 COPY_NODE_FIELD(relation);
2024 COPY_NODE_FIELD(object);
2025 COPY_NODE_FIELD(objarg);
2026 COPY_STRING_FIELD(subname);
2027 COPY_STRING_FIELD(newname);
2028 COPY_SCALAR_FIELD(renameType);
2033 static AlterOwnerStmt *
2034 _copyAlterOwnerStmt(AlterOwnerStmt *from)
2036 AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);
2038 COPY_NODE_FIELD(relation);
2039 COPY_NODE_FIELD(object);
2040 COPY_NODE_FIELD(objarg);
2041 COPY_STRING_FIELD(addname);
2042 COPY_STRING_FIELD(newowner);
2043 COPY_SCALAR_FIELD(objectType);
2049 _copyRuleStmt(RuleStmt *from)
2051 RuleStmt *newnode = makeNode(RuleStmt);
2053 COPY_NODE_FIELD(relation);
2054 COPY_STRING_FIELD(rulename);
2055 COPY_NODE_FIELD(whereClause);
2056 COPY_SCALAR_FIELD(event);
2057 COPY_SCALAR_FIELD(instead);
2058 COPY_NODE_FIELD(actions);
2059 COPY_SCALAR_FIELD(replace);
2065 _copyNotifyStmt(NotifyStmt *from)
2067 NotifyStmt *newnode = makeNode(NotifyStmt);
2069 COPY_NODE_FIELD(relation);
2075 _copyListenStmt(ListenStmt *from)
2077 ListenStmt *newnode = makeNode(ListenStmt);
2079 COPY_NODE_FIELD(relation);
2084 static UnlistenStmt *
2085 _copyUnlistenStmt(UnlistenStmt *from)
2087 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2089 COPY_NODE_FIELD(relation);
2094 static TransactionStmt *
2095 _copyTransactionStmt(TransactionStmt *from)
2097 TransactionStmt *newnode = makeNode(TransactionStmt);
2099 COPY_SCALAR_FIELD(kind);
2100 COPY_NODE_FIELD(options);
2105 static CompositeTypeStmt *
2106 _copyCompositeTypeStmt(CompositeTypeStmt *from)
2108 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
2110 COPY_NODE_FIELD(typevar);
2111 COPY_NODE_FIELD(coldeflist);
2117 _copyViewStmt(ViewStmt *from)
2119 ViewStmt *newnode = makeNode(ViewStmt);
2121 COPY_NODE_FIELD(view);
2122 COPY_NODE_FIELD(aliases);
2123 COPY_NODE_FIELD(query);
2124 COPY_SCALAR_FIELD(replace);
2130 _copyLoadStmt(LoadStmt *from)
2132 LoadStmt *newnode = makeNode(LoadStmt);
2134 COPY_STRING_FIELD(filename);
2139 static CreateDomainStmt *
2140 _copyCreateDomainStmt(CreateDomainStmt *from)
2142 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2144 COPY_NODE_FIELD(domainname);
2145 COPY_NODE_FIELD(typename);
2146 COPY_NODE_FIELD(constraints);
2151 static CreateOpClassStmt *
2152 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2154 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2156 COPY_NODE_FIELD(opclassname);
2157 COPY_STRING_FIELD(amname);
2158 COPY_NODE_FIELD(datatype);
2159 COPY_NODE_FIELD(items);
2160 COPY_SCALAR_FIELD(isDefault);
2165 static CreateOpClassItem *
2166 _copyCreateOpClassItem(CreateOpClassItem *from)
2168 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2170 COPY_SCALAR_FIELD(itemtype);
2171 COPY_NODE_FIELD(name);
2172 COPY_NODE_FIELD(args);
2173 COPY_SCALAR_FIELD(number);
2174 COPY_SCALAR_FIELD(recheck);
2175 COPY_NODE_FIELD(storedtype);
2180 static CreatedbStmt *
2181 _copyCreatedbStmt(CreatedbStmt *from)
2183 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2185 COPY_STRING_FIELD(dbname);
2186 COPY_NODE_FIELD(options);
2191 static AlterDatabaseSetStmt *
2192 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2194 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2196 COPY_STRING_FIELD(dbname);
2197 COPY_STRING_FIELD(variable);
2198 COPY_NODE_FIELD(value);
2204 _copyDropdbStmt(DropdbStmt *from)
2206 DropdbStmt *newnode = makeNode(DropdbStmt);
2208 COPY_STRING_FIELD(dbname);
2214 _copyVacuumStmt(VacuumStmt *from)
2216 VacuumStmt *newnode = makeNode(VacuumStmt);
2218 COPY_SCALAR_FIELD(vacuum);
2219 COPY_SCALAR_FIELD(full);
2220 COPY_SCALAR_FIELD(analyze);
2221 COPY_SCALAR_FIELD(freeze);
2222 COPY_SCALAR_FIELD(verbose);
2223 COPY_NODE_FIELD(relation);
2224 COPY_NODE_FIELD(va_cols);
2229 static ExplainStmt *
2230 _copyExplainStmt(ExplainStmt *from)
2232 ExplainStmt *newnode = makeNode(ExplainStmt);
2234 COPY_NODE_FIELD(query);
2235 COPY_SCALAR_FIELD(verbose);
2236 COPY_SCALAR_FIELD(analyze);
2241 static CreateSeqStmt *
2242 _copyCreateSeqStmt(CreateSeqStmt *from)
2244 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2246 COPY_NODE_FIELD(sequence);
2247 COPY_NODE_FIELD(options);
2252 static AlterSeqStmt *
2253 _copyAlterSeqStmt(AlterSeqStmt *from)
2255 AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
2257 COPY_NODE_FIELD(sequence);
2258 COPY_NODE_FIELD(options);
2263 static VariableSetStmt *
2264 _copyVariableSetStmt(VariableSetStmt *from)
2266 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2268 COPY_STRING_FIELD(name);
2269 COPY_NODE_FIELD(args);
2270 COPY_SCALAR_FIELD(is_local);
2275 static VariableShowStmt *
2276 _copyVariableShowStmt(VariableShowStmt *from)
2278 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2280 COPY_STRING_FIELD(name);
2285 static VariableResetStmt *
2286 _copyVariableResetStmt(VariableResetStmt *from)
2288 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2290 COPY_STRING_FIELD(name);
2295 static CreateTableSpaceStmt *
2296 _copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
2298 CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
2300 COPY_STRING_FIELD(tablespacename);
2301 COPY_STRING_FIELD(owner);
2302 COPY_STRING_FIELD(location);
2307 static DropTableSpaceStmt *
2308 _copyDropTableSpaceStmt(DropTableSpaceStmt *from)
2310 DropTableSpaceStmt *newnode = makeNode(DropTableSpaceStmt);
2312 COPY_STRING_FIELD(tablespacename);
2317 static CreateTrigStmt *
2318 _copyCreateTrigStmt(CreateTrigStmt *from)
2320 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2322 COPY_STRING_FIELD(trigname);
2323 COPY_NODE_FIELD(relation);
2324 COPY_NODE_FIELD(funcname);
2325 COPY_NODE_FIELD(args);
2326 COPY_SCALAR_FIELD(before);
2327 COPY_SCALAR_FIELD(row);
2328 strcpy(newnode->actions, from->actions); /* in-line string field */
2329 COPY_SCALAR_FIELD(isconstraint);
2330 COPY_SCALAR_FIELD(deferrable);
2331 COPY_SCALAR_FIELD(initdeferred);
2332 COPY_NODE_FIELD(constrrel);
2337 static DropPropertyStmt *
2338 _copyDropPropertyStmt(DropPropertyStmt *from)
2340 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2342 COPY_NODE_FIELD(relation);
2343 COPY_STRING_FIELD(property);
2344 COPY_SCALAR_FIELD(removeType);
2345 COPY_SCALAR_FIELD(behavior);
2350 static CreatePLangStmt *
2351 _copyCreatePLangStmt(CreatePLangStmt *from)
2353 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2355 COPY_STRING_FIELD(plname);
2356 COPY_NODE_FIELD(plhandler);
2357 COPY_NODE_FIELD(plvalidator);
2358 COPY_SCALAR_FIELD(pltrusted);
2363 static DropPLangStmt *
2364 _copyDropPLangStmt(DropPLangStmt *from)
2366 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2368 COPY_STRING_FIELD(plname);
2369 COPY_SCALAR_FIELD(behavior);
2374 static CreateUserStmt *
2375 _copyCreateUserStmt(CreateUserStmt *from)
2377 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2379 COPY_STRING_FIELD(user);
2380 COPY_NODE_FIELD(options);
2385 static AlterUserStmt *
2386 _copyAlterUserStmt(AlterUserStmt *from)
2388 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2390 COPY_STRING_FIELD(user);
2391 COPY_NODE_FIELD(options);
2396 static AlterUserSetStmt *
2397 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2399 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2401 COPY_STRING_FIELD(user);
2402 COPY_STRING_FIELD(variable);
2403 COPY_NODE_FIELD(value);
2408 static DropUserStmt *
2409 _copyDropUserStmt(DropUserStmt *from)
2411 DropUserStmt *newnode = makeNode(DropUserStmt);
2413 COPY_NODE_FIELD(users);
2419 _copyLockStmt(LockStmt *from)
2421 LockStmt *newnode = makeNode(LockStmt);
2423 COPY_NODE_FIELD(relations);
2424 COPY_SCALAR_FIELD(mode);
2425 COPY_SCALAR_FIELD(nowait);
2430 static ConstraintsSetStmt *
2431 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2433 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2435 COPY_NODE_FIELD(constraints);
2436 COPY_SCALAR_FIELD(deferred);
2441 static CreateGroupStmt *
2442 _copyCreateGroupStmt(CreateGroupStmt *from)
2444 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2446 COPY_STRING_FIELD(name);
2447 COPY_NODE_FIELD(options);
2452 static AlterGroupStmt *
2453 _copyAlterGroupStmt(AlterGroupStmt *from)
2455 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2457 COPY_STRING_FIELD(name);
2458 COPY_SCALAR_FIELD(action);
2459 COPY_NODE_FIELD(listUsers);
2464 static DropGroupStmt *
2465 _copyDropGroupStmt(DropGroupStmt *from)
2467 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2469 COPY_STRING_FIELD(name);
2474 static ReindexStmt *
2475 _copyReindexStmt(ReindexStmt *from)
2477 ReindexStmt *newnode = makeNode(ReindexStmt);
2479 COPY_SCALAR_FIELD(kind);
2480 COPY_NODE_FIELD(relation);
2481 COPY_STRING_FIELD(name);
2482 COPY_SCALAR_FIELD(force);
2483 COPY_SCALAR_FIELD(all);
2488 static CreateSchemaStmt *
2489 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2491 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2493 COPY_STRING_FIELD(schemaname);
2494 COPY_STRING_FIELD(authid);
2495 COPY_NODE_FIELD(schemaElts);
2500 static CreateConversionStmt *
2501 _copyCreateConversionStmt(CreateConversionStmt *from)
2503 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2505 COPY_NODE_FIELD(conversion_name);
2506 COPY_STRING_FIELD(for_encoding_name);
2507 COPY_STRING_FIELD(to_encoding_name);
2508 COPY_NODE_FIELD(func_name);
2509 COPY_SCALAR_FIELD(def);
2514 static CreateCastStmt *
2515 _copyCreateCastStmt(CreateCastStmt *from)
2517 CreateCastStmt *newnode = makeNode(CreateCastStmt);
2519 COPY_NODE_FIELD(sourcetype);
2520 COPY_NODE_FIELD(targettype);
2521 COPY_NODE_FIELD(func);
2522 COPY_SCALAR_FIELD(context);
2527 static DropCastStmt *
2528 _copyDropCastStmt(DropCastStmt *from)
2530 DropCastStmt *newnode = makeNode(DropCastStmt);
2532 COPY_NODE_FIELD(sourcetype);
2533 COPY_NODE_FIELD(targettype);
2534 COPY_SCALAR_FIELD(behavior);
2539 static PrepareStmt *
2540 _copyPrepareStmt(PrepareStmt *from)
2542 PrepareStmt *newnode = makeNode(PrepareStmt);
2544 COPY_STRING_FIELD(name);
2545 COPY_NODE_FIELD(argtypes);
2546 COPY_NODE_FIELD(argtype_oids);
2547 COPY_NODE_FIELD(query);
2552 static ExecuteStmt *
2553 _copyExecuteStmt(ExecuteStmt *from)
2555 ExecuteStmt *newnode = makeNode(ExecuteStmt);
2557 COPY_STRING_FIELD(name);
2558 COPY_NODE_FIELD(into);
2559 COPY_NODE_FIELD(params);
2564 static DeallocateStmt *
2565 _copyDeallocateStmt(DeallocateStmt *from)
2567 DeallocateStmt *newnode = makeNode(DeallocateStmt);
2569 COPY_STRING_FIELD(name);
2575 /* ****************************************************************
2576 * pg_list.h copy functions
2577 * ****************************************************************
2581 * Perform a deep copy of the specified list, using copyObject(). The
2582 * list MUST be of type T_List; T_IntList and T_OidList nodes don't
2583 * need deep copies, so they should be copied via list_copy()
2585 #define COPY_NODE_CELL(new, old) \
2586 (new) = (ListCell *) palloc(sizeof(ListCell)); \
2587 lfirst(new) = copyObject(lfirst(old));
2590 _copyList(List *from)
2596 Assert(list_length(from) >= 1);
2598 new = makeNode(List);
2599 new->length = from->length;
2601 COPY_NODE_CELL(new->head, from->head);
2602 prev_new = new->head;
2603 curr_old = lnext(from->head);
2607 COPY_NODE_CELL(prev_new->next, curr_old);
2608 prev_new = prev_new->next;
2609 curr_old = curr_old->next;
2611 prev_new->next = NULL;
2612 new->tail = prev_new;
2617 /* ****************************************************************
2618 * value.h copy functions
2619 * ****************************************************************
2622 _copyValue(Value *from)
2624 Value *newnode = makeNode(Value);
2626 /* See also _copyAConst when changing this code! */
2628 COPY_SCALAR_FIELD(type);
2632 COPY_SCALAR_FIELD(val.ival);
2637 COPY_STRING_FIELD(val.str);
2643 elog(ERROR, "unrecognized node type: %d",
2653 * Create a copy of a Node tree or list. This is a "deep" copy: all
2654 * substructure is copied too, recursively.
2657 copyObject(void *from)
2664 switch (nodeTag(from))
2670 retval = _copyPlan(from);
2673 retval = _copyResult(from);
2676 retval = _copyAppend(from);
2679 retval = _copyBitmapAnd(from);
2682 retval = _copyBitmapOr(from);
2685 retval = _copyScan(from);
2688 retval = _copySeqScan(from);
2691 retval = _copyIndexScan(from);
2693 case T_BitmapIndexScan:
2694 retval = _copyBitmapIndexScan(from);
2696 case T_BitmapHeapScan:
2697 retval = _copyBitmapHeapScan(from);
2700 retval = _copyTidScan(from);
2702 case T_SubqueryScan:
2703 retval = _copySubqueryScan(from);
2705 case T_FunctionScan:
2706 retval = _copyFunctionScan(from);
2709 retval = _copyJoin(from);
2712 retval = _copyNestLoop(from);
2715 retval = _copyMergeJoin(from);
2718 retval = _copyHashJoin(from);
2721 retval = _copyMaterial(from);
2724 retval = _copySort(from);
2727 retval = _copyGroup(from);
2730 retval = _copyAgg(from);
2733 retval = _copyUnique(from);
2736 retval = _copyHash(from);
2739 retval = _copySetOp(from);
2742 retval = _copyLimit(from);
2749 retval = _copyAlias(from);
2752 retval = _copyRangeVar(from);
2755 retval = _copyVar(from);
2758 retval = _copyConst(from);
2761 retval = _copyParam(from);
2764 retval = _copyAggref(from);
2767 retval = _copyArrayRef(from);
2770 retval = _copyFuncExpr(from);
2773 retval = _copyOpExpr(from);
2775 case T_DistinctExpr:
2776 retval = _copyDistinctExpr(from);
2778 case T_ScalarArrayOpExpr:
2779 retval = _copyScalarArrayOpExpr(from);
2782 retval = _copyBoolExpr(from);
2785 retval = _copySubLink(from);
2788 retval = _copySubPlan(from);
2791 retval = _copyFieldSelect(from);
2794 retval = _copyFieldStore(from);
2797 retval = _copyRelabelType(from);
2799 case T_ConvertRowtypeExpr:
2800 retval = _copyConvertRowtypeExpr(from);
2803 retval = _copyCaseExpr(from);
2806 retval = _copyCaseWhen(from);
2808 case T_CaseTestExpr:
2809 retval = _copyCaseTestExpr(from);
2812 retval = _copyArrayExpr(from);
2815 retval = _copyRowExpr(from);
2817 case T_CoalesceExpr:
2818 retval = _copyCoalesceExpr(from);
2821 retval = _copyNullIfExpr(from);
2824 retval = _copyNullTest(from);
2827 retval = _copyBooleanTest(from);
2829 case T_CoerceToDomain:
2830 retval = _copyCoerceToDomain(from);
2832 case T_CoerceToDomainValue:
2833 retval = _copyCoerceToDomainValue(from);
2835 case T_SetToDefault:
2836 retval = _copySetToDefault(from);
2839 retval = _copyTargetEntry(from);
2842 retval = _copyRangeTblRef(from);
2845 retval = _copyJoinExpr(from);
2848 retval = _copyFromExpr(from);
2855 retval = _copyPathKeyItem(from);
2857 case T_RestrictInfo:
2858 retval = _copyRestrictInfo(from);
2861 retval = _copyJoinInfo(from);
2863 case T_InClauseInfo:
2864 retval = _copyInClauseInfo(from);
2875 retval = _copyValue(from);
2882 retval = _copyList(from);
2886 * Lists of integers and OIDs don't need to be deep-copied, so
2887 * we perform a shallow copy via list_copy()
2891 retval = list_copy(from);
2898 retval = _copyQuery(from);
2901 retval = _copyInsertStmt(from);
2904 retval = _copyDeleteStmt(from);
2907 retval = _copyUpdateStmt(from);
2910 retval = _copySelectStmt(from);
2912 case T_SetOperationStmt:
2913 retval = _copySetOperationStmt(from);
2915 case T_AlterTableStmt:
2916 retval = _copyAlterTableStmt(from);
2918 case T_AlterTableCmd:
2919 retval = _copyAlterTableCmd(from);
2921 case T_AlterDomainStmt:
2922 retval = _copyAlterDomainStmt(from);
2925 retval = _copyGrantStmt(from);
2927 case T_DeclareCursorStmt:
2928 retval = _copyDeclareCursorStmt(from);
2930 case T_ClosePortalStmt:
2931 retval = _copyClosePortalStmt(from);
2934 retval = _copyClusterStmt(from);
2937 retval = _copyCopyStmt(from);
2940 retval = _copyCreateStmt(from);
2943 retval = _copyInhRelation(from);
2946 retval = _copyDefineStmt(from);
2949 retval = _copyDropStmt(from);
2951 case T_TruncateStmt:
2952 retval = _copyTruncateStmt(from);
2955 retval = _copyCommentStmt(from);
2958 retval = _copyFetchStmt(from);
2961 retval = _copyIndexStmt(from);
2963 case T_CreateFunctionStmt:
2964 retval = _copyCreateFunctionStmt(from);
2966 case T_FunctionParameter:
2967 retval = _copyFunctionParameter(from);
2969 case T_AlterFunctionStmt:
2970 retval = _copyAlterFunctionStmt(from);
2972 case T_RemoveAggrStmt:
2973 retval = _copyRemoveAggrStmt(from);
2975 case T_RemoveFuncStmt:
2976 retval = _copyRemoveFuncStmt(from);
2978 case T_RemoveOperStmt:
2979 retval = _copyRemoveOperStmt(from);
2981 case T_RemoveOpClassStmt:
2982 retval = _copyRemoveOpClassStmt(from);
2985 retval = _copyRenameStmt(from);
2987 case T_AlterOwnerStmt:
2988 retval = _copyAlterOwnerStmt(from);
2991 retval = _copyRuleStmt(from);
2994 retval = _copyNotifyStmt(from);
2997 retval = _copyListenStmt(from);
2999 case T_UnlistenStmt:
3000 retval = _copyUnlistenStmt(from);
3002 case T_TransactionStmt:
3003 retval = _copyTransactionStmt(from);
3005 case T_CompositeTypeStmt:
3006 retval = _copyCompositeTypeStmt(from);
3009 retval = _copyViewStmt(from);
3012 retval = _copyLoadStmt(from);
3014 case T_CreateDomainStmt:
3015 retval = _copyCreateDomainStmt(from);
3017 case T_CreateOpClassStmt:
3018 retval = _copyCreateOpClassStmt(from);
3020 case T_CreateOpClassItem:
3021 retval = _copyCreateOpClassItem(from);
3023 case T_CreatedbStmt:
3024 retval = _copyCreatedbStmt(from);
3026 case T_AlterDatabaseSetStmt:
3027 retval = _copyAlterDatabaseSetStmt(from);
3030 retval = _copyDropdbStmt(from);
3033 retval = _copyVacuumStmt(from);
3036 retval = _copyExplainStmt(from);
3038 case T_CreateSeqStmt:
3039 retval = _copyCreateSeqStmt(from);
3041 case T_AlterSeqStmt:
3042 retval = _copyAlterSeqStmt(from);
3044 case T_VariableSetStmt:
3045 retval = _copyVariableSetStmt(from);
3047 case T_VariableShowStmt:
3048 retval = _copyVariableShowStmt(from);
3050 case T_VariableResetStmt:
3051 retval = _copyVariableResetStmt(from);
3053 case T_CreateTableSpaceStmt:
3054 retval = _copyCreateTableSpaceStmt(from);
3056 case T_DropTableSpaceStmt:
3057 retval = _copyDropTableSpaceStmt(from);
3059 case T_CreateTrigStmt:
3060 retval = _copyCreateTrigStmt(from);
3062 case T_DropPropertyStmt:
3063 retval = _copyDropPropertyStmt(from);
3065 case T_CreatePLangStmt:
3066 retval = _copyCreatePLangStmt(from);
3068 case T_DropPLangStmt:
3069 retval = _copyDropPLangStmt(from);
3071 case T_CreateUserStmt:
3072 retval = _copyCreateUserStmt(from);
3074 case T_AlterUserStmt:
3075 retval = _copyAlterUserStmt(from);
3077 case T_AlterUserSetStmt:
3078 retval = _copyAlterUserSetStmt(from);
3080 case T_DropUserStmt:
3081 retval = _copyDropUserStmt(from);
3084 retval = _copyLockStmt(from);
3086 case T_ConstraintsSetStmt:
3087 retval = _copyConstraintsSetStmt(from);
3089 case T_CreateGroupStmt:
3090 retval = _copyCreateGroupStmt(from);
3092 case T_AlterGroupStmt:
3093 retval = _copyAlterGroupStmt(from);
3095 case T_DropGroupStmt:
3096 retval = _copyDropGroupStmt(from);
3099 retval = _copyReindexStmt(from);
3101 case T_CheckPointStmt:
3102 retval = (void *) makeNode(CheckPointStmt);
3104 case T_CreateSchemaStmt:
3105 retval = _copyCreateSchemaStmt(from);
3107 case T_CreateConversionStmt:
3108 retval = _copyCreateConversionStmt(from);
3110 case T_CreateCastStmt:
3111 retval = _copyCreateCastStmt(from);
3113 case T_DropCastStmt:
3114 retval = _copyDropCastStmt(from);
3117 retval = _copyPrepareStmt(from);
3120 retval = _copyExecuteStmt(from);
3122 case T_DeallocateStmt:
3123 retval = _copyDeallocateStmt(from);
3127 retval = _copyAExpr(from);
3130 retval = _copyColumnRef(from);
3133 retval = _copyParamRef(from);
3136 retval = _copyAConst(from);
3139 retval = _copyFuncCall(from);
3142 retval = _copyAIndices(from);
3144 case T_A_Indirection:
3145 retval = _copyA_Indirection(from);
3148 retval = _copyResTarget(from);
3151 retval = _copyTypeCast(from);
3154 retval = _copySortBy(from);
3156 case T_RangeSubselect:
3157 retval = _copyRangeSubselect(from);
3159 case T_RangeFunction:
3160 retval = _copyRangeFunction(from);
3163 retval = _copyTypeName(from);
3166 retval = _copyIndexElem(from);
3169 retval = _copyColumnDef(from);
3172 retval = _copyConstraint(from);
3175 retval = _copyDefElem(from);
3177 case T_RangeTblEntry:
3178 retval = _copyRangeTblEntry(from);
3181 retval = _copySortClause(from);
3184 retval = _copyGroupClause(from);
3186 case T_FkConstraint:
3187 retval = _copyFkConstraint(from);
3190 retval = _copyPrivGrantee(from);
3192 case T_FuncWithArgs:
3193 retval = _copyFuncWithArgs(from);
3197 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
3198 retval = from; /* keep compiler quiet */