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-2003, 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.262 2003/08/04 02:39:59 momjian 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(numCols);
452 COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
453 COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
463 _copyGroup(Group *from)
465 Group *newnode = makeNode(Group);
467 CopyPlanFields((Plan *) from, (Plan *) newnode);
469 COPY_SCALAR_FIELD(numCols);
470 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
481 Agg *newnode = makeNode(Agg);
483 CopyPlanFields((Plan *) from, (Plan *) newnode);
485 COPY_SCALAR_FIELD(aggstrategy);
486 COPY_SCALAR_FIELD(numCols);
487 if (from->numCols > 0)
488 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
489 COPY_SCALAR_FIELD(numGroups);
498 _copyUnique(Unique *from)
500 Unique *newnode = makeNode(Unique);
503 * copy node superclass fields
505 CopyPlanFields((Plan *) from, (Plan *) newnode);
508 * copy remainder of node
510 COPY_SCALAR_FIELD(numCols);
511 COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
520 _copyHash(Hash *from)
522 Hash *newnode = makeNode(Hash);
525 * copy node superclass fields
527 CopyPlanFields((Plan *) from, (Plan *) newnode);
530 * copy remainder of node
532 COPY_NODE_FIELD(hashkeys);
541 _copySetOp(SetOp *from)
543 SetOp *newnode = makeNode(SetOp);
546 * copy node superclass fields
548 CopyPlanFields((Plan *) from, (Plan *) newnode);
551 * copy remainder of node
553 COPY_SCALAR_FIELD(cmd);
554 COPY_SCALAR_FIELD(numCols);
555 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
556 COPY_SCALAR_FIELD(flagColIdx);
565 _copyLimit(Limit *from)
567 Limit *newnode = makeNode(Limit);
570 * copy node superclass fields
572 CopyPlanFields((Plan *) from, (Plan *) newnode);
575 * copy remainder of node
577 COPY_NODE_FIELD(limitOffset);
578 COPY_NODE_FIELD(limitCount);
583 /* ****************************************************************
584 * primnodes.h copy functions
585 * ****************************************************************
592 _copyResdom(Resdom *from)
594 Resdom *newnode = makeNode(Resdom);
596 COPY_SCALAR_FIELD(resno);
597 COPY_SCALAR_FIELD(restype);
598 COPY_SCALAR_FIELD(restypmod);
599 COPY_STRING_FIELD(resname);
600 COPY_SCALAR_FIELD(ressortgroupref);
601 COPY_SCALAR_FIELD(resorigtbl);
602 COPY_SCALAR_FIELD(resorigcol);
603 COPY_SCALAR_FIELD(resjunk);
612 _copyAlias(Alias *from)
614 Alias *newnode = makeNode(Alias);
616 COPY_STRING_FIELD(aliasname);
617 COPY_NODE_FIELD(colnames);
626 _copyRangeVar(RangeVar *from)
628 RangeVar *newnode = makeNode(RangeVar);
630 COPY_STRING_FIELD(catalogname);
631 COPY_STRING_FIELD(schemaname);
632 COPY_STRING_FIELD(relname);
633 COPY_SCALAR_FIELD(inhOpt);
634 COPY_SCALAR_FIELD(istemp);
635 COPY_NODE_FIELD(alias);
641 * We don't need a _copyExpr because Expr is an abstract supertype which
642 * should never actually get instantiated. Also, since it has no common
643 * fields except NodeTag, there's no need for a helper routine to factor
644 * out copying the common fields...
653 Var *newnode = makeNode(Var);
655 COPY_SCALAR_FIELD(varno);
656 COPY_SCALAR_FIELD(varattno);
657 COPY_SCALAR_FIELD(vartype);
658 COPY_SCALAR_FIELD(vartypmod);
659 COPY_SCALAR_FIELD(varlevelsup);
660 COPY_SCALAR_FIELD(varnoold);
661 COPY_SCALAR_FIELD(varoattno);
670 _copyConst(Const *from)
672 Const *newnode = makeNode(Const);
674 COPY_SCALAR_FIELD(consttype);
675 COPY_SCALAR_FIELD(constlen);
677 if (from->constbyval || from->constisnull)
680 * passed by value so just copy the datum. Also, don't try to copy
681 * struct when value is null!
683 newnode->constvalue = from->constvalue;
688 * passed by reference. We need a palloc'd copy.
690 newnode->constvalue = datumCopy(from->constvalue,
695 COPY_SCALAR_FIELD(constisnull);
696 COPY_SCALAR_FIELD(constbyval);
705 _copyParam(Param *from)
707 Param *newnode = makeNode(Param);
709 COPY_SCALAR_FIELD(paramkind);
710 COPY_SCALAR_FIELD(paramid);
711 COPY_STRING_FIELD(paramname);
712 COPY_SCALAR_FIELD(paramtype);
721 _copyAggref(Aggref *from)
723 Aggref *newnode = makeNode(Aggref);
725 COPY_SCALAR_FIELD(aggfnoid);
726 COPY_SCALAR_FIELD(aggtype);
727 COPY_NODE_FIELD(target);
728 COPY_SCALAR_FIELD(agglevelsup);
729 COPY_SCALAR_FIELD(aggstar);
730 COPY_SCALAR_FIELD(aggdistinct);
739 _copyArrayRef(ArrayRef *from)
741 ArrayRef *newnode = makeNode(ArrayRef);
743 COPY_SCALAR_FIELD(refrestype);
744 COPY_SCALAR_FIELD(refarraytype);
745 COPY_SCALAR_FIELD(refelemtype);
746 COPY_NODE_FIELD(refupperindexpr);
747 COPY_NODE_FIELD(reflowerindexpr);
748 COPY_NODE_FIELD(refexpr);
749 COPY_NODE_FIELD(refassgnexpr);
758 _copyFuncExpr(FuncExpr * from)
760 FuncExpr *newnode = makeNode(FuncExpr);
762 COPY_SCALAR_FIELD(funcid);
763 COPY_SCALAR_FIELD(funcresulttype);
764 COPY_SCALAR_FIELD(funcretset);
765 COPY_SCALAR_FIELD(funcformat);
766 COPY_NODE_FIELD(args);
775 _copyOpExpr(OpExpr * from)
777 OpExpr *newnode = makeNode(OpExpr);
779 COPY_SCALAR_FIELD(opno);
780 COPY_SCALAR_FIELD(opfuncid);
781 COPY_SCALAR_FIELD(opresulttype);
782 COPY_SCALAR_FIELD(opretset);
783 COPY_NODE_FIELD(args);
789 * _copyDistinctExpr (same as OpExpr)
791 static DistinctExpr *
792 _copyDistinctExpr(DistinctExpr * from)
794 DistinctExpr *newnode = makeNode(DistinctExpr);
796 COPY_SCALAR_FIELD(opno);
797 COPY_SCALAR_FIELD(opfuncid);
798 COPY_SCALAR_FIELD(opresulttype);
799 COPY_SCALAR_FIELD(opretset);
800 COPY_NODE_FIELD(args);
806 * _copyScalarArrayOpExpr
808 static ScalarArrayOpExpr *
809 _copyScalarArrayOpExpr(ScalarArrayOpExpr * from)
811 ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
813 COPY_SCALAR_FIELD(opno);
814 COPY_SCALAR_FIELD(opfuncid);
815 COPY_SCALAR_FIELD(useOr);
816 COPY_NODE_FIELD(args);
825 _copyBoolExpr(BoolExpr * from)
827 BoolExpr *newnode = makeNode(BoolExpr);
829 COPY_SCALAR_FIELD(boolop);
830 COPY_NODE_FIELD(args);
839 _copySubLink(SubLink *from)
841 SubLink *newnode = makeNode(SubLink);
843 COPY_SCALAR_FIELD(subLinkType);
844 COPY_SCALAR_FIELD(useOr);
845 COPY_NODE_FIELD(lefthand);
846 COPY_NODE_FIELD(operName);
847 COPY_OIDLIST_FIELD(operOids);
848 COPY_NODE_FIELD(subselect);
857 _copySubPlan(SubPlan *from)
859 SubPlan *newnode = makeNode(SubPlan);
861 COPY_SCALAR_FIELD(subLinkType);
862 COPY_SCALAR_FIELD(useOr);
863 COPY_NODE_FIELD(exprs);
864 COPY_INTLIST_FIELD(paramIds);
865 COPY_NODE_FIELD(plan);
866 COPY_SCALAR_FIELD(plan_id);
867 COPY_NODE_FIELD(rtable);
868 COPY_SCALAR_FIELD(useHashTable);
869 COPY_SCALAR_FIELD(unknownEqFalse);
870 COPY_INTLIST_FIELD(setParam);
871 COPY_INTLIST_FIELD(parParam);
872 COPY_NODE_FIELD(args);
881 _copyFieldSelect(FieldSelect *from)
883 FieldSelect *newnode = makeNode(FieldSelect);
885 COPY_NODE_FIELD(arg);
886 COPY_SCALAR_FIELD(fieldnum);
887 COPY_SCALAR_FIELD(resulttype);
888 COPY_SCALAR_FIELD(resulttypmod);
897 _copyRelabelType(RelabelType *from)
899 RelabelType *newnode = makeNode(RelabelType);
901 COPY_NODE_FIELD(arg);
902 COPY_SCALAR_FIELD(resulttype);
903 COPY_SCALAR_FIELD(resulttypmod);
904 COPY_SCALAR_FIELD(relabelformat);
913 _copyCaseExpr(CaseExpr *from)
915 CaseExpr *newnode = makeNode(CaseExpr);
917 COPY_SCALAR_FIELD(casetype);
918 COPY_NODE_FIELD(arg);
919 COPY_NODE_FIELD(args);
920 COPY_NODE_FIELD(defresult);
929 _copyCaseWhen(CaseWhen *from)
931 CaseWhen *newnode = makeNode(CaseWhen);
933 COPY_NODE_FIELD(expr);
934 COPY_NODE_FIELD(result);
943 _copyArrayExpr(ArrayExpr * from)
945 ArrayExpr *newnode = makeNode(ArrayExpr);
947 COPY_SCALAR_FIELD(array_typeid);
948 COPY_SCALAR_FIELD(element_typeid);
949 COPY_NODE_FIELD(elements);
950 COPY_SCALAR_FIELD(ndims);
958 static CoalesceExpr *
959 _copyCoalesceExpr(CoalesceExpr * from)
961 CoalesceExpr *newnode = makeNode(CoalesceExpr);
963 COPY_SCALAR_FIELD(coalescetype);
964 COPY_NODE_FIELD(args);
970 * _copyNullIfExpr (same as OpExpr)
973 _copyNullIfExpr(NullIfExpr * from)
975 NullIfExpr *newnode = makeNode(NullIfExpr);
977 COPY_SCALAR_FIELD(opno);
978 COPY_SCALAR_FIELD(opfuncid);
979 COPY_SCALAR_FIELD(opresulttype);
980 COPY_SCALAR_FIELD(opretset);
981 COPY_NODE_FIELD(args);
990 _copyNullTest(NullTest *from)
992 NullTest *newnode = makeNode(NullTest);
994 COPY_NODE_FIELD(arg);
995 COPY_SCALAR_FIELD(nulltesttype);
1003 static BooleanTest *
1004 _copyBooleanTest(BooleanTest *from)
1006 BooleanTest *newnode = makeNode(BooleanTest);
1008 COPY_NODE_FIELD(arg);
1009 COPY_SCALAR_FIELD(booltesttype);
1015 * _copyCoerceToDomain
1017 static CoerceToDomain *
1018 _copyCoerceToDomain(CoerceToDomain * from)
1020 CoerceToDomain *newnode = makeNode(CoerceToDomain);
1022 COPY_NODE_FIELD(arg);
1023 COPY_SCALAR_FIELD(resulttype);
1024 COPY_SCALAR_FIELD(resulttypmod);
1025 COPY_SCALAR_FIELD(coercionformat);
1031 * _copyCoerceToDomainValue
1033 static CoerceToDomainValue *
1034 _copyCoerceToDomainValue(CoerceToDomainValue * from)
1036 CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1038 COPY_SCALAR_FIELD(typeId);
1039 COPY_SCALAR_FIELD(typeMod);
1047 static SetToDefault *
1048 _copySetToDefault(SetToDefault * from)
1050 SetToDefault *newnode = makeNode(SetToDefault);
1052 COPY_SCALAR_FIELD(typeId);
1053 COPY_SCALAR_FIELD(typeMod);
1061 static TargetEntry *
1062 _copyTargetEntry(TargetEntry *from)
1064 TargetEntry *newnode = makeNode(TargetEntry);
1066 COPY_NODE_FIELD(resdom);
1067 COPY_NODE_FIELD(expr);
1075 static RangeTblRef *
1076 _copyRangeTblRef(RangeTblRef *from)
1078 RangeTblRef *newnode = makeNode(RangeTblRef);
1080 COPY_SCALAR_FIELD(rtindex);
1089 _copyJoinExpr(JoinExpr *from)
1091 JoinExpr *newnode = makeNode(JoinExpr);
1093 COPY_SCALAR_FIELD(jointype);
1094 COPY_SCALAR_FIELD(isNatural);
1095 COPY_NODE_FIELD(larg);
1096 COPY_NODE_FIELD(rarg);
1097 COPY_NODE_FIELD(using);
1098 COPY_NODE_FIELD(quals);
1099 COPY_NODE_FIELD(alias);
1100 COPY_SCALAR_FIELD(rtindex);
1109 _copyFromExpr(FromExpr *from)
1111 FromExpr *newnode = makeNode(FromExpr);
1113 COPY_NODE_FIELD(fromlist);
1114 COPY_NODE_FIELD(quals);
1119 /* ****************************************************************
1120 * relation.h copy functions
1122 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1123 * There are some subsidiary structs that are useful to copy, though.
1124 * ****************************************************************
1130 static PathKeyItem *
1131 _copyPathKeyItem(PathKeyItem *from)
1133 PathKeyItem *newnode = makeNode(PathKeyItem);
1135 COPY_NODE_FIELD(key);
1136 COPY_SCALAR_FIELD(sortop);
1144 static RestrictInfo *
1145 _copyRestrictInfo(RestrictInfo *from)
1147 RestrictInfo *newnode = makeNode(RestrictInfo);
1149 COPY_NODE_FIELD(clause);
1150 COPY_SCALAR_FIELD(ispusheddown);
1151 COPY_NODE_FIELD(subclauseindices); /* XXX probably bad */
1152 COPY_SCALAR_FIELD(eval_cost);
1153 COPY_SCALAR_FIELD(this_selec);
1154 COPY_BITMAPSET_FIELD(left_relids);
1155 COPY_BITMAPSET_FIELD(right_relids);
1156 COPY_SCALAR_FIELD(mergejoinoperator);
1157 COPY_SCALAR_FIELD(left_sortop);
1158 COPY_SCALAR_FIELD(right_sortop);
1161 * Do not copy pathkeys, since they'd not be canonical in a copied
1164 newnode->left_pathkey = NIL;
1165 newnode->right_pathkey = NIL;
1167 COPY_SCALAR_FIELD(left_mergescansel);
1168 COPY_SCALAR_FIELD(right_mergescansel);
1169 COPY_SCALAR_FIELD(hashjoinoperator);
1170 COPY_SCALAR_FIELD(left_bucketsize);
1171 COPY_SCALAR_FIELD(right_bucketsize);
1180 _copyJoinInfo(JoinInfo *from)
1182 JoinInfo *newnode = makeNode(JoinInfo);
1184 COPY_BITMAPSET_FIELD(unjoined_relids);
1185 COPY_NODE_FIELD(jinfo_restrictinfo);
1193 static InClauseInfo *
1194 _copyInClauseInfo(InClauseInfo * from)
1196 InClauseInfo *newnode = makeNode(InClauseInfo);
1198 COPY_BITMAPSET_FIELD(lefthand);
1199 COPY_BITMAPSET_FIELD(righthand);
1200 COPY_NODE_FIELD(sub_targetlist);
1205 /* ****************************************************************
1206 * parsenodes.h copy functions
1207 * ****************************************************************
1210 static RangeTblEntry *
1211 _copyRangeTblEntry(RangeTblEntry *from)
1213 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1215 COPY_SCALAR_FIELD(rtekind);
1216 COPY_SCALAR_FIELD(relid);
1217 COPY_NODE_FIELD(subquery);
1218 COPY_NODE_FIELD(funcexpr);
1219 COPY_NODE_FIELD(coldeflist);
1220 COPY_SCALAR_FIELD(jointype);
1221 COPY_NODE_FIELD(joinaliasvars);
1222 COPY_NODE_FIELD(alias);
1223 COPY_NODE_FIELD(eref);
1224 COPY_SCALAR_FIELD(inh);
1225 COPY_SCALAR_FIELD(inFromCl);
1226 COPY_SCALAR_FIELD(checkForRead);
1227 COPY_SCALAR_FIELD(checkForWrite);
1228 COPY_SCALAR_FIELD(checkAsUser);
1233 static FkConstraint *
1234 _copyFkConstraint(FkConstraint *from)
1236 FkConstraint *newnode = makeNode(FkConstraint);
1238 COPY_STRING_FIELD(constr_name);
1239 COPY_NODE_FIELD(pktable);
1240 COPY_NODE_FIELD(fk_attrs);
1241 COPY_NODE_FIELD(pk_attrs);
1242 COPY_SCALAR_FIELD(fk_matchtype);
1243 COPY_SCALAR_FIELD(fk_upd_action);
1244 COPY_SCALAR_FIELD(fk_del_action);
1245 COPY_SCALAR_FIELD(deferrable);
1246 COPY_SCALAR_FIELD(initdeferred);
1247 COPY_SCALAR_FIELD(skip_validation);
1253 _copySortClause(SortClause *from)
1255 SortClause *newnode = makeNode(SortClause);
1257 COPY_SCALAR_FIELD(tleSortGroupRef);
1258 COPY_SCALAR_FIELD(sortop);
1263 static GroupClause *
1264 _copyGroupClause(GroupClause *from)
1266 GroupClause *newnode = makeNode(GroupClause);
1268 COPY_SCALAR_FIELD(tleSortGroupRef);
1269 COPY_SCALAR_FIELD(sortop);
1275 _copyAExpr(A_Expr *from)
1277 A_Expr *newnode = makeNode(A_Expr);
1279 COPY_SCALAR_FIELD(kind);
1280 COPY_NODE_FIELD(name);
1281 COPY_NODE_FIELD(lexpr);
1282 COPY_NODE_FIELD(rexpr);
1288 _copyColumnRef(ColumnRef *from)
1290 ColumnRef *newnode = makeNode(ColumnRef);
1292 COPY_NODE_FIELD(fields);
1293 COPY_NODE_FIELD(indirection);
1299 _copyParamRef(ParamRef *from)
1301 ParamRef *newnode = makeNode(ParamRef);
1303 COPY_SCALAR_FIELD(number);
1304 COPY_NODE_FIELD(fields);
1305 COPY_NODE_FIELD(indirection);
1311 _copyAConst(A_Const *from)
1313 A_Const *newnode = makeNode(A_Const);
1315 /* This part must duplicate _copyValue */
1316 COPY_SCALAR_FIELD(val.type);
1317 switch (from->val.type)
1320 COPY_SCALAR_FIELD(val.val.ival);
1325 COPY_STRING_FIELD(val.val.str);
1331 elog(ERROR, "unrecognized node type: %d",
1332 (int) from->val.type);
1336 COPY_NODE_FIELD(typename);
1342 _copyFuncCall(FuncCall *from)
1344 FuncCall *newnode = makeNode(FuncCall);
1346 COPY_NODE_FIELD(funcname);
1347 COPY_NODE_FIELD(args);
1348 COPY_SCALAR_FIELD(agg_star);
1349 COPY_SCALAR_FIELD(agg_distinct);
1355 _copyAIndices(A_Indices *from)
1357 A_Indices *newnode = makeNode(A_Indices);
1359 COPY_NODE_FIELD(lidx);
1360 COPY_NODE_FIELD(uidx);
1365 static ExprFieldSelect *
1366 _copyExprFieldSelect(ExprFieldSelect *from)
1368 ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
1370 COPY_NODE_FIELD(arg);
1371 COPY_NODE_FIELD(fields);
1372 COPY_NODE_FIELD(indirection);
1378 _copyResTarget(ResTarget *from)
1380 ResTarget *newnode = makeNode(ResTarget);
1382 COPY_STRING_FIELD(name);
1383 COPY_NODE_FIELD(indirection);
1384 COPY_NODE_FIELD(val);
1390 _copyTypeName(TypeName *from)
1392 TypeName *newnode = makeNode(TypeName);
1394 COPY_NODE_FIELD(names);
1395 COPY_SCALAR_FIELD(typeid);
1396 COPY_SCALAR_FIELD(timezone);
1397 COPY_SCALAR_FIELD(setof);
1398 COPY_SCALAR_FIELD(pct_type);
1399 COPY_SCALAR_FIELD(typmod);
1400 COPY_NODE_FIELD(arrayBounds);
1405 static SortGroupBy *
1406 _copySortGroupBy(SortGroupBy *from)
1408 SortGroupBy *newnode = makeNode(SortGroupBy);
1410 COPY_NODE_FIELD(useOp);
1411 COPY_NODE_FIELD(node);
1416 static RangeSubselect *
1417 _copyRangeSubselect(RangeSubselect *from)
1419 RangeSubselect *newnode = makeNode(RangeSubselect);
1421 COPY_NODE_FIELD(subquery);
1422 COPY_NODE_FIELD(alias);
1427 static RangeFunction *
1428 _copyRangeFunction(RangeFunction *from)
1430 RangeFunction *newnode = makeNode(RangeFunction);
1432 COPY_NODE_FIELD(funccallnode);
1433 COPY_NODE_FIELD(alias);
1434 COPY_NODE_FIELD(coldeflist);
1440 _copyTypeCast(TypeCast *from)
1442 TypeCast *newnode = makeNode(TypeCast);
1444 COPY_NODE_FIELD(arg);
1445 COPY_NODE_FIELD(typename);
1451 _copyIndexElem(IndexElem *from)
1453 IndexElem *newnode = makeNode(IndexElem);
1455 COPY_STRING_FIELD(name);
1456 COPY_NODE_FIELD(expr);
1457 COPY_NODE_FIELD(opclass);
1463 _copyColumnDef(ColumnDef *from)
1465 ColumnDef *newnode = makeNode(ColumnDef);
1467 COPY_STRING_FIELD(colname);
1468 COPY_NODE_FIELD(typename);
1469 COPY_SCALAR_FIELD(inhcount);
1470 COPY_SCALAR_FIELD(is_local);
1471 COPY_SCALAR_FIELD(is_not_null);
1472 COPY_NODE_FIELD(raw_default);
1473 COPY_STRING_FIELD(cooked_default);
1474 COPY_NODE_FIELD(constraints);
1475 COPY_NODE_FIELD(support);
1481 _copyConstraint(Constraint *from)
1483 Constraint *newnode = makeNode(Constraint);
1485 COPY_SCALAR_FIELD(contype);
1486 COPY_STRING_FIELD(name);
1487 COPY_NODE_FIELD(raw_expr);
1488 COPY_STRING_FIELD(cooked_expr);
1489 COPY_NODE_FIELD(keys);
1495 _copyDefElem(DefElem *from)
1497 DefElem *newnode = makeNode(DefElem);
1499 COPY_STRING_FIELD(defname);
1500 COPY_NODE_FIELD(arg);
1506 _copyQuery(Query *from)
1508 Query *newnode = makeNode(Query);
1510 COPY_SCALAR_FIELD(commandType);
1511 COPY_SCALAR_FIELD(querySource);
1512 COPY_SCALAR_FIELD(canSetTag);
1513 COPY_NODE_FIELD(utilityStmt);
1514 COPY_SCALAR_FIELD(resultRelation);
1515 COPY_NODE_FIELD(into);
1516 COPY_SCALAR_FIELD(hasAggs);
1517 COPY_SCALAR_FIELD(hasSubLinks);
1518 COPY_NODE_FIELD(rtable);
1519 COPY_NODE_FIELD(jointree);
1520 COPY_INTLIST_FIELD(rowMarks);
1521 COPY_NODE_FIELD(targetList);
1522 COPY_NODE_FIELD(groupClause);
1523 COPY_NODE_FIELD(havingQual);
1524 COPY_NODE_FIELD(distinctClause);
1525 COPY_NODE_FIELD(sortClause);
1526 COPY_NODE_FIELD(limitOffset);
1527 COPY_NODE_FIELD(limitCount);
1528 COPY_NODE_FIELD(setOperations);
1529 COPY_INTLIST_FIELD(resultRelations);
1530 COPY_NODE_FIELD(in_info_list);
1531 COPY_SCALAR_FIELD(hasJoinRTEs);
1534 * We do not copy the other planner internal fields: base_rel_list,
1535 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. That
1536 * would get us into copying RelOptInfo/Path trees, which we don't
1537 * want to do. It is necessary to copy in_info_list and hasJoinRTEs
1538 * for the benefit of inheritance_planner(), which may try to copy a
1539 * Query in which these are already set.
1546 _copyInsertStmt(InsertStmt *from)
1548 InsertStmt *newnode = makeNode(InsertStmt);
1550 COPY_NODE_FIELD(relation);
1551 COPY_NODE_FIELD(cols);
1552 COPY_NODE_FIELD(targetList);
1553 COPY_NODE_FIELD(selectStmt);
1559 _copyDeleteStmt(DeleteStmt *from)
1561 DeleteStmt *newnode = makeNode(DeleteStmt);
1563 COPY_NODE_FIELD(relation);
1564 COPY_NODE_FIELD(whereClause);
1570 _copyUpdateStmt(UpdateStmt *from)
1572 UpdateStmt *newnode = makeNode(UpdateStmt);
1574 COPY_NODE_FIELD(relation);
1575 COPY_NODE_FIELD(targetList);
1576 COPY_NODE_FIELD(whereClause);
1577 COPY_NODE_FIELD(fromClause);
1583 _copySelectStmt(SelectStmt *from)
1585 SelectStmt *newnode = makeNode(SelectStmt);
1587 COPY_NODE_FIELD(distinctClause);
1588 COPY_NODE_FIELD(into);
1589 COPY_NODE_FIELD(intoColNames);
1590 COPY_NODE_FIELD(targetList);
1591 COPY_NODE_FIELD(fromClause);
1592 COPY_NODE_FIELD(whereClause);
1593 COPY_NODE_FIELD(groupClause);
1594 COPY_NODE_FIELD(havingClause);
1595 COPY_NODE_FIELD(sortClause);
1596 COPY_NODE_FIELD(limitOffset);
1597 COPY_NODE_FIELD(limitCount);
1598 COPY_NODE_FIELD(forUpdate);
1599 COPY_SCALAR_FIELD(op);
1600 COPY_SCALAR_FIELD(all);
1601 COPY_NODE_FIELD(larg);
1602 COPY_NODE_FIELD(rarg);
1607 static SetOperationStmt *
1608 _copySetOperationStmt(SetOperationStmt *from)
1610 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1612 COPY_SCALAR_FIELD(op);
1613 COPY_SCALAR_FIELD(all);
1614 COPY_NODE_FIELD(larg);
1615 COPY_NODE_FIELD(rarg);
1616 COPY_OIDLIST_FIELD(colTypes);
1621 static AlterTableStmt *
1622 _copyAlterTableStmt(AlterTableStmt *from)
1624 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1626 COPY_SCALAR_FIELD(subtype);
1627 COPY_NODE_FIELD(relation);
1628 COPY_STRING_FIELD(name);
1629 COPY_NODE_FIELD(def);
1630 COPY_SCALAR_FIELD(behavior);
1635 static AlterDomainStmt *
1636 _copyAlterDomainStmt(AlterDomainStmt * from)
1638 AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1640 COPY_SCALAR_FIELD(subtype);
1641 COPY_NODE_FIELD(typename);
1642 COPY_STRING_FIELD(name);
1643 COPY_NODE_FIELD(def);
1644 COPY_SCALAR_FIELD(behavior);
1650 _copyGrantStmt(GrantStmt *from)
1652 GrantStmt *newnode = makeNode(GrantStmt);
1654 COPY_SCALAR_FIELD(is_grant);
1655 COPY_SCALAR_FIELD(objtype);
1656 COPY_NODE_FIELD(objects);
1657 COPY_INTLIST_FIELD(privileges);
1658 COPY_NODE_FIELD(grantees);
1659 COPY_SCALAR_FIELD(grant_option);
1660 COPY_SCALAR_FIELD(behavior);
1665 static PrivGrantee *
1666 _copyPrivGrantee(PrivGrantee *from)
1668 PrivGrantee *newnode = makeNode(PrivGrantee);
1670 COPY_STRING_FIELD(username);
1671 COPY_STRING_FIELD(groupname);
1676 static FuncWithArgs *
1677 _copyFuncWithArgs(FuncWithArgs *from)
1679 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1681 COPY_NODE_FIELD(funcname);
1682 COPY_NODE_FIELD(funcargs);
1687 static DeclareCursorStmt *
1688 _copyDeclareCursorStmt(DeclareCursorStmt * from)
1690 DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
1692 COPY_STRING_FIELD(portalname);
1693 COPY_SCALAR_FIELD(options);
1694 COPY_NODE_FIELD(query);
1699 static ClosePortalStmt *
1700 _copyClosePortalStmt(ClosePortalStmt *from)
1702 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1704 COPY_STRING_FIELD(portalname);
1709 static ClusterStmt *
1710 _copyClusterStmt(ClusterStmt *from)
1712 ClusterStmt *newnode = makeNode(ClusterStmt);
1714 COPY_NODE_FIELD(relation);
1715 COPY_STRING_FIELD(indexname);
1721 _copyCopyStmt(CopyStmt *from)
1723 CopyStmt *newnode = makeNode(CopyStmt);
1725 COPY_NODE_FIELD(relation);
1726 COPY_NODE_FIELD(attlist);
1727 COPY_SCALAR_FIELD(is_from);
1728 COPY_STRING_FIELD(filename);
1729 COPY_NODE_FIELD(options);
1735 _copyCreateStmt(CreateStmt *from)
1737 CreateStmt *newnode = makeNode(CreateStmt);
1739 COPY_NODE_FIELD(relation);
1740 COPY_NODE_FIELD(tableElts);
1741 COPY_NODE_FIELD(inhRelations);
1742 COPY_NODE_FIELD(constraints);
1743 COPY_SCALAR_FIELD(hasoids);
1744 COPY_SCALAR_FIELD(oncommit);
1749 static InhRelation *
1750 _copyInhRelation(InhRelation * from)
1752 InhRelation *newnode = makeNode(InhRelation);
1754 COPY_NODE_FIELD(relation);
1755 COPY_SCALAR_FIELD(including_defaults);
1761 _copyDefineStmt(DefineStmt *from)
1763 DefineStmt *newnode = makeNode(DefineStmt);
1765 COPY_SCALAR_FIELD(kind);
1766 COPY_NODE_FIELD(defnames);
1767 COPY_NODE_FIELD(definition);
1773 _copyDropStmt(DropStmt *from)
1775 DropStmt *newnode = makeNode(DropStmt);
1777 COPY_NODE_FIELD(objects);
1778 COPY_SCALAR_FIELD(removeType);
1779 COPY_SCALAR_FIELD(behavior);
1784 static TruncateStmt *
1785 _copyTruncateStmt(TruncateStmt *from)
1787 TruncateStmt *newnode = makeNode(TruncateStmt);
1789 COPY_NODE_FIELD(relation);
1794 static CommentStmt *
1795 _copyCommentStmt(CommentStmt *from)
1797 CommentStmt *newnode = makeNode(CommentStmt);
1799 COPY_SCALAR_FIELD(objtype);
1800 COPY_NODE_FIELD(objname);
1801 COPY_NODE_FIELD(objargs);
1802 COPY_STRING_FIELD(comment);
1808 _copyFetchStmt(FetchStmt *from)
1810 FetchStmt *newnode = makeNode(FetchStmt);
1812 COPY_SCALAR_FIELD(direction);
1813 COPY_SCALAR_FIELD(howMany);
1814 COPY_STRING_FIELD(portalname);
1815 COPY_SCALAR_FIELD(ismove);
1821 _copyIndexStmt(IndexStmt *from)
1823 IndexStmt *newnode = makeNode(IndexStmt);
1825 COPY_STRING_FIELD(idxname);
1826 COPY_NODE_FIELD(relation);
1827 COPY_STRING_FIELD(accessMethod);
1828 COPY_NODE_FIELD(indexParams);
1829 COPY_NODE_FIELD(whereClause);
1830 COPY_NODE_FIELD(rangetable);
1831 COPY_SCALAR_FIELD(unique);
1832 COPY_SCALAR_FIELD(primary);
1833 COPY_SCALAR_FIELD(isconstraint);
1838 static CreateFunctionStmt *
1839 _copyCreateFunctionStmt(CreateFunctionStmt *from)
1841 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
1843 COPY_SCALAR_FIELD(replace);
1844 COPY_NODE_FIELD(funcname);
1845 COPY_NODE_FIELD(argTypes);
1846 COPY_NODE_FIELD(returnType);
1847 COPY_NODE_FIELD(options);
1848 COPY_NODE_FIELD(withClause);
1853 static RemoveAggrStmt *
1854 _copyRemoveAggrStmt(RemoveAggrStmt *from)
1856 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1858 COPY_NODE_FIELD(aggname);
1859 COPY_NODE_FIELD(aggtype);
1860 COPY_SCALAR_FIELD(behavior);
1865 static RemoveFuncStmt *
1866 _copyRemoveFuncStmt(RemoveFuncStmt *from)
1868 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
1870 COPY_NODE_FIELD(funcname);
1871 COPY_NODE_FIELD(args);
1872 COPY_SCALAR_FIELD(behavior);
1877 static RemoveOperStmt *
1878 _copyRemoveOperStmt(RemoveOperStmt *from)
1880 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
1882 COPY_NODE_FIELD(opname);
1883 COPY_NODE_FIELD(args);
1884 COPY_SCALAR_FIELD(behavior);
1889 static RemoveOpClassStmt *
1890 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
1892 RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
1894 COPY_NODE_FIELD(opclassname);
1895 COPY_STRING_FIELD(amname);
1896 COPY_SCALAR_FIELD(behavior);
1902 _copyRenameStmt(RenameStmt *from)
1904 RenameStmt *newnode = makeNode(RenameStmt);
1906 COPY_NODE_FIELD(relation);
1907 COPY_NODE_FIELD(object);
1908 COPY_NODE_FIELD(objarg);
1909 COPY_STRING_FIELD(subname);
1910 COPY_STRING_FIELD(newname);
1911 COPY_SCALAR_FIELD(renameType);
1917 _copyRuleStmt(RuleStmt *from)
1919 RuleStmt *newnode = makeNode(RuleStmt);
1921 COPY_NODE_FIELD(relation);
1922 COPY_STRING_FIELD(rulename);
1923 COPY_NODE_FIELD(whereClause);
1924 COPY_SCALAR_FIELD(event);
1925 COPY_SCALAR_FIELD(instead);
1926 COPY_NODE_FIELD(actions);
1927 COPY_SCALAR_FIELD(replace);
1933 _copyNotifyStmt(NotifyStmt *from)
1935 NotifyStmt *newnode = makeNode(NotifyStmt);
1937 COPY_NODE_FIELD(relation);
1943 _copyListenStmt(ListenStmt *from)
1945 ListenStmt *newnode = makeNode(ListenStmt);
1947 COPY_NODE_FIELD(relation);
1952 static UnlistenStmt *
1953 _copyUnlistenStmt(UnlistenStmt *from)
1955 UnlistenStmt *newnode = makeNode(UnlistenStmt);
1957 COPY_NODE_FIELD(relation);
1962 static TransactionStmt *
1963 _copyTransactionStmt(TransactionStmt *from)
1965 TransactionStmt *newnode = makeNode(TransactionStmt);
1967 COPY_SCALAR_FIELD(kind);
1968 COPY_NODE_FIELD(options);
1973 static CompositeTypeStmt *
1974 _copyCompositeTypeStmt(CompositeTypeStmt *from)
1976 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
1978 COPY_NODE_FIELD(typevar);
1979 COPY_NODE_FIELD(coldeflist);
1985 _copyViewStmt(ViewStmt *from)
1987 ViewStmt *newnode = makeNode(ViewStmt);
1989 COPY_NODE_FIELD(view);
1990 COPY_NODE_FIELD(aliases);
1991 COPY_NODE_FIELD(query);
1992 COPY_SCALAR_FIELD(replace);
1998 _copyLoadStmt(LoadStmt *from)
2000 LoadStmt *newnode = makeNode(LoadStmt);
2002 COPY_STRING_FIELD(filename);
2007 static CreateDomainStmt *
2008 _copyCreateDomainStmt(CreateDomainStmt *from)
2010 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2012 COPY_NODE_FIELD(domainname);
2013 COPY_NODE_FIELD(typename);
2014 COPY_NODE_FIELD(constraints);
2019 static CreateOpClassStmt *
2020 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2022 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2024 COPY_NODE_FIELD(opclassname);
2025 COPY_STRING_FIELD(amname);
2026 COPY_NODE_FIELD(datatype);
2027 COPY_NODE_FIELD(items);
2028 COPY_SCALAR_FIELD(isDefault);
2033 static CreateOpClassItem *
2034 _copyCreateOpClassItem(CreateOpClassItem *from)
2036 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2038 COPY_SCALAR_FIELD(itemtype);
2039 COPY_NODE_FIELD(name);
2040 COPY_NODE_FIELD(args);
2041 COPY_SCALAR_FIELD(number);
2042 COPY_SCALAR_FIELD(recheck);
2043 COPY_NODE_FIELD(storedtype);
2048 static CreatedbStmt *
2049 _copyCreatedbStmt(CreatedbStmt *from)
2051 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2053 COPY_STRING_FIELD(dbname);
2054 COPY_NODE_FIELD(options);
2059 static AlterDatabaseSetStmt *
2060 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2062 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2064 COPY_STRING_FIELD(dbname);
2065 COPY_STRING_FIELD(variable);
2066 COPY_NODE_FIELD(value);
2072 _copyDropdbStmt(DropdbStmt *from)
2074 DropdbStmt *newnode = makeNode(DropdbStmt);
2076 COPY_STRING_FIELD(dbname);
2082 _copyVacuumStmt(VacuumStmt *from)
2084 VacuumStmt *newnode = makeNode(VacuumStmt);
2086 COPY_SCALAR_FIELD(vacuum);
2087 COPY_SCALAR_FIELD(full);
2088 COPY_SCALAR_FIELD(analyze);
2089 COPY_SCALAR_FIELD(freeze);
2090 COPY_SCALAR_FIELD(verbose);
2091 COPY_NODE_FIELD(relation);
2092 COPY_NODE_FIELD(va_cols);
2097 static ExplainStmt *
2098 _copyExplainStmt(ExplainStmt *from)
2100 ExplainStmt *newnode = makeNode(ExplainStmt);
2102 COPY_NODE_FIELD(query);
2103 COPY_SCALAR_FIELD(verbose);
2104 COPY_SCALAR_FIELD(analyze);
2109 static CreateSeqStmt *
2110 _copyCreateSeqStmt(CreateSeqStmt *from)
2112 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2114 COPY_NODE_FIELD(sequence);
2115 COPY_NODE_FIELD(options);
2120 static AlterSeqStmt *
2121 _copyAlterSeqStmt(AlterSeqStmt * from)
2123 AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
2125 COPY_NODE_FIELD(sequence);
2126 COPY_NODE_FIELD(options);
2131 static VariableSetStmt *
2132 _copyVariableSetStmt(VariableSetStmt *from)
2134 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2136 COPY_STRING_FIELD(name);
2137 COPY_NODE_FIELD(args);
2138 COPY_SCALAR_FIELD(is_local);
2143 static VariableShowStmt *
2144 _copyVariableShowStmt(VariableShowStmt *from)
2146 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2148 COPY_STRING_FIELD(name);
2153 static VariableResetStmt *
2154 _copyVariableResetStmt(VariableResetStmt *from)
2156 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2158 COPY_STRING_FIELD(name);
2163 static CreateTrigStmt *
2164 _copyCreateTrigStmt(CreateTrigStmt *from)
2166 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2168 COPY_STRING_FIELD(trigname);
2169 COPY_NODE_FIELD(relation);
2170 COPY_NODE_FIELD(funcname);
2171 COPY_NODE_FIELD(args);
2172 COPY_SCALAR_FIELD(before);
2173 COPY_SCALAR_FIELD(row);
2174 strcpy(newnode->actions, from->actions); /* in-line string field */
2175 COPY_SCALAR_FIELD(isconstraint);
2176 COPY_SCALAR_FIELD(deferrable);
2177 COPY_SCALAR_FIELD(initdeferred);
2178 COPY_NODE_FIELD(constrrel);
2183 static DropPropertyStmt *
2184 _copyDropPropertyStmt(DropPropertyStmt *from)
2186 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2188 COPY_NODE_FIELD(relation);
2189 COPY_STRING_FIELD(property);
2190 COPY_SCALAR_FIELD(removeType);
2191 COPY_SCALAR_FIELD(behavior);
2196 static CreatePLangStmt *
2197 _copyCreatePLangStmt(CreatePLangStmt *from)
2199 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2201 COPY_STRING_FIELD(plname);
2202 COPY_NODE_FIELD(plhandler);
2203 COPY_NODE_FIELD(plvalidator);
2204 COPY_SCALAR_FIELD(pltrusted);
2209 static DropPLangStmt *
2210 _copyDropPLangStmt(DropPLangStmt *from)
2212 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2214 COPY_STRING_FIELD(plname);
2215 COPY_SCALAR_FIELD(behavior);
2220 static CreateUserStmt *
2221 _copyCreateUserStmt(CreateUserStmt *from)
2223 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2225 COPY_STRING_FIELD(user);
2226 COPY_NODE_FIELD(options);
2231 static AlterUserStmt *
2232 _copyAlterUserStmt(AlterUserStmt *from)
2234 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2236 COPY_STRING_FIELD(user);
2237 COPY_NODE_FIELD(options);
2242 static AlterUserSetStmt *
2243 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2245 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2247 COPY_STRING_FIELD(user);
2248 COPY_STRING_FIELD(variable);
2249 COPY_NODE_FIELD(value);
2254 static DropUserStmt *
2255 _copyDropUserStmt(DropUserStmt *from)
2257 DropUserStmt *newnode = makeNode(DropUserStmt);
2259 COPY_NODE_FIELD(users);
2265 _copyLockStmt(LockStmt *from)
2267 LockStmt *newnode = makeNode(LockStmt);
2269 COPY_NODE_FIELD(relations);
2270 COPY_SCALAR_FIELD(mode);
2275 static ConstraintsSetStmt *
2276 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2278 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2280 COPY_NODE_FIELD(constraints);
2281 COPY_SCALAR_FIELD(deferred);
2286 static CreateGroupStmt *
2287 _copyCreateGroupStmt(CreateGroupStmt *from)
2289 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2291 COPY_STRING_FIELD(name);
2292 COPY_NODE_FIELD(options);
2297 static AlterGroupStmt *
2298 _copyAlterGroupStmt(AlterGroupStmt *from)
2300 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2302 COPY_STRING_FIELD(name);
2303 COPY_SCALAR_FIELD(action);
2304 COPY_NODE_FIELD(listUsers);
2309 static DropGroupStmt *
2310 _copyDropGroupStmt(DropGroupStmt *from)
2312 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2314 COPY_STRING_FIELD(name);
2319 static ReindexStmt *
2320 _copyReindexStmt(ReindexStmt *from)
2322 ReindexStmt *newnode = makeNode(ReindexStmt);
2324 COPY_SCALAR_FIELD(kind);
2325 COPY_NODE_FIELD(relation);
2326 COPY_STRING_FIELD(name);
2327 COPY_SCALAR_FIELD(force);
2328 COPY_SCALAR_FIELD(all);
2333 static CreateSchemaStmt *
2334 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2336 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2338 COPY_STRING_FIELD(schemaname);
2339 COPY_STRING_FIELD(authid);
2340 COPY_NODE_FIELD(schemaElts);
2345 static CreateConversionStmt *
2346 _copyCreateConversionStmt(CreateConversionStmt *from)
2348 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2350 COPY_NODE_FIELD(conversion_name);
2351 COPY_STRING_FIELD(for_encoding_name);
2352 COPY_STRING_FIELD(to_encoding_name);
2353 COPY_NODE_FIELD(func_name);
2354 COPY_SCALAR_FIELD(def);
2359 static CreateCastStmt *
2360 _copyCreateCastStmt(CreateCastStmt *from)
2362 CreateCastStmt *newnode = makeNode(CreateCastStmt);
2364 COPY_NODE_FIELD(sourcetype);
2365 COPY_NODE_FIELD(targettype);
2366 COPY_NODE_FIELD(func);
2367 COPY_SCALAR_FIELD(context);
2372 static DropCastStmt *
2373 _copyDropCastStmt(DropCastStmt *from)
2375 DropCastStmt *newnode = makeNode(DropCastStmt);
2377 COPY_NODE_FIELD(sourcetype);
2378 COPY_NODE_FIELD(targettype);
2379 COPY_SCALAR_FIELD(behavior);
2384 static PrepareStmt *
2385 _copyPrepareStmt(PrepareStmt *from)
2387 PrepareStmt *newnode = makeNode(PrepareStmt);
2389 COPY_STRING_FIELD(name);
2390 COPY_NODE_FIELD(argtypes);
2391 COPY_OIDLIST_FIELD(argtype_oids);
2392 COPY_NODE_FIELD(query);
2397 static ExecuteStmt *
2398 _copyExecuteStmt(ExecuteStmt *from)
2400 ExecuteStmt *newnode = makeNode(ExecuteStmt);
2402 COPY_STRING_FIELD(name);
2403 COPY_NODE_FIELD(into);
2404 COPY_NODE_FIELD(params);
2409 static DeallocateStmt *
2410 _copyDeallocateStmt(DeallocateStmt *from)
2412 DeallocateStmt *newnode = makeNode(DeallocateStmt);
2414 COPY_STRING_FIELD(name);
2420 /* ****************************************************************
2421 * pg_list.h copy functions
2422 * ****************************************************************
2426 _copyValue(Value *from)
2428 Value *newnode = makeNode(Value);
2430 /* See also _copyAConst when changing this code! */
2432 COPY_SCALAR_FIELD(type);
2436 COPY_SCALAR_FIELD(val.ival);
2441 COPY_STRING_FIELD(val.str);
2447 elog(ERROR, "unrecognized node type: %d",
2457 * Create a copy of a Node tree or list. This is a "deep" copy: all
2458 * substructure is copied too, recursively.
2461 copyObject(void *from)
2468 switch (nodeTag(from))
2474 retval = _copyPlan(from);
2477 retval = _copyResult(from);
2480 retval = _copyAppend(from);
2483 retval = _copyScan(from);
2486 retval = _copySeqScan(from);
2489 retval = _copyIndexScan(from);
2492 retval = _copyTidScan(from);
2494 case T_SubqueryScan:
2495 retval = _copySubqueryScan(from);
2497 case T_FunctionScan:
2498 retval = _copyFunctionScan(from);
2501 retval = _copyJoin(from);
2504 retval = _copyNestLoop(from);
2507 retval = _copyMergeJoin(from);
2510 retval = _copyHashJoin(from);
2513 retval = _copyMaterial(from);
2516 retval = _copySort(from);
2519 retval = _copyGroup(from);
2522 retval = _copyAgg(from);
2525 retval = _copyUnique(from);
2528 retval = _copyHash(from);
2531 retval = _copySetOp(from);
2534 retval = _copyLimit(from);
2541 retval = _copyResdom(from);
2544 retval = _copyAlias(from);
2547 retval = _copyRangeVar(from);
2550 retval = _copyVar(from);
2553 retval = _copyConst(from);
2556 retval = _copyParam(from);
2559 retval = _copyAggref(from);
2562 retval = _copyArrayRef(from);
2565 retval = _copyFuncExpr(from);
2568 retval = _copyOpExpr(from);
2570 case T_DistinctExpr:
2571 retval = _copyDistinctExpr(from);
2573 case T_ScalarArrayOpExpr:
2574 retval = _copyScalarArrayOpExpr(from);
2577 retval = _copyBoolExpr(from);
2580 retval = _copySubLink(from);
2583 retval = _copySubPlan(from);
2586 retval = _copyFieldSelect(from);
2589 retval = _copyRelabelType(from);
2592 retval = _copyCaseExpr(from);
2595 retval = _copyCaseWhen(from);
2598 retval = _copyArrayExpr(from);
2600 case T_CoalesceExpr:
2601 retval = _copyCoalesceExpr(from);
2604 retval = _copyNullIfExpr(from);
2607 retval = _copyNullTest(from);
2610 retval = _copyBooleanTest(from);
2612 case T_CoerceToDomain:
2613 retval = _copyCoerceToDomain(from);
2615 case T_CoerceToDomainValue:
2616 retval = _copyCoerceToDomainValue(from);
2618 case T_SetToDefault:
2619 retval = _copySetToDefault(from);
2622 retval = _copyTargetEntry(from);
2625 retval = _copyRangeTblRef(from);
2628 retval = _copyJoinExpr(from);
2631 retval = _copyFromExpr(from);
2638 retval = _copyPathKeyItem(from);
2640 case T_RestrictInfo:
2641 retval = _copyRestrictInfo(from);
2644 retval = _copyJoinInfo(from);
2646 case T_InClauseInfo:
2647 retval = _copyInClauseInfo(from);
2658 retval = _copyValue(from);
2667 /* rather ugly coding for speed... */
2668 /* Note the input list cannot be NIL if we got here. */
2669 newcell = makeNode(List);
2670 lfirst(newcell) = copyObject(lfirst(list));
2672 retval = (void *) newcell;
2675 foreach(oldl, lnext(list))
2677 newcell = makeNode(List);
2678 lfirst(newcell) = copyObject(lfirst(oldl));
2679 prev->next = newcell;
2690 retval = _copyQuery(from);
2693 retval = _copyInsertStmt(from);
2696 retval = _copyDeleteStmt(from);
2699 retval = _copyUpdateStmt(from);
2702 retval = _copySelectStmt(from);
2704 case T_SetOperationStmt:
2705 retval = _copySetOperationStmt(from);
2707 case T_AlterTableStmt:
2708 retval = _copyAlterTableStmt(from);
2710 case T_AlterDomainStmt:
2711 retval = _copyAlterDomainStmt(from);
2714 retval = _copyGrantStmt(from);
2716 case T_DeclareCursorStmt:
2717 retval = _copyDeclareCursorStmt(from);
2719 case T_ClosePortalStmt:
2720 retval = _copyClosePortalStmt(from);
2723 retval = _copyClusterStmt(from);
2726 retval = _copyCopyStmt(from);
2729 retval = _copyCreateStmt(from);
2732 retval = _copyInhRelation(from);
2735 retval = _copyDefineStmt(from);
2738 retval = _copyDropStmt(from);
2740 case T_TruncateStmt:
2741 retval = _copyTruncateStmt(from);
2744 retval = _copyCommentStmt(from);
2747 retval = _copyFetchStmt(from);
2750 retval = _copyIndexStmt(from);
2752 case T_CreateFunctionStmt:
2753 retval = _copyCreateFunctionStmt(from);
2755 case T_RemoveAggrStmt:
2756 retval = _copyRemoveAggrStmt(from);
2758 case T_RemoveFuncStmt:
2759 retval = _copyRemoveFuncStmt(from);
2761 case T_RemoveOperStmt:
2762 retval = _copyRemoveOperStmt(from);
2764 case T_RemoveOpClassStmt:
2765 retval = _copyRemoveOpClassStmt(from);
2768 retval = _copyRenameStmt(from);
2771 retval = _copyRuleStmt(from);
2774 retval = _copyNotifyStmt(from);
2777 retval = _copyListenStmt(from);
2779 case T_UnlistenStmt:
2780 retval = _copyUnlistenStmt(from);
2782 case T_TransactionStmt:
2783 retval = _copyTransactionStmt(from);
2785 case T_CompositeTypeStmt:
2786 retval = _copyCompositeTypeStmt(from);
2789 retval = _copyViewStmt(from);
2792 retval = _copyLoadStmt(from);
2794 case T_CreateDomainStmt:
2795 retval = _copyCreateDomainStmt(from);
2797 case T_CreateOpClassStmt:
2798 retval = _copyCreateOpClassStmt(from);
2800 case T_CreateOpClassItem:
2801 retval = _copyCreateOpClassItem(from);
2803 case T_CreatedbStmt:
2804 retval = _copyCreatedbStmt(from);
2806 case T_AlterDatabaseSetStmt:
2807 retval = _copyAlterDatabaseSetStmt(from);
2810 retval = _copyDropdbStmt(from);
2813 retval = _copyVacuumStmt(from);
2816 retval = _copyExplainStmt(from);
2818 case T_CreateSeqStmt:
2819 retval = _copyCreateSeqStmt(from);
2821 case T_AlterSeqStmt:
2822 retval = _copyAlterSeqStmt(from);
2824 case T_VariableSetStmt:
2825 retval = _copyVariableSetStmt(from);
2827 case T_VariableShowStmt:
2828 retval = _copyVariableShowStmt(from);
2830 case T_VariableResetStmt:
2831 retval = _copyVariableResetStmt(from);
2833 case T_CreateTrigStmt:
2834 retval = _copyCreateTrigStmt(from);
2836 case T_DropPropertyStmt:
2837 retval = _copyDropPropertyStmt(from);
2839 case T_CreatePLangStmt:
2840 retval = _copyCreatePLangStmt(from);
2842 case T_DropPLangStmt:
2843 retval = _copyDropPLangStmt(from);
2845 case T_CreateUserStmt:
2846 retval = _copyCreateUserStmt(from);
2848 case T_AlterUserStmt:
2849 retval = _copyAlterUserStmt(from);
2851 case T_AlterUserSetStmt:
2852 retval = _copyAlterUserSetStmt(from);
2854 case T_DropUserStmt:
2855 retval = _copyDropUserStmt(from);
2858 retval = _copyLockStmt(from);
2860 case T_ConstraintsSetStmt:
2861 retval = _copyConstraintsSetStmt(from);
2863 case T_CreateGroupStmt:
2864 retval = _copyCreateGroupStmt(from);
2866 case T_AlterGroupStmt:
2867 retval = _copyAlterGroupStmt(from);
2869 case T_DropGroupStmt:
2870 retval = _copyDropGroupStmt(from);
2873 retval = _copyReindexStmt(from);
2875 case T_CheckPointStmt:
2876 retval = (void *) makeNode(CheckPointStmt);
2878 case T_CreateSchemaStmt:
2879 retval = _copyCreateSchemaStmt(from);
2881 case T_CreateConversionStmt:
2882 retval = _copyCreateConversionStmt(from);
2884 case T_CreateCastStmt:
2885 retval = _copyCreateCastStmt(from);
2887 case T_DropCastStmt:
2888 retval = _copyDropCastStmt(from);
2891 retval = _copyPrepareStmt(from);
2894 retval = _copyExecuteStmt(from);
2896 case T_DeallocateStmt:
2897 retval = _copyDeallocateStmt(from);
2901 retval = _copyAExpr(from);
2904 retval = _copyColumnRef(from);
2907 retval = _copyParamRef(from);
2910 retval = _copyAConst(from);
2913 retval = _copyFuncCall(from);
2916 retval = _copyAIndices(from);
2918 case T_ExprFieldSelect:
2919 retval = _copyExprFieldSelect(from);
2922 retval = _copyResTarget(from);
2925 retval = _copyTypeCast(from);
2928 retval = _copySortGroupBy(from);
2930 case T_RangeSubselect:
2931 retval = _copyRangeSubselect(from);
2933 case T_RangeFunction:
2934 retval = _copyRangeFunction(from);
2937 retval = _copyTypeName(from);
2940 retval = _copyIndexElem(from);
2943 retval = _copyColumnDef(from);
2946 retval = _copyConstraint(from);
2949 retval = _copyDefElem(from);
2951 case T_RangeTblEntry:
2952 retval = _copyRangeTblEntry(from);
2955 retval = _copySortClause(from);
2958 retval = _copyGroupClause(from);
2960 case T_FkConstraint:
2961 retval = _copyFkConstraint(from);
2964 retval = _copyPrivGrantee(from);
2966 case T_FuncWithArgs:
2967 retval = _copyFuncWithArgs(from);
2971 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
2972 retval = from; /* keep compiler quiet */