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-2002, PostgreSQL Global Development Group
15 * Portions Copyright (c) 1994, Regents of the University of California
18 * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.235 2003/01/10 21:08:10 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 list of integers */
47 #define COPY_INTLIST_FIELD(fldname) \
48 (newnode->fldname = listCopy(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); \
65 * This copy function only copies the "cons-cells" of the list, not the
66 * pointed-to objects. (Use copyObject if you want a "deep" copy.)
68 * We also use this function for copying lists of integers, which is
69 * grotty but unlikely to break --- it could fail if sizeof(pointer)
70 * is less than sizeof(int), but I don't know any such machines...
72 * Note that copyObject will surely coredump if applied to a list
82 /* rather ugly coding for speed... */
86 newlist = nl = makeList1(lfirst(list));
88 foreach(l, lnext(list))
90 lnext(nl) = makeList1(lfirst(l));
96 /* ****************************************************************
97 * plannodes.h copy functions
98 * ****************************************************************
104 * This function copies the fields of the Plan node. It is used by
105 * all the copy functions for classes which inherit from Plan.
108 CopyPlanFields(Plan *from, Plan *newnode)
110 COPY_SCALAR_FIELD(startup_cost);
111 COPY_SCALAR_FIELD(total_cost);
112 COPY_SCALAR_FIELD(plan_rows);
113 COPY_SCALAR_FIELD(plan_width);
114 COPY_NODE_FIELD(targetlist);
115 COPY_NODE_FIELD(qual);
116 COPY_NODE_FIELD(lefttree);
117 COPY_NODE_FIELD(righttree);
118 COPY_NODE_FIELD(initPlan);
119 COPY_INTLIST_FIELD(extParam);
120 COPY_INTLIST_FIELD(locParam);
121 COPY_SCALAR_FIELD(nParamExec);
128 _copyPlan(Plan *from)
130 Plan *newnode = makeNode(Plan);
133 * copy node superclass fields
135 CopyPlanFields(from, newnode);
145 _copyResult(Result *from)
147 Result *newnode = makeNode(Result);
150 * copy node superclass fields
152 CopyPlanFields((Plan *) from, (Plan *) newnode);
155 * copy remainder of node
157 COPY_NODE_FIELD(resconstantqual);
166 _copyAppend(Append *from)
168 Append *newnode = makeNode(Append);
171 * copy node superclass fields
173 CopyPlanFields((Plan *) from, (Plan *) newnode);
176 * copy remainder of node
178 COPY_NODE_FIELD(appendplans);
179 COPY_SCALAR_FIELD(isTarget);
188 * This function copies the fields of the Scan node. It is used by
189 * all the copy functions for classes which inherit from Scan.
192 CopyScanFields(Scan *from, Scan *newnode)
194 CopyPlanFields((Plan *) from, (Plan *) newnode);
196 COPY_SCALAR_FIELD(scanrelid);
203 _copyScan(Scan *from)
205 Scan *newnode = makeNode(Scan);
208 * copy node superclass fields
210 CopyScanFields((Scan *) from, (Scan *) newnode);
219 _copySeqScan(SeqScan *from)
221 SeqScan *newnode = makeNode(SeqScan);
224 * copy node superclass fields
226 CopyScanFields((Scan *) from, (Scan *) newnode);
235 _copyIndexScan(IndexScan *from)
237 IndexScan *newnode = makeNode(IndexScan);
240 * copy node superclass fields
242 CopyScanFields((Scan *) from, (Scan *) newnode);
245 * copy remainder of node
247 COPY_INTLIST_FIELD(indxid);
248 COPY_NODE_FIELD(indxqual);
249 COPY_NODE_FIELD(indxqualorig);
250 COPY_SCALAR_FIELD(indxorderdir);
259 _copyTidScan(TidScan *from)
261 TidScan *newnode = makeNode(TidScan);
264 * copy node superclass fields
266 CopyScanFields((Scan *) from, (Scan *) newnode);
269 * copy remainder of node
271 COPY_NODE_FIELD(tideval);
279 static SubqueryScan *
280 _copySubqueryScan(SubqueryScan *from)
282 SubqueryScan *newnode = makeNode(SubqueryScan);
285 * copy node superclass fields
287 CopyScanFields((Scan *) from, (Scan *) newnode);
290 * copy remainder of node
292 COPY_NODE_FIELD(subplan);
300 static FunctionScan *
301 _copyFunctionScan(FunctionScan *from)
303 FunctionScan *newnode = makeNode(FunctionScan);
306 * copy node superclass fields
308 CopyScanFields((Scan *) from, (Scan *) newnode);
316 * This function copies the fields of the Join node. It is used by
317 * all the copy functions for classes which inherit from Join.
320 CopyJoinFields(Join *from, Join *newnode)
322 CopyPlanFields((Plan *) from, (Plan *) newnode);
324 COPY_SCALAR_FIELD(jointype);
325 COPY_NODE_FIELD(joinqual);
333 _copyJoin(Join *from)
335 Join *newnode = makeNode(Join);
338 * copy node superclass fields
340 CopyJoinFields(from, newnode);
350 _copyNestLoop(NestLoop *from)
352 NestLoop *newnode = makeNode(NestLoop);
355 * copy node superclass fields
357 CopyJoinFields((Join *) from, (Join *) newnode);
367 _copyMergeJoin(MergeJoin *from)
369 MergeJoin *newnode = makeNode(MergeJoin);
372 * copy node superclass fields
374 CopyJoinFields((Join *) from, (Join *) newnode);
377 * copy remainder of node
379 COPY_NODE_FIELD(mergeclauses);
388 _copyHashJoin(HashJoin *from)
390 HashJoin *newnode = makeNode(HashJoin);
393 * copy node superclass fields
395 CopyJoinFields((Join *) from, (Join *) newnode);
398 * copy remainder of node
400 COPY_NODE_FIELD(hashclauses);
410 _copyMaterial(Material *from)
412 Material *newnode = makeNode(Material);
415 * copy node superclass fields
417 CopyPlanFields((Plan *) from, (Plan *) newnode);
427 _copySort(Sort *from)
429 Sort *newnode = makeNode(Sort);
432 * copy node superclass fields
434 CopyPlanFields((Plan *) from, (Plan *) newnode);
436 COPY_SCALAR_FIELD(keycount);
446 _copyGroup(Group *from)
448 Group *newnode = makeNode(Group);
450 CopyPlanFields((Plan *) from, (Plan *) newnode);
452 COPY_SCALAR_FIELD(numCols);
453 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
464 Agg *newnode = makeNode(Agg);
466 CopyPlanFields((Plan *) from, (Plan *) newnode);
468 COPY_SCALAR_FIELD(aggstrategy);
469 COPY_SCALAR_FIELD(numCols);
470 if (from->numCols > 0)
471 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
472 COPY_SCALAR_FIELD(numGroups);
481 _copyUnique(Unique *from)
483 Unique *newnode = makeNode(Unique);
486 * copy node superclass fields
488 CopyPlanFields((Plan *) from, (Plan *) newnode);
491 * copy remainder of node
493 COPY_SCALAR_FIELD(numCols);
494 COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
503 _copyHash(Hash *from)
505 Hash *newnode = makeNode(Hash);
508 * copy node superclass fields
510 CopyPlanFields((Plan *) from, (Plan *) newnode);
513 * copy remainder of node
515 COPY_NODE_FIELD(hashkeys);
524 _copySetOp(SetOp *from)
526 SetOp *newnode = makeNode(SetOp);
529 * copy node superclass fields
531 CopyPlanFields((Plan *) from, (Plan *) newnode);
534 * copy remainder of node
536 COPY_SCALAR_FIELD(cmd);
537 COPY_SCALAR_FIELD(numCols);
538 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
539 COPY_SCALAR_FIELD(flagColIdx);
548 _copyLimit(Limit *from)
550 Limit *newnode = makeNode(Limit);
553 * copy node superclass fields
555 CopyPlanFields((Plan *) from, (Plan *) newnode);
558 * copy remainder of node
560 COPY_NODE_FIELD(limitOffset);
561 COPY_NODE_FIELD(limitCount);
566 /* ****************************************************************
567 * primnodes.h copy functions
568 * ****************************************************************
575 _copyResdom(Resdom *from)
577 Resdom *newnode = makeNode(Resdom);
579 COPY_SCALAR_FIELD(resno);
580 COPY_SCALAR_FIELD(restype);
581 COPY_SCALAR_FIELD(restypmod);
582 COPY_STRING_FIELD(resname);
583 COPY_SCALAR_FIELD(ressortgroupref);
584 COPY_SCALAR_FIELD(reskey);
585 COPY_SCALAR_FIELD(reskeyop);
586 COPY_SCALAR_FIELD(resjunk);
595 _copyAlias(Alias *from)
597 Alias *newnode = makeNode(Alias);
599 COPY_STRING_FIELD(aliasname);
600 COPY_NODE_FIELD(colnames);
609 _copyRangeVar(RangeVar *from)
611 RangeVar *newnode = makeNode(RangeVar);
613 COPY_STRING_FIELD(catalogname);
614 COPY_STRING_FIELD(schemaname);
615 COPY_STRING_FIELD(relname);
616 COPY_SCALAR_FIELD(inhOpt);
617 COPY_SCALAR_FIELD(istemp);
618 COPY_NODE_FIELD(alias);
624 * We don't need a _copyExpr because Expr is an abstract supertype which
625 * should never actually get instantiated. Also, since it has no common
626 * fields except NodeTag, there's no need for a helper routine to factor
627 * out copying the common fields...
636 Var *newnode = makeNode(Var);
638 COPY_SCALAR_FIELD(varno);
639 COPY_SCALAR_FIELD(varattno);
640 COPY_SCALAR_FIELD(vartype);
641 COPY_SCALAR_FIELD(vartypmod);
642 COPY_SCALAR_FIELD(varlevelsup);
643 COPY_SCALAR_FIELD(varnoold);
644 COPY_SCALAR_FIELD(varoattno);
653 _copyConst(Const *from)
655 Const *newnode = makeNode(Const);
657 COPY_SCALAR_FIELD(consttype);
658 COPY_SCALAR_FIELD(constlen);
660 if (from->constbyval || from->constisnull)
663 * passed by value so just copy the datum. Also, don't try to copy
664 * struct when value is null!
666 newnode->constvalue = from->constvalue;
671 * passed by reference. We need a palloc'd copy.
673 newnode->constvalue = datumCopy(from->constvalue,
678 COPY_SCALAR_FIELD(constisnull);
679 COPY_SCALAR_FIELD(constbyval);
688 _copyParam(Param *from)
690 Param *newnode = makeNode(Param);
692 COPY_SCALAR_FIELD(paramkind);
693 COPY_SCALAR_FIELD(paramid);
694 COPY_STRING_FIELD(paramname);
695 COPY_SCALAR_FIELD(paramtype);
704 _copyAggref(Aggref *from)
706 Aggref *newnode = makeNode(Aggref);
708 COPY_SCALAR_FIELD(aggfnoid);
709 COPY_SCALAR_FIELD(aggtype);
710 COPY_NODE_FIELD(target);
711 COPY_SCALAR_FIELD(aggstar);
712 COPY_SCALAR_FIELD(aggdistinct);
721 _copyArrayRef(ArrayRef *from)
723 ArrayRef *newnode = makeNode(ArrayRef);
725 COPY_SCALAR_FIELD(refrestype);
726 COPY_SCALAR_FIELD(refattrlength);
727 COPY_SCALAR_FIELD(refelemlength);
728 COPY_SCALAR_FIELD(refelembyval);
729 COPY_SCALAR_FIELD(refelemalign);
730 COPY_NODE_FIELD(refupperindexpr);
731 COPY_NODE_FIELD(reflowerindexpr);
732 COPY_NODE_FIELD(refexpr);
733 COPY_NODE_FIELD(refassgnexpr);
742 _copyFuncExpr(FuncExpr *from)
744 FuncExpr *newnode = makeNode(FuncExpr);
746 COPY_SCALAR_FIELD(funcid);
747 COPY_SCALAR_FIELD(funcresulttype);
748 COPY_SCALAR_FIELD(funcretset);
749 COPY_SCALAR_FIELD(funcformat);
750 COPY_NODE_FIELD(args);
759 _copyOpExpr(OpExpr *from)
761 OpExpr *newnode = makeNode(OpExpr);
763 COPY_SCALAR_FIELD(opno);
764 COPY_SCALAR_FIELD(opfuncid);
765 COPY_SCALAR_FIELD(opresulttype);
766 COPY_SCALAR_FIELD(opretset);
767 COPY_NODE_FIELD(args);
775 static DistinctExpr *
776 _copyDistinctExpr(DistinctExpr *from)
778 DistinctExpr *newnode = makeNode(DistinctExpr);
780 COPY_SCALAR_FIELD(opno);
781 COPY_SCALAR_FIELD(opfuncid);
782 COPY_SCALAR_FIELD(opresulttype);
783 COPY_SCALAR_FIELD(opretset);
784 COPY_NODE_FIELD(args);
793 _copyBoolExpr(BoolExpr *from)
795 BoolExpr *newnode = makeNode(BoolExpr);
797 COPY_SCALAR_FIELD(boolop);
798 COPY_NODE_FIELD(args);
807 _copySubLink(SubLink *from)
809 SubLink *newnode = makeNode(SubLink);
811 COPY_SCALAR_FIELD(subLinkType);
812 COPY_SCALAR_FIELD(useOr);
813 COPY_NODE_FIELD(lefthand);
814 COPY_NODE_FIELD(operName);
815 COPY_INTLIST_FIELD(operOids);
816 COPY_NODE_FIELD(subselect);
825 _copySubPlan(SubPlan *from)
827 SubPlan *newnode = makeNode(SubPlan);
829 COPY_SCALAR_FIELD(subLinkType);
830 COPY_SCALAR_FIELD(useOr);
831 COPY_NODE_FIELD(exprs);
832 COPY_INTLIST_FIELD(paramIds);
833 COPY_NODE_FIELD(plan);
834 COPY_SCALAR_FIELD(plan_id);
835 COPY_NODE_FIELD(rtable);
836 COPY_SCALAR_FIELD(useHashTable);
837 COPY_SCALAR_FIELD(unknownEqFalse);
838 COPY_INTLIST_FIELD(setParam);
839 COPY_INTLIST_FIELD(parParam);
840 COPY_NODE_FIELD(args);
849 _copyFieldSelect(FieldSelect *from)
851 FieldSelect *newnode = makeNode(FieldSelect);
853 COPY_NODE_FIELD(arg);
854 COPY_SCALAR_FIELD(fieldnum);
855 COPY_SCALAR_FIELD(resulttype);
856 COPY_SCALAR_FIELD(resulttypmod);
865 _copyRelabelType(RelabelType *from)
867 RelabelType *newnode = makeNode(RelabelType);
869 COPY_NODE_FIELD(arg);
870 COPY_SCALAR_FIELD(resulttype);
871 COPY_SCALAR_FIELD(resulttypmod);
872 COPY_SCALAR_FIELD(relabelformat);
881 _copyCaseExpr(CaseExpr *from)
883 CaseExpr *newnode = makeNode(CaseExpr);
885 COPY_SCALAR_FIELD(casetype);
886 COPY_NODE_FIELD(arg);
887 COPY_NODE_FIELD(args);
888 COPY_NODE_FIELD(defresult);
897 _copyCaseWhen(CaseWhen *from)
899 CaseWhen *newnode = makeNode(CaseWhen);
901 COPY_NODE_FIELD(expr);
902 COPY_NODE_FIELD(result);
911 _copyNullTest(NullTest *from)
913 NullTest *newnode = makeNode(NullTest);
915 COPY_NODE_FIELD(arg);
916 COPY_SCALAR_FIELD(nulltesttype);
925 _copyBooleanTest(BooleanTest *from)
927 BooleanTest *newnode = makeNode(BooleanTest);
929 COPY_NODE_FIELD(arg);
930 COPY_SCALAR_FIELD(booltesttype);
936 * _copyConstraintTest
938 static ConstraintTest *
939 _copyConstraintTest(ConstraintTest *from)
941 ConstraintTest *newnode = makeNode(ConstraintTest);
943 COPY_NODE_FIELD(arg);
944 COPY_SCALAR_FIELD(testtype);
945 COPY_STRING_FIELD(name);
946 COPY_STRING_FIELD(domname);
947 COPY_NODE_FIELD(check_expr);
953 * _copyConstraintTestValue
955 static ConstraintTestValue *
956 _copyConstraintTestValue(ConstraintTestValue *from)
958 ConstraintTestValue *newnode = makeNode(ConstraintTestValue);
960 COPY_SCALAR_FIELD(typeId);
961 COPY_SCALAR_FIELD(typeMod);
970 _copyTargetEntry(TargetEntry *from)
972 TargetEntry *newnode = makeNode(TargetEntry);
974 COPY_NODE_FIELD(resdom);
975 COPY_NODE_FIELD(expr);
984 _copyRangeTblRef(RangeTblRef *from)
986 RangeTblRef *newnode = makeNode(RangeTblRef);
988 COPY_SCALAR_FIELD(rtindex);
997 _copyJoinExpr(JoinExpr *from)
999 JoinExpr *newnode = makeNode(JoinExpr);
1001 COPY_SCALAR_FIELD(jointype);
1002 COPY_SCALAR_FIELD(isNatural);
1003 COPY_NODE_FIELD(larg);
1004 COPY_NODE_FIELD(rarg);
1005 COPY_NODE_FIELD(using);
1006 COPY_NODE_FIELD(quals);
1007 COPY_NODE_FIELD(alias);
1008 COPY_SCALAR_FIELD(rtindex);
1017 _copyFromExpr(FromExpr *from)
1019 FromExpr *newnode = makeNode(FromExpr);
1021 COPY_NODE_FIELD(fromlist);
1022 COPY_NODE_FIELD(quals);
1027 /* ****************************************************************
1028 * relation.h copy functions
1030 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1031 * There are some subsidiary structs that are useful to copy, though.
1032 * ****************************************************************
1038 static PathKeyItem *
1039 _copyPathKeyItem(PathKeyItem *from)
1041 PathKeyItem *newnode = makeNode(PathKeyItem);
1043 COPY_NODE_FIELD(key);
1044 COPY_SCALAR_FIELD(sortop);
1052 static RestrictInfo *
1053 _copyRestrictInfo(RestrictInfo *from)
1055 RestrictInfo *newnode = makeNode(RestrictInfo);
1057 COPY_NODE_FIELD(clause);
1058 COPY_SCALAR_FIELD(ispusheddown);
1059 COPY_NODE_FIELD(subclauseindices); /* XXX probably bad */
1060 COPY_SCALAR_FIELD(eval_cost);
1061 COPY_SCALAR_FIELD(this_selec);
1062 COPY_SCALAR_FIELD(mergejoinoperator);
1063 COPY_SCALAR_FIELD(left_sortop);
1064 COPY_SCALAR_FIELD(right_sortop);
1067 * Do not copy pathkeys, since they'd not be canonical in a copied
1070 newnode->left_pathkey = NIL;
1071 newnode->right_pathkey = NIL;
1073 COPY_SCALAR_FIELD(left_mergescansel);
1074 COPY_SCALAR_FIELD(right_mergescansel);
1075 COPY_SCALAR_FIELD(hashjoinoperator);
1076 COPY_SCALAR_FIELD(left_bucketsize);
1077 COPY_SCALAR_FIELD(right_bucketsize);
1086 _copyJoinInfo(JoinInfo *from)
1088 JoinInfo *newnode = makeNode(JoinInfo);
1090 COPY_INTLIST_FIELD(unjoined_relids);
1091 COPY_NODE_FIELD(jinfo_restrictinfo);
1096 /* ****************************************************************
1097 * parsenodes.h copy functions
1098 * ****************************************************************
1101 static RangeTblEntry *
1102 _copyRangeTblEntry(RangeTblEntry *from)
1104 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1106 COPY_SCALAR_FIELD(rtekind);
1107 COPY_SCALAR_FIELD(relid);
1108 COPY_NODE_FIELD(subquery);
1109 COPY_NODE_FIELD(funcexpr);
1110 COPY_NODE_FIELD(coldeflist);
1111 COPY_SCALAR_FIELD(jointype);
1112 COPY_NODE_FIELD(joinaliasvars);
1113 COPY_NODE_FIELD(alias);
1114 COPY_NODE_FIELD(eref);
1115 COPY_SCALAR_FIELD(inh);
1116 COPY_SCALAR_FIELD(inFromCl);
1117 COPY_SCALAR_FIELD(checkForRead);
1118 COPY_SCALAR_FIELD(checkForWrite);
1119 COPY_SCALAR_FIELD(checkAsUser);
1124 static FkConstraint *
1125 _copyFkConstraint(FkConstraint *from)
1127 FkConstraint *newnode = makeNode(FkConstraint);
1129 COPY_STRING_FIELD(constr_name);
1130 COPY_NODE_FIELD(pktable);
1131 COPY_NODE_FIELD(fk_attrs);
1132 COPY_NODE_FIELD(pk_attrs);
1133 COPY_SCALAR_FIELD(fk_matchtype);
1134 COPY_SCALAR_FIELD(fk_upd_action);
1135 COPY_SCALAR_FIELD(fk_del_action);
1136 COPY_SCALAR_FIELD(deferrable);
1137 COPY_SCALAR_FIELD(initdeferred);
1138 COPY_SCALAR_FIELD(skip_validation);
1144 _copySortClause(SortClause *from)
1146 SortClause *newnode = makeNode(SortClause);
1148 COPY_SCALAR_FIELD(tleSortGroupRef);
1149 COPY_SCALAR_FIELD(sortop);
1154 static GroupClause *
1155 _copyGroupClause(GroupClause *from)
1157 GroupClause *newnode = makeNode(GroupClause);
1159 COPY_SCALAR_FIELD(tleSortGroupRef);
1160 COPY_SCALAR_FIELD(sortop);
1166 _copyAExpr(A_Expr *from)
1168 A_Expr *newnode = makeNode(A_Expr);
1170 COPY_SCALAR_FIELD(oper);
1171 COPY_NODE_FIELD(name);
1172 COPY_NODE_FIELD(lexpr);
1173 COPY_NODE_FIELD(rexpr);
1179 _copyColumnRef(ColumnRef *from)
1181 ColumnRef *newnode = makeNode(ColumnRef);
1183 COPY_NODE_FIELD(fields);
1184 COPY_NODE_FIELD(indirection);
1190 _copyParamRef(ParamRef *from)
1192 ParamRef *newnode = makeNode(ParamRef);
1194 COPY_SCALAR_FIELD(number);
1195 COPY_NODE_FIELD(fields);
1196 COPY_NODE_FIELD(indirection);
1202 _copyAConst(A_Const *from)
1204 A_Const *newnode = makeNode(A_Const);
1206 /* This part must duplicate _copyValue */
1207 COPY_SCALAR_FIELD(val.type);
1208 switch (from->val.type)
1211 COPY_SCALAR_FIELD(val.val.ival);
1216 COPY_STRING_FIELD(val.val.str);
1222 elog(ERROR, "_copyAConst: unknown node type %d", from->val.type);
1226 COPY_NODE_FIELD(typename);
1232 _copyFuncCall(FuncCall *from)
1234 FuncCall *newnode = makeNode(FuncCall);
1236 COPY_NODE_FIELD(funcname);
1237 COPY_NODE_FIELD(args);
1238 COPY_SCALAR_FIELD(agg_star);
1239 COPY_SCALAR_FIELD(agg_distinct);
1245 _copyAIndices(A_Indices *from)
1247 A_Indices *newnode = makeNode(A_Indices);
1249 COPY_NODE_FIELD(lidx);
1250 COPY_NODE_FIELD(uidx);
1255 static ExprFieldSelect *
1256 _copyExprFieldSelect(ExprFieldSelect *from)
1258 ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
1260 COPY_NODE_FIELD(arg);
1261 COPY_NODE_FIELD(fields);
1262 COPY_NODE_FIELD(indirection);
1268 _copyResTarget(ResTarget *from)
1270 ResTarget *newnode = makeNode(ResTarget);
1272 COPY_STRING_FIELD(name);
1273 COPY_NODE_FIELD(indirection);
1274 COPY_NODE_FIELD(val);
1280 _copyTypeName(TypeName *from)
1282 TypeName *newnode = makeNode(TypeName);
1284 COPY_NODE_FIELD(names);
1285 COPY_SCALAR_FIELD(typeid);
1286 COPY_SCALAR_FIELD(timezone);
1287 COPY_SCALAR_FIELD(setof);
1288 COPY_SCALAR_FIELD(pct_type);
1289 COPY_SCALAR_FIELD(typmod);
1290 COPY_NODE_FIELD(arrayBounds);
1295 static SortGroupBy *
1296 _copySortGroupBy(SortGroupBy *from)
1298 SortGroupBy *newnode = makeNode(SortGroupBy);
1300 COPY_NODE_FIELD(useOp);
1301 COPY_NODE_FIELD(node);
1306 static RangeSubselect *
1307 _copyRangeSubselect(RangeSubselect *from)
1309 RangeSubselect *newnode = makeNode(RangeSubselect);
1311 COPY_NODE_FIELD(subquery);
1312 COPY_NODE_FIELD(alias);
1317 static RangeFunction *
1318 _copyRangeFunction(RangeFunction *from)
1320 RangeFunction *newnode = makeNode(RangeFunction);
1322 COPY_NODE_FIELD(funccallnode);
1323 COPY_NODE_FIELD(alias);
1324 COPY_NODE_FIELD(coldeflist);
1330 _copyTypeCast(TypeCast *from)
1332 TypeCast *newnode = makeNode(TypeCast);
1334 COPY_NODE_FIELD(arg);
1335 COPY_NODE_FIELD(typename);
1341 _copyIndexElem(IndexElem *from)
1343 IndexElem *newnode = makeNode(IndexElem);
1345 COPY_STRING_FIELD(name);
1346 COPY_NODE_FIELD(funcname);
1347 COPY_NODE_FIELD(args);
1348 COPY_NODE_FIELD(opclass);
1354 _copyColumnDef(ColumnDef *from)
1356 ColumnDef *newnode = makeNode(ColumnDef);
1358 COPY_STRING_FIELD(colname);
1359 COPY_NODE_FIELD(typename);
1360 COPY_SCALAR_FIELD(inhcount);
1361 COPY_SCALAR_FIELD(is_local);
1362 COPY_SCALAR_FIELD(is_not_null);
1363 COPY_NODE_FIELD(raw_default);
1364 COPY_STRING_FIELD(cooked_default);
1365 COPY_NODE_FIELD(constraints);
1366 COPY_NODE_FIELD(support);
1372 _copyConstraint(Constraint *from)
1374 Constraint *newnode = makeNode(Constraint);
1376 COPY_SCALAR_FIELD(contype);
1377 COPY_STRING_FIELD(name);
1378 COPY_NODE_FIELD(raw_expr);
1379 COPY_STRING_FIELD(cooked_expr);
1380 COPY_NODE_FIELD(keys);
1386 _copyDefElem(DefElem *from)
1388 DefElem *newnode = makeNode(DefElem);
1390 COPY_STRING_FIELD(defname);
1391 COPY_NODE_FIELD(arg);
1397 _copyQuery(Query *from)
1399 Query *newnode = makeNode(Query);
1401 COPY_SCALAR_FIELD(commandType);
1402 COPY_SCALAR_FIELD(querySource);
1403 COPY_NODE_FIELD(utilityStmt);
1404 COPY_SCALAR_FIELD(resultRelation);
1405 COPY_NODE_FIELD(into);
1406 COPY_SCALAR_FIELD(isPortal);
1407 COPY_SCALAR_FIELD(isBinary);
1408 COPY_SCALAR_FIELD(hasAggs);
1409 COPY_SCALAR_FIELD(hasSubLinks);
1410 COPY_NODE_FIELD(rtable);
1411 COPY_NODE_FIELD(jointree);
1412 COPY_INTLIST_FIELD(rowMarks);
1413 COPY_NODE_FIELD(targetList);
1414 COPY_NODE_FIELD(groupClause);
1415 COPY_NODE_FIELD(havingQual);
1416 COPY_NODE_FIELD(distinctClause);
1417 COPY_NODE_FIELD(sortClause);
1418 COPY_NODE_FIELD(limitOffset);
1419 COPY_NODE_FIELD(limitCount);
1420 COPY_NODE_FIELD(setOperations);
1421 COPY_INTLIST_FIELD(resultRelations);
1424 * We do not copy the planner internal fields: base_rel_list,
1425 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys,
1426 * hasJoinRTEs. That would get us into copying RelOptInfo/Path
1427 * trees, which we don't want to do.
1434 _copyInsertStmt(InsertStmt *from)
1436 InsertStmt *newnode = makeNode(InsertStmt);
1438 COPY_NODE_FIELD(relation);
1439 COPY_NODE_FIELD(cols);
1440 COPY_NODE_FIELD(targetList);
1441 COPY_NODE_FIELD(selectStmt);
1447 _copyDeleteStmt(DeleteStmt *from)
1449 DeleteStmt *newnode = makeNode(DeleteStmt);
1451 COPY_NODE_FIELD(relation);
1452 COPY_NODE_FIELD(whereClause);
1458 _copyUpdateStmt(UpdateStmt *from)
1460 UpdateStmt *newnode = makeNode(UpdateStmt);
1462 COPY_NODE_FIELD(relation);
1463 COPY_NODE_FIELD(targetList);
1464 COPY_NODE_FIELD(whereClause);
1465 COPY_NODE_FIELD(fromClause);
1471 _copySelectStmt(SelectStmt *from)
1473 SelectStmt *newnode = makeNode(SelectStmt);
1475 COPY_NODE_FIELD(distinctClause);
1476 COPY_NODE_FIELD(into);
1477 COPY_NODE_FIELD(intoColNames);
1478 COPY_NODE_FIELD(targetList);
1479 COPY_NODE_FIELD(fromClause);
1480 COPY_NODE_FIELD(whereClause);
1481 COPY_NODE_FIELD(groupClause);
1482 COPY_NODE_FIELD(havingClause);
1483 COPY_NODE_FIELD(sortClause);
1484 COPY_STRING_FIELD(portalname);
1485 COPY_SCALAR_FIELD(binary);
1486 COPY_NODE_FIELD(limitOffset);
1487 COPY_NODE_FIELD(limitCount);
1488 COPY_NODE_FIELD(forUpdate);
1489 COPY_SCALAR_FIELD(op);
1490 COPY_SCALAR_FIELD(all);
1491 COPY_NODE_FIELD(larg);
1492 COPY_NODE_FIELD(rarg);
1497 static SetOperationStmt *
1498 _copySetOperationStmt(SetOperationStmt *from)
1500 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1502 COPY_SCALAR_FIELD(op);
1503 COPY_SCALAR_FIELD(all);
1504 COPY_NODE_FIELD(larg);
1505 COPY_NODE_FIELD(rarg);
1506 COPY_INTLIST_FIELD(colTypes);
1511 static AlterTableStmt *
1512 _copyAlterTableStmt(AlterTableStmt *from)
1514 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1516 COPY_SCALAR_FIELD(subtype);
1517 COPY_NODE_FIELD(relation);
1518 COPY_STRING_FIELD(name);
1519 COPY_NODE_FIELD(def);
1520 COPY_SCALAR_FIELD(behavior);
1525 static AlterDomainStmt *
1526 _copyAlterDomainStmt(AlterDomainStmt *from)
1528 AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1530 COPY_SCALAR_FIELD(subtype);
1531 COPY_NODE_FIELD(typename);
1532 COPY_STRING_FIELD(name);
1533 COPY_NODE_FIELD(def);
1534 COPY_SCALAR_FIELD(behavior);
1540 _copyGrantStmt(GrantStmt *from)
1542 GrantStmt *newnode = makeNode(GrantStmt);
1544 COPY_SCALAR_FIELD(is_grant);
1545 COPY_SCALAR_FIELD(objtype);
1546 COPY_NODE_FIELD(objects);
1547 COPY_INTLIST_FIELD(privileges);
1548 COPY_NODE_FIELD(grantees);
1553 static PrivGrantee *
1554 _copyPrivGrantee(PrivGrantee *from)
1556 PrivGrantee *newnode = makeNode(PrivGrantee);
1558 COPY_STRING_FIELD(username);
1559 COPY_STRING_FIELD(groupname);
1564 static FuncWithArgs *
1565 _copyFuncWithArgs(FuncWithArgs *from)
1567 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1569 COPY_NODE_FIELD(funcname);
1570 COPY_NODE_FIELD(funcargs);
1575 static InsertDefault *
1576 _copyInsertDefault(InsertDefault *from)
1578 InsertDefault *newnode = makeNode(InsertDefault);
1584 static ClosePortalStmt *
1585 _copyClosePortalStmt(ClosePortalStmt *from)
1587 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1589 COPY_STRING_FIELD(portalname);
1594 static ClusterStmt *
1595 _copyClusterStmt(ClusterStmt *from)
1597 ClusterStmt *newnode = makeNode(ClusterStmt);
1599 COPY_NODE_FIELD(relation);
1600 COPY_STRING_FIELD(indexname);
1606 _copyCopyStmt(CopyStmt *from)
1608 CopyStmt *newnode = makeNode(CopyStmt);
1610 COPY_NODE_FIELD(relation);
1611 COPY_NODE_FIELD(attlist);
1612 COPY_SCALAR_FIELD(is_from);
1613 COPY_STRING_FIELD(filename);
1614 COPY_NODE_FIELD(options);
1620 _copyCreateStmt(CreateStmt *from)
1622 CreateStmt *newnode = makeNode(CreateStmt);
1624 COPY_NODE_FIELD(relation);
1625 COPY_NODE_FIELD(tableElts);
1626 COPY_NODE_FIELD(inhRelations);
1627 COPY_NODE_FIELD(constraints);
1628 COPY_SCALAR_FIELD(hasoids);
1629 COPY_SCALAR_FIELD(oncommit);
1635 _copyDefineStmt(DefineStmt *from)
1637 DefineStmt *newnode = makeNode(DefineStmt);
1639 COPY_SCALAR_FIELD(defType);
1640 COPY_NODE_FIELD(defnames);
1641 COPY_NODE_FIELD(definition);
1647 _copyDropStmt(DropStmt *from)
1649 DropStmt *newnode = makeNode(DropStmt);
1651 COPY_NODE_FIELD(objects);
1652 COPY_SCALAR_FIELD(removeType);
1653 COPY_SCALAR_FIELD(behavior);
1658 static TruncateStmt *
1659 _copyTruncateStmt(TruncateStmt *from)
1661 TruncateStmt *newnode = makeNode(TruncateStmt);
1663 COPY_NODE_FIELD(relation);
1668 static CommentStmt *
1669 _copyCommentStmt(CommentStmt *from)
1671 CommentStmt *newnode = makeNode(CommentStmt);
1673 COPY_SCALAR_FIELD(objtype);
1674 COPY_NODE_FIELD(objname);
1675 COPY_NODE_FIELD(objargs);
1676 COPY_STRING_FIELD(comment);
1682 _copyFetchStmt(FetchStmt *from)
1684 FetchStmt *newnode = makeNode(FetchStmt);
1686 COPY_SCALAR_FIELD(direction);
1687 COPY_SCALAR_FIELD(howMany);
1688 COPY_STRING_FIELD(portalname);
1689 COPY_SCALAR_FIELD(ismove);
1695 _copyIndexStmt(IndexStmt *from)
1697 IndexStmt *newnode = makeNode(IndexStmt);
1699 COPY_STRING_FIELD(idxname);
1700 COPY_NODE_FIELD(relation);
1701 COPY_STRING_FIELD(accessMethod);
1702 COPY_NODE_FIELD(indexParams);
1703 COPY_NODE_FIELD(whereClause);
1704 COPY_NODE_FIELD(rangetable);
1705 COPY_SCALAR_FIELD(unique);
1706 COPY_SCALAR_FIELD(primary);
1707 COPY_SCALAR_FIELD(isconstraint);
1712 static CreateFunctionStmt *
1713 _copyCreateFunctionStmt(CreateFunctionStmt *from)
1715 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
1717 COPY_SCALAR_FIELD(replace);
1718 COPY_NODE_FIELD(funcname);
1719 COPY_NODE_FIELD(argTypes);
1720 COPY_NODE_FIELD(returnType);
1721 COPY_NODE_FIELD(options);
1722 COPY_NODE_FIELD(withClause);
1727 static RemoveAggrStmt *
1728 _copyRemoveAggrStmt(RemoveAggrStmt *from)
1730 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1732 COPY_NODE_FIELD(aggname);
1733 COPY_NODE_FIELD(aggtype);
1734 COPY_SCALAR_FIELD(behavior);
1739 static RemoveFuncStmt *
1740 _copyRemoveFuncStmt(RemoveFuncStmt *from)
1742 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
1744 COPY_NODE_FIELD(funcname);
1745 COPY_NODE_FIELD(args);
1746 COPY_SCALAR_FIELD(behavior);
1751 static RemoveOperStmt *
1752 _copyRemoveOperStmt(RemoveOperStmt *from)
1754 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
1756 COPY_NODE_FIELD(opname);
1757 COPY_NODE_FIELD(args);
1758 COPY_SCALAR_FIELD(behavior);
1763 static RemoveOpClassStmt *
1764 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
1766 RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
1768 COPY_NODE_FIELD(opclassname);
1769 COPY_STRING_FIELD(amname);
1770 COPY_SCALAR_FIELD(behavior);
1776 _copyRenameStmt(RenameStmt *from)
1778 RenameStmt *newnode = makeNode(RenameStmt);
1780 COPY_NODE_FIELD(relation);
1781 COPY_STRING_FIELD(oldname);
1782 COPY_STRING_FIELD(newname);
1783 COPY_SCALAR_FIELD(renameType);
1789 _copyRuleStmt(RuleStmt *from)
1791 RuleStmt *newnode = makeNode(RuleStmt);
1793 COPY_NODE_FIELD(relation);
1794 COPY_STRING_FIELD(rulename);
1795 COPY_NODE_FIELD(whereClause);
1796 COPY_SCALAR_FIELD(event);
1797 COPY_SCALAR_FIELD(instead);
1798 COPY_NODE_FIELD(actions);
1799 COPY_SCALAR_FIELD(replace);
1805 _copyNotifyStmt(NotifyStmt *from)
1807 NotifyStmt *newnode = makeNode(NotifyStmt);
1809 COPY_NODE_FIELD(relation);
1815 _copyListenStmt(ListenStmt *from)
1817 ListenStmt *newnode = makeNode(ListenStmt);
1819 COPY_NODE_FIELD(relation);
1824 static UnlistenStmt *
1825 _copyUnlistenStmt(UnlistenStmt *from)
1827 UnlistenStmt *newnode = makeNode(UnlistenStmt);
1829 COPY_NODE_FIELD(relation);
1834 static TransactionStmt *
1835 _copyTransactionStmt(TransactionStmt *from)
1837 TransactionStmt *newnode = makeNode(TransactionStmt);
1839 COPY_SCALAR_FIELD(command);
1840 COPY_NODE_FIELD(options);
1845 static CompositeTypeStmt *
1846 _copyCompositeTypeStmt(CompositeTypeStmt *from)
1848 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
1850 COPY_NODE_FIELD(typevar);
1851 COPY_NODE_FIELD(coldeflist);
1857 _copyViewStmt(ViewStmt *from)
1859 ViewStmt *newnode = makeNode(ViewStmt);
1861 COPY_NODE_FIELD(view);
1862 COPY_NODE_FIELD(aliases);
1863 COPY_NODE_FIELD(query);
1864 COPY_SCALAR_FIELD(replace);
1870 _copyLoadStmt(LoadStmt *from)
1872 LoadStmt *newnode = makeNode(LoadStmt);
1874 COPY_STRING_FIELD(filename);
1879 static CreateDomainStmt *
1880 _copyCreateDomainStmt(CreateDomainStmt *from)
1882 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
1884 COPY_NODE_FIELD(domainname);
1885 COPY_NODE_FIELD(typename);
1886 COPY_NODE_FIELD(constraints);
1891 static CreateOpClassStmt *
1892 _copyCreateOpClassStmt(CreateOpClassStmt *from)
1894 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
1896 COPY_NODE_FIELD(opclassname);
1897 COPY_STRING_FIELD(amname);
1898 COPY_NODE_FIELD(datatype);
1899 COPY_NODE_FIELD(items);
1900 COPY_SCALAR_FIELD(isDefault);
1905 static CreateOpClassItem *
1906 _copyCreateOpClassItem(CreateOpClassItem *from)
1908 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
1910 COPY_SCALAR_FIELD(itemtype);
1911 COPY_NODE_FIELD(name);
1912 COPY_NODE_FIELD(args);
1913 COPY_SCALAR_FIELD(number);
1914 COPY_SCALAR_FIELD(recheck);
1915 COPY_NODE_FIELD(storedtype);
1920 static CreatedbStmt *
1921 _copyCreatedbStmt(CreatedbStmt *from)
1923 CreatedbStmt *newnode = makeNode(CreatedbStmt);
1925 COPY_STRING_FIELD(dbname);
1926 COPY_NODE_FIELD(options);
1931 static AlterDatabaseSetStmt *
1932 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
1934 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
1936 COPY_STRING_FIELD(dbname);
1937 COPY_STRING_FIELD(variable);
1938 COPY_NODE_FIELD(value);
1944 _copyDropdbStmt(DropdbStmt *from)
1946 DropdbStmt *newnode = makeNode(DropdbStmt);
1948 COPY_STRING_FIELD(dbname);
1954 _copyVacuumStmt(VacuumStmt *from)
1956 VacuumStmt *newnode = makeNode(VacuumStmt);
1958 COPY_SCALAR_FIELD(vacuum);
1959 COPY_SCALAR_FIELD(full);
1960 COPY_SCALAR_FIELD(analyze);
1961 COPY_SCALAR_FIELD(freeze);
1962 COPY_SCALAR_FIELD(verbose);
1963 COPY_NODE_FIELD(relation);
1964 COPY_NODE_FIELD(va_cols);
1969 static ExplainStmt *
1970 _copyExplainStmt(ExplainStmt *from)
1972 ExplainStmt *newnode = makeNode(ExplainStmt);
1974 COPY_NODE_FIELD(query);
1975 COPY_SCALAR_FIELD(verbose);
1976 COPY_SCALAR_FIELD(analyze);
1981 static CreateSeqStmt *
1982 _copyCreateSeqStmt(CreateSeqStmt *from)
1984 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
1986 COPY_NODE_FIELD(sequence);
1987 COPY_NODE_FIELD(options);
1992 static VariableSetStmt *
1993 _copyVariableSetStmt(VariableSetStmt *from)
1995 VariableSetStmt *newnode = makeNode(VariableSetStmt);
1997 COPY_STRING_FIELD(name);
1998 COPY_NODE_FIELD(args);
1999 COPY_SCALAR_FIELD(is_local);
2004 static VariableShowStmt *
2005 _copyVariableShowStmt(VariableShowStmt *from)
2007 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2009 COPY_STRING_FIELD(name);
2014 static VariableResetStmt *
2015 _copyVariableResetStmt(VariableResetStmt *from)
2017 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2019 COPY_STRING_FIELD(name);
2024 static CreateTrigStmt *
2025 _copyCreateTrigStmt(CreateTrigStmt *from)
2027 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2029 COPY_STRING_FIELD(trigname);
2030 COPY_NODE_FIELD(relation);
2031 COPY_NODE_FIELD(funcname);
2032 COPY_NODE_FIELD(args);
2033 COPY_SCALAR_FIELD(before);
2034 COPY_SCALAR_FIELD(row);
2035 strcpy(newnode->actions, from->actions); /* in-line string field */
2036 COPY_SCALAR_FIELD(isconstraint);
2037 COPY_SCALAR_FIELD(deferrable);
2038 COPY_SCALAR_FIELD(initdeferred);
2039 COPY_NODE_FIELD(constrrel);
2044 static DropPropertyStmt *
2045 _copyDropPropertyStmt(DropPropertyStmt *from)
2047 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2049 COPY_NODE_FIELD(relation);
2050 COPY_STRING_FIELD(property);
2051 COPY_SCALAR_FIELD(removeType);
2052 COPY_SCALAR_FIELD(behavior);
2057 static CreatePLangStmt *
2058 _copyCreatePLangStmt(CreatePLangStmt *from)
2060 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2062 COPY_STRING_FIELD(plname);
2063 COPY_NODE_FIELD(plhandler);
2064 COPY_NODE_FIELD(plvalidator);
2065 COPY_SCALAR_FIELD(pltrusted);
2070 static DropPLangStmt *
2071 _copyDropPLangStmt(DropPLangStmt *from)
2073 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2075 COPY_STRING_FIELD(plname);
2076 COPY_SCALAR_FIELD(behavior);
2081 static CreateUserStmt *
2082 _copyCreateUserStmt(CreateUserStmt *from)
2084 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2086 COPY_STRING_FIELD(user);
2087 COPY_NODE_FIELD(options);
2092 static AlterUserStmt *
2093 _copyAlterUserStmt(AlterUserStmt *from)
2095 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2097 COPY_STRING_FIELD(user);
2098 COPY_NODE_FIELD(options);
2103 static AlterUserSetStmt *
2104 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2106 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2108 COPY_STRING_FIELD(user);
2109 COPY_STRING_FIELD(variable);
2110 COPY_NODE_FIELD(value);
2115 static DropUserStmt *
2116 _copyDropUserStmt(DropUserStmt *from)
2118 DropUserStmt *newnode = makeNode(DropUserStmt);
2120 COPY_NODE_FIELD(users);
2126 _copyLockStmt(LockStmt *from)
2128 LockStmt *newnode = makeNode(LockStmt);
2130 COPY_NODE_FIELD(relations);
2131 COPY_SCALAR_FIELD(mode);
2136 static ConstraintsSetStmt *
2137 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2139 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2141 COPY_NODE_FIELD(constraints);
2142 COPY_SCALAR_FIELD(deferred);
2147 static CreateGroupStmt *
2148 _copyCreateGroupStmt(CreateGroupStmt *from)
2150 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2152 COPY_STRING_FIELD(name);
2153 COPY_NODE_FIELD(options);
2158 static AlterGroupStmt *
2159 _copyAlterGroupStmt(AlterGroupStmt *from)
2161 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2163 COPY_STRING_FIELD(name);
2164 COPY_SCALAR_FIELD(action);
2165 COPY_NODE_FIELD(listUsers);
2170 static DropGroupStmt *
2171 _copyDropGroupStmt(DropGroupStmt *from)
2173 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2175 COPY_STRING_FIELD(name);
2180 static ReindexStmt *
2181 _copyReindexStmt(ReindexStmt *from)
2183 ReindexStmt *newnode = makeNode(ReindexStmt);
2185 COPY_SCALAR_FIELD(reindexType);
2186 COPY_NODE_FIELD(relation);
2187 COPY_STRING_FIELD(name);
2188 COPY_SCALAR_FIELD(force);
2189 COPY_SCALAR_FIELD(all);
2194 static CreateSchemaStmt *
2195 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2197 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2199 COPY_STRING_FIELD(schemaname);
2200 COPY_STRING_FIELD(authid);
2201 COPY_NODE_FIELD(schemaElts);
2206 static CreateConversionStmt *
2207 _copyCreateConversionStmt(CreateConversionStmt *from)
2209 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2211 COPY_NODE_FIELD(conversion_name);
2212 COPY_STRING_FIELD(for_encoding_name);
2213 COPY_STRING_FIELD(to_encoding_name);
2214 COPY_NODE_FIELD(func_name);
2215 COPY_SCALAR_FIELD(def);
2220 static CreateCastStmt *
2221 _copyCreateCastStmt(CreateCastStmt *from)
2223 CreateCastStmt *newnode = makeNode(CreateCastStmt);
2225 COPY_NODE_FIELD(sourcetype);
2226 COPY_NODE_FIELD(targettype);
2227 COPY_NODE_FIELD(func);
2228 COPY_SCALAR_FIELD(context);
2233 static DropCastStmt *
2234 _copyDropCastStmt(DropCastStmt *from)
2236 DropCastStmt *newnode = makeNode(DropCastStmt);
2238 COPY_NODE_FIELD(sourcetype);
2239 COPY_NODE_FIELD(targettype);
2240 COPY_SCALAR_FIELD(behavior);
2245 static PrepareStmt *
2246 _copyPrepareStmt(PrepareStmt *from)
2248 PrepareStmt *newnode = makeNode(PrepareStmt);
2250 COPY_STRING_FIELD(name);
2251 COPY_NODE_FIELD(argtypes);
2252 COPY_INTLIST_FIELD(argtype_oids);
2253 COPY_NODE_FIELD(query);
2258 static ExecuteStmt *
2259 _copyExecuteStmt(ExecuteStmt *from)
2261 ExecuteStmt *newnode = makeNode(ExecuteStmt);
2263 COPY_STRING_FIELD(name);
2264 COPY_NODE_FIELD(into);
2265 COPY_NODE_FIELD(params);
2270 static DeallocateStmt *
2271 _copyDeallocateStmt(DeallocateStmt *from)
2273 DeallocateStmt *newnode = makeNode(DeallocateStmt);
2275 COPY_STRING_FIELD(name);
2281 /* ****************************************************************
2282 * pg_list.h copy functions
2283 * ****************************************************************
2287 _copyValue(Value *from)
2289 Value *newnode = makeNode(Value);
2291 /* See also _copyAConst when changing this code! */
2293 COPY_SCALAR_FIELD(type);
2297 COPY_SCALAR_FIELD(val.ival);
2302 COPY_STRING_FIELD(val.str);
2308 elog(ERROR, "_copyValue: unknown node type %d", from->type);
2317 * Create a copy of a Node tree or list. This is a "deep" copy: all
2318 * substructure is copied too, recursively.
2321 copyObject(void *from)
2328 switch (nodeTag(from))
2334 retval = _copyPlan(from);
2337 retval = _copyResult(from);
2340 retval = _copyAppend(from);
2343 retval = _copyScan(from);
2346 retval = _copySeqScan(from);
2349 retval = _copyIndexScan(from);
2352 retval = _copyTidScan(from);
2354 case T_SubqueryScan:
2355 retval = _copySubqueryScan(from);
2357 case T_FunctionScan:
2358 retval = _copyFunctionScan(from);
2361 retval = _copyJoin(from);
2364 retval = _copyNestLoop(from);
2367 retval = _copyMergeJoin(from);
2370 retval = _copyHashJoin(from);
2373 retval = _copyMaterial(from);
2376 retval = _copySort(from);
2379 retval = _copyGroup(from);
2382 retval = _copyAgg(from);
2385 retval = _copyUnique(from);
2388 retval = _copyHash(from);
2391 retval = _copySetOp(from);
2394 retval = _copyLimit(from);
2401 retval = _copyResdom(from);
2404 retval = _copyAlias(from);
2407 retval = _copyRangeVar(from);
2410 retval = _copyVar(from);
2413 retval = _copyConst(from);
2416 retval = _copyParam(from);
2419 retval = _copyAggref(from);
2422 retval = _copyArrayRef(from);
2425 retval = _copyFuncExpr(from);
2428 retval = _copyOpExpr(from);
2430 case T_DistinctExpr:
2431 retval = _copyDistinctExpr(from);
2434 retval = _copyBoolExpr(from);
2437 retval = _copySubLink(from);
2440 retval = _copySubPlan(from);
2443 retval = _copyFieldSelect(from);
2446 retval = _copyRelabelType(from);
2449 retval = _copyCaseExpr(from);
2452 retval = _copyCaseWhen(from);
2455 retval = _copyNullTest(from);
2458 retval = _copyBooleanTest(from);
2460 case T_ConstraintTest:
2461 retval = _copyConstraintTest(from);
2463 case T_ConstraintTestValue:
2464 retval = _copyConstraintTestValue(from);
2467 retval = _copyTargetEntry(from);
2470 retval = _copyRangeTblRef(from);
2473 retval = _copyJoinExpr(from);
2476 retval = _copyFromExpr(from);
2483 retval = _copyPathKeyItem(from);
2485 case T_RestrictInfo:
2486 retval = _copyRestrictInfo(from);
2489 retval = _copyJoinInfo(from);
2500 retval = _copyValue(from);
2508 /* rather ugly coding for speed... */
2509 /* Note the input list cannot be NIL if we got here. */
2510 nl = makeList1(copyObject(lfirst(list)));
2513 foreach(l, lnext(list))
2515 lnext(nl) = makeList1(copyObject(lfirst(l)));
2525 retval = _copyQuery(from);
2528 retval = _copyInsertStmt(from);
2531 retval = _copyDeleteStmt(from);
2534 retval = _copyUpdateStmt(from);
2537 retval = _copySelectStmt(from);
2539 case T_SetOperationStmt:
2540 retval = _copySetOperationStmt(from);
2542 case T_AlterTableStmt:
2543 retval = _copyAlterTableStmt(from);
2545 case T_AlterDomainStmt:
2546 retval = _copyAlterDomainStmt(from);
2549 retval = _copyGrantStmt(from);
2551 case T_ClosePortalStmt:
2552 retval = _copyClosePortalStmt(from);
2555 retval = _copyClusterStmt(from);
2558 retval = _copyCopyStmt(from);
2561 retval = _copyCreateStmt(from);
2564 retval = _copyDefineStmt(from);
2567 retval = _copyDropStmt(from);
2569 case T_TruncateStmt:
2570 retval = _copyTruncateStmt(from);
2573 retval = _copyCommentStmt(from);
2576 retval = _copyFetchStmt(from);
2579 retval = _copyIndexStmt(from);
2581 case T_CreateFunctionStmt:
2582 retval = _copyCreateFunctionStmt(from);
2584 case T_RemoveAggrStmt:
2585 retval = _copyRemoveAggrStmt(from);
2587 case T_RemoveFuncStmt:
2588 retval = _copyRemoveFuncStmt(from);
2590 case T_RemoveOperStmt:
2591 retval = _copyRemoveOperStmt(from);
2593 case T_RemoveOpClassStmt:
2594 retval = _copyRemoveOpClassStmt(from);
2597 retval = _copyRenameStmt(from);
2600 retval = _copyRuleStmt(from);
2603 retval = _copyNotifyStmt(from);
2606 retval = _copyListenStmt(from);
2608 case T_UnlistenStmt:
2609 retval = _copyUnlistenStmt(from);
2611 case T_TransactionStmt:
2612 retval = _copyTransactionStmt(from);
2614 case T_CompositeTypeStmt:
2615 retval = _copyCompositeTypeStmt(from);
2618 retval = _copyViewStmt(from);
2621 retval = _copyLoadStmt(from);
2623 case T_CreateDomainStmt:
2624 retval = _copyCreateDomainStmt(from);
2626 case T_CreateOpClassStmt:
2627 retval = _copyCreateOpClassStmt(from);
2629 case T_CreateOpClassItem:
2630 retval = _copyCreateOpClassItem(from);
2632 case T_CreatedbStmt:
2633 retval = _copyCreatedbStmt(from);
2635 case T_AlterDatabaseSetStmt:
2636 retval = _copyAlterDatabaseSetStmt(from);
2639 retval = _copyDropdbStmt(from);
2642 retval = _copyVacuumStmt(from);
2645 retval = _copyExplainStmt(from);
2647 case T_CreateSeqStmt:
2648 retval = _copyCreateSeqStmt(from);
2650 case T_VariableSetStmt:
2651 retval = _copyVariableSetStmt(from);
2653 case T_VariableShowStmt:
2654 retval = _copyVariableShowStmt(from);
2656 case T_VariableResetStmt:
2657 retval = _copyVariableResetStmt(from);
2659 case T_CreateTrigStmt:
2660 retval = _copyCreateTrigStmt(from);
2662 case T_DropPropertyStmt:
2663 retval = _copyDropPropertyStmt(from);
2665 case T_CreatePLangStmt:
2666 retval = _copyCreatePLangStmt(from);
2668 case T_DropPLangStmt:
2669 retval = _copyDropPLangStmt(from);
2671 case T_CreateUserStmt:
2672 retval = _copyCreateUserStmt(from);
2674 case T_AlterUserStmt:
2675 retval = _copyAlterUserStmt(from);
2677 case T_AlterUserSetStmt:
2678 retval = _copyAlterUserSetStmt(from);
2680 case T_DropUserStmt:
2681 retval = _copyDropUserStmt(from);
2684 retval = _copyLockStmt(from);
2686 case T_ConstraintsSetStmt:
2687 retval = _copyConstraintsSetStmt(from);
2689 case T_CreateGroupStmt:
2690 retval = _copyCreateGroupStmt(from);
2692 case T_AlterGroupStmt:
2693 retval = _copyAlterGroupStmt(from);
2695 case T_DropGroupStmt:
2696 retval = _copyDropGroupStmt(from);
2699 retval = _copyReindexStmt(from);
2701 case T_CheckPointStmt:
2702 retval = (void *) makeNode(CheckPointStmt);
2704 case T_CreateSchemaStmt:
2705 retval = _copyCreateSchemaStmt(from);
2707 case T_CreateConversionStmt:
2708 retval = _copyCreateConversionStmt(from);
2710 case T_CreateCastStmt:
2711 retval = _copyCreateCastStmt(from);
2713 case T_DropCastStmt:
2714 retval = _copyDropCastStmt(from);
2717 retval = _copyPrepareStmt(from);
2720 retval = _copyExecuteStmt(from);
2722 case T_DeallocateStmt:
2723 retval = _copyDeallocateStmt(from);
2727 retval = _copyAExpr(from);
2730 retval = _copyColumnRef(from);
2733 retval = _copyParamRef(from);
2736 retval = _copyAConst(from);
2739 retval = _copyFuncCall(from);
2742 retval = _copyAIndices(from);
2744 case T_ExprFieldSelect:
2745 retval = _copyExprFieldSelect(from);
2748 retval = _copyResTarget(from);
2751 retval = _copyTypeCast(from);
2754 retval = _copySortGroupBy(from);
2756 case T_RangeSubselect:
2757 retval = _copyRangeSubselect(from);
2759 case T_RangeFunction:
2760 retval = _copyRangeFunction(from);
2763 retval = _copyTypeName(from);
2766 retval = _copyIndexElem(from);
2769 retval = _copyColumnDef(from);
2772 retval = _copyConstraint(from);
2775 retval = _copyDefElem(from);
2777 case T_RangeTblEntry:
2778 retval = _copyRangeTblEntry(from);
2781 retval = _copySortClause(from);
2784 retval = _copyGroupClause(from);
2786 case T_FkConstraint:
2787 retval = _copyFkConstraint(from);
2790 retval = _copyPrivGrantee(from);
2792 case T_FuncWithArgs:
2793 retval = _copyFuncWithArgs(from);
2795 case T_InsertDefault:
2796 retval = _copyInsertDefault(from);
2800 elog(ERROR, "copyObject: don't know how to copy node type %d",
2802 retval = from; /* keep compiler quiet */