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-2001, 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.189 2002/06/18 17:27:57 momjian Exp $
20 *-------------------------------------------------------------------------
25 #include "optimizer/clauses.h"
26 #include "optimizer/planmain.h"
31 * a macro to simplify calling of copyObject on the specified field
33 #define Node_Copy(from, newnode, field) \
34 ((newnode)->field = copyObject((from)->field))
39 * This copy function only copies the "cons-cells" of the list, not the
40 * pointed-to objects. (Use copyObject if you want a "deep" copy.)
42 * We also use this function for copying lists of integers, which is
43 * grotty but unlikely to break --- it could fail if sizeof(pointer)
44 * is less than sizeof(int), but I don't know any such machines...
46 * Note that copyObject will surely coredump if applied to a list
56 /* rather ugly coding for speed... */
60 newlist = nl = makeList1(lfirst(list));
62 foreach(l, lnext(list))
64 lnext(nl) = makeList1(lfirst(l));
70 /* ****************************************************************
71 * plannodes.h copy functions
72 * ****************************************************************
78 * This function copies the fields of the Plan node. It is used by
79 * all the copy functions for classes which inherit from Plan.
83 CopyPlanFields(Plan *from, Plan *newnode)
85 newnode->startup_cost = from->startup_cost;
86 newnode->total_cost = from->total_cost;
87 newnode->plan_rows = from->plan_rows;
88 newnode->plan_width = from->plan_width;
89 /* state is NOT copied */
90 Node_Copy(from, newnode, targetlist);
91 Node_Copy(from, newnode, qual);
92 Node_Copy(from, newnode, lefttree);
93 Node_Copy(from, newnode, righttree);
94 newnode->extParam = listCopy(from->extParam);
95 newnode->locParam = listCopy(from->locParam);
96 newnode->chgParam = listCopy(from->chgParam);
97 Node_Copy(from, newnode, initPlan);
98 /* subPlan list must point to subplans in the new subtree, not the old */
99 if (from->subPlan != NIL)
100 newnode->subPlan = nconc(pull_subplans((Node *) newnode->targetlist),
101 pull_subplans((Node *) newnode->qual));
103 newnode->subPlan = NIL;
104 newnode->nParamExec = from->nParamExec;
112 _copyPlan(Plan *from)
114 Plan *newnode = makeNode(Plan);
117 * copy the node superclass fields
119 CopyPlanFields(from, newnode);
130 _copyResult(Result *from)
132 Result *newnode = makeNode(Result);
135 * copy node superclass fields
137 CopyPlanFields((Plan *) from, (Plan *) newnode);
140 * copy remainder of node
142 Node_Copy(from, newnode, resconstantqual);
145 * We must add subplans in resconstantqual to the new plan's subPlan
148 if (from->plan.subPlan != NIL)
149 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
150 pull_subplans(newnode->resconstantqual));
160 _copyAppend(Append *from)
162 Append *newnode = makeNode(Append);
165 * copy node superclass fields
167 CopyPlanFields((Plan *) from, (Plan *) newnode);
170 * copy remainder of node
172 Node_Copy(from, newnode, appendplans);
173 newnode->isTarget = from->isTarget;
182 * This function copies the fields of the Scan node. It is used by
183 * all the copy functions for classes which inherit from Scan.
187 CopyScanFields(Scan *from, Scan *newnode)
189 newnode->scanrelid = from->scanrelid;
198 _copyScan(Scan *from)
200 Scan *newnode = makeNode(Scan);
203 * copy node superclass fields
205 CopyPlanFields((Plan *) from, (Plan *) newnode);
206 CopyScanFields((Scan *) from, (Scan *) newnode);
216 _copySeqScan(SeqScan *from)
218 SeqScan *newnode = makeNode(SeqScan);
221 * copy node superclass fields
223 CopyPlanFields((Plan *) from, (Plan *) newnode);
224 CopyScanFields((Scan *) from, (Scan *) newnode);
234 _copyIndexScan(IndexScan *from)
236 IndexScan *newnode = makeNode(IndexScan);
239 * copy node superclass fields
241 CopyPlanFields((Plan *) from, (Plan *) newnode);
242 CopyScanFields((Scan *) from, (Scan *) newnode);
245 * copy remainder of node
247 newnode->indxid = listCopy(from->indxid);
248 Node_Copy(from, newnode, indxqual);
249 Node_Copy(from, newnode, indxqualorig);
250 newnode->indxorderdir = from->indxorderdir;
253 * We must add subplans in index quals to the new plan's subPlan list
255 if (from->scan.plan.subPlan != NIL)
257 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
258 pull_subplans((Node *) newnode->indxqual));
259 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
260 pull_subplans((Node *) newnode->indxqualorig));
271 _copyTidScan(TidScan *from)
273 TidScan *newnode = makeNode(TidScan);
276 * copy node superclass fields
278 CopyPlanFields((Plan *) from, (Plan *) newnode);
279 CopyScanFields((Scan *) from, (Scan *) newnode);
282 * copy remainder of node
284 newnode->needRescan = from->needRescan;
285 Node_Copy(from, newnode, tideval);
294 static SubqueryScan *
295 _copySubqueryScan(SubqueryScan *from)
297 SubqueryScan *newnode = makeNode(SubqueryScan);
300 * copy node superclass fields
302 CopyPlanFields((Plan *) from, (Plan *) newnode);
303 CopyScanFields((Scan *) from, (Scan *) newnode);
306 * copy remainder of node
308 Node_Copy(from, newnode, subplan);
317 static FunctionScan *
318 _copyFunctionScan(FunctionScan *from)
320 FunctionScan *newnode = makeNode(FunctionScan);
323 * copy node superclass fields
325 CopyPlanFields((Plan *) from, (Plan *) newnode);
326 CopyScanFields((Scan *) from, (Scan *) newnode);
334 * This function copies the fields of the Join node. It is used by
335 * all the copy functions for classes which inherit from Join.
339 CopyJoinFields(Join *from, Join *newnode)
341 newnode->jointype = from->jointype;
342 Node_Copy(from, newnode, joinqual);
343 /* subPlan list must point to subplans in the new subtree, not the old */
344 if (from->plan.subPlan != NIL)
345 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
346 pull_subplans((Node *) newnode->joinqual));
355 _copyJoin(Join *from)
357 Join *newnode = makeNode(Join);
360 * copy node superclass fields
362 CopyPlanFields((Plan *) from, (Plan *) newnode);
363 CopyJoinFields(from, newnode);
374 _copyNestLoop(NestLoop *from)
376 NestLoop *newnode = makeNode(NestLoop);
379 * copy node superclass fields
381 CopyPlanFields((Plan *) from, (Plan *) newnode);
382 CopyJoinFields((Join *) from, (Join *) newnode);
393 _copyMergeJoin(MergeJoin *from)
395 MergeJoin *newnode = makeNode(MergeJoin);
398 * copy node superclass fields
400 CopyPlanFields((Plan *) from, (Plan *) newnode);
401 CopyJoinFields((Join *) from, (Join *) newnode);
404 * copy remainder of node
406 Node_Copy(from, newnode, mergeclauses);
409 * We must add subplans in mergeclauses to the new plan's subPlan list
411 if (from->join.plan.subPlan != NIL)
412 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
413 pull_subplans((Node *) newnode->mergeclauses));
423 _copyHashJoin(HashJoin *from)
425 HashJoin *newnode = makeNode(HashJoin);
428 * copy node superclass fields
430 CopyPlanFields((Plan *) from, (Plan *) newnode);
431 CopyJoinFields((Join *) from, (Join *) newnode);
434 * copy remainder of node
436 Node_Copy(from, newnode, hashclauses);
437 newnode->hashjoinop = from->hashjoinop;
440 * We must add subplans in hashclauses to the new plan's subPlan list
442 if (from->join.plan.subPlan != NIL)
443 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
444 pull_subplans((Node *) newnode->hashclauses));
455 _copyMaterial(Material *from)
457 Material *newnode = makeNode(Material);
460 * copy node superclass fields
462 CopyPlanFields((Plan *) from, (Plan *) newnode);
473 _copySort(Sort *from)
475 Sort *newnode = makeNode(Sort);
478 * copy node superclass fields
480 CopyPlanFields((Plan *) from, (Plan *) newnode);
482 newnode->keycount = from->keycount;
493 _copyGroup(Group *from)
495 Group *newnode = makeNode(Group);
497 CopyPlanFields((Plan *) from, (Plan *) newnode);
499 newnode->tuplePerGroup = from->tuplePerGroup;
500 newnode->numCols = from->numCols;
501 newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
502 memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
514 Agg *newnode = makeNode(Agg);
516 CopyPlanFields((Plan *) from, (Plan *) newnode);
526 _copyGroupClause(GroupClause *from)
528 GroupClause *newnode = makeNode(GroupClause);
530 newnode->tleSortGroupRef = from->tleSortGroupRef;
531 newnode->sortop = from->sortop;
541 _copyUnique(Unique *from)
543 Unique *newnode = makeNode(Unique);
546 * copy node superclass fields
548 CopyPlanFields((Plan *) from, (Plan *) newnode);
551 * copy remainder of node
553 newnode->numCols = from->numCols;
554 newnode->uniqColIdx = palloc(from->numCols * sizeof(AttrNumber));
555 memcpy(newnode->uniqColIdx, from->uniqColIdx, from->numCols * sizeof(AttrNumber));
565 _copySetOp(SetOp *from)
567 SetOp *newnode = makeNode(SetOp);
570 * copy node superclass fields
572 CopyPlanFields((Plan *) from, (Plan *) newnode);
575 * copy remainder of node
577 newnode->cmd = from->cmd;
578 newnode->numCols = from->numCols;
579 newnode->dupColIdx = palloc(from->numCols * sizeof(AttrNumber));
580 memcpy(newnode->dupColIdx, from->dupColIdx, from->numCols * sizeof(AttrNumber));
581 newnode->flagColIdx = from->flagColIdx;
591 _copyLimit(Limit *from)
593 Limit *newnode = makeNode(Limit);
596 * copy node superclass fields
598 CopyPlanFields((Plan *) from, (Plan *) newnode);
601 * copy remainder of node
603 Node_Copy(from, newnode, limitOffset);
604 Node_Copy(from, newnode, limitCount);
614 _copyHash(Hash *from)
616 Hash *newnode = makeNode(Hash);
619 * copy node superclass fields
621 CopyPlanFields((Plan *) from, (Plan *) newnode);
624 * copy remainder of node
626 Node_Copy(from, newnode, hashkey);
632 _copySubPlan(SubPlan *from)
634 SubPlan *newnode = makeNode(SubPlan);
636 Node_Copy(from, newnode, plan);
637 newnode->plan_id = from->plan_id;
638 Node_Copy(from, newnode, rtable);
639 newnode->setParam = listCopy(from->setParam);
640 newnode->parParam = listCopy(from->parParam);
641 Node_Copy(from, newnode, sublink);
643 /* do not copy execution state */
644 newnode->needShutdown = false;
645 newnode->curTuple = NULL;
650 /* ****************************************************************
651 * primnodes.h copy functions
652 * ****************************************************************
660 _copyResdom(Resdom *from)
662 Resdom *newnode = makeNode(Resdom);
664 newnode->resno = from->resno;
665 newnode->restype = from->restype;
666 newnode->restypmod = from->restypmod;
667 if (from->resname != NULL)
668 newnode->resname = pstrdup(from->resname);
669 newnode->ressortgroupref = from->ressortgroupref;
670 newnode->reskey = from->reskey;
671 newnode->reskeyop = from->reskeyop;
672 newnode->resjunk = from->resjunk;
678 _copyFjoin(Fjoin *from)
680 Fjoin *newnode = makeNode(Fjoin);
683 * copy node superclass fields
686 newnode->fj_initialized = from->fj_initialized;
687 newnode->fj_nNodes = from->fj_nNodes;
689 Node_Copy(from, newnode, fj_innerNode);
691 newnode->fj_results = (DatumPtr)
692 palloc((from->fj_nNodes) * sizeof(Datum));
693 memmove(from->fj_results,
695 (from->fj_nNodes) * sizeof(Datum));
697 newnode->fj_alwaysDone = (BoolPtr)
698 palloc((from->fj_nNodes) * sizeof(bool));
699 memmove(from->fj_alwaysDone,
700 newnode->fj_alwaysDone,
701 (from->fj_nNodes) * sizeof(bool));
712 _copyExpr(Expr *from)
714 Expr *newnode = makeNode(Expr);
717 * copy node superclass fields
719 newnode->typeOid = from->typeOid;
720 newnode->opType = from->opType;
722 Node_Copy(from, newnode, oper);
723 Node_Copy(from, newnode, args);
735 Var *newnode = makeNode(Var);
738 * copy remainder of node
740 newnode->varno = from->varno;
741 newnode->varattno = from->varattno;
742 newnode->vartype = from->vartype;
743 newnode->vartypmod = from->vartypmod;
744 newnode->varlevelsup = from->varlevelsup;
746 newnode->varnoold = from->varnoold;
747 newnode->varoattno = from->varoattno;
757 _copyOper(Oper *from)
759 Oper *newnode = makeNode(Oper);
762 * copy remainder of node
764 newnode->opno = from->opno;
765 newnode->opid = from->opid;
766 newnode->opresulttype = from->opresulttype;
767 newnode->opretset = from->opretset;
768 /* Do not copy the run-time state, if any */
769 newnode->op_fcache = NULL;
779 _copyConst(Const *from)
781 Const *newnode = makeNode(Const);
784 * copy remainder of node
786 newnode->consttype = from->consttype;
787 newnode->constlen = from->constlen;
789 if (from->constbyval || from->constisnull)
792 * passed by value so just copy the datum. Also, don't try to copy
793 * struct when value is null!
796 newnode->constvalue = from->constvalue;
801 * not passed by value. datum contains a pointer.
803 int length = from->constlen;
805 if (length == -1) /* variable-length type? */
806 length = VARSIZE(from->constvalue);
807 newnode->constvalue = PointerGetDatum(palloc(length));
808 memcpy(DatumGetPointer(newnode->constvalue),
809 DatumGetPointer(from->constvalue),
813 newnode->constisnull = from->constisnull;
814 newnode->constbyval = from->constbyval;
815 newnode->constisset = from->constisset;
816 newnode->constiscast = from->constiscast;
826 _copyParam(Param *from)
828 Param *newnode = makeNode(Param);
831 * copy remainder of node
833 newnode->paramkind = from->paramkind;
834 newnode->paramid = from->paramid;
836 if (from->paramname != NULL)
837 newnode->paramname = pstrdup(from->paramname);
838 newnode->paramtype = from->paramtype;
848 _copyFunc(Func *from)
850 Func *newnode = makeNode(Func);
853 * copy remainder of node
855 newnode->funcid = from->funcid;
856 newnode->funcresulttype = from->funcresulttype;
857 newnode->funcretset = from->funcretset;
858 /* Do not copy the run-time state, if any */
859 newnode->func_fcache = NULL;
869 _copyAggref(Aggref *from)
871 Aggref *newnode = makeNode(Aggref);
873 newnode->aggfnoid = from->aggfnoid;
874 newnode->aggtype = from->aggtype;
875 Node_Copy(from, newnode, target);
876 newnode->aggstar = from->aggstar;
877 newnode->aggdistinct = from->aggdistinct;
878 newnode->aggno = from->aggno; /* probably not needed */
888 _copySubLink(SubLink *from)
890 SubLink *newnode = makeNode(SubLink);
893 * copy remainder of node
895 newnode->subLinkType = from->subLinkType;
896 newnode->useor = from->useor;
897 Node_Copy(from, newnode, lefthand);
898 Node_Copy(from, newnode, oper);
899 Node_Copy(from, newnode, subselect);
909 _copyFieldSelect(FieldSelect *from)
911 FieldSelect *newnode = makeNode(FieldSelect);
914 * copy remainder of node
916 Node_Copy(from, newnode, arg);
917 newnode->fieldnum = from->fieldnum;
918 newnode->resulttype = from->resulttype;
919 newnode->resulttypmod = from->resulttypmod;
929 _copyRelabelType(RelabelType *from)
931 RelabelType *newnode = makeNode(RelabelType);
934 * copy remainder of node
936 Node_Copy(from, newnode, arg);
937 newnode->resulttype = from->resulttype;
938 newnode->resulttypmod = from->resulttypmod;
944 _copyRangeTblRef(RangeTblRef *from)
946 RangeTblRef *newnode = makeNode(RangeTblRef);
948 newnode->rtindex = from->rtindex;
954 _copyFromExpr(FromExpr *from)
956 FromExpr *newnode = makeNode(FromExpr);
958 Node_Copy(from, newnode, fromlist);
959 Node_Copy(from, newnode, quals);
965 _copyJoinExpr(JoinExpr *from)
967 JoinExpr *newnode = makeNode(JoinExpr);
969 newnode->jointype = from->jointype;
970 newnode->isNatural = from->isNatural;
971 Node_Copy(from, newnode, larg);
972 Node_Copy(from, newnode, rarg);
973 Node_Copy(from, newnode, using);
974 Node_Copy(from, newnode, quals);
975 Node_Copy(from, newnode, alias);
976 newnode->rtindex = from->rtindex;
986 _copyCaseExpr(CaseExpr *from)
988 CaseExpr *newnode = makeNode(CaseExpr);
991 * copy remainder of node
993 newnode->casetype = from->casetype;
995 Node_Copy(from, newnode, arg);
996 Node_Copy(from, newnode, args);
997 Node_Copy(from, newnode, defresult);
1007 _copyCaseWhen(CaseWhen *from)
1009 CaseWhen *newnode = makeNode(CaseWhen);
1012 * copy remainder of node
1014 Node_Copy(from, newnode, expr);
1015 Node_Copy(from, newnode, result);
1025 _copyNullTest(NullTest *from)
1027 NullTest *newnode = makeNode(NullTest);
1030 * copy remainder of node
1032 Node_Copy(from, newnode, arg);
1033 newnode->nulltesttype = from->nulltesttype;
1042 static BooleanTest *
1043 _copyBooleanTest(BooleanTest *from)
1045 BooleanTest *newnode = makeNode(BooleanTest);
1048 * copy remainder of node
1050 Node_Copy(from, newnode, arg);
1051 newnode->booltesttype = from->booltesttype;
1057 _copyArrayRef(ArrayRef *from)
1059 ArrayRef *newnode = makeNode(ArrayRef);
1062 * copy remainder of node
1064 newnode->refattrlength = from->refattrlength;
1065 newnode->refelemlength = from->refelemlength;
1066 newnode->refelemtype = from->refelemtype;
1067 newnode->refelembyval = from->refelembyval;
1069 Node_Copy(from, newnode, refupperindexpr);
1070 Node_Copy(from, newnode, reflowerindexpr);
1071 Node_Copy(from, newnode, refexpr);
1072 Node_Copy(from, newnode, refassgnexpr);
1077 /* ****************************************************************
1078 * relation.h copy functions
1079 * ****************************************************************
1087 _copyRelOptInfo(RelOptInfo *from)
1089 RelOptInfo *newnode = makeNode(RelOptInfo);
1091 newnode->reloptkind = from->reloptkind;
1093 newnode->relids = listCopy(from->relids);
1095 newnode->rows = from->rows;
1096 newnode->width = from->width;
1098 Node_Copy(from, newnode, targetlist);
1099 Node_Copy(from, newnode, pathlist);
1100 /* XXX cheapest-path fields should point to members of pathlist? */
1101 Node_Copy(from, newnode, cheapest_startup_path);
1102 Node_Copy(from, newnode, cheapest_total_path);
1103 newnode->pruneable = from->pruneable;
1105 newnode->rtekind = from->rtekind;
1106 Node_Copy(from, newnode, indexlist);
1107 newnode->pages = from->pages;
1108 newnode->tuples = from->tuples;
1109 Node_Copy(from, newnode, subplan);
1111 newnode->joinrti = from->joinrti;
1112 newnode->joinrteids = listCopy(from->joinrteids);
1114 Node_Copy(from, newnode, baserestrictinfo);
1115 newnode->baserestrictcost = from->baserestrictcost;
1116 newnode->outerjoinset = listCopy(from->outerjoinset);
1117 Node_Copy(from, newnode, joininfo);
1118 Node_Copy(from, newnode, innerjoin);
1127 static IndexOptInfo *
1128 _copyIndexOptInfo(IndexOptInfo *from)
1130 IndexOptInfo *newnode = makeNode(IndexOptInfo);
1133 newnode->indexoid = from->indexoid;
1134 newnode->pages = from->pages;
1135 newnode->tuples = from->tuples;
1137 newnode->ncolumns = from->ncolumns;
1138 newnode->nkeys = from->nkeys;
1140 if (from->classlist)
1142 /* copy the trailing zero too */
1143 len = (from->ncolumns + 1) * sizeof(Oid);
1144 newnode->classlist = (Oid *) palloc(len);
1145 memcpy(newnode->classlist, from->classlist, len);
1148 if (from->indexkeys)
1150 /* copy the trailing zero too */
1151 len = (from->nkeys + 1) * sizeof(int);
1152 newnode->indexkeys = (int *) palloc(len);
1153 memcpy(newnode->indexkeys, from->indexkeys, len);
1158 /* copy the trailing zero too */
1159 len = (from->ncolumns + 1) * sizeof(Oid);
1160 newnode->ordering = (Oid *) palloc(len);
1161 memcpy(newnode->ordering, from->ordering, len);
1164 newnode->relam = from->relam;
1165 newnode->amcostestimate = from->amcostestimate;
1166 newnode->indproc = from->indproc;
1167 Node_Copy(from, newnode, indpred);
1168 newnode->unique = from->unique;
1176 * This function copies the fields of the Path node. It is used by
1177 * all the copy functions for classes which inherit from Path.
1181 CopyPathFields(Path *from, Path *newnode)
1184 * Modify the next line, since it causes the copying to cycle (i.e.
1185 * the parent points right back here! -- JMH, 7/7/92. Old version:
1186 * Node_Copy(from, newnode, parent);
1188 newnode->parent = from->parent;
1190 newnode->startup_cost = from->startup_cost;
1191 newnode->total_cost = from->total_cost;
1193 newnode->pathtype = from->pathtype;
1195 Node_Copy(from, newnode, pathkeys);
1203 _copyPath(Path *from)
1205 Path *newnode = makeNode(Path);
1207 CopyPathFields(from, newnode);
1217 _copyIndexPath(IndexPath *from)
1219 IndexPath *newnode = makeNode(IndexPath);
1222 * copy the node superclass fields
1224 CopyPathFields((Path *) from, (Path *) newnode);
1227 * copy remainder of node
1229 Node_Copy(from, newnode, indexinfo);
1230 Node_Copy(from, newnode, indexqual);
1231 newnode->indexscandir = from->indexscandir;
1232 newnode->joinrelids = listCopy(from->joinrelids);
1233 newnode->alljoinquals = from->alljoinquals;
1234 newnode->rows = from->rows;
1244 _copyTidPath(TidPath *from)
1246 TidPath *newnode = makeNode(TidPath);
1249 * copy the node superclass fields
1251 CopyPathFields((Path *) from, (Path *) newnode);
1254 * copy remainder of node
1256 Node_Copy(from, newnode, tideval);
1257 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1267 _copyAppendPath(AppendPath *from)
1269 AppendPath *newnode = makeNode(AppendPath);
1272 * copy the node superclass fields
1274 CopyPathFields((Path *) from, (Path *) newnode);
1277 * copy remainder of node
1279 Node_Copy(from, newnode, subpaths);
1285 * CopyJoinPathFields
1287 * This function copies the fields of the JoinPath node. It is used by
1288 * all the copy functions for classes which inherit from JoinPath.
1292 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1294 newnode->jointype = from->jointype;
1295 Node_Copy(from, newnode, outerjoinpath);
1296 Node_Copy(from, newnode, innerjoinpath);
1297 Node_Copy(from, newnode, joinrestrictinfo);
1305 _copyNestPath(NestPath *from)
1307 NestPath *newnode = makeNode(NestPath);
1310 * copy the node superclass fields
1312 CopyPathFields((Path *) from, (Path *) newnode);
1313 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1323 _copyMergePath(MergePath *from)
1325 MergePath *newnode = makeNode(MergePath);
1328 * copy the node superclass fields
1330 CopyPathFields((Path *) from, (Path *) newnode);
1331 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1334 * copy the remainder of the node
1336 Node_Copy(from, newnode, path_mergeclauses);
1337 Node_Copy(from, newnode, outersortkeys);
1338 Node_Copy(from, newnode, innersortkeys);
1348 _copyHashPath(HashPath *from)
1350 HashPath *newnode = makeNode(HashPath);
1353 * copy the node superclass fields
1355 CopyPathFields((Path *) from, (Path *) newnode);
1356 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1359 * copy remainder of node
1361 Node_Copy(from, newnode, path_hashclauses);
1370 static PathKeyItem *
1371 _copyPathKeyItem(PathKeyItem *from)
1373 PathKeyItem *newnode = makeNode(PathKeyItem);
1376 * copy remainder of node
1378 Node_Copy(from, newnode, key);
1379 newnode->sortop = from->sortop;
1388 static RestrictInfo *
1389 _copyRestrictInfo(RestrictInfo *from)
1391 RestrictInfo *newnode = makeNode(RestrictInfo);
1394 * copy remainder of node
1396 Node_Copy(from, newnode, clause);
1397 newnode->ispusheddown = from->ispusheddown;
1398 Node_Copy(from, newnode, subclauseindices);
1399 newnode->eval_cost = from->eval_cost;
1400 newnode->this_selec = from->this_selec;
1401 newnode->mergejoinoperator = from->mergejoinoperator;
1402 newnode->left_sortop = from->left_sortop;
1403 newnode->right_sortop = from->right_sortop;
1406 * Do not copy pathkeys, since they'd not be canonical in a copied
1409 newnode->left_pathkey = NIL;
1410 newnode->right_pathkey = NIL;
1411 newnode->left_mergescansel = from->left_mergescansel;
1412 newnode->right_mergescansel = from->right_mergescansel;
1413 newnode->hashjoinoperator = from->hashjoinoperator;
1414 newnode->left_bucketsize = from->left_bucketsize;
1415 newnode->right_bucketsize = from->right_bucketsize;
1425 _copyJoinInfo(JoinInfo *from)
1427 JoinInfo *newnode = makeNode(JoinInfo);
1430 * copy remainder of node
1432 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1433 Node_Copy(from, newnode, jinfo_restrictinfo);
1439 _copyStream(Stream *from)
1441 Stream *newnode = makeNode(Stream);
1443 newnode->pathptr = from->pathptr;
1444 newnode->cinfo = from->cinfo;
1445 newnode->clausetype = from->clausetype;
1447 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1449 Node_Copy(from, newnode, downstream);
1450 if (newnode->downstream)
1451 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1453 newnode->groupup = from->groupup;
1454 newnode->groupcost = from->groupcost;
1455 newnode->groupsel = from->groupsel;
1460 /* ****************************************************************
1461 * parsenodes.h copy functions
1462 * ****************************************************************
1465 static TargetEntry *
1466 _copyTargetEntry(TargetEntry *from)
1468 TargetEntry *newnode = makeNode(TargetEntry);
1470 Node_Copy(from, newnode, resdom);
1471 Node_Copy(from, newnode, fjoin);
1472 Node_Copy(from, newnode, expr);
1476 static RangeTblEntry *
1477 _copyRangeTblEntry(RangeTblEntry *from)
1479 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1481 newnode->rtekind = from->rtekind;
1482 newnode->relid = from->relid;
1483 Node_Copy(from, newnode, subquery);
1484 Node_Copy(from, newnode, funcexpr);
1485 newnode->jointype = from->jointype;
1486 Node_Copy(from, newnode, joinaliasvars);
1487 Node_Copy(from, newnode, alias);
1488 Node_Copy(from, newnode, eref);
1489 newnode->inh = from->inh;
1490 newnode->inFromCl = from->inFromCl;
1491 newnode->checkForRead = from->checkForRead;
1492 newnode->checkForWrite = from->checkForWrite;
1493 newnode->checkAsUser = from->checkAsUser;
1498 static FkConstraint *
1499 _copyFkConstraint(FkConstraint *from)
1501 FkConstraint *newnode = makeNode(FkConstraint);
1503 if (from->constr_name)
1504 newnode->constr_name = pstrdup(from->constr_name);
1505 Node_Copy(from, newnode, pktable);
1506 Node_Copy(from, newnode, fk_attrs);
1507 Node_Copy(from, newnode, pk_attrs);
1508 if (from->match_type)
1509 newnode->match_type = pstrdup(from->match_type);
1510 newnode->actions = from->actions;
1511 newnode->deferrable = from->deferrable;
1512 newnode->initdeferred = from->initdeferred;
1518 _copySortClause(SortClause *from)
1520 SortClause *newnode = makeNode(SortClause);
1522 newnode->tleSortGroupRef = from->tleSortGroupRef;
1523 newnode->sortop = from->sortop;
1529 _copyAExpr(A_Expr *from)
1531 A_Expr *newnode = makeNode(A_Expr);
1533 newnode->oper = from->oper;
1534 Node_Copy(from, newnode, name);
1535 Node_Copy(from, newnode, lexpr);
1536 Node_Copy(from, newnode, rexpr);
1542 _copyColumnRef(ColumnRef *from)
1544 ColumnRef *newnode = makeNode(ColumnRef);
1546 Node_Copy(from, newnode, fields);
1547 Node_Copy(from, newnode, indirection);
1553 _copyParamRef(ParamRef *from)
1555 ParamRef *newnode = makeNode(ParamRef);
1557 newnode->number = from->number;
1558 Node_Copy(from, newnode, fields);
1559 Node_Copy(from, newnode, indirection);
1565 _copyAConst(A_Const *from)
1567 A_Const *newnode = makeNode(A_Const);
1569 newnode->val = *((Value *) (copyObject(&(from->val))));
1570 Node_Copy(from, newnode, typename);
1576 _copyIdent(Ident *from)
1578 Ident *newnode = makeNode(Ident);
1580 newnode->name = pstrdup(from->name);
1586 _copyFuncCall(FuncCall *from)
1588 FuncCall *newnode = makeNode(FuncCall);
1590 Node_Copy(from, newnode, funcname);
1591 Node_Copy(from, newnode, args);
1592 newnode->agg_star = from->agg_star;
1593 newnode->agg_distinct = from->agg_distinct;
1599 _copyAIndices(A_Indices *from)
1601 A_Indices *newnode = makeNode(A_Indices);
1603 Node_Copy(from, newnode, lidx);
1604 Node_Copy(from, newnode, uidx);
1609 static ExprFieldSelect *
1610 _copyExprFieldSelect(ExprFieldSelect *from)
1612 ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
1614 Node_Copy(from, newnode, arg);
1615 Node_Copy(from, newnode, fields);
1616 Node_Copy(from, newnode, indirection);
1622 _copyResTarget(ResTarget *from)
1624 ResTarget *newnode = makeNode(ResTarget);
1627 newnode->name = pstrdup(from->name);
1628 Node_Copy(from, newnode, indirection);
1629 Node_Copy(from, newnode, val);
1635 _copyTypeName(TypeName *from)
1637 TypeName *newnode = makeNode(TypeName);
1639 Node_Copy(from, newnode, names);
1640 newnode->typeid = from->typeid;
1641 newnode->timezone = from->timezone;
1642 newnode->setof = from->setof;
1643 newnode->pct_type = from->pct_type;
1644 newnode->typmod = from->typmod;
1645 Node_Copy(from, newnode, arrayBounds);
1650 static SortGroupBy *
1651 _copySortGroupBy(SortGroupBy *from)
1653 SortGroupBy *newnode = makeNode(SortGroupBy);
1655 Node_Copy(from, newnode, useOp);
1656 Node_Copy(from, newnode, node);
1662 _copyAlias(Alias *from)
1664 Alias *newnode = makeNode(Alias);
1666 if (from->aliasname)
1667 newnode->aliasname = pstrdup(from->aliasname);
1668 Node_Copy(from, newnode, colnames);
1674 _copyRangeVar(RangeVar *from)
1676 RangeVar *newnode = makeNode(RangeVar);
1678 if (from->catalogname)
1679 newnode->catalogname = pstrdup(from->catalogname);
1680 if (from->schemaname)
1681 newnode->schemaname = pstrdup(from->schemaname);
1683 newnode->relname = pstrdup(from->relname);
1684 newnode->inhOpt = from->inhOpt;
1685 newnode->istemp = from->istemp;
1686 Node_Copy(from, newnode, alias);
1691 static RangeSubselect *
1692 _copyRangeSubselect(RangeSubselect *from)
1694 RangeSubselect *newnode = makeNode(RangeSubselect);
1696 Node_Copy(from, newnode, subquery);
1697 Node_Copy(from, newnode, alias);
1702 static RangeFunction *
1703 _copyRangeFunction(RangeFunction *from)
1705 RangeFunction *newnode = makeNode(RangeFunction);
1707 Node_Copy(from, newnode, funccallnode);
1708 Node_Copy(from, newnode, alias);
1714 _copyTypeCast(TypeCast *from)
1716 TypeCast *newnode = makeNode(TypeCast);
1718 Node_Copy(from, newnode, arg);
1719 Node_Copy(from, newnode, typename);
1725 _copyIndexElem(IndexElem *from)
1727 IndexElem *newnode = makeNode(IndexElem);
1730 newnode->name = pstrdup(from->name);
1731 Node_Copy(from, newnode, funcname);
1732 Node_Copy(from, newnode, args);
1733 Node_Copy(from, newnode, opclass);
1739 _copyColumnDef(ColumnDef *from)
1741 ColumnDef *newnode = makeNode(ColumnDef);
1744 newnode->colname = pstrdup(from->colname);
1745 Node_Copy(from, newnode, typename);
1746 newnode->is_not_null = from->is_not_null;
1747 Node_Copy(from, newnode, raw_default);
1748 if (from->cooked_default)
1749 newnode->cooked_default = pstrdup(from->cooked_default);
1750 Node_Copy(from, newnode, constraints);
1756 _copyConstraint(Constraint *from)
1758 Constraint *newnode = makeNode(Constraint);
1760 newnode->contype = from->contype;
1762 newnode->name = pstrdup(from->name);
1763 Node_Copy(from, newnode, raw_expr);
1764 if (from->cooked_expr)
1765 newnode->cooked_expr = pstrdup(from->cooked_expr);
1766 Node_Copy(from, newnode, keys);
1772 _copyDefElem(DefElem *from)
1774 DefElem *newnode = makeNode(DefElem);
1777 newnode->defname = pstrdup(from->defname);
1778 Node_Copy(from, newnode, arg);
1784 _copyQuery(Query *from)
1786 Query *newnode = makeNode(Query);
1788 newnode->commandType = from->commandType;
1789 Node_Copy(from, newnode, utilityStmt);
1790 newnode->resultRelation = from->resultRelation;
1791 Node_Copy(from, newnode, into);
1792 newnode->isPortal = from->isPortal;
1793 newnode->isBinary = from->isBinary;
1794 newnode->hasAggs = from->hasAggs;
1795 newnode->hasSubLinks = from->hasSubLinks;
1796 newnode->originalQuery = from->originalQuery;
1798 Node_Copy(from, newnode, rtable);
1799 Node_Copy(from, newnode, jointree);
1801 newnode->rowMarks = listCopy(from->rowMarks);
1803 Node_Copy(from, newnode, targetList);
1805 Node_Copy(from, newnode, groupClause);
1806 Node_Copy(from, newnode, havingQual);
1807 Node_Copy(from, newnode, distinctClause);
1808 Node_Copy(from, newnode, sortClause);
1810 Node_Copy(from, newnode, limitOffset);
1811 Node_Copy(from, newnode, limitCount);
1813 Node_Copy(from, newnode, setOperations);
1815 newnode->resultRelations = listCopy(from->resultRelations);
1818 * We do not copy the planner internal fields: base_rel_list,
1819 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. Not
1820 * entirely clear if this is right?
1827 _copyInsertStmt(InsertStmt *from)
1829 InsertStmt *newnode = makeNode(InsertStmt);
1831 Node_Copy(from, newnode, relation);
1832 Node_Copy(from, newnode, cols);
1833 Node_Copy(from, newnode, targetList);
1834 Node_Copy(from, newnode, selectStmt);
1840 _copyDeleteStmt(DeleteStmt *from)
1842 DeleteStmt *newnode = makeNode(DeleteStmt);
1844 Node_Copy(from, newnode, relation);
1845 Node_Copy(from, newnode, whereClause);
1851 _copyUpdateStmt(UpdateStmt *from)
1853 UpdateStmt *newnode = makeNode(UpdateStmt);
1855 Node_Copy(from, newnode, relation);
1856 Node_Copy(from, newnode, targetList);
1857 Node_Copy(from, newnode, whereClause);
1858 Node_Copy(from, newnode, fromClause);
1864 _copySelectStmt(SelectStmt *from)
1866 SelectStmt *newnode = makeNode(SelectStmt);
1868 Node_Copy(from, newnode, distinctClause);
1869 Node_Copy(from, newnode, into);
1870 Node_Copy(from, newnode, intoColNames);
1871 Node_Copy(from, newnode, targetList);
1872 Node_Copy(from, newnode, fromClause);
1873 Node_Copy(from, newnode, whereClause);
1874 Node_Copy(from, newnode, groupClause);
1875 Node_Copy(from, newnode, havingClause);
1876 Node_Copy(from, newnode, sortClause);
1877 if (from->portalname)
1878 newnode->portalname = pstrdup(from->portalname);
1879 newnode->binary = from->binary;
1880 Node_Copy(from, newnode, limitOffset);
1881 Node_Copy(from, newnode, limitCount);
1882 Node_Copy(from, newnode, forUpdate);
1883 newnode->op = from->op;
1884 newnode->all = from->all;
1885 Node_Copy(from, newnode, larg);
1886 Node_Copy(from, newnode, rarg);
1891 static SetOperationStmt *
1892 _copySetOperationStmt(SetOperationStmt *from)
1894 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1896 newnode->op = from->op;
1897 newnode->all = from->all;
1898 Node_Copy(from, newnode, larg);
1899 Node_Copy(from, newnode, rarg);
1900 newnode->colTypes = listCopy(from->colTypes);
1905 static AlterTableStmt *
1906 _copyAlterTableStmt(AlterTableStmt *from)
1908 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1910 newnode->subtype = from->subtype;
1911 Node_Copy(from, newnode, relation);
1913 newnode->name = pstrdup(from->name);
1914 Node_Copy(from, newnode, def);
1915 newnode->behavior = from->behavior;
1921 _copyGrantStmt(GrantStmt *from)
1923 GrantStmt *newnode = makeNode(GrantStmt);
1925 newnode->is_grant = from->is_grant;
1926 newnode->objtype = from->objtype;
1927 Node_Copy(from, newnode, objects);
1928 newnode->privileges = listCopy(from->privileges);
1929 Node_Copy(from, newnode, grantees);
1934 static PrivGrantee *
1935 _copyPrivGrantee(PrivGrantee *from)
1937 PrivGrantee *newnode = makeNode(PrivGrantee);
1940 newnode->username = pstrdup(from->username);
1941 if (from->groupname)
1942 newnode->groupname = pstrdup(from->groupname);
1947 static FuncWithArgs *
1948 _copyFuncWithArgs(FuncWithArgs *from)
1950 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1952 Node_Copy(from, newnode, funcname);
1953 Node_Copy(from, newnode, funcargs);
1958 static InsertDefault *
1959 _copyInsertDefault(InsertDefault *from)
1961 InsertDefault *newnode = makeNode(InsertDefault);
1967 static ClosePortalStmt *
1968 _copyClosePortalStmt(ClosePortalStmt *from)
1970 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1972 if (from->portalname)
1973 newnode->portalname = pstrdup(from->portalname);
1978 static ClusterStmt *
1979 _copyClusterStmt(ClusterStmt *from)
1981 ClusterStmt *newnode = makeNode(ClusterStmt);
1983 Node_Copy(from, newnode, relation);
1984 if (from->indexname)
1985 newnode->indexname = pstrdup(from->indexname);
1991 _copyCopyStmt(CopyStmt *from)
1993 CopyStmt *newnode = makeNode(CopyStmt);
1995 newnode->binary = from->binary;
1996 Node_Copy(from, newnode, relation);
1997 newnode->oids = from->oids;
1998 newnode->direction = from->direction;
2000 newnode->filename = pstrdup(from->filename);
2001 if (from->delimiter)
2002 newnode->delimiter = pstrdup(from->delimiter);
2003 if (from->null_print)
2004 newnode->null_print = pstrdup(from->null_print);
2010 _copyCreateStmt(CreateStmt *from)
2012 CreateStmt *newnode = makeNode(CreateStmt);
2014 Node_Copy(from, newnode, relation);
2015 Node_Copy(from, newnode, tableElts);
2016 Node_Copy(from, newnode, inhRelations);
2017 Node_Copy(from, newnode, constraints);
2018 newnode->hasoids = from->hasoids;
2024 _copyDefineStmt(DefineStmt *from)
2026 DefineStmt *newnode = makeNode(DefineStmt);
2028 newnode->defType = from->defType;
2029 Node_Copy(from, newnode, defnames);
2030 Node_Copy(from, newnode, definition);
2036 _copyDropStmt(DropStmt *from)
2038 DropStmt *newnode = makeNode(DropStmt);
2040 Node_Copy(from, newnode, objects);
2041 newnode->removeType = from->removeType;
2042 newnode->behavior = from->behavior;
2047 static TruncateStmt *
2048 _copyTruncateStmt(TruncateStmt *from)
2050 TruncateStmt *newnode = makeNode(TruncateStmt);
2052 Node_Copy(from, newnode, relation);
2057 static CommentStmt *
2058 _copyCommentStmt(CommentStmt *from)
2060 CommentStmt *newnode = makeNode(CommentStmt);
2062 newnode->objtype = from->objtype;
2063 Node_Copy(from, newnode, objname);
2064 Node_Copy(from, newnode, objargs);
2066 newnode->comment = pstrdup(from->comment);
2072 _copyFetchStmt(FetchStmt *from)
2074 FetchStmt *newnode = makeNode(FetchStmt);
2076 newnode->direction = from->direction;
2077 newnode->howMany = from->howMany;
2078 newnode->portalname = pstrdup(from->portalname);
2079 newnode->ismove = from->ismove;
2085 _copyIndexStmt(IndexStmt *from)
2087 IndexStmt *newnode = makeNode(IndexStmt);
2089 newnode->idxname = pstrdup(from->idxname);
2090 Node_Copy(from, newnode, relation);
2091 newnode->accessMethod = pstrdup(from->accessMethod);
2092 Node_Copy(from, newnode, indexParams);
2093 Node_Copy(from, newnode, whereClause);
2094 Node_Copy(from, newnode, rangetable);
2095 newnode->unique = from->unique;
2096 newnode->primary = from->primary;
2101 static CreateFunctionStmt *
2102 _copyCreateFunctionStmt(CreateFunctionStmt *from)
2104 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
2106 newnode->replace = from->replace;
2107 Node_Copy(from, newnode, funcname);
2108 Node_Copy(from, newnode, argTypes);
2109 Node_Copy(from, newnode, returnType);
2110 Node_Copy(from, newnode, options);
2111 Node_Copy(from, newnode, withClause);
2116 static RemoveAggrStmt *
2117 _copyRemoveAggrStmt(RemoveAggrStmt *from)
2119 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
2121 Node_Copy(from, newnode, aggname);
2122 Node_Copy(from, newnode, aggtype);
2127 static RemoveFuncStmt *
2128 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2130 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2132 Node_Copy(from, newnode, funcname);
2133 Node_Copy(from, newnode, args);
2138 static RemoveOperStmt *
2139 _copyRemoveOperStmt(RemoveOperStmt *from)
2141 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2143 Node_Copy(from, newnode, opname);
2144 Node_Copy(from, newnode, args);
2150 _copyRenameStmt(RenameStmt *from)
2152 RenameStmt *newnode = makeNode(RenameStmt);
2154 Node_Copy(from, newnode, relation);
2156 newnode->oldname = pstrdup(from->oldname);
2158 newnode->newname = pstrdup(from->newname);
2159 newnode->renameType = from->renameType;
2165 _copyRuleStmt(RuleStmt *from)
2167 RuleStmt *newnode = makeNode(RuleStmt);
2169 Node_Copy(from, newnode, relation);
2170 newnode->rulename = pstrdup(from->rulename);
2171 Node_Copy(from, newnode, whereClause);
2172 newnode->event = from->event;
2173 newnode->instead = from->instead;
2174 Node_Copy(from, newnode, actions);
2180 _copyNotifyStmt(NotifyStmt *from)
2182 NotifyStmt *newnode = makeNode(NotifyStmt);
2184 Node_Copy(from, newnode, relation);
2190 _copyListenStmt(ListenStmt *from)
2192 ListenStmt *newnode = makeNode(ListenStmt);
2194 Node_Copy(from, newnode, relation);
2199 static UnlistenStmt *
2200 _copyUnlistenStmt(UnlistenStmt *from)
2202 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2204 Node_Copy(from, newnode, relation);
2209 static TransactionStmt *
2210 _copyTransactionStmt(TransactionStmt *from)
2212 TransactionStmt *newnode = makeNode(TransactionStmt);
2214 newnode->command = from->command;
2220 _copyViewStmt(ViewStmt *from)
2222 ViewStmt *newnode = makeNode(ViewStmt);
2224 Node_Copy(from, newnode, view);
2225 Node_Copy(from, newnode, aliases);
2226 Node_Copy(from, newnode, query);
2232 _copyLoadStmt(LoadStmt *from)
2234 LoadStmt *newnode = makeNode(LoadStmt);
2237 newnode->filename = pstrdup(from->filename);
2242 static CreateDomainStmt *
2243 _copyCreateDomainStmt(CreateDomainStmt *from)
2245 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2247 Node_Copy(from, newnode, domainname);
2248 Node_Copy(from, newnode, typename);
2249 Node_Copy(from, newnode, constraints);
2254 static CreatedbStmt *
2255 _copyCreatedbStmt(CreatedbStmt *from)
2257 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2260 newnode->dbname = pstrdup(from->dbname);
2261 Node_Copy(from, newnode, options);
2266 static AlterDatabaseSetStmt *
2267 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2269 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2272 newnode->dbname = pstrdup(from->dbname);
2274 newnode->variable = pstrdup(from->variable);
2275 Node_Copy(from, newnode, value);
2281 _copyDropdbStmt(DropdbStmt *from)
2283 DropdbStmt *newnode = makeNode(DropdbStmt);
2286 newnode->dbname = pstrdup(from->dbname);
2292 _copyVacuumStmt(VacuumStmt *from)
2294 VacuumStmt *newnode = makeNode(VacuumStmt);
2296 newnode->vacuum = from->vacuum;
2297 newnode->full = from->full;
2298 newnode->analyze = from->analyze;
2299 newnode->freeze = from->freeze;
2300 newnode->verbose = from->verbose;
2301 Node_Copy(from, newnode, relation);
2302 Node_Copy(from, newnode, va_cols);
2307 static ExplainStmt *
2308 _copyExplainStmt(ExplainStmt *from)
2310 ExplainStmt *newnode = makeNode(ExplainStmt);
2312 Node_Copy(from, newnode, query);
2313 newnode->verbose = from->verbose;
2314 newnode->analyze = from->analyze;
2319 static CreateSeqStmt *
2320 _copyCreateSeqStmt(CreateSeqStmt *from)
2322 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2324 Node_Copy(from, newnode, sequence);
2325 Node_Copy(from, newnode, options);
2330 static VariableSetStmt *
2331 _copyVariableSetStmt(VariableSetStmt *from)
2333 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2336 newnode->name = pstrdup(from->name);
2337 Node_Copy(from, newnode, args);
2338 newnode->is_local = from->is_local;
2343 static VariableShowStmt *
2344 _copyVariableShowStmt(VariableShowStmt *from)
2346 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2349 newnode->name = pstrdup(from->name);
2354 static VariableResetStmt *
2355 _copyVariableResetStmt(VariableResetStmt *from)
2357 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2360 newnode->name = pstrdup(from->name);
2365 static CreateTrigStmt *
2366 _copyCreateTrigStmt(CreateTrigStmt *from)
2368 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2371 newnode->trigname = pstrdup(from->trigname);
2372 Node_Copy(from, newnode, relation);
2373 Node_Copy(from, newnode, funcname);
2374 Node_Copy(from, newnode, args);
2375 newnode->before = from->before;
2376 newnode->row = from->row;
2377 memcpy(newnode->actions, from->actions, sizeof(from->actions));
2379 newnode->lang = pstrdup(from->lang);
2381 newnode->text = pstrdup(from->text);
2383 Node_Copy(from, newnode, attr);
2385 newnode->when = pstrdup(from->when);
2386 newnode->isconstraint = from->isconstraint;
2387 newnode->deferrable = from->deferrable;
2388 newnode->initdeferred = from->initdeferred;
2389 Node_Copy(from, newnode, constrrel);
2394 static DropPropertyStmt *
2395 _copyDropPropertyStmt(DropPropertyStmt *from)
2397 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2399 Node_Copy(from, newnode, relation);
2401 newnode->property = pstrdup(from->property);
2402 newnode->removeType = from->removeType;
2407 static CreatePLangStmt *
2408 _copyCreatePLangStmt(CreatePLangStmt *from)
2410 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2413 newnode->plname = pstrdup(from->plname);
2414 Node_Copy(from, newnode, plhandler);
2415 Node_Copy(from, newnode, plvalidator);
2416 if (from->plcompiler)
2417 newnode->plcompiler = pstrdup(from->plcompiler);
2418 newnode->pltrusted = from->pltrusted;
2423 static DropPLangStmt *
2424 _copyDropPLangStmt(DropPLangStmt *from)
2426 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2429 newnode->plname = pstrdup(from->plname);
2434 static CreateUserStmt *
2435 _copyCreateUserStmt(CreateUserStmt *from)
2437 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2440 newnode->user = pstrdup(from->user);
2441 Node_Copy(from, newnode, options);
2446 static AlterUserStmt *
2447 _copyAlterUserStmt(AlterUserStmt *from)
2449 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2452 newnode->user = pstrdup(from->user);
2453 Node_Copy(from, newnode, options);
2458 static AlterUserSetStmt *
2459 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2461 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2464 newnode->user = pstrdup(from->user);
2466 newnode->variable = pstrdup(from->variable);
2467 Node_Copy(from, newnode, value);
2472 static DropUserStmt *
2473 _copyDropUserStmt(DropUserStmt *from)
2475 DropUserStmt *newnode = makeNode(DropUserStmt);
2477 Node_Copy(from, newnode, users);
2483 _copyLockStmt(LockStmt *from)
2485 LockStmt *newnode = makeNode(LockStmt);
2487 Node_Copy(from, newnode, relations);
2489 newnode->mode = from->mode;
2494 static ConstraintsSetStmt *
2495 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2497 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2499 Node_Copy(from, newnode, constraints);
2500 newnode->deferred = from->deferred;
2505 static CreateGroupStmt *
2506 _copyCreateGroupStmt(CreateGroupStmt *from)
2508 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2511 newnode->name = pstrdup(from->name);
2512 Node_Copy(from, newnode, options);
2517 static AlterGroupStmt *
2518 _copyAlterGroupStmt(AlterGroupStmt *from)
2520 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2523 newnode->name = pstrdup(from->name);
2524 newnode->action = from->action;
2525 Node_Copy(from, newnode, listUsers);
2530 static DropGroupStmt *
2531 _copyDropGroupStmt(DropGroupStmt *from)
2533 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2536 newnode->name = pstrdup(from->name);
2541 static ReindexStmt *
2542 _copyReindexStmt(ReindexStmt *from)
2544 ReindexStmt *newnode = makeNode(ReindexStmt);
2546 newnode->reindexType = from->reindexType;
2547 Node_Copy(from, newnode, relation);
2549 newnode->name = pstrdup(from->name);
2550 newnode->force = from->force;
2551 newnode->all = from->all;
2556 static CreateSchemaStmt *
2557 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2559 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2561 newnode->schemaname = pstrdup(from->schemaname);
2563 newnode->authid = pstrdup(from->authid);
2564 Node_Copy(from, newnode, schemaElts);
2570 /* ****************************************************************
2571 * pg_list.h copy functions
2572 * ****************************************************************
2576 _copyValue(Value *from)
2578 Value *newnode = makeNode(Value);
2580 newnode->type = from->type;
2584 newnode->val.ival = from->val.ival;
2589 newnode->val.str = pstrdup(from->val.str);
2598 * copyObject returns a copy of the node or list. If it is a list, it
2599 * recursively copies its items.
2603 copyObject(void *from)
2610 switch (nodeTag(from))
2616 retval = _copyPlan(from);
2619 retval = _copyResult(from);
2622 retval = _copyAppend(from);
2625 retval = _copyScan(from);
2628 retval = _copySeqScan(from);
2631 retval = _copyIndexScan(from);
2634 retval = _copyTidScan(from);
2636 case T_SubqueryScan:
2637 retval = _copySubqueryScan(from);
2639 case T_FunctionScan:
2640 retval = _copyFunctionScan(from);
2643 retval = _copyJoin(from);
2646 retval = _copyNestLoop(from);
2649 retval = _copyMergeJoin(from);
2652 retval = _copyHashJoin(from);
2655 retval = _copyMaterial(from);
2658 retval = _copySort(from);
2661 retval = _copyGroup(from);
2664 retval = _copyAgg(from);
2667 retval = _copyUnique(from);
2670 retval = _copySetOp(from);
2673 retval = _copyLimit(from);
2676 retval = _copyHash(from);
2679 retval = _copySubPlan(from);
2686 retval = _copyResdom(from);
2689 retval = _copyFjoin(from);
2692 retval = _copyExpr(from);
2695 retval = _copyVar(from);
2698 retval = _copyOper(from);
2701 retval = _copyConst(from);
2704 retval = _copyParam(from);
2707 retval = _copyAggref(from);
2710 retval = _copySubLink(from);
2713 retval = _copyFunc(from);
2716 retval = _copyArrayRef(from);
2719 retval = _copyFieldSelect(from);
2722 retval = _copyRelabelType(from);
2725 retval = _copyRangeTblRef(from);
2728 retval = _copyFromExpr(from);
2731 retval = _copyJoinExpr(from);
2738 retval = _copyRelOptInfo(from);
2741 retval = _copyPath(from);
2744 retval = _copyIndexPath(from);
2747 retval = _copyTidPath(from);
2750 retval = _copyAppendPath(from);
2753 retval = _copyNestPath(from);
2756 retval = _copyMergePath(from);
2759 retval = _copyHashPath(from);
2762 retval = _copyPathKeyItem(from);
2764 case T_RestrictInfo:
2765 retval = _copyRestrictInfo(from);
2768 retval = _copyJoinInfo(from);
2771 retval = _copyStream(from);
2773 case T_IndexOptInfo:
2774 retval = _copyIndexOptInfo(from);
2784 retval = _copyValue(from);
2792 /* rather ugly coding for speed... */
2793 /* Note the input list cannot be NIL if we got here. */
2794 nl = makeList1(copyObject(lfirst(list)));
2797 foreach(l, lnext(list))
2799 lnext(nl) = makeList1(copyObject(lfirst(l)));
2809 retval = _copyQuery(from);
2812 retval = _copyInsertStmt(from);
2815 retval = _copyDeleteStmt(from);
2818 retval = _copyUpdateStmt(from);
2821 retval = _copySelectStmt(from);
2823 case T_SetOperationStmt:
2824 retval = _copySetOperationStmt(from);
2826 case T_AlterTableStmt:
2827 retval = _copyAlterTableStmt(from);
2830 retval = _copyGrantStmt(from);
2832 case T_ClosePortalStmt:
2833 retval = _copyClosePortalStmt(from);
2836 retval = _copyClusterStmt(from);
2839 retval = _copyCopyStmt(from);
2842 retval = _copyCreateStmt(from);
2845 retval = _copyDefineStmt(from);
2848 retval = _copyDropStmt(from);
2850 case T_TruncateStmt:
2851 retval = _copyTruncateStmt(from);
2854 retval = _copyCommentStmt(from);
2857 retval = _copyFetchStmt(from);
2860 retval = _copyIndexStmt(from);
2862 case T_CreateFunctionStmt:
2863 retval = _copyCreateFunctionStmt(from);
2865 case T_RemoveAggrStmt:
2866 retval = _copyRemoveAggrStmt(from);
2868 case T_RemoveFuncStmt:
2869 retval = _copyRemoveFuncStmt(from);
2871 case T_RemoveOperStmt:
2872 retval = _copyRemoveOperStmt(from);
2875 retval = _copyRenameStmt(from);
2878 retval = _copyRuleStmt(from);
2881 retval = _copyNotifyStmt(from);
2884 retval = _copyListenStmt(from);
2886 case T_UnlistenStmt:
2887 retval = _copyUnlistenStmt(from);
2889 case T_TransactionStmt:
2890 retval = _copyTransactionStmt(from);
2893 retval = _copyViewStmt(from);
2896 retval = _copyLoadStmt(from);
2898 case T_CreateDomainStmt:
2899 retval = _copyCreateDomainStmt(from);
2901 case T_CreatedbStmt:
2902 retval = _copyCreatedbStmt(from);
2904 case T_AlterDatabaseSetStmt:
2905 retval = _copyAlterDatabaseSetStmt(from);
2908 retval = _copyDropdbStmt(from);
2911 retval = _copyVacuumStmt(from);
2914 retval = _copyExplainStmt(from);
2916 case T_CreateSeqStmt:
2917 retval = _copyCreateSeqStmt(from);
2919 case T_VariableSetStmt:
2920 retval = _copyVariableSetStmt(from);
2922 case T_VariableShowStmt:
2923 retval = _copyVariableShowStmt(from);
2925 case T_VariableResetStmt:
2926 retval = _copyVariableResetStmt(from);
2928 case T_CreateTrigStmt:
2929 retval = _copyCreateTrigStmt(from);
2931 case T_DropPropertyStmt:
2932 retval = _copyDropPropertyStmt(from);
2934 case T_CreatePLangStmt:
2935 retval = _copyCreatePLangStmt(from);
2937 case T_DropPLangStmt:
2938 retval = _copyDropPLangStmt(from);
2940 case T_CreateUserStmt:
2941 retval = _copyCreateUserStmt(from);
2943 case T_AlterUserStmt:
2944 retval = _copyAlterUserStmt(from);
2946 case T_AlterUserSetStmt:
2947 retval = _copyAlterUserSetStmt(from);
2949 case T_DropUserStmt:
2950 retval = _copyDropUserStmt(from);
2953 retval = _copyLockStmt(from);
2955 case T_ConstraintsSetStmt:
2956 retval = _copyConstraintsSetStmt(from);
2958 case T_CreateGroupStmt:
2959 retval = _copyCreateGroupStmt(from);
2961 case T_AlterGroupStmt:
2962 retval = _copyAlterGroupStmt(from);
2964 case T_DropGroupStmt:
2965 retval = _copyDropGroupStmt(from);
2968 retval = _copyReindexStmt(from);
2970 case T_CheckPointStmt:
2971 retval = (void *) makeNode(CheckPointStmt);
2973 case T_CreateSchemaStmt:
2974 retval = _copyCreateSchemaStmt(from);
2978 retval = _copyAExpr(from);
2981 retval = _copyColumnRef(from);
2984 retval = _copyParamRef(from);
2987 retval = _copyAConst(from);
2990 retval = _copyIdent(from);
2993 retval = _copyFuncCall(from);
2996 retval = _copyAIndices(from);
2998 case T_ExprFieldSelect:
2999 retval = _copyExprFieldSelect(from);
3002 retval = _copyResTarget(from);
3005 retval = _copyTypeCast(from);
3008 retval = _copySortGroupBy(from);
3011 retval = _copyAlias(from);
3014 retval = _copyRangeVar(from);
3016 case T_RangeSubselect:
3017 retval = _copyRangeSubselect(from);
3019 case T_RangeFunction:
3020 retval = _copyRangeFunction(from);
3023 retval = _copyTypeName(from);
3026 retval = _copyIndexElem(from);
3029 retval = _copyColumnDef(from);
3032 retval = _copyConstraint(from);
3035 retval = _copyDefElem(from);
3038 retval = _copyTargetEntry(from);
3040 case T_RangeTblEntry:
3041 retval = _copyRangeTblEntry(from);
3044 retval = _copySortClause(from);
3047 retval = _copyGroupClause(from);
3050 retval = _copyCaseExpr(from);
3053 retval = _copyCaseWhen(from);
3056 retval = _copyNullTest(from);
3059 retval = _copyBooleanTest(from);
3061 case T_FkConstraint:
3062 retval = _copyFkConstraint(from);
3065 retval = _copyPrivGrantee(from);
3067 case T_FuncWithArgs:
3068 retval = _copyFuncWithArgs(from);
3070 case T_InsertDefault:
3071 retval = _copyInsertDefault(from);
3075 elog(ERROR, "copyObject: don't know how to copy node type %d",
3077 retval = from; /* keep compiler quiet */