1 /*-------------------------------------------------------------------------
4 * Copy functions for Postgres tree nodes.
6 * NOTE: a general convention when copying or comparing plan nodes is
7 * that we ignore the executor state subnode. We do not need to look
8 * at it because no current uses of copyObject() or equal() need to
9 * deal with already-executing plan trees. By leaving the state subnodes
10 * out, we avoid needing to write copy/compare routines for all the
11 * different executor state node types.
14 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
15 * Portions Copyright (c) 1994, Regents of the University of California
18 * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.222 2002/11/25 03:33:27 tgl Exp $
20 *-------------------------------------------------------------------------
25 #include "optimizer/clauses.h"
26 #include "optimizer/planmain.h"
27 #include "utils/datum.h"
31 * Macros to simplify copying of different kinds of fields. Use these
32 * wherever possible to reduce the chance for silly typos. Note that these
33 * hard-wire the convention that the local variables in a Copy routine are
34 * named 'newnode' and 'from'.
37 /* Copy a simple scalar field (int, float, bool, enum, etc) */
38 #define COPY_SCALAR_FIELD(fldname) \
39 (newnode->fldname = from->fldname)
41 /* Copy a field that is a pointer to some kind of Node or Node tree */
42 #define COPY_NODE_FIELD(fldname) \
43 (newnode->fldname = copyObject(from->fldname))
45 /* Copy a field that is a pointer to a list of integers */
46 #define COPY_INTLIST_FIELD(fldname) \
47 (newnode->fldname = listCopy(from->fldname))
49 /* Copy a field that is a pointer to a C string, or perhaps NULL */
50 #define COPY_STRING_FIELD(fldname) \
51 (newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)
53 /* Copy a field that is a pointer to a simple palloc'd object of size sz */
54 #define COPY_POINTER_FIELD(fldname, sz) \
57 newnode->fldname = palloc(_size); \
58 memcpy(newnode->fldname, from->fldname, _size); \
61 /* Special hack for fixing subplan lists of Plan nodes (ick) */
62 #define FIX_SUBPLAN_LINKS(subplanfldname, fldname) \
64 if (from->subplanfldname != NIL) \
65 newnode->subplanfldname = \
66 nconc(newnode->subplanfldname, \
67 pull_subplans((Node *) (newnode->fldname))); \
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, which is
77 * grotty but unlikely to break --- it could fail if sizeof(pointer)
78 * is less than sizeof(int), but I don't know any such machines...
80 * Note that copyObject will surely coredump if applied to a list
90 /* rather ugly coding for speed... */
94 newlist = nl = makeList1(lfirst(list));
96 foreach(l, lnext(list))
98 lnext(nl) = makeList1(lfirst(l));
104 /* ****************************************************************
105 * plannodes.h copy functions
106 * ****************************************************************
112 * This function copies the fields of the Plan node. It is used by
113 * all the copy functions for classes which inherit from Plan.
116 CopyPlanFields(Plan *from, Plan *newnode)
118 COPY_SCALAR_FIELD(startup_cost);
119 COPY_SCALAR_FIELD(total_cost);
120 COPY_SCALAR_FIELD(plan_rows);
121 COPY_SCALAR_FIELD(plan_width);
122 /* execution state is NOT copied */
123 COPY_NODE_FIELD(targetlist);
124 COPY_NODE_FIELD(qual);
125 COPY_NODE_FIELD(lefttree);
126 COPY_NODE_FIELD(righttree);
127 COPY_INTLIST_FIELD(extParam);
128 COPY_INTLIST_FIELD(locParam);
129 COPY_INTLIST_FIELD(chgParam);
130 COPY_NODE_FIELD(initPlan);
131 /* subPlan list must point to subplans in the new subtree, not the old */
132 newnode->subPlan = NIL;
133 FIX_SUBPLAN_LINKS(subPlan, targetlist);
134 FIX_SUBPLAN_LINKS(subPlan, qual);
135 COPY_SCALAR_FIELD(nParamExec);
142 _copyPlan(Plan *from)
144 Plan *newnode = makeNode(Plan);
147 * copy node superclass fields
149 CopyPlanFields(from, newnode);
159 _copyResult(Result *from)
161 Result *newnode = makeNode(Result);
164 * copy node superclass fields
166 CopyPlanFields((Plan *) from, (Plan *) newnode);
169 * copy remainder of node
171 COPY_NODE_FIELD(resconstantqual);
173 /* subPlan list must point to subplans in the new subtree, not the old */
174 FIX_SUBPLAN_LINKS(plan.subPlan, resconstantqual);
183 _copyAppend(Append *from)
185 Append *newnode = makeNode(Append);
188 * copy node superclass fields
190 CopyPlanFields((Plan *) from, (Plan *) newnode);
193 * copy remainder of node
195 COPY_NODE_FIELD(appendplans);
196 COPY_SCALAR_FIELD(isTarget);
205 * This function copies the fields of the Scan node. It is used by
206 * all the copy functions for classes which inherit from Scan.
209 CopyScanFields(Scan *from, Scan *newnode)
211 CopyPlanFields((Plan *) from, (Plan *) newnode);
213 COPY_SCALAR_FIELD(scanrelid);
220 _copyScan(Scan *from)
222 Scan *newnode = makeNode(Scan);
225 * copy node superclass fields
227 CopyScanFields((Scan *) from, (Scan *) newnode);
236 _copySeqScan(SeqScan *from)
238 SeqScan *newnode = makeNode(SeqScan);
241 * copy node superclass fields
243 CopyScanFields((Scan *) from, (Scan *) newnode);
252 _copyIndexScan(IndexScan *from)
254 IndexScan *newnode = makeNode(IndexScan);
257 * copy node superclass fields
259 CopyScanFields((Scan *) from, (Scan *) newnode);
262 * copy remainder of node
264 COPY_INTLIST_FIELD(indxid);
265 COPY_NODE_FIELD(indxqual);
266 COPY_NODE_FIELD(indxqualorig);
267 COPY_SCALAR_FIELD(indxorderdir);
269 /* subPlan list must point to subplans in the new subtree, not the old */
270 FIX_SUBPLAN_LINKS(scan.plan.subPlan, indxqual);
271 FIX_SUBPLAN_LINKS(scan.plan.subPlan, indxqualorig);
280 _copyTidScan(TidScan *from)
282 TidScan *newnode = makeNode(TidScan);
285 * copy node superclass fields
287 CopyScanFields((Scan *) from, (Scan *) newnode);
290 * copy remainder of node
292 COPY_SCALAR_FIELD(needRescan);
293 COPY_NODE_FIELD(tideval);
295 /* subPlan list must point to subplans in the new subtree, not the old */
296 FIX_SUBPLAN_LINKS(scan.plan.subPlan, tideval);
304 static SubqueryScan *
305 _copySubqueryScan(SubqueryScan *from)
307 SubqueryScan *newnode = makeNode(SubqueryScan);
310 * copy node superclass fields
312 CopyScanFields((Scan *) from, (Scan *) newnode);
315 * copy remainder of node
317 COPY_NODE_FIELD(subplan);
325 static FunctionScan *
326 _copyFunctionScan(FunctionScan *from)
328 FunctionScan *newnode = makeNode(FunctionScan);
331 * copy node superclass fields
333 CopyScanFields((Scan *) from, (Scan *) newnode);
341 * This function copies the fields of the Join node. It is used by
342 * all the copy functions for classes which inherit from Join.
345 CopyJoinFields(Join *from, Join *newnode)
347 CopyPlanFields((Plan *) from, (Plan *) newnode);
349 COPY_SCALAR_FIELD(jointype);
350 COPY_NODE_FIELD(joinqual);
352 /* subPlan list must point to subplans in the new subtree, not the old */
353 FIX_SUBPLAN_LINKS(plan.subPlan, joinqual);
361 _copyJoin(Join *from)
363 Join *newnode = makeNode(Join);
366 * copy node superclass fields
368 CopyJoinFields(from, newnode);
378 _copyNestLoop(NestLoop *from)
380 NestLoop *newnode = makeNode(NestLoop);
383 * copy node superclass fields
385 CopyJoinFields((Join *) from, (Join *) newnode);
395 _copyMergeJoin(MergeJoin *from)
397 MergeJoin *newnode = makeNode(MergeJoin);
400 * copy node superclass fields
402 CopyJoinFields((Join *) from, (Join *) newnode);
405 * copy remainder of node
407 COPY_NODE_FIELD(mergeclauses);
409 /* subPlan list must point to subplans in the new subtree, not the old */
410 FIX_SUBPLAN_LINKS(join.plan.subPlan, mergeclauses);
419 _copyHashJoin(HashJoin *from)
421 HashJoin *newnode = makeNode(HashJoin);
424 * copy node superclass fields
426 CopyJoinFields((Join *) from, (Join *) newnode);
429 * copy remainder of node
431 COPY_NODE_FIELD(hashclauses);
432 COPY_SCALAR_FIELD(hashjoinop);
434 /* subPlan list must point to subplans in the new subtree, not the old */
435 FIX_SUBPLAN_LINKS(join.plan.subPlan, hashclauses);
445 _copyMaterial(Material *from)
447 Material *newnode = makeNode(Material);
450 * copy node superclass fields
452 CopyPlanFields((Plan *) from, (Plan *) newnode);
462 _copySort(Sort *from)
464 Sort *newnode = makeNode(Sort);
467 * copy node superclass fields
469 CopyPlanFields((Plan *) from, (Plan *) newnode);
471 COPY_SCALAR_FIELD(keycount);
481 _copyGroup(Group *from)
483 Group *newnode = makeNode(Group);
485 CopyPlanFields((Plan *) from, (Plan *) newnode);
487 COPY_SCALAR_FIELD(numCols);
488 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
499 Agg *newnode = makeNode(Agg);
501 CopyPlanFields((Plan *) from, (Plan *) newnode);
503 COPY_SCALAR_FIELD(aggstrategy);
504 COPY_SCALAR_FIELD(numCols);
505 if (from->numCols > 0)
506 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
507 COPY_SCALAR_FIELD(numGroups);
516 _copyUnique(Unique *from)
518 Unique *newnode = makeNode(Unique);
521 * copy node superclass fields
523 CopyPlanFields((Plan *) from, (Plan *) newnode);
526 * copy remainder of node
528 COPY_SCALAR_FIELD(numCols);
529 COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
538 _copySetOp(SetOp *from)
540 SetOp *newnode = makeNode(SetOp);
543 * copy node superclass fields
545 CopyPlanFields((Plan *) from, (Plan *) newnode);
548 * copy remainder of node
550 COPY_SCALAR_FIELD(cmd);
551 COPY_SCALAR_FIELD(numCols);
552 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
553 COPY_SCALAR_FIELD(flagColIdx);
562 _copyLimit(Limit *from)
564 Limit *newnode = makeNode(Limit);
567 * copy node superclass fields
569 CopyPlanFields((Plan *) from, (Plan *) newnode);
572 * copy remainder of node
574 COPY_NODE_FIELD(limitOffset);
575 COPY_NODE_FIELD(limitCount);
584 _copyHash(Hash *from)
586 Hash *newnode = makeNode(Hash);
589 * copy node superclass fields
591 CopyPlanFields((Plan *) from, (Plan *) newnode);
594 * copy remainder of node
596 COPY_NODE_FIELD(hashkey);
598 /* XXX could the hashkey contain subplans? Not at present... */
604 _copySubPlan(SubPlan *from)
606 SubPlan *newnode = makeNode(SubPlan);
608 COPY_NODE_FIELD(plan);
609 COPY_SCALAR_FIELD(plan_id);
610 COPY_NODE_FIELD(rtable);
611 COPY_INTLIST_FIELD(setParam);
612 COPY_INTLIST_FIELD(parParam);
613 COPY_NODE_FIELD(sublink);
615 /* do not copy execution state */
616 newnode->needShutdown = false;
617 newnode->curTuple = NULL;
622 /* ****************************************************************
623 * primnodes.h copy functions
624 * ****************************************************************
631 _copyResdom(Resdom *from)
633 Resdom *newnode = makeNode(Resdom);
635 COPY_SCALAR_FIELD(resno);
636 COPY_SCALAR_FIELD(restype);
637 COPY_SCALAR_FIELD(restypmod);
638 COPY_STRING_FIELD(resname);
639 COPY_SCALAR_FIELD(ressortgroupref);
640 COPY_SCALAR_FIELD(reskey);
641 COPY_SCALAR_FIELD(reskeyop);
642 COPY_SCALAR_FIELD(resjunk);
648 _copyFjoin(Fjoin *from)
650 Fjoin *newnode = makeNode(Fjoin);
652 COPY_SCALAR_FIELD(fj_initialized);
653 COPY_SCALAR_FIELD(fj_nNodes);
654 COPY_NODE_FIELD(fj_innerNode);
655 COPY_POINTER_FIELD(fj_results, from->fj_nNodes * sizeof(Datum));
656 COPY_POINTER_FIELD(fj_alwaysDone, from->fj_nNodes * sizeof(bool));
662 _copyAlias(Alias *from)
664 Alias *newnode = makeNode(Alias);
666 COPY_STRING_FIELD(aliasname);
667 COPY_NODE_FIELD(colnames);
673 _copyRangeVar(RangeVar *from)
675 RangeVar *newnode = makeNode(RangeVar);
677 COPY_STRING_FIELD(catalogname);
678 COPY_STRING_FIELD(schemaname);
679 COPY_STRING_FIELD(relname);
680 COPY_SCALAR_FIELD(inhOpt);
681 COPY_SCALAR_FIELD(istemp);
682 COPY_NODE_FIELD(alias);
691 _copyExpr(Expr *from)
693 Expr *newnode = makeNode(Expr);
695 COPY_SCALAR_FIELD(typeOid);
696 COPY_SCALAR_FIELD(opType);
697 COPY_NODE_FIELD(oper);
698 COPY_NODE_FIELD(args);
709 Var *newnode = makeNode(Var);
711 COPY_SCALAR_FIELD(varno);
712 COPY_SCALAR_FIELD(varattno);
713 COPY_SCALAR_FIELD(vartype);
714 COPY_SCALAR_FIELD(vartypmod);
715 COPY_SCALAR_FIELD(varlevelsup);
716 COPY_SCALAR_FIELD(varnoold);
717 COPY_SCALAR_FIELD(varoattno);
726 _copyOper(Oper *from)
728 Oper *newnode = makeNode(Oper);
730 COPY_SCALAR_FIELD(opno);
731 COPY_SCALAR_FIELD(opid);
732 COPY_SCALAR_FIELD(opresulttype);
733 COPY_SCALAR_FIELD(opretset);
735 /* Do not copy the run-time state, if any */
736 newnode->op_fcache = NULL;
745 _copyConst(Const *from)
747 Const *newnode = makeNode(Const);
749 COPY_SCALAR_FIELD(consttype);
750 COPY_SCALAR_FIELD(constlen);
752 if (from->constbyval || from->constisnull)
755 * passed by value so just copy the datum. Also, don't try to copy
756 * struct when value is null!
758 newnode->constvalue = from->constvalue;
763 * passed by reference. We need a palloc'd copy.
765 newnode->constvalue = datumCopy(from->constvalue,
770 COPY_SCALAR_FIELD(constisnull);
771 COPY_SCALAR_FIELD(constbyval);
772 COPY_SCALAR_FIELD(constisset);
773 COPY_SCALAR_FIELD(constiscast);
782 _copyParam(Param *from)
784 Param *newnode = makeNode(Param);
786 COPY_SCALAR_FIELD(paramkind);
787 COPY_SCALAR_FIELD(paramid);
788 COPY_STRING_FIELD(paramname);
789 COPY_SCALAR_FIELD(paramtype);
798 _copyFunc(Func *from)
800 Func *newnode = makeNode(Func);
802 COPY_SCALAR_FIELD(funcid);
803 COPY_SCALAR_FIELD(funcresulttype);
804 COPY_SCALAR_FIELD(funcretset);
805 COPY_SCALAR_FIELD(funcformat);
807 /* Do not copy the run-time state, if any */
808 newnode->func_fcache = NULL;
817 _copyAggref(Aggref *from)
819 Aggref *newnode = makeNode(Aggref);
821 COPY_SCALAR_FIELD(aggfnoid);
822 COPY_SCALAR_FIELD(aggtype);
823 COPY_NODE_FIELD(target);
824 COPY_SCALAR_FIELD(aggstar);
825 COPY_SCALAR_FIELD(aggdistinct);
826 COPY_SCALAR_FIELD(aggno); /* probably not necessary */
835 _copySubLink(SubLink *from)
837 SubLink *newnode = makeNode(SubLink);
839 COPY_SCALAR_FIELD(subLinkType);
840 COPY_SCALAR_FIELD(useor);
841 COPY_NODE_FIELD(lefthand);
842 COPY_NODE_FIELD(oper);
843 COPY_NODE_FIELD(subselect);
852 _copyFieldSelect(FieldSelect *from)
854 FieldSelect *newnode = makeNode(FieldSelect);
856 COPY_NODE_FIELD(arg);
857 COPY_SCALAR_FIELD(fieldnum);
858 COPY_SCALAR_FIELD(resulttype);
859 COPY_SCALAR_FIELD(resulttypmod);
868 _copyRelabelType(RelabelType *from)
870 RelabelType *newnode = makeNode(RelabelType);
872 COPY_NODE_FIELD(arg);
873 COPY_SCALAR_FIELD(resulttype);
874 COPY_SCALAR_FIELD(resulttypmod);
875 COPY_SCALAR_FIELD(relabelformat);
881 _copyRangeTblRef(RangeTblRef *from)
883 RangeTblRef *newnode = makeNode(RangeTblRef);
885 COPY_SCALAR_FIELD(rtindex);
891 _copyJoinExpr(JoinExpr *from)
893 JoinExpr *newnode = makeNode(JoinExpr);
895 COPY_SCALAR_FIELD(jointype);
896 COPY_SCALAR_FIELD(isNatural);
897 COPY_NODE_FIELD(larg);
898 COPY_NODE_FIELD(rarg);
899 COPY_NODE_FIELD(using);
900 COPY_NODE_FIELD(quals);
901 COPY_NODE_FIELD(alias);
902 COPY_SCALAR_FIELD(rtindex);
908 _copyFromExpr(FromExpr *from)
910 FromExpr *newnode = makeNode(FromExpr);
912 COPY_NODE_FIELD(fromlist);
913 COPY_NODE_FIELD(quals);
919 _copyArrayRef(ArrayRef *from)
921 ArrayRef *newnode = makeNode(ArrayRef);
923 COPY_SCALAR_FIELD(refrestype);
924 COPY_SCALAR_FIELD(refattrlength);
925 COPY_SCALAR_FIELD(refelemlength);
926 COPY_SCALAR_FIELD(refelembyval);
927 COPY_SCALAR_FIELD(refelemalign);
928 COPY_NODE_FIELD(refupperindexpr);
929 COPY_NODE_FIELD(reflowerindexpr);
930 COPY_NODE_FIELD(refexpr);
931 COPY_NODE_FIELD(refassgnexpr);
936 /* ****************************************************************
937 * relation.h copy functions
939 * XXX the code to copy RelOptInfo and Path nodes is really completely bogus,
940 * because it makes no attempt to deal with multiple links from RelOptInfo
941 * to Paths, nor with back-links from Paths to their parent RelOptInfo.
942 * Currently, since we never actually try to copy a RelOptInfo, this is okay.
943 * ****************************************************************
950 _copyRelOptInfo(RelOptInfo *from)
952 RelOptInfo *newnode = makeNode(RelOptInfo);
954 COPY_SCALAR_FIELD(reloptkind);
955 COPY_INTLIST_FIELD(relids);
956 COPY_SCALAR_FIELD(rows);
957 COPY_SCALAR_FIELD(width);
958 COPY_NODE_FIELD(targetlist);
959 COPY_NODE_FIELD(pathlist);
960 /* XXX cheapest-path fields should point to members of pathlist? */
961 COPY_NODE_FIELD(cheapest_startup_path);
962 COPY_NODE_FIELD(cheapest_total_path);
963 COPY_SCALAR_FIELD(pruneable);
964 COPY_SCALAR_FIELD(rtekind);
965 COPY_NODE_FIELD(indexlist);
966 COPY_SCALAR_FIELD(pages);
967 COPY_SCALAR_FIELD(tuples);
968 COPY_NODE_FIELD(subplan);
969 COPY_SCALAR_FIELD(joinrti);
970 COPY_INTLIST_FIELD(joinrteids);
971 COPY_NODE_FIELD(baserestrictinfo);
972 COPY_SCALAR_FIELD(baserestrictcost);
973 COPY_INTLIST_FIELD(outerjoinset);
974 COPY_NODE_FIELD(joininfo);
975 COPY_INTLIST_FIELD(index_outer_relids);
976 COPY_NODE_FIELD(index_inner_paths);
984 static IndexOptInfo *
985 _copyIndexOptInfo(IndexOptInfo *from)
987 IndexOptInfo *newnode = makeNode(IndexOptInfo);
989 COPY_SCALAR_FIELD(indexoid);
990 COPY_SCALAR_FIELD(pages);
991 COPY_SCALAR_FIELD(tuples);
992 COPY_SCALAR_FIELD(ncolumns);
993 COPY_SCALAR_FIELD(nkeys);
997 /* copy the trailing zero too */
998 COPY_POINTER_FIELD(classlist, (from->ncolumns + 1) * sizeof(Oid));
1001 if (from->indexkeys)
1003 /* copy the trailing zero too */
1004 COPY_POINTER_FIELD(indexkeys, (from->nkeys + 1) * sizeof(int));
1009 /* copy the trailing zero too */
1010 COPY_POINTER_FIELD(ordering, (from->ncolumns + 1) * sizeof(Oid));
1013 COPY_SCALAR_FIELD(relam);
1014 COPY_SCALAR_FIELD(amcostestimate);
1015 COPY_SCALAR_FIELD(indproc);
1016 COPY_NODE_FIELD(indpred);
1017 COPY_SCALAR_FIELD(unique);
1018 COPY_INTLIST_FIELD(outer_relids);
1019 COPY_NODE_FIELD(inner_paths);
1027 * This function copies the fields of the Path node. It is used by
1028 * all the copy functions for classes which inherit from Path.
1031 CopyPathFields(Path *from, Path *newnode)
1034 * Modify the next line, since it causes the copying to cycle (i.e.
1035 * the parent points right back here! -- JMH, 7/7/92. Old version:
1036 * COPY_NODE_FIELD(parent);
1038 COPY_SCALAR_FIELD(parent);
1040 COPY_SCALAR_FIELD(startup_cost);
1041 COPY_SCALAR_FIELD(total_cost);
1042 COPY_SCALAR_FIELD(pathtype);
1043 COPY_NODE_FIELD(pathkeys);
1050 _copyPath(Path *from)
1052 Path *newnode = makeNode(Path);
1054 CopyPathFields(from, newnode);
1063 _copyIndexPath(IndexPath *from)
1065 IndexPath *newnode = makeNode(IndexPath);
1068 * copy node superclass fields
1070 CopyPathFields((Path *) from, (Path *) newnode);
1073 * copy remainder of node
1075 COPY_NODE_FIELD(indexinfo);
1076 COPY_NODE_FIELD(indexqual);
1077 COPY_SCALAR_FIELD(indexscandir);
1078 COPY_SCALAR_FIELD(rows);
1087 _copyTidPath(TidPath *from)
1089 TidPath *newnode = makeNode(TidPath);
1092 * copy node superclass fields
1094 CopyPathFields((Path *) from, (Path *) newnode);
1097 * copy remainder of node
1099 COPY_NODE_FIELD(tideval);
1100 COPY_INTLIST_FIELD(unjoined_relids);
1109 _copyAppendPath(AppendPath *from)
1111 AppendPath *newnode = makeNode(AppendPath);
1114 * copy node superclass fields
1116 CopyPathFields((Path *) from, (Path *) newnode);
1119 * copy remainder of node
1121 COPY_NODE_FIELD(subpaths);
1130 _copyResultPath(ResultPath *from)
1132 ResultPath *newnode = makeNode(ResultPath);
1135 * copy node superclass fields
1137 CopyPathFields((Path *) from, (Path *) newnode);
1140 * copy remainder of node
1142 COPY_NODE_FIELD(subpath);
1143 COPY_NODE_FIELD(constantqual);
1149 * CopyJoinPathFields
1151 * This function copies the fields of the JoinPath node. It is used by
1152 * all the copy functions for classes which inherit from JoinPath.
1155 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1157 CopyPathFields((Path *) from, (Path *) newnode);
1159 COPY_SCALAR_FIELD(jointype);
1160 COPY_NODE_FIELD(outerjoinpath);
1161 COPY_NODE_FIELD(innerjoinpath);
1162 COPY_NODE_FIELD(joinrestrictinfo);
1169 _copyNestPath(NestPath *from)
1171 NestPath *newnode = makeNode(NestPath);
1174 * copy node superclass fields
1176 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1185 _copyMergePath(MergePath *from)
1187 MergePath *newnode = makeNode(MergePath);
1190 * copy node superclass fields
1192 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1195 * copy remainder of node
1197 COPY_NODE_FIELD(path_mergeclauses);
1198 COPY_NODE_FIELD(outersortkeys);
1199 COPY_NODE_FIELD(innersortkeys);
1208 _copyHashPath(HashPath *from)
1210 HashPath *newnode = makeNode(HashPath);
1213 * copy node superclass fields
1215 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1218 * copy remainder of node
1220 COPY_NODE_FIELD(path_hashclauses);
1228 static PathKeyItem *
1229 _copyPathKeyItem(PathKeyItem *from)
1231 PathKeyItem *newnode = makeNode(PathKeyItem);
1233 COPY_NODE_FIELD(key);
1234 COPY_SCALAR_FIELD(sortop);
1242 static RestrictInfo *
1243 _copyRestrictInfo(RestrictInfo *from)
1245 RestrictInfo *newnode = makeNode(RestrictInfo);
1247 COPY_NODE_FIELD(clause);
1248 COPY_SCALAR_FIELD(ispusheddown);
1249 COPY_NODE_FIELD(subclauseindices); /* XXX probably bad */
1250 COPY_SCALAR_FIELD(eval_cost);
1251 COPY_SCALAR_FIELD(this_selec);
1252 COPY_SCALAR_FIELD(mergejoinoperator);
1253 COPY_SCALAR_FIELD(left_sortop);
1254 COPY_SCALAR_FIELD(right_sortop);
1257 * Do not copy pathkeys, since they'd not be canonical in a copied
1260 newnode->left_pathkey = NIL;
1261 newnode->right_pathkey = NIL;
1263 COPY_SCALAR_FIELD(left_mergescansel);
1264 COPY_SCALAR_FIELD(right_mergescansel);
1265 COPY_SCALAR_FIELD(hashjoinoperator);
1266 COPY_SCALAR_FIELD(left_bucketsize);
1267 COPY_SCALAR_FIELD(right_bucketsize);
1276 _copyJoinInfo(JoinInfo *from)
1278 JoinInfo *newnode = makeNode(JoinInfo);
1280 COPY_INTLIST_FIELD(unjoined_relids);
1281 COPY_NODE_FIELD(jinfo_restrictinfo);
1287 * _copyInnerIndexscanInfo
1289 static InnerIndexscanInfo *
1290 _copyInnerIndexscanInfo(InnerIndexscanInfo *from)
1292 InnerIndexscanInfo *newnode = makeNode(InnerIndexscanInfo);
1294 COPY_INTLIST_FIELD(other_relids);
1295 COPY_SCALAR_FIELD(isouterjoin);
1296 COPY_NODE_FIELD(best_innerpath);
1301 /* ****************************************************************
1302 * parsenodes.h copy functions
1303 * ****************************************************************
1306 static TargetEntry *
1307 _copyTargetEntry(TargetEntry *from)
1309 TargetEntry *newnode = makeNode(TargetEntry);
1311 COPY_NODE_FIELD(resdom);
1312 COPY_NODE_FIELD(fjoin);
1313 COPY_NODE_FIELD(expr);
1318 static RangeTblEntry *
1319 _copyRangeTblEntry(RangeTblEntry *from)
1321 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1323 COPY_SCALAR_FIELD(rtekind);
1324 COPY_SCALAR_FIELD(relid);
1325 COPY_NODE_FIELD(subquery);
1326 COPY_NODE_FIELD(funcexpr);
1327 COPY_NODE_FIELD(coldeflist);
1328 COPY_SCALAR_FIELD(jointype);
1329 COPY_NODE_FIELD(joinaliasvars);
1330 COPY_NODE_FIELD(alias);
1331 COPY_NODE_FIELD(eref);
1332 COPY_SCALAR_FIELD(inh);
1333 COPY_SCALAR_FIELD(inFromCl);
1334 COPY_SCALAR_FIELD(checkForRead);
1335 COPY_SCALAR_FIELD(checkForWrite);
1336 COPY_SCALAR_FIELD(checkAsUser);
1341 static FkConstraint *
1342 _copyFkConstraint(FkConstraint *from)
1344 FkConstraint *newnode = makeNode(FkConstraint);
1346 COPY_STRING_FIELD(constr_name);
1347 COPY_NODE_FIELD(pktable);
1348 COPY_NODE_FIELD(fk_attrs);
1349 COPY_NODE_FIELD(pk_attrs);
1350 COPY_SCALAR_FIELD(fk_matchtype);
1351 COPY_SCALAR_FIELD(fk_upd_action);
1352 COPY_SCALAR_FIELD(fk_del_action);
1353 COPY_SCALAR_FIELD(deferrable);
1354 COPY_SCALAR_FIELD(initdeferred);
1355 COPY_SCALAR_FIELD(skip_validation);
1361 _copySortClause(SortClause *from)
1363 SortClause *newnode = makeNode(SortClause);
1365 COPY_SCALAR_FIELD(tleSortGroupRef);
1366 COPY_SCALAR_FIELD(sortop);
1371 static GroupClause *
1372 _copyGroupClause(GroupClause *from)
1374 GroupClause *newnode = makeNode(GroupClause);
1376 COPY_SCALAR_FIELD(tleSortGroupRef);
1377 COPY_SCALAR_FIELD(sortop);
1383 _copyAExpr(A_Expr *from)
1385 A_Expr *newnode = makeNode(A_Expr);
1387 COPY_SCALAR_FIELD(oper);
1388 COPY_NODE_FIELD(name);
1389 COPY_NODE_FIELD(lexpr);
1390 COPY_NODE_FIELD(rexpr);
1396 _copyColumnRef(ColumnRef *from)
1398 ColumnRef *newnode = makeNode(ColumnRef);
1400 COPY_NODE_FIELD(fields);
1401 COPY_NODE_FIELD(indirection);
1407 _copyParamRef(ParamRef *from)
1409 ParamRef *newnode = makeNode(ParamRef);
1411 COPY_SCALAR_FIELD(number);
1412 COPY_NODE_FIELD(fields);
1413 COPY_NODE_FIELD(indirection);
1419 _copyAConst(A_Const *from)
1421 A_Const *newnode = makeNode(A_Const);
1423 /* This part must duplicate _copyValue */
1424 COPY_SCALAR_FIELD(val.type);
1425 switch (from->val.type)
1428 COPY_SCALAR_FIELD(val.val.ival);
1433 COPY_STRING_FIELD(val.val.str);
1439 elog(ERROR, "_copyAConst: unknown node type %d", from->val.type);
1443 COPY_NODE_FIELD(typename);
1449 _copyFuncCall(FuncCall *from)
1451 FuncCall *newnode = makeNode(FuncCall);
1453 COPY_NODE_FIELD(funcname);
1454 COPY_NODE_FIELD(args);
1455 COPY_SCALAR_FIELD(agg_star);
1456 COPY_SCALAR_FIELD(agg_distinct);
1462 _copyAIndices(A_Indices *from)
1464 A_Indices *newnode = makeNode(A_Indices);
1466 COPY_NODE_FIELD(lidx);
1467 COPY_NODE_FIELD(uidx);
1472 static ExprFieldSelect *
1473 _copyExprFieldSelect(ExprFieldSelect *from)
1475 ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
1477 COPY_NODE_FIELD(arg);
1478 COPY_NODE_FIELD(fields);
1479 COPY_NODE_FIELD(indirection);
1485 _copyResTarget(ResTarget *from)
1487 ResTarget *newnode = makeNode(ResTarget);
1489 COPY_STRING_FIELD(name);
1490 COPY_NODE_FIELD(indirection);
1491 COPY_NODE_FIELD(val);
1497 _copyTypeName(TypeName *from)
1499 TypeName *newnode = makeNode(TypeName);
1501 COPY_NODE_FIELD(names);
1502 COPY_SCALAR_FIELD(typeid);
1503 COPY_SCALAR_FIELD(timezone);
1504 COPY_SCALAR_FIELD(setof);
1505 COPY_SCALAR_FIELD(pct_type);
1506 COPY_SCALAR_FIELD(typmod);
1507 COPY_NODE_FIELD(arrayBounds);
1512 static SortGroupBy *
1513 _copySortGroupBy(SortGroupBy *from)
1515 SortGroupBy *newnode = makeNode(SortGroupBy);
1517 COPY_NODE_FIELD(useOp);
1518 COPY_NODE_FIELD(node);
1523 static RangeSubselect *
1524 _copyRangeSubselect(RangeSubselect *from)
1526 RangeSubselect *newnode = makeNode(RangeSubselect);
1528 COPY_NODE_FIELD(subquery);
1529 COPY_NODE_FIELD(alias);
1534 static RangeFunction *
1535 _copyRangeFunction(RangeFunction *from)
1537 RangeFunction *newnode = makeNode(RangeFunction);
1539 COPY_NODE_FIELD(funccallnode);
1540 COPY_NODE_FIELD(alias);
1541 COPY_NODE_FIELD(coldeflist);
1547 _copyTypeCast(TypeCast *from)
1549 TypeCast *newnode = makeNode(TypeCast);
1551 COPY_NODE_FIELD(arg);
1552 COPY_NODE_FIELD(typename);
1558 _copyIndexElem(IndexElem *from)
1560 IndexElem *newnode = makeNode(IndexElem);
1562 COPY_STRING_FIELD(name);
1563 COPY_NODE_FIELD(funcname);
1564 COPY_NODE_FIELD(args);
1565 COPY_NODE_FIELD(opclass);
1571 _copyColumnDef(ColumnDef *from)
1573 ColumnDef *newnode = makeNode(ColumnDef);
1575 COPY_STRING_FIELD(colname);
1576 COPY_NODE_FIELD(typename);
1577 COPY_SCALAR_FIELD(inhcount);
1578 COPY_SCALAR_FIELD(is_local);
1579 COPY_SCALAR_FIELD(is_not_null);
1580 COPY_NODE_FIELD(raw_default);
1581 COPY_STRING_FIELD(cooked_default);
1582 COPY_NODE_FIELD(constraints);
1583 COPY_NODE_FIELD(support);
1589 _copyConstraint(Constraint *from)
1591 Constraint *newnode = makeNode(Constraint);
1593 COPY_SCALAR_FIELD(contype);
1594 COPY_STRING_FIELD(name);
1595 COPY_NODE_FIELD(raw_expr);
1596 COPY_STRING_FIELD(cooked_expr);
1597 COPY_NODE_FIELD(keys);
1603 _copyCaseExpr(CaseExpr *from)
1605 CaseExpr *newnode = makeNode(CaseExpr);
1607 COPY_SCALAR_FIELD(casetype);
1608 COPY_NODE_FIELD(arg);
1609 COPY_NODE_FIELD(args);
1610 COPY_NODE_FIELD(defresult);
1616 _copyCaseWhen(CaseWhen *from)
1618 CaseWhen *newnode = makeNode(CaseWhen);
1620 COPY_NODE_FIELD(expr);
1621 COPY_NODE_FIELD(result);
1627 _copyNullTest(NullTest *from)
1629 NullTest *newnode = makeNode(NullTest);
1631 COPY_NODE_FIELD(arg);
1632 COPY_SCALAR_FIELD(nulltesttype);
1637 static BooleanTest *
1638 _copyBooleanTest(BooleanTest *from)
1640 BooleanTest *newnode = makeNode(BooleanTest);
1642 COPY_NODE_FIELD(arg);
1643 COPY_SCALAR_FIELD(booltesttype);
1648 static ConstraintTest *
1649 _copyConstraintTest(ConstraintTest *from)
1651 ConstraintTest *newnode = makeNode(ConstraintTest);
1653 COPY_NODE_FIELD(arg);
1654 COPY_SCALAR_FIELD(testtype);
1655 COPY_STRING_FIELD(name);
1656 COPY_STRING_FIELD(domname);
1657 COPY_NODE_FIELD(check_expr);
1662 static DomainConstraintValue *
1663 _copyDomainConstraintValue(DomainConstraintValue *from)
1665 DomainConstraintValue *newnode = makeNode(DomainConstraintValue);
1670 static ConstraintTestValue *
1671 _copyConstraintTestValue(ConstraintTestValue *from)
1673 ConstraintTestValue *newnode = makeNode(ConstraintTestValue);
1675 COPY_SCALAR_FIELD(typeId);
1676 COPY_SCALAR_FIELD(typeMod);
1682 _copyDefElem(DefElem *from)
1684 DefElem *newnode = makeNode(DefElem);
1686 COPY_STRING_FIELD(defname);
1687 COPY_NODE_FIELD(arg);
1693 _copyQuery(Query *from)
1695 Query *newnode = makeNode(Query);
1697 COPY_SCALAR_FIELD(commandType);
1698 COPY_SCALAR_FIELD(querySource);
1699 COPY_NODE_FIELD(utilityStmt);
1700 COPY_SCALAR_FIELD(resultRelation);
1701 COPY_NODE_FIELD(into);
1702 COPY_SCALAR_FIELD(isPortal);
1703 COPY_SCALAR_FIELD(isBinary);
1704 COPY_SCALAR_FIELD(hasAggs);
1705 COPY_SCALAR_FIELD(hasSubLinks);
1706 COPY_NODE_FIELD(rtable);
1707 COPY_NODE_FIELD(jointree);
1708 COPY_INTLIST_FIELD(rowMarks);
1709 COPY_NODE_FIELD(targetList);
1710 COPY_NODE_FIELD(groupClause);
1711 COPY_NODE_FIELD(havingQual);
1712 COPY_NODE_FIELD(distinctClause);
1713 COPY_NODE_FIELD(sortClause);
1714 COPY_NODE_FIELD(limitOffset);
1715 COPY_NODE_FIELD(limitCount);
1716 COPY_NODE_FIELD(setOperations);
1717 COPY_INTLIST_FIELD(resultRelations);
1720 * We do not copy the planner internal fields: base_rel_list,
1721 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys,
1722 * hasJoinRTEs. Not entirely clear if this is right?
1729 _copyInsertStmt(InsertStmt *from)
1731 InsertStmt *newnode = makeNode(InsertStmt);
1733 COPY_NODE_FIELD(relation);
1734 COPY_NODE_FIELD(cols);
1735 COPY_NODE_FIELD(targetList);
1736 COPY_NODE_FIELD(selectStmt);
1742 _copyDeleteStmt(DeleteStmt *from)
1744 DeleteStmt *newnode = makeNode(DeleteStmt);
1746 COPY_NODE_FIELD(relation);
1747 COPY_NODE_FIELD(whereClause);
1753 _copyUpdateStmt(UpdateStmt *from)
1755 UpdateStmt *newnode = makeNode(UpdateStmt);
1757 COPY_NODE_FIELD(relation);
1758 COPY_NODE_FIELD(targetList);
1759 COPY_NODE_FIELD(whereClause);
1760 COPY_NODE_FIELD(fromClause);
1766 _copySelectStmt(SelectStmt *from)
1768 SelectStmt *newnode = makeNode(SelectStmt);
1770 COPY_NODE_FIELD(distinctClause);
1771 COPY_NODE_FIELD(into);
1772 COPY_NODE_FIELD(intoColNames);
1773 COPY_NODE_FIELD(targetList);
1774 COPY_NODE_FIELD(fromClause);
1775 COPY_NODE_FIELD(whereClause);
1776 COPY_NODE_FIELD(groupClause);
1777 COPY_NODE_FIELD(havingClause);
1778 COPY_NODE_FIELD(sortClause);
1779 COPY_STRING_FIELD(portalname);
1780 COPY_SCALAR_FIELD(binary);
1781 COPY_NODE_FIELD(limitOffset);
1782 COPY_NODE_FIELD(limitCount);
1783 COPY_NODE_FIELD(forUpdate);
1784 COPY_SCALAR_FIELD(op);
1785 COPY_SCALAR_FIELD(all);
1786 COPY_NODE_FIELD(larg);
1787 COPY_NODE_FIELD(rarg);
1792 static SetOperationStmt *
1793 _copySetOperationStmt(SetOperationStmt *from)
1795 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1797 COPY_SCALAR_FIELD(op);
1798 COPY_SCALAR_FIELD(all);
1799 COPY_NODE_FIELD(larg);
1800 COPY_NODE_FIELD(rarg);
1801 COPY_INTLIST_FIELD(colTypes);
1806 static AlterTableStmt *
1807 _copyAlterTableStmt(AlterTableStmt *from)
1809 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1811 COPY_SCALAR_FIELD(subtype);
1812 COPY_NODE_FIELD(relation);
1813 COPY_STRING_FIELD(name);
1814 COPY_NODE_FIELD(def);
1815 COPY_SCALAR_FIELD(behavior);
1821 _copyGrantStmt(GrantStmt *from)
1823 GrantStmt *newnode = makeNode(GrantStmt);
1825 COPY_SCALAR_FIELD(is_grant);
1826 COPY_SCALAR_FIELD(objtype);
1827 COPY_NODE_FIELD(objects);
1828 COPY_INTLIST_FIELD(privileges);
1829 COPY_NODE_FIELD(grantees);
1834 static PrivGrantee *
1835 _copyPrivGrantee(PrivGrantee *from)
1837 PrivGrantee *newnode = makeNode(PrivGrantee);
1839 COPY_STRING_FIELD(username);
1840 COPY_STRING_FIELD(groupname);
1845 static FuncWithArgs *
1846 _copyFuncWithArgs(FuncWithArgs *from)
1848 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1850 COPY_NODE_FIELD(funcname);
1851 COPY_NODE_FIELD(funcargs);
1856 static InsertDefault *
1857 _copyInsertDefault(InsertDefault *from)
1859 InsertDefault *newnode = makeNode(InsertDefault);
1865 static ClosePortalStmt *
1866 _copyClosePortalStmt(ClosePortalStmt *from)
1868 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1870 COPY_STRING_FIELD(portalname);
1875 static ClusterStmt *
1876 _copyClusterStmt(ClusterStmt *from)
1878 ClusterStmt *newnode = makeNode(ClusterStmt);
1880 COPY_NODE_FIELD(relation);
1881 COPY_STRING_FIELD(indexname);
1887 _copyCopyStmt(CopyStmt *from)
1889 CopyStmt *newnode = makeNode(CopyStmt);
1891 COPY_NODE_FIELD(relation);
1892 COPY_NODE_FIELD(attlist);
1893 COPY_SCALAR_FIELD(is_from);
1894 COPY_STRING_FIELD(filename);
1895 COPY_NODE_FIELD(options);
1901 _copyCreateStmt(CreateStmt *from)
1903 CreateStmt *newnode = makeNode(CreateStmt);
1905 COPY_NODE_FIELD(relation);
1906 COPY_NODE_FIELD(tableElts);
1907 COPY_NODE_FIELD(inhRelations);
1908 COPY_NODE_FIELD(constraints);
1909 COPY_SCALAR_FIELD(hasoids);
1910 COPY_SCALAR_FIELD(oncommit);
1916 _copyDefineStmt(DefineStmt *from)
1918 DefineStmt *newnode = makeNode(DefineStmt);
1920 COPY_SCALAR_FIELD(defType);
1921 COPY_NODE_FIELD(defnames);
1922 COPY_NODE_FIELD(definition);
1928 _copyDropStmt(DropStmt *from)
1930 DropStmt *newnode = makeNode(DropStmt);
1932 COPY_NODE_FIELD(objects);
1933 COPY_SCALAR_FIELD(removeType);
1934 COPY_SCALAR_FIELD(behavior);
1939 static TruncateStmt *
1940 _copyTruncateStmt(TruncateStmt *from)
1942 TruncateStmt *newnode = makeNode(TruncateStmt);
1944 COPY_NODE_FIELD(relation);
1949 static CommentStmt *
1950 _copyCommentStmt(CommentStmt *from)
1952 CommentStmt *newnode = makeNode(CommentStmt);
1954 COPY_SCALAR_FIELD(objtype);
1955 COPY_NODE_FIELD(objname);
1956 COPY_NODE_FIELD(objargs);
1957 COPY_STRING_FIELD(comment);
1963 _copyFetchStmt(FetchStmt *from)
1965 FetchStmt *newnode = makeNode(FetchStmt);
1967 COPY_SCALAR_FIELD(direction);
1968 COPY_SCALAR_FIELD(howMany);
1969 COPY_STRING_FIELD(portalname);
1970 COPY_SCALAR_FIELD(ismove);
1976 _copyIndexStmt(IndexStmt *from)
1978 IndexStmt *newnode = makeNode(IndexStmt);
1980 COPY_STRING_FIELD(idxname);
1981 COPY_NODE_FIELD(relation);
1982 COPY_STRING_FIELD(accessMethod);
1983 COPY_NODE_FIELD(indexParams);
1984 COPY_NODE_FIELD(whereClause);
1985 COPY_NODE_FIELD(rangetable);
1986 COPY_SCALAR_FIELD(unique);
1987 COPY_SCALAR_FIELD(primary);
1988 COPY_SCALAR_FIELD(isconstraint);
1993 static CreateFunctionStmt *
1994 _copyCreateFunctionStmt(CreateFunctionStmt *from)
1996 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
1998 COPY_SCALAR_FIELD(replace);
1999 COPY_NODE_FIELD(funcname);
2000 COPY_NODE_FIELD(argTypes);
2001 COPY_NODE_FIELD(returnType);
2002 COPY_NODE_FIELD(options);
2003 COPY_NODE_FIELD(withClause);
2008 static RemoveAggrStmt *
2009 _copyRemoveAggrStmt(RemoveAggrStmt *from)
2011 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
2013 COPY_NODE_FIELD(aggname);
2014 COPY_NODE_FIELD(aggtype);
2015 COPY_SCALAR_FIELD(behavior);
2020 static RemoveFuncStmt *
2021 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2023 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2025 COPY_NODE_FIELD(funcname);
2026 COPY_NODE_FIELD(args);
2027 COPY_SCALAR_FIELD(behavior);
2032 static RemoveOperStmt *
2033 _copyRemoveOperStmt(RemoveOperStmt *from)
2035 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2037 COPY_NODE_FIELD(opname);
2038 COPY_NODE_FIELD(args);
2039 COPY_SCALAR_FIELD(behavior);
2044 static RemoveOpClassStmt *
2045 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
2047 RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
2049 COPY_NODE_FIELD(opclassname);
2050 COPY_STRING_FIELD(amname);
2051 COPY_SCALAR_FIELD(behavior);
2057 _copyRenameStmt(RenameStmt *from)
2059 RenameStmt *newnode = makeNode(RenameStmt);
2061 COPY_NODE_FIELD(relation);
2062 COPY_STRING_FIELD(oldname);
2063 COPY_STRING_FIELD(newname);
2064 COPY_SCALAR_FIELD(renameType);
2070 _copyRuleStmt(RuleStmt *from)
2072 RuleStmt *newnode = makeNode(RuleStmt);
2074 COPY_NODE_FIELD(relation);
2075 COPY_STRING_FIELD(rulename);
2076 COPY_NODE_FIELD(whereClause);
2077 COPY_SCALAR_FIELD(event);
2078 COPY_SCALAR_FIELD(instead);
2079 COPY_NODE_FIELD(actions);
2080 COPY_SCALAR_FIELD(replace);
2086 _copyNotifyStmt(NotifyStmt *from)
2088 NotifyStmt *newnode = makeNode(NotifyStmt);
2090 COPY_NODE_FIELD(relation);
2096 _copyListenStmt(ListenStmt *from)
2098 ListenStmt *newnode = makeNode(ListenStmt);
2100 COPY_NODE_FIELD(relation);
2105 static UnlistenStmt *
2106 _copyUnlistenStmt(UnlistenStmt *from)
2108 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2110 COPY_NODE_FIELD(relation);
2115 static TransactionStmt *
2116 _copyTransactionStmt(TransactionStmt *from)
2118 TransactionStmt *newnode = makeNode(TransactionStmt);
2120 COPY_SCALAR_FIELD(command);
2121 COPY_NODE_FIELD(options);
2126 static CompositeTypeStmt *
2127 _copyCompositeTypeStmt(CompositeTypeStmt *from)
2129 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
2131 COPY_NODE_FIELD(typevar);
2132 COPY_NODE_FIELD(coldeflist);
2138 _copyViewStmt(ViewStmt *from)
2140 ViewStmt *newnode = makeNode(ViewStmt);
2142 COPY_NODE_FIELD(view);
2143 COPY_NODE_FIELD(aliases);
2144 COPY_NODE_FIELD(query);
2145 COPY_SCALAR_FIELD(replace);
2151 _copyLoadStmt(LoadStmt *from)
2153 LoadStmt *newnode = makeNode(LoadStmt);
2155 COPY_STRING_FIELD(filename);
2160 static CreateDomainStmt *
2161 _copyCreateDomainStmt(CreateDomainStmt *from)
2163 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2165 COPY_NODE_FIELD(domainname);
2166 COPY_NODE_FIELD(typename);
2167 COPY_NODE_FIELD(constraints);
2172 static CreateOpClassStmt *
2173 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2175 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2177 COPY_NODE_FIELD(opclassname);
2178 COPY_STRING_FIELD(amname);
2179 COPY_NODE_FIELD(datatype);
2180 COPY_NODE_FIELD(items);
2181 COPY_SCALAR_FIELD(isDefault);
2186 static CreateOpClassItem *
2187 _copyCreateOpClassItem(CreateOpClassItem *from)
2189 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2191 COPY_SCALAR_FIELD(itemtype);
2192 COPY_NODE_FIELD(name);
2193 COPY_NODE_FIELD(args);
2194 COPY_SCALAR_FIELD(number);
2195 COPY_SCALAR_FIELD(recheck);
2196 COPY_NODE_FIELD(storedtype);
2201 static CreatedbStmt *
2202 _copyCreatedbStmt(CreatedbStmt *from)
2204 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2206 COPY_STRING_FIELD(dbname);
2207 COPY_NODE_FIELD(options);
2212 static AlterDatabaseSetStmt *
2213 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2215 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2217 COPY_STRING_FIELD(dbname);
2218 COPY_STRING_FIELD(variable);
2219 COPY_NODE_FIELD(value);
2225 _copyDropdbStmt(DropdbStmt *from)
2227 DropdbStmt *newnode = makeNode(DropdbStmt);
2229 COPY_STRING_FIELD(dbname);
2235 _copyVacuumStmt(VacuumStmt *from)
2237 VacuumStmt *newnode = makeNode(VacuumStmt);
2239 COPY_SCALAR_FIELD(vacuum);
2240 COPY_SCALAR_FIELD(full);
2241 COPY_SCALAR_FIELD(analyze);
2242 COPY_SCALAR_FIELD(freeze);
2243 COPY_SCALAR_FIELD(verbose);
2244 COPY_NODE_FIELD(relation);
2245 COPY_NODE_FIELD(va_cols);
2250 static ExplainStmt *
2251 _copyExplainStmt(ExplainStmt *from)
2253 ExplainStmt *newnode = makeNode(ExplainStmt);
2255 COPY_NODE_FIELD(query);
2256 COPY_SCALAR_FIELD(verbose);
2257 COPY_SCALAR_FIELD(analyze);
2262 static CreateSeqStmt *
2263 _copyCreateSeqStmt(CreateSeqStmt *from)
2265 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2267 COPY_NODE_FIELD(sequence);
2268 COPY_NODE_FIELD(options);
2273 static VariableSetStmt *
2274 _copyVariableSetStmt(VariableSetStmt *from)
2276 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2278 COPY_STRING_FIELD(name);
2279 COPY_NODE_FIELD(args);
2280 COPY_SCALAR_FIELD(is_local);
2285 static VariableShowStmt *
2286 _copyVariableShowStmt(VariableShowStmt *from)
2288 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2290 COPY_STRING_FIELD(name);
2295 static VariableResetStmt *
2296 _copyVariableResetStmt(VariableResetStmt *from)
2298 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2300 COPY_STRING_FIELD(name);
2305 static CreateTrigStmt *
2306 _copyCreateTrigStmt(CreateTrigStmt *from)
2308 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2310 COPY_STRING_FIELD(trigname);
2311 COPY_NODE_FIELD(relation);
2312 COPY_NODE_FIELD(funcname);
2313 COPY_NODE_FIELD(args);
2314 COPY_SCALAR_FIELD(before);
2315 COPY_SCALAR_FIELD(row);
2316 strcpy(newnode->actions, from->actions); /* in-line string field */
2317 COPY_SCALAR_FIELD(isconstraint);
2318 COPY_SCALAR_FIELD(deferrable);
2319 COPY_SCALAR_FIELD(initdeferred);
2320 COPY_NODE_FIELD(constrrel);
2325 static DropPropertyStmt *
2326 _copyDropPropertyStmt(DropPropertyStmt *from)
2328 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2330 COPY_NODE_FIELD(relation);
2331 COPY_STRING_FIELD(property);
2332 COPY_SCALAR_FIELD(removeType);
2333 COPY_SCALAR_FIELD(behavior);
2338 static CreatePLangStmt *
2339 _copyCreatePLangStmt(CreatePLangStmt *from)
2341 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2343 COPY_STRING_FIELD(plname);
2344 COPY_NODE_FIELD(plhandler);
2345 COPY_NODE_FIELD(plvalidator);
2346 COPY_SCALAR_FIELD(pltrusted);
2351 static DropPLangStmt *
2352 _copyDropPLangStmt(DropPLangStmt *from)
2354 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2356 COPY_STRING_FIELD(plname);
2357 COPY_SCALAR_FIELD(behavior);
2362 static CreateUserStmt *
2363 _copyCreateUserStmt(CreateUserStmt *from)
2365 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2367 COPY_STRING_FIELD(user);
2368 COPY_NODE_FIELD(options);
2373 static AlterUserStmt *
2374 _copyAlterUserStmt(AlterUserStmt *from)
2376 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2378 COPY_STRING_FIELD(user);
2379 COPY_NODE_FIELD(options);
2384 static AlterUserSetStmt *
2385 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2387 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2389 COPY_STRING_FIELD(user);
2390 COPY_STRING_FIELD(variable);
2391 COPY_NODE_FIELD(value);
2396 static DropUserStmt *
2397 _copyDropUserStmt(DropUserStmt *from)
2399 DropUserStmt *newnode = makeNode(DropUserStmt);
2401 COPY_NODE_FIELD(users);
2407 _copyLockStmt(LockStmt *from)
2409 LockStmt *newnode = makeNode(LockStmt);
2411 COPY_NODE_FIELD(relations);
2412 COPY_SCALAR_FIELD(mode);
2417 static ConstraintsSetStmt *
2418 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2420 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2422 COPY_NODE_FIELD(constraints);
2423 COPY_SCALAR_FIELD(deferred);
2428 static CreateGroupStmt *
2429 _copyCreateGroupStmt(CreateGroupStmt *from)
2431 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2433 COPY_STRING_FIELD(name);
2434 COPY_NODE_FIELD(options);
2439 static AlterGroupStmt *
2440 _copyAlterGroupStmt(AlterGroupStmt *from)
2442 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2444 COPY_STRING_FIELD(name);
2445 COPY_SCALAR_FIELD(action);
2446 COPY_NODE_FIELD(listUsers);
2451 static DropGroupStmt *
2452 _copyDropGroupStmt(DropGroupStmt *from)
2454 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2456 COPY_STRING_FIELD(name);
2461 static ReindexStmt *
2462 _copyReindexStmt(ReindexStmt *from)
2464 ReindexStmt *newnode = makeNode(ReindexStmt);
2466 COPY_SCALAR_FIELD(reindexType);
2467 COPY_NODE_FIELD(relation);
2468 COPY_STRING_FIELD(name);
2469 COPY_SCALAR_FIELD(force);
2470 COPY_SCALAR_FIELD(all);
2475 static CreateSchemaStmt *
2476 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2478 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2480 COPY_STRING_FIELD(schemaname);
2481 COPY_STRING_FIELD(authid);
2482 COPY_NODE_FIELD(schemaElts);
2487 static CreateConversionStmt *
2488 _copyCreateConversionStmt(CreateConversionStmt *from)
2490 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2492 COPY_NODE_FIELD(conversion_name);
2493 COPY_STRING_FIELD(for_encoding_name);
2494 COPY_STRING_FIELD(to_encoding_name);
2495 COPY_NODE_FIELD(func_name);
2496 COPY_SCALAR_FIELD(def);
2501 static CreateCastStmt *
2502 _copyCreateCastStmt(CreateCastStmt *from)
2504 CreateCastStmt *newnode = makeNode(CreateCastStmt);
2506 COPY_NODE_FIELD(sourcetype);
2507 COPY_NODE_FIELD(targettype);
2508 COPY_NODE_FIELD(func);
2509 COPY_SCALAR_FIELD(context);
2514 static DropCastStmt *
2515 _copyDropCastStmt(DropCastStmt *from)
2517 DropCastStmt *newnode = makeNode(DropCastStmt);
2519 COPY_NODE_FIELD(sourcetype);
2520 COPY_NODE_FIELD(targettype);
2521 COPY_SCALAR_FIELD(behavior);
2526 static PrepareStmt *
2527 _copyPrepareStmt(PrepareStmt *from)
2529 PrepareStmt *newnode = makeNode(PrepareStmt);
2531 COPY_STRING_FIELD(name);
2532 COPY_NODE_FIELD(argtypes);
2533 COPY_INTLIST_FIELD(argtype_oids);
2534 COPY_NODE_FIELD(query);
2539 static ExecuteStmt *
2540 _copyExecuteStmt(ExecuteStmt *from)
2542 ExecuteStmt *newnode = makeNode(ExecuteStmt);
2544 COPY_STRING_FIELD(name);
2545 COPY_NODE_FIELD(into);
2546 COPY_NODE_FIELD(params);
2551 static DeallocateStmt *
2552 _copyDeallocateStmt(DeallocateStmt *from)
2554 DeallocateStmt *newnode = makeNode(DeallocateStmt);
2556 COPY_STRING_FIELD(name);
2562 /* ****************************************************************
2563 * pg_list.h copy functions
2564 * ****************************************************************
2568 _copyValue(Value *from)
2570 Value *newnode = makeNode(Value);
2572 /* See also _copyAConst when changing this code! */
2574 COPY_SCALAR_FIELD(type);
2578 COPY_SCALAR_FIELD(val.ival);
2583 COPY_STRING_FIELD(val.str);
2589 elog(ERROR, "_copyValue: unknown node type %d", from->type);
2598 * Create a copy of a Node tree or list. This is a "deep" copy: all
2599 * substructure is copied too, recursively.
2602 copyObject(void *from)
2609 switch (nodeTag(from))
2615 retval = _copyPlan(from);
2618 retval = _copyResult(from);
2621 retval = _copyAppend(from);
2624 retval = _copyScan(from);
2627 retval = _copySeqScan(from);
2630 retval = _copyIndexScan(from);
2633 retval = _copyTidScan(from);
2635 case T_SubqueryScan:
2636 retval = _copySubqueryScan(from);
2638 case T_FunctionScan:
2639 retval = _copyFunctionScan(from);
2642 retval = _copyJoin(from);
2645 retval = _copyNestLoop(from);
2648 retval = _copyMergeJoin(from);
2651 retval = _copyHashJoin(from);
2654 retval = _copyMaterial(from);
2657 retval = _copySort(from);
2660 retval = _copyGroup(from);
2663 retval = _copyAgg(from);
2666 retval = _copyUnique(from);
2669 retval = _copySetOp(from);
2672 retval = _copyLimit(from);
2675 retval = _copyHash(from);
2678 retval = _copySubPlan(from);
2685 retval = _copyResdom(from);
2688 retval = _copyFjoin(from);
2691 retval = _copyAlias(from);
2694 retval = _copyRangeVar(from);
2697 retval = _copyExpr(from);
2700 retval = _copyVar(from);
2703 retval = _copyOper(from);
2706 retval = _copyConst(from);
2709 retval = _copyParam(from);
2712 retval = _copyFunc(from);
2715 retval = _copyAggref(from);
2718 retval = _copySubLink(from);
2721 retval = _copyFieldSelect(from);
2724 retval = _copyRelabelType(from);
2727 retval = _copyRangeTblRef(from);
2730 retval = _copyJoinExpr(from);
2733 retval = _copyFromExpr(from);
2736 retval = _copyArrayRef(from);
2743 retval = _copyRelOptInfo(from);
2746 retval = _copyPath(from);
2749 retval = _copyIndexPath(from);
2752 retval = _copyTidPath(from);
2755 retval = _copyAppendPath(from);
2758 retval = _copyResultPath(from);
2761 retval = _copyNestPath(from);
2764 retval = _copyMergePath(from);
2767 retval = _copyHashPath(from);
2770 retval = _copyPathKeyItem(from);
2772 case T_RestrictInfo:
2773 retval = _copyRestrictInfo(from);
2776 retval = _copyJoinInfo(from);
2778 case T_IndexOptInfo:
2779 retval = _copyIndexOptInfo(from);
2781 case T_InnerIndexscanInfo:
2782 retval = _copyInnerIndexscanInfo(from);
2793 retval = _copyValue(from);
2801 /* rather ugly coding for speed... */
2802 /* Note the input list cannot be NIL if we got here. */
2803 nl = makeList1(copyObject(lfirst(list)));
2806 foreach(l, lnext(list))
2808 lnext(nl) = makeList1(copyObject(lfirst(l)));
2818 retval = _copyQuery(from);
2821 retval = _copyInsertStmt(from);
2824 retval = _copyDeleteStmt(from);
2827 retval = _copyUpdateStmt(from);
2830 retval = _copySelectStmt(from);
2832 case T_SetOperationStmt:
2833 retval = _copySetOperationStmt(from);
2835 case T_AlterTableStmt:
2836 retval = _copyAlterTableStmt(from);
2839 retval = _copyGrantStmt(from);
2841 case T_ClosePortalStmt:
2842 retval = _copyClosePortalStmt(from);
2845 retval = _copyClusterStmt(from);
2848 retval = _copyCopyStmt(from);
2851 retval = _copyCreateStmt(from);
2854 retval = _copyDefineStmt(from);
2857 retval = _copyDropStmt(from);
2859 case T_TruncateStmt:
2860 retval = _copyTruncateStmt(from);
2863 retval = _copyCommentStmt(from);
2866 retval = _copyFetchStmt(from);
2869 retval = _copyIndexStmt(from);
2871 case T_CreateFunctionStmt:
2872 retval = _copyCreateFunctionStmt(from);
2874 case T_RemoveAggrStmt:
2875 retval = _copyRemoveAggrStmt(from);
2877 case T_RemoveFuncStmt:
2878 retval = _copyRemoveFuncStmt(from);
2880 case T_RemoveOperStmt:
2881 retval = _copyRemoveOperStmt(from);
2883 case T_RemoveOpClassStmt:
2884 retval = _copyRemoveOpClassStmt(from);
2887 retval = _copyRenameStmt(from);
2890 retval = _copyRuleStmt(from);
2893 retval = _copyNotifyStmt(from);
2896 retval = _copyListenStmt(from);
2898 case T_UnlistenStmt:
2899 retval = _copyUnlistenStmt(from);
2901 case T_TransactionStmt:
2902 retval = _copyTransactionStmt(from);
2904 case T_CompositeTypeStmt:
2905 retval = _copyCompositeTypeStmt(from);
2908 retval = _copyViewStmt(from);
2911 retval = _copyLoadStmt(from);
2913 case T_CreateDomainStmt:
2914 retval = _copyCreateDomainStmt(from);
2916 case T_CreateOpClassStmt:
2917 retval = _copyCreateOpClassStmt(from);
2919 case T_CreateOpClassItem:
2920 retval = _copyCreateOpClassItem(from);
2922 case T_CreatedbStmt:
2923 retval = _copyCreatedbStmt(from);
2925 case T_AlterDatabaseSetStmt:
2926 retval = _copyAlterDatabaseSetStmt(from);
2929 retval = _copyDropdbStmt(from);
2932 retval = _copyVacuumStmt(from);
2935 retval = _copyExplainStmt(from);
2937 case T_CreateSeqStmt:
2938 retval = _copyCreateSeqStmt(from);
2940 case T_VariableSetStmt:
2941 retval = _copyVariableSetStmt(from);
2943 case T_VariableShowStmt:
2944 retval = _copyVariableShowStmt(from);
2946 case T_VariableResetStmt:
2947 retval = _copyVariableResetStmt(from);
2949 case T_CreateTrigStmt:
2950 retval = _copyCreateTrigStmt(from);
2952 case T_DropPropertyStmt:
2953 retval = _copyDropPropertyStmt(from);
2955 case T_CreatePLangStmt:
2956 retval = _copyCreatePLangStmt(from);
2958 case T_DropPLangStmt:
2959 retval = _copyDropPLangStmt(from);
2961 case T_CreateUserStmt:
2962 retval = _copyCreateUserStmt(from);
2964 case T_AlterUserStmt:
2965 retval = _copyAlterUserStmt(from);
2967 case T_AlterUserSetStmt:
2968 retval = _copyAlterUserSetStmt(from);
2970 case T_DropUserStmt:
2971 retval = _copyDropUserStmt(from);
2974 retval = _copyLockStmt(from);
2976 case T_ConstraintsSetStmt:
2977 retval = _copyConstraintsSetStmt(from);
2979 case T_CreateGroupStmt:
2980 retval = _copyCreateGroupStmt(from);
2982 case T_AlterGroupStmt:
2983 retval = _copyAlterGroupStmt(from);
2985 case T_DropGroupStmt:
2986 retval = _copyDropGroupStmt(from);
2989 retval = _copyReindexStmt(from);
2991 case T_CheckPointStmt:
2992 retval = (void *) makeNode(CheckPointStmt);
2994 case T_CreateSchemaStmt:
2995 retval = _copyCreateSchemaStmt(from);
2997 case T_CreateConversionStmt:
2998 retval = _copyCreateConversionStmt(from);
3000 case T_CreateCastStmt:
3001 retval = _copyCreateCastStmt(from);
3003 case T_DropCastStmt:
3004 retval = _copyDropCastStmt(from);
3007 retval = _copyPrepareStmt(from);
3010 retval = _copyExecuteStmt(from);
3012 case T_DeallocateStmt:
3013 retval = _copyDeallocateStmt(from);
3017 retval = _copyAExpr(from);
3020 retval = _copyColumnRef(from);
3023 retval = _copyParamRef(from);
3026 retval = _copyAConst(from);
3029 retval = _copyFuncCall(from);
3032 retval = _copyAIndices(from);
3034 case T_ExprFieldSelect:
3035 retval = _copyExprFieldSelect(from);
3038 retval = _copyResTarget(from);
3041 retval = _copyTypeCast(from);
3044 retval = _copySortGroupBy(from);
3046 case T_RangeSubselect:
3047 retval = _copyRangeSubselect(from);
3049 case T_RangeFunction:
3050 retval = _copyRangeFunction(from);
3053 retval = _copyTypeName(from);
3056 retval = _copyIndexElem(from);
3059 retval = _copyColumnDef(from);
3062 retval = _copyConstraint(from);
3065 retval = _copyDefElem(from);
3068 retval = _copyTargetEntry(from);
3070 case T_RangeTblEntry:
3071 retval = _copyRangeTblEntry(from);
3074 retval = _copySortClause(from);
3077 retval = _copyGroupClause(from);
3080 retval = _copyCaseExpr(from);
3083 retval = _copyCaseWhen(from);
3086 retval = _copyNullTest(from);
3089 retval = _copyBooleanTest(from);
3091 case T_ConstraintTest:
3092 retval = _copyConstraintTest(from);
3094 case T_ConstraintTestValue:
3095 retval = _copyConstraintTestValue(from);
3097 case T_FkConstraint:
3098 retval = _copyFkConstraint(from);
3101 retval = _copyPrivGrantee(from);
3103 case T_FuncWithArgs:
3104 retval = _copyFuncWithArgs(from);
3106 case T_InsertDefault:
3107 retval = _copyInsertDefault(from);
3109 case T_DomainConstraintValue:
3110 retval = _copyDomainConstraintValue(from);
3114 elog(ERROR, "copyObject: don't know how to copy node type %d",
3116 retval = from; /* keep compiler quiet */