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.266 2003/11/09 21:30:36 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 /* this can become COPY_NODE_FIELD when intlists are normal objects: */
267 List *newstrat = NIL;
270 foreach(tmp, from->indxstrategy)
272 newstrat = lappend(newstrat, listCopy(lfirst(tmp)));
274 newnode->indxstrategy = newstrat;
276 COPY_SCALAR_FIELD(indxorderdir);
285 _copyTidScan(TidScan *from)
287 TidScan *newnode = makeNode(TidScan);
290 * copy node superclass fields
292 CopyScanFields((Scan *) from, (Scan *) newnode);
295 * copy remainder of node
297 COPY_NODE_FIELD(tideval);
305 static SubqueryScan *
306 _copySubqueryScan(SubqueryScan *from)
308 SubqueryScan *newnode = makeNode(SubqueryScan);
311 * copy node superclass fields
313 CopyScanFields((Scan *) from, (Scan *) newnode);
316 * copy remainder of node
318 COPY_NODE_FIELD(subplan);
326 static FunctionScan *
327 _copyFunctionScan(FunctionScan *from)
329 FunctionScan *newnode = makeNode(FunctionScan);
332 * copy node superclass fields
334 CopyScanFields((Scan *) from, (Scan *) newnode);
342 * This function copies the fields of the Join node. It is used by
343 * all the copy functions for classes which inherit from Join.
346 CopyJoinFields(Join *from, Join *newnode)
348 CopyPlanFields((Plan *) from, (Plan *) newnode);
350 COPY_SCALAR_FIELD(jointype);
351 COPY_NODE_FIELD(joinqual);
359 _copyJoin(Join *from)
361 Join *newnode = makeNode(Join);
364 * copy node superclass fields
366 CopyJoinFields(from, newnode);
376 _copyNestLoop(NestLoop *from)
378 NestLoop *newnode = makeNode(NestLoop);
381 * copy node superclass fields
383 CopyJoinFields((Join *) from, (Join *) newnode);
393 _copyMergeJoin(MergeJoin *from)
395 MergeJoin *newnode = makeNode(MergeJoin);
398 * copy node superclass fields
400 CopyJoinFields((Join *) from, (Join *) newnode);
403 * copy remainder of node
405 COPY_NODE_FIELD(mergeclauses);
414 _copyHashJoin(HashJoin *from)
416 HashJoin *newnode = makeNode(HashJoin);
419 * copy node superclass fields
421 CopyJoinFields((Join *) from, (Join *) newnode);
424 * copy remainder of node
426 COPY_NODE_FIELD(hashclauses);
436 _copyMaterial(Material *from)
438 Material *newnode = makeNode(Material);
441 * copy node superclass fields
443 CopyPlanFields((Plan *) from, (Plan *) newnode);
453 _copySort(Sort *from)
455 Sort *newnode = makeNode(Sort);
458 * copy node superclass fields
460 CopyPlanFields((Plan *) from, (Plan *) newnode);
462 COPY_SCALAR_FIELD(numCols);
463 COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
464 COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
474 _copyGroup(Group *from)
476 Group *newnode = makeNode(Group);
478 CopyPlanFields((Plan *) from, (Plan *) newnode);
480 COPY_SCALAR_FIELD(numCols);
481 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
492 Agg *newnode = makeNode(Agg);
494 CopyPlanFields((Plan *) from, (Plan *) newnode);
496 COPY_SCALAR_FIELD(aggstrategy);
497 COPY_SCALAR_FIELD(numCols);
498 if (from->numCols > 0)
499 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
500 COPY_SCALAR_FIELD(numGroups);
509 _copyUnique(Unique *from)
511 Unique *newnode = makeNode(Unique);
514 * copy node superclass fields
516 CopyPlanFields((Plan *) from, (Plan *) newnode);
519 * copy remainder of node
521 COPY_SCALAR_FIELD(numCols);
522 COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
531 _copyHash(Hash *from)
533 Hash *newnode = makeNode(Hash);
536 * copy node superclass fields
538 CopyPlanFields((Plan *) from, (Plan *) newnode);
541 * copy remainder of node
543 COPY_NODE_FIELD(hashkeys);
552 _copySetOp(SetOp *from)
554 SetOp *newnode = makeNode(SetOp);
557 * copy node superclass fields
559 CopyPlanFields((Plan *) from, (Plan *) newnode);
562 * copy remainder of node
564 COPY_SCALAR_FIELD(cmd);
565 COPY_SCALAR_FIELD(numCols);
566 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
567 COPY_SCALAR_FIELD(flagColIdx);
576 _copyLimit(Limit *from)
578 Limit *newnode = makeNode(Limit);
581 * copy node superclass fields
583 CopyPlanFields((Plan *) from, (Plan *) newnode);
586 * copy remainder of node
588 COPY_NODE_FIELD(limitOffset);
589 COPY_NODE_FIELD(limitCount);
594 /* ****************************************************************
595 * primnodes.h copy functions
596 * ****************************************************************
603 _copyResdom(Resdom *from)
605 Resdom *newnode = makeNode(Resdom);
607 COPY_SCALAR_FIELD(resno);
608 COPY_SCALAR_FIELD(restype);
609 COPY_SCALAR_FIELD(restypmod);
610 COPY_STRING_FIELD(resname);
611 COPY_SCALAR_FIELD(ressortgroupref);
612 COPY_SCALAR_FIELD(resorigtbl);
613 COPY_SCALAR_FIELD(resorigcol);
614 COPY_SCALAR_FIELD(resjunk);
623 _copyAlias(Alias *from)
625 Alias *newnode = makeNode(Alias);
627 COPY_STRING_FIELD(aliasname);
628 COPY_NODE_FIELD(colnames);
637 _copyRangeVar(RangeVar *from)
639 RangeVar *newnode = makeNode(RangeVar);
641 COPY_STRING_FIELD(catalogname);
642 COPY_STRING_FIELD(schemaname);
643 COPY_STRING_FIELD(relname);
644 COPY_SCALAR_FIELD(inhOpt);
645 COPY_SCALAR_FIELD(istemp);
646 COPY_NODE_FIELD(alias);
652 * We don't need a _copyExpr because Expr is an abstract supertype which
653 * should never actually get instantiated. Also, since it has no common
654 * fields except NodeTag, there's no need for a helper routine to factor
655 * out copying the common fields...
664 Var *newnode = makeNode(Var);
666 COPY_SCALAR_FIELD(varno);
667 COPY_SCALAR_FIELD(varattno);
668 COPY_SCALAR_FIELD(vartype);
669 COPY_SCALAR_FIELD(vartypmod);
670 COPY_SCALAR_FIELD(varlevelsup);
671 COPY_SCALAR_FIELD(varnoold);
672 COPY_SCALAR_FIELD(varoattno);
681 _copyConst(Const *from)
683 Const *newnode = makeNode(Const);
685 COPY_SCALAR_FIELD(consttype);
686 COPY_SCALAR_FIELD(constlen);
688 if (from->constbyval || from->constisnull)
691 * passed by value so just copy the datum. Also, don't try to copy
692 * struct when value is null!
694 newnode->constvalue = from->constvalue;
699 * passed by reference. We need a palloc'd copy.
701 newnode->constvalue = datumCopy(from->constvalue,
706 COPY_SCALAR_FIELD(constisnull);
707 COPY_SCALAR_FIELD(constbyval);
716 _copyParam(Param *from)
718 Param *newnode = makeNode(Param);
720 COPY_SCALAR_FIELD(paramkind);
721 COPY_SCALAR_FIELD(paramid);
722 COPY_STRING_FIELD(paramname);
723 COPY_SCALAR_FIELD(paramtype);
732 _copyAggref(Aggref *from)
734 Aggref *newnode = makeNode(Aggref);
736 COPY_SCALAR_FIELD(aggfnoid);
737 COPY_SCALAR_FIELD(aggtype);
738 COPY_NODE_FIELD(target);
739 COPY_SCALAR_FIELD(agglevelsup);
740 COPY_SCALAR_FIELD(aggstar);
741 COPY_SCALAR_FIELD(aggdistinct);
750 _copyArrayRef(ArrayRef *from)
752 ArrayRef *newnode = makeNode(ArrayRef);
754 COPY_SCALAR_FIELD(refrestype);
755 COPY_SCALAR_FIELD(refarraytype);
756 COPY_SCALAR_FIELD(refelemtype);
757 COPY_NODE_FIELD(refupperindexpr);
758 COPY_NODE_FIELD(reflowerindexpr);
759 COPY_NODE_FIELD(refexpr);
760 COPY_NODE_FIELD(refassgnexpr);
769 _copyFuncExpr(FuncExpr *from)
771 FuncExpr *newnode = makeNode(FuncExpr);
773 COPY_SCALAR_FIELD(funcid);
774 COPY_SCALAR_FIELD(funcresulttype);
775 COPY_SCALAR_FIELD(funcretset);
776 COPY_SCALAR_FIELD(funcformat);
777 COPY_NODE_FIELD(args);
786 _copyOpExpr(OpExpr *from)
788 OpExpr *newnode = makeNode(OpExpr);
790 COPY_SCALAR_FIELD(opno);
791 COPY_SCALAR_FIELD(opfuncid);
792 COPY_SCALAR_FIELD(opresulttype);
793 COPY_SCALAR_FIELD(opretset);
794 COPY_NODE_FIELD(args);
800 * _copyDistinctExpr (same as OpExpr)
802 static DistinctExpr *
803 _copyDistinctExpr(DistinctExpr *from)
805 DistinctExpr *newnode = makeNode(DistinctExpr);
807 COPY_SCALAR_FIELD(opno);
808 COPY_SCALAR_FIELD(opfuncid);
809 COPY_SCALAR_FIELD(opresulttype);
810 COPY_SCALAR_FIELD(opretset);
811 COPY_NODE_FIELD(args);
817 * _copyScalarArrayOpExpr
819 static ScalarArrayOpExpr *
820 _copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
822 ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
824 COPY_SCALAR_FIELD(opno);
825 COPY_SCALAR_FIELD(opfuncid);
826 COPY_SCALAR_FIELD(useOr);
827 COPY_NODE_FIELD(args);
836 _copyBoolExpr(BoolExpr *from)
838 BoolExpr *newnode = makeNode(BoolExpr);
840 COPY_SCALAR_FIELD(boolop);
841 COPY_NODE_FIELD(args);
850 _copySubLink(SubLink *from)
852 SubLink *newnode = makeNode(SubLink);
854 COPY_SCALAR_FIELD(subLinkType);
855 COPY_SCALAR_FIELD(useOr);
856 COPY_NODE_FIELD(lefthand);
857 COPY_NODE_FIELD(operName);
858 COPY_OIDLIST_FIELD(operOids);
859 COPY_NODE_FIELD(subselect);
868 _copySubPlan(SubPlan *from)
870 SubPlan *newnode = makeNode(SubPlan);
872 COPY_SCALAR_FIELD(subLinkType);
873 COPY_SCALAR_FIELD(useOr);
874 COPY_NODE_FIELD(exprs);
875 COPY_INTLIST_FIELD(paramIds);
876 COPY_NODE_FIELD(plan);
877 COPY_SCALAR_FIELD(plan_id);
878 COPY_NODE_FIELD(rtable);
879 COPY_SCALAR_FIELD(useHashTable);
880 COPY_SCALAR_FIELD(unknownEqFalse);
881 COPY_INTLIST_FIELD(setParam);
882 COPY_INTLIST_FIELD(parParam);
883 COPY_NODE_FIELD(args);
892 _copyFieldSelect(FieldSelect *from)
894 FieldSelect *newnode = makeNode(FieldSelect);
896 COPY_NODE_FIELD(arg);
897 COPY_SCALAR_FIELD(fieldnum);
898 COPY_SCALAR_FIELD(resulttype);
899 COPY_SCALAR_FIELD(resulttypmod);
908 _copyRelabelType(RelabelType *from)
910 RelabelType *newnode = makeNode(RelabelType);
912 COPY_NODE_FIELD(arg);
913 COPY_SCALAR_FIELD(resulttype);
914 COPY_SCALAR_FIELD(resulttypmod);
915 COPY_SCALAR_FIELD(relabelformat);
924 _copyCaseExpr(CaseExpr *from)
926 CaseExpr *newnode = makeNode(CaseExpr);
928 COPY_SCALAR_FIELD(casetype);
929 COPY_NODE_FIELD(arg);
930 COPY_NODE_FIELD(args);
931 COPY_NODE_FIELD(defresult);
940 _copyCaseWhen(CaseWhen *from)
942 CaseWhen *newnode = makeNode(CaseWhen);
944 COPY_NODE_FIELD(expr);
945 COPY_NODE_FIELD(result);
954 _copyArrayExpr(ArrayExpr *from)
956 ArrayExpr *newnode = makeNode(ArrayExpr);
958 COPY_SCALAR_FIELD(array_typeid);
959 COPY_SCALAR_FIELD(element_typeid);
960 COPY_NODE_FIELD(elements);
961 COPY_SCALAR_FIELD(multidims);
969 static CoalesceExpr *
970 _copyCoalesceExpr(CoalesceExpr *from)
972 CoalesceExpr *newnode = makeNode(CoalesceExpr);
974 COPY_SCALAR_FIELD(coalescetype);
975 COPY_NODE_FIELD(args);
981 * _copyNullIfExpr (same as OpExpr)
984 _copyNullIfExpr(NullIfExpr *from)
986 NullIfExpr *newnode = makeNode(NullIfExpr);
988 COPY_SCALAR_FIELD(opno);
989 COPY_SCALAR_FIELD(opfuncid);
990 COPY_SCALAR_FIELD(opresulttype);
991 COPY_SCALAR_FIELD(opretset);
992 COPY_NODE_FIELD(args);
1001 _copyNullTest(NullTest *from)
1003 NullTest *newnode = makeNode(NullTest);
1005 COPY_NODE_FIELD(arg);
1006 COPY_SCALAR_FIELD(nulltesttype);
1014 static BooleanTest *
1015 _copyBooleanTest(BooleanTest *from)
1017 BooleanTest *newnode = makeNode(BooleanTest);
1019 COPY_NODE_FIELD(arg);
1020 COPY_SCALAR_FIELD(booltesttype);
1026 * _copyCoerceToDomain
1028 static CoerceToDomain *
1029 _copyCoerceToDomain(CoerceToDomain *from)
1031 CoerceToDomain *newnode = makeNode(CoerceToDomain);
1033 COPY_NODE_FIELD(arg);
1034 COPY_SCALAR_FIELD(resulttype);
1035 COPY_SCALAR_FIELD(resulttypmod);
1036 COPY_SCALAR_FIELD(coercionformat);
1042 * _copyCoerceToDomainValue
1044 static CoerceToDomainValue *
1045 _copyCoerceToDomainValue(CoerceToDomainValue *from)
1047 CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1049 COPY_SCALAR_FIELD(typeId);
1050 COPY_SCALAR_FIELD(typeMod);
1058 static SetToDefault *
1059 _copySetToDefault(SetToDefault *from)
1061 SetToDefault *newnode = makeNode(SetToDefault);
1063 COPY_SCALAR_FIELD(typeId);
1064 COPY_SCALAR_FIELD(typeMod);
1072 static TargetEntry *
1073 _copyTargetEntry(TargetEntry *from)
1075 TargetEntry *newnode = makeNode(TargetEntry);
1077 COPY_NODE_FIELD(resdom);
1078 COPY_NODE_FIELD(expr);
1086 static RangeTblRef *
1087 _copyRangeTblRef(RangeTblRef *from)
1089 RangeTblRef *newnode = makeNode(RangeTblRef);
1091 COPY_SCALAR_FIELD(rtindex);
1100 _copyJoinExpr(JoinExpr *from)
1102 JoinExpr *newnode = makeNode(JoinExpr);
1104 COPY_SCALAR_FIELD(jointype);
1105 COPY_SCALAR_FIELD(isNatural);
1106 COPY_NODE_FIELD(larg);
1107 COPY_NODE_FIELD(rarg);
1108 COPY_NODE_FIELD(using);
1109 COPY_NODE_FIELD(quals);
1110 COPY_NODE_FIELD(alias);
1111 COPY_SCALAR_FIELD(rtindex);
1120 _copyFromExpr(FromExpr *from)
1122 FromExpr *newnode = makeNode(FromExpr);
1124 COPY_NODE_FIELD(fromlist);
1125 COPY_NODE_FIELD(quals);
1130 /* ****************************************************************
1131 * relation.h copy functions
1133 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1134 * There are some subsidiary structs that are useful to copy, though.
1135 * ****************************************************************
1141 static PathKeyItem *
1142 _copyPathKeyItem(PathKeyItem *from)
1144 PathKeyItem *newnode = makeNode(PathKeyItem);
1146 COPY_NODE_FIELD(key);
1147 COPY_SCALAR_FIELD(sortop);
1155 static RestrictInfo *
1156 _copyRestrictInfo(RestrictInfo *from)
1158 RestrictInfo *newnode = makeNode(RestrictInfo);
1160 COPY_NODE_FIELD(clause);
1161 COPY_SCALAR_FIELD(ispusheddown);
1162 COPY_NODE_FIELD(subclauseindices); /* XXX probably bad */
1163 COPY_SCALAR_FIELD(eval_cost);
1164 COPY_SCALAR_FIELD(this_selec);
1165 COPY_BITMAPSET_FIELD(left_relids);
1166 COPY_BITMAPSET_FIELD(right_relids);
1167 COPY_SCALAR_FIELD(mergejoinoperator);
1168 COPY_SCALAR_FIELD(left_sortop);
1169 COPY_SCALAR_FIELD(right_sortop);
1172 * Do not copy pathkeys, since they'd not be canonical in a copied
1175 newnode->left_pathkey = NIL;
1176 newnode->right_pathkey = NIL;
1178 COPY_SCALAR_FIELD(left_mergescansel);
1179 COPY_SCALAR_FIELD(right_mergescansel);
1180 COPY_SCALAR_FIELD(hashjoinoperator);
1181 COPY_SCALAR_FIELD(left_bucketsize);
1182 COPY_SCALAR_FIELD(right_bucketsize);
1191 _copyJoinInfo(JoinInfo *from)
1193 JoinInfo *newnode = makeNode(JoinInfo);
1195 COPY_BITMAPSET_FIELD(unjoined_relids);
1196 COPY_NODE_FIELD(jinfo_restrictinfo);
1204 static InClauseInfo *
1205 _copyInClauseInfo(InClauseInfo *from)
1207 InClauseInfo *newnode = makeNode(InClauseInfo);
1209 COPY_BITMAPSET_FIELD(lefthand);
1210 COPY_BITMAPSET_FIELD(righthand);
1211 COPY_NODE_FIELD(sub_targetlist);
1216 /* ****************************************************************
1217 * parsenodes.h copy functions
1218 * ****************************************************************
1221 static RangeTblEntry *
1222 _copyRangeTblEntry(RangeTblEntry *from)
1224 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1226 COPY_SCALAR_FIELD(rtekind);
1227 COPY_SCALAR_FIELD(relid);
1228 COPY_NODE_FIELD(subquery);
1229 COPY_NODE_FIELD(funcexpr);
1230 COPY_NODE_FIELD(coldeflist);
1231 COPY_SCALAR_FIELD(jointype);
1232 COPY_NODE_FIELD(joinaliasvars);
1233 COPY_NODE_FIELD(alias);
1234 COPY_NODE_FIELD(eref);
1235 COPY_SCALAR_FIELD(inh);
1236 COPY_SCALAR_FIELD(inFromCl);
1237 COPY_SCALAR_FIELD(checkForRead);
1238 COPY_SCALAR_FIELD(checkForWrite);
1239 COPY_SCALAR_FIELD(checkAsUser);
1244 static FkConstraint *
1245 _copyFkConstraint(FkConstraint *from)
1247 FkConstraint *newnode = makeNode(FkConstraint);
1249 COPY_STRING_FIELD(constr_name);
1250 COPY_NODE_FIELD(pktable);
1251 COPY_NODE_FIELD(fk_attrs);
1252 COPY_NODE_FIELD(pk_attrs);
1253 COPY_SCALAR_FIELD(fk_matchtype);
1254 COPY_SCALAR_FIELD(fk_upd_action);
1255 COPY_SCALAR_FIELD(fk_del_action);
1256 COPY_SCALAR_FIELD(deferrable);
1257 COPY_SCALAR_FIELD(initdeferred);
1258 COPY_SCALAR_FIELD(skip_validation);
1264 _copySortClause(SortClause *from)
1266 SortClause *newnode = makeNode(SortClause);
1268 COPY_SCALAR_FIELD(tleSortGroupRef);
1269 COPY_SCALAR_FIELD(sortop);
1274 static GroupClause *
1275 _copyGroupClause(GroupClause *from)
1277 GroupClause *newnode = makeNode(GroupClause);
1279 COPY_SCALAR_FIELD(tleSortGroupRef);
1280 COPY_SCALAR_FIELD(sortop);
1286 _copyAExpr(A_Expr *from)
1288 A_Expr *newnode = makeNode(A_Expr);
1290 COPY_SCALAR_FIELD(kind);
1291 COPY_NODE_FIELD(name);
1292 COPY_NODE_FIELD(lexpr);
1293 COPY_NODE_FIELD(rexpr);
1299 _copyColumnRef(ColumnRef *from)
1301 ColumnRef *newnode = makeNode(ColumnRef);
1303 COPY_NODE_FIELD(fields);
1304 COPY_NODE_FIELD(indirection);
1310 _copyParamRef(ParamRef *from)
1312 ParamRef *newnode = makeNode(ParamRef);
1314 COPY_SCALAR_FIELD(number);
1315 COPY_NODE_FIELD(fields);
1316 COPY_NODE_FIELD(indirection);
1322 _copyAConst(A_Const *from)
1324 A_Const *newnode = makeNode(A_Const);
1326 /* This part must duplicate _copyValue */
1327 COPY_SCALAR_FIELD(val.type);
1328 switch (from->val.type)
1331 COPY_SCALAR_FIELD(val.val.ival);
1336 COPY_STRING_FIELD(val.val.str);
1342 elog(ERROR, "unrecognized node type: %d",
1343 (int) from->val.type);
1347 COPY_NODE_FIELD(typename);
1353 _copyFuncCall(FuncCall *from)
1355 FuncCall *newnode = makeNode(FuncCall);
1357 COPY_NODE_FIELD(funcname);
1358 COPY_NODE_FIELD(args);
1359 COPY_SCALAR_FIELD(agg_star);
1360 COPY_SCALAR_FIELD(agg_distinct);
1366 _copyAIndices(A_Indices *from)
1368 A_Indices *newnode = makeNode(A_Indices);
1370 COPY_NODE_FIELD(lidx);
1371 COPY_NODE_FIELD(uidx);
1376 static ExprFieldSelect *
1377 _copyExprFieldSelect(ExprFieldSelect *from)
1379 ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
1381 COPY_NODE_FIELD(arg);
1382 COPY_NODE_FIELD(fields);
1383 COPY_NODE_FIELD(indirection);
1389 _copyResTarget(ResTarget *from)
1391 ResTarget *newnode = makeNode(ResTarget);
1393 COPY_STRING_FIELD(name);
1394 COPY_NODE_FIELD(indirection);
1395 COPY_NODE_FIELD(val);
1401 _copyTypeName(TypeName *from)
1403 TypeName *newnode = makeNode(TypeName);
1405 COPY_NODE_FIELD(names);
1406 COPY_SCALAR_FIELD(typeid);
1407 COPY_SCALAR_FIELD(timezone);
1408 COPY_SCALAR_FIELD(setof);
1409 COPY_SCALAR_FIELD(pct_type);
1410 COPY_SCALAR_FIELD(typmod);
1411 COPY_NODE_FIELD(arrayBounds);
1417 _copySortBy(SortBy *from)
1419 SortBy *newnode = makeNode(SortBy);
1421 COPY_SCALAR_FIELD(sortby_kind);
1422 COPY_NODE_FIELD(useOp);
1423 COPY_NODE_FIELD(node);
1428 static RangeSubselect *
1429 _copyRangeSubselect(RangeSubselect *from)
1431 RangeSubselect *newnode = makeNode(RangeSubselect);
1433 COPY_NODE_FIELD(subquery);
1434 COPY_NODE_FIELD(alias);
1439 static RangeFunction *
1440 _copyRangeFunction(RangeFunction *from)
1442 RangeFunction *newnode = makeNode(RangeFunction);
1444 COPY_NODE_FIELD(funccallnode);
1445 COPY_NODE_FIELD(alias);
1446 COPY_NODE_FIELD(coldeflist);
1452 _copyTypeCast(TypeCast *from)
1454 TypeCast *newnode = makeNode(TypeCast);
1456 COPY_NODE_FIELD(arg);
1457 COPY_NODE_FIELD(typename);
1463 _copyIndexElem(IndexElem *from)
1465 IndexElem *newnode = makeNode(IndexElem);
1467 COPY_STRING_FIELD(name);
1468 COPY_NODE_FIELD(expr);
1469 COPY_NODE_FIELD(opclass);
1475 _copyColumnDef(ColumnDef *from)
1477 ColumnDef *newnode = makeNode(ColumnDef);
1479 COPY_STRING_FIELD(colname);
1480 COPY_NODE_FIELD(typename);
1481 COPY_SCALAR_FIELD(inhcount);
1482 COPY_SCALAR_FIELD(is_local);
1483 COPY_SCALAR_FIELD(is_not_null);
1484 COPY_NODE_FIELD(raw_default);
1485 COPY_STRING_FIELD(cooked_default);
1486 COPY_NODE_FIELD(constraints);
1487 COPY_NODE_FIELD(support);
1493 _copyConstraint(Constraint *from)
1495 Constraint *newnode = makeNode(Constraint);
1497 COPY_SCALAR_FIELD(contype);
1498 COPY_STRING_FIELD(name);
1499 COPY_NODE_FIELD(raw_expr);
1500 COPY_STRING_FIELD(cooked_expr);
1501 COPY_NODE_FIELD(keys);
1507 _copyDefElem(DefElem *from)
1509 DefElem *newnode = makeNode(DefElem);
1511 COPY_STRING_FIELD(defname);
1512 COPY_NODE_FIELD(arg);
1518 _copyQuery(Query *from)
1520 Query *newnode = makeNode(Query);
1522 COPY_SCALAR_FIELD(commandType);
1523 COPY_SCALAR_FIELD(querySource);
1524 COPY_SCALAR_FIELD(canSetTag);
1525 COPY_NODE_FIELD(utilityStmt);
1526 COPY_SCALAR_FIELD(resultRelation);
1527 COPY_NODE_FIELD(into);
1528 COPY_SCALAR_FIELD(hasAggs);
1529 COPY_SCALAR_FIELD(hasSubLinks);
1530 COPY_NODE_FIELD(rtable);
1531 COPY_NODE_FIELD(jointree);
1532 COPY_INTLIST_FIELD(rowMarks);
1533 COPY_NODE_FIELD(targetList);
1534 COPY_NODE_FIELD(groupClause);
1535 COPY_NODE_FIELD(havingQual);
1536 COPY_NODE_FIELD(distinctClause);
1537 COPY_NODE_FIELD(sortClause);
1538 COPY_NODE_FIELD(limitOffset);
1539 COPY_NODE_FIELD(limitCount);
1540 COPY_NODE_FIELD(setOperations);
1541 COPY_INTLIST_FIELD(resultRelations);
1542 COPY_NODE_FIELD(in_info_list);
1543 COPY_SCALAR_FIELD(hasJoinRTEs);
1546 * We do not copy the other planner internal fields: base_rel_list,
1547 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. That
1548 * would get us into copying RelOptInfo/Path trees, which we don't
1549 * want to do. It is necessary to copy in_info_list and hasJoinRTEs
1550 * for the benefit of inheritance_planner(), which may try to copy a
1551 * Query in which these are already set.
1558 _copyInsertStmt(InsertStmt *from)
1560 InsertStmt *newnode = makeNode(InsertStmt);
1562 COPY_NODE_FIELD(relation);
1563 COPY_NODE_FIELD(cols);
1564 COPY_NODE_FIELD(targetList);
1565 COPY_NODE_FIELD(selectStmt);
1571 _copyDeleteStmt(DeleteStmt *from)
1573 DeleteStmt *newnode = makeNode(DeleteStmt);
1575 COPY_NODE_FIELD(relation);
1576 COPY_NODE_FIELD(whereClause);
1582 _copyUpdateStmt(UpdateStmt *from)
1584 UpdateStmt *newnode = makeNode(UpdateStmt);
1586 COPY_NODE_FIELD(relation);
1587 COPY_NODE_FIELD(targetList);
1588 COPY_NODE_FIELD(whereClause);
1589 COPY_NODE_FIELD(fromClause);
1595 _copySelectStmt(SelectStmt *from)
1597 SelectStmt *newnode = makeNode(SelectStmt);
1599 COPY_NODE_FIELD(distinctClause);
1600 COPY_NODE_FIELD(into);
1601 COPY_NODE_FIELD(intoColNames);
1602 COPY_NODE_FIELD(targetList);
1603 COPY_NODE_FIELD(fromClause);
1604 COPY_NODE_FIELD(whereClause);
1605 COPY_NODE_FIELD(groupClause);
1606 COPY_NODE_FIELD(havingClause);
1607 COPY_NODE_FIELD(sortClause);
1608 COPY_NODE_FIELD(limitOffset);
1609 COPY_NODE_FIELD(limitCount);
1610 COPY_NODE_FIELD(forUpdate);
1611 COPY_SCALAR_FIELD(op);
1612 COPY_SCALAR_FIELD(all);
1613 COPY_NODE_FIELD(larg);
1614 COPY_NODE_FIELD(rarg);
1619 static SetOperationStmt *
1620 _copySetOperationStmt(SetOperationStmt *from)
1622 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1624 COPY_SCALAR_FIELD(op);
1625 COPY_SCALAR_FIELD(all);
1626 COPY_NODE_FIELD(larg);
1627 COPY_NODE_FIELD(rarg);
1628 COPY_OIDLIST_FIELD(colTypes);
1633 static AlterTableStmt *
1634 _copyAlterTableStmt(AlterTableStmt *from)
1636 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1638 COPY_SCALAR_FIELD(subtype);
1639 COPY_NODE_FIELD(relation);
1640 COPY_STRING_FIELD(name);
1641 COPY_NODE_FIELD(def);
1642 COPY_SCALAR_FIELD(behavior);
1647 static AlterDomainStmt *
1648 _copyAlterDomainStmt(AlterDomainStmt *from)
1650 AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1652 COPY_SCALAR_FIELD(subtype);
1653 COPY_NODE_FIELD(typename);
1654 COPY_STRING_FIELD(name);
1655 COPY_NODE_FIELD(def);
1656 COPY_SCALAR_FIELD(behavior);
1662 _copyGrantStmt(GrantStmt *from)
1664 GrantStmt *newnode = makeNode(GrantStmt);
1666 COPY_SCALAR_FIELD(is_grant);
1667 COPY_SCALAR_FIELD(objtype);
1668 COPY_NODE_FIELD(objects);
1669 COPY_INTLIST_FIELD(privileges);
1670 COPY_NODE_FIELD(grantees);
1671 COPY_SCALAR_FIELD(grant_option);
1672 COPY_SCALAR_FIELD(behavior);
1677 static PrivGrantee *
1678 _copyPrivGrantee(PrivGrantee *from)
1680 PrivGrantee *newnode = makeNode(PrivGrantee);
1682 COPY_STRING_FIELD(username);
1683 COPY_STRING_FIELD(groupname);
1688 static FuncWithArgs *
1689 _copyFuncWithArgs(FuncWithArgs *from)
1691 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1693 COPY_NODE_FIELD(funcname);
1694 COPY_NODE_FIELD(funcargs);
1699 static DeclareCursorStmt *
1700 _copyDeclareCursorStmt(DeclareCursorStmt *from)
1702 DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
1704 COPY_STRING_FIELD(portalname);
1705 COPY_SCALAR_FIELD(options);
1706 COPY_NODE_FIELD(query);
1711 static ClosePortalStmt *
1712 _copyClosePortalStmt(ClosePortalStmt *from)
1714 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1716 COPY_STRING_FIELD(portalname);
1721 static ClusterStmt *
1722 _copyClusterStmt(ClusterStmt *from)
1724 ClusterStmt *newnode = makeNode(ClusterStmt);
1726 COPY_NODE_FIELD(relation);
1727 COPY_STRING_FIELD(indexname);
1733 _copyCopyStmt(CopyStmt *from)
1735 CopyStmt *newnode = makeNode(CopyStmt);
1737 COPY_NODE_FIELD(relation);
1738 COPY_NODE_FIELD(attlist);
1739 COPY_SCALAR_FIELD(is_from);
1740 COPY_STRING_FIELD(filename);
1741 COPY_NODE_FIELD(options);
1747 _copyCreateStmt(CreateStmt *from)
1749 CreateStmt *newnode = makeNode(CreateStmt);
1751 COPY_NODE_FIELD(relation);
1752 COPY_NODE_FIELD(tableElts);
1753 COPY_NODE_FIELD(inhRelations);
1754 COPY_NODE_FIELD(constraints);
1755 COPY_SCALAR_FIELD(hasoids);
1756 COPY_SCALAR_FIELD(oncommit);
1761 static InhRelation *
1762 _copyInhRelation(InhRelation *from)
1764 InhRelation *newnode = makeNode(InhRelation);
1766 COPY_NODE_FIELD(relation);
1767 COPY_SCALAR_FIELD(including_defaults);
1773 _copyDefineStmt(DefineStmt *from)
1775 DefineStmt *newnode = makeNode(DefineStmt);
1777 COPY_SCALAR_FIELD(kind);
1778 COPY_NODE_FIELD(defnames);
1779 COPY_NODE_FIELD(definition);
1785 _copyDropStmt(DropStmt *from)
1787 DropStmt *newnode = makeNode(DropStmt);
1789 COPY_NODE_FIELD(objects);
1790 COPY_SCALAR_FIELD(removeType);
1791 COPY_SCALAR_FIELD(behavior);
1796 static TruncateStmt *
1797 _copyTruncateStmt(TruncateStmt *from)
1799 TruncateStmt *newnode = makeNode(TruncateStmt);
1801 COPY_NODE_FIELD(relation);
1806 static CommentStmt *
1807 _copyCommentStmt(CommentStmt *from)
1809 CommentStmt *newnode = makeNode(CommentStmt);
1811 COPY_SCALAR_FIELD(objtype);
1812 COPY_NODE_FIELD(objname);
1813 COPY_NODE_FIELD(objargs);
1814 COPY_STRING_FIELD(comment);
1820 _copyFetchStmt(FetchStmt *from)
1822 FetchStmt *newnode = makeNode(FetchStmt);
1824 COPY_SCALAR_FIELD(direction);
1825 COPY_SCALAR_FIELD(howMany);
1826 COPY_STRING_FIELD(portalname);
1827 COPY_SCALAR_FIELD(ismove);
1833 _copyIndexStmt(IndexStmt *from)
1835 IndexStmt *newnode = makeNode(IndexStmt);
1837 COPY_STRING_FIELD(idxname);
1838 COPY_NODE_FIELD(relation);
1839 COPY_STRING_FIELD(accessMethod);
1840 COPY_NODE_FIELD(indexParams);
1841 COPY_NODE_FIELD(whereClause);
1842 COPY_NODE_FIELD(rangetable);
1843 COPY_SCALAR_FIELD(unique);
1844 COPY_SCALAR_FIELD(primary);
1845 COPY_SCALAR_FIELD(isconstraint);
1850 static CreateFunctionStmt *
1851 _copyCreateFunctionStmt(CreateFunctionStmt *from)
1853 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
1855 COPY_SCALAR_FIELD(replace);
1856 COPY_NODE_FIELD(funcname);
1857 COPY_NODE_FIELD(argTypes);
1858 COPY_NODE_FIELD(returnType);
1859 COPY_NODE_FIELD(options);
1860 COPY_NODE_FIELD(withClause);
1865 static RemoveAggrStmt *
1866 _copyRemoveAggrStmt(RemoveAggrStmt *from)
1868 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1870 COPY_NODE_FIELD(aggname);
1871 COPY_NODE_FIELD(aggtype);
1872 COPY_SCALAR_FIELD(behavior);
1877 static RemoveFuncStmt *
1878 _copyRemoveFuncStmt(RemoveFuncStmt *from)
1880 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
1882 COPY_NODE_FIELD(funcname);
1883 COPY_NODE_FIELD(args);
1884 COPY_SCALAR_FIELD(behavior);
1889 static RemoveOperStmt *
1890 _copyRemoveOperStmt(RemoveOperStmt *from)
1892 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
1894 COPY_NODE_FIELD(opname);
1895 COPY_NODE_FIELD(args);
1896 COPY_SCALAR_FIELD(behavior);
1901 static RemoveOpClassStmt *
1902 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
1904 RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
1906 COPY_NODE_FIELD(opclassname);
1907 COPY_STRING_FIELD(amname);
1908 COPY_SCALAR_FIELD(behavior);
1914 _copyRenameStmt(RenameStmt *from)
1916 RenameStmt *newnode = makeNode(RenameStmt);
1918 COPY_NODE_FIELD(relation);
1919 COPY_NODE_FIELD(object);
1920 COPY_NODE_FIELD(objarg);
1921 COPY_STRING_FIELD(subname);
1922 COPY_STRING_FIELD(newname);
1923 COPY_SCALAR_FIELD(renameType);
1929 _copyRuleStmt(RuleStmt *from)
1931 RuleStmt *newnode = makeNode(RuleStmt);
1933 COPY_NODE_FIELD(relation);
1934 COPY_STRING_FIELD(rulename);
1935 COPY_NODE_FIELD(whereClause);
1936 COPY_SCALAR_FIELD(event);
1937 COPY_SCALAR_FIELD(instead);
1938 COPY_NODE_FIELD(actions);
1939 COPY_SCALAR_FIELD(replace);
1945 _copyNotifyStmt(NotifyStmt *from)
1947 NotifyStmt *newnode = makeNode(NotifyStmt);
1949 COPY_NODE_FIELD(relation);
1955 _copyListenStmt(ListenStmt *from)
1957 ListenStmt *newnode = makeNode(ListenStmt);
1959 COPY_NODE_FIELD(relation);
1964 static UnlistenStmt *
1965 _copyUnlistenStmt(UnlistenStmt *from)
1967 UnlistenStmt *newnode = makeNode(UnlistenStmt);
1969 COPY_NODE_FIELD(relation);
1974 static TransactionStmt *
1975 _copyTransactionStmt(TransactionStmt *from)
1977 TransactionStmt *newnode = makeNode(TransactionStmt);
1979 COPY_SCALAR_FIELD(kind);
1980 COPY_NODE_FIELD(options);
1985 static CompositeTypeStmt *
1986 _copyCompositeTypeStmt(CompositeTypeStmt *from)
1988 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
1990 COPY_NODE_FIELD(typevar);
1991 COPY_NODE_FIELD(coldeflist);
1997 _copyViewStmt(ViewStmt *from)
1999 ViewStmt *newnode = makeNode(ViewStmt);
2001 COPY_NODE_FIELD(view);
2002 COPY_NODE_FIELD(aliases);
2003 COPY_NODE_FIELD(query);
2004 COPY_SCALAR_FIELD(replace);
2010 _copyLoadStmt(LoadStmt *from)
2012 LoadStmt *newnode = makeNode(LoadStmt);
2014 COPY_STRING_FIELD(filename);
2019 static CreateDomainStmt *
2020 _copyCreateDomainStmt(CreateDomainStmt *from)
2022 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2024 COPY_NODE_FIELD(domainname);
2025 COPY_NODE_FIELD(typename);
2026 COPY_NODE_FIELD(constraints);
2031 static CreateOpClassStmt *
2032 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2034 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2036 COPY_NODE_FIELD(opclassname);
2037 COPY_STRING_FIELD(amname);
2038 COPY_NODE_FIELD(datatype);
2039 COPY_NODE_FIELD(items);
2040 COPY_SCALAR_FIELD(isDefault);
2045 static CreateOpClassItem *
2046 _copyCreateOpClassItem(CreateOpClassItem *from)
2048 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2050 COPY_SCALAR_FIELD(itemtype);
2051 COPY_NODE_FIELD(name);
2052 COPY_NODE_FIELD(args);
2053 COPY_SCALAR_FIELD(number);
2054 COPY_SCALAR_FIELD(recheck);
2055 COPY_NODE_FIELD(storedtype);
2060 static CreatedbStmt *
2061 _copyCreatedbStmt(CreatedbStmt *from)
2063 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2065 COPY_STRING_FIELD(dbname);
2066 COPY_NODE_FIELD(options);
2071 static AlterDatabaseSetStmt *
2072 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2074 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2076 COPY_STRING_FIELD(dbname);
2077 COPY_STRING_FIELD(variable);
2078 COPY_NODE_FIELD(value);
2084 _copyDropdbStmt(DropdbStmt *from)
2086 DropdbStmt *newnode = makeNode(DropdbStmt);
2088 COPY_STRING_FIELD(dbname);
2094 _copyVacuumStmt(VacuumStmt *from)
2096 VacuumStmt *newnode = makeNode(VacuumStmt);
2098 COPY_SCALAR_FIELD(vacuum);
2099 COPY_SCALAR_FIELD(full);
2100 COPY_SCALAR_FIELD(analyze);
2101 COPY_SCALAR_FIELD(freeze);
2102 COPY_SCALAR_FIELD(verbose);
2103 COPY_NODE_FIELD(relation);
2104 COPY_NODE_FIELD(va_cols);
2109 static ExplainStmt *
2110 _copyExplainStmt(ExplainStmt *from)
2112 ExplainStmt *newnode = makeNode(ExplainStmt);
2114 COPY_NODE_FIELD(query);
2115 COPY_SCALAR_FIELD(verbose);
2116 COPY_SCALAR_FIELD(analyze);
2121 static CreateSeqStmt *
2122 _copyCreateSeqStmt(CreateSeqStmt *from)
2124 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2126 COPY_NODE_FIELD(sequence);
2127 COPY_NODE_FIELD(options);
2132 static AlterSeqStmt *
2133 _copyAlterSeqStmt(AlterSeqStmt *from)
2135 AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
2137 COPY_NODE_FIELD(sequence);
2138 COPY_NODE_FIELD(options);
2143 static VariableSetStmt *
2144 _copyVariableSetStmt(VariableSetStmt *from)
2146 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2148 COPY_STRING_FIELD(name);
2149 COPY_NODE_FIELD(args);
2150 COPY_SCALAR_FIELD(is_local);
2155 static VariableShowStmt *
2156 _copyVariableShowStmt(VariableShowStmt *from)
2158 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2160 COPY_STRING_FIELD(name);
2165 static VariableResetStmt *
2166 _copyVariableResetStmt(VariableResetStmt *from)
2168 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2170 COPY_STRING_FIELD(name);
2175 static CreateTrigStmt *
2176 _copyCreateTrigStmt(CreateTrigStmt *from)
2178 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2180 COPY_STRING_FIELD(trigname);
2181 COPY_NODE_FIELD(relation);
2182 COPY_NODE_FIELD(funcname);
2183 COPY_NODE_FIELD(args);
2184 COPY_SCALAR_FIELD(before);
2185 COPY_SCALAR_FIELD(row);
2186 strcpy(newnode->actions, from->actions); /* in-line string field */
2187 COPY_SCALAR_FIELD(isconstraint);
2188 COPY_SCALAR_FIELD(deferrable);
2189 COPY_SCALAR_FIELD(initdeferred);
2190 COPY_NODE_FIELD(constrrel);
2195 static DropPropertyStmt *
2196 _copyDropPropertyStmt(DropPropertyStmt *from)
2198 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2200 COPY_NODE_FIELD(relation);
2201 COPY_STRING_FIELD(property);
2202 COPY_SCALAR_FIELD(removeType);
2203 COPY_SCALAR_FIELD(behavior);
2208 static CreatePLangStmt *
2209 _copyCreatePLangStmt(CreatePLangStmt *from)
2211 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2213 COPY_STRING_FIELD(plname);
2214 COPY_NODE_FIELD(plhandler);
2215 COPY_NODE_FIELD(plvalidator);
2216 COPY_SCALAR_FIELD(pltrusted);
2221 static DropPLangStmt *
2222 _copyDropPLangStmt(DropPLangStmt *from)
2224 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2226 COPY_STRING_FIELD(plname);
2227 COPY_SCALAR_FIELD(behavior);
2232 static CreateUserStmt *
2233 _copyCreateUserStmt(CreateUserStmt *from)
2235 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2237 COPY_STRING_FIELD(user);
2238 COPY_NODE_FIELD(options);
2243 static AlterUserStmt *
2244 _copyAlterUserStmt(AlterUserStmt *from)
2246 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2248 COPY_STRING_FIELD(user);
2249 COPY_NODE_FIELD(options);
2254 static AlterUserSetStmt *
2255 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2257 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2259 COPY_STRING_FIELD(user);
2260 COPY_STRING_FIELD(variable);
2261 COPY_NODE_FIELD(value);
2266 static DropUserStmt *
2267 _copyDropUserStmt(DropUserStmt *from)
2269 DropUserStmt *newnode = makeNode(DropUserStmt);
2271 COPY_NODE_FIELD(users);
2277 _copyLockStmt(LockStmt *from)
2279 LockStmt *newnode = makeNode(LockStmt);
2281 COPY_NODE_FIELD(relations);
2282 COPY_SCALAR_FIELD(mode);
2287 static ConstraintsSetStmt *
2288 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2290 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2292 COPY_NODE_FIELD(constraints);
2293 COPY_SCALAR_FIELD(deferred);
2298 static CreateGroupStmt *
2299 _copyCreateGroupStmt(CreateGroupStmt *from)
2301 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2303 COPY_STRING_FIELD(name);
2304 COPY_NODE_FIELD(options);
2309 static AlterGroupStmt *
2310 _copyAlterGroupStmt(AlterGroupStmt *from)
2312 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2314 COPY_STRING_FIELD(name);
2315 COPY_SCALAR_FIELD(action);
2316 COPY_NODE_FIELD(listUsers);
2321 static DropGroupStmt *
2322 _copyDropGroupStmt(DropGroupStmt *from)
2324 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2326 COPY_STRING_FIELD(name);
2331 static ReindexStmt *
2332 _copyReindexStmt(ReindexStmt *from)
2334 ReindexStmt *newnode = makeNode(ReindexStmt);
2336 COPY_SCALAR_FIELD(kind);
2337 COPY_NODE_FIELD(relation);
2338 COPY_STRING_FIELD(name);
2339 COPY_SCALAR_FIELD(force);
2340 COPY_SCALAR_FIELD(all);
2345 static CreateSchemaStmt *
2346 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2348 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2350 COPY_STRING_FIELD(schemaname);
2351 COPY_STRING_FIELD(authid);
2352 COPY_NODE_FIELD(schemaElts);
2357 static CreateConversionStmt *
2358 _copyCreateConversionStmt(CreateConversionStmt *from)
2360 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2362 COPY_NODE_FIELD(conversion_name);
2363 COPY_STRING_FIELD(for_encoding_name);
2364 COPY_STRING_FIELD(to_encoding_name);
2365 COPY_NODE_FIELD(func_name);
2366 COPY_SCALAR_FIELD(def);
2371 static CreateCastStmt *
2372 _copyCreateCastStmt(CreateCastStmt *from)
2374 CreateCastStmt *newnode = makeNode(CreateCastStmt);
2376 COPY_NODE_FIELD(sourcetype);
2377 COPY_NODE_FIELD(targettype);
2378 COPY_NODE_FIELD(func);
2379 COPY_SCALAR_FIELD(context);
2384 static DropCastStmt *
2385 _copyDropCastStmt(DropCastStmt *from)
2387 DropCastStmt *newnode = makeNode(DropCastStmt);
2389 COPY_NODE_FIELD(sourcetype);
2390 COPY_NODE_FIELD(targettype);
2391 COPY_SCALAR_FIELD(behavior);
2396 static PrepareStmt *
2397 _copyPrepareStmt(PrepareStmt *from)
2399 PrepareStmt *newnode = makeNode(PrepareStmt);
2401 COPY_STRING_FIELD(name);
2402 COPY_NODE_FIELD(argtypes);
2403 COPY_OIDLIST_FIELD(argtype_oids);
2404 COPY_NODE_FIELD(query);
2409 static ExecuteStmt *
2410 _copyExecuteStmt(ExecuteStmt *from)
2412 ExecuteStmt *newnode = makeNode(ExecuteStmt);
2414 COPY_STRING_FIELD(name);
2415 COPY_NODE_FIELD(into);
2416 COPY_NODE_FIELD(params);
2421 static DeallocateStmt *
2422 _copyDeallocateStmt(DeallocateStmt *from)
2424 DeallocateStmt *newnode = makeNode(DeallocateStmt);
2426 COPY_STRING_FIELD(name);
2432 /* ****************************************************************
2433 * pg_list.h copy functions
2434 * ****************************************************************
2438 _copyValue(Value *from)
2440 Value *newnode = makeNode(Value);
2442 /* See also _copyAConst when changing this code! */
2444 COPY_SCALAR_FIELD(type);
2448 COPY_SCALAR_FIELD(val.ival);
2453 COPY_STRING_FIELD(val.str);
2459 elog(ERROR, "unrecognized node type: %d",
2469 * Create a copy of a Node tree or list. This is a "deep" copy: all
2470 * substructure is copied too, recursively.
2473 copyObject(void *from)
2480 switch (nodeTag(from))
2486 retval = _copyPlan(from);
2489 retval = _copyResult(from);
2492 retval = _copyAppend(from);
2495 retval = _copyScan(from);
2498 retval = _copySeqScan(from);
2501 retval = _copyIndexScan(from);
2504 retval = _copyTidScan(from);
2506 case T_SubqueryScan:
2507 retval = _copySubqueryScan(from);
2509 case T_FunctionScan:
2510 retval = _copyFunctionScan(from);
2513 retval = _copyJoin(from);
2516 retval = _copyNestLoop(from);
2519 retval = _copyMergeJoin(from);
2522 retval = _copyHashJoin(from);
2525 retval = _copyMaterial(from);
2528 retval = _copySort(from);
2531 retval = _copyGroup(from);
2534 retval = _copyAgg(from);
2537 retval = _copyUnique(from);
2540 retval = _copyHash(from);
2543 retval = _copySetOp(from);
2546 retval = _copyLimit(from);
2553 retval = _copyResdom(from);
2556 retval = _copyAlias(from);
2559 retval = _copyRangeVar(from);
2562 retval = _copyVar(from);
2565 retval = _copyConst(from);
2568 retval = _copyParam(from);
2571 retval = _copyAggref(from);
2574 retval = _copyArrayRef(from);
2577 retval = _copyFuncExpr(from);
2580 retval = _copyOpExpr(from);
2582 case T_DistinctExpr:
2583 retval = _copyDistinctExpr(from);
2585 case T_ScalarArrayOpExpr:
2586 retval = _copyScalarArrayOpExpr(from);
2589 retval = _copyBoolExpr(from);
2592 retval = _copySubLink(from);
2595 retval = _copySubPlan(from);
2598 retval = _copyFieldSelect(from);
2601 retval = _copyRelabelType(from);
2604 retval = _copyCaseExpr(from);
2607 retval = _copyCaseWhen(from);
2610 retval = _copyArrayExpr(from);
2612 case T_CoalesceExpr:
2613 retval = _copyCoalesceExpr(from);
2616 retval = _copyNullIfExpr(from);
2619 retval = _copyNullTest(from);
2622 retval = _copyBooleanTest(from);
2624 case T_CoerceToDomain:
2625 retval = _copyCoerceToDomain(from);
2627 case T_CoerceToDomainValue:
2628 retval = _copyCoerceToDomainValue(from);
2630 case T_SetToDefault:
2631 retval = _copySetToDefault(from);
2634 retval = _copyTargetEntry(from);
2637 retval = _copyRangeTblRef(from);
2640 retval = _copyJoinExpr(from);
2643 retval = _copyFromExpr(from);
2650 retval = _copyPathKeyItem(from);
2652 case T_RestrictInfo:
2653 retval = _copyRestrictInfo(from);
2656 retval = _copyJoinInfo(from);
2658 case T_InClauseInfo:
2659 retval = _copyInClauseInfo(from);
2670 retval = _copyValue(from);
2679 /* rather ugly coding for speed... */
2680 /* Note the input list cannot be NIL if we got here. */
2681 newcell = makeNode(List);
2682 lfirst(newcell) = copyObject(lfirst(list));
2684 retval = (void *) newcell;
2687 foreach(oldl, lnext(list))
2689 newcell = makeNode(List);
2690 lfirst(newcell) = copyObject(lfirst(oldl));
2691 prev->next = newcell;
2702 retval = _copyQuery(from);
2705 retval = _copyInsertStmt(from);
2708 retval = _copyDeleteStmt(from);
2711 retval = _copyUpdateStmt(from);
2714 retval = _copySelectStmt(from);
2716 case T_SetOperationStmt:
2717 retval = _copySetOperationStmt(from);
2719 case T_AlterTableStmt:
2720 retval = _copyAlterTableStmt(from);
2722 case T_AlterDomainStmt:
2723 retval = _copyAlterDomainStmt(from);
2726 retval = _copyGrantStmt(from);
2728 case T_DeclareCursorStmt:
2729 retval = _copyDeclareCursorStmt(from);
2731 case T_ClosePortalStmt:
2732 retval = _copyClosePortalStmt(from);
2735 retval = _copyClusterStmt(from);
2738 retval = _copyCopyStmt(from);
2741 retval = _copyCreateStmt(from);
2744 retval = _copyInhRelation(from);
2747 retval = _copyDefineStmt(from);
2750 retval = _copyDropStmt(from);
2752 case T_TruncateStmt:
2753 retval = _copyTruncateStmt(from);
2756 retval = _copyCommentStmt(from);
2759 retval = _copyFetchStmt(from);
2762 retval = _copyIndexStmt(from);
2764 case T_CreateFunctionStmt:
2765 retval = _copyCreateFunctionStmt(from);
2767 case T_RemoveAggrStmt:
2768 retval = _copyRemoveAggrStmt(from);
2770 case T_RemoveFuncStmt:
2771 retval = _copyRemoveFuncStmt(from);
2773 case T_RemoveOperStmt:
2774 retval = _copyRemoveOperStmt(from);
2776 case T_RemoveOpClassStmt:
2777 retval = _copyRemoveOpClassStmt(from);
2780 retval = _copyRenameStmt(from);
2783 retval = _copyRuleStmt(from);
2786 retval = _copyNotifyStmt(from);
2789 retval = _copyListenStmt(from);
2791 case T_UnlistenStmt:
2792 retval = _copyUnlistenStmt(from);
2794 case T_TransactionStmt:
2795 retval = _copyTransactionStmt(from);
2797 case T_CompositeTypeStmt:
2798 retval = _copyCompositeTypeStmt(from);
2801 retval = _copyViewStmt(from);
2804 retval = _copyLoadStmt(from);
2806 case T_CreateDomainStmt:
2807 retval = _copyCreateDomainStmt(from);
2809 case T_CreateOpClassStmt:
2810 retval = _copyCreateOpClassStmt(from);
2812 case T_CreateOpClassItem:
2813 retval = _copyCreateOpClassItem(from);
2815 case T_CreatedbStmt:
2816 retval = _copyCreatedbStmt(from);
2818 case T_AlterDatabaseSetStmt:
2819 retval = _copyAlterDatabaseSetStmt(from);
2822 retval = _copyDropdbStmt(from);
2825 retval = _copyVacuumStmt(from);
2828 retval = _copyExplainStmt(from);
2830 case T_CreateSeqStmt:
2831 retval = _copyCreateSeqStmt(from);
2833 case T_AlterSeqStmt:
2834 retval = _copyAlterSeqStmt(from);
2836 case T_VariableSetStmt:
2837 retval = _copyVariableSetStmt(from);
2839 case T_VariableShowStmt:
2840 retval = _copyVariableShowStmt(from);
2842 case T_VariableResetStmt:
2843 retval = _copyVariableResetStmt(from);
2845 case T_CreateTrigStmt:
2846 retval = _copyCreateTrigStmt(from);
2848 case T_DropPropertyStmt:
2849 retval = _copyDropPropertyStmt(from);
2851 case T_CreatePLangStmt:
2852 retval = _copyCreatePLangStmt(from);
2854 case T_DropPLangStmt:
2855 retval = _copyDropPLangStmt(from);
2857 case T_CreateUserStmt:
2858 retval = _copyCreateUserStmt(from);
2860 case T_AlterUserStmt:
2861 retval = _copyAlterUserStmt(from);
2863 case T_AlterUserSetStmt:
2864 retval = _copyAlterUserSetStmt(from);
2866 case T_DropUserStmt:
2867 retval = _copyDropUserStmt(from);
2870 retval = _copyLockStmt(from);
2872 case T_ConstraintsSetStmt:
2873 retval = _copyConstraintsSetStmt(from);
2875 case T_CreateGroupStmt:
2876 retval = _copyCreateGroupStmt(from);
2878 case T_AlterGroupStmt:
2879 retval = _copyAlterGroupStmt(from);
2881 case T_DropGroupStmt:
2882 retval = _copyDropGroupStmt(from);
2885 retval = _copyReindexStmt(from);
2887 case T_CheckPointStmt:
2888 retval = (void *) makeNode(CheckPointStmt);
2890 case T_CreateSchemaStmt:
2891 retval = _copyCreateSchemaStmt(from);
2893 case T_CreateConversionStmt:
2894 retval = _copyCreateConversionStmt(from);
2896 case T_CreateCastStmt:
2897 retval = _copyCreateCastStmt(from);
2899 case T_DropCastStmt:
2900 retval = _copyDropCastStmt(from);
2903 retval = _copyPrepareStmt(from);
2906 retval = _copyExecuteStmt(from);
2908 case T_DeallocateStmt:
2909 retval = _copyDeallocateStmt(from);
2913 retval = _copyAExpr(from);
2916 retval = _copyColumnRef(from);
2919 retval = _copyParamRef(from);
2922 retval = _copyAConst(from);
2925 retval = _copyFuncCall(from);
2928 retval = _copyAIndices(from);
2930 case T_ExprFieldSelect:
2931 retval = _copyExprFieldSelect(from);
2934 retval = _copyResTarget(from);
2937 retval = _copyTypeCast(from);
2940 retval = _copySortBy(from);
2942 case T_RangeSubselect:
2943 retval = _copyRangeSubselect(from);
2945 case T_RangeFunction:
2946 retval = _copyRangeFunction(from);
2949 retval = _copyTypeName(from);
2952 retval = _copyIndexElem(from);
2955 retval = _copyColumnDef(from);
2958 retval = _copyConstraint(from);
2961 retval = _copyDefElem(from);
2963 case T_RangeTblEntry:
2964 retval = _copyRangeTblEntry(from);
2967 retval = _copySortClause(from);
2970 retval = _copyGroupClause(from);
2972 case T_FkConstraint:
2973 retval = _copyFkConstraint(from);
2976 retval = _copyPrivGrantee(from);
2978 case T_FuncWithArgs:
2979 retval = _copyFuncWithArgs(from);
2983 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
2984 retval = from; /* keep compiler quiet */