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.225 2002/11/30 05:21:01 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);
433 /* subPlan list must point to subplans in the new subtree, not the old */
434 FIX_SUBPLAN_LINKS(join.plan.subPlan, hashclauses);
444 _copyMaterial(Material *from)
446 Material *newnode = makeNode(Material);
449 * copy node superclass fields
451 CopyPlanFields((Plan *) from, (Plan *) newnode);
461 _copySort(Sort *from)
463 Sort *newnode = makeNode(Sort);
466 * copy node superclass fields
468 CopyPlanFields((Plan *) from, (Plan *) newnode);
470 COPY_SCALAR_FIELD(keycount);
480 _copyGroup(Group *from)
482 Group *newnode = makeNode(Group);
484 CopyPlanFields((Plan *) from, (Plan *) newnode);
486 COPY_SCALAR_FIELD(numCols);
487 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
498 Agg *newnode = makeNode(Agg);
500 CopyPlanFields((Plan *) from, (Plan *) newnode);
502 COPY_SCALAR_FIELD(aggstrategy);
503 COPY_SCALAR_FIELD(numCols);
504 if (from->numCols > 0)
505 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
506 COPY_SCALAR_FIELD(numGroups);
515 _copyUnique(Unique *from)
517 Unique *newnode = makeNode(Unique);
520 * copy node superclass fields
522 CopyPlanFields((Plan *) from, (Plan *) newnode);
525 * copy remainder of node
527 COPY_SCALAR_FIELD(numCols);
528 COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
537 _copySetOp(SetOp *from)
539 SetOp *newnode = makeNode(SetOp);
542 * copy node superclass fields
544 CopyPlanFields((Plan *) from, (Plan *) newnode);
547 * copy remainder of node
549 COPY_SCALAR_FIELD(cmd);
550 COPY_SCALAR_FIELD(numCols);
551 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
552 COPY_SCALAR_FIELD(flagColIdx);
561 _copyLimit(Limit *from)
563 Limit *newnode = makeNode(Limit);
566 * copy node superclass fields
568 CopyPlanFields((Plan *) from, (Plan *) newnode);
571 * copy remainder of node
573 COPY_NODE_FIELD(limitOffset);
574 COPY_NODE_FIELD(limitCount);
583 _copyHash(Hash *from)
585 Hash *newnode = makeNode(Hash);
588 * copy node superclass fields
590 CopyPlanFields((Plan *) from, (Plan *) newnode);
593 * copy remainder of node
595 COPY_NODE_FIELD(hashkeys);
597 /* XXX could the hashkeys contain subplans? Not at present... */
603 _copySubPlan(SubPlan *from)
605 SubPlan *newnode = makeNode(SubPlan);
607 COPY_NODE_FIELD(plan);
608 COPY_SCALAR_FIELD(plan_id);
609 COPY_NODE_FIELD(rtable);
610 COPY_INTLIST_FIELD(setParam);
611 COPY_INTLIST_FIELD(parParam);
612 COPY_NODE_FIELD(sublink);
614 /* do not copy execution state */
615 newnode->needShutdown = false;
616 newnode->curTuple = NULL;
621 /* ****************************************************************
622 * primnodes.h copy functions
623 * ****************************************************************
630 _copyResdom(Resdom *from)
632 Resdom *newnode = makeNode(Resdom);
634 COPY_SCALAR_FIELD(resno);
635 COPY_SCALAR_FIELD(restype);
636 COPY_SCALAR_FIELD(restypmod);
637 COPY_STRING_FIELD(resname);
638 COPY_SCALAR_FIELD(ressortgroupref);
639 COPY_SCALAR_FIELD(reskey);
640 COPY_SCALAR_FIELD(reskeyop);
641 COPY_SCALAR_FIELD(resjunk);
647 _copyFjoin(Fjoin *from)
649 Fjoin *newnode = makeNode(Fjoin);
651 COPY_SCALAR_FIELD(fj_initialized);
652 COPY_SCALAR_FIELD(fj_nNodes);
653 COPY_NODE_FIELD(fj_innerNode);
654 COPY_POINTER_FIELD(fj_results, from->fj_nNodes * sizeof(Datum));
655 COPY_POINTER_FIELD(fj_alwaysDone, from->fj_nNodes * sizeof(bool));
661 _copyAlias(Alias *from)
663 Alias *newnode = makeNode(Alias);
665 COPY_STRING_FIELD(aliasname);
666 COPY_NODE_FIELD(colnames);
672 _copyRangeVar(RangeVar *from)
674 RangeVar *newnode = makeNode(RangeVar);
676 COPY_STRING_FIELD(catalogname);
677 COPY_STRING_FIELD(schemaname);
678 COPY_STRING_FIELD(relname);
679 COPY_SCALAR_FIELD(inhOpt);
680 COPY_SCALAR_FIELD(istemp);
681 COPY_NODE_FIELD(alias);
690 _copyExpr(Expr *from)
692 Expr *newnode = makeNode(Expr);
694 COPY_SCALAR_FIELD(typeOid);
695 COPY_SCALAR_FIELD(opType);
696 COPY_NODE_FIELD(oper);
697 COPY_NODE_FIELD(args);
708 Var *newnode = makeNode(Var);
710 COPY_SCALAR_FIELD(varno);
711 COPY_SCALAR_FIELD(varattno);
712 COPY_SCALAR_FIELD(vartype);
713 COPY_SCALAR_FIELD(vartypmod);
714 COPY_SCALAR_FIELD(varlevelsup);
715 COPY_SCALAR_FIELD(varnoold);
716 COPY_SCALAR_FIELD(varoattno);
725 _copyOper(Oper *from)
727 Oper *newnode = makeNode(Oper);
729 COPY_SCALAR_FIELD(opno);
730 COPY_SCALAR_FIELD(opid);
731 COPY_SCALAR_FIELD(opresulttype);
732 COPY_SCALAR_FIELD(opretset);
734 /* Do not copy the run-time state, if any */
735 newnode->op_fcache = NULL;
744 _copyConst(Const *from)
746 Const *newnode = makeNode(Const);
748 COPY_SCALAR_FIELD(consttype);
749 COPY_SCALAR_FIELD(constlen);
751 if (from->constbyval || from->constisnull)
754 * passed by value so just copy the datum. Also, don't try to copy
755 * struct when value is null!
757 newnode->constvalue = from->constvalue;
762 * passed by reference. We need a palloc'd copy.
764 newnode->constvalue = datumCopy(from->constvalue,
769 COPY_SCALAR_FIELD(constisnull);
770 COPY_SCALAR_FIELD(constbyval);
779 _copyParam(Param *from)
781 Param *newnode = makeNode(Param);
783 COPY_SCALAR_FIELD(paramkind);
784 COPY_SCALAR_FIELD(paramid);
785 COPY_STRING_FIELD(paramname);
786 COPY_SCALAR_FIELD(paramtype);
795 _copyFunc(Func *from)
797 Func *newnode = makeNode(Func);
799 COPY_SCALAR_FIELD(funcid);
800 COPY_SCALAR_FIELD(funcresulttype);
801 COPY_SCALAR_FIELD(funcretset);
802 COPY_SCALAR_FIELD(funcformat);
804 /* Do not copy the run-time state, if any */
805 newnode->func_fcache = NULL;
814 _copyAggref(Aggref *from)
816 Aggref *newnode = makeNode(Aggref);
818 COPY_SCALAR_FIELD(aggfnoid);
819 COPY_SCALAR_FIELD(aggtype);
820 COPY_NODE_FIELD(target);
821 COPY_SCALAR_FIELD(aggstar);
822 COPY_SCALAR_FIELD(aggdistinct);
823 COPY_SCALAR_FIELD(aggno); /* probably not necessary */
832 _copySubLink(SubLink *from)
834 SubLink *newnode = makeNode(SubLink);
836 COPY_SCALAR_FIELD(subLinkType);
837 COPY_SCALAR_FIELD(useor);
838 COPY_NODE_FIELD(lefthand);
839 COPY_NODE_FIELD(oper);
840 COPY_NODE_FIELD(subselect);
849 _copyFieldSelect(FieldSelect *from)
851 FieldSelect *newnode = makeNode(FieldSelect);
853 COPY_NODE_FIELD(arg);
854 COPY_SCALAR_FIELD(fieldnum);
855 COPY_SCALAR_FIELD(resulttype);
856 COPY_SCALAR_FIELD(resulttypmod);
865 _copyRelabelType(RelabelType *from)
867 RelabelType *newnode = makeNode(RelabelType);
869 COPY_NODE_FIELD(arg);
870 COPY_SCALAR_FIELD(resulttype);
871 COPY_SCALAR_FIELD(resulttypmod);
872 COPY_SCALAR_FIELD(relabelformat);
878 _copyRangeTblRef(RangeTblRef *from)
880 RangeTblRef *newnode = makeNode(RangeTblRef);
882 COPY_SCALAR_FIELD(rtindex);
888 _copyJoinExpr(JoinExpr *from)
890 JoinExpr *newnode = makeNode(JoinExpr);
892 COPY_SCALAR_FIELD(jointype);
893 COPY_SCALAR_FIELD(isNatural);
894 COPY_NODE_FIELD(larg);
895 COPY_NODE_FIELD(rarg);
896 COPY_NODE_FIELD(using);
897 COPY_NODE_FIELD(quals);
898 COPY_NODE_FIELD(alias);
899 COPY_SCALAR_FIELD(rtindex);
905 _copyFromExpr(FromExpr *from)
907 FromExpr *newnode = makeNode(FromExpr);
909 COPY_NODE_FIELD(fromlist);
910 COPY_NODE_FIELD(quals);
916 _copyArrayRef(ArrayRef *from)
918 ArrayRef *newnode = makeNode(ArrayRef);
920 COPY_SCALAR_FIELD(refrestype);
921 COPY_SCALAR_FIELD(refattrlength);
922 COPY_SCALAR_FIELD(refelemlength);
923 COPY_SCALAR_FIELD(refelembyval);
924 COPY_SCALAR_FIELD(refelemalign);
925 COPY_NODE_FIELD(refupperindexpr);
926 COPY_NODE_FIELD(reflowerindexpr);
927 COPY_NODE_FIELD(refexpr);
928 COPY_NODE_FIELD(refassgnexpr);
933 /* ****************************************************************
934 * relation.h copy functions
936 * XXX the code to copy RelOptInfo and Path nodes is really completely bogus,
937 * because it makes no attempt to deal with multiple links from RelOptInfo
938 * to Paths, nor with back-links from Paths to their parent RelOptInfo.
939 * Currently, since we never actually try to copy a RelOptInfo, this is okay.
940 * ****************************************************************
947 _copyRelOptInfo(RelOptInfo *from)
949 RelOptInfo *newnode = makeNode(RelOptInfo);
951 COPY_SCALAR_FIELD(reloptkind);
952 COPY_INTLIST_FIELD(relids);
953 COPY_SCALAR_FIELD(rows);
954 COPY_SCALAR_FIELD(width);
955 COPY_NODE_FIELD(targetlist);
956 COPY_NODE_FIELD(pathlist);
957 /* XXX cheapest-path fields should point to members of pathlist? */
958 COPY_NODE_FIELD(cheapest_startup_path);
959 COPY_NODE_FIELD(cheapest_total_path);
960 COPY_SCALAR_FIELD(pruneable);
961 COPY_SCALAR_FIELD(rtekind);
962 COPY_NODE_FIELD(indexlist);
963 COPY_SCALAR_FIELD(pages);
964 COPY_SCALAR_FIELD(tuples);
965 COPY_NODE_FIELD(subplan);
966 COPY_SCALAR_FIELD(joinrti);
967 COPY_INTLIST_FIELD(joinrteids);
968 COPY_NODE_FIELD(baserestrictinfo);
969 COPY_SCALAR_FIELD(baserestrictcost);
970 COPY_INTLIST_FIELD(outerjoinset);
971 COPY_NODE_FIELD(joininfo);
972 COPY_INTLIST_FIELD(index_outer_relids);
973 COPY_NODE_FIELD(index_inner_paths);
981 static IndexOptInfo *
982 _copyIndexOptInfo(IndexOptInfo *from)
984 IndexOptInfo *newnode = makeNode(IndexOptInfo);
986 COPY_SCALAR_FIELD(indexoid);
987 COPY_SCALAR_FIELD(pages);
988 COPY_SCALAR_FIELD(tuples);
989 COPY_SCALAR_FIELD(ncolumns);
990 COPY_SCALAR_FIELD(nkeys);
994 /* copy the trailing zero too */
995 COPY_POINTER_FIELD(classlist, (from->ncolumns + 1) * sizeof(Oid));
1000 /* copy the trailing zero too */
1001 COPY_POINTER_FIELD(indexkeys, (from->nkeys + 1) * sizeof(int));
1006 /* copy the trailing zero too */
1007 COPY_POINTER_FIELD(ordering, (from->ncolumns + 1) * sizeof(Oid));
1010 COPY_SCALAR_FIELD(relam);
1011 COPY_SCALAR_FIELD(amcostestimate);
1012 COPY_SCALAR_FIELD(indproc);
1013 COPY_NODE_FIELD(indpred);
1014 COPY_SCALAR_FIELD(unique);
1015 COPY_INTLIST_FIELD(outer_relids);
1016 COPY_NODE_FIELD(inner_paths);
1024 * This function copies the fields of the Path node. It is used by
1025 * all the copy functions for classes which inherit from Path.
1028 CopyPathFields(Path *from, Path *newnode)
1031 * Modify the next line, since it causes the copying to cycle (i.e.
1032 * the parent points right back here! -- JMH, 7/7/92. Old version:
1033 * COPY_NODE_FIELD(parent);
1035 COPY_SCALAR_FIELD(parent);
1037 COPY_SCALAR_FIELD(startup_cost);
1038 COPY_SCALAR_FIELD(total_cost);
1039 COPY_SCALAR_FIELD(pathtype);
1040 COPY_NODE_FIELD(pathkeys);
1047 _copyPath(Path *from)
1049 Path *newnode = makeNode(Path);
1051 CopyPathFields(from, newnode);
1060 _copyIndexPath(IndexPath *from)
1062 IndexPath *newnode = makeNode(IndexPath);
1065 * copy node superclass fields
1067 CopyPathFields((Path *) from, (Path *) newnode);
1070 * copy remainder of node
1072 COPY_NODE_FIELD(indexinfo);
1073 COPY_NODE_FIELD(indexqual);
1074 COPY_SCALAR_FIELD(indexscandir);
1075 COPY_SCALAR_FIELD(rows);
1084 _copyTidPath(TidPath *from)
1086 TidPath *newnode = makeNode(TidPath);
1089 * copy node superclass fields
1091 CopyPathFields((Path *) from, (Path *) newnode);
1094 * copy remainder of node
1096 COPY_NODE_FIELD(tideval);
1097 COPY_INTLIST_FIELD(unjoined_relids);
1106 _copyAppendPath(AppendPath *from)
1108 AppendPath *newnode = makeNode(AppendPath);
1111 * copy node superclass fields
1113 CopyPathFields((Path *) from, (Path *) newnode);
1116 * copy remainder of node
1118 COPY_NODE_FIELD(subpaths);
1127 _copyResultPath(ResultPath *from)
1129 ResultPath *newnode = makeNode(ResultPath);
1132 * copy node superclass fields
1134 CopyPathFields((Path *) from, (Path *) newnode);
1137 * copy remainder of node
1139 COPY_NODE_FIELD(subpath);
1140 COPY_NODE_FIELD(constantqual);
1148 static MaterialPath *
1149 _copyMaterialPath(MaterialPath *from)
1151 MaterialPath *newnode = makeNode(MaterialPath);
1154 * copy node superclass fields
1156 CopyPathFields((Path *) from, (Path *) newnode);
1159 * copy remainder of node
1161 COPY_NODE_FIELD(subpath);
1167 * CopyJoinPathFields
1169 * This function copies the fields of the JoinPath node. It is used by
1170 * all the copy functions for classes which inherit from JoinPath.
1173 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1175 CopyPathFields((Path *) from, (Path *) newnode);
1177 COPY_SCALAR_FIELD(jointype);
1178 COPY_NODE_FIELD(outerjoinpath);
1179 COPY_NODE_FIELD(innerjoinpath);
1180 COPY_NODE_FIELD(joinrestrictinfo);
1187 _copyNestPath(NestPath *from)
1189 NestPath *newnode = makeNode(NestPath);
1192 * copy node superclass fields
1194 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1203 _copyMergePath(MergePath *from)
1205 MergePath *newnode = makeNode(MergePath);
1208 * copy node superclass fields
1210 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1213 * copy remainder of node
1215 COPY_NODE_FIELD(path_mergeclauses);
1216 COPY_NODE_FIELD(outersortkeys);
1217 COPY_NODE_FIELD(innersortkeys);
1226 _copyHashPath(HashPath *from)
1228 HashPath *newnode = makeNode(HashPath);
1231 * copy node superclass fields
1233 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1236 * copy remainder of node
1238 COPY_NODE_FIELD(path_hashclauses);
1246 static PathKeyItem *
1247 _copyPathKeyItem(PathKeyItem *from)
1249 PathKeyItem *newnode = makeNode(PathKeyItem);
1251 COPY_NODE_FIELD(key);
1252 COPY_SCALAR_FIELD(sortop);
1260 static RestrictInfo *
1261 _copyRestrictInfo(RestrictInfo *from)
1263 RestrictInfo *newnode = makeNode(RestrictInfo);
1265 COPY_NODE_FIELD(clause);
1266 COPY_SCALAR_FIELD(ispusheddown);
1267 COPY_NODE_FIELD(subclauseindices); /* XXX probably bad */
1268 COPY_SCALAR_FIELD(eval_cost);
1269 COPY_SCALAR_FIELD(this_selec);
1270 COPY_SCALAR_FIELD(mergejoinoperator);
1271 COPY_SCALAR_FIELD(left_sortop);
1272 COPY_SCALAR_FIELD(right_sortop);
1275 * Do not copy pathkeys, since they'd not be canonical in a copied
1278 newnode->left_pathkey = NIL;
1279 newnode->right_pathkey = NIL;
1281 COPY_SCALAR_FIELD(left_mergescansel);
1282 COPY_SCALAR_FIELD(right_mergescansel);
1283 COPY_SCALAR_FIELD(hashjoinoperator);
1284 COPY_SCALAR_FIELD(left_bucketsize);
1285 COPY_SCALAR_FIELD(right_bucketsize);
1294 _copyJoinInfo(JoinInfo *from)
1296 JoinInfo *newnode = makeNode(JoinInfo);
1298 COPY_INTLIST_FIELD(unjoined_relids);
1299 COPY_NODE_FIELD(jinfo_restrictinfo);
1305 * _copyInnerIndexscanInfo
1307 static InnerIndexscanInfo *
1308 _copyInnerIndexscanInfo(InnerIndexscanInfo *from)
1310 InnerIndexscanInfo *newnode = makeNode(InnerIndexscanInfo);
1312 COPY_INTLIST_FIELD(other_relids);
1313 COPY_SCALAR_FIELD(isouterjoin);
1314 COPY_NODE_FIELD(best_innerpath);
1319 /* ****************************************************************
1320 * parsenodes.h copy functions
1321 * ****************************************************************
1324 static TargetEntry *
1325 _copyTargetEntry(TargetEntry *from)
1327 TargetEntry *newnode = makeNode(TargetEntry);
1329 COPY_NODE_FIELD(resdom);
1330 COPY_NODE_FIELD(fjoin);
1331 COPY_NODE_FIELD(expr);
1336 static RangeTblEntry *
1337 _copyRangeTblEntry(RangeTblEntry *from)
1339 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1341 COPY_SCALAR_FIELD(rtekind);
1342 COPY_SCALAR_FIELD(relid);
1343 COPY_NODE_FIELD(subquery);
1344 COPY_NODE_FIELD(funcexpr);
1345 COPY_NODE_FIELD(coldeflist);
1346 COPY_SCALAR_FIELD(jointype);
1347 COPY_NODE_FIELD(joinaliasvars);
1348 COPY_NODE_FIELD(alias);
1349 COPY_NODE_FIELD(eref);
1350 COPY_SCALAR_FIELD(inh);
1351 COPY_SCALAR_FIELD(inFromCl);
1352 COPY_SCALAR_FIELD(checkForRead);
1353 COPY_SCALAR_FIELD(checkForWrite);
1354 COPY_SCALAR_FIELD(checkAsUser);
1359 static FkConstraint *
1360 _copyFkConstraint(FkConstraint *from)
1362 FkConstraint *newnode = makeNode(FkConstraint);
1364 COPY_STRING_FIELD(constr_name);
1365 COPY_NODE_FIELD(pktable);
1366 COPY_NODE_FIELD(fk_attrs);
1367 COPY_NODE_FIELD(pk_attrs);
1368 COPY_SCALAR_FIELD(fk_matchtype);
1369 COPY_SCALAR_FIELD(fk_upd_action);
1370 COPY_SCALAR_FIELD(fk_del_action);
1371 COPY_SCALAR_FIELD(deferrable);
1372 COPY_SCALAR_FIELD(initdeferred);
1373 COPY_SCALAR_FIELD(skip_validation);
1379 _copySortClause(SortClause *from)
1381 SortClause *newnode = makeNode(SortClause);
1383 COPY_SCALAR_FIELD(tleSortGroupRef);
1384 COPY_SCALAR_FIELD(sortop);
1389 static GroupClause *
1390 _copyGroupClause(GroupClause *from)
1392 GroupClause *newnode = makeNode(GroupClause);
1394 COPY_SCALAR_FIELD(tleSortGroupRef);
1395 COPY_SCALAR_FIELD(sortop);
1401 _copyAExpr(A_Expr *from)
1403 A_Expr *newnode = makeNode(A_Expr);
1405 COPY_SCALAR_FIELD(oper);
1406 COPY_NODE_FIELD(name);
1407 COPY_NODE_FIELD(lexpr);
1408 COPY_NODE_FIELD(rexpr);
1414 _copyColumnRef(ColumnRef *from)
1416 ColumnRef *newnode = makeNode(ColumnRef);
1418 COPY_NODE_FIELD(fields);
1419 COPY_NODE_FIELD(indirection);
1425 _copyParamRef(ParamRef *from)
1427 ParamRef *newnode = makeNode(ParamRef);
1429 COPY_SCALAR_FIELD(number);
1430 COPY_NODE_FIELD(fields);
1431 COPY_NODE_FIELD(indirection);
1437 _copyAConst(A_Const *from)
1439 A_Const *newnode = makeNode(A_Const);
1441 /* This part must duplicate _copyValue */
1442 COPY_SCALAR_FIELD(val.type);
1443 switch (from->val.type)
1446 COPY_SCALAR_FIELD(val.val.ival);
1451 COPY_STRING_FIELD(val.val.str);
1457 elog(ERROR, "_copyAConst: unknown node type %d", from->val.type);
1461 COPY_NODE_FIELD(typename);
1467 _copyFuncCall(FuncCall *from)
1469 FuncCall *newnode = makeNode(FuncCall);
1471 COPY_NODE_FIELD(funcname);
1472 COPY_NODE_FIELD(args);
1473 COPY_SCALAR_FIELD(agg_star);
1474 COPY_SCALAR_FIELD(agg_distinct);
1480 _copyAIndices(A_Indices *from)
1482 A_Indices *newnode = makeNode(A_Indices);
1484 COPY_NODE_FIELD(lidx);
1485 COPY_NODE_FIELD(uidx);
1490 static ExprFieldSelect *
1491 _copyExprFieldSelect(ExprFieldSelect *from)
1493 ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
1495 COPY_NODE_FIELD(arg);
1496 COPY_NODE_FIELD(fields);
1497 COPY_NODE_FIELD(indirection);
1503 _copyResTarget(ResTarget *from)
1505 ResTarget *newnode = makeNode(ResTarget);
1507 COPY_STRING_FIELD(name);
1508 COPY_NODE_FIELD(indirection);
1509 COPY_NODE_FIELD(val);
1515 _copyTypeName(TypeName *from)
1517 TypeName *newnode = makeNode(TypeName);
1519 COPY_NODE_FIELD(names);
1520 COPY_SCALAR_FIELD(typeid);
1521 COPY_SCALAR_FIELD(timezone);
1522 COPY_SCALAR_FIELD(setof);
1523 COPY_SCALAR_FIELD(pct_type);
1524 COPY_SCALAR_FIELD(typmod);
1525 COPY_NODE_FIELD(arrayBounds);
1530 static SortGroupBy *
1531 _copySortGroupBy(SortGroupBy *from)
1533 SortGroupBy *newnode = makeNode(SortGroupBy);
1535 COPY_NODE_FIELD(useOp);
1536 COPY_NODE_FIELD(node);
1541 static RangeSubselect *
1542 _copyRangeSubselect(RangeSubselect *from)
1544 RangeSubselect *newnode = makeNode(RangeSubselect);
1546 COPY_NODE_FIELD(subquery);
1547 COPY_NODE_FIELD(alias);
1552 static RangeFunction *
1553 _copyRangeFunction(RangeFunction *from)
1555 RangeFunction *newnode = makeNode(RangeFunction);
1557 COPY_NODE_FIELD(funccallnode);
1558 COPY_NODE_FIELD(alias);
1559 COPY_NODE_FIELD(coldeflist);
1565 _copyTypeCast(TypeCast *from)
1567 TypeCast *newnode = makeNode(TypeCast);
1569 COPY_NODE_FIELD(arg);
1570 COPY_NODE_FIELD(typename);
1576 _copyIndexElem(IndexElem *from)
1578 IndexElem *newnode = makeNode(IndexElem);
1580 COPY_STRING_FIELD(name);
1581 COPY_NODE_FIELD(funcname);
1582 COPY_NODE_FIELD(args);
1583 COPY_NODE_FIELD(opclass);
1589 _copyColumnDef(ColumnDef *from)
1591 ColumnDef *newnode = makeNode(ColumnDef);
1593 COPY_STRING_FIELD(colname);
1594 COPY_NODE_FIELD(typename);
1595 COPY_SCALAR_FIELD(inhcount);
1596 COPY_SCALAR_FIELD(is_local);
1597 COPY_SCALAR_FIELD(is_not_null);
1598 COPY_NODE_FIELD(raw_default);
1599 COPY_STRING_FIELD(cooked_default);
1600 COPY_NODE_FIELD(constraints);
1601 COPY_NODE_FIELD(support);
1607 _copyConstraint(Constraint *from)
1609 Constraint *newnode = makeNode(Constraint);
1611 COPY_SCALAR_FIELD(contype);
1612 COPY_STRING_FIELD(name);
1613 COPY_NODE_FIELD(raw_expr);
1614 COPY_STRING_FIELD(cooked_expr);
1615 COPY_NODE_FIELD(keys);
1621 _copyCaseExpr(CaseExpr *from)
1623 CaseExpr *newnode = makeNode(CaseExpr);
1625 COPY_SCALAR_FIELD(casetype);
1626 COPY_NODE_FIELD(arg);
1627 COPY_NODE_FIELD(args);
1628 COPY_NODE_FIELD(defresult);
1634 _copyCaseWhen(CaseWhen *from)
1636 CaseWhen *newnode = makeNode(CaseWhen);
1638 COPY_NODE_FIELD(expr);
1639 COPY_NODE_FIELD(result);
1645 _copyNullTest(NullTest *from)
1647 NullTest *newnode = makeNode(NullTest);
1649 COPY_NODE_FIELD(arg);
1650 COPY_SCALAR_FIELD(nulltesttype);
1655 static BooleanTest *
1656 _copyBooleanTest(BooleanTest *from)
1658 BooleanTest *newnode = makeNode(BooleanTest);
1660 COPY_NODE_FIELD(arg);
1661 COPY_SCALAR_FIELD(booltesttype);
1666 static ConstraintTest *
1667 _copyConstraintTest(ConstraintTest *from)
1669 ConstraintTest *newnode = makeNode(ConstraintTest);
1671 COPY_NODE_FIELD(arg);
1672 COPY_SCALAR_FIELD(testtype);
1673 COPY_STRING_FIELD(name);
1674 COPY_STRING_FIELD(domname);
1675 COPY_NODE_FIELD(check_expr);
1680 static DomainConstraintValue *
1681 _copyDomainConstraintValue(DomainConstraintValue *from)
1683 DomainConstraintValue *newnode = makeNode(DomainConstraintValue);
1688 static ConstraintTestValue *
1689 _copyConstraintTestValue(ConstraintTestValue *from)
1691 ConstraintTestValue *newnode = makeNode(ConstraintTestValue);
1693 COPY_SCALAR_FIELD(typeId);
1694 COPY_SCALAR_FIELD(typeMod);
1700 _copyDefElem(DefElem *from)
1702 DefElem *newnode = makeNode(DefElem);
1704 COPY_STRING_FIELD(defname);
1705 COPY_NODE_FIELD(arg);
1711 _copyQuery(Query *from)
1713 Query *newnode = makeNode(Query);
1715 COPY_SCALAR_FIELD(commandType);
1716 COPY_SCALAR_FIELD(querySource);
1717 COPY_NODE_FIELD(utilityStmt);
1718 COPY_SCALAR_FIELD(resultRelation);
1719 COPY_NODE_FIELD(into);
1720 COPY_SCALAR_FIELD(isPortal);
1721 COPY_SCALAR_FIELD(isBinary);
1722 COPY_SCALAR_FIELD(hasAggs);
1723 COPY_SCALAR_FIELD(hasSubLinks);
1724 COPY_NODE_FIELD(rtable);
1725 COPY_NODE_FIELD(jointree);
1726 COPY_INTLIST_FIELD(rowMarks);
1727 COPY_NODE_FIELD(targetList);
1728 COPY_NODE_FIELD(groupClause);
1729 COPY_NODE_FIELD(havingQual);
1730 COPY_NODE_FIELD(distinctClause);
1731 COPY_NODE_FIELD(sortClause);
1732 COPY_NODE_FIELD(limitOffset);
1733 COPY_NODE_FIELD(limitCount);
1734 COPY_NODE_FIELD(setOperations);
1735 COPY_INTLIST_FIELD(resultRelations);
1738 * We do not copy the planner internal fields: base_rel_list,
1739 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys,
1740 * hasJoinRTEs. Not entirely clear if this is right?
1747 _copyInsertStmt(InsertStmt *from)
1749 InsertStmt *newnode = makeNode(InsertStmt);
1751 COPY_NODE_FIELD(relation);
1752 COPY_NODE_FIELD(cols);
1753 COPY_NODE_FIELD(targetList);
1754 COPY_NODE_FIELD(selectStmt);
1760 _copyDeleteStmt(DeleteStmt *from)
1762 DeleteStmt *newnode = makeNode(DeleteStmt);
1764 COPY_NODE_FIELD(relation);
1765 COPY_NODE_FIELD(whereClause);
1771 _copyUpdateStmt(UpdateStmt *from)
1773 UpdateStmt *newnode = makeNode(UpdateStmt);
1775 COPY_NODE_FIELD(relation);
1776 COPY_NODE_FIELD(targetList);
1777 COPY_NODE_FIELD(whereClause);
1778 COPY_NODE_FIELD(fromClause);
1784 _copySelectStmt(SelectStmt *from)
1786 SelectStmt *newnode = makeNode(SelectStmt);
1788 COPY_NODE_FIELD(distinctClause);
1789 COPY_NODE_FIELD(into);
1790 COPY_NODE_FIELD(intoColNames);
1791 COPY_NODE_FIELD(targetList);
1792 COPY_NODE_FIELD(fromClause);
1793 COPY_NODE_FIELD(whereClause);
1794 COPY_NODE_FIELD(groupClause);
1795 COPY_NODE_FIELD(havingClause);
1796 COPY_NODE_FIELD(sortClause);
1797 COPY_STRING_FIELD(portalname);
1798 COPY_SCALAR_FIELD(binary);
1799 COPY_NODE_FIELD(limitOffset);
1800 COPY_NODE_FIELD(limitCount);
1801 COPY_NODE_FIELD(forUpdate);
1802 COPY_SCALAR_FIELD(op);
1803 COPY_SCALAR_FIELD(all);
1804 COPY_NODE_FIELD(larg);
1805 COPY_NODE_FIELD(rarg);
1810 static SetOperationStmt *
1811 _copySetOperationStmt(SetOperationStmt *from)
1813 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1815 COPY_SCALAR_FIELD(op);
1816 COPY_SCALAR_FIELD(all);
1817 COPY_NODE_FIELD(larg);
1818 COPY_NODE_FIELD(rarg);
1819 COPY_INTLIST_FIELD(colTypes);
1824 static AlterTableStmt *
1825 _copyAlterTableStmt(AlterTableStmt *from)
1827 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1829 COPY_SCALAR_FIELD(subtype);
1830 COPY_NODE_FIELD(relation);
1831 COPY_STRING_FIELD(name);
1832 COPY_NODE_FIELD(def);
1833 COPY_SCALAR_FIELD(behavior);
1839 _copyGrantStmt(GrantStmt *from)
1841 GrantStmt *newnode = makeNode(GrantStmt);
1843 COPY_SCALAR_FIELD(is_grant);
1844 COPY_SCALAR_FIELD(objtype);
1845 COPY_NODE_FIELD(objects);
1846 COPY_INTLIST_FIELD(privileges);
1847 COPY_NODE_FIELD(grantees);
1852 static PrivGrantee *
1853 _copyPrivGrantee(PrivGrantee *from)
1855 PrivGrantee *newnode = makeNode(PrivGrantee);
1857 COPY_STRING_FIELD(username);
1858 COPY_STRING_FIELD(groupname);
1863 static FuncWithArgs *
1864 _copyFuncWithArgs(FuncWithArgs *from)
1866 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1868 COPY_NODE_FIELD(funcname);
1869 COPY_NODE_FIELD(funcargs);
1874 static InsertDefault *
1875 _copyInsertDefault(InsertDefault *from)
1877 InsertDefault *newnode = makeNode(InsertDefault);
1883 static ClosePortalStmt *
1884 _copyClosePortalStmt(ClosePortalStmt *from)
1886 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1888 COPY_STRING_FIELD(portalname);
1893 static ClusterStmt *
1894 _copyClusterStmt(ClusterStmt *from)
1896 ClusterStmt *newnode = makeNode(ClusterStmt);
1898 COPY_NODE_FIELD(relation);
1899 COPY_STRING_FIELD(indexname);
1905 _copyCopyStmt(CopyStmt *from)
1907 CopyStmt *newnode = makeNode(CopyStmt);
1909 COPY_NODE_FIELD(relation);
1910 COPY_NODE_FIELD(attlist);
1911 COPY_SCALAR_FIELD(is_from);
1912 COPY_STRING_FIELD(filename);
1913 COPY_NODE_FIELD(options);
1919 _copyCreateStmt(CreateStmt *from)
1921 CreateStmt *newnode = makeNode(CreateStmt);
1923 COPY_NODE_FIELD(relation);
1924 COPY_NODE_FIELD(tableElts);
1925 COPY_NODE_FIELD(inhRelations);
1926 COPY_NODE_FIELD(constraints);
1927 COPY_SCALAR_FIELD(hasoids);
1928 COPY_SCALAR_FIELD(oncommit);
1934 _copyDefineStmt(DefineStmt *from)
1936 DefineStmt *newnode = makeNode(DefineStmt);
1938 COPY_SCALAR_FIELD(defType);
1939 COPY_NODE_FIELD(defnames);
1940 COPY_NODE_FIELD(definition);
1946 _copyDropStmt(DropStmt *from)
1948 DropStmt *newnode = makeNode(DropStmt);
1950 COPY_NODE_FIELD(objects);
1951 COPY_SCALAR_FIELD(removeType);
1952 COPY_SCALAR_FIELD(behavior);
1957 static TruncateStmt *
1958 _copyTruncateStmt(TruncateStmt *from)
1960 TruncateStmt *newnode = makeNode(TruncateStmt);
1962 COPY_NODE_FIELD(relation);
1967 static CommentStmt *
1968 _copyCommentStmt(CommentStmt *from)
1970 CommentStmt *newnode = makeNode(CommentStmt);
1972 COPY_SCALAR_FIELD(objtype);
1973 COPY_NODE_FIELD(objname);
1974 COPY_NODE_FIELD(objargs);
1975 COPY_STRING_FIELD(comment);
1981 _copyFetchStmt(FetchStmt *from)
1983 FetchStmt *newnode = makeNode(FetchStmt);
1985 COPY_SCALAR_FIELD(direction);
1986 COPY_SCALAR_FIELD(howMany);
1987 COPY_STRING_FIELD(portalname);
1988 COPY_SCALAR_FIELD(ismove);
1994 _copyIndexStmt(IndexStmt *from)
1996 IndexStmt *newnode = makeNode(IndexStmt);
1998 COPY_STRING_FIELD(idxname);
1999 COPY_NODE_FIELD(relation);
2000 COPY_STRING_FIELD(accessMethod);
2001 COPY_NODE_FIELD(indexParams);
2002 COPY_NODE_FIELD(whereClause);
2003 COPY_NODE_FIELD(rangetable);
2004 COPY_SCALAR_FIELD(unique);
2005 COPY_SCALAR_FIELD(primary);
2006 COPY_SCALAR_FIELD(isconstraint);
2011 static CreateFunctionStmt *
2012 _copyCreateFunctionStmt(CreateFunctionStmt *from)
2014 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
2016 COPY_SCALAR_FIELD(replace);
2017 COPY_NODE_FIELD(funcname);
2018 COPY_NODE_FIELD(argTypes);
2019 COPY_NODE_FIELD(returnType);
2020 COPY_NODE_FIELD(options);
2021 COPY_NODE_FIELD(withClause);
2026 static RemoveAggrStmt *
2027 _copyRemoveAggrStmt(RemoveAggrStmt *from)
2029 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
2031 COPY_NODE_FIELD(aggname);
2032 COPY_NODE_FIELD(aggtype);
2033 COPY_SCALAR_FIELD(behavior);
2038 static RemoveFuncStmt *
2039 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2041 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2043 COPY_NODE_FIELD(funcname);
2044 COPY_NODE_FIELD(args);
2045 COPY_SCALAR_FIELD(behavior);
2050 static RemoveOperStmt *
2051 _copyRemoveOperStmt(RemoveOperStmt *from)
2053 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2055 COPY_NODE_FIELD(opname);
2056 COPY_NODE_FIELD(args);
2057 COPY_SCALAR_FIELD(behavior);
2062 static RemoveOpClassStmt *
2063 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
2065 RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
2067 COPY_NODE_FIELD(opclassname);
2068 COPY_STRING_FIELD(amname);
2069 COPY_SCALAR_FIELD(behavior);
2075 _copyRenameStmt(RenameStmt *from)
2077 RenameStmt *newnode = makeNode(RenameStmt);
2079 COPY_NODE_FIELD(relation);
2080 COPY_STRING_FIELD(oldname);
2081 COPY_STRING_FIELD(newname);
2082 COPY_SCALAR_FIELD(renameType);
2088 _copyRuleStmt(RuleStmt *from)
2090 RuleStmt *newnode = makeNode(RuleStmt);
2092 COPY_NODE_FIELD(relation);
2093 COPY_STRING_FIELD(rulename);
2094 COPY_NODE_FIELD(whereClause);
2095 COPY_SCALAR_FIELD(event);
2096 COPY_SCALAR_FIELD(instead);
2097 COPY_NODE_FIELD(actions);
2098 COPY_SCALAR_FIELD(replace);
2104 _copyNotifyStmt(NotifyStmt *from)
2106 NotifyStmt *newnode = makeNode(NotifyStmt);
2108 COPY_NODE_FIELD(relation);
2114 _copyListenStmt(ListenStmt *from)
2116 ListenStmt *newnode = makeNode(ListenStmt);
2118 COPY_NODE_FIELD(relation);
2123 static UnlistenStmt *
2124 _copyUnlistenStmt(UnlistenStmt *from)
2126 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2128 COPY_NODE_FIELD(relation);
2133 static TransactionStmt *
2134 _copyTransactionStmt(TransactionStmt *from)
2136 TransactionStmt *newnode = makeNode(TransactionStmt);
2138 COPY_SCALAR_FIELD(command);
2139 COPY_NODE_FIELD(options);
2144 static CompositeTypeStmt *
2145 _copyCompositeTypeStmt(CompositeTypeStmt *from)
2147 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
2149 COPY_NODE_FIELD(typevar);
2150 COPY_NODE_FIELD(coldeflist);
2156 _copyViewStmt(ViewStmt *from)
2158 ViewStmt *newnode = makeNode(ViewStmt);
2160 COPY_NODE_FIELD(view);
2161 COPY_NODE_FIELD(aliases);
2162 COPY_NODE_FIELD(query);
2163 COPY_SCALAR_FIELD(replace);
2169 _copyLoadStmt(LoadStmt *from)
2171 LoadStmt *newnode = makeNode(LoadStmt);
2173 COPY_STRING_FIELD(filename);
2178 static CreateDomainStmt *
2179 _copyCreateDomainStmt(CreateDomainStmt *from)
2181 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2183 COPY_NODE_FIELD(domainname);
2184 COPY_NODE_FIELD(typename);
2185 COPY_NODE_FIELD(constraints);
2190 static CreateOpClassStmt *
2191 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2193 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2195 COPY_NODE_FIELD(opclassname);
2196 COPY_STRING_FIELD(amname);
2197 COPY_NODE_FIELD(datatype);
2198 COPY_NODE_FIELD(items);
2199 COPY_SCALAR_FIELD(isDefault);
2204 static CreateOpClassItem *
2205 _copyCreateOpClassItem(CreateOpClassItem *from)
2207 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2209 COPY_SCALAR_FIELD(itemtype);
2210 COPY_NODE_FIELD(name);
2211 COPY_NODE_FIELD(args);
2212 COPY_SCALAR_FIELD(number);
2213 COPY_SCALAR_FIELD(recheck);
2214 COPY_NODE_FIELD(storedtype);
2219 static CreatedbStmt *
2220 _copyCreatedbStmt(CreatedbStmt *from)
2222 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2224 COPY_STRING_FIELD(dbname);
2225 COPY_NODE_FIELD(options);
2230 static AlterDatabaseSetStmt *
2231 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2233 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2235 COPY_STRING_FIELD(dbname);
2236 COPY_STRING_FIELD(variable);
2237 COPY_NODE_FIELD(value);
2243 _copyDropdbStmt(DropdbStmt *from)
2245 DropdbStmt *newnode = makeNode(DropdbStmt);
2247 COPY_STRING_FIELD(dbname);
2253 _copyVacuumStmt(VacuumStmt *from)
2255 VacuumStmt *newnode = makeNode(VacuumStmt);
2257 COPY_SCALAR_FIELD(vacuum);
2258 COPY_SCALAR_FIELD(full);
2259 COPY_SCALAR_FIELD(analyze);
2260 COPY_SCALAR_FIELD(freeze);
2261 COPY_SCALAR_FIELD(verbose);
2262 COPY_NODE_FIELD(relation);
2263 COPY_NODE_FIELD(va_cols);
2268 static ExplainStmt *
2269 _copyExplainStmt(ExplainStmt *from)
2271 ExplainStmt *newnode = makeNode(ExplainStmt);
2273 COPY_NODE_FIELD(query);
2274 COPY_SCALAR_FIELD(verbose);
2275 COPY_SCALAR_FIELD(analyze);
2280 static CreateSeqStmt *
2281 _copyCreateSeqStmt(CreateSeqStmt *from)
2283 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2285 COPY_NODE_FIELD(sequence);
2286 COPY_NODE_FIELD(options);
2291 static VariableSetStmt *
2292 _copyVariableSetStmt(VariableSetStmt *from)
2294 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2296 COPY_STRING_FIELD(name);
2297 COPY_NODE_FIELD(args);
2298 COPY_SCALAR_FIELD(is_local);
2303 static VariableShowStmt *
2304 _copyVariableShowStmt(VariableShowStmt *from)
2306 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2308 COPY_STRING_FIELD(name);
2313 static VariableResetStmt *
2314 _copyVariableResetStmt(VariableResetStmt *from)
2316 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2318 COPY_STRING_FIELD(name);
2323 static CreateTrigStmt *
2324 _copyCreateTrigStmt(CreateTrigStmt *from)
2326 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2328 COPY_STRING_FIELD(trigname);
2329 COPY_NODE_FIELD(relation);
2330 COPY_NODE_FIELD(funcname);
2331 COPY_NODE_FIELD(args);
2332 COPY_SCALAR_FIELD(before);
2333 COPY_SCALAR_FIELD(row);
2334 strcpy(newnode->actions, from->actions); /* in-line string field */
2335 COPY_SCALAR_FIELD(isconstraint);
2336 COPY_SCALAR_FIELD(deferrable);
2337 COPY_SCALAR_FIELD(initdeferred);
2338 COPY_NODE_FIELD(constrrel);
2343 static DropPropertyStmt *
2344 _copyDropPropertyStmt(DropPropertyStmt *from)
2346 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2348 COPY_NODE_FIELD(relation);
2349 COPY_STRING_FIELD(property);
2350 COPY_SCALAR_FIELD(removeType);
2351 COPY_SCALAR_FIELD(behavior);
2356 static CreatePLangStmt *
2357 _copyCreatePLangStmt(CreatePLangStmt *from)
2359 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2361 COPY_STRING_FIELD(plname);
2362 COPY_NODE_FIELD(plhandler);
2363 COPY_NODE_FIELD(plvalidator);
2364 COPY_SCALAR_FIELD(pltrusted);
2369 static DropPLangStmt *
2370 _copyDropPLangStmt(DropPLangStmt *from)
2372 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2374 COPY_STRING_FIELD(plname);
2375 COPY_SCALAR_FIELD(behavior);
2380 static CreateUserStmt *
2381 _copyCreateUserStmt(CreateUserStmt *from)
2383 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2385 COPY_STRING_FIELD(user);
2386 COPY_NODE_FIELD(options);
2391 static AlterUserStmt *
2392 _copyAlterUserStmt(AlterUserStmt *from)
2394 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2396 COPY_STRING_FIELD(user);
2397 COPY_NODE_FIELD(options);
2402 static AlterUserSetStmt *
2403 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2405 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2407 COPY_STRING_FIELD(user);
2408 COPY_STRING_FIELD(variable);
2409 COPY_NODE_FIELD(value);
2414 static DropUserStmt *
2415 _copyDropUserStmt(DropUserStmt *from)
2417 DropUserStmt *newnode = makeNode(DropUserStmt);
2419 COPY_NODE_FIELD(users);
2425 _copyLockStmt(LockStmt *from)
2427 LockStmt *newnode = makeNode(LockStmt);
2429 COPY_NODE_FIELD(relations);
2430 COPY_SCALAR_FIELD(mode);
2435 static ConstraintsSetStmt *
2436 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2438 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2440 COPY_NODE_FIELD(constraints);
2441 COPY_SCALAR_FIELD(deferred);
2446 static CreateGroupStmt *
2447 _copyCreateGroupStmt(CreateGroupStmt *from)
2449 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2451 COPY_STRING_FIELD(name);
2452 COPY_NODE_FIELD(options);
2457 static AlterGroupStmt *
2458 _copyAlterGroupStmt(AlterGroupStmt *from)
2460 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2462 COPY_STRING_FIELD(name);
2463 COPY_SCALAR_FIELD(action);
2464 COPY_NODE_FIELD(listUsers);
2469 static DropGroupStmt *
2470 _copyDropGroupStmt(DropGroupStmt *from)
2472 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2474 COPY_STRING_FIELD(name);
2479 static ReindexStmt *
2480 _copyReindexStmt(ReindexStmt *from)
2482 ReindexStmt *newnode = makeNode(ReindexStmt);
2484 COPY_SCALAR_FIELD(reindexType);
2485 COPY_NODE_FIELD(relation);
2486 COPY_STRING_FIELD(name);
2487 COPY_SCALAR_FIELD(force);
2488 COPY_SCALAR_FIELD(all);
2493 static CreateSchemaStmt *
2494 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2496 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2498 COPY_STRING_FIELD(schemaname);
2499 COPY_STRING_FIELD(authid);
2500 COPY_NODE_FIELD(schemaElts);
2505 static CreateConversionStmt *
2506 _copyCreateConversionStmt(CreateConversionStmt *from)
2508 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2510 COPY_NODE_FIELD(conversion_name);
2511 COPY_STRING_FIELD(for_encoding_name);
2512 COPY_STRING_FIELD(to_encoding_name);
2513 COPY_NODE_FIELD(func_name);
2514 COPY_SCALAR_FIELD(def);
2519 static CreateCastStmt *
2520 _copyCreateCastStmt(CreateCastStmt *from)
2522 CreateCastStmt *newnode = makeNode(CreateCastStmt);
2524 COPY_NODE_FIELD(sourcetype);
2525 COPY_NODE_FIELD(targettype);
2526 COPY_NODE_FIELD(func);
2527 COPY_SCALAR_FIELD(context);
2532 static DropCastStmt *
2533 _copyDropCastStmt(DropCastStmt *from)
2535 DropCastStmt *newnode = makeNode(DropCastStmt);
2537 COPY_NODE_FIELD(sourcetype);
2538 COPY_NODE_FIELD(targettype);
2539 COPY_SCALAR_FIELD(behavior);
2544 static PrepareStmt *
2545 _copyPrepareStmt(PrepareStmt *from)
2547 PrepareStmt *newnode = makeNode(PrepareStmt);
2549 COPY_STRING_FIELD(name);
2550 COPY_NODE_FIELD(argtypes);
2551 COPY_INTLIST_FIELD(argtype_oids);
2552 COPY_NODE_FIELD(query);
2557 static ExecuteStmt *
2558 _copyExecuteStmt(ExecuteStmt *from)
2560 ExecuteStmt *newnode = makeNode(ExecuteStmt);
2562 COPY_STRING_FIELD(name);
2563 COPY_NODE_FIELD(into);
2564 COPY_NODE_FIELD(params);
2569 static DeallocateStmt *
2570 _copyDeallocateStmt(DeallocateStmt *from)
2572 DeallocateStmt *newnode = makeNode(DeallocateStmt);
2574 COPY_STRING_FIELD(name);
2580 /* ****************************************************************
2581 * pg_list.h copy functions
2582 * ****************************************************************
2586 _copyValue(Value *from)
2588 Value *newnode = makeNode(Value);
2590 /* See also _copyAConst when changing this code! */
2592 COPY_SCALAR_FIELD(type);
2596 COPY_SCALAR_FIELD(val.ival);
2601 COPY_STRING_FIELD(val.str);
2607 elog(ERROR, "_copyValue: unknown node type %d", from->type);
2616 * Create a copy of a Node tree or list. This is a "deep" copy: all
2617 * substructure is copied too, recursively.
2620 copyObject(void *from)
2627 switch (nodeTag(from))
2633 retval = _copyPlan(from);
2636 retval = _copyResult(from);
2639 retval = _copyAppend(from);
2642 retval = _copyScan(from);
2645 retval = _copySeqScan(from);
2648 retval = _copyIndexScan(from);
2651 retval = _copyTidScan(from);
2653 case T_SubqueryScan:
2654 retval = _copySubqueryScan(from);
2656 case T_FunctionScan:
2657 retval = _copyFunctionScan(from);
2660 retval = _copyJoin(from);
2663 retval = _copyNestLoop(from);
2666 retval = _copyMergeJoin(from);
2669 retval = _copyHashJoin(from);
2672 retval = _copyMaterial(from);
2675 retval = _copySort(from);
2678 retval = _copyGroup(from);
2681 retval = _copyAgg(from);
2684 retval = _copyUnique(from);
2687 retval = _copySetOp(from);
2690 retval = _copyLimit(from);
2693 retval = _copyHash(from);
2696 retval = _copySubPlan(from);
2703 retval = _copyResdom(from);
2706 retval = _copyFjoin(from);
2709 retval = _copyAlias(from);
2712 retval = _copyRangeVar(from);
2715 retval = _copyExpr(from);
2718 retval = _copyVar(from);
2721 retval = _copyOper(from);
2724 retval = _copyConst(from);
2727 retval = _copyParam(from);
2730 retval = _copyFunc(from);
2733 retval = _copyAggref(from);
2736 retval = _copySubLink(from);
2739 retval = _copyFieldSelect(from);
2742 retval = _copyRelabelType(from);
2745 retval = _copyRangeTblRef(from);
2748 retval = _copyJoinExpr(from);
2751 retval = _copyFromExpr(from);
2754 retval = _copyArrayRef(from);
2761 retval = _copyRelOptInfo(from);
2763 case T_IndexOptInfo:
2764 retval = _copyIndexOptInfo(from);
2767 retval = _copyPath(from);
2770 retval = _copyIndexPath(from);
2773 retval = _copyTidPath(from);
2776 retval = _copyAppendPath(from);
2779 retval = _copyResultPath(from);
2781 case T_MaterialPath:
2782 retval = _copyMaterialPath(from);
2785 retval = _copyNestPath(from);
2788 retval = _copyMergePath(from);
2791 retval = _copyHashPath(from);
2794 retval = _copyPathKeyItem(from);
2796 case T_RestrictInfo:
2797 retval = _copyRestrictInfo(from);
2800 retval = _copyJoinInfo(from);
2802 case T_InnerIndexscanInfo:
2803 retval = _copyInnerIndexscanInfo(from);
2814 retval = _copyValue(from);
2822 /* rather ugly coding for speed... */
2823 /* Note the input list cannot be NIL if we got here. */
2824 nl = makeList1(copyObject(lfirst(list)));
2827 foreach(l, lnext(list))
2829 lnext(nl) = makeList1(copyObject(lfirst(l)));
2839 retval = _copyQuery(from);
2842 retval = _copyInsertStmt(from);
2845 retval = _copyDeleteStmt(from);
2848 retval = _copyUpdateStmt(from);
2851 retval = _copySelectStmt(from);
2853 case T_SetOperationStmt:
2854 retval = _copySetOperationStmt(from);
2856 case T_AlterTableStmt:
2857 retval = _copyAlterTableStmt(from);
2860 retval = _copyGrantStmt(from);
2862 case T_ClosePortalStmt:
2863 retval = _copyClosePortalStmt(from);
2866 retval = _copyClusterStmt(from);
2869 retval = _copyCopyStmt(from);
2872 retval = _copyCreateStmt(from);
2875 retval = _copyDefineStmt(from);
2878 retval = _copyDropStmt(from);
2880 case T_TruncateStmt:
2881 retval = _copyTruncateStmt(from);
2884 retval = _copyCommentStmt(from);
2887 retval = _copyFetchStmt(from);
2890 retval = _copyIndexStmt(from);
2892 case T_CreateFunctionStmt:
2893 retval = _copyCreateFunctionStmt(from);
2895 case T_RemoveAggrStmt:
2896 retval = _copyRemoveAggrStmt(from);
2898 case T_RemoveFuncStmt:
2899 retval = _copyRemoveFuncStmt(from);
2901 case T_RemoveOperStmt:
2902 retval = _copyRemoveOperStmt(from);
2904 case T_RemoveOpClassStmt:
2905 retval = _copyRemoveOpClassStmt(from);
2908 retval = _copyRenameStmt(from);
2911 retval = _copyRuleStmt(from);
2914 retval = _copyNotifyStmt(from);
2917 retval = _copyListenStmt(from);
2919 case T_UnlistenStmt:
2920 retval = _copyUnlistenStmt(from);
2922 case T_TransactionStmt:
2923 retval = _copyTransactionStmt(from);
2925 case T_CompositeTypeStmt:
2926 retval = _copyCompositeTypeStmt(from);
2929 retval = _copyViewStmt(from);
2932 retval = _copyLoadStmt(from);
2934 case T_CreateDomainStmt:
2935 retval = _copyCreateDomainStmt(from);
2937 case T_CreateOpClassStmt:
2938 retval = _copyCreateOpClassStmt(from);
2940 case T_CreateOpClassItem:
2941 retval = _copyCreateOpClassItem(from);
2943 case T_CreatedbStmt:
2944 retval = _copyCreatedbStmt(from);
2946 case T_AlterDatabaseSetStmt:
2947 retval = _copyAlterDatabaseSetStmt(from);
2950 retval = _copyDropdbStmt(from);
2953 retval = _copyVacuumStmt(from);
2956 retval = _copyExplainStmt(from);
2958 case T_CreateSeqStmt:
2959 retval = _copyCreateSeqStmt(from);
2961 case T_VariableSetStmt:
2962 retval = _copyVariableSetStmt(from);
2964 case T_VariableShowStmt:
2965 retval = _copyVariableShowStmt(from);
2967 case T_VariableResetStmt:
2968 retval = _copyVariableResetStmt(from);
2970 case T_CreateTrigStmt:
2971 retval = _copyCreateTrigStmt(from);
2973 case T_DropPropertyStmt:
2974 retval = _copyDropPropertyStmt(from);
2976 case T_CreatePLangStmt:
2977 retval = _copyCreatePLangStmt(from);
2979 case T_DropPLangStmt:
2980 retval = _copyDropPLangStmt(from);
2982 case T_CreateUserStmt:
2983 retval = _copyCreateUserStmt(from);
2985 case T_AlterUserStmt:
2986 retval = _copyAlterUserStmt(from);
2988 case T_AlterUserSetStmt:
2989 retval = _copyAlterUserSetStmt(from);
2991 case T_DropUserStmt:
2992 retval = _copyDropUserStmt(from);
2995 retval = _copyLockStmt(from);
2997 case T_ConstraintsSetStmt:
2998 retval = _copyConstraintsSetStmt(from);
3000 case T_CreateGroupStmt:
3001 retval = _copyCreateGroupStmt(from);
3003 case T_AlterGroupStmt:
3004 retval = _copyAlterGroupStmt(from);
3006 case T_DropGroupStmt:
3007 retval = _copyDropGroupStmt(from);
3010 retval = _copyReindexStmt(from);
3012 case T_CheckPointStmt:
3013 retval = (void *) makeNode(CheckPointStmt);
3015 case T_CreateSchemaStmt:
3016 retval = _copyCreateSchemaStmt(from);
3018 case T_CreateConversionStmt:
3019 retval = _copyCreateConversionStmt(from);
3021 case T_CreateCastStmt:
3022 retval = _copyCreateCastStmt(from);
3024 case T_DropCastStmt:
3025 retval = _copyDropCastStmt(from);
3028 retval = _copyPrepareStmt(from);
3031 retval = _copyExecuteStmt(from);
3033 case T_DeallocateStmt:
3034 retval = _copyDeallocateStmt(from);
3038 retval = _copyAExpr(from);
3041 retval = _copyColumnRef(from);
3044 retval = _copyParamRef(from);
3047 retval = _copyAConst(from);
3050 retval = _copyFuncCall(from);
3053 retval = _copyAIndices(from);
3055 case T_ExprFieldSelect:
3056 retval = _copyExprFieldSelect(from);
3059 retval = _copyResTarget(from);
3062 retval = _copyTypeCast(from);
3065 retval = _copySortGroupBy(from);
3067 case T_RangeSubselect:
3068 retval = _copyRangeSubselect(from);
3070 case T_RangeFunction:
3071 retval = _copyRangeFunction(from);
3074 retval = _copyTypeName(from);
3077 retval = _copyIndexElem(from);
3080 retval = _copyColumnDef(from);
3083 retval = _copyConstraint(from);
3086 retval = _copyDefElem(from);
3089 retval = _copyTargetEntry(from);
3091 case T_RangeTblEntry:
3092 retval = _copyRangeTblEntry(from);
3095 retval = _copySortClause(from);
3098 retval = _copyGroupClause(from);
3101 retval = _copyCaseExpr(from);
3104 retval = _copyCaseWhen(from);
3107 retval = _copyNullTest(from);
3110 retval = _copyBooleanTest(from);
3112 case T_ConstraintTest:
3113 retval = _copyConstraintTest(from);
3115 case T_ConstraintTestValue:
3116 retval = _copyConstraintTestValue(from);
3118 case T_FkConstraint:
3119 retval = _copyFkConstraint(from);
3122 retval = _copyPrivGrantee(from);
3124 case T_FuncWithArgs:
3125 retval = _copyFuncWithArgs(from);
3127 case T_InsertDefault:
3128 retval = _copyInsertDefault(from);
3130 case T_DomainConstraintValue:
3131 retval = _copyDomainConstraintValue(from);
3135 elog(ERROR, "copyObject: don't know how to copy node type %d",
3137 retval = from; /* keep compiler quiet */