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.243 2003/02/10 04:44:44 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 list of Oids */
51 #define COPY_OIDLIST_FIELD(fldname) \
52 (newnode->fldname = listCopy(from->fldname))
54 /* Copy a field that is a pointer to a Bitmapset */
55 #define COPY_BITMAPSET_FIELD(fldname) \
56 (newnode->fldname = bms_copy(from->fldname))
58 /* Copy a field that is a pointer to a C string, or perhaps NULL */
59 #define COPY_STRING_FIELD(fldname) \
60 (newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)
62 /* Copy a field that is a pointer to a simple palloc'd object of size sz */
63 #define COPY_POINTER_FIELD(fldname, sz) \
66 newnode->fldname = palloc(_size); \
67 memcpy(newnode->fldname, from->fldname, _size); \
73 * This copy function only copies the "cons-cells" of the list, not the
74 * pointed-to objects. (Use copyObject if you want a "deep" copy.)
76 * We also use this function for copying lists of integers and Oids,
77 * which is notationally a bit ugly, but perfectly safe.
79 * Note that copyObject will surely coredump if applied to a list
80 * of integers or Oids!
90 /* rather ugly coding for speed... */
94 newcell = makeNode(List);
95 newcell->elem = list->elem;
97 newlist = prev = newcell;
99 foreach(oldl, lnext(list))
101 newcell = makeNode(List);
102 newcell->elem = oldl->elem;
103 prev->next = newcell;
111 /* ****************************************************************
112 * plannodes.h copy functions
113 * ****************************************************************
119 * This function copies the fields of the Plan node. It is used by
120 * all the copy functions for classes which inherit from Plan.
123 CopyPlanFields(Plan *from, Plan *newnode)
125 COPY_SCALAR_FIELD(startup_cost);
126 COPY_SCALAR_FIELD(total_cost);
127 COPY_SCALAR_FIELD(plan_rows);
128 COPY_SCALAR_FIELD(plan_width);
129 COPY_NODE_FIELD(targetlist);
130 COPY_NODE_FIELD(qual);
131 COPY_NODE_FIELD(lefttree);
132 COPY_NODE_FIELD(righttree);
133 COPY_NODE_FIELD(initPlan);
134 COPY_BITMAPSET_FIELD(extParam);
135 COPY_BITMAPSET_FIELD(allParam);
136 COPY_SCALAR_FIELD(nParamExec);
143 _copyPlan(Plan *from)
145 Plan *newnode = makeNode(Plan);
148 * copy node superclass fields
150 CopyPlanFields(from, newnode);
160 _copyResult(Result *from)
162 Result *newnode = makeNode(Result);
165 * copy node superclass fields
167 CopyPlanFields((Plan *) from, (Plan *) newnode);
170 * copy remainder of node
172 COPY_NODE_FIELD(resconstantqual);
181 _copyAppend(Append *from)
183 Append *newnode = makeNode(Append);
186 * copy node superclass fields
188 CopyPlanFields((Plan *) from, (Plan *) newnode);
191 * copy remainder of node
193 COPY_NODE_FIELD(appendplans);
194 COPY_SCALAR_FIELD(isTarget);
203 * This function copies the fields of the Scan node. It is used by
204 * all the copy functions for classes which inherit from Scan.
207 CopyScanFields(Scan *from, Scan *newnode)
209 CopyPlanFields((Plan *) from, (Plan *) newnode);
211 COPY_SCALAR_FIELD(scanrelid);
218 _copyScan(Scan *from)
220 Scan *newnode = makeNode(Scan);
223 * copy node superclass fields
225 CopyScanFields((Scan *) from, (Scan *) newnode);
234 _copySeqScan(SeqScan *from)
236 SeqScan *newnode = makeNode(SeqScan);
239 * copy node superclass fields
241 CopyScanFields((Scan *) from, (Scan *) newnode);
250 _copyIndexScan(IndexScan *from)
252 IndexScan *newnode = makeNode(IndexScan);
255 * copy node superclass fields
257 CopyScanFields((Scan *) from, (Scan *) newnode);
260 * copy remainder of node
262 COPY_OIDLIST_FIELD(indxid);
263 COPY_NODE_FIELD(indxqual);
264 COPY_NODE_FIELD(indxqualorig);
265 COPY_SCALAR_FIELD(indxorderdir);
274 _copyTidScan(TidScan *from)
276 TidScan *newnode = makeNode(TidScan);
279 * copy node superclass fields
281 CopyScanFields((Scan *) from, (Scan *) newnode);
284 * copy remainder of node
286 COPY_NODE_FIELD(tideval);
294 static SubqueryScan *
295 _copySubqueryScan(SubqueryScan *from)
297 SubqueryScan *newnode = makeNode(SubqueryScan);
300 * copy node superclass fields
302 CopyScanFields((Scan *) from, (Scan *) newnode);
305 * copy remainder of node
307 COPY_NODE_FIELD(subplan);
315 static FunctionScan *
316 _copyFunctionScan(FunctionScan *from)
318 FunctionScan *newnode = makeNode(FunctionScan);
321 * copy node superclass fields
323 CopyScanFields((Scan *) from, (Scan *) newnode);
331 * This function copies the fields of the Join node. It is used by
332 * all the copy functions for classes which inherit from Join.
335 CopyJoinFields(Join *from, Join *newnode)
337 CopyPlanFields((Plan *) from, (Plan *) newnode);
339 COPY_SCALAR_FIELD(jointype);
340 COPY_NODE_FIELD(joinqual);
348 _copyJoin(Join *from)
350 Join *newnode = makeNode(Join);
353 * copy node superclass fields
355 CopyJoinFields(from, newnode);
365 _copyNestLoop(NestLoop *from)
367 NestLoop *newnode = makeNode(NestLoop);
370 * copy node superclass fields
372 CopyJoinFields((Join *) from, (Join *) newnode);
382 _copyMergeJoin(MergeJoin *from)
384 MergeJoin *newnode = makeNode(MergeJoin);
387 * copy node superclass fields
389 CopyJoinFields((Join *) from, (Join *) newnode);
392 * copy remainder of node
394 COPY_NODE_FIELD(mergeclauses);
403 _copyHashJoin(HashJoin *from)
405 HashJoin *newnode = makeNode(HashJoin);
408 * copy node superclass fields
410 CopyJoinFields((Join *) from, (Join *) newnode);
413 * copy remainder of node
415 COPY_NODE_FIELD(hashclauses);
425 _copyMaterial(Material *from)
427 Material *newnode = makeNode(Material);
430 * copy node superclass fields
432 CopyPlanFields((Plan *) from, (Plan *) newnode);
442 _copySort(Sort *from)
444 Sort *newnode = makeNode(Sort);
447 * copy node superclass fields
449 CopyPlanFields((Plan *) from, (Plan *) newnode);
451 COPY_SCALAR_FIELD(keycount);
461 _copyGroup(Group *from)
463 Group *newnode = makeNode(Group);
465 CopyPlanFields((Plan *) from, (Plan *) newnode);
467 COPY_SCALAR_FIELD(numCols);
468 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
479 Agg *newnode = makeNode(Agg);
481 CopyPlanFields((Plan *) from, (Plan *) newnode);
483 COPY_SCALAR_FIELD(aggstrategy);
484 COPY_SCALAR_FIELD(numCols);
485 if (from->numCols > 0)
486 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
487 COPY_SCALAR_FIELD(numGroups);
496 _copyUnique(Unique *from)
498 Unique *newnode = makeNode(Unique);
501 * copy node superclass fields
503 CopyPlanFields((Plan *) from, (Plan *) newnode);
506 * copy remainder of node
508 COPY_SCALAR_FIELD(numCols);
509 COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
518 _copyHash(Hash *from)
520 Hash *newnode = makeNode(Hash);
523 * copy node superclass fields
525 CopyPlanFields((Plan *) from, (Plan *) newnode);
528 * copy remainder of node
530 COPY_NODE_FIELD(hashkeys);
539 _copySetOp(SetOp *from)
541 SetOp *newnode = makeNode(SetOp);
544 * copy node superclass fields
546 CopyPlanFields((Plan *) from, (Plan *) newnode);
549 * copy remainder of node
551 COPY_SCALAR_FIELD(cmd);
552 COPY_SCALAR_FIELD(numCols);
553 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
554 COPY_SCALAR_FIELD(flagColIdx);
563 _copyLimit(Limit *from)
565 Limit *newnode = makeNode(Limit);
568 * copy node superclass fields
570 CopyPlanFields((Plan *) from, (Plan *) newnode);
573 * copy remainder of node
575 COPY_NODE_FIELD(limitOffset);
576 COPY_NODE_FIELD(limitCount);
581 /* ****************************************************************
582 * primnodes.h copy functions
583 * ****************************************************************
590 _copyResdom(Resdom *from)
592 Resdom *newnode = makeNode(Resdom);
594 COPY_SCALAR_FIELD(resno);
595 COPY_SCALAR_FIELD(restype);
596 COPY_SCALAR_FIELD(restypmod);
597 COPY_STRING_FIELD(resname);
598 COPY_SCALAR_FIELD(ressortgroupref);
599 COPY_SCALAR_FIELD(reskey);
600 COPY_SCALAR_FIELD(reskeyop);
601 COPY_SCALAR_FIELD(resjunk);
610 _copyAlias(Alias *from)
612 Alias *newnode = makeNode(Alias);
614 COPY_STRING_FIELD(aliasname);
615 COPY_NODE_FIELD(colnames);
624 _copyRangeVar(RangeVar *from)
626 RangeVar *newnode = makeNode(RangeVar);
628 COPY_STRING_FIELD(catalogname);
629 COPY_STRING_FIELD(schemaname);
630 COPY_STRING_FIELD(relname);
631 COPY_SCALAR_FIELD(inhOpt);
632 COPY_SCALAR_FIELD(istemp);
633 COPY_NODE_FIELD(alias);
639 * We don't need a _copyExpr because Expr is an abstract supertype which
640 * should never actually get instantiated. Also, since it has no common
641 * fields except NodeTag, there's no need for a helper routine to factor
642 * out copying the common fields...
651 Var *newnode = makeNode(Var);
653 COPY_SCALAR_FIELD(varno);
654 COPY_SCALAR_FIELD(varattno);
655 COPY_SCALAR_FIELD(vartype);
656 COPY_SCALAR_FIELD(vartypmod);
657 COPY_SCALAR_FIELD(varlevelsup);
658 COPY_SCALAR_FIELD(varnoold);
659 COPY_SCALAR_FIELD(varoattno);
668 _copyConst(Const *from)
670 Const *newnode = makeNode(Const);
672 COPY_SCALAR_FIELD(consttype);
673 COPY_SCALAR_FIELD(constlen);
675 if (from->constbyval || from->constisnull)
678 * passed by value so just copy the datum. Also, don't try to copy
679 * struct when value is null!
681 newnode->constvalue = from->constvalue;
686 * passed by reference. We need a palloc'd copy.
688 newnode->constvalue = datumCopy(from->constvalue,
693 COPY_SCALAR_FIELD(constisnull);
694 COPY_SCALAR_FIELD(constbyval);
703 _copyParam(Param *from)
705 Param *newnode = makeNode(Param);
707 COPY_SCALAR_FIELD(paramkind);
708 COPY_SCALAR_FIELD(paramid);
709 COPY_STRING_FIELD(paramname);
710 COPY_SCALAR_FIELD(paramtype);
719 _copyAggref(Aggref *from)
721 Aggref *newnode = makeNode(Aggref);
723 COPY_SCALAR_FIELD(aggfnoid);
724 COPY_SCALAR_FIELD(aggtype);
725 COPY_NODE_FIELD(target);
726 COPY_SCALAR_FIELD(aggstar);
727 COPY_SCALAR_FIELD(aggdistinct);
736 _copyArrayRef(ArrayRef *from)
738 ArrayRef *newnode = makeNode(ArrayRef);
740 COPY_SCALAR_FIELD(refrestype);
741 COPY_SCALAR_FIELD(refattrlength);
742 COPY_SCALAR_FIELD(refelemlength);
743 COPY_SCALAR_FIELD(refelembyval);
744 COPY_SCALAR_FIELD(refelemalign);
745 COPY_NODE_FIELD(refupperindexpr);
746 COPY_NODE_FIELD(reflowerindexpr);
747 COPY_NODE_FIELD(refexpr);
748 COPY_NODE_FIELD(refassgnexpr);
757 _copyFuncExpr(FuncExpr *from)
759 FuncExpr *newnode = makeNode(FuncExpr);
761 COPY_SCALAR_FIELD(funcid);
762 COPY_SCALAR_FIELD(funcresulttype);
763 COPY_SCALAR_FIELD(funcretset);
764 COPY_SCALAR_FIELD(funcformat);
765 COPY_NODE_FIELD(args);
774 _copyOpExpr(OpExpr *from)
776 OpExpr *newnode = makeNode(OpExpr);
778 COPY_SCALAR_FIELD(opno);
779 COPY_SCALAR_FIELD(opfuncid);
780 COPY_SCALAR_FIELD(opresulttype);
781 COPY_SCALAR_FIELD(opretset);
782 COPY_NODE_FIELD(args);
790 static DistinctExpr *
791 _copyDistinctExpr(DistinctExpr *from)
793 DistinctExpr *newnode = makeNode(DistinctExpr);
795 COPY_SCALAR_FIELD(opno);
796 COPY_SCALAR_FIELD(opfuncid);
797 COPY_SCALAR_FIELD(opresulttype);
798 COPY_SCALAR_FIELD(opretset);
799 COPY_NODE_FIELD(args);
808 _copyBoolExpr(BoolExpr *from)
810 BoolExpr *newnode = makeNode(BoolExpr);
812 COPY_SCALAR_FIELD(boolop);
813 COPY_NODE_FIELD(args);
822 _copySubLink(SubLink *from)
824 SubLink *newnode = makeNode(SubLink);
826 COPY_SCALAR_FIELD(subLinkType);
827 COPY_SCALAR_FIELD(useOr);
828 COPY_NODE_FIELD(lefthand);
829 COPY_NODE_FIELD(operName);
830 COPY_OIDLIST_FIELD(operOids);
831 COPY_NODE_FIELD(subselect);
840 _copySubPlan(SubPlan *from)
842 SubPlan *newnode = makeNode(SubPlan);
844 COPY_SCALAR_FIELD(subLinkType);
845 COPY_SCALAR_FIELD(useOr);
846 COPY_NODE_FIELD(exprs);
847 COPY_INTLIST_FIELD(paramIds);
848 COPY_NODE_FIELD(plan);
849 COPY_SCALAR_FIELD(plan_id);
850 COPY_NODE_FIELD(rtable);
851 COPY_SCALAR_FIELD(useHashTable);
852 COPY_SCALAR_FIELD(unknownEqFalse);
853 COPY_INTLIST_FIELD(setParam);
854 COPY_INTLIST_FIELD(parParam);
855 COPY_NODE_FIELD(args);
864 _copyFieldSelect(FieldSelect *from)
866 FieldSelect *newnode = makeNode(FieldSelect);
868 COPY_NODE_FIELD(arg);
869 COPY_SCALAR_FIELD(fieldnum);
870 COPY_SCALAR_FIELD(resulttype);
871 COPY_SCALAR_FIELD(resulttypmod);
880 _copyRelabelType(RelabelType *from)
882 RelabelType *newnode = makeNode(RelabelType);
884 COPY_NODE_FIELD(arg);
885 COPY_SCALAR_FIELD(resulttype);
886 COPY_SCALAR_FIELD(resulttypmod);
887 COPY_SCALAR_FIELD(relabelformat);
896 _copyCaseExpr(CaseExpr *from)
898 CaseExpr *newnode = makeNode(CaseExpr);
900 COPY_SCALAR_FIELD(casetype);
901 COPY_NODE_FIELD(arg);
902 COPY_NODE_FIELD(args);
903 COPY_NODE_FIELD(defresult);
912 _copyCaseWhen(CaseWhen *from)
914 CaseWhen *newnode = makeNode(CaseWhen);
916 COPY_NODE_FIELD(expr);
917 COPY_NODE_FIELD(result);
926 _copyNullTest(NullTest *from)
928 NullTest *newnode = makeNode(NullTest);
930 COPY_NODE_FIELD(arg);
931 COPY_SCALAR_FIELD(nulltesttype);
940 _copyBooleanTest(BooleanTest *from)
942 BooleanTest *newnode = makeNode(BooleanTest);
944 COPY_NODE_FIELD(arg);
945 COPY_SCALAR_FIELD(booltesttype);
951 * _copyCoerceToDomain
953 static CoerceToDomain *
954 _copyCoerceToDomain(CoerceToDomain *from)
956 CoerceToDomain *newnode = makeNode(CoerceToDomain);
958 COPY_NODE_FIELD(arg);
959 COPY_SCALAR_FIELD(resulttype);
960 COPY_SCALAR_FIELD(resulttypmod);
961 COPY_SCALAR_FIELD(coercionformat);
967 * _copyCoerceToDomainValue
969 static CoerceToDomainValue *
970 _copyCoerceToDomainValue(CoerceToDomainValue *from)
972 CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
974 COPY_SCALAR_FIELD(typeId);
975 COPY_SCALAR_FIELD(typeMod);
984 _copyTargetEntry(TargetEntry *from)
986 TargetEntry *newnode = makeNode(TargetEntry);
988 COPY_NODE_FIELD(resdom);
989 COPY_NODE_FIELD(expr);
998 _copyRangeTblRef(RangeTblRef *from)
1000 RangeTblRef *newnode = makeNode(RangeTblRef);
1002 COPY_SCALAR_FIELD(rtindex);
1011 _copyJoinExpr(JoinExpr *from)
1013 JoinExpr *newnode = makeNode(JoinExpr);
1015 COPY_SCALAR_FIELD(jointype);
1016 COPY_SCALAR_FIELD(isNatural);
1017 COPY_NODE_FIELD(larg);
1018 COPY_NODE_FIELD(rarg);
1019 COPY_NODE_FIELD(using);
1020 COPY_NODE_FIELD(quals);
1021 COPY_NODE_FIELD(alias);
1022 COPY_SCALAR_FIELD(rtindex);
1031 _copyFromExpr(FromExpr *from)
1033 FromExpr *newnode = makeNode(FromExpr);
1035 COPY_NODE_FIELD(fromlist);
1036 COPY_NODE_FIELD(quals);
1041 /* ****************************************************************
1042 * relation.h copy functions
1044 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1045 * There are some subsidiary structs that are useful to copy, though.
1046 * ****************************************************************
1052 static PathKeyItem *
1053 _copyPathKeyItem(PathKeyItem *from)
1055 PathKeyItem *newnode = makeNode(PathKeyItem);
1057 COPY_NODE_FIELD(key);
1058 COPY_SCALAR_FIELD(sortop);
1066 static RestrictInfo *
1067 _copyRestrictInfo(RestrictInfo *from)
1069 RestrictInfo *newnode = makeNode(RestrictInfo);
1071 COPY_NODE_FIELD(clause);
1072 COPY_SCALAR_FIELD(ispusheddown);
1073 COPY_NODE_FIELD(subclauseindices); /* XXX probably bad */
1074 COPY_SCALAR_FIELD(eval_cost);
1075 COPY_SCALAR_FIELD(this_selec);
1076 COPY_BITMAPSET_FIELD(left_relids);
1077 COPY_BITMAPSET_FIELD(right_relids);
1078 COPY_SCALAR_FIELD(mergejoinoperator);
1079 COPY_SCALAR_FIELD(left_sortop);
1080 COPY_SCALAR_FIELD(right_sortop);
1083 * Do not copy pathkeys, since they'd not be canonical in a copied
1086 newnode->left_pathkey = NIL;
1087 newnode->right_pathkey = NIL;
1089 COPY_SCALAR_FIELD(left_mergescansel);
1090 COPY_SCALAR_FIELD(right_mergescansel);
1091 COPY_SCALAR_FIELD(hashjoinoperator);
1092 COPY_SCALAR_FIELD(left_bucketsize);
1093 COPY_SCALAR_FIELD(right_bucketsize);
1102 _copyJoinInfo(JoinInfo *from)
1104 JoinInfo *newnode = makeNode(JoinInfo);
1106 COPY_BITMAPSET_FIELD(unjoined_relids);
1107 COPY_NODE_FIELD(jinfo_restrictinfo);
1115 static InClauseInfo *
1116 _copyInClauseInfo(InClauseInfo *from)
1118 InClauseInfo *newnode = makeNode(InClauseInfo);
1120 COPY_BITMAPSET_FIELD(lefthand);
1121 COPY_BITMAPSET_FIELD(righthand);
1122 COPY_NODE_FIELD(sub_targetlist);
1127 /* ****************************************************************
1128 * parsenodes.h copy functions
1129 * ****************************************************************
1132 static RangeTblEntry *
1133 _copyRangeTblEntry(RangeTblEntry *from)
1135 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1137 COPY_SCALAR_FIELD(rtekind);
1138 COPY_SCALAR_FIELD(relid);
1139 COPY_NODE_FIELD(subquery);
1140 COPY_NODE_FIELD(funcexpr);
1141 COPY_NODE_FIELD(coldeflist);
1142 COPY_SCALAR_FIELD(jointype);
1143 COPY_NODE_FIELD(joinaliasvars);
1144 COPY_NODE_FIELD(alias);
1145 COPY_NODE_FIELD(eref);
1146 COPY_SCALAR_FIELD(inh);
1147 COPY_SCALAR_FIELD(inFromCl);
1148 COPY_SCALAR_FIELD(checkForRead);
1149 COPY_SCALAR_FIELD(checkForWrite);
1150 COPY_SCALAR_FIELD(checkAsUser);
1155 static FkConstraint *
1156 _copyFkConstraint(FkConstraint *from)
1158 FkConstraint *newnode = makeNode(FkConstraint);
1160 COPY_STRING_FIELD(constr_name);
1161 COPY_NODE_FIELD(pktable);
1162 COPY_NODE_FIELD(fk_attrs);
1163 COPY_NODE_FIELD(pk_attrs);
1164 COPY_SCALAR_FIELD(fk_matchtype);
1165 COPY_SCALAR_FIELD(fk_upd_action);
1166 COPY_SCALAR_FIELD(fk_del_action);
1167 COPY_SCALAR_FIELD(deferrable);
1168 COPY_SCALAR_FIELD(initdeferred);
1169 COPY_SCALAR_FIELD(skip_validation);
1175 _copySortClause(SortClause *from)
1177 SortClause *newnode = makeNode(SortClause);
1179 COPY_SCALAR_FIELD(tleSortGroupRef);
1180 COPY_SCALAR_FIELD(sortop);
1185 static GroupClause *
1186 _copyGroupClause(GroupClause *from)
1188 GroupClause *newnode = makeNode(GroupClause);
1190 COPY_SCALAR_FIELD(tleSortGroupRef);
1191 COPY_SCALAR_FIELD(sortop);
1197 _copyAExpr(A_Expr *from)
1199 A_Expr *newnode = makeNode(A_Expr);
1201 COPY_SCALAR_FIELD(kind);
1202 COPY_NODE_FIELD(name);
1203 COPY_NODE_FIELD(lexpr);
1204 COPY_NODE_FIELD(rexpr);
1210 _copyColumnRef(ColumnRef *from)
1212 ColumnRef *newnode = makeNode(ColumnRef);
1214 COPY_NODE_FIELD(fields);
1215 COPY_NODE_FIELD(indirection);
1221 _copyParamRef(ParamRef *from)
1223 ParamRef *newnode = makeNode(ParamRef);
1225 COPY_SCALAR_FIELD(number);
1226 COPY_NODE_FIELD(fields);
1227 COPY_NODE_FIELD(indirection);
1233 _copyAConst(A_Const *from)
1235 A_Const *newnode = makeNode(A_Const);
1237 /* This part must duplicate _copyValue */
1238 COPY_SCALAR_FIELD(val.type);
1239 switch (from->val.type)
1242 COPY_SCALAR_FIELD(val.val.ival);
1247 COPY_STRING_FIELD(val.val.str);
1253 elog(ERROR, "_copyAConst: unknown node type %d", from->val.type);
1257 COPY_NODE_FIELD(typename);
1263 _copyFuncCall(FuncCall *from)
1265 FuncCall *newnode = makeNode(FuncCall);
1267 COPY_NODE_FIELD(funcname);
1268 COPY_NODE_FIELD(args);
1269 COPY_SCALAR_FIELD(agg_star);
1270 COPY_SCALAR_FIELD(agg_distinct);
1276 _copyAIndices(A_Indices *from)
1278 A_Indices *newnode = makeNode(A_Indices);
1280 COPY_NODE_FIELD(lidx);
1281 COPY_NODE_FIELD(uidx);
1286 static ExprFieldSelect *
1287 _copyExprFieldSelect(ExprFieldSelect *from)
1289 ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
1291 COPY_NODE_FIELD(arg);
1292 COPY_NODE_FIELD(fields);
1293 COPY_NODE_FIELD(indirection);
1299 _copyResTarget(ResTarget *from)
1301 ResTarget *newnode = makeNode(ResTarget);
1303 COPY_STRING_FIELD(name);
1304 COPY_NODE_FIELD(indirection);
1305 COPY_NODE_FIELD(val);
1311 _copyTypeName(TypeName *from)
1313 TypeName *newnode = makeNode(TypeName);
1315 COPY_NODE_FIELD(names);
1316 COPY_SCALAR_FIELD(typeid);
1317 COPY_SCALAR_FIELD(timezone);
1318 COPY_SCALAR_FIELD(setof);
1319 COPY_SCALAR_FIELD(pct_type);
1320 COPY_SCALAR_FIELD(typmod);
1321 COPY_NODE_FIELD(arrayBounds);
1326 static SortGroupBy *
1327 _copySortGroupBy(SortGroupBy *from)
1329 SortGroupBy *newnode = makeNode(SortGroupBy);
1331 COPY_NODE_FIELD(useOp);
1332 COPY_NODE_FIELD(node);
1337 static RangeSubselect *
1338 _copyRangeSubselect(RangeSubselect *from)
1340 RangeSubselect *newnode = makeNode(RangeSubselect);
1342 COPY_NODE_FIELD(subquery);
1343 COPY_NODE_FIELD(alias);
1348 static RangeFunction *
1349 _copyRangeFunction(RangeFunction *from)
1351 RangeFunction *newnode = makeNode(RangeFunction);
1353 COPY_NODE_FIELD(funccallnode);
1354 COPY_NODE_FIELD(alias);
1355 COPY_NODE_FIELD(coldeflist);
1361 _copyTypeCast(TypeCast *from)
1363 TypeCast *newnode = makeNode(TypeCast);
1365 COPY_NODE_FIELD(arg);
1366 COPY_NODE_FIELD(typename);
1372 _copyIndexElem(IndexElem *from)
1374 IndexElem *newnode = makeNode(IndexElem);
1376 COPY_STRING_FIELD(name);
1377 COPY_NODE_FIELD(funcname);
1378 COPY_NODE_FIELD(args);
1379 COPY_NODE_FIELD(opclass);
1385 _copyColumnDef(ColumnDef *from)
1387 ColumnDef *newnode = makeNode(ColumnDef);
1389 COPY_STRING_FIELD(colname);
1390 COPY_NODE_FIELD(typename);
1391 COPY_SCALAR_FIELD(inhcount);
1392 COPY_SCALAR_FIELD(is_local);
1393 COPY_SCALAR_FIELD(is_not_null);
1394 COPY_NODE_FIELD(raw_default);
1395 COPY_STRING_FIELD(cooked_default);
1396 COPY_NODE_FIELD(constraints);
1397 COPY_NODE_FIELD(support);
1403 _copyConstraint(Constraint *from)
1405 Constraint *newnode = makeNode(Constraint);
1407 COPY_SCALAR_FIELD(contype);
1408 COPY_STRING_FIELD(name);
1409 COPY_NODE_FIELD(raw_expr);
1410 COPY_STRING_FIELD(cooked_expr);
1411 COPY_NODE_FIELD(keys);
1417 _copyDefElem(DefElem *from)
1419 DefElem *newnode = makeNode(DefElem);
1421 COPY_STRING_FIELD(defname);
1422 COPY_NODE_FIELD(arg);
1428 _copyQuery(Query *from)
1430 Query *newnode = makeNode(Query);
1432 COPY_SCALAR_FIELD(commandType);
1433 COPY_SCALAR_FIELD(querySource);
1434 COPY_NODE_FIELD(utilityStmt);
1435 COPY_SCALAR_FIELD(resultRelation);
1436 COPY_NODE_FIELD(into);
1437 COPY_SCALAR_FIELD(isPortal);
1438 COPY_SCALAR_FIELD(isBinary);
1439 COPY_SCALAR_FIELD(hasAggs);
1440 COPY_SCALAR_FIELD(hasSubLinks);
1441 COPY_NODE_FIELD(rtable);
1442 COPY_NODE_FIELD(jointree);
1443 COPY_INTLIST_FIELD(rowMarks);
1444 COPY_NODE_FIELD(targetList);
1445 COPY_NODE_FIELD(groupClause);
1446 COPY_NODE_FIELD(havingQual);
1447 COPY_NODE_FIELD(distinctClause);
1448 COPY_NODE_FIELD(sortClause);
1449 COPY_NODE_FIELD(limitOffset);
1450 COPY_NODE_FIELD(limitCount);
1451 COPY_NODE_FIELD(setOperations);
1452 COPY_INTLIST_FIELD(resultRelations);
1455 * We do not copy the planner internal fields: base_rel_list,
1456 * other_rel_list, join_rel_list, equi_key_list, in_info_list,
1457 * query_pathkeys, hasJoinRTEs. That would get us into copying
1458 * RelOptInfo/Path trees, which we don't want to do.
1465 _copyInsertStmt(InsertStmt *from)
1467 InsertStmt *newnode = makeNode(InsertStmt);
1469 COPY_NODE_FIELD(relation);
1470 COPY_NODE_FIELD(cols);
1471 COPY_NODE_FIELD(targetList);
1472 COPY_NODE_FIELD(selectStmt);
1478 _copyDeleteStmt(DeleteStmt *from)
1480 DeleteStmt *newnode = makeNode(DeleteStmt);
1482 COPY_NODE_FIELD(relation);
1483 COPY_NODE_FIELD(whereClause);
1489 _copyUpdateStmt(UpdateStmt *from)
1491 UpdateStmt *newnode = makeNode(UpdateStmt);
1493 COPY_NODE_FIELD(relation);
1494 COPY_NODE_FIELD(targetList);
1495 COPY_NODE_FIELD(whereClause);
1496 COPY_NODE_FIELD(fromClause);
1502 _copySelectStmt(SelectStmt *from)
1504 SelectStmt *newnode = makeNode(SelectStmt);
1506 COPY_NODE_FIELD(distinctClause);
1507 COPY_NODE_FIELD(into);
1508 COPY_NODE_FIELD(intoColNames);
1509 COPY_NODE_FIELD(targetList);
1510 COPY_NODE_FIELD(fromClause);
1511 COPY_NODE_FIELD(whereClause);
1512 COPY_NODE_FIELD(groupClause);
1513 COPY_NODE_FIELD(havingClause);
1514 COPY_NODE_FIELD(sortClause);
1515 COPY_STRING_FIELD(portalname);
1516 COPY_SCALAR_FIELD(binary);
1517 COPY_NODE_FIELD(limitOffset);
1518 COPY_NODE_FIELD(limitCount);
1519 COPY_NODE_FIELD(forUpdate);
1520 COPY_SCALAR_FIELD(op);
1521 COPY_SCALAR_FIELD(all);
1522 COPY_NODE_FIELD(larg);
1523 COPY_NODE_FIELD(rarg);
1528 static SetOperationStmt *
1529 _copySetOperationStmt(SetOperationStmt *from)
1531 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1533 COPY_SCALAR_FIELD(op);
1534 COPY_SCALAR_FIELD(all);
1535 COPY_NODE_FIELD(larg);
1536 COPY_NODE_FIELD(rarg);
1537 COPY_OIDLIST_FIELD(colTypes);
1542 static AlterTableStmt *
1543 _copyAlterTableStmt(AlterTableStmt *from)
1545 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1547 COPY_SCALAR_FIELD(subtype);
1548 COPY_NODE_FIELD(relation);
1549 COPY_STRING_FIELD(name);
1550 COPY_NODE_FIELD(def);
1551 COPY_SCALAR_FIELD(behavior);
1556 static AlterDomainStmt *
1557 _copyAlterDomainStmt(AlterDomainStmt *from)
1559 AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1561 COPY_SCALAR_FIELD(subtype);
1562 COPY_NODE_FIELD(typename);
1563 COPY_STRING_FIELD(name);
1564 COPY_NODE_FIELD(def);
1565 COPY_SCALAR_FIELD(behavior);
1571 _copyGrantStmt(GrantStmt *from)
1573 GrantStmt *newnode = makeNode(GrantStmt);
1575 COPY_SCALAR_FIELD(is_grant);
1576 COPY_SCALAR_FIELD(objtype);
1577 COPY_NODE_FIELD(objects);
1578 COPY_INTLIST_FIELD(privileges);
1579 COPY_NODE_FIELD(grantees);
1580 COPY_SCALAR_FIELD(grant_option);
1581 COPY_SCALAR_FIELD(behavior);
1586 static PrivGrantee *
1587 _copyPrivGrantee(PrivGrantee *from)
1589 PrivGrantee *newnode = makeNode(PrivGrantee);
1591 COPY_STRING_FIELD(username);
1592 COPY_STRING_FIELD(groupname);
1597 static FuncWithArgs *
1598 _copyFuncWithArgs(FuncWithArgs *from)
1600 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1602 COPY_NODE_FIELD(funcname);
1603 COPY_NODE_FIELD(funcargs);
1608 static InsertDefault *
1609 _copyInsertDefault(InsertDefault *from)
1611 InsertDefault *newnode = makeNode(InsertDefault);
1617 static ClosePortalStmt *
1618 _copyClosePortalStmt(ClosePortalStmt *from)
1620 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1622 COPY_STRING_FIELD(portalname);
1627 static ClusterStmt *
1628 _copyClusterStmt(ClusterStmt *from)
1630 ClusterStmt *newnode = makeNode(ClusterStmt);
1632 COPY_NODE_FIELD(relation);
1633 COPY_STRING_FIELD(indexname);
1639 _copyCopyStmt(CopyStmt *from)
1641 CopyStmt *newnode = makeNode(CopyStmt);
1643 COPY_NODE_FIELD(relation);
1644 COPY_NODE_FIELD(attlist);
1645 COPY_SCALAR_FIELD(is_from);
1646 COPY_STRING_FIELD(filename);
1647 COPY_NODE_FIELD(options);
1653 _copyCreateStmt(CreateStmt *from)
1655 CreateStmt *newnode = makeNode(CreateStmt);
1657 COPY_NODE_FIELD(relation);
1658 COPY_NODE_FIELD(tableElts);
1659 COPY_NODE_FIELD(inhRelations);
1660 COPY_NODE_FIELD(constraints);
1661 COPY_SCALAR_FIELD(hasoids);
1662 COPY_SCALAR_FIELD(oncommit);
1668 _copyDefineStmt(DefineStmt *from)
1670 DefineStmt *newnode = makeNode(DefineStmt);
1672 COPY_SCALAR_FIELD(kind);
1673 COPY_NODE_FIELD(defnames);
1674 COPY_NODE_FIELD(definition);
1680 _copyDropStmt(DropStmt *from)
1682 DropStmt *newnode = makeNode(DropStmt);
1684 COPY_NODE_FIELD(objects);
1685 COPY_SCALAR_FIELD(removeType);
1686 COPY_SCALAR_FIELD(behavior);
1691 static TruncateStmt *
1692 _copyTruncateStmt(TruncateStmt *from)
1694 TruncateStmt *newnode = makeNode(TruncateStmt);
1696 COPY_NODE_FIELD(relation);
1701 static CommentStmt *
1702 _copyCommentStmt(CommentStmt *from)
1704 CommentStmt *newnode = makeNode(CommentStmt);
1706 COPY_SCALAR_FIELD(objtype);
1707 COPY_NODE_FIELD(objname);
1708 COPY_NODE_FIELD(objargs);
1709 COPY_STRING_FIELD(comment);
1715 _copyFetchStmt(FetchStmt *from)
1717 FetchStmt *newnode = makeNode(FetchStmt);
1719 COPY_SCALAR_FIELD(direction);
1720 COPY_SCALAR_FIELD(howMany);
1721 COPY_STRING_FIELD(portalname);
1722 COPY_SCALAR_FIELD(ismove);
1728 _copyIndexStmt(IndexStmt *from)
1730 IndexStmt *newnode = makeNode(IndexStmt);
1732 COPY_STRING_FIELD(idxname);
1733 COPY_NODE_FIELD(relation);
1734 COPY_STRING_FIELD(accessMethod);
1735 COPY_NODE_FIELD(indexParams);
1736 COPY_NODE_FIELD(whereClause);
1737 COPY_NODE_FIELD(rangetable);
1738 COPY_SCALAR_FIELD(unique);
1739 COPY_SCALAR_FIELD(primary);
1740 COPY_SCALAR_FIELD(isconstraint);
1745 static CreateFunctionStmt *
1746 _copyCreateFunctionStmt(CreateFunctionStmt *from)
1748 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
1750 COPY_SCALAR_FIELD(replace);
1751 COPY_NODE_FIELD(funcname);
1752 COPY_NODE_FIELD(argTypes);
1753 COPY_NODE_FIELD(returnType);
1754 COPY_NODE_FIELD(options);
1755 COPY_NODE_FIELD(withClause);
1760 static RemoveAggrStmt *
1761 _copyRemoveAggrStmt(RemoveAggrStmt *from)
1763 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1765 COPY_NODE_FIELD(aggname);
1766 COPY_NODE_FIELD(aggtype);
1767 COPY_SCALAR_FIELD(behavior);
1772 static RemoveFuncStmt *
1773 _copyRemoveFuncStmt(RemoveFuncStmt *from)
1775 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
1777 COPY_NODE_FIELD(funcname);
1778 COPY_NODE_FIELD(args);
1779 COPY_SCALAR_FIELD(behavior);
1784 static RemoveOperStmt *
1785 _copyRemoveOperStmt(RemoveOperStmt *from)
1787 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
1789 COPY_NODE_FIELD(opname);
1790 COPY_NODE_FIELD(args);
1791 COPY_SCALAR_FIELD(behavior);
1796 static RemoveOpClassStmt *
1797 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
1799 RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
1801 COPY_NODE_FIELD(opclassname);
1802 COPY_STRING_FIELD(amname);
1803 COPY_SCALAR_FIELD(behavior);
1809 _copyRenameStmt(RenameStmt *from)
1811 RenameStmt *newnode = makeNode(RenameStmt);
1813 COPY_NODE_FIELD(relation);
1814 COPY_STRING_FIELD(oldname);
1815 COPY_STRING_FIELD(newname);
1816 COPY_SCALAR_FIELD(renameType);
1822 _copyRuleStmt(RuleStmt *from)
1824 RuleStmt *newnode = makeNode(RuleStmt);
1826 COPY_NODE_FIELD(relation);
1827 COPY_STRING_FIELD(rulename);
1828 COPY_NODE_FIELD(whereClause);
1829 COPY_SCALAR_FIELD(event);
1830 COPY_SCALAR_FIELD(instead);
1831 COPY_NODE_FIELD(actions);
1832 COPY_SCALAR_FIELD(replace);
1838 _copyNotifyStmt(NotifyStmt *from)
1840 NotifyStmt *newnode = makeNode(NotifyStmt);
1842 COPY_NODE_FIELD(relation);
1848 _copyListenStmt(ListenStmt *from)
1850 ListenStmt *newnode = makeNode(ListenStmt);
1852 COPY_NODE_FIELD(relation);
1857 static UnlistenStmt *
1858 _copyUnlistenStmt(UnlistenStmt *from)
1860 UnlistenStmt *newnode = makeNode(UnlistenStmt);
1862 COPY_NODE_FIELD(relation);
1867 static TransactionStmt *
1868 _copyTransactionStmt(TransactionStmt *from)
1870 TransactionStmt *newnode = makeNode(TransactionStmt);
1872 COPY_SCALAR_FIELD(kind);
1873 COPY_NODE_FIELD(options);
1878 static CompositeTypeStmt *
1879 _copyCompositeTypeStmt(CompositeTypeStmt *from)
1881 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
1883 COPY_NODE_FIELD(typevar);
1884 COPY_NODE_FIELD(coldeflist);
1890 _copyViewStmt(ViewStmt *from)
1892 ViewStmt *newnode = makeNode(ViewStmt);
1894 COPY_NODE_FIELD(view);
1895 COPY_NODE_FIELD(aliases);
1896 COPY_NODE_FIELD(query);
1897 COPY_SCALAR_FIELD(replace);
1903 _copyLoadStmt(LoadStmt *from)
1905 LoadStmt *newnode = makeNode(LoadStmt);
1907 COPY_STRING_FIELD(filename);
1912 static CreateDomainStmt *
1913 _copyCreateDomainStmt(CreateDomainStmt *from)
1915 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
1917 COPY_NODE_FIELD(domainname);
1918 COPY_NODE_FIELD(typename);
1919 COPY_NODE_FIELD(constraints);
1924 static CreateOpClassStmt *
1925 _copyCreateOpClassStmt(CreateOpClassStmt *from)
1927 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
1929 COPY_NODE_FIELD(opclassname);
1930 COPY_STRING_FIELD(amname);
1931 COPY_NODE_FIELD(datatype);
1932 COPY_NODE_FIELD(items);
1933 COPY_SCALAR_FIELD(isDefault);
1938 static CreateOpClassItem *
1939 _copyCreateOpClassItem(CreateOpClassItem *from)
1941 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
1943 COPY_SCALAR_FIELD(itemtype);
1944 COPY_NODE_FIELD(name);
1945 COPY_NODE_FIELD(args);
1946 COPY_SCALAR_FIELD(number);
1947 COPY_SCALAR_FIELD(recheck);
1948 COPY_NODE_FIELD(storedtype);
1953 static CreatedbStmt *
1954 _copyCreatedbStmt(CreatedbStmt *from)
1956 CreatedbStmt *newnode = makeNode(CreatedbStmt);
1958 COPY_STRING_FIELD(dbname);
1959 COPY_NODE_FIELD(options);
1964 static AlterDatabaseSetStmt *
1965 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
1967 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
1969 COPY_STRING_FIELD(dbname);
1970 COPY_STRING_FIELD(variable);
1971 COPY_NODE_FIELD(value);
1977 _copyDropdbStmt(DropdbStmt *from)
1979 DropdbStmt *newnode = makeNode(DropdbStmt);
1981 COPY_STRING_FIELD(dbname);
1987 _copyVacuumStmt(VacuumStmt *from)
1989 VacuumStmt *newnode = makeNode(VacuumStmt);
1991 COPY_SCALAR_FIELD(vacuum);
1992 COPY_SCALAR_FIELD(full);
1993 COPY_SCALAR_FIELD(analyze);
1994 COPY_SCALAR_FIELD(freeze);
1995 COPY_SCALAR_FIELD(verbose);
1996 COPY_NODE_FIELD(relation);
1997 COPY_NODE_FIELD(va_cols);
2002 static ExplainStmt *
2003 _copyExplainStmt(ExplainStmt *from)
2005 ExplainStmt *newnode = makeNode(ExplainStmt);
2007 COPY_NODE_FIELD(query);
2008 COPY_SCALAR_FIELD(verbose);
2009 COPY_SCALAR_FIELD(analyze);
2014 static CreateSeqStmt *
2015 _copyCreateSeqStmt(CreateSeqStmt *from)
2017 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2019 COPY_NODE_FIELD(sequence);
2020 COPY_NODE_FIELD(options);
2025 static VariableSetStmt *
2026 _copyVariableSetStmt(VariableSetStmt *from)
2028 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2030 COPY_STRING_FIELD(name);
2031 COPY_NODE_FIELD(args);
2032 COPY_SCALAR_FIELD(is_local);
2037 static VariableShowStmt *
2038 _copyVariableShowStmt(VariableShowStmt *from)
2040 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2042 COPY_STRING_FIELD(name);
2047 static VariableResetStmt *
2048 _copyVariableResetStmt(VariableResetStmt *from)
2050 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2052 COPY_STRING_FIELD(name);
2057 static CreateTrigStmt *
2058 _copyCreateTrigStmt(CreateTrigStmt *from)
2060 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2062 COPY_STRING_FIELD(trigname);
2063 COPY_NODE_FIELD(relation);
2064 COPY_NODE_FIELD(funcname);
2065 COPY_NODE_FIELD(args);
2066 COPY_SCALAR_FIELD(before);
2067 COPY_SCALAR_FIELD(row);
2068 strcpy(newnode->actions, from->actions); /* in-line string field */
2069 COPY_SCALAR_FIELD(isconstraint);
2070 COPY_SCALAR_FIELD(deferrable);
2071 COPY_SCALAR_FIELD(initdeferred);
2072 COPY_NODE_FIELD(constrrel);
2077 static DropPropertyStmt *
2078 _copyDropPropertyStmt(DropPropertyStmt *from)
2080 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2082 COPY_NODE_FIELD(relation);
2083 COPY_STRING_FIELD(property);
2084 COPY_SCALAR_FIELD(removeType);
2085 COPY_SCALAR_FIELD(behavior);
2090 static CreatePLangStmt *
2091 _copyCreatePLangStmt(CreatePLangStmt *from)
2093 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2095 COPY_STRING_FIELD(plname);
2096 COPY_NODE_FIELD(plhandler);
2097 COPY_NODE_FIELD(plvalidator);
2098 COPY_SCALAR_FIELD(pltrusted);
2103 static DropPLangStmt *
2104 _copyDropPLangStmt(DropPLangStmt *from)
2106 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2108 COPY_STRING_FIELD(plname);
2109 COPY_SCALAR_FIELD(behavior);
2114 static CreateUserStmt *
2115 _copyCreateUserStmt(CreateUserStmt *from)
2117 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2119 COPY_STRING_FIELD(user);
2120 COPY_NODE_FIELD(options);
2125 static AlterUserStmt *
2126 _copyAlterUserStmt(AlterUserStmt *from)
2128 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2130 COPY_STRING_FIELD(user);
2131 COPY_NODE_FIELD(options);
2136 static AlterUserSetStmt *
2137 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2139 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2141 COPY_STRING_FIELD(user);
2142 COPY_STRING_FIELD(variable);
2143 COPY_NODE_FIELD(value);
2148 static DropUserStmt *
2149 _copyDropUserStmt(DropUserStmt *from)
2151 DropUserStmt *newnode = makeNode(DropUserStmt);
2153 COPY_NODE_FIELD(users);
2159 _copyLockStmt(LockStmt *from)
2161 LockStmt *newnode = makeNode(LockStmt);
2163 COPY_NODE_FIELD(relations);
2164 COPY_SCALAR_FIELD(mode);
2169 static ConstraintsSetStmt *
2170 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2172 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2174 COPY_NODE_FIELD(constraints);
2175 COPY_SCALAR_FIELD(deferred);
2180 static CreateGroupStmt *
2181 _copyCreateGroupStmt(CreateGroupStmt *from)
2183 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2185 COPY_STRING_FIELD(name);
2186 COPY_NODE_FIELD(options);
2191 static AlterGroupStmt *
2192 _copyAlterGroupStmt(AlterGroupStmt *from)
2194 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2196 COPY_STRING_FIELD(name);
2197 COPY_SCALAR_FIELD(action);
2198 COPY_NODE_FIELD(listUsers);
2203 static DropGroupStmt *
2204 _copyDropGroupStmt(DropGroupStmt *from)
2206 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2208 COPY_STRING_FIELD(name);
2213 static ReindexStmt *
2214 _copyReindexStmt(ReindexStmt *from)
2216 ReindexStmt *newnode = makeNode(ReindexStmt);
2218 COPY_SCALAR_FIELD(kind);
2219 COPY_NODE_FIELD(relation);
2220 COPY_STRING_FIELD(name);
2221 COPY_SCALAR_FIELD(force);
2222 COPY_SCALAR_FIELD(all);
2227 static CreateSchemaStmt *
2228 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2230 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2232 COPY_STRING_FIELD(schemaname);
2233 COPY_STRING_FIELD(authid);
2234 COPY_NODE_FIELD(schemaElts);
2239 static CreateConversionStmt *
2240 _copyCreateConversionStmt(CreateConversionStmt *from)
2242 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2244 COPY_NODE_FIELD(conversion_name);
2245 COPY_STRING_FIELD(for_encoding_name);
2246 COPY_STRING_FIELD(to_encoding_name);
2247 COPY_NODE_FIELD(func_name);
2248 COPY_SCALAR_FIELD(def);
2253 static CreateCastStmt *
2254 _copyCreateCastStmt(CreateCastStmt *from)
2256 CreateCastStmt *newnode = makeNode(CreateCastStmt);
2258 COPY_NODE_FIELD(sourcetype);
2259 COPY_NODE_FIELD(targettype);
2260 COPY_NODE_FIELD(func);
2261 COPY_SCALAR_FIELD(context);
2266 static DropCastStmt *
2267 _copyDropCastStmt(DropCastStmt *from)
2269 DropCastStmt *newnode = makeNode(DropCastStmt);
2271 COPY_NODE_FIELD(sourcetype);
2272 COPY_NODE_FIELD(targettype);
2273 COPY_SCALAR_FIELD(behavior);
2278 static PrepareStmt *
2279 _copyPrepareStmt(PrepareStmt *from)
2281 PrepareStmt *newnode = makeNode(PrepareStmt);
2283 COPY_STRING_FIELD(name);
2284 COPY_NODE_FIELD(argtypes);
2285 COPY_OIDLIST_FIELD(argtype_oids);
2286 COPY_NODE_FIELD(query);
2291 static ExecuteStmt *
2292 _copyExecuteStmt(ExecuteStmt *from)
2294 ExecuteStmt *newnode = makeNode(ExecuteStmt);
2296 COPY_STRING_FIELD(name);
2297 COPY_NODE_FIELD(into);
2298 COPY_NODE_FIELD(params);
2303 static DeallocateStmt *
2304 _copyDeallocateStmt(DeallocateStmt *from)
2306 DeallocateStmt *newnode = makeNode(DeallocateStmt);
2308 COPY_STRING_FIELD(name);
2314 /* ****************************************************************
2315 * pg_list.h copy functions
2316 * ****************************************************************
2320 _copyValue(Value *from)
2322 Value *newnode = makeNode(Value);
2324 /* See also _copyAConst when changing this code! */
2326 COPY_SCALAR_FIELD(type);
2330 COPY_SCALAR_FIELD(val.ival);
2335 COPY_STRING_FIELD(val.str);
2341 elog(ERROR, "_copyValue: unknown node type %d", from->type);
2350 * Create a copy of a Node tree or list. This is a "deep" copy: all
2351 * substructure is copied too, recursively.
2354 copyObject(void *from)
2361 switch (nodeTag(from))
2367 retval = _copyPlan(from);
2370 retval = _copyResult(from);
2373 retval = _copyAppend(from);
2376 retval = _copyScan(from);
2379 retval = _copySeqScan(from);
2382 retval = _copyIndexScan(from);
2385 retval = _copyTidScan(from);
2387 case T_SubqueryScan:
2388 retval = _copySubqueryScan(from);
2390 case T_FunctionScan:
2391 retval = _copyFunctionScan(from);
2394 retval = _copyJoin(from);
2397 retval = _copyNestLoop(from);
2400 retval = _copyMergeJoin(from);
2403 retval = _copyHashJoin(from);
2406 retval = _copyMaterial(from);
2409 retval = _copySort(from);
2412 retval = _copyGroup(from);
2415 retval = _copyAgg(from);
2418 retval = _copyUnique(from);
2421 retval = _copyHash(from);
2424 retval = _copySetOp(from);
2427 retval = _copyLimit(from);
2434 retval = _copyResdom(from);
2437 retval = _copyAlias(from);
2440 retval = _copyRangeVar(from);
2443 retval = _copyVar(from);
2446 retval = _copyConst(from);
2449 retval = _copyParam(from);
2452 retval = _copyAggref(from);
2455 retval = _copyArrayRef(from);
2458 retval = _copyFuncExpr(from);
2461 retval = _copyOpExpr(from);
2463 case T_DistinctExpr:
2464 retval = _copyDistinctExpr(from);
2467 retval = _copyBoolExpr(from);
2470 retval = _copySubLink(from);
2473 retval = _copySubPlan(from);
2476 retval = _copyFieldSelect(from);
2479 retval = _copyRelabelType(from);
2482 retval = _copyCaseExpr(from);
2485 retval = _copyCaseWhen(from);
2488 retval = _copyNullTest(from);
2491 retval = _copyBooleanTest(from);
2493 case T_CoerceToDomain:
2494 retval = _copyCoerceToDomain(from);
2496 case T_CoerceToDomainValue:
2497 retval = _copyCoerceToDomainValue(from);
2500 retval = _copyTargetEntry(from);
2503 retval = _copyRangeTblRef(from);
2506 retval = _copyJoinExpr(from);
2509 retval = _copyFromExpr(from);
2516 retval = _copyPathKeyItem(from);
2518 case T_RestrictInfo:
2519 retval = _copyRestrictInfo(from);
2522 retval = _copyJoinInfo(from);
2524 case T_InClauseInfo:
2525 retval = _copyInClauseInfo(from);
2536 retval = _copyValue(from);
2545 /* rather ugly coding for speed... */
2546 /* Note the input list cannot be NIL if we got here. */
2547 newcell = makeNode(List);
2548 lfirst(newcell) = copyObject(lfirst(list));
2550 retval = (void *) newcell;
2553 foreach(oldl, lnext(list))
2555 newcell = makeNode(List);
2556 lfirst(newcell) = copyObject(lfirst(oldl));
2557 prev->next = newcell;
2568 retval = _copyQuery(from);
2571 retval = _copyInsertStmt(from);
2574 retval = _copyDeleteStmt(from);
2577 retval = _copyUpdateStmt(from);
2580 retval = _copySelectStmt(from);
2582 case T_SetOperationStmt:
2583 retval = _copySetOperationStmt(from);
2585 case T_AlterTableStmt:
2586 retval = _copyAlterTableStmt(from);
2588 case T_AlterDomainStmt:
2589 retval = _copyAlterDomainStmt(from);
2592 retval = _copyGrantStmt(from);
2594 case T_ClosePortalStmt:
2595 retval = _copyClosePortalStmt(from);
2598 retval = _copyClusterStmt(from);
2601 retval = _copyCopyStmt(from);
2604 retval = _copyCreateStmt(from);
2607 retval = _copyDefineStmt(from);
2610 retval = _copyDropStmt(from);
2612 case T_TruncateStmt:
2613 retval = _copyTruncateStmt(from);
2616 retval = _copyCommentStmt(from);
2619 retval = _copyFetchStmt(from);
2622 retval = _copyIndexStmt(from);
2624 case T_CreateFunctionStmt:
2625 retval = _copyCreateFunctionStmt(from);
2627 case T_RemoveAggrStmt:
2628 retval = _copyRemoveAggrStmt(from);
2630 case T_RemoveFuncStmt:
2631 retval = _copyRemoveFuncStmt(from);
2633 case T_RemoveOperStmt:
2634 retval = _copyRemoveOperStmt(from);
2636 case T_RemoveOpClassStmt:
2637 retval = _copyRemoveOpClassStmt(from);
2640 retval = _copyRenameStmt(from);
2643 retval = _copyRuleStmt(from);
2646 retval = _copyNotifyStmt(from);
2649 retval = _copyListenStmt(from);
2651 case T_UnlistenStmt:
2652 retval = _copyUnlistenStmt(from);
2654 case T_TransactionStmt:
2655 retval = _copyTransactionStmt(from);
2657 case T_CompositeTypeStmt:
2658 retval = _copyCompositeTypeStmt(from);
2661 retval = _copyViewStmt(from);
2664 retval = _copyLoadStmt(from);
2666 case T_CreateDomainStmt:
2667 retval = _copyCreateDomainStmt(from);
2669 case T_CreateOpClassStmt:
2670 retval = _copyCreateOpClassStmt(from);
2672 case T_CreateOpClassItem:
2673 retval = _copyCreateOpClassItem(from);
2675 case T_CreatedbStmt:
2676 retval = _copyCreatedbStmt(from);
2678 case T_AlterDatabaseSetStmt:
2679 retval = _copyAlterDatabaseSetStmt(from);
2682 retval = _copyDropdbStmt(from);
2685 retval = _copyVacuumStmt(from);
2688 retval = _copyExplainStmt(from);
2690 case T_CreateSeqStmt:
2691 retval = _copyCreateSeqStmt(from);
2693 case T_VariableSetStmt:
2694 retval = _copyVariableSetStmt(from);
2696 case T_VariableShowStmt:
2697 retval = _copyVariableShowStmt(from);
2699 case T_VariableResetStmt:
2700 retval = _copyVariableResetStmt(from);
2702 case T_CreateTrigStmt:
2703 retval = _copyCreateTrigStmt(from);
2705 case T_DropPropertyStmt:
2706 retval = _copyDropPropertyStmt(from);
2708 case T_CreatePLangStmt:
2709 retval = _copyCreatePLangStmt(from);
2711 case T_DropPLangStmt:
2712 retval = _copyDropPLangStmt(from);
2714 case T_CreateUserStmt:
2715 retval = _copyCreateUserStmt(from);
2717 case T_AlterUserStmt:
2718 retval = _copyAlterUserStmt(from);
2720 case T_AlterUserSetStmt:
2721 retval = _copyAlterUserSetStmt(from);
2723 case T_DropUserStmt:
2724 retval = _copyDropUserStmt(from);
2727 retval = _copyLockStmt(from);
2729 case T_ConstraintsSetStmt:
2730 retval = _copyConstraintsSetStmt(from);
2732 case T_CreateGroupStmt:
2733 retval = _copyCreateGroupStmt(from);
2735 case T_AlterGroupStmt:
2736 retval = _copyAlterGroupStmt(from);
2738 case T_DropGroupStmt:
2739 retval = _copyDropGroupStmt(from);
2742 retval = _copyReindexStmt(from);
2744 case T_CheckPointStmt:
2745 retval = (void *) makeNode(CheckPointStmt);
2747 case T_CreateSchemaStmt:
2748 retval = _copyCreateSchemaStmt(from);
2750 case T_CreateConversionStmt:
2751 retval = _copyCreateConversionStmt(from);
2753 case T_CreateCastStmt:
2754 retval = _copyCreateCastStmt(from);
2756 case T_DropCastStmt:
2757 retval = _copyDropCastStmt(from);
2760 retval = _copyPrepareStmt(from);
2763 retval = _copyExecuteStmt(from);
2765 case T_DeallocateStmt:
2766 retval = _copyDeallocateStmt(from);
2770 retval = _copyAExpr(from);
2773 retval = _copyColumnRef(from);
2776 retval = _copyParamRef(from);
2779 retval = _copyAConst(from);
2782 retval = _copyFuncCall(from);
2785 retval = _copyAIndices(from);
2787 case T_ExprFieldSelect:
2788 retval = _copyExprFieldSelect(from);
2791 retval = _copyResTarget(from);
2794 retval = _copyTypeCast(from);
2797 retval = _copySortGroupBy(from);
2799 case T_RangeSubselect:
2800 retval = _copyRangeSubselect(from);
2802 case T_RangeFunction:
2803 retval = _copyRangeFunction(from);
2806 retval = _copyTypeName(from);
2809 retval = _copyIndexElem(from);
2812 retval = _copyColumnDef(from);
2815 retval = _copyConstraint(from);
2818 retval = _copyDefElem(from);
2820 case T_RangeTblEntry:
2821 retval = _copyRangeTblEntry(from);
2824 retval = _copySortClause(from);
2827 retval = _copyGroupClause(from);
2829 case T_FkConstraint:
2830 retval = _copyFkConstraint(from);
2833 retval = _copyPrivGrantee(from);
2835 case T_FuncWithArgs:
2836 retval = _copyFuncWithArgs(from);
2838 case T_InsertDefault:
2839 retval = _copyInsertDefault(from);
2843 elog(ERROR, "copyObject: don't know how to copy node type %d",
2845 retval = from; /* keep compiler quiet */