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.265 2003/08/17 23:43:25 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(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(multidims);
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);
1406 _copySortBy(SortBy *from)
1408 SortBy *newnode = makeNode(SortBy);
1410 COPY_SCALAR_FIELD(sortby_kind);
1411 COPY_NODE_FIELD(useOp);
1412 COPY_NODE_FIELD(node);
1417 static RangeSubselect *
1418 _copyRangeSubselect(RangeSubselect *from)
1420 RangeSubselect *newnode = makeNode(RangeSubselect);
1422 COPY_NODE_FIELD(subquery);
1423 COPY_NODE_FIELD(alias);
1428 static RangeFunction *
1429 _copyRangeFunction(RangeFunction *from)
1431 RangeFunction *newnode = makeNode(RangeFunction);
1433 COPY_NODE_FIELD(funccallnode);
1434 COPY_NODE_FIELD(alias);
1435 COPY_NODE_FIELD(coldeflist);
1441 _copyTypeCast(TypeCast *from)
1443 TypeCast *newnode = makeNode(TypeCast);
1445 COPY_NODE_FIELD(arg);
1446 COPY_NODE_FIELD(typename);
1452 _copyIndexElem(IndexElem *from)
1454 IndexElem *newnode = makeNode(IndexElem);
1456 COPY_STRING_FIELD(name);
1457 COPY_NODE_FIELD(expr);
1458 COPY_NODE_FIELD(opclass);
1464 _copyColumnDef(ColumnDef *from)
1466 ColumnDef *newnode = makeNode(ColumnDef);
1468 COPY_STRING_FIELD(colname);
1469 COPY_NODE_FIELD(typename);
1470 COPY_SCALAR_FIELD(inhcount);
1471 COPY_SCALAR_FIELD(is_local);
1472 COPY_SCALAR_FIELD(is_not_null);
1473 COPY_NODE_FIELD(raw_default);
1474 COPY_STRING_FIELD(cooked_default);
1475 COPY_NODE_FIELD(constraints);
1476 COPY_NODE_FIELD(support);
1482 _copyConstraint(Constraint *from)
1484 Constraint *newnode = makeNode(Constraint);
1486 COPY_SCALAR_FIELD(contype);
1487 COPY_STRING_FIELD(name);
1488 COPY_NODE_FIELD(raw_expr);
1489 COPY_STRING_FIELD(cooked_expr);
1490 COPY_NODE_FIELD(keys);
1496 _copyDefElem(DefElem *from)
1498 DefElem *newnode = makeNode(DefElem);
1500 COPY_STRING_FIELD(defname);
1501 COPY_NODE_FIELD(arg);
1507 _copyQuery(Query *from)
1509 Query *newnode = makeNode(Query);
1511 COPY_SCALAR_FIELD(commandType);
1512 COPY_SCALAR_FIELD(querySource);
1513 COPY_SCALAR_FIELD(canSetTag);
1514 COPY_NODE_FIELD(utilityStmt);
1515 COPY_SCALAR_FIELD(resultRelation);
1516 COPY_NODE_FIELD(into);
1517 COPY_SCALAR_FIELD(hasAggs);
1518 COPY_SCALAR_FIELD(hasSubLinks);
1519 COPY_NODE_FIELD(rtable);
1520 COPY_NODE_FIELD(jointree);
1521 COPY_INTLIST_FIELD(rowMarks);
1522 COPY_NODE_FIELD(targetList);
1523 COPY_NODE_FIELD(groupClause);
1524 COPY_NODE_FIELD(havingQual);
1525 COPY_NODE_FIELD(distinctClause);
1526 COPY_NODE_FIELD(sortClause);
1527 COPY_NODE_FIELD(limitOffset);
1528 COPY_NODE_FIELD(limitCount);
1529 COPY_NODE_FIELD(setOperations);
1530 COPY_INTLIST_FIELD(resultRelations);
1531 COPY_NODE_FIELD(in_info_list);
1532 COPY_SCALAR_FIELD(hasJoinRTEs);
1535 * We do not copy the other planner internal fields: base_rel_list,
1536 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. That
1537 * would get us into copying RelOptInfo/Path trees, which we don't
1538 * want to do. It is necessary to copy in_info_list and hasJoinRTEs
1539 * for the benefit of inheritance_planner(), which may try to copy a
1540 * Query in which these are already set.
1547 _copyInsertStmt(InsertStmt *from)
1549 InsertStmt *newnode = makeNode(InsertStmt);
1551 COPY_NODE_FIELD(relation);
1552 COPY_NODE_FIELD(cols);
1553 COPY_NODE_FIELD(targetList);
1554 COPY_NODE_FIELD(selectStmt);
1560 _copyDeleteStmt(DeleteStmt *from)
1562 DeleteStmt *newnode = makeNode(DeleteStmt);
1564 COPY_NODE_FIELD(relation);
1565 COPY_NODE_FIELD(whereClause);
1571 _copyUpdateStmt(UpdateStmt *from)
1573 UpdateStmt *newnode = makeNode(UpdateStmt);
1575 COPY_NODE_FIELD(relation);
1576 COPY_NODE_FIELD(targetList);
1577 COPY_NODE_FIELD(whereClause);
1578 COPY_NODE_FIELD(fromClause);
1584 _copySelectStmt(SelectStmt *from)
1586 SelectStmt *newnode = makeNode(SelectStmt);
1588 COPY_NODE_FIELD(distinctClause);
1589 COPY_NODE_FIELD(into);
1590 COPY_NODE_FIELD(intoColNames);
1591 COPY_NODE_FIELD(targetList);
1592 COPY_NODE_FIELD(fromClause);
1593 COPY_NODE_FIELD(whereClause);
1594 COPY_NODE_FIELD(groupClause);
1595 COPY_NODE_FIELD(havingClause);
1596 COPY_NODE_FIELD(sortClause);
1597 COPY_NODE_FIELD(limitOffset);
1598 COPY_NODE_FIELD(limitCount);
1599 COPY_NODE_FIELD(forUpdate);
1600 COPY_SCALAR_FIELD(op);
1601 COPY_SCALAR_FIELD(all);
1602 COPY_NODE_FIELD(larg);
1603 COPY_NODE_FIELD(rarg);
1608 static SetOperationStmt *
1609 _copySetOperationStmt(SetOperationStmt *from)
1611 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1613 COPY_SCALAR_FIELD(op);
1614 COPY_SCALAR_FIELD(all);
1615 COPY_NODE_FIELD(larg);
1616 COPY_NODE_FIELD(rarg);
1617 COPY_OIDLIST_FIELD(colTypes);
1622 static AlterTableStmt *
1623 _copyAlterTableStmt(AlterTableStmt *from)
1625 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1627 COPY_SCALAR_FIELD(subtype);
1628 COPY_NODE_FIELD(relation);
1629 COPY_STRING_FIELD(name);
1630 COPY_NODE_FIELD(def);
1631 COPY_SCALAR_FIELD(behavior);
1636 static AlterDomainStmt *
1637 _copyAlterDomainStmt(AlterDomainStmt *from)
1639 AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1641 COPY_SCALAR_FIELD(subtype);
1642 COPY_NODE_FIELD(typename);
1643 COPY_STRING_FIELD(name);
1644 COPY_NODE_FIELD(def);
1645 COPY_SCALAR_FIELD(behavior);
1651 _copyGrantStmt(GrantStmt *from)
1653 GrantStmt *newnode = makeNode(GrantStmt);
1655 COPY_SCALAR_FIELD(is_grant);
1656 COPY_SCALAR_FIELD(objtype);
1657 COPY_NODE_FIELD(objects);
1658 COPY_INTLIST_FIELD(privileges);
1659 COPY_NODE_FIELD(grantees);
1660 COPY_SCALAR_FIELD(grant_option);
1661 COPY_SCALAR_FIELD(behavior);
1666 static PrivGrantee *
1667 _copyPrivGrantee(PrivGrantee *from)
1669 PrivGrantee *newnode = makeNode(PrivGrantee);
1671 COPY_STRING_FIELD(username);
1672 COPY_STRING_FIELD(groupname);
1677 static FuncWithArgs *
1678 _copyFuncWithArgs(FuncWithArgs *from)
1680 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1682 COPY_NODE_FIELD(funcname);
1683 COPY_NODE_FIELD(funcargs);
1688 static DeclareCursorStmt *
1689 _copyDeclareCursorStmt(DeclareCursorStmt *from)
1691 DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
1693 COPY_STRING_FIELD(portalname);
1694 COPY_SCALAR_FIELD(options);
1695 COPY_NODE_FIELD(query);
1700 static ClosePortalStmt *
1701 _copyClosePortalStmt(ClosePortalStmt *from)
1703 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1705 COPY_STRING_FIELD(portalname);
1710 static ClusterStmt *
1711 _copyClusterStmt(ClusterStmt *from)
1713 ClusterStmt *newnode = makeNode(ClusterStmt);
1715 COPY_NODE_FIELD(relation);
1716 COPY_STRING_FIELD(indexname);
1722 _copyCopyStmt(CopyStmt *from)
1724 CopyStmt *newnode = makeNode(CopyStmt);
1726 COPY_NODE_FIELD(relation);
1727 COPY_NODE_FIELD(attlist);
1728 COPY_SCALAR_FIELD(is_from);
1729 COPY_STRING_FIELD(filename);
1730 COPY_NODE_FIELD(options);
1736 _copyCreateStmt(CreateStmt *from)
1738 CreateStmt *newnode = makeNode(CreateStmt);
1740 COPY_NODE_FIELD(relation);
1741 COPY_NODE_FIELD(tableElts);
1742 COPY_NODE_FIELD(inhRelations);
1743 COPY_NODE_FIELD(constraints);
1744 COPY_SCALAR_FIELD(hasoids);
1745 COPY_SCALAR_FIELD(oncommit);
1750 static InhRelation *
1751 _copyInhRelation(InhRelation *from)
1753 InhRelation *newnode = makeNode(InhRelation);
1755 COPY_NODE_FIELD(relation);
1756 COPY_SCALAR_FIELD(including_defaults);
1762 _copyDefineStmt(DefineStmt *from)
1764 DefineStmt *newnode = makeNode(DefineStmt);
1766 COPY_SCALAR_FIELD(kind);
1767 COPY_NODE_FIELD(defnames);
1768 COPY_NODE_FIELD(definition);
1774 _copyDropStmt(DropStmt *from)
1776 DropStmt *newnode = makeNode(DropStmt);
1778 COPY_NODE_FIELD(objects);
1779 COPY_SCALAR_FIELD(removeType);
1780 COPY_SCALAR_FIELD(behavior);
1785 static TruncateStmt *
1786 _copyTruncateStmt(TruncateStmt *from)
1788 TruncateStmt *newnode = makeNode(TruncateStmt);
1790 COPY_NODE_FIELD(relation);
1795 static CommentStmt *
1796 _copyCommentStmt(CommentStmt *from)
1798 CommentStmt *newnode = makeNode(CommentStmt);
1800 COPY_SCALAR_FIELD(objtype);
1801 COPY_NODE_FIELD(objname);
1802 COPY_NODE_FIELD(objargs);
1803 COPY_STRING_FIELD(comment);
1809 _copyFetchStmt(FetchStmt *from)
1811 FetchStmt *newnode = makeNode(FetchStmt);
1813 COPY_SCALAR_FIELD(direction);
1814 COPY_SCALAR_FIELD(howMany);
1815 COPY_STRING_FIELD(portalname);
1816 COPY_SCALAR_FIELD(ismove);
1822 _copyIndexStmt(IndexStmt *from)
1824 IndexStmt *newnode = makeNode(IndexStmt);
1826 COPY_STRING_FIELD(idxname);
1827 COPY_NODE_FIELD(relation);
1828 COPY_STRING_FIELD(accessMethod);
1829 COPY_NODE_FIELD(indexParams);
1830 COPY_NODE_FIELD(whereClause);
1831 COPY_NODE_FIELD(rangetable);
1832 COPY_SCALAR_FIELD(unique);
1833 COPY_SCALAR_FIELD(primary);
1834 COPY_SCALAR_FIELD(isconstraint);
1839 static CreateFunctionStmt *
1840 _copyCreateFunctionStmt(CreateFunctionStmt *from)
1842 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
1844 COPY_SCALAR_FIELD(replace);
1845 COPY_NODE_FIELD(funcname);
1846 COPY_NODE_FIELD(argTypes);
1847 COPY_NODE_FIELD(returnType);
1848 COPY_NODE_FIELD(options);
1849 COPY_NODE_FIELD(withClause);
1854 static RemoveAggrStmt *
1855 _copyRemoveAggrStmt(RemoveAggrStmt *from)
1857 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1859 COPY_NODE_FIELD(aggname);
1860 COPY_NODE_FIELD(aggtype);
1861 COPY_SCALAR_FIELD(behavior);
1866 static RemoveFuncStmt *
1867 _copyRemoveFuncStmt(RemoveFuncStmt *from)
1869 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
1871 COPY_NODE_FIELD(funcname);
1872 COPY_NODE_FIELD(args);
1873 COPY_SCALAR_FIELD(behavior);
1878 static RemoveOperStmt *
1879 _copyRemoveOperStmt(RemoveOperStmt *from)
1881 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
1883 COPY_NODE_FIELD(opname);
1884 COPY_NODE_FIELD(args);
1885 COPY_SCALAR_FIELD(behavior);
1890 static RemoveOpClassStmt *
1891 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
1893 RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
1895 COPY_NODE_FIELD(opclassname);
1896 COPY_STRING_FIELD(amname);
1897 COPY_SCALAR_FIELD(behavior);
1903 _copyRenameStmt(RenameStmt *from)
1905 RenameStmt *newnode = makeNode(RenameStmt);
1907 COPY_NODE_FIELD(relation);
1908 COPY_NODE_FIELD(object);
1909 COPY_NODE_FIELD(objarg);
1910 COPY_STRING_FIELD(subname);
1911 COPY_STRING_FIELD(newname);
1912 COPY_SCALAR_FIELD(renameType);
1918 _copyRuleStmt(RuleStmt *from)
1920 RuleStmt *newnode = makeNode(RuleStmt);
1922 COPY_NODE_FIELD(relation);
1923 COPY_STRING_FIELD(rulename);
1924 COPY_NODE_FIELD(whereClause);
1925 COPY_SCALAR_FIELD(event);
1926 COPY_SCALAR_FIELD(instead);
1927 COPY_NODE_FIELD(actions);
1928 COPY_SCALAR_FIELD(replace);
1934 _copyNotifyStmt(NotifyStmt *from)
1936 NotifyStmt *newnode = makeNode(NotifyStmt);
1938 COPY_NODE_FIELD(relation);
1944 _copyListenStmt(ListenStmt *from)
1946 ListenStmt *newnode = makeNode(ListenStmt);
1948 COPY_NODE_FIELD(relation);
1953 static UnlistenStmt *
1954 _copyUnlistenStmt(UnlistenStmt *from)
1956 UnlistenStmt *newnode = makeNode(UnlistenStmt);
1958 COPY_NODE_FIELD(relation);
1963 static TransactionStmt *
1964 _copyTransactionStmt(TransactionStmt *from)
1966 TransactionStmt *newnode = makeNode(TransactionStmt);
1968 COPY_SCALAR_FIELD(kind);
1969 COPY_NODE_FIELD(options);
1974 static CompositeTypeStmt *
1975 _copyCompositeTypeStmt(CompositeTypeStmt *from)
1977 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
1979 COPY_NODE_FIELD(typevar);
1980 COPY_NODE_FIELD(coldeflist);
1986 _copyViewStmt(ViewStmt *from)
1988 ViewStmt *newnode = makeNode(ViewStmt);
1990 COPY_NODE_FIELD(view);
1991 COPY_NODE_FIELD(aliases);
1992 COPY_NODE_FIELD(query);
1993 COPY_SCALAR_FIELD(replace);
1999 _copyLoadStmt(LoadStmt *from)
2001 LoadStmt *newnode = makeNode(LoadStmt);
2003 COPY_STRING_FIELD(filename);
2008 static CreateDomainStmt *
2009 _copyCreateDomainStmt(CreateDomainStmt *from)
2011 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2013 COPY_NODE_FIELD(domainname);
2014 COPY_NODE_FIELD(typename);
2015 COPY_NODE_FIELD(constraints);
2020 static CreateOpClassStmt *
2021 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2023 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2025 COPY_NODE_FIELD(opclassname);
2026 COPY_STRING_FIELD(amname);
2027 COPY_NODE_FIELD(datatype);
2028 COPY_NODE_FIELD(items);
2029 COPY_SCALAR_FIELD(isDefault);
2034 static CreateOpClassItem *
2035 _copyCreateOpClassItem(CreateOpClassItem *from)
2037 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2039 COPY_SCALAR_FIELD(itemtype);
2040 COPY_NODE_FIELD(name);
2041 COPY_NODE_FIELD(args);
2042 COPY_SCALAR_FIELD(number);
2043 COPY_SCALAR_FIELD(recheck);
2044 COPY_NODE_FIELD(storedtype);
2049 static CreatedbStmt *
2050 _copyCreatedbStmt(CreatedbStmt *from)
2052 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2054 COPY_STRING_FIELD(dbname);
2055 COPY_NODE_FIELD(options);
2060 static AlterDatabaseSetStmt *
2061 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2063 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2065 COPY_STRING_FIELD(dbname);
2066 COPY_STRING_FIELD(variable);
2067 COPY_NODE_FIELD(value);
2073 _copyDropdbStmt(DropdbStmt *from)
2075 DropdbStmt *newnode = makeNode(DropdbStmt);
2077 COPY_STRING_FIELD(dbname);
2083 _copyVacuumStmt(VacuumStmt *from)
2085 VacuumStmt *newnode = makeNode(VacuumStmt);
2087 COPY_SCALAR_FIELD(vacuum);
2088 COPY_SCALAR_FIELD(full);
2089 COPY_SCALAR_FIELD(analyze);
2090 COPY_SCALAR_FIELD(freeze);
2091 COPY_SCALAR_FIELD(verbose);
2092 COPY_NODE_FIELD(relation);
2093 COPY_NODE_FIELD(va_cols);
2098 static ExplainStmt *
2099 _copyExplainStmt(ExplainStmt *from)
2101 ExplainStmt *newnode = makeNode(ExplainStmt);
2103 COPY_NODE_FIELD(query);
2104 COPY_SCALAR_FIELD(verbose);
2105 COPY_SCALAR_FIELD(analyze);
2110 static CreateSeqStmt *
2111 _copyCreateSeqStmt(CreateSeqStmt *from)
2113 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2115 COPY_NODE_FIELD(sequence);
2116 COPY_NODE_FIELD(options);
2121 static AlterSeqStmt *
2122 _copyAlterSeqStmt(AlterSeqStmt *from)
2124 AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
2126 COPY_NODE_FIELD(sequence);
2127 COPY_NODE_FIELD(options);
2132 static VariableSetStmt *
2133 _copyVariableSetStmt(VariableSetStmt *from)
2135 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2137 COPY_STRING_FIELD(name);
2138 COPY_NODE_FIELD(args);
2139 COPY_SCALAR_FIELD(is_local);
2144 static VariableShowStmt *
2145 _copyVariableShowStmt(VariableShowStmt *from)
2147 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2149 COPY_STRING_FIELD(name);
2154 static VariableResetStmt *
2155 _copyVariableResetStmt(VariableResetStmt *from)
2157 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2159 COPY_STRING_FIELD(name);
2164 static CreateTrigStmt *
2165 _copyCreateTrigStmt(CreateTrigStmt *from)
2167 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2169 COPY_STRING_FIELD(trigname);
2170 COPY_NODE_FIELD(relation);
2171 COPY_NODE_FIELD(funcname);
2172 COPY_NODE_FIELD(args);
2173 COPY_SCALAR_FIELD(before);
2174 COPY_SCALAR_FIELD(row);
2175 strcpy(newnode->actions, from->actions); /* in-line string field */
2176 COPY_SCALAR_FIELD(isconstraint);
2177 COPY_SCALAR_FIELD(deferrable);
2178 COPY_SCALAR_FIELD(initdeferred);
2179 COPY_NODE_FIELD(constrrel);
2184 static DropPropertyStmt *
2185 _copyDropPropertyStmt(DropPropertyStmt *from)
2187 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2189 COPY_NODE_FIELD(relation);
2190 COPY_STRING_FIELD(property);
2191 COPY_SCALAR_FIELD(removeType);
2192 COPY_SCALAR_FIELD(behavior);
2197 static CreatePLangStmt *
2198 _copyCreatePLangStmt(CreatePLangStmt *from)
2200 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2202 COPY_STRING_FIELD(plname);
2203 COPY_NODE_FIELD(plhandler);
2204 COPY_NODE_FIELD(plvalidator);
2205 COPY_SCALAR_FIELD(pltrusted);
2210 static DropPLangStmt *
2211 _copyDropPLangStmt(DropPLangStmt *from)
2213 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2215 COPY_STRING_FIELD(plname);
2216 COPY_SCALAR_FIELD(behavior);
2221 static CreateUserStmt *
2222 _copyCreateUserStmt(CreateUserStmt *from)
2224 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2226 COPY_STRING_FIELD(user);
2227 COPY_NODE_FIELD(options);
2232 static AlterUserStmt *
2233 _copyAlterUserStmt(AlterUserStmt *from)
2235 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2237 COPY_STRING_FIELD(user);
2238 COPY_NODE_FIELD(options);
2243 static AlterUserSetStmt *
2244 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2246 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2248 COPY_STRING_FIELD(user);
2249 COPY_STRING_FIELD(variable);
2250 COPY_NODE_FIELD(value);
2255 static DropUserStmt *
2256 _copyDropUserStmt(DropUserStmt *from)
2258 DropUserStmt *newnode = makeNode(DropUserStmt);
2260 COPY_NODE_FIELD(users);
2266 _copyLockStmt(LockStmt *from)
2268 LockStmt *newnode = makeNode(LockStmt);
2270 COPY_NODE_FIELD(relations);
2271 COPY_SCALAR_FIELD(mode);
2276 static ConstraintsSetStmt *
2277 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2279 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2281 COPY_NODE_FIELD(constraints);
2282 COPY_SCALAR_FIELD(deferred);
2287 static CreateGroupStmt *
2288 _copyCreateGroupStmt(CreateGroupStmt *from)
2290 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2292 COPY_STRING_FIELD(name);
2293 COPY_NODE_FIELD(options);
2298 static AlterGroupStmt *
2299 _copyAlterGroupStmt(AlterGroupStmt *from)
2301 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2303 COPY_STRING_FIELD(name);
2304 COPY_SCALAR_FIELD(action);
2305 COPY_NODE_FIELD(listUsers);
2310 static DropGroupStmt *
2311 _copyDropGroupStmt(DropGroupStmt *from)
2313 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2315 COPY_STRING_FIELD(name);
2320 static ReindexStmt *
2321 _copyReindexStmt(ReindexStmt *from)
2323 ReindexStmt *newnode = makeNode(ReindexStmt);
2325 COPY_SCALAR_FIELD(kind);
2326 COPY_NODE_FIELD(relation);
2327 COPY_STRING_FIELD(name);
2328 COPY_SCALAR_FIELD(force);
2329 COPY_SCALAR_FIELD(all);
2334 static CreateSchemaStmt *
2335 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2337 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2339 COPY_STRING_FIELD(schemaname);
2340 COPY_STRING_FIELD(authid);
2341 COPY_NODE_FIELD(schemaElts);
2346 static CreateConversionStmt *
2347 _copyCreateConversionStmt(CreateConversionStmt *from)
2349 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2351 COPY_NODE_FIELD(conversion_name);
2352 COPY_STRING_FIELD(for_encoding_name);
2353 COPY_STRING_FIELD(to_encoding_name);
2354 COPY_NODE_FIELD(func_name);
2355 COPY_SCALAR_FIELD(def);
2360 static CreateCastStmt *
2361 _copyCreateCastStmt(CreateCastStmt *from)
2363 CreateCastStmt *newnode = makeNode(CreateCastStmt);
2365 COPY_NODE_FIELD(sourcetype);
2366 COPY_NODE_FIELD(targettype);
2367 COPY_NODE_FIELD(func);
2368 COPY_SCALAR_FIELD(context);
2373 static DropCastStmt *
2374 _copyDropCastStmt(DropCastStmt *from)
2376 DropCastStmt *newnode = makeNode(DropCastStmt);
2378 COPY_NODE_FIELD(sourcetype);
2379 COPY_NODE_FIELD(targettype);
2380 COPY_SCALAR_FIELD(behavior);
2385 static PrepareStmt *
2386 _copyPrepareStmt(PrepareStmt *from)
2388 PrepareStmt *newnode = makeNode(PrepareStmt);
2390 COPY_STRING_FIELD(name);
2391 COPY_NODE_FIELD(argtypes);
2392 COPY_OIDLIST_FIELD(argtype_oids);
2393 COPY_NODE_FIELD(query);
2398 static ExecuteStmt *
2399 _copyExecuteStmt(ExecuteStmt *from)
2401 ExecuteStmt *newnode = makeNode(ExecuteStmt);
2403 COPY_STRING_FIELD(name);
2404 COPY_NODE_FIELD(into);
2405 COPY_NODE_FIELD(params);
2410 static DeallocateStmt *
2411 _copyDeallocateStmt(DeallocateStmt *from)
2413 DeallocateStmt *newnode = makeNode(DeallocateStmt);
2415 COPY_STRING_FIELD(name);
2421 /* ****************************************************************
2422 * pg_list.h copy functions
2423 * ****************************************************************
2427 _copyValue(Value *from)
2429 Value *newnode = makeNode(Value);
2431 /* See also _copyAConst when changing this code! */
2433 COPY_SCALAR_FIELD(type);
2437 COPY_SCALAR_FIELD(val.ival);
2442 COPY_STRING_FIELD(val.str);
2448 elog(ERROR, "unrecognized node type: %d",
2458 * Create a copy of a Node tree or list. This is a "deep" copy: all
2459 * substructure is copied too, recursively.
2462 copyObject(void *from)
2469 switch (nodeTag(from))
2475 retval = _copyPlan(from);
2478 retval = _copyResult(from);
2481 retval = _copyAppend(from);
2484 retval = _copyScan(from);
2487 retval = _copySeqScan(from);
2490 retval = _copyIndexScan(from);
2493 retval = _copyTidScan(from);
2495 case T_SubqueryScan:
2496 retval = _copySubqueryScan(from);
2498 case T_FunctionScan:
2499 retval = _copyFunctionScan(from);
2502 retval = _copyJoin(from);
2505 retval = _copyNestLoop(from);
2508 retval = _copyMergeJoin(from);
2511 retval = _copyHashJoin(from);
2514 retval = _copyMaterial(from);
2517 retval = _copySort(from);
2520 retval = _copyGroup(from);
2523 retval = _copyAgg(from);
2526 retval = _copyUnique(from);
2529 retval = _copyHash(from);
2532 retval = _copySetOp(from);
2535 retval = _copyLimit(from);
2542 retval = _copyResdom(from);
2545 retval = _copyAlias(from);
2548 retval = _copyRangeVar(from);
2551 retval = _copyVar(from);
2554 retval = _copyConst(from);
2557 retval = _copyParam(from);
2560 retval = _copyAggref(from);
2563 retval = _copyArrayRef(from);
2566 retval = _copyFuncExpr(from);
2569 retval = _copyOpExpr(from);
2571 case T_DistinctExpr:
2572 retval = _copyDistinctExpr(from);
2574 case T_ScalarArrayOpExpr:
2575 retval = _copyScalarArrayOpExpr(from);
2578 retval = _copyBoolExpr(from);
2581 retval = _copySubLink(from);
2584 retval = _copySubPlan(from);
2587 retval = _copyFieldSelect(from);
2590 retval = _copyRelabelType(from);
2593 retval = _copyCaseExpr(from);
2596 retval = _copyCaseWhen(from);
2599 retval = _copyArrayExpr(from);
2601 case T_CoalesceExpr:
2602 retval = _copyCoalesceExpr(from);
2605 retval = _copyNullIfExpr(from);
2608 retval = _copyNullTest(from);
2611 retval = _copyBooleanTest(from);
2613 case T_CoerceToDomain:
2614 retval = _copyCoerceToDomain(from);
2616 case T_CoerceToDomainValue:
2617 retval = _copyCoerceToDomainValue(from);
2619 case T_SetToDefault:
2620 retval = _copySetToDefault(from);
2623 retval = _copyTargetEntry(from);
2626 retval = _copyRangeTblRef(from);
2629 retval = _copyJoinExpr(from);
2632 retval = _copyFromExpr(from);
2639 retval = _copyPathKeyItem(from);
2641 case T_RestrictInfo:
2642 retval = _copyRestrictInfo(from);
2645 retval = _copyJoinInfo(from);
2647 case T_InClauseInfo:
2648 retval = _copyInClauseInfo(from);
2659 retval = _copyValue(from);
2668 /* rather ugly coding for speed... */
2669 /* Note the input list cannot be NIL if we got here. */
2670 newcell = makeNode(List);
2671 lfirst(newcell) = copyObject(lfirst(list));
2673 retval = (void *) newcell;
2676 foreach(oldl, lnext(list))
2678 newcell = makeNode(List);
2679 lfirst(newcell) = copyObject(lfirst(oldl));
2680 prev->next = newcell;
2691 retval = _copyQuery(from);
2694 retval = _copyInsertStmt(from);
2697 retval = _copyDeleteStmt(from);
2700 retval = _copyUpdateStmt(from);
2703 retval = _copySelectStmt(from);
2705 case T_SetOperationStmt:
2706 retval = _copySetOperationStmt(from);
2708 case T_AlterTableStmt:
2709 retval = _copyAlterTableStmt(from);
2711 case T_AlterDomainStmt:
2712 retval = _copyAlterDomainStmt(from);
2715 retval = _copyGrantStmt(from);
2717 case T_DeclareCursorStmt:
2718 retval = _copyDeclareCursorStmt(from);
2720 case T_ClosePortalStmt:
2721 retval = _copyClosePortalStmt(from);
2724 retval = _copyClusterStmt(from);
2727 retval = _copyCopyStmt(from);
2730 retval = _copyCreateStmt(from);
2733 retval = _copyInhRelation(from);
2736 retval = _copyDefineStmt(from);
2739 retval = _copyDropStmt(from);
2741 case T_TruncateStmt:
2742 retval = _copyTruncateStmt(from);
2745 retval = _copyCommentStmt(from);
2748 retval = _copyFetchStmt(from);
2751 retval = _copyIndexStmt(from);
2753 case T_CreateFunctionStmt:
2754 retval = _copyCreateFunctionStmt(from);
2756 case T_RemoveAggrStmt:
2757 retval = _copyRemoveAggrStmt(from);
2759 case T_RemoveFuncStmt:
2760 retval = _copyRemoveFuncStmt(from);
2762 case T_RemoveOperStmt:
2763 retval = _copyRemoveOperStmt(from);
2765 case T_RemoveOpClassStmt:
2766 retval = _copyRemoveOpClassStmt(from);
2769 retval = _copyRenameStmt(from);
2772 retval = _copyRuleStmt(from);
2775 retval = _copyNotifyStmt(from);
2778 retval = _copyListenStmt(from);
2780 case T_UnlistenStmt:
2781 retval = _copyUnlistenStmt(from);
2783 case T_TransactionStmt:
2784 retval = _copyTransactionStmt(from);
2786 case T_CompositeTypeStmt:
2787 retval = _copyCompositeTypeStmt(from);
2790 retval = _copyViewStmt(from);
2793 retval = _copyLoadStmt(from);
2795 case T_CreateDomainStmt:
2796 retval = _copyCreateDomainStmt(from);
2798 case T_CreateOpClassStmt:
2799 retval = _copyCreateOpClassStmt(from);
2801 case T_CreateOpClassItem:
2802 retval = _copyCreateOpClassItem(from);
2804 case T_CreatedbStmt:
2805 retval = _copyCreatedbStmt(from);
2807 case T_AlterDatabaseSetStmt:
2808 retval = _copyAlterDatabaseSetStmt(from);
2811 retval = _copyDropdbStmt(from);
2814 retval = _copyVacuumStmt(from);
2817 retval = _copyExplainStmt(from);
2819 case T_CreateSeqStmt:
2820 retval = _copyCreateSeqStmt(from);
2822 case T_AlterSeqStmt:
2823 retval = _copyAlterSeqStmt(from);
2825 case T_VariableSetStmt:
2826 retval = _copyVariableSetStmt(from);
2828 case T_VariableShowStmt:
2829 retval = _copyVariableShowStmt(from);
2831 case T_VariableResetStmt:
2832 retval = _copyVariableResetStmt(from);
2834 case T_CreateTrigStmt:
2835 retval = _copyCreateTrigStmt(from);
2837 case T_DropPropertyStmt:
2838 retval = _copyDropPropertyStmt(from);
2840 case T_CreatePLangStmt:
2841 retval = _copyCreatePLangStmt(from);
2843 case T_DropPLangStmt:
2844 retval = _copyDropPLangStmt(from);
2846 case T_CreateUserStmt:
2847 retval = _copyCreateUserStmt(from);
2849 case T_AlterUserStmt:
2850 retval = _copyAlterUserStmt(from);
2852 case T_AlterUserSetStmt:
2853 retval = _copyAlterUserSetStmt(from);
2855 case T_DropUserStmt:
2856 retval = _copyDropUserStmt(from);
2859 retval = _copyLockStmt(from);
2861 case T_ConstraintsSetStmt:
2862 retval = _copyConstraintsSetStmt(from);
2864 case T_CreateGroupStmt:
2865 retval = _copyCreateGroupStmt(from);
2867 case T_AlterGroupStmt:
2868 retval = _copyAlterGroupStmt(from);
2870 case T_DropGroupStmt:
2871 retval = _copyDropGroupStmt(from);
2874 retval = _copyReindexStmt(from);
2876 case T_CheckPointStmt:
2877 retval = (void *) makeNode(CheckPointStmt);
2879 case T_CreateSchemaStmt:
2880 retval = _copyCreateSchemaStmt(from);
2882 case T_CreateConversionStmt:
2883 retval = _copyCreateConversionStmt(from);
2885 case T_CreateCastStmt:
2886 retval = _copyCreateCastStmt(from);
2888 case T_DropCastStmt:
2889 retval = _copyDropCastStmt(from);
2892 retval = _copyPrepareStmt(from);
2895 retval = _copyExecuteStmt(from);
2897 case T_DeallocateStmt:
2898 retval = _copyDeallocateStmt(from);
2902 retval = _copyAExpr(from);
2905 retval = _copyColumnRef(from);
2908 retval = _copyParamRef(from);
2911 retval = _copyAConst(from);
2914 retval = _copyFuncCall(from);
2917 retval = _copyAIndices(from);
2919 case T_ExprFieldSelect:
2920 retval = _copyExprFieldSelect(from);
2923 retval = _copyResTarget(from);
2926 retval = _copyTypeCast(from);
2929 retval = _copySortBy(from);
2931 case T_RangeSubselect:
2932 retval = _copyRangeSubselect(from);
2934 case T_RangeFunction:
2935 retval = _copyRangeFunction(from);
2938 retval = _copyTypeName(from);
2941 retval = _copyIndexElem(from);
2944 retval = _copyColumnDef(from);
2947 retval = _copyConstraint(from);
2950 retval = _copyDefElem(from);
2952 case T_RangeTblEntry:
2953 retval = _copyRangeTblEntry(from);
2956 retval = _copySortClause(from);
2959 retval = _copyGroupClause(from);
2961 case T_FkConstraint:
2962 retval = _copyFkConstraint(from);
2965 retval = _copyPrivGrantee(from);
2967 case T_FuncWithArgs:
2968 retval = _copyFuncWithArgs(from);
2972 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
2973 retval = from; /* keep compiler quiet */