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 * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.272 2004/01/04 03:51:52 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 /* this can become COPY_NODE_FIELD when OID lists are normal objects: */
278 List *newsubtype = NIL;
281 foreach(tmp, from->indxsubtype)
283 newsubtype = lappend(newsubtype, listCopy(lfirst(tmp)));
285 newnode->indxsubtype = newsubtype;
287 COPY_SCALAR_FIELD(indxorderdir);
296 _copyTidScan(TidScan *from)
298 TidScan *newnode = makeNode(TidScan);
301 * copy node superclass fields
303 CopyScanFields((Scan *) from, (Scan *) newnode);
306 * copy remainder of node
308 COPY_NODE_FIELD(tideval);
316 static SubqueryScan *
317 _copySubqueryScan(SubqueryScan *from)
319 SubqueryScan *newnode = makeNode(SubqueryScan);
322 * copy node superclass fields
324 CopyScanFields((Scan *) from, (Scan *) newnode);
327 * copy remainder of node
329 COPY_NODE_FIELD(subplan);
337 static FunctionScan *
338 _copyFunctionScan(FunctionScan *from)
340 FunctionScan *newnode = makeNode(FunctionScan);
343 * copy node superclass fields
345 CopyScanFields((Scan *) from, (Scan *) newnode);
353 * This function copies the fields of the Join node. It is used by
354 * all the copy functions for classes which inherit from Join.
357 CopyJoinFields(Join *from, Join *newnode)
359 CopyPlanFields((Plan *) from, (Plan *) newnode);
361 COPY_SCALAR_FIELD(jointype);
362 COPY_NODE_FIELD(joinqual);
370 _copyJoin(Join *from)
372 Join *newnode = makeNode(Join);
375 * copy node superclass fields
377 CopyJoinFields(from, newnode);
387 _copyNestLoop(NestLoop *from)
389 NestLoop *newnode = makeNode(NestLoop);
392 * copy node superclass fields
394 CopyJoinFields((Join *) from, (Join *) newnode);
404 _copyMergeJoin(MergeJoin *from)
406 MergeJoin *newnode = makeNode(MergeJoin);
409 * copy node superclass fields
411 CopyJoinFields((Join *) from, (Join *) newnode);
414 * copy remainder of node
416 COPY_NODE_FIELD(mergeclauses);
425 _copyHashJoin(HashJoin *from)
427 HashJoin *newnode = makeNode(HashJoin);
430 * copy node superclass fields
432 CopyJoinFields((Join *) from, (Join *) newnode);
435 * copy remainder of node
437 COPY_NODE_FIELD(hashclauses);
447 _copyMaterial(Material *from)
449 Material *newnode = makeNode(Material);
452 * copy node superclass fields
454 CopyPlanFields((Plan *) from, (Plan *) newnode);
464 _copySort(Sort *from)
466 Sort *newnode = makeNode(Sort);
469 * copy node superclass fields
471 CopyPlanFields((Plan *) from, (Plan *) newnode);
473 COPY_SCALAR_FIELD(numCols);
474 COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
475 COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
485 _copyGroup(Group *from)
487 Group *newnode = makeNode(Group);
489 CopyPlanFields((Plan *) from, (Plan *) newnode);
491 COPY_SCALAR_FIELD(numCols);
492 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
503 Agg *newnode = makeNode(Agg);
505 CopyPlanFields((Plan *) from, (Plan *) newnode);
507 COPY_SCALAR_FIELD(aggstrategy);
508 COPY_SCALAR_FIELD(numCols);
509 if (from->numCols > 0)
510 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
511 COPY_SCALAR_FIELD(numGroups);
520 _copyUnique(Unique *from)
522 Unique *newnode = makeNode(Unique);
525 * copy node superclass fields
527 CopyPlanFields((Plan *) from, (Plan *) newnode);
530 * copy remainder of node
532 COPY_SCALAR_FIELD(numCols);
533 COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
542 _copyHash(Hash *from)
544 Hash *newnode = makeNode(Hash);
547 * copy node superclass fields
549 CopyPlanFields((Plan *) from, (Plan *) newnode);
552 * copy remainder of node
562 _copySetOp(SetOp *from)
564 SetOp *newnode = makeNode(SetOp);
567 * copy node superclass fields
569 CopyPlanFields((Plan *) from, (Plan *) newnode);
572 * copy remainder of node
574 COPY_SCALAR_FIELD(cmd);
575 COPY_SCALAR_FIELD(numCols);
576 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
577 COPY_SCALAR_FIELD(flagColIdx);
586 _copyLimit(Limit *from)
588 Limit *newnode = makeNode(Limit);
591 * copy node superclass fields
593 CopyPlanFields((Plan *) from, (Plan *) newnode);
596 * copy remainder of node
598 COPY_NODE_FIELD(limitOffset);
599 COPY_NODE_FIELD(limitCount);
604 /* ****************************************************************
605 * primnodes.h copy functions
606 * ****************************************************************
613 _copyResdom(Resdom *from)
615 Resdom *newnode = makeNode(Resdom);
617 COPY_SCALAR_FIELD(resno);
618 COPY_SCALAR_FIELD(restype);
619 COPY_SCALAR_FIELD(restypmod);
620 COPY_STRING_FIELD(resname);
621 COPY_SCALAR_FIELD(ressortgroupref);
622 COPY_SCALAR_FIELD(resorigtbl);
623 COPY_SCALAR_FIELD(resorigcol);
624 COPY_SCALAR_FIELD(resjunk);
633 _copyAlias(Alias *from)
635 Alias *newnode = makeNode(Alias);
637 COPY_STRING_FIELD(aliasname);
638 COPY_NODE_FIELD(colnames);
647 _copyRangeVar(RangeVar *from)
649 RangeVar *newnode = makeNode(RangeVar);
651 COPY_STRING_FIELD(catalogname);
652 COPY_STRING_FIELD(schemaname);
653 COPY_STRING_FIELD(relname);
654 COPY_SCALAR_FIELD(inhOpt);
655 COPY_SCALAR_FIELD(istemp);
656 COPY_NODE_FIELD(alias);
662 * We don't need a _copyExpr because Expr is an abstract supertype which
663 * should never actually get instantiated. Also, since it has no common
664 * fields except NodeTag, there's no need for a helper routine to factor
665 * out copying the common fields...
674 Var *newnode = makeNode(Var);
676 COPY_SCALAR_FIELD(varno);
677 COPY_SCALAR_FIELD(varattno);
678 COPY_SCALAR_FIELD(vartype);
679 COPY_SCALAR_FIELD(vartypmod);
680 COPY_SCALAR_FIELD(varlevelsup);
681 COPY_SCALAR_FIELD(varnoold);
682 COPY_SCALAR_FIELD(varoattno);
691 _copyConst(Const *from)
693 Const *newnode = makeNode(Const);
695 COPY_SCALAR_FIELD(consttype);
696 COPY_SCALAR_FIELD(constlen);
698 if (from->constbyval || from->constisnull)
701 * passed by value so just copy the datum. Also, don't try to copy
702 * struct when value is null!
704 newnode->constvalue = from->constvalue;
709 * passed by reference. We need a palloc'd copy.
711 newnode->constvalue = datumCopy(from->constvalue,
716 COPY_SCALAR_FIELD(constisnull);
717 COPY_SCALAR_FIELD(constbyval);
726 _copyParam(Param *from)
728 Param *newnode = makeNode(Param);
730 COPY_SCALAR_FIELD(paramkind);
731 COPY_SCALAR_FIELD(paramid);
732 COPY_STRING_FIELD(paramname);
733 COPY_SCALAR_FIELD(paramtype);
742 _copyAggref(Aggref *from)
744 Aggref *newnode = makeNode(Aggref);
746 COPY_SCALAR_FIELD(aggfnoid);
747 COPY_SCALAR_FIELD(aggtype);
748 COPY_NODE_FIELD(target);
749 COPY_SCALAR_FIELD(agglevelsup);
750 COPY_SCALAR_FIELD(aggstar);
751 COPY_SCALAR_FIELD(aggdistinct);
760 _copyArrayRef(ArrayRef *from)
762 ArrayRef *newnode = makeNode(ArrayRef);
764 COPY_SCALAR_FIELD(refrestype);
765 COPY_SCALAR_FIELD(refarraytype);
766 COPY_SCALAR_FIELD(refelemtype);
767 COPY_NODE_FIELD(refupperindexpr);
768 COPY_NODE_FIELD(reflowerindexpr);
769 COPY_NODE_FIELD(refexpr);
770 COPY_NODE_FIELD(refassgnexpr);
779 _copyFuncExpr(FuncExpr *from)
781 FuncExpr *newnode = makeNode(FuncExpr);
783 COPY_SCALAR_FIELD(funcid);
784 COPY_SCALAR_FIELD(funcresulttype);
785 COPY_SCALAR_FIELD(funcretset);
786 COPY_SCALAR_FIELD(funcformat);
787 COPY_NODE_FIELD(args);
796 _copyOpExpr(OpExpr *from)
798 OpExpr *newnode = makeNode(OpExpr);
800 COPY_SCALAR_FIELD(opno);
801 COPY_SCALAR_FIELD(opfuncid);
802 COPY_SCALAR_FIELD(opresulttype);
803 COPY_SCALAR_FIELD(opretset);
804 COPY_NODE_FIELD(args);
810 * _copyDistinctExpr (same as OpExpr)
812 static DistinctExpr *
813 _copyDistinctExpr(DistinctExpr *from)
815 DistinctExpr *newnode = makeNode(DistinctExpr);
817 COPY_SCALAR_FIELD(opno);
818 COPY_SCALAR_FIELD(opfuncid);
819 COPY_SCALAR_FIELD(opresulttype);
820 COPY_SCALAR_FIELD(opretset);
821 COPY_NODE_FIELD(args);
827 * _copyScalarArrayOpExpr
829 static ScalarArrayOpExpr *
830 _copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
832 ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
834 COPY_SCALAR_FIELD(opno);
835 COPY_SCALAR_FIELD(opfuncid);
836 COPY_SCALAR_FIELD(useOr);
837 COPY_NODE_FIELD(args);
846 _copyBoolExpr(BoolExpr *from)
848 BoolExpr *newnode = makeNode(BoolExpr);
850 COPY_SCALAR_FIELD(boolop);
851 COPY_NODE_FIELD(args);
860 _copySubLink(SubLink *from)
862 SubLink *newnode = makeNode(SubLink);
864 COPY_SCALAR_FIELD(subLinkType);
865 COPY_SCALAR_FIELD(useOr);
866 COPY_NODE_FIELD(lefthand);
867 COPY_NODE_FIELD(operName);
868 COPY_OIDLIST_FIELD(operOids);
869 COPY_NODE_FIELD(subselect);
878 _copySubPlan(SubPlan *from)
880 SubPlan *newnode = makeNode(SubPlan);
882 COPY_SCALAR_FIELD(subLinkType);
883 COPY_SCALAR_FIELD(useOr);
884 COPY_NODE_FIELD(exprs);
885 COPY_INTLIST_FIELD(paramIds);
886 COPY_NODE_FIELD(plan);
887 COPY_SCALAR_FIELD(plan_id);
888 COPY_NODE_FIELD(rtable);
889 COPY_SCALAR_FIELD(useHashTable);
890 COPY_SCALAR_FIELD(unknownEqFalse);
891 COPY_INTLIST_FIELD(setParam);
892 COPY_INTLIST_FIELD(parParam);
893 COPY_NODE_FIELD(args);
902 _copyFieldSelect(FieldSelect *from)
904 FieldSelect *newnode = makeNode(FieldSelect);
906 COPY_NODE_FIELD(arg);
907 COPY_SCALAR_FIELD(fieldnum);
908 COPY_SCALAR_FIELD(resulttype);
909 COPY_SCALAR_FIELD(resulttypmod);
918 _copyRelabelType(RelabelType *from)
920 RelabelType *newnode = makeNode(RelabelType);
922 COPY_NODE_FIELD(arg);
923 COPY_SCALAR_FIELD(resulttype);
924 COPY_SCALAR_FIELD(resulttypmod);
925 COPY_SCALAR_FIELD(relabelformat);
934 _copyCaseExpr(CaseExpr *from)
936 CaseExpr *newnode = makeNode(CaseExpr);
938 COPY_SCALAR_FIELD(casetype);
939 COPY_NODE_FIELD(arg);
940 COPY_NODE_FIELD(args);
941 COPY_NODE_FIELD(defresult);
950 _copyCaseWhen(CaseWhen *from)
952 CaseWhen *newnode = makeNode(CaseWhen);
954 COPY_NODE_FIELD(expr);
955 COPY_NODE_FIELD(result);
964 _copyArrayExpr(ArrayExpr *from)
966 ArrayExpr *newnode = makeNode(ArrayExpr);
968 COPY_SCALAR_FIELD(array_typeid);
969 COPY_SCALAR_FIELD(element_typeid);
970 COPY_NODE_FIELD(elements);
971 COPY_SCALAR_FIELD(multidims);
979 static CoalesceExpr *
980 _copyCoalesceExpr(CoalesceExpr *from)
982 CoalesceExpr *newnode = makeNode(CoalesceExpr);
984 COPY_SCALAR_FIELD(coalescetype);
985 COPY_NODE_FIELD(args);
991 * _copyNullIfExpr (same as OpExpr)
994 _copyNullIfExpr(NullIfExpr *from)
996 NullIfExpr *newnode = makeNode(NullIfExpr);
998 COPY_SCALAR_FIELD(opno);
999 COPY_SCALAR_FIELD(opfuncid);
1000 COPY_SCALAR_FIELD(opresulttype);
1001 COPY_SCALAR_FIELD(opretset);
1002 COPY_NODE_FIELD(args);
1011 _copyNullTest(NullTest *from)
1013 NullTest *newnode = makeNode(NullTest);
1015 COPY_NODE_FIELD(arg);
1016 COPY_SCALAR_FIELD(nulltesttype);
1024 static BooleanTest *
1025 _copyBooleanTest(BooleanTest *from)
1027 BooleanTest *newnode = makeNode(BooleanTest);
1029 COPY_NODE_FIELD(arg);
1030 COPY_SCALAR_FIELD(booltesttype);
1036 * _copyCoerceToDomain
1038 static CoerceToDomain *
1039 _copyCoerceToDomain(CoerceToDomain *from)
1041 CoerceToDomain *newnode = makeNode(CoerceToDomain);
1043 COPY_NODE_FIELD(arg);
1044 COPY_SCALAR_FIELD(resulttype);
1045 COPY_SCALAR_FIELD(resulttypmod);
1046 COPY_SCALAR_FIELD(coercionformat);
1052 * _copyCoerceToDomainValue
1054 static CoerceToDomainValue *
1055 _copyCoerceToDomainValue(CoerceToDomainValue *from)
1057 CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1059 COPY_SCALAR_FIELD(typeId);
1060 COPY_SCALAR_FIELD(typeMod);
1068 static SetToDefault *
1069 _copySetToDefault(SetToDefault *from)
1071 SetToDefault *newnode = makeNode(SetToDefault);
1073 COPY_SCALAR_FIELD(typeId);
1074 COPY_SCALAR_FIELD(typeMod);
1082 static TargetEntry *
1083 _copyTargetEntry(TargetEntry *from)
1085 TargetEntry *newnode = makeNode(TargetEntry);
1087 COPY_NODE_FIELD(resdom);
1088 COPY_NODE_FIELD(expr);
1096 static RangeTblRef *
1097 _copyRangeTblRef(RangeTblRef *from)
1099 RangeTblRef *newnode = makeNode(RangeTblRef);
1101 COPY_SCALAR_FIELD(rtindex);
1110 _copyJoinExpr(JoinExpr *from)
1112 JoinExpr *newnode = makeNode(JoinExpr);
1114 COPY_SCALAR_FIELD(jointype);
1115 COPY_SCALAR_FIELD(isNatural);
1116 COPY_NODE_FIELD(larg);
1117 COPY_NODE_FIELD(rarg);
1118 COPY_NODE_FIELD(using);
1119 COPY_NODE_FIELD(quals);
1120 COPY_NODE_FIELD(alias);
1121 COPY_SCALAR_FIELD(rtindex);
1130 _copyFromExpr(FromExpr *from)
1132 FromExpr *newnode = makeNode(FromExpr);
1134 COPY_NODE_FIELD(fromlist);
1135 COPY_NODE_FIELD(quals);
1140 /* ****************************************************************
1141 * relation.h copy functions
1143 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1144 * There are some subsidiary structs that are useful to copy, though.
1145 * ****************************************************************
1151 static PathKeyItem *
1152 _copyPathKeyItem(PathKeyItem *from)
1154 PathKeyItem *newnode = makeNode(PathKeyItem);
1156 COPY_NODE_FIELD(key);
1157 COPY_SCALAR_FIELD(sortop);
1165 static RestrictInfo *
1166 _copyRestrictInfo(RestrictInfo *from)
1168 RestrictInfo *newnode = makeNode(RestrictInfo);
1170 COPY_NODE_FIELD(clause);
1171 COPY_SCALAR_FIELD(ispusheddown);
1172 COPY_SCALAR_FIELD(canjoin);
1173 COPY_BITMAPSET_FIELD(clause_relids);
1174 COPY_BITMAPSET_FIELD(left_relids);
1175 COPY_BITMAPSET_FIELD(right_relids);
1176 COPY_NODE_FIELD(orclause);
1177 COPY_SCALAR_FIELD(eval_cost);
1178 COPY_SCALAR_FIELD(this_selec);
1179 COPY_SCALAR_FIELD(mergejoinoperator);
1180 COPY_SCALAR_FIELD(left_sortop);
1181 COPY_SCALAR_FIELD(right_sortop);
1184 * Do not copy pathkeys, since they'd not be canonical in a copied
1187 newnode->left_pathkey = NIL;
1188 newnode->right_pathkey = NIL;
1190 COPY_SCALAR_FIELD(left_mergescansel);
1191 COPY_SCALAR_FIELD(right_mergescansel);
1192 COPY_SCALAR_FIELD(hashjoinoperator);
1193 COPY_SCALAR_FIELD(left_bucketsize);
1194 COPY_SCALAR_FIELD(right_bucketsize);
1203 _copyJoinInfo(JoinInfo *from)
1205 JoinInfo *newnode = makeNode(JoinInfo);
1207 COPY_BITMAPSET_FIELD(unjoined_relids);
1208 COPY_NODE_FIELD(jinfo_restrictinfo);
1216 static InClauseInfo *
1217 _copyInClauseInfo(InClauseInfo *from)
1219 InClauseInfo *newnode = makeNode(InClauseInfo);
1221 COPY_BITMAPSET_FIELD(lefthand);
1222 COPY_BITMAPSET_FIELD(righthand);
1223 COPY_NODE_FIELD(sub_targetlist);
1228 /* ****************************************************************
1229 * parsenodes.h copy functions
1230 * ****************************************************************
1233 static RangeTblEntry *
1234 _copyRangeTblEntry(RangeTblEntry *from)
1236 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1238 COPY_SCALAR_FIELD(rtekind);
1239 COPY_SCALAR_FIELD(relid);
1240 COPY_NODE_FIELD(subquery);
1241 COPY_NODE_FIELD(funcexpr);
1242 COPY_NODE_FIELD(coldeflist);
1243 COPY_SCALAR_FIELD(jointype);
1244 COPY_NODE_FIELD(joinaliasvars);
1245 COPY_NODE_FIELD(alias);
1246 COPY_NODE_FIELD(eref);
1247 COPY_SCALAR_FIELD(inh);
1248 COPY_SCALAR_FIELD(inFromCl);
1249 COPY_SCALAR_FIELD(checkForRead);
1250 COPY_SCALAR_FIELD(checkForWrite);
1251 COPY_SCALAR_FIELD(checkAsUser);
1256 static FkConstraint *
1257 _copyFkConstraint(FkConstraint *from)
1259 FkConstraint *newnode = makeNode(FkConstraint);
1261 COPY_STRING_FIELD(constr_name);
1262 COPY_NODE_FIELD(pktable);
1263 COPY_NODE_FIELD(fk_attrs);
1264 COPY_NODE_FIELD(pk_attrs);
1265 COPY_SCALAR_FIELD(fk_matchtype);
1266 COPY_SCALAR_FIELD(fk_upd_action);
1267 COPY_SCALAR_FIELD(fk_del_action);
1268 COPY_SCALAR_FIELD(deferrable);
1269 COPY_SCALAR_FIELD(initdeferred);
1270 COPY_SCALAR_FIELD(skip_validation);
1276 _copySortClause(SortClause *from)
1278 SortClause *newnode = makeNode(SortClause);
1280 COPY_SCALAR_FIELD(tleSortGroupRef);
1281 COPY_SCALAR_FIELD(sortop);
1286 static GroupClause *
1287 _copyGroupClause(GroupClause *from)
1289 GroupClause *newnode = makeNode(GroupClause);
1291 COPY_SCALAR_FIELD(tleSortGroupRef);
1292 COPY_SCALAR_FIELD(sortop);
1298 _copyAExpr(A_Expr *from)
1300 A_Expr *newnode = makeNode(A_Expr);
1302 COPY_SCALAR_FIELD(kind);
1303 COPY_NODE_FIELD(name);
1304 COPY_NODE_FIELD(lexpr);
1305 COPY_NODE_FIELD(rexpr);
1311 _copyColumnRef(ColumnRef *from)
1313 ColumnRef *newnode = makeNode(ColumnRef);
1315 COPY_NODE_FIELD(fields);
1316 COPY_NODE_FIELD(indirection);
1322 _copyParamRef(ParamRef *from)
1324 ParamRef *newnode = makeNode(ParamRef);
1326 COPY_SCALAR_FIELD(number);
1327 COPY_NODE_FIELD(fields);
1328 COPY_NODE_FIELD(indirection);
1334 _copyAConst(A_Const *from)
1336 A_Const *newnode = makeNode(A_Const);
1338 /* This part must duplicate _copyValue */
1339 COPY_SCALAR_FIELD(val.type);
1340 switch (from->val.type)
1343 COPY_SCALAR_FIELD(val.val.ival);
1348 COPY_STRING_FIELD(val.val.str);
1354 elog(ERROR, "unrecognized node type: %d",
1355 (int) from->val.type);
1359 COPY_NODE_FIELD(typename);
1365 _copyFuncCall(FuncCall *from)
1367 FuncCall *newnode = makeNode(FuncCall);
1369 COPY_NODE_FIELD(funcname);
1370 COPY_NODE_FIELD(args);
1371 COPY_SCALAR_FIELD(agg_star);
1372 COPY_SCALAR_FIELD(agg_distinct);
1378 _copyAIndices(A_Indices *from)
1380 A_Indices *newnode = makeNode(A_Indices);
1382 COPY_NODE_FIELD(lidx);
1383 COPY_NODE_FIELD(uidx);
1388 static ExprFieldSelect *
1389 _copyExprFieldSelect(ExprFieldSelect *from)
1391 ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
1393 COPY_NODE_FIELD(arg);
1394 COPY_NODE_FIELD(fields);
1395 COPY_NODE_FIELD(indirection);
1401 _copyResTarget(ResTarget *from)
1403 ResTarget *newnode = makeNode(ResTarget);
1405 COPY_STRING_FIELD(name);
1406 COPY_NODE_FIELD(indirection);
1407 COPY_NODE_FIELD(val);
1413 _copyTypeName(TypeName *from)
1415 TypeName *newnode = makeNode(TypeName);
1417 COPY_NODE_FIELD(names);
1418 COPY_SCALAR_FIELD(typeid);
1419 COPY_SCALAR_FIELD(timezone);
1420 COPY_SCALAR_FIELD(setof);
1421 COPY_SCALAR_FIELD(pct_type);
1422 COPY_SCALAR_FIELD(typmod);
1423 COPY_NODE_FIELD(arrayBounds);
1429 _copySortBy(SortBy *from)
1431 SortBy *newnode = makeNode(SortBy);
1433 COPY_SCALAR_FIELD(sortby_kind);
1434 COPY_NODE_FIELD(useOp);
1435 COPY_NODE_FIELD(node);
1440 static RangeSubselect *
1441 _copyRangeSubselect(RangeSubselect *from)
1443 RangeSubselect *newnode = makeNode(RangeSubselect);
1445 COPY_NODE_FIELD(subquery);
1446 COPY_NODE_FIELD(alias);
1451 static RangeFunction *
1452 _copyRangeFunction(RangeFunction *from)
1454 RangeFunction *newnode = makeNode(RangeFunction);
1456 COPY_NODE_FIELD(funccallnode);
1457 COPY_NODE_FIELD(alias);
1458 COPY_NODE_FIELD(coldeflist);
1464 _copyTypeCast(TypeCast *from)
1466 TypeCast *newnode = makeNode(TypeCast);
1468 COPY_NODE_FIELD(arg);
1469 COPY_NODE_FIELD(typename);
1475 _copyIndexElem(IndexElem *from)
1477 IndexElem *newnode = makeNode(IndexElem);
1479 COPY_STRING_FIELD(name);
1480 COPY_NODE_FIELD(expr);
1481 COPY_NODE_FIELD(opclass);
1487 _copyColumnDef(ColumnDef *from)
1489 ColumnDef *newnode = makeNode(ColumnDef);
1491 COPY_STRING_FIELD(colname);
1492 COPY_NODE_FIELD(typename);
1493 COPY_SCALAR_FIELD(inhcount);
1494 COPY_SCALAR_FIELD(is_local);
1495 COPY_SCALAR_FIELD(is_not_null);
1496 COPY_NODE_FIELD(raw_default);
1497 COPY_STRING_FIELD(cooked_default);
1498 COPY_NODE_FIELD(constraints);
1499 COPY_NODE_FIELD(support);
1505 _copyConstraint(Constraint *from)
1507 Constraint *newnode = makeNode(Constraint);
1509 COPY_SCALAR_FIELD(contype);
1510 COPY_STRING_FIELD(name);
1511 COPY_NODE_FIELD(raw_expr);
1512 COPY_STRING_FIELD(cooked_expr);
1513 COPY_NODE_FIELD(keys);
1519 _copyDefElem(DefElem *from)
1521 DefElem *newnode = makeNode(DefElem);
1523 COPY_STRING_FIELD(defname);
1524 COPY_NODE_FIELD(arg);
1530 _copyQuery(Query *from)
1532 Query *newnode = makeNode(Query);
1534 COPY_SCALAR_FIELD(commandType);
1535 COPY_SCALAR_FIELD(querySource);
1536 COPY_SCALAR_FIELD(canSetTag);
1537 COPY_NODE_FIELD(utilityStmt);
1538 COPY_SCALAR_FIELD(resultRelation);
1539 COPY_NODE_FIELD(into);
1540 COPY_SCALAR_FIELD(hasAggs);
1541 COPY_SCALAR_FIELD(hasSubLinks);
1542 COPY_NODE_FIELD(rtable);
1543 COPY_NODE_FIELD(jointree);
1544 COPY_INTLIST_FIELD(rowMarks);
1545 COPY_NODE_FIELD(targetList);
1546 COPY_NODE_FIELD(groupClause);
1547 COPY_NODE_FIELD(havingQual);
1548 COPY_NODE_FIELD(distinctClause);
1549 COPY_NODE_FIELD(sortClause);
1550 COPY_NODE_FIELD(limitOffset);
1551 COPY_NODE_FIELD(limitCount);
1552 COPY_NODE_FIELD(setOperations);
1553 COPY_INTLIST_FIELD(resultRelations);
1554 COPY_NODE_FIELD(in_info_list);
1555 COPY_SCALAR_FIELD(hasJoinRTEs);
1558 * We do not copy the other planner internal fields: base_rel_list,
1559 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. That
1560 * would get us into copying RelOptInfo/Path trees, which we don't
1561 * want to do. It is necessary to copy in_info_list and hasJoinRTEs
1562 * for the benefit of inheritance_planner(), which may try to copy a
1563 * Query in which these are already set.
1570 _copyInsertStmt(InsertStmt *from)
1572 InsertStmt *newnode = makeNode(InsertStmt);
1574 COPY_NODE_FIELD(relation);
1575 COPY_NODE_FIELD(cols);
1576 COPY_NODE_FIELD(targetList);
1577 COPY_NODE_FIELD(selectStmt);
1583 _copyDeleteStmt(DeleteStmt *from)
1585 DeleteStmt *newnode = makeNode(DeleteStmt);
1587 COPY_NODE_FIELD(relation);
1588 COPY_NODE_FIELD(whereClause);
1594 _copyUpdateStmt(UpdateStmt *from)
1596 UpdateStmt *newnode = makeNode(UpdateStmt);
1598 COPY_NODE_FIELD(relation);
1599 COPY_NODE_FIELD(targetList);
1600 COPY_NODE_FIELD(whereClause);
1601 COPY_NODE_FIELD(fromClause);
1607 _copySelectStmt(SelectStmt *from)
1609 SelectStmt *newnode = makeNode(SelectStmt);
1611 COPY_NODE_FIELD(distinctClause);
1612 COPY_NODE_FIELD(into);
1613 COPY_NODE_FIELD(intoColNames);
1614 COPY_NODE_FIELD(targetList);
1615 COPY_NODE_FIELD(fromClause);
1616 COPY_NODE_FIELD(whereClause);
1617 COPY_NODE_FIELD(groupClause);
1618 COPY_NODE_FIELD(havingClause);
1619 COPY_NODE_FIELD(sortClause);
1620 COPY_NODE_FIELD(limitOffset);
1621 COPY_NODE_FIELD(limitCount);
1622 COPY_NODE_FIELD(forUpdate);
1623 COPY_SCALAR_FIELD(op);
1624 COPY_SCALAR_FIELD(all);
1625 COPY_NODE_FIELD(larg);
1626 COPY_NODE_FIELD(rarg);
1631 static SetOperationStmt *
1632 _copySetOperationStmt(SetOperationStmt *from)
1634 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1636 COPY_SCALAR_FIELD(op);
1637 COPY_SCALAR_FIELD(all);
1638 COPY_NODE_FIELD(larg);
1639 COPY_NODE_FIELD(rarg);
1640 COPY_OIDLIST_FIELD(colTypes);
1645 static AlterTableStmt *
1646 _copyAlterTableStmt(AlterTableStmt *from)
1648 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1650 COPY_SCALAR_FIELD(subtype);
1651 COPY_NODE_FIELD(relation);
1652 COPY_STRING_FIELD(name);
1653 COPY_NODE_FIELD(def);
1654 COPY_SCALAR_FIELD(behavior);
1659 static AlterDomainStmt *
1660 _copyAlterDomainStmt(AlterDomainStmt *from)
1662 AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1664 COPY_SCALAR_FIELD(subtype);
1665 COPY_NODE_FIELD(typename);
1666 COPY_STRING_FIELD(name);
1667 COPY_NODE_FIELD(def);
1668 COPY_SCALAR_FIELD(behavior);
1674 _copyGrantStmt(GrantStmt *from)
1676 GrantStmt *newnode = makeNode(GrantStmt);
1678 COPY_SCALAR_FIELD(is_grant);
1679 COPY_SCALAR_FIELD(objtype);
1680 COPY_NODE_FIELD(objects);
1681 COPY_INTLIST_FIELD(privileges);
1682 COPY_NODE_FIELD(grantees);
1683 COPY_SCALAR_FIELD(grant_option);
1684 COPY_SCALAR_FIELD(behavior);
1689 static PrivGrantee *
1690 _copyPrivGrantee(PrivGrantee *from)
1692 PrivGrantee *newnode = makeNode(PrivGrantee);
1694 COPY_STRING_FIELD(username);
1695 COPY_STRING_FIELD(groupname);
1700 static FuncWithArgs *
1701 _copyFuncWithArgs(FuncWithArgs *from)
1703 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1705 COPY_NODE_FIELD(funcname);
1706 COPY_NODE_FIELD(funcargs);
1711 static DeclareCursorStmt *
1712 _copyDeclareCursorStmt(DeclareCursorStmt *from)
1714 DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
1716 COPY_STRING_FIELD(portalname);
1717 COPY_SCALAR_FIELD(options);
1718 COPY_NODE_FIELD(query);
1723 static ClosePortalStmt *
1724 _copyClosePortalStmt(ClosePortalStmt *from)
1726 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1728 COPY_STRING_FIELD(portalname);
1733 static ClusterStmt *
1734 _copyClusterStmt(ClusterStmt *from)
1736 ClusterStmt *newnode = makeNode(ClusterStmt);
1738 COPY_NODE_FIELD(relation);
1739 COPY_STRING_FIELD(indexname);
1745 _copyCopyStmt(CopyStmt *from)
1747 CopyStmt *newnode = makeNode(CopyStmt);
1749 COPY_NODE_FIELD(relation);
1750 COPY_NODE_FIELD(attlist);
1751 COPY_SCALAR_FIELD(is_from);
1752 COPY_STRING_FIELD(filename);
1753 COPY_NODE_FIELD(options);
1759 _copyCreateStmt(CreateStmt *from)
1761 CreateStmt *newnode = makeNode(CreateStmt);
1763 COPY_NODE_FIELD(relation);
1764 COPY_NODE_FIELD(tableElts);
1765 COPY_NODE_FIELD(inhRelations);
1766 COPY_NODE_FIELD(constraints);
1767 COPY_SCALAR_FIELD(hasoids);
1768 COPY_SCALAR_FIELD(oncommit);
1773 static InhRelation *
1774 _copyInhRelation(InhRelation *from)
1776 InhRelation *newnode = makeNode(InhRelation);
1778 COPY_NODE_FIELD(relation);
1779 COPY_SCALAR_FIELD(including_defaults);
1785 _copyDefineStmt(DefineStmt *from)
1787 DefineStmt *newnode = makeNode(DefineStmt);
1789 COPY_SCALAR_FIELD(kind);
1790 COPY_NODE_FIELD(defnames);
1791 COPY_NODE_FIELD(definition);
1797 _copyDropStmt(DropStmt *from)
1799 DropStmt *newnode = makeNode(DropStmt);
1801 COPY_NODE_FIELD(objects);
1802 COPY_SCALAR_FIELD(removeType);
1803 COPY_SCALAR_FIELD(behavior);
1808 static TruncateStmt *
1809 _copyTruncateStmt(TruncateStmt *from)
1811 TruncateStmt *newnode = makeNode(TruncateStmt);
1813 COPY_NODE_FIELD(relation);
1818 static CommentStmt *
1819 _copyCommentStmt(CommentStmt *from)
1821 CommentStmt *newnode = makeNode(CommentStmt);
1823 COPY_SCALAR_FIELD(objtype);
1824 COPY_NODE_FIELD(objname);
1825 COPY_NODE_FIELD(objargs);
1826 COPY_STRING_FIELD(comment);
1832 _copyFetchStmt(FetchStmt *from)
1834 FetchStmt *newnode = makeNode(FetchStmt);
1836 COPY_SCALAR_FIELD(direction);
1837 COPY_SCALAR_FIELD(howMany);
1838 COPY_STRING_FIELD(portalname);
1839 COPY_SCALAR_FIELD(ismove);
1845 _copyIndexStmt(IndexStmt *from)
1847 IndexStmt *newnode = makeNode(IndexStmt);
1849 COPY_STRING_FIELD(idxname);
1850 COPY_NODE_FIELD(relation);
1851 COPY_STRING_FIELD(accessMethod);
1852 COPY_NODE_FIELD(indexParams);
1853 COPY_NODE_FIELD(whereClause);
1854 COPY_NODE_FIELD(rangetable);
1855 COPY_SCALAR_FIELD(unique);
1856 COPY_SCALAR_FIELD(primary);
1857 COPY_SCALAR_FIELD(isconstraint);
1862 static CreateFunctionStmt *
1863 _copyCreateFunctionStmt(CreateFunctionStmt *from)
1865 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
1867 COPY_SCALAR_FIELD(replace);
1868 COPY_NODE_FIELD(funcname);
1869 COPY_NODE_FIELD(argTypes);
1870 COPY_NODE_FIELD(returnType);
1871 COPY_NODE_FIELD(options);
1872 COPY_NODE_FIELD(withClause);
1877 static RemoveAggrStmt *
1878 _copyRemoveAggrStmt(RemoveAggrStmt *from)
1880 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1882 COPY_NODE_FIELD(aggname);
1883 COPY_NODE_FIELD(aggtype);
1884 COPY_SCALAR_FIELD(behavior);
1889 static RemoveFuncStmt *
1890 _copyRemoveFuncStmt(RemoveFuncStmt *from)
1892 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
1894 COPY_NODE_FIELD(funcname);
1895 COPY_NODE_FIELD(args);
1896 COPY_SCALAR_FIELD(behavior);
1901 static RemoveOperStmt *
1902 _copyRemoveOperStmt(RemoveOperStmt *from)
1904 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
1906 COPY_NODE_FIELD(opname);
1907 COPY_NODE_FIELD(args);
1908 COPY_SCALAR_FIELD(behavior);
1913 static RemoveOpClassStmt *
1914 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
1916 RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
1918 COPY_NODE_FIELD(opclassname);
1919 COPY_STRING_FIELD(amname);
1920 COPY_SCALAR_FIELD(behavior);
1926 _copyRenameStmt(RenameStmt *from)
1928 RenameStmt *newnode = makeNode(RenameStmt);
1930 COPY_NODE_FIELD(relation);
1931 COPY_NODE_FIELD(object);
1932 COPY_NODE_FIELD(objarg);
1933 COPY_STRING_FIELD(subname);
1934 COPY_STRING_FIELD(newname);
1935 COPY_SCALAR_FIELD(renameType);
1941 _copyRuleStmt(RuleStmt *from)
1943 RuleStmt *newnode = makeNode(RuleStmt);
1945 COPY_NODE_FIELD(relation);
1946 COPY_STRING_FIELD(rulename);
1947 COPY_NODE_FIELD(whereClause);
1948 COPY_SCALAR_FIELD(event);
1949 COPY_SCALAR_FIELD(instead);
1950 COPY_NODE_FIELD(actions);
1951 COPY_SCALAR_FIELD(replace);
1957 _copyNotifyStmt(NotifyStmt *from)
1959 NotifyStmt *newnode = makeNode(NotifyStmt);
1961 COPY_NODE_FIELD(relation);
1967 _copyListenStmt(ListenStmt *from)
1969 ListenStmt *newnode = makeNode(ListenStmt);
1971 COPY_NODE_FIELD(relation);
1976 static UnlistenStmt *
1977 _copyUnlistenStmt(UnlistenStmt *from)
1979 UnlistenStmt *newnode = makeNode(UnlistenStmt);
1981 COPY_NODE_FIELD(relation);
1986 static TransactionStmt *
1987 _copyTransactionStmt(TransactionStmt *from)
1989 TransactionStmt *newnode = makeNode(TransactionStmt);
1991 COPY_SCALAR_FIELD(kind);
1992 COPY_NODE_FIELD(options);
1997 static CompositeTypeStmt *
1998 _copyCompositeTypeStmt(CompositeTypeStmt *from)
2000 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
2002 COPY_NODE_FIELD(typevar);
2003 COPY_NODE_FIELD(coldeflist);
2009 _copyViewStmt(ViewStmt *from)
2011 ViewStmt *newnode = makeNode(ViewStmt);
2013 COPY_NODE_FIELD(view);
2014 COPY_NODE_FIELD(aliases);
2015 COPY_NODE_FIELD(query);
2016 COPY_SCALAR_FIELD(replace);
2022 _copyLoadStmt(LoadStmt *from)
2024 LoadStmt *newnode = makeNode(LoadStmt);
2026 COPY_STRING_FIELD(filename);
2031 static CreateDomainStmt *
2032 _copyCreateDomainStmt(CreateDomainStmt *from)
2034 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2036 COPY_NODE_FIELD(domainname);
2037 COPY_NODE_FIELD(typename);
2038 COPY_NODE_FIELD(constraints);
2043 static CreateOpClassStmt *
2044 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2046 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2048 COPY_NODE_FIELD(opclassname);
2049 COPY_STRING_FIELD(amname);
2050 COPY_NODE_FIELD(datatype);
2051 COPY_NODE_FIELD(items);
2052 COPY_SCALAR_FIELD(isDefault);
2057 static CreateOpClassItem *
2058 _copyCreateOpClassItem(CreateOpClassItem *from)
2060 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2062 COPY_SCALAR_FIELD(itemtype);
2063 COPY_NODE_FIELD(name);
2064 COPY_NODE_FIELD(args);
2065 COPY_SCALAR_FIELD(number);
2066 COPY_SCALAR_FIELD(recheck);
2067 COPY_NODE_FIELD(storedtype);
2072 static CreatedbStmt *
2073 _copyCreatedbStmt(CreatedbStmt *from)
2075 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2077 COPY_STRING_FIELD(dbname);
2078 COPY_NODE_FIELD(options);
2083 static AlterDatabaseSetStmt *
2084 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2086 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2088 COPY_STRING_FIELD(dbname);
2089 COPY_STRING_FIELD(variable);
2090 COPY_NODE_FIELD(value);
2096 _copyDropdbStmt(DropdbStmt *from)
2098 DropdbStmt *newnode = makeNode(DropdbStmt);
2100 COPY_STRING_FIELD(dbname);
2106 _copyVacuumStmt(VacuumStmt *from)
2108 VacuumStmt *newnode = makeNode(VacuumStmt);
2110 COPY_SCALAR_FIELD(vacuum);
2111 COPY_SCALAR_FIELD(full);
2112 COPY_SCALAR_FIELD(analyze);
2113 COPY_SCALAR_FIELD(freeze);
2114 COPY_SCALAR_FIELD(verbose);
2115 COPY_NODE_FIELD(relation);
2116 COPY_NODE_FIELD(va_cols);
2121 static ExplainStmt *
2122 _copyExplainStmt(ExplainStmt *from)
2124 ExplainStmt *newnode = makeNode(ExplainStmt);
2126 COPY_NODE_FIELD(query);
2127 COPY_SCALAR_FIELD(verbose);
2128 COPY_SCALAR_FIELD(analyze);
2133 static CreateSeqStmt *
2134 _copyCreateSeqStmt(CreateSeqStmt *from)
2136 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2138 COPY_NODE_FIELD(sequence);
2139 COPY_NODE_FIELD(options);
2144 static AlterSeqStmt *
2145 _copyAlterSeqStmt(AlterSeqStmt *from)
2147 AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
2149 COPY_NODE_FIELD(sequence);
2150 COPY_NODE_FIELD(options);
2155 static VariableSetStmt *
2156 _copyVariableSetStmt(VariableSetStmt *from)
2158 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2160 COPY_STRING_FIELD(name);
2161 COPY_NODE_FIELD(args);
2162 COPY_SCALAR_FIELD(is_local);
2167 static VariableShowStmt *
2168 _copyVariableShowStmt(VariableShowStmt *from)
2170 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2172 COPY_STRING_FIELD(name);
2177 static VariableResetStmt *
2178 _copyVariableResetStmt(VariableResetStmt *from)
2180 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2182 COPY_STRING_FIELD(name);
2187 static CreateTrigStmt *
2188 _copyCreateTrigStmt(CreateTrigStmt *from)
2190 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2192 COPY_STRING_FIELD(trigname);
2193 COPY_NODE_FIELD(relation);
2194 COPY_NODE_FIELD(funcname);
2195 COPY_NODE_FIELD(args);
2196 COPY_SCALAR_FIELD(before);
2197 COPY_SCALAR_FIELD(row);
2198 strcpy(newnode->actions, from->actions); /* in-line string field */
2199 COPY_SCALAR_FIELD(isconstraint);
2200 COPY_SCALAR_FIELD(deferrable);
2201 COPY_SCALAR_FIELD(initdeferred);
2202 COPY_NODE_FIELD(constrrel);
2207 static DropPropertyStmt *
2208 _copyDropPropertyStmt(DropPropertyStmt *from)
2210 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2212 COPY_NODE_FIELD(relation);
2213 COPY_STRING_FIELD(property);
2214 COPY_SCALAR_FIELD(removeType);
2215 COPY_SCALAR_FIELD(behavior);
2220 static CreatePLangStmt *
2221 _copyCreatePLangStmt(CreatePLangStmt *from)
2223 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2225 COPY_STRING_FIELD(plname);
2226 COPY_NODE_FIELD(plhandler);
2227 COPY_NODE_FIELD(plvalidator);
2228 COPY_SCALAR_FIELD(pltrusted);
2233 static DropPLangStmt *
2234 _copyDropPLangStmt(DropPLangStmt *from)
2236 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2238 COPY_STRING_FIELD(plname);
2239 COPY_SCALAR_FIELD(behavior);
2244 static CreateUserStmt *
2245 _copyCreateUserStmt(CreateUserStmt *from)
2247 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2249 COPY_STRING_FIELD(user);
2250 COPY_NODE_FIELD(options);
2255 static AlterUserStmt *
2256 _copyAlterUserStmt(AlterUserStmt *from)
2258 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2260 COPY_STRING_FIELD(user);
2261 COPY_NODE_FIELD(options);
2266 static AlterUserSetStmt *
2267 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2269 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2271 COPY_STRING_FIELD(user);
2272 COPY_STRING_FIELD(variable);
2273 COPY_NODE_FIELD(value);
2278 static DropUserStmt *
2279 _copyDropUserStmt(DropUserStmt *from)
2281 DropUserStmt *newnode = makeNode(DropUserStmt);
2283 COPY_NODE_FIELD(users);
2289 _copyLockStmt(LockStmt *from)
2291 LockStmt *newnode = makeNode(LockStmt);
2293 COPY_NODE_FIELD(relations);
2294 COPY_SCALAR_FIELD(mode);
2299 static ConstraintsSetStmt *
2300 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2302 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2304 COPY_NODE_FIELD(constraints);
2305 COPY_SCALAR_FIELD(deferred);
2310 static CreateGroupStmt *
2311 _copyCreateGroupStmt(CreateGroupStmt *from)
2313 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2315 COPY_STRING_FIELD(name);
2316 COPY_NODE_FIELD(options);
2321 static AlterGroupStmt *
2322 _copyAlterGroupStmt(AlterGroupStmt *from)
2324 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2326 COPY_STRING_FIELD(name);
2327 COPY_SCALAR_FIELD(action);
2328 COPY_NODE_FIELD(listUsers);
2333 static DropGroupStmt *
2334 _copyDropGroupStmt(DropGroupStmt *from)
2336 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2338 COPY_STRING_FIELD(name);
2343 static ReindexStmt *
2344 _copyReindexStmt(ReindexStmt *from)
2346 ReindexStmt *newnode = makeNode(ReindexStmt);
2348 COPY_SCALAR_FIELD(kind);
2349 COPY_NODE_FIELD(relation);
2350 COPY_STRING_FIELD(name);
2351 COPY_SCALAR_FIELD(force);
2352 COPY_SCALAR_FIELD(all);
2357 static CreateSchemaStmt *
2358 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2360 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2362 COPY_STRING_FIELD(schemaname);
2363 COPY_STRING_FIELD(authid);
2364 COPY_NODE_FIELD(schemaElts);
2369 static CreateConversionStmt *
2370 _copyCreateConversionStmt(CreateConversionStmt *from)
2372 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2374 COPY_NODE_FIELD(conversion_name);
2375 COPY_STRING_FIELD(for_encoding_name);
2376 COPY_STRING_FIELD(to_encoding_name);
2377 COPY_NODE_FIELD(func_name);
2378 COPY_SCALAR_FIELD(def);
2383 static CreateCastStmt *
2384 _copyCreateCastStmt(CreateCastStmt *from)
2386 CreateCastStmt *newnode = makeNode(CreateCastStmt);
2388 COPY_NODE_FIELD(sourcetype);
2389 COPY_NODE_FIELD(targettype);
2390 COPY_NODE_FIELD(func);
2391 COPY_SCALAR_FIELD(context);
2396 static DropCastStmt *
2397 _copyDropCastStmt(DropCastStmt *from)
2399 DropCastStmt *newnode = makeNode(DropCastStmt);
2401 COPY_NODE_FIELD(sourcetype);
2402 COPY_NODE_FIELD(targettype);
2403 COPY_SCALAR_FIELD(behavior);
2408 static PrepareStmt *
2409 _copyPrepareStmt(PrepareStmt *from)
2411 PrepareStmt *newnode = makeNode(PrepareStmt);
2413 COPY_STRING_FIELD(name);
2414 COPY_NODE_FIELD(argtypes);
2415 COPY_OIDLIST_FIELD(argtype_oids);
2416 COPY_NODE_FIELD(query);
2421 static ExecuteStmt *
2422 _copyExecuteStmt(ExecuteStmt *from)
2424 ExecuteStmt *newnode = makeNode(ExecuteStmt);
2426 COPY_STRING_FIELD(name);
2427 COPY_NODE_FIELD(into);
2428 COPY_NODE_FIELD(params);
2433 static DeallocateStmt *
2434 _copyDeallocateStmt(DeallocateStmt *from)
2436 DeallocateStmt *newnode = makeNode(DeallocateStmt);
2438 COPY_STRING_FIELD(name);
2444 /* ****************************************************************
2445 * pg_list.h copy functions
2446 * ****************************************************************
2450 _copyValue(Value *from)
2452 Value *newnode = makeNode(Value);
2454 /* See also _copyAConst when changing this code! */
2456 COPY_SCALAR_FIELD(type);
2460 COPY_SCALAR_FIELD(val.ival);
2465 COPY_STRING_FIELD(val.str);
2471 elog(ERROR, "unrecognized node type: %d",
2481 * Create a copy of a Node tree or list. This is a "deep" copy: all
2482 * substructure is copied too, recursively.
2485 copyObject(void *from)
2492 switch (nodeTag(from))
2498 retval = _copyPlan(from);
2501 retval = _copyResult(from);
2504 retval = _copyAppend(from);
2507 retval = _copyScan(from);
2510 retval = _copySeqScan(from);
2513 retval = _copyIndexScan(from);
2516 retval = _copyTidScan(from);
2518 case T_SubqueryScan:
2519 retval = _copySubqueryScan(from);
2521 case T_FunctionScan:
2522 retval = _copyFunctionScan(from);
2525 retval = _copyJoin(from);
2528 retval = _copyNestLoop(from);
2531 retval = _copyMergeJoin(from);
2534 retval = _copyHashJoin(from);
2537 retval = _copyMaterial(from);
2540 retval = _copySort(from);
2543 retval = _copyGroup(from);
2546 retval = _copyAgg(from);
2549 retval = _copyUnique(from);
2552 retval = _copyHash(from);
2555 retval = _copySetOp(from);
2558 retval = _copyLimit(from);
2565 retval = _copyResdom(from);
2568 retval = _copyAlias(from);
2571 retval = _copyRangeVar(from);
2574 retval = _copyVar(from);
2577 retval = _copyConst(from);
2580 retval = _copyParam(from);
2583 retval = _copyAggref(from);
2586 retval = _copyArrayRef(from);
2589 retval = _copyFuncExpr(from);
2592 retval = _copyOpExpr(from);
2594 case T_DistinctExpr:
2595 retval = _copyDistinctExpr(from);
2597 case T_ScalarArrayOpExpr:
2598 retval = _copyScalarArrayOpExpr(from);
2601 retval = _copyBoolExpr(from);
2604 retval = _copySubLink(from);
2607 retval = _copySubPlan(from);
2610 retval = _copyFieldSelect(from);
2613 retval = _copyRelabelType(from);
2616 retval = _copyCaseExpr(from);
2619 retval = _copyCaseWhen(from);
2622 retval = _copyArrayExpr(from);
2624 case T_CoalesceExpr:
2625 retval = _copyCoalesceExpr(from);
2628 retval = _copyNullIfExpr(from);
2631 retval = _copyNullTest(from);
2634 retval = _copyBooleanTest(from);
2636 case T_CoerceToDomain:
2637 retval = _copyCoerceToDomain(from);
2639 case T_CoerceToDomainValue:
2640 retval = _copyCoerceToDomainValue(from);
2642 case T_SetToDefault:
2643 retval = _copySetToDefault(from);
2646 retval = _copyTargetEntry(from);
2649 retval = _copyRangeTblRef(from);
2652 retval = _copyJoinExpr(from);
2655 retval = _copyFromExpr(from);
2662 retval = _copyPathKeyItem(from);
2664 case T_RestrictInfo:
2665 retval = _copyRestrictInfo(from);
2668 retval = _copyJoinInfo(from);
2670 case T_InClauseInfo:
2671 retval = _copyInClauseInfo(from);
2682 retval = _copyValue(from);
2691 /* rather ugly coding for speed... */
2692 /* Note the input list cannot be NIL if we got here. */
2693 newcell = makeNode(List);
2694 lfirst(newcell) = copyObject(lfirst(list));
2696 retval = (void *) newcell;
2699 foreach(oldl, lnext(list))
2701 newcell = makeNode(List);
2702 lfirst(newcell) = copyObject(lfirst(oldl));
2703 prev->next = newcell;
2714 retval = _copyQuery(from);
2717 retval = _copyInsertStmt(from);
2720 retval = _copyDeleteStmt(from);
2723 retval = _copyUpdateStmt(from);
2726 retval = _copySelectStmt(from);
2728 case T_SetOperationStmt:
2729 retval = _copySetOperationStmt(from);
2731 case T_AlterTableStmt:
2732 retval = _copyAlterTableStmt(from);
2734 case T_AlterDomainStmt:
2735 retval = _copyAlterDomainStmt(from);
2738 retval = _copyGrantStmt(from);
2740 case T_DeclareCursorStmt:
2741 retval = _copyDeclareCursorStmt(from);
2743 case T_ClosePortalStmt:
2744 retval = _copyClosePortalStmt(from);
2747 retval = _copyClusterStmt(from);
2750 retval = _copyCopyStmt(from);
2753 retval = _copyCreateStmt(from);
2756 retval = _copyInhRelation(from);
2759 retval = _copyDefineStmt(from);
2762 retval = _copyDropStmt(from);
2764 case T_TruncateStmt:
2765 retval = _copyTruncateStmt(from);
2768 retval = _copyCommentStmt(from);
2771 retval = _copyFetchStmt(from);
2774 retval = _copyIndexStmt(from);
2776 case T_CreateFunctionStmt:
2777 retval = _copyCreateFunctionStmt(from);
2779 case T_RemoveAggrStmt:
2780 retval = _copyRemoveAggrStmt(from);
2782 case T_RemoveFuncStmt:
2783 retval = _copyRemoveFuncStmt(from);
2785 case T_RemoveOperStmt:
2786 retval = _copyRemoveOperStmt(from);
2788 case T_RemoveOpClassStmt:
2789 retval = _copyRemoveOpClassStmt(from);
2792 retval = _copyRenameStmt(from);
2795 retval = _copyRuleStmt(from);
2798 retval = _copyNotifyStmt(from);
2801 retval = _copyListenStmt(from);
2803 case T_UnlistenStmt:
2804 retval = _copyUnlistenStmt(from);
2806 case T_TransactionStmt:
2807 retval = _copyTransactionStmt(from);
2809 case T_CompositeTypeStmt:
2810 retval = _copyCompositeTypeStmt(from);
2813 retval = _copyViewStmt(from);
2816 retval = _copyLoadStmt(from);
2818 case T_CreateDomainStmt:
2819 retval = _copyCreateDomainStmt(from);
2821 case T_CreateOpClassStmt:
2822 retval = _copyCreateOpClassStmt(from);
2824 case T_CreateOpClassItem:
2825 retval = _copyCreateOpClassItem(from);
2827 case T_CreatedbStmt:
2828 retval = _copyCreatedbStmt(from);
2830 case T_AlterDatabaseSetStmt:
2831 retval = _copyAlterDatabaseSetStmt(from);
2834 retval = _copyDropdbStmt(from);
2837 retval = _copyVacuumStmt(from);
2840 retval = _copyExplainStmt(from);
2842 case T_CreateSeqStmt:
2843 retval = _copyCreateSeqStmt(from);
2845 case T_AlterSeqStmt:
2846 retval = _copyAlterSeqStmt(from);
2848 case T_VariableSetStmt:
2849 retval = _copyVariableSetStmt(from);
2851 case T_VariableShowStmt:
2852 retval = _copyVariableShowStmt(from);
2854 case T_VariableResetStmt:
2855 retval = _copyVariableResetStmt(from);
2857 case T_CreateTrigStmt:
2858 retval = _copyCreateTrigStmt(from);
2860 case T_DropPropertyStmt:
2861 retval = _copyDropPropertyStmt(from);
2863 case T_CreatePLangStmt:
2864 retval = _copyCreatePLangStmt(from);
2866 case T_DropPLangStmt:
2867 retval = _copyDropPLangStmt(from);
2869 case T_CreateUserStmt:
2870 retval = _copyCreateUserStmt(from);
2872 case T_AlterUserStmt:
2873 retval = _copyAlterUserStmt(from);
2875 case T_AlterUserSetStmt:
2876 retval = _copyAlterUserSetStmt(from);
2878 case T_DropUserStmt:
2879 retval = _copyDropUserStmt(from);
2882 retval = _copyLockStmt(from);
2884 case T_ConstraintsSetStmt:
2885 retval = _copyConstraintsSetStmt(from);
2887 case T_CreateGroupStmt:
2888 retval = _copyCreateGroupStmt(from);
2890 case T_AlterGroupStmt:
2891 retval = _copyAlterGroupStmt(from);
2893 case T_DropGroupStmt:
2894 retval = _copyDropGroupStmt(from);
2897 retval = _copyReindexStmt(from);
2899 case T_CheckPointStmt:
2900 retval = (void *) makeNode(CheckPointStmt);
2902 case T_CreateSchemaStmt:
2903 retval = _copyCreateSchemaStmt(from);
2905 case T_CreateConversionStmt:
2906 retval = _copyCreateConversionStmt(from);
2908 case T_CreateCastStmt:
2909 retval = _copyCreateCastStmt(from);
2911 case T_DropCastStmt:
2912 retval = _copyDropCastStmt(from);
2915 retval = _copyPrepareStmt(from);
2918 retval = _copyExecuteStmt(from);
2920 case T_DeallocateStmt:
2921 retval = _copyDeallocateStmt(from);
2925 retval = _copyAExpr(from);
2928 retval = _copyColumnRef(from);
2931 retval = _copyParamRef(from);
2934 retval = _copyAConst(from);
2937 retval = _copyFuncCall(from);
2940 retval = _copyAIndices(from);
2942 case T_ExprFieldSelect:
2943 retval = _copyExprFieldSelect(from);
2946 retval = _copyResTarget(from);
2949 retval = _copyTypeCast(from);
2952 retval = _copySortBy(from);
2954 case T_RangeSubselect:
2955 retval = _copyRangeSubselect(from);
2957 case T_RangeFunction:
2958 retval = _copyRangeFunction(from);
2961 retval = _copyTypeName(from);
2964 retval = _copyIndexElem(from);
2967 retval = _copyColumnDef(from);
2970 retval = _copyConstraint(from);
2973 retval = _copyDefElem(from);
2975 case T_RangeTblEntry:
2976 retval = _copyRangeTblEntry(from);
2979 retval = _copySortClause(from);
2982 retval = _copyGroupClause(from);
2984 case T_FkConstraint:
2985 retval = _copyFkConstraint(from);
2988 retval = _copyPrivGrantee(from);
2990 case T_FuncWithArgs:
2991 retval = _copyFuncWithArgs(from);
2995 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
2996 retval = from; /* keep compiler quiet */