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.311 2005/07/02 23:00:39 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);
1054 _copyMinMaxExpr(MinMaxExpr *from)
1056 MinMaxExpr *newnode = makeNode(MinMaxExpr);
1058 COPY_SCALAR_FIELD(minmaxtype);
1059 COPY_SCALAR_FIELD(op);
1060 COPY_NODE_FIELD(args);
1066 * _copyNullIfExpr (same as OpExpr)
1069 _copyNullIfExpr(NullIfExpr *from)
1071 NullIfExpr *newnode = makeNode(NullIfExpr);
1073 COPY_SCALAR_FIELD(opno);
1074 COPY_SCALAR_FIELD(opfuncid);
1075 COPY_SCALAR_FIELD(opresulttype);
1076 COPY_SCALAR_FIELD(opretset);
1077 COPY_NODE_FIELD(args);
1086 _copyNullTest(NullTest *from)
1088 NullTest *newnode = makeNode(NullTest);
1090 COPY_NODE_FIELD(arg);
1091 COPY_SCALAR_FIELD(nulltesttype);
1099 static BooleanTest *
1100 _copyBooleanTest(BooleanTest *from)
1102 BooleanTest *newnode = makeNode(BooleanTest);
1104 COPY_NODE_FIELD(arg);
1105 COPY_SCALAR_FIELD(booltesttype);
1111 * _copyCoerceToDomain
1113 static CoerceToDomain *
1114 _copyCoerceToDomain(CoerceToDomain *from)
1116 CoerceToDomain *newnode = makeNode(CoerceToDomain);
1118 COPY_NODE_FIELD(arg);
1119 COPY_SCALAR_FIELD(resulttype);
1120 COPY_SCALAR_FIELD(resulttypmod);
1121 COPY_SCALAR_FIELD(coercionformat);
1127 * _copyCoerceToDomainValue
1129 static CoerceToDomainValue *
1130 _copyCoerceToDomainValue(CoerceToDomainValue *from)
1132 CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1134 COPY_SCALAR_FIELD(typeId);
1135 COPY_SCALAR_FIELD(typeMod);
1143 static SetToDefault *
1144 _copySetToDefault(SetToDefault *from)
1146 SetToDefault *newnode = makeNode(SetToDefault);
1148 COPY_SCALAR_FIELD(typeId);
1149 COPY_SCALAR_FIELD(typeMod);
1157 static TargetEntry *
1158 _copyTargetEntry(TargetEntry *from)
1160 TargetEntry *newnode = makeNode(TargetEntry);
1162 COPY_NODE_FIELD(expr);
1163 COPY_SCALAR_FIELD(resno);
1164 COPY_STRING_FIELD(resname);
1165 COPY_SCALAR_FIELD(ressortgroupref);
1166 COPY_SCALAR_FIELD(resorigtbl);
1167 COPY_SCALAR_FIELD(resorigcol);
1168 COPY_SCALAR_FIELD(resjunk);
1176 static RangeTblRef *
1177 _copyRangeTblRef(RangeTblRef *from)
1179 RangeTblRef *newnode = makeNode(RangeTblRef);
1181 COPY_SCALAR_FIELD(rtindex);
1190 _copyJoinExpr(JoinExpr *from)
1192 JoinExpr *newnode = makeNode(JoinExpr);
1194 COPY_SCALAR_FIELD(jointype);
1195 COPY_SCALAR_FIELD(isNatural);
1196 COPY_NODE_FIELD(larg);
1197 COPY_NODE_FIELD(rarg);
1198 COPY_NODE_FIELD(using);
1199 COPY_NODE_FIELD(quals);
1200 COPY_NODE_FIELD(alias);
1201 COPY_SCALAR_FIELD(rtindex);
1210 _copyFromExpr(FromExpr *from)
1212 FromExpr *newnode = makeNode(FromExpr);
1214 COPY_NODE_FIELD(fromlist);
1215 COPY_NODE_FIELD(quals);
1220 /* ****************************************************************
1221 * relation.h copy functions
1223 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1224 * There are some subsidiary structs that are useful to copy, though.
1225 * ****************************************************************
1231 static PathKeyItem *
1232 _copyPathKeyItem(PathKeyItem *from)
1234 PathKeyItem *newnode = makeNode(PathKeyItem);
1236 COPY_NODE_FIELD(key);
1237 COPY_SCALAR_FIELD(sortop);
1245 static RestrictInfo *
1246 _copyRestrictInfo(RestrictInfo *from)
1248 RestrictInfo *newnode = makeNode(RestrictInfo);
1250 COPY_NODE_FIELD(clause);
1251 COPY_SCALAR_FIELD(is_pushed_down);
1252 COPY_SCALAR_FIELD(can_join);
1253 COPY_BITMAPSET_FIELD(clause_relids);
1254 COPY_BITMAPSET_FIELD(required_relids);
1255 COPY_BITMAPSET_FIELD(left_relids);
1256 COPY_BITMAPSET_FIELD(right_relids);
1257 COPY_NODE_FIELD(orclause);
1258 COPY_SCALAR_FIELD(eval_cost);
1259 COPY_SCALAR_FIELD(this_selec);
1260 COPY_SCALAR_FIELD(mergejoinoperator);
1261 COPY_SCALAR_FIELD(left_sortop);
1262 COPY_SCALAR_FIELD(right_sortop);
1265 * Do not copy pathkeys, since they'd not be canonical in a copied
1268 newnode->left_pathkey = NIL;
1269 newnode->right_pathkey = NIL;
1271 COPY_SCALAR_FIELD(left_mergescansel);
1272 COPY_SCALAR_FIELD(right_mergescansel);
1273 COPY_SCALAR_FIELD(hashjoinoperator);
1274 COPY_SCALAR_FIELD(left_bucketsize);
1275 COPY_SCALAR_FIELD(right_bucketsize);
1283 static InClauseInfo *
1284 _copyInClauseInfo(InClauseInfo *from)
1286 InClauseInfo *newnode = makeNode(InClauseInfo);
1288 COPY_BITMAPSET_FIELD(lefthand);
1289 COPY_BITMAPSET_FIELD(righthand);
1290 COPY_NODE_FIELD(sub_targetlist);
1295 /* ****************************************************************
1296 * parsenodes.h copy functions
1297 * ****************************************************************
1300 static RangeTblEntry *
1301 _copyRangeTblEntry(RangeTblEntry *from)
1303 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1305 COPY_SCALAR_FIELD(rtekind);
1306 COPY_SCALAR_FIELD(relid);
1307 COPY_NODE_FIELD(subquery);
1308 COPY_NODE_FIELD(funcexpr);
1309 COPY_NODE_FIELD(coldeflist);
1310 COPY_SCALAR_FIELD(jointype);
1311 COPY_NODE_FIELD(joinaliasvars);
1312 COPY_NODE_FIELD(alias);
1313 COPY_NODE_FIELD(eref);
1314 COPY_SCALAR_FIELD(inh);
1315 COPY_SCALAR_FIELD(inFromCl);
1316 COPY_SCALAR_FIELD(requiredPerms);
1317 COPY_SCALAR_FIELD(checkAsUser);
1322 static FkConstraint *
1323 _copyFkConstraint(FkConstraint *from)
1325 FkConstraint *newnode = makeNode(FkConstraint);
1327 COPY_STRING_FIELD(constr_name);
1328 COPY_NODE_FIELD(pktable);
1329 COPY_NODE_FIELD(fk_attrs);
1330 COPY_NODE_FIELD(pk_attrs);
1331 COPY_SCALAR_FIELD(fk_matchtype);
1332 COPY_SCALAR_FIELD(fk_upd_action);
1333 COPY_SCALAR_FIELD(fk_del_action);
1334 COPY_SCALAR_FIELD(deferrable);
1335 COPY_SCALAR_FIELD(initdeferred);
1336 COPY_SCALAR_FIELD(skip_validation);
1342 _copySortClause(SortClause *from)
1344 SortClause *newnode = makeNode(SortClause);
1346 COPY_SCALAR_FIELD(tleSortGroupRef);
1347 COPY_SCALAR_FIELD(sortop);
1352 static GroupClause *
1353 _copyGroupClause(GroupClause *from)
1355 GroupClause *newnode = makeNode(GroupClause);
1357 COPY_SCALAR_FIELD(tleSortGroupRef);
1358 COPY_SCALAR_FIELD(sortop);
1364 _copyAExpr(A_Expr *from)
1366 A_Expr *newnode = makeNode(A_Expr);
1368 COPY_SCALAR_FIELD(kind);
1369 COPY_NODE_FIELD(name);
1370 COPY_NODE_FIELD(lexpr);
1371 COPY_NODE_FIELD(rexpr);
1377 _copyColumnRef(ColumnRef *from)
1379 ColumnRef *newnode = makeNode(ColumnRef);
1381 COPY_NODE_FIELD(fields);
1387 _copyParamRef(ParamRef *from)
1389 ParamRef *newnode = makeNode(ParamRef);
1391 COPY_SCALAR_FIELD(number);
1397 _copyAConst(A_Const *from)
1399 A_Const *newnode = makeNode(A_Const);
1401 /* This part must duplicate _copyValue */
1402 COPY_SCALAR_FIELD(val.type);
1403 switch (from->val.type)
1406 COPY_SCALAR_FIELD(val.val.ival);
1411 COPY_STRING_FIELD(val.val.str);
1417 elog(ERROR, "unrecognized node type: %d",
1418 (int) from->val.type);
1422 COPY_NODE_FIELD(typename);
1428 _copyFuncCall(FuncCall *from)
1430 FuncCall *newnode = makeNode(FuncCall);
1432 COPY_NODE_FIELD(funcname);
1433 COPY_NODE_FIELD(args);
1434 COPY_SCALAR_FIELD(agg_star);
1435 COPY_SCALAR_FIELD(agg_distinct);
1441 _copyAIndices(A_Indices *from)
1443 A_Indices *newnode = makeNode(A_Indices);
1445 COPY_NODE_FIELD(lidx);
1446 COPY_NODE_FIELD(uidx);
1451 static A_Indirection *
1452 _copyA_Indirection(A_Indirection *from)
1454 A_Indirection *newnode = makeNode(A_Indirection);
1456 COPY_NODE_FIELD(arg);
1457 COPY_NODE_FIELD(indirection);
1463 _copyResTarget(ResTarget *from)
1465 ResTarget *newnode = makeNode(ResTarget);
1467 COPY_STRING_FIELD(name);
1468 COPY_NODE_FIELD(indirection);
1469 COPY_NODE_FIELD(val);
1475 _copyTypeName(TypeName *from)
1477 TypeName *newnode = makeNode(TypeName);
1479 COPY_NODE_FIELD(names);
1480 COPY_SCALAR_FIELD(typeid);
1481 COPY_SCALAR_FIELD(timezone);
1482 COPY_SCALAR_FIELD(setof);
1483 COPY_SCALAR_FIELD(pct_type);
1484 COPY_SCALAR_FIELD(typmod);
1485 COPY_NODE_FIELD(arrayBounds);
1491 _copySortBy(SortBy *from)
1493 SortBy *newnode = makeNode(SortBy);
1495 COPY_SCALAR_FIELD(sortby_kind);
1496 COPY_NODE_FIELD(useOp);
1497 COPY_NODE_FIELD(node);
1502 static RangeSubselect *
1503 _copyRangeSubselect(RangeSubselect *from)
1505 RangeSubselect *newnode = makeNode(RangeSubselect);
1507 COPY_NODE_FIELD(subquery);
1508 COPY_NODE_FIELD(alias);
1513 static RangeFunction *
1514 _copyRangeFunction(RangeFunction *from)
1516 RangeFunction *newnode = makeNode(RangeFunction);
1518 COPY_NODE_FIELD(funccallnode);
1519 COPY_NODE_FIELD(alias);
1520 COPY_NODE_FIELD(coldeflist);
1526 _copyTypeCast(TypeCast *from)
1528 TypeCast *newnode = makeNode(TypeCast);
1530 COPY_NODE_FIELD(arg);
1531 COPY_NODE_FIELD(typename);
1537 _copyIndexElem(IndexElem *from)
1539 IndexElem *newnode = makeNode(IndexElem);
1541 COPY_STRING_FIELD(name);
1542 COPY_NODE_FIELD(expr);
1543 COPY_NODE_FIELD(opclass);
1549 _copyColumnDef(ColumnDef *from)
1551 ColumnDef *newnode = makeNode(ColumnDef);
1553 COPY_STRING_FIELD(colname);
1554 COPY_NODE_FIELD(typename);
1555 COPY_SCALAR_FIELD(inhcount);
1556 COPY_SCALAR_FIELD(is_local);
1557 COPY_SCALAR_FIELD(is_not_null);
1558 COPY_NODE_FIELD(raw_default);
1559 COPY_STRING_FIELD(cooked_default);
1560 COPY_NODE_FIELD(constraints);
1561 COPY_NODE_FIELD(support);
1567 _copyConstraint(Constraint *from)
1569 Constraint *newnode = makeNode(Constraint);
1571 COPY_SCALAR_FIELD(contype);
1572 COPY_STRING_FIELD(name);
1573 COPY_NODE_FIELD(raw_expr);
1574 COPY_STRING_FIELD(cooked_expr);
1575 COPY_NODE_FIELD(keys);
1576 COPY_STRING_FIELD(indexspace);
1582 _copyDefElem(DefElem *from)
1584 DefElem *newnode = makeNode(DefElem);
1586 COPY_STRING_FIELD(defname);
1587 COPY_NODE_FIELD(arg);
1593 _copyQuery(Query *from)
1595 Query *newnode = makeNode(Query);
1597 COPY_SCALAR_FIELD(commandType);
1598 COPY_SCALAR_FIELD(querySource);
1599 COPY_SCALAR_FIELD(canSetTag);
1600 COPY_NODE_FIELD(utilityStmt);
1601 COPY_SCALAR_FIELD(resultRelation);
1602 COPY_NODE_FIELD(into);
1603 COPY_SCALAR_FIELD(intoHasOids);
1604 COPY_SCALAR_FIELD(hasAggs);
1605 COPY_SCALAR_FIELD(hasSubLinks);
1606 COPY_NODE_FIELD(rtable);
1607 COPY_NODE_FIELD(jointree);
1608 COPY_NODE_FIELD(rowMarks);
1609 COPY_SCALAR_FIELD(forUpdate);
1610 COPY_NODE_FIELD(targetList);
1611 COPY_NODE_FIELD(groupClause);
1612 COPY_NODE_FIELD(havingQual);
1613 COPY_NODE_FIELD(distinctClause);
1614 COPY_NODE_FIELD(sortClause);
1615 COPY_NODE_FIELD(limitOffset);
1616 COPY_NODE_FIELD(limitCount);
1617 COPY_NODE_FIELD(setOperations);
1618 COPY_NODE_FIELD(resultRelations);
1624 _copyInsertStmt(InsertStmt *from)
1626 InsertStmt *newnode = makeNode(InsertStmt);
1628 COPY_NODE_FIELD(relation);
1629 COPY_NODE_FIELD(cols);
1630 COPY_NODE_FIELD(targetList);
1631 COPY_NODE_FIELD(selectStmt);
1637 _copyDeleteStmt(DeleteStmt *from)
1639 DeleteStmt *newnode = makeNode(DeleteStmt);
1641 COPY_NODE_FIELD(relation);
1642 COPY_NODE_FIELD(whereClause);
1643 COPY_NODE_FIELD(usingClause);
1649 _copyUpdateStmt(UpdateStmt *from)
1651 UpdateStmt *newnode = makeNode(UpdateStmt);
1653 COPY_NODE_FIELD(relation);
1654 COPY_NODE_FIELD(targetList);
1655 COPY_NODE_FIELD(whereClause);
1656 COPY_NODE_FIELD(fromClause);
1662 _copySelectStmt(SelectStmt *from)
1664 SelectStmt *newnode = makeNode(SelectStmt);
1666 COPY_NODE_FIELD(distinctClause);
1667 COPY_NODE_FIELD(into);
1668 COPY_NODE_FIELD(intoColNames);
1669 COPY_SCALAR_FIELD(intoHasOids);
1670 COPY_NODE_FIELD(targetList);
1671 COPY_NODE_FIELD(fromClause);
1672 COPY_NODE_FIELD(whereClause);
1673 COPY_NODE_FIELD(groupClause);
1674 COPY_NODE_FIELD(havingClause);
1675 COPY_NODE_FIELD(sortClause);
1676 COPY_NODE_FIELD(limitOffset);
1677 COPY_NODE_FIELD(limitCount);
1678 COPY_NODE_FIELD(lockedRels);
1679 COPY_SCALAR_FIELD(forUpdate);
1680 COPY_SCALAR_FIELD(op);
1681 COPY_SCALAR_FIELD(all);
1682 COPY_NODE_FIELD(larg);
1683 COPY_NODE_FIELD(rarg);
1688 static SetOperationStmt *
1689 _copySetOperationStmt(SetOperationStmt *from)
1691 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1693 COPY_SCALAR_FIELD(op);
1694 COPY_SCALAR_FIELD(all);
1695 COPY_NODE_FIELD(larg);
1696 COPY_NODE_FIELD(rarg);
1697 COPY_NODE_FIELD(colTypes);
1702 static AlterTableStmt *
1703 _copyAlterTableStmt(AlterTableStmt *from)
1705 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1707 COPY_NODE_FIELD(relation);
1708 COPY_NODE_FIELD(cmds);
1709 COPY_SCALAR_FIELD(relkind);
1714 static AlterTableCmd *
1715 _copyAlterTableCmd(AlterTableCmd *from)
1717 AlterTableCmd *newnode = makeNode(AlterTableCmd);
1719 COPY_SCALAR_FIELD(subtype);
1720 COPY_STRING_FIELD(name);
1721 COPY_NODE_FIELD(def);
1722 COPY_NODE_FIELD(transform);
1723 COPY_SCALAR_FIELD(behavior);
1728 static AlterDomainStmt *
1729 _copyAlterDomainStmt(AlterDomainStmt *from)
1731 AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1733 COPY_SCALAR_FIELD(subtype);
1734 COPY_NODE_FIELD(typename);
1735 COPY_STRING_FIELD(name);
1736 COPY_NODE_FIELD(def);
1737 COPY_SCALAR_FIELD(behavior);
1743 _copyGrantStmt(GrantStmt *from)
1745 GrantStmt *newnode = makeNode(GrantStmt);
1747 COPY_SCALAR_FIELD(is_grant);
1748 COPY_SCALAR_FIELD(objtype);
1749 COPY_NODE_FIELD(objects);
1750 COPY_NODE_FIELD(privileges);
1751 COPY_NODE_FIELD(grantees);
1752 COPY_SCALAR_FIELD(grant_option);
1753 COPY_SCALAR_FIELD(behavior);
1758 static PrivGrantee *
1759 _copyPrivGrantee(PrivGrantee *from)
1761 PrivGrantee *newnode = makeNode(PrivGrantee);
1763 COPY_STRING_FIELD(rolname);
1768 static FuncWithArgs *
1769 _copyFuncWithArgs(FuncWithArgs *from)
1771 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1773 COPY_NODE_FIELD(funcname);
1774 COPY_NODE_FIELD(funcargs);
1779 static GrantRoleStmt *
1780 _copyGrantRoleStmt(GrantRoleStmt *from)
1782 GrantRoleStmt *newnode = makeNode(GrantRoleStmt);
1784 COPY_NODE_FIELD(granted_roles);
1785 COPY_NODE_FIELD(grantee_roles);
1786 COPY_SCALAR_FIELD(is_grant);
1787 COPY_SCALAR_FIELD(admin_opt);
1788 COPY_STRING_FIELD(grantor);
1789 COPY_SCALAR_FIELD(behavior);
1794 static DeclareCursorStmt *
1795 _copyDeclareCursorStmt(DeclareCursorStmt *from)
1797 DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
1799 COPY_STRING_FIELD(portalname);
1800 COPY_SCALAR_FIELD(options);
1801 COPY_NODE_FIELD(query);
1806 static ClosePortalStmt *
1807 _copyClosePortalStmt(ClosePortalStmt *from)
1809 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1811 COPY_STRING_FIELD(portalname);
1816 static ClusterStmt *
1817 _copyClusterStmt(ClusterStmt *from)
1819 ClusterStmt *newnode = makeNode(ClusterStmt);
1821 COPY_NODE_FIELD(relation);
1822 COPY_STRING_FIELD(indexname);
1828 _copyCopyStmt(CopyStmt *from)
1830 CopyStmt *newnode = makeNode(CopyStmt);
1832 COPY_NODE_FIELD(relation);
1833 COPY_NODE_FIELD(attlist);
1834 COPY_SCALAR_FIELD(is_from);
1835 COPY_STRING_FIELD(filename);
1836 COPY_NODE_FIELD(options);
1842 _copyCreateStmt(CreateStmt *from)
1844 CreateStmt *newnode = makeNode(CreateStmt);
1846 COPY_NODE_FIELD(relation);
1847 COPY_NODE_FIELD(tableElts);
1848 COPY_NODE_FIELD(inhRelations);
1849 COPY_NODE_FIELD(constraints);
1850 COPY_SCALAR_FIELD(hasoids);
1851 COPY_SCALAR_FIELD(oncommit);
1852 COPY_STRING_FIELD(tablespacename);
1857 static InhRelation *
1858 _copyInhRelation(InhRelation *from)
1860 InhRelation *newnode = makeNode(InhRelation);
1862 COPY_NODE_FIELD(relation);
1863 COPY_SCALAR_FIELD(including_defaults);
1869 _copyDefineStmt(DefineStmt *from)
1871 DefineStmt *newnode = makeNode(DefineStmt);
1873 COPY_SCALAR_FIELD(kind);
1874 COPY_NODE_FIELD(defnames);
1875 COPY_NODE_FIELD(definition);
1881 _copyDropStmt(DropStmt *from)
1883 DropStmt *newnode = makeNode(DropStmt);
1885 COPY_NODE_FIELD(objects);
1886 COPY_SCALAR_FIELD(removeType);
1887 COPY_SCALAR_FIELD(behavior);
1892 static TruncateStmt *
1893 _copyTruncateStmt(TruncateStmt *from)
1895 TruncateStmt *newnode = makeNode(TruncateStmt);
1897 COPY_NODE_FIELD(relations);
1902 static CommentStmt *
1903 _copyCommentStmt(CommentStmt *from)
1905 CommentStmt *newnode = makeNode(CommentStmt);
1907 COPY_SCALAR_FIELD(objtype);
1908 COPY_NODE_FIELD(objname);
1909 COPY_NODE_FIELD(objargs);
1910 COPY_STRING_FIELD(comment);
1916 _copyFetchStmt(FetchStmt *from)
1918 FetchStmt *newnode = makeNode(FetchStmt);
1920 COPY_SCALAR_FIELD(direction);
1921 COPY_SCALAR_FIELD(howMany);
1922 COPY_STRING_FIELD(portalname);
1923 COPY_SCALAR_FIELD(ismove);
1929 _copyIndexStmt(IndexStmt *from)
1931 IndexStmt *newnode = makeNode(IndexStmt);
1933 COPY_STRING_FIELD(idxname);
1934 COPY_NODE_FIELD(relation);
1935 COPY_STRING_FIELD(accessMethod);
1936 COPY_STRING_FIELD(tableSpace);
1937 COPY_NODE_FIELD(indexParams);
1938 COPY_NODE_FIELD(whereClause);
1939 COPY_NODE_FIELD(rangetable);
1940 COPY_SCALAR_FIELD(unique);
1941 COPY_SCALAR_FIELD(primary);
1942 COPY_SCALAR_FIELD(isconstraint);
1947 static CreateFunctionStmt *
1948 _copyCreateFunctionStmt(CreateFunctionStmt *from)
1950 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
1952 COPY_SCALAR_FIELD(replace);
1953 COPY_NODE_FIELD(funcname);
1954 COPY_NODE_FIELD(parameters);
1955 COPY_NODE_FIELD(returnType);
1956 COPY_NODE_FIELD(options);
1957 COPY_NODE_FIELD(withClause);
1962 static FunctionParameter *
1963 _copyFunctionParameter(FunctionParameter *from)
1965 FunctionParameter *newnode = makeNode(FunctionParameter);
1967 COPY_STRING_FIELD(name);
1968 COPY_NODE_FIELD(argType);
1969 COPY_SCALAR_FIELD(mode);
1974 static AlterFunctionStmt *
1975 _copyAlterFunctionStmt(AlterFunctionStmt *from)
1977 AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);
1979 COPY_NODE_FIELD(func);
1980 COPY_NODE_FIELD(actions);
1985 static RemoveAggrStmt *
1986 _copyRemoveAggrStmt(RemoveAggrStmt *from)
1988 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1990 COPY_NODE_FIELD(aggname);
1991 COPY_NODE_FIELD(aggtype);
1992 COPY_SCALAR_FIELD(behavior);
1997 static RemoveFuncStmt *
1998 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2000 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2002 COPY_NODE_FIELD(funcname);
2003 COPY_NODE_FIELD(args);
2004 COPY_SCALAR_FIELD(behavior);
2009 static RemoveOperStmt *
2010 _copyRemoveOperStmt(RemoveOperStmt *from)
2012 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2014 COPY_NODE_FIELD(opname);
2015 COPY_NODE_FIELD(args);
2016 COPY_SCALAR_FIELD(behavior);
2021 static RemoveOpClassStmt *
2022 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
2024 RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
2026 COPY_NODE_FIELD(opclassname);
2027 COPY_STRING_FIELD(amname);
2028 COPY_SCALAR_FIELD(behavior);
2034 _copyRenameStmt(RenameStmt *from)
2036 RenameStmt *newnode = makeNode(RenameStmt);
2038 COPY_NODE_FIELD(relation);
2039 COPY_NODE_FIELD(object);
2040 COPY_NODE_FIELD(objarg);
2041 COPY_STRING_FIELD(subname);
2042 COPY_STRING_FIELD(newname);
2043 COPY_SCALAR_FIELD(renameType);
2048 static AlterOwnerStmt *
2049 _copyAlterOwnerStmt(AlterOwnerStmt *from)
2051 AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);
2053 COPY_NODE_FIELD(relation);
2054 COPY_NODE_FIELD(object);
2055 COPY_NODE_FIELD(objarg);
2056 COPY_STRING_FIELD(addname);
2057 COPY_STRING_FIELD(newowner);
2058 COPY_SCALAR_FIELD(objectType);
2064 _copyRuleStmt(RuleStmt *from)
2066 RuleStmt *newnode = makeNode(RuleStmt);
2068 COPY_NODE_FIELD(relation);
2069 COPY_STRING_FIELD(rulename);
2070 COPY_NODE_FIELD(whereClause);
2071 COPY_SCALAR_FIELD(event);
2072 COPY_SCALAR_FIELD(instead);
2073 COPY_NODE_FIELD(actions);
2074 COPY_SCALAR_FIELD(replace);
2080 _copyNotifyStmt(NotifyStmt *from)
2082 NotifyStmt *newnode = makeNode(NotifyStmt);
2084 COPY_NODE_FIELD(relation);
2090 _copyListenStmt(ListenStmt *from)
2092 ListenStmt *newnode = makeNode(ListenStmt);
2094 COPY_NODE_FIELD(relation);
2099 static UnlistenStmt *
2100 _copyUnlistenStmt(UnlistenStmt *from)
2102 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2104 COPY_NODE_FIELD(relation);
2109 static TransactionStmt *
2110 _copyTransactionStmt(TransactionStmt *from)
2112 TransactionStmt *newnode = makeNode(TransactionStmt);
2114 COPY_SCALAR_FIELD(kind);
2115 COPY_NODE_FIELD(options);
2116 COPY_STRING_FIELD(gid);
2121 static CompositeTypeStmt *
2122 _copyCompositeTypeStmt(CompositeTypeStmt *from)
2124 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
2126 COPY_NODE_FIELD(typevar);
2127 COPY_NODE_FIELD(coldeflist);
2133 _copyViewStmt(ViewStmt *from)
2135 ViewStmt *newnode = makeNode(ViewStmt);
2137 COPY_NODE_FIELD(view);
2138 COPY_NODE_FIELD(aliases);
2139 COPY_NODE_FIELD(query);
2140 COPY_SCALAR_FIELD(replace);
2146 _copyLoadStmt(LoadStmt *from)
2148 LoadStmt *newnode = makeNode(LoadStmt);
2150 COPY_STRING_FIELD(filename);
2155 static CreateDomainStmt *
2156 _copyCreateDomainStmt(CreateDomainStmt *from)
2158 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2160 COPY_NODE_FIELD(domainname);
2161 COPY_NODE_FIELD(typename);
2162 COPY_NODE_FIELD(constraints);
2167 static CreateOpClassStmt *
2168 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2170 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2172 COPY_NODE_FIELD(opclassname);
2173 COPY_STRING_FIELD(amname);
2174 COPY_NODE_FIELD(datatype);
2175 COPY_NODE_FIELD(items);
2176 COPY_SCALAR_FIELD(isDefault);
2181 static CreateOpClassItem *
2182 _copyCreateOpClassItem(CreateOpClassItem *from)
2184 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2186 COPY_SCALAR_FIELD(itemtype);
2187 COPY_NODE_FIELD(name);
2188 COPY_NODE_FIELD(args);
2189 COPY_SCALAR_FIELD(number);
2190 COPY_SCALAR_FIELD(recheck);
2191 COPY_NODE_FIELD(storedtype);
2196 static CreatedbStmt *
2197 _copyCreatedbStmt(CreatedbStmt *from)
2199 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2201 COPY_STRING_FIELD(dbname);
2202 COPY_NODE_FIELD(options);
2207 static AlterDatabaseSetStmt *
2208 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2210 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2212 COPY_STRING_FIELD(dbname);
2213 COPY_STRING_FIELD(variable);
2214 COPY_NODE_FIELD(value);
2220 _copyDropdbStmt(DropdbStmt *from)
2222 DropdbStmt *newnode = makeNode(DropdbStmt);
2224 COPY_STRING_FIELD(dbname);
2230 _copyVacuumStmt(VacuumStmt *from)
2232 VacuumStmt *newnode = makeNode(VacuumStmt);
2234 COPY_SCALAR_FIELD(vacuum);
2235 COPY_SCALAR_FIELD(full);
2236 COPY_SCALAR_FIELD(analyze);
2237 COPY_SCALAR_FIELD(freeze);
2238 COPY_SCALAR_FIELD(verbose);
2239 COPY_NODE_FIELD(relation);
2240 COPY_NODE_FIELD(va_cols);
2245 static ExplainStmt *
2246 _copyExplainStmt(ExplainStmt *from)
2248 ExplainStmt *newnode = makeNode(ExplainStmt);
2250 COPY_NODE_FIELD(query);
2251 COPY_SCALAR_FIELD(verbose);
2252 COPY_SCALAR_FIELD(analyze);
2257 static CreateSeqStmt *
2258 _copyCreateSeqStmt(CreateSeqStmt *from)
2260 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2262 COPY_NODE_FIELD(sequence);
2263 COPY_NODE_FIELD(options);
2268 static AlterSeqStmt *
2269 _copyAlterSeqStmt(AlterSeqStmt *from)
2271 AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
2273 COPY_NODE_FIELD(sequence);
2274 COPY_NODE_FIELD(options);
2279 static VariableSetStmt *
2280 _copyVariableSetStmt(VariableSetStmt *from)
2282 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2284 COPY_STRING_FIELD(name);
2285 COPY_NODE_FIELD(args);
2286 COPY_SCALAR_FIELD(is_local);
2291 static VariableShowStmt *
2292 _copyVariableShowStmt(VariableShowStmt *from)
2294 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2296 COPY_STRING_FIELD(name);
2301 static VariableResetStmt *
2302 _copyVariableResetStmt(VariableResetStmt *from)
2304 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2306 COPY_STRING_FIELD(name);
2311 static CreateTableSpaceStmt *
2312 _copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
2314 CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
2316 COPY_STRING_FIELD(tablespacename);
2317 COPY_STRING_FIELD(owner);
2318 COPY_STRING_FIELD(location);
2323 static DropTableSpaceStmt *
2324 _copyDropTableSpaceStmt(DropTableSpaceStmt *from)
2326 DropTableSpaceStmt *newnode = makeNode(DropTableSpaceStmt);
2328 COPY_STRING_FIELD(tablespacename);
2333 static CreateTrigStmt *
2334 _copyCreateTrigStmt(CreateTrigStmt *from)
2336 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2338 COPY_STRING_FIELD(trigname);
2339 COPY_NODE_FIELD(relation);
2340 COPY_NODE_FIELD(funcname);
2341 COPY_NODE_FIELD(args);
2342 COPY_SCALAR_FIELD(before);
2343 COPY_SCALAR_FIELD(row);
2344 strcpy(newnode->actions, from->actions); /* in-line string field */
2345 COPY_SCALAR_FIELD(isconstraint);
2346 COPY_SCALAR_FIELD(deferrable);
2347 COPY_SCALAR_FIELD(initdeferred);
2348 COPY_NODE_FIELD(constrrel);
2353 static DropPropertyStmt *
2354 _copyDropPropertyStmt(DropPropertyStmt *from)
2356 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2358 COPY_NODE_FIELD(relation);
2359 COPY_STRING_FIELD(property);
2360 COPY_SCALAR_FIELD(removeType);
2361 COPY_SCALAR_FIELD(behavior);
2366 static CreatePLangStmt *
2367 _copyCreatePLangStmt(CreatePLangStmt *from)
2369 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2371 COPY_STRING_FIELD(plname);
2372 COPY_NODE_FIELD(plhandler);
2373 COPY_NODE_FIELD(plvalidator);
2374 COPY_SCALAR_FIELD(pltrusted);
2379 static DropPLangStmt *
2380 _copyDropPLangStmt(DropPLangStmt *from)
2382 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2384 COPY_STRING_FIELD(plname);
2385 COPY_SCALAR_FIELD(behavior);
2390 static CreateRoleStmt *
2391 _copyCreateRoleStmt(CreateRoleStmt *from)
2393 CreateRoleStmt *newnode = makeNode(CreateRoleStmt);
2395 COPY_STRING_FIELD(role);
2396 COPY_NODE_FIELD(options);
2401 static AlterRoleStmt *
2402 _copyAlterRoleStmt(AlterRoleStmt *from)
2404 AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
2406 COPY_STRING_FIELD(role);
2407 COPY_NODE_FIELD(options);
2408 COPY_SCALAR_FIELD(action);
2413 static AlterRoleSetStmt *
2414 _copyAlterRoleSetStmt(AlterRoleSetStmt *from)
2416 AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
2418 COPY_STRING_FIELD(role);
2419 COPY_STRING_FIELD(variable);
2420 COPY_NODE_FIELD(value);
2425 static DropRoleStmt *
2426 _copyDropRoleStmt(DropRoleStmt *from)
2428 DropRoleStmt *newnode = makeNode(DropRoleStmt);
2430 COPY_NODE_FIELD(roles);
2436 _copyLockStmt(LockStmt *from)
2438 LockStmt *newnode = makeNode(LockStmt);
2440 COPY_NODE_FIELD(relations);
2441 COPY_SCALAR_FIELD(mode);
2442 COPY_SCALAR_FIELD(nowait);
2447 static ConstraintsSetStmt *
2448 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2450 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2452 COPY_NODE_FIELD(constraints);
2453 COPY_SCALAR_FIELD(deferred);
2458 static ReindexStmt *
2459 _copyReindexStmt(ReindexStmt *from)
2461 ReindexStmt *newnode = makeNode(ReindexStmt);
2463 COPY_SCALAR_FIELD(kind);
2464 COPY_NODE_FIELD(relation);
2465 COPY_STRING_FIELD(name);
2466 COPY_SCALAR_FIELD(do_system);
2467 COPY_SCALAR_FIELD(do_user);
2472 static CreateSchemaStmt *
2473 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2475 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2477 COPY_STRING_FIELD(schemaname);
2478 COPY_STRING_FIELD(authid);
2479 COPY_NODE_FIELD(schemaElts);
2484 static CreateConversionStmt *
2485 _copyCreateConversionStmt(CreateConversionStmt *from)
2487 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2489 COPY_NODE_FIELD(conversion_name);
2490 COPY_STRING_FIELD(for_encoding_name);
2491 COPY_STRING_FIELD(to_encoding_name);
2492 COPY_NODE_FIELD(func_name);
2493 COPY_SCALAR_FIELD(def);
2498 static CreateCastStmt *
2499 _copyCreateCastStmt(CreateCastStmt *from)
2501 CreateCastStmt *newnode = makeNode(CreateCastStmt);
2503 COPY_NODE_FIELD(sourcetype);
2504 COPY_NODE_FIELD(targettype);
2505 COPY_NODE_FIELD(func);
2506 COPY_SCALAR_FIELD(context);
2511 static DropCastStmt *
2512 _copyDropCastStmt(DropCastStmt *from)
2514 DropCastStmt *newnode = makeNode(DropCastStmt);
2516 COPY_NODE_FIELD(sourcetype);
2517 COPY_NODE_FIELD(targettype);
2518 COPY_SCALAR_FIELD(behavior);
2523 static PrepareStmt *
2524 _copyPrepareStmt(PrepareStmt *from)
2526 PrepareStmt *newnode = makeNode(PrepareStmt);
2528 COPY_STRING_FIELD(name);
2529 COPY_NODE_FIELD(argtypes);
2530 COPY_NODE_FIELD(argtype_oids);
2531 COPY_NODE_FIELD(query);
2536 static ExecuteStmt *
2537 _copyExecuteStmt(ExecuteStmt *from)
2539 ExecuteStmt *newnode = makeNode(ExecuteStmt);
2541 COPY_STRING_FIELD(name);
2542 COPY_NODE_FIELD(into);
2543 COPY_NODE_FIELD(params);
2548 static DeallocateStmt *
2549 _copyDeallocateStmt(DeallocateStmt *from)
2551 DeallocateStmt *newnode = makeNode(DeallocateStmt);
2553 COPY_STRING_FIELD(name);
2559 /* ****************************************************************
2560 * pg_list.h copy functions
2561 * ****************************************************************
2565 * Perform a deep copy of the specified list, using copyObject(). The
2566 * list MUST be of type T_List; T_IntList and T_OidList nodes don't
2567 * need deep copies, so they should be copied via list_copy()
2569 #define COPY_NODE_CELL(new, old) \
2570 (new) = (ListCell *) palloc(sizeof(ListCell)); \
2571 lfirst(new) = copyObject(lfirst(old));
2574 _copyList(List *from)
2580 Assert(list_length(from) >= 1);
2582 new = makeNode(List);
2583 new->length = from->length;
2585 COPY_NODE_CELL(new->head, from->head);
2586 prev_new = new->head;
2587 curr_old = lnext(from->head);
2591 COPY_NODE_CELL(prev_new->next, curr_old);
2592 prev_new = prev_new->next;
2593 curr_old = curr_old->next;
2595 prev_new->next = NULL;
2596 new->tail = prev_new;
2601 /* ****************************************************************
2602 * value.h copy functions
2603 * ****************************************************************
2606 _copyValue(Value *from)
2608 Value *newnode = makeNode(Value);
2610 /* See also _copyAConst when changing this code! */
2612 COPY_SCALAR_FIELD(type);
2616 COPY_SCALAR_FIELD(val.ival);
2621 COPY_STRING_FIELD(val.str);
2627 elog(ERROR, "unrecognized node type: %d",
2637 * Create a copy of a Node tree or list. This is a "deep" copy: all
2638 * substructure is copied too, recursively.
2641 copyObject(void *from)
2648 switch (nodeTag(from))
2654 retval = _copyPlan(from);
2657 retval = _copyResult(from);
2660 retval = _copyAppend(from);
2663 retval = _copyBitmapAnd(from);
2666 retval = _copyBitmapOr(from);
2669 retval = _copyScan(from);
2672 retval = _copySeqScan(from);
2675 retval = _copyIndexScan(from);
2677 case T_BitmapIndexScan:
2678 retval = _copyBitmapIndexScan(from);
2680 case T_BitmapHeapScan:
2681 retval = _copyBitmapHeapScan(from);
2684 retval = _copyTidScan(from);
2686 case T_SubqueryScan:
2687 retval = _copySubqueryScan(from);
2689 case T_FunctionScan:
2690 retval = _copyFunctionScan(from);
2693 retval = _copyJoin(from);
2696 retval = _copyNestLoop(from);
2699 retval = _copyMergeJoin(from);
2702 retval = _copyHashJoin(from);
2705 retval = _copyMaterial(from);
2708 retval = _copySort(from);
2711 retval = _copyGroup(from);
2714 retval = _copyAgg(from);
2717 retval = _copyUnique(from);
2720 retval = _copyHash(from);
2723 retval = _copySetOp(from);
2726 retval = _copyLimit(from);
2733 retval = _copyAlias(from);
2736 retval = _copyRangeVar(from);
2739 retval = _copyVar(from);
2742 retval = _copyConst(from);
2745 retval = _copyParam(from);
2748 retval = _copyAggref(from);
2751 retval = _copyArrayRef(from);
2754 retval = _copyFuncExpr(from);
2757 retval = _copyOpExpr(from);
2759 case T_DistinctExpr:
2760 retval = _copyDistinctExpr(from);
2762 case T_ScalarArrayOpExpr:
2763 retval = _copyScalarArrayOpExpr(from);
2766 retval = _copyBoolExpr(from);
2769 retval = _copySubLink(from);
2772 retval = _copySubPlan(from);
2775 retval = _copyFieldSelect(from);
2778 retval = _copyFieldStore(from);
2781 retval = _copyRelabelType(from);
2783 case T_ConvertRowtypeExpr:
2784 retval = _copyConvertRowtypeExpr(from);
2787 retval = _copyCaseExpr(from);
2790 retval = _copyCaseWhen(from);
2792 case T_CaseTestExpr:
2793 retval = _copyCaseTestExpr(from);
2796 retval = _copyArrayExpr(from);
2799 retval = _copyRowExpr(from);
2801 case T_CoalesceExpr:
2802 retval = _copyCoalesceExpr(from);
2805 retval = _copyMinMaxExpr(from);
2808 retval = _copyNullIfExpr(from);
2811 retval = _copyNullTest(from);
2814 retval = _copyBooleanTest(from);
2816 case T_CoerceToDomain:
2817 retval = _copyCoerceToDomain(from);
2819 case T_CoerceToDomainValue:
2820 retval = _copyCoerceToDomainValue(from);
2822 case T_SetToDefault:
2823 retval = _copySetToDefault(from);
2826 retval = _copyTargetEntry(from);
2829 retval = _copyRangeTblRef(from);
2832 retval = _copyJoinExpr(from);
2835 retval = _copyFromExpr(from);
2842 retval = _copyPathKeyItem(from);
2844 case T_RestrictInfo:
2845 retval = _copyRestrictInfo(from);
2847 case T_InClauseInfo:
2848 retval = _copyInClauseInfo(from);
2859 retval = _copyValue(from);
2866 retval = _copyList(from);
2870 * Lists of integers and OIDs don't need to be deep-copied, so
2871 * we perform a shallow copy via list_copy()
2875 retval = list_copy(from);
2882 retval = _copyQuery(from);
2885 retval = _copyInsertStmt(from);
2888 retval = _copyDeleteStmt(from);
2891 retval = _copyUpdateStmt(from);
2894 retval = _copySelectStmt(from);
2896 case T_SetOperationStmt:
2897 retval = _copySetOperationStmt(from);
2899 case T_AlterTableStmt:
2900 retval = _copyAlterTableStmt(from);
2902 case T_AlterTableCmd:
2903 retval = _copyAlterTableCmd(from);
2905 case T_AlterDomainStmt:
2906 retval = _copyAlterDomainStmt(from);
2909 retval = _copyGrantStmt(from);
2911 case T_GrantRoleStmt:
2912 retval = _copyGrantRoleStmt(from);
2914 case T_DeclareCursorStmt:
2915 retval = _copyDeclareCursorStmt(from);
2917 case T_ClosePortalStmt:
2918 retval = _copyClosePortalStmt(from);
2921 retval = _copyClusterStmt(from);
2924 retval = _copyCopyStmt(from);
2927 retval = _copyCreateStmt(from);
2930 retval = _copyInhRelation(from);
2933 retval = _copyDefineStmt(from);
2936 retval = _copyDropStmt(from);
2938 case T_TruncateStmt:
2939 retval = _copyTruncateStmt(from);
2942 retval = _copyCommentStmt(from);
2945 retval = _copyFetchStmt(from);
2948 retval = _copyIndexStmt(from);
2950 case T_CreateFunctionStmt:
2951 retval = _copyCreateFunctionStmt(from);
2953 case T_FunctionParameter:
2954 retval = _copyFunctionParameter(from);
2956 case T_AlterFunctionStmt:
2957 retval = _copyAlterFunctionStmt(from);
2959 case T_RemoveAggrStmt:
2960 retval = _copyRemoveAggrStmt(from);
2962 case T_RemoveFuncStmt:
2963 retval = _copyRemoveFuncStmt(from);
2965 case T_RemoveOperStmt:
2966 retval = _copyRemoveOperStmt(from);
2968 case T_RemoveOpClassStmt:
2969 retval = _copyRemoveOpClassStmt(from);
2972 retval = _copyRenameStmt(from);
2974 case T_AlterOwnerStmt:
2975 retval = _copyAlterOwnerStmt(from);
2978 retval = _copyRuleStmt(from);
2981 retval = _copyNotifyStmt(from);
2984 retval = _copyListenStmt(from);
2986 case T_UnlistenStmt:
2987 retval = _copyUnlistenStmt(from);
2989 case T_TransactionStmt:
2990 retval = _copyTransactionStmt(from);
2992 case T_CompositeTypeStmt:
2993 retval = _copyCompositeTypeStmt(from);
2996 retval = _copyViewStmt(from);
2999 retval = _copyLoadStmt(from);
3001 case T_CreateDomainStmt:
3002 retval = _copyCreateDomainStmt(from);
3004 case T_CreateOpClassStmt:
3005 retval = _copyCreateOpClassStmt(from);
3007 case T_CreateOpClassItem:
3008 retval = _copyCreateOpClassItem(from);
3010 case T_CreatedbStmt:
3011 retval = _copyCreatedbStmt(from);
3013 case T_AlterDatabaseSetStmt:
3014 retval = _copyAlterDatabaseSetStmt(from);
3017 retval = _copyDropdbStmt(from);
3020 retval = _copyVacuumStmt(from);
3023 retval = _copyExplainStmt(from);
3025 case T_CreateSeqStmt:
3026 retval = _copyCreateSeqStmt(from);
3028 case T_AlterSeqStmt:
3029 retval = _copyAlterSeqStmt(from);
3031 case T_VariableSetStmt:
3032 retval = _copyVariableSetStmt(from);
3034 case T_VariableShowStmt:
3035 retval = _copyVariableShowStmt(from);
3037 case T_VariableResetStmt:
3038 retval = _copyVariableResetStmt(from);
3040 case T_CreateTableSpaceStmt:
3041 retval = _copyCreateTableSpaceStmt(from);
3043 case T_DropTableSpaceStmt:
3044 retval = _copyDropTableSpaceStmt(from);
3046 case T_CreateTrigStmt:
3047 retval = _copyCreateTrigStmt(from);
3049 case T_DropPropertyStmt:
3050 retval = _copyDropPropertyStmt(from);
3052 case T_CreatePLangStmt:
3053 retval = _copyCreatePLangStmt(from);
3055 case T_DropPLangStmt:
3056 retval = _copyDropPLangStmt(from);
3058 case T_CreateRoleStmt:
3059 retval = _copyCreateRoleStmt(from);
3061 case T_AlterRoleStmt:
3062 retval = _copyAlterRoleStmt(from);
3064 case T_AlterRoleSetStmt:
3065 retval = _copyAlterRoleSetStmt(from);
3067 case T_DropRoleStmt:
3068 retval = _copyDropRoleStmt(from);
3071 retval = _copyLockStmt(from);
3073 case T_ConstraintsSetStmt:
3074 retval = _copyConstraintsSetStmt(from);
3077 retval = _copyReindexStmt(from);
3079 case T_CheckPointStmt:
3080 retval = (void *) makeNode(CheckPointStmt);
3082 case T_CreateSchemaStmt:
3083 retval = _copyCreateSchemaStmt(from);
3085 case T_CreateConversionStmt:
3086 retval = _copyCreateConversionStmt(from);
3088 case T_CreateCastStmt:
3089 retval = _copyCreateCastStmt(from);
3091 case T_DropCastStmt:
3092 retval = _copyDropCastStmt(from);
3095 retval = _copyPrepareStmt(from);
3098 retval = _copyExecuteStmt(from);
3100 case T_DeallocateStmt:
3101 retval = _copyDeallocateStmt(from);
3105 retval = _copyAExpr(from);
3108 retval = _copyColumnRef(from);
3111 retval = _copyParamRef(from);
3114 retval = _copyAConst(from);
3117 retval = _copyFuncCall(from);
3120 retval = _copyAIndices(from);
3122 case T_A_Indirection:
3123 retval = _copyA_Indirection(from);
3126 retval = _copyResTarget(from);
3129 retval = _copyTypeCast(from);
3132 retval = _copySortBy(from);
3134 case T_RangeSubselect:
3135 retval = _copyRangeSubselect(from);
3137 case T_RangeFunction:
3138 retval = _copyRangeFunction(from);
3141 retval = _copyTypeName(from);
3144 retval = _copyIndexElem(from);
3147 retval = _copyColumnDef(from);
3150 retval = _copyConstraint(from);
3153 retval = _copyDefElem(from);
3155 case T_RangeTblEntry:
3156 retval = _copyRangeTblEntry(from);
3159 retval = _copySortClause(from);
3162 retval = _copyGroupClause(from);
3164 case T_FkConstraint:
3165 retval = _copyFkConstraint(from);
3168 retval = _copyPrivGrantee(from);
3170 case T_FuncWithArgs:
3171 retval = _copyFuncWithArgs(from);
3175 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
3176 retval = from; /* keep compiler quiet */