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-2000, PostgreSQL, Inc
15 * Portions Copyright (c) 1994, Regents of the University of California
18 * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.124 2000/10/05 19:11:27 tgl Exp $
20 *-------------------------------------------------------------------------
25 #include "optimizer/clauses.h"
26 #include "optimizer/planmain.h"
27 #include "utils/acl.h"
32 * a macro to simplify calling of copyObject on the specified field
34 #define Node_Copy(from, newnode, field) \
35 ((newnode)->field = copyObject((from)->field))
40 * This copy function only copies the "cons-cells" of the list, not the
41 * pointed-to objects. (Use copyObject if you want a "deep" copy.)
43 * We also use this function for copying lists of integers, which is
44 * grotty but unlikely to break --- it could fail if sizeof(pointer)
45 * is less than sizeof(int), but I don't know any such machines...
47 * Note that copyObject will surely coredump if applied to a list
57 /* rather ugly coding for speed... */
61 newlist = nl = lcons(lfirst(list), NIL);
63 foreach(l, lnext(list))
65 lnext(nl) = lcons(lfirst(l), NIL);
71 /* ****************************************************************
72 * plannodes.h copy functions
73 * ****************************************************************
79 * This function copies the fields of the Plan node. It is used by
80 * all the copy functions for classes which inherit from Plan.
84 CopyPlanFields(Plan *from, Plan *newnode)
86 newnode->startup_cost = from->startup_cost;
87 newnode->total_cost = from->total_cost;
88 newnode->plan_rows = from->plan_rows;
89 newnode->plan_width = from->plan_width;
90 /* state is NOT copied */
91 Node_Copy(from, newnode, targetlist);
92 Node_Copy(from, newnode, qual);
93 Node_Copy(from, newnode, lefttree);
94 Node_Copy(from, newnode, righttree);
95 newnode->extParam = listCopy(from->extParam);
96 newnode->locParam = listCopy(from->locParam);
97 newnode->chgParam = listCopy(from->chgParam);
98 Node_Copy(from, newnode, initPlan);
99 /* subPlan list must point to subplans in the new subtree, not the old */
100 if (from->subPlan != NIL)
101 newnode->subPlan = nconc(pull_subplans((Node *) newnode->targetlist),
102 pull_subplans((Node *) newnode->qual));
104 newnode->subPlan = NIL;
105 newnode->nParamExec = from->nParamExec;
113 _copyPlan(Plan *from)
115 Plan *newnode = makeNode(Plan);
118 * copy the node superclass fields
121 CopyPlanFields(from, newnode);
132 _copyResult(Result *from)
134 Result *newnode = makeNode(Result);
137 * copy node superclass fields
140 CopyPlanFields((Plan *) from, (Plan *) newnode);
143 * copy remainder of node
146 Node_Copy(from, newnode, resconstantqual);
149 * We must add subplans in resconstantqual to the new plan's subPlan
152 if (from->plan.subPlan != NIL)
153 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
154 pull_subplans(newnode->resconstantqual));
164 _copyAppend(Append *from)
166 Append *newnode = makeNode(Append);
169 * copy node superclass fields
172 CopyPlanFields((Plan *) from, (Plan *) newnode);
175 * copy remainder of node
178 Node_Copy(from, newnode, appendplans);
179 newnode->inheritrelid = from->inheritrelid;
180 Node_Copy(from, newnode, inheritrtable);
189 * This function copies the fields of the Scan node. It is used by
190 * all the copy functions for classes which inherit from Scan.
194 CopyScanFields(Scan *from, Scan *newnode)
196 newnode->scanrelid = from->scanrelid;
205 _copyScan(Scan *from)
207 Scan *newnode = makeNode(Scan);
210 * copy node superclass fields
213 CopyPlanFields((Plan *) from, (Plan *) newnode);
214 CopyScanFields((Scan *) from, (Scan *) newnode);
224 _copySeqScan(SeqScan *from)
226 SeqScan *newnode = makeNode(SeqScan);
229 * copy node superclass fields
232 CopyPlanFields((Plan *) from, (Plan *) newnode);
233 CopyScanFields((Scan *) from, (Scan *) newnode);
243 _copyIndexScan(IndexScan *from)
245 IndexScan *newnode = makeNode(IndexScan);
248 * copy node superclass fields
251 CopyPlanFields((Plan *) from, (Plan *) newnode);
252 CopyScanFields((Scan *) from, (Scan *) newnode);
255 * copy remainder of node
258 newnode->indxid = listCopy(from->indxid);
259 Node_Copy(from, newnode, indxqual);
260 Node_Copy(from, newnode, indxqualorig);
261 newnode->indxorderdir = from->indxorderdir;
264 * We must add subplans in index quals to the new plan's subPlan list
266 if (from->scan.plan.subPlan != NIL)
268 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
269 pull_subplans((Node *) newnode->indxqual));
270 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
271 pull_subplans((Node *) newnode->indxqualorig));
282 _copyTidScan(TidScan *from)
284 TidScan *newnode = makeNode(TidScan);
287 * copy node superclass fields
290 CopyPlanFields((Plan *) from, (Plan *) newnode);
291 CopyScanFields((Scan *) from, (Scan *) newnode);
293 * copy remainder of node
296 newnode->needRescan = from->needRescan;
297 Node_Copy(from, newnode, tideval);
306 static SubqueryScan *
307 _copySubqueryScan(SubqueryScan *from)
309 SubqueryScan *newnode = makeNode(SubqueryScan);
312 * copy node superclass fields
315 CopyPlanFields((Plan *) from, (Plan *) newnode);
316 CopyScanFields((Scan *) from, (Scan *) newnode);
319 * copy remainder of node
322 Node_Copy(from, newnode, subplan);
331 * This function copies the fields of the Join node. It is used by
332 * all the copy functions for classes which inherit from Join.
336 CopyJoinFields(Join *from, Join *newnode)
338 newnode->jointype = from->jointype;
339 Node_Copy(from, newnode, joinqual);
340 /* subPlan list must point to subplans in the new subtree, not the old */
341 if (from->plan.subPlan != NIL)
342 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
343 pull_subplans((Node *) newnode->joinqual));
352 _copyJoin(Join *from)
354 Join *newnode = makeNode(Join);
357 * copy node superclass fields
360 CopyPlanFields((Plan *) from, (Plan *) newnode);
361 CopyJoinFields(from, newnode);
372 _copyNestLoop(NestLoop *from)
374 NestLoop *newnode = makeNode(NestLoop);
377 * copy node superclass fields
380 CopyPlanFields((Plan *) from, (Plan *) newnode);
381 CopyJoinFields((Join *) from, (Join *) newnode);
392 _copyMergeJoin(MergeJoin *from)
394 MergeJoin *newnode = makeNode(MergeJoin);
397 * copy node superclass fields
400 CopyPlanFields((Plan *) from, (Plan *) newnode);
401 CopyJoinFields((Join *) from, (Join *) newnode);
404 * copy remainder of node
407 Node_Copy(from, newnode, mergeclauses);
410 * We must add subplans in mergeclauses to the new plan's subPlan list
412 if (from->join.plan.subPlan != NIL)
413 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
414 pull_subplans((Node *) newnode->mergeclauses));
424 _copyHashJoin(HashJoin *from)
426 HashJoin *newnode = makeNode(HashJoin);
429 * copy node superclass fields
432 CopyPlanFields((Plan *) from, (Plan *) newnode);
433 CopyJoinFields((Join *) from, (Join *) newnode);
436 * copy remainder of node
439 Node_Copy(from, newnode, hashclauses);
440 newnode->hashjoinop = from->hashjoinop;
443 * We must add subplans in hashclauses to the new plan's subPlan list
445 if (from->join.plan.subPlan != NIL)
446 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
447 pull_subplans((Node *) newnode->hashclauses));
458 _copyMaterial(Material *from)
460 Material *newnode = makeNode(Material);
463 * copy node superclass fields
466 CopyPlanFields((Plan *) from, (Plan *) newnode);
477 _copySort(Sort *from)
479 Sort *newnode = makeNode(Sort);
482 * copy node superclass fields
485 CopyPlanFields((Plan *) from, (Plan *) newnode);
487 newnode->keycount = from->keycount;
498 _copyGroup(Group *from)
500 Group *newnode = makeNode(Group);
502 CopyPlanFields((Plan *) from, (Plan *) newnode);
504 newnode->tuplePerGroup = from->tuplePerGroup;
505 newnode->numCols = from->numCols;
506 newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
507 memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
519 Agg *newnode = makeNode(Agg);
521 CopyPlanFields((Plan *) from, (Plan *) newnode);
531 _copyGroupClause(GroupClause *from)
533 GroupClause *newnode = makeNode(GroupClause);
535 newnode->tleSortGroupRef = from->tleSortGroupRef;
536 newnode->sortop = from->sortop;
546 _copyUnique(Unique *from)
548 Unique *newnode = makeNode(Unique);
551 * copy node superclass fields
554 CopyPlanFields((Plan *) from, (Plan *) newnode);
557 * copy remainder of node
560 newnode->numCols = from->numCols;
561 newnode->uniqColIdx = palloc(from->numCols * sizeof(AttrNumber));
562 memcpy(newnode->uniqColIdx, from->uniqColIdx, from->numCols * sizeof(AttrNumber));
572 _copySetOp(SetOp *from)
574 SetOp *newnode = makeNode(SetOp);
577 * copy node superclass fields
580 CopyPlanFields((Plan *) from, (Plan *) newnode);
583 * copy remainder of node
586 newnode->cmd = from->cmd;
587 newnode->numCols = from->numCols;
588 newnode->dupColIdx = palloc(from->numCols * sizeof(AttrNumber));
589 memcpy(newnode->dupColIdx, from->dupColIdx, from->numCols * sizeof(AttrNumber));
590 newnode->flagColIdx = from->flagColIdx;
600 _copyHash(Hash *from)
602 Hash *newnode = makeNode(Hash);
605 * copy node superclass fields
608 CopyPlanFields((Plan *) from, (Plan *) newnode);
611 * copy remainder of node
614 Node_Copy(from, newnode, hashkey);
620 _copySubPlan(SubPlan *from)
622 SubPlan *newnode = makeNode(SubPlan);
624 Node_Copy(from, newnode, plan);
625 newnode->plan_id = from->plan_id;
626 Node_Copy(from, newnode, rtable);
627 newnode->setParam = listCopy(from->setParam);
628 newnode->parParam = listCopy(from->parParam);
629 Node_Copy(from, newnode, sublink);
631 /* do not copy execution state */
632 newnode->needShutdown = false;
633 newnode->curTuple = NULL;
638 /* ****************************************************************
639 * primnodes.h copy functions
640 * ****************************************************************
648 _copyResdom(Resdom *from)
650 Resdom *newnode = makeNode(Resdom);
652 newnode->resno = from->resno;
653 newnode->restype = from->restype;
654 newnode->restypmod = from->restypmod;
655 if (from->resname != NULL)
656 newnode->resname = pstrdup(from->resname);
657 newnode->ressortgroupref = from->ressortgroupref;
658 newnode->reskey = from->reskey;
659 newnode->reskeyop = from->reskeyop;
660 newnode->resjunk = from->resjunk;
666 _copyFjoin(Fjoin *from)
668 Fjoin *newnode = makeNode(Fjoin);
671 * copy node superclass fields
675 newnode->fj_initialized = from->fj_initialized;
676 newnode->fj_nNodes = from->fj_nNodes;
678 Node_Copy(from, newnode, fj_innerNode);
680 newnode->fj_results = (DatumPtr)
681 palloc((from->fj_nNodes) * sizeof(Datum));
682 memmove(from->fj_results,
684 (from->fj_nNodes) * sizeof(Datum));
686 newnode->fj_alwaysDone = (BoolPtr)
687 palloc((from->fj_nNodes) * sizeof(bool));
688 memmove(from->fj_alwaysDone,
689 newnode->fj_alwaysDone,
690 (from->fj_nNodes) * sizeof(bool));
701 _copyExpr(Expr *from)
703 Expr *newnode = makeNode(Expr);
706 * copy node superclass fields
709 newnode->typeOid = from->typeOid;
710 newnode->opType = from->opType;
712 Node_Copy(from, newnode, oper);
713 Node_Copy(from, newnode, args);
725 Var *newnode = makeNode(Var);
728 * copy remainder of node
731 newnode->varno = from->varno;
732 newnode->varattno = from->varattno;
733 newnode->vartype = from->vartype;
734 newnode->vartypmod = from->vartypmod;
735 newnode->varlevelsup = from->varlevelsup;
737 newnode->varnoold = from->varnoold;
738 newnode->varoattno = from->varoattno;
744 _copyAttr(Attr *from)
746 Attr *newnode = makeNode(Attr);
749 newnode->relname = pstrdup(from->relname);
750 Node_Copy(from, newnode, attrs);
760 _copyOper(Oper *from)
762 Oper *newnode = makeNode(Oper);
765 * copy remainder of node
768 newnode->opno = from->opno;
769 newnode->opid = from->opid;
770 newnode->opresulttype = from->opresulttype;
771 /* Do not copy the run-time state, if any */
772 newnode->op_fcache = NULL;
782 _copyConst(Const *from)
784 Const *newnode = makeNode(Const);
787 * copy remainder of node
790 newnode->consttype = from->consttype;
791 newnode->constlen = from->constlen;
793 if (from->constbyval || from->constisnull)
796 * passed by value so just copy the datum.
797 * Also, don't try to copy struct when value is null!
800 newnode->constvalue = from->constvalue;
805 * not passed by value. datum contains a pointer.
808 int length = from->constlen;
810 if (length == -1) /* variable-length type? */
811 length = VARSIZE(from->constvalue);
812 newnode->constvalue = PointerGetDatum(palloc(length));
813 memcpy(DatumGetPointer(newnode->constvalue),
814 DatumGetPointer(from->constvalue),
818 newnode->constisnull = from->constisnull;
819 newnode->constbyval = from->constbyval;
820 newnode->constisset = from->constisset;
821 newnode->constiscast = from->constiscast;
831 _copyParam(Param *from)
833 Param *newnode = makeNode(Param);
836 * copy remainder of node
839 newnode->paramkind = from->paramkind;
840 newnode->paramid = from->paramid;
842 if (from->paramname != NULL)
843 newnode->paramname = pstrdup(from->paramname);
844 newnode->paramtype = from->paramtype;
854 _copyFunc(Func *from)
856 Func *newnode = makeNode(Func);
859 * copy remainder of node
862 newnode->funcid = from->funcid;
863 newnode->functype = from->functype;
864 /* Do not copy the run-time state, if any */
865 newnode->func_fcache = NULL;
875 _copyAggref(Aggref *from)
877 Aggref *newnode = makeNode(Aggref);
880 * copy remainder of node
883 newnode->aggname = pstrdup(from->aggname);
884 newnode->basetype = from->basetype;
885 newnode->aggtype = from->aggtype;
886 Node_Copy(from, newnode, target);
887 newnode->aggstar = from->aggstar;
888 newnode->aggdistinct = from->aggdistinct;
889 newnode->aggno = from->aggno; /* probably not needed */
899 _copySubLink(SubLink *from)
901 SubLink *newnode = makeNode(SubLink);
904 * copy remainder of node
907 newnode->subLinkType = from->subLinkType;
908 newnode->useor = from->useor;
909 Node_Copy(from, newnode, lefthand);
910 Node_Copy(from, newnode, oper);
911 Node_Copy(from, newnode, subselect);
921 _copyFieldSelect(FieldSelect *from)
923 FieldSelect *newnode = makeNode(FieldSelect);
926 * copy remainder of node
929 Node_Copy(from, newnode, arg);
930 newnode->fieldnum = from->fieldnum;
931 newnode->resulttype = from->resulttype;
932 newnode->resulttypmod = from->resulttypmod;
942 _copyRelabelType(RelabelType *from)
944 RelabelType *newnode = makeNode(RelabelType);
947 * copy remainder of node
950 Node_Copy(from, newnode, arg);
951 newnode->resulttype = from->resulttype;
952 newnode->resulttypmod = from->resulttypmod;
958 _copyRangeTblRef(RangeTblRef *from)
960 RangeTblRef *newnode = makeNode(RangeTblRef);
962 newnode->rtindex = from->rtindex;
968 _copyFromExpr(FromExpr *from)
970 FromExpr *newnode = makeNode(FromExpr);
972 Node_Copy(from, newnode, fromlist);
973 Node_Copy(from, newnode, quals);
979 _copyJoinExpr(JoinExpr *from)
981 JoinExpr *newnode = makeNode(JoinExpr);
983 newnode->jointype = from->jointype;
984 newnode->isNatural = from->isNatural;
985 Node_Copy(from, newnode, larg);
986 Node_Copy(from, newnode, rarg);
987 Node_Copy(from, newnode, using);
988 Node_Copy(from, newnode, quals);
989 Node_Copy(from, newnode, alias);
990 Node_Copy(from, newnode, colnames);
991 Node_Copy(from, newnode, colvars);
1001 _copyCaseExpr(CaseExpr *from)
1003 CaseExpr *newnode = makeNode(CaseExpr);
1006 * copy remainder of node
1009 newnode->casetype = from->casetype;
1011 Node_Copy(from, newnode, arg);
1012 Node_Copy(from, newnode, args);
1013 Node_Copy(from, newnode, defresult);
1023 _copyCaseWhen(CaseWhen *from)
1025 CaseWhen *newnode = makeNode(CaseWhen);
1028 * copy remainder of node
1031 Node_Copy(from, newnode, expr);
1032 Node_Copy(from, newnode, result);
1038 _copyArrayRef(ArrayRef *from)
1040 ArrayRef *newnode = makeNode(ArrayRef);
1043 * copy remainder of node
1046 newnode->refattrlength = from->refattrlength;
1047 newnode->refelemlength = from->refelemlength;
1048 newnode->refelemtype = from->refelemtype;
1049 newnode->refelembyval = from->refelembyval;
1051 Node_Copy(from, newnode, refupperindexpr);
1052 Node_Copy(from, newnode, reflowerindexpr);
1053 Node_Copy(from, newnode, refexpr);
1054 Node_Copy(from, newnode, refassgnexpr);
1059 /* ****************************************************************
1060 * relation.h copy functions
1061 * ****************************************************************
1069 * when you change this, also make sure to fix up xfunc_copyRelOptInfo in
1070 * planner/path/xfunc.c accordingly!!!
1074 _copyRelOptInfo(RelOptInfo *from)
1076 RelOptInfo *newnode = makeNode(RelOptInfo);
1078 newnode->relids = listCopy(from->relids);
1080 newnode->rows = from->rows;
1081 newnode->width = from->width;
1083 Node_Copy(from, newnode, targetlist);
1084 Node_Copy(from, newnode, pathlist);
1085 /* XXX cheapest-path fields should point to members of pathlist? */
1086 Node_Copy(from, newnode, cheapest_startup_path);
1087 Node_Copy(from, newnode, cheapest_total_path);
1088 newnode->pruneable = from->pruneable;
1090 newnode->issubquery = from->issubquery;
1091 newnode->indexed = from->indexed;
1092 newnode->pages = from->pages;
1093 newnode->tuples = from->tuples;
1094 Node_Copy(from, newnode, subplan);
1096 Node_Copy(from, newnode, baserestrictinfo);
1097 newnode->baserestrictcost = from->baserestrictcost;
1098 newnode->outerjoinset = listCopy(from->outerjoinset);
1099 Node_Copy(from, newnode, joininfo);
1100 Node_Copy(from, newnode, innerjoin);
1109 static IndexOptInfo *
1110 _copyIndexOptInfo(IndexOptInfo *from)
1112 IndexOptInfo *newnode = makeNode(IndexOptInfo);
1116 newnode->indexoid = from->indexoid;
1117 newnode->pages = from->pages;
1118 newnode->tuples = from->tuples;
1120 if (from->classlist)
1122 for (len = 0; from->classlist[len] != 0; len++)
1124 newnode->classlist = (Oid *) palloc(sizeof(Oid) * (len + 1));
1125 for (i = 0; i < len; i++)
1126 newnode->classlist[i] = from->classlist[i];
1127 newnode->classlist[len] = 0;
1130 if (from->indexkeys)
1132 for (len = 0; from->indexkeys[len] != 0; len++)
1134 newnode->indexkeys = (int *) palloc(sizeof(int) * (len + 1));
1135 for (i = 0; i < len; i++)
1136 newnode->indexkeys[i] = from->indexkeys[i];
1137 newnode->indexkeys[len] = 0;
1142 for (len = 0; from->ordering[len] != 0; len++)
1144 newnode->ordering = (Oid *) palloc(sizeof(Oid) * (len + 1));
1145 for (i = 0; i < len; i++)
1146 newnode->ordering[i] = from->ordering[i];
1147 newnode->ordering[len] = 0;
1150 newnode->relam = from->relam;
1151 newnode->amcostestimate = from->amcostestimate;
1152 newnode->indproc = from->indproc;
1153 Node_Copy(from, newnode, indpred);
1154 newnode->lossy = from->lossy;
1162 * This function copies the fields of the Path node. It is used by
1163 * all the copy functions for classes which inherit from Path.
1167 CopyPathFields(Path *from, Path *newnode)
1171 * Modify the next line, since it causes the copying to cycle (i.e.
1172 * the parent points right back here! -- JMH, 7/7/92. Old version:
1173 * Node_Copy(from, newnode, parent);
1175 newnode->parent = from->parent;
1177 newnode->startup_cost = from->startup_cost;
1178 newnode->total_cost = from->total_cost;
1180 newnode->pathtype = from->pathtype;
1182 Node_Copy(from, newnode, pathkeys);
1190 _copyPath(Path *from)
1192 Path *newnode = makeNode(Path);
1194 CopyPathFields(from, newnode);
1204 _copyIndexPath(IndexPath *from)
1206 IndexPath *newnode = makeNode(IndexPath);
1209 * copy the node superclass fields
1212 CopyPathFields((Path *) from, (Path *) newnode);
1215 * copy remainder of node
1218 newnode->indexid = listCopy(from->indexid);
1219 Node_Copy(from, newnode, indexqual);
1220 newnode->indexscandir = from->indexscandir;
1221 newnode->joinrelids = listCopy(from->joinrelids);
1222 newnode->alljoinquals = from->alljoinquals;
1223 newnode->rows = from->rows;
1233 _copyTidPath(TidPath *from)
1235 TidPath *newnode = makeNode(TidPath);
1238 * copy the node superclass fields
1241 CopyPathFields((Path *) from, (Path *) newnode);
1244 * copy remainder of node
1247 Node_Copy(from, newnode, tideval);
1248 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1254 * CopyJoinPathFields
1256 * This function copies the fields of the JoinPath node. It is used by
1257 * all the copy functions for classes which inherit from JoinPath.
1261 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1263 newnode->jointype = from->jointype;
1264 Node_Copy(from, newnode, outerjoinpath);
1265 Node_Copy(from, newnode, innerjoinpath);
1266 Node_Copy(from, newnode, joinrestrictinfo);
1274 _copyNestPath(NestPath *from)
1276 NestPath *newnode = makeNode(NestPath);
1279 * copy the node superclass fields
1282 CopyPathFields((Path *) from, (Path *) newnode);
1283 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1293 _copyMergePath(MergePath *from)
1295 MergePath *newnode = makeNode(MergePath);
1298 * copy the node superclass fields
1301 CopyPathFields((Path *) from, (Path *) newnode);
1302 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1305 * copy the remainder of the node
1308 Node_Copy(from, newnode, path_mergeclauses);
1309 Node_Copy(from, newnode, outersortkeys);
1310 Node_Copy(from, newnode, innersortkeys);
1320 _copyHashPath(HashPath *from)
1322 HashPath *newnode = makeNode(HashPath);
1325 * copy the node superclass fields
1328 CopyPathFields((Path *) from, (Path *) newnode);
1329 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1332 * copy remainder of node
1335 Node_Copy(from, newnode, path_hashclauses);
1344 static PathKeyItem *
1345 _copyPathKeyItem(PathKeyItem *from)
1347 PathKeyItem *newnode = makeNode(PathKeyItem);
1350 * copy remainder of node
1353 Node_Copy(from, newnode, key);
1354 newnode->sortop = from->sortop;
1363 static RestrictInfo *
1364 _copyRestrictInfo(RestrictInfo *from)
1366 RestrictInfo *newnode = makeNode(RestrictInfo);
1369 * copy remainder of node
1372 Node_Copy(from, newnode, clause);
1373 newnode->ispusheddown = from->ispusheddown;
1374 Node_Copy(from, newnode, subclauseindices);
1375 newnode->mergejoinoperator = from->mergejoinoperator;
1376 newnode->left_sortop = from->left_sortop;
1377 newnode->right_sortop = from->right_sortop;
1378 newnode->hashjoinoperator = from->hashjoinoperator;
1388 _copyJoinInfo(JoinInfo *from)
1390 JoinInfo *newnode = makeNode(JoinInfo);
1393 * copy remainder of node
1396 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1397 Node_Copy(from, newnode, jinfo_restrictinfo);
1403 _copyIter(Iter *from)
1405 Iter *newnode = makeNode(Iter);
1407 Node_Copy(from, newnode, iterexpr);
1408 newnode->itertype = from->itertype;
1414 _copyStream(Stream *from)
1416 Stream *newnode = makeNode(Stream);
1418 newnode->pathptr = from->pathptr;
1419 newnode->cinfo = from->cinfo;
1420 newnode->clausetype = from->clausetype;
1422 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1424 Node_Copy(from, newnode, downstream);
1425 if (newnode->downstream)
1426 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1428 newnode->groupup = from->groupup;
1429 newnode->groupcost = from->groupcost;
1430 newnode->groupsel = from->groupsel;
1435 /* ****************************************************************
1436 * parsenodes.h copy functions
1437 * ****************************************************************
1440 static TargetEntry *
1441 _copyTargetEntry(TargetEntry *from)
1443 TargetEntry *newnode = makeNode(TargetEntry);
1445 Node_Copy(from, newnode, resdom);
1446 Node_Copy(from, newnode, fjoin);
1447 Node_Copy(from, newnode, expr);
1451 static RangeTblEntry *
1452 _copyRangeTblEntry(RangeTblEntry *from)
1454 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1457 newnode->relname = pstrdup(from->relname);
1458 newnode->relid = from->relid;
1459 Node_Copy(from, newnode, subquery);
1460 Node_Copy(from, newnode, alias);
1461 Node_Copy(from, newnode, eref);
1462 newnode->inh = from->inh;
1463 newnode->inFromCl = from->inFromCl;
1464 newnode->checkForRead = from->checkForRead;
1465 newnode->checkForWrite = from->checkForWrite;
1466 newnode->checkAsUser = from->checkAsUser;
1471 static FkConstraint *
1472 _copyFkConstraint(FkConstraint *from)
1474 FkConstraint *newnode = makeNode(FkConstraint);
1476 if (from->constr_name)
1477 newnode->constr_name = pstrdup(from->constr_name);
1478 if (from->pktable_name)
1479 newnode->pktable_name = pstrdup(from->pktable_name);
1480 Node_Copy(from, newnode, fk_attrs);
1481 Node_Copy(from, newnode, pk_attrs);
1482 if (from->match_type)
1483 newnode->match_type = pstrdup(from->match_type);
1484 newnode->actions = from->actions;
1485 newnode->deferrable = from->deferrable;
1486 newnode->initdeferred = from->initdeferred;
1492 _copySortClause(SortClause *from)
1494 SortClause *newnode = makeNode(SortClause);
1496 newnode->tleSortGroupRef = from->tleSortGroupRef;
1497 newnode->sortop = from->sortop;
1503 _copyAExpr(A_Expr *from)
1505 A_Expr *newnode = makeNode(A_Expr);
1507 newnode->oper = from->oper;
1509 newnode->opname = pstrdup(from->opname);
1510 Node_Copy(from, newnode, lexpr);
1511 Node_Copy(from, newnode, rexpr);
1517 _copyAConst(A_Const *from)
1519 A_Const *newnode = makeNode(A_Const);
1521 newnode->val = *((Value *) (copyObject(&(from->val))));
1522 Node_Copy(from, newnode, typename);
1528 _copyParamNo(ParamNo *from)
1530 ParamNo *newnode = makeNode(ParamNo);
1532 newnode->number = from->number;
1533 Node_Copy(from, newnode, typename);
1534 Node_Copy(from, newnode, indirection);
1540 _copyIdent(Ident *from)
1542 Ident *newnode = makeNode(Ident);
1545 newnode->name = pstrdup(from->name);
1546 Node_Copy(from, newnode, indirection);
1547 newnode->isRel = from->isRel;
1553 _copyFuncCall(FuncCall *from)
1555 FuncCall *newnode = makeNode(FuncCall);
1558 newnode->funcname = pstrdup(from->funcname);
1559 Node_Copy(from, newnode, args);
1560 newnode->agg_star = from->agg_star;
1561 newnode->agg_distinct = from->agg_distinct;
1567 _copyAIndices(A_Indices *from)
1569 A_Indices *newnode = makeNode(A_Indices);
1571 Node_Copy(from, newnode, lidx);
1572 Node_Copy(from, newnode, uidx);
1578 _copyResTarget(ResTarget *from)
1580 ResTarget *newnode = makeNode(ResTarget);
1583 newnode->name = pstrdup(from->name);
1584 Node_Copy(from, newnode, indirection);
1585 Node_Copy(from, newnode, val);
1591 _copyTypeName(TypeName *from)
1593 TypeName *newnode = makeNode(TypeName);
1596 newnode->name = pstrdup(from->name);
1597 newnode->timezone = from->timezone;
1598 newnode->setof = from->setof;
1599 newnode->typmod = from->typmod;
1600 Node_Copy(from, newnode, arrayBounds);
1605 static SortGroupBy *
1606 _copySortGroupBy(SortGroupBy *from)
1608 SortGroupBy *newnode = makeNode(SortGroupBy);
1611 newnode->useOp = pstrdup(from->useOp);
1612 Node_Copy(from, newnode, node);
1618 _copyRangeVar(RangeVar *from)
1620 RangeVar *newnode = makeNode(RangeVar);
1623 newnode->relname = pstrdup(from->relname);
1624 newnode->inh = from->inh;
1625 Node_Copy(from, newnode, name);
1630 static RangeSubselect *
1631 _copyRangeSubselect(RangeSubselect *from)
1633 RangeSubselect *newnode = makeNode(RangeSubselect);
1635 Node_Copy(from, newnode, subquery);
1636 Node_Copy(from, newnode, name);
1642 _copyTypeCast(TypeCast *from)
1644 TypeCast *newnode = makeNode(TypeCast);
1646 Node_Copy(from, newnode, arg);
1647 Node_Copy(from, newnode, typename);
1653 _copyIndexElem(IndexElem *from)
1655 IndexElem *newnode = makeNode(IndexElem);
1658 newnode->name = pstrdup(from->name);
1659 Node_Copy(from, newnode, args);
1661 newnode->class = pstrdup(from->class);
1667 _copyColumnDef(ColumnDef *from)
1669 ColumnDef *newnode = makeNode(ColumnDef);
1672 newnode->colname = pstrdup(from->colname);
1673 Node_Copy(from, newnode, typename);
1674 newnode->is_not_null = from->is_not_null;
1675 newnode->is_sequence = from->is_sequence;
1676 Node_Copy(from, newnode, raw_default);
1677 if (from->cooked_default)
1678 newnode->cooked_default = pstrdup(from->cooked_default);
1679 Node_Copy(from, newnode, constraints);
1685 _copyConstraint(Constraint *from)
1687 Constraint *newnode = makeNode(Constraint);
1689 newnode->contype = from->contype;
1691 newnode->name = pstrdup(from->name);
1692 Node_Copy(from, newnode, raw_expr);
1693 if (from->cooked_expr)
1694 newnode->cooked_expr = pstrdup(from->cooked_expr);
1695 Node_Copy(from, newnode, keys);
1701 _copyDefElem(DefElem *from)
1703 DefElem *newnode = makeNode(DefElem);
1706 newnode->defname = pstrdup(from->defname);
1707 Node_Copy(from, newnode, arg);
1713 _copyQuery(Query *from)
1715 Query *newnode = makeNode(Query);
1717 newnode->commandType = from->commandType;
1718 Node_Copy(from, newnode, utilityStmt);
1719 newnode->resultRelation = from->resultRelation;
1721 newnode->into = pstrdup(from->into);
1722 newnode->isPortal = from->isPortal;
1723 newnode->isBinary = from->isBinary;
1724 newnode->isTemp = from->isTemp;
1725 newnode->hasAggs = from->hasAggs;
1726 newnode->hasSubLinks = from->hasSubLinks;
1728 Node_Copy(from, newnode, rtable);
1729 Node_Copy(from, newnode, jointree);
1731 newnode->rowMarks = listCopy(from->rowMarks);
1733 Node_Copy(from, newnode, targetList);
1735 Node_Copy(from, newnode, groupClause);
1736 Node_Copy(from, newnode, havingQual);
1737 Node_Copy(from, newnode, distinctClause);
1738 Node_Copy(from, newnode, sortClause);
1740 Node_Copy(from, newnode, limitOffset);
1741 Node_Copy(from, newnode, limitCount);
1743 Node_Copy(from, newnode, setOperations);
1746 * We do not copy the planner internal fields: base_rel_list,
1747 * join_rel_list, equi_key_list, query_pathkeys. Not entirely clear if
1755 _copyInsertStmt(InsertStmt *from)
1757 InsertStmt *newnode = makeNode(InsertStmt);
1760 newnode->relname = pstrdup(from->relname);
1761 Node_Copy(from, newnode, cols);
1762 Node_Copy(from, newnode, targetList);
1763 Node_Copy(from, newnode, selectStmt);
1769 _copyDeleteStmt(DeleteStmt *from)
1771 DeleteStmt *newnode = makeNode(DeleteStmt);
1774 newnode->relname = pstrdup(from->relname);
1775 Node_Copy(from, newnode, whereClause);
1776 newnode->inh = from->inh;
1782 _copyUpdateStmt(UpdateStmt *from)
1784 UpdateStmt *newnode = makeNode(UpdateStmt);
1787 newnode->relname = pstrdup(from->relname);
1788 Node_Copy(from, newnode, targetList);
1789 Node_Copy(from, newnode, whereClause);
1790 Node_Copy(from, newnode, fromClause);
1791 newnode->inh = from->inh;
1797 _copySelectStmt(SelectStmt *from)
1799 SelectStmt *newnode = makeNode(SelectStmt);
1801 Node_Copy(from, newnode, distinctClause);
1803 newnode->into = pstrdup(from->into);
1804 Node_Copy(from, newnode, targetList);
1805 Node_Copy(from, newnode, fromClause);
1806 Node_Copy(from, newnode, whereClause);
1807 Node_Copy(from, newnode, groupClause);
1808 Node_Copy(from, newnode, havingClause);
1809 Node_Copy(from, newnode, sortClause);
1810 if (from->portalname)
1811 newnode->portalname = pstrdup(from->portalname);
1812 newnode->binary = from->binary;
1813 newnode->istemp = from->istemp;
1814 Node_Copy(from, newnode, limitOffset);
1815 Node_Copy(from, newnode, limitCount);
1816 Node_Copy(from, newnode, forUpdate);
1821 static SetOperationStmt *
1822 _copySetOperationStmt(SetOperationStmt *from)
1824 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1826 newnode->op = from->op;
1827 newnode->all = from->all;
1828 Node_Copy(from, newnode, larg);
1829 Node_Copy(from, newnode, rarg);
1830 newnode->colTypes = listCopy(from->colTypes);
1835 static AlterTableStmt *
1836 _copyAlterTableStmt(AlterTableStmt *from)
1838 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1840 newnode->subtype = from->subtype;
1842 newnode->relname = pstrdup(from->relname);
1843 newnode->inh = from->inh;
1845 newnode->name = pstrdup(from->name);
1846 Node_Copy(from, newnode, def);
1847 newnode->behavior = from->behavior;
1852 static ChangeACLStmt *
1853 _copyChangeACLStmt(ChangeACLStmt *from)
1855 ChangeACLStmt *newnode = makeNode(ChangeACLStmt);
1859 newnode->aclitem = (struct AclItem *) palloc(sizeof(struct AclItem));
1860 memcpy(newnode->aclitem, from->aclitem, sizeof(struct AclItem));
1862 newnode->modechg = from->modechg;
1863 Node_Copy(from, newnode, relNames);
1868 static ClosePortalStmt *
1869 _copyClosePortalStmt(ClosePortalStmt *from)
1871 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1873 if (from->portalname)
1874 newnode->portalname = pstrdup(from->portalname);
1879 static ClusterStmt *
1880 _copyClusterStmt(ClusterStmt *from)
1882 ClusterStmt *newnode = makeNode(ClusterStmt);
1885 newnode->relname = pstrdup(from->relname);
1886 if (from->indexname)
1887 newnode->indexname = pstrdup(from->indexname);
1893 _copyCopyStmt(CopyStmt *from)
1895 CopyStmt *newnode = makeNode(CopyStmt);
1897 newnode->binary = from->binary;
1899 newnode->relname = pstrdup(from->relname);
1900 newnode->oids = from->oids;
1901 newnode->direction = from->direction;
1903 newnode->filename = pstrdup(from->filename);
1904 if (from->delimiter)
1905 newnode->delimiter = pstrdup(from->delimiter);
1906 if (from->null_print)
1907 newnode->null_print = pstrdup(from->null_print);
1913 _copyCreateStmt(CreateStmt *from)
1915 CreateStmt *newnode = makeNode(CreateStmt);
1917 newnode->istemp = from->istemp;
1918 newnode->relname = pstrdup(from->relname);
1919 Node_Copy(from, newnode, tableElts);
1920 Node_Copy(from, newnode, inhRelnames);
1921 Node_Copy(from, newnode, constraints);
1926 static VersionStmt *
1927 _copyVersionStmt(VersionStmt *from)
1929 VersionStmt *newnode = makeNode(VersionStmt);
1931 newnode->relname = pstrdup(from->relname);
1932 newnode->direction = from->direction;
1933 newnode->fromRelname = pstrdup(from->fromRelname);
1934 newnode->date = pstrdup(from->date);
1940 _copyDefineStmt(DefineStmt *from)
1942 DefineStmt *newnode = makeNode(DefineStmt);
1944 newnode->defType = from->defType;
1945 newnode->defname = pstrdup(from->defname);
1946 Node_Copy(from, newnode, definition);
1952 _copyDropStmt(DropStmt *from)
1954 DropStmt *newnode = makeNode(DropStmt);
1956 Node_Copy(from, newnode, relNames);
1957 newnode->sequence = from->sequence;
1962 static TruncateStmt *
1963 _copyTruncateStmt(TruncateStmt *from)
1965 TruncateStmt *newnode = makeNode(TruncateStmt);
1967 newnode->relName = pstrdup(from->relName);
1972 static CommentStmt *
1973 _copyCommentStmt(CommentStmt *from)
1975 CommentStmt *newnode = makeNode(CommentStmt);
1977 newnode->objtype = from->objtype;
1978 newnode->objname = pstrdup(from->objname);
1979 if (from->objproperty)
1980 newnode->objproperty = pstrdup(from->objproperty);
1981 Node_Copy(from, newnode, objlist);
1982 newnode->comment = pstrdup(from->comment);
1988 _copyExtendStmt(ExtendStmt *from)
1990 ExtendStmt *newnode = makeNode(ExtendStmt);
1992 newnode->idxname = pstrdup(from->idxname);
1993 Node_Copy(from, newnode, whereClause);
1994 Node_Copy(from, newnode, rangetable);
2000 _copyFetchStmt(FetchStmt *from)
2002 FetchStmt *newnode = makeNode(FetchStmt);
2004 newnode->direction = from->direction;
2005 newnode->howMany = from->howMany;
2006 newnode->portalname = pstrdup(from->portalname);
2007 newnode->ismove = from->ismove;
2013 _copyIndexStmt(IndexStmt *from)
2015 IndexStmt *newnode = makeNode(IndexStmt);
2017 newnode->idxname = pstrdup(from->idxname);
2018 newnode->relname = pstrdup(from->relname);
2019 newnode->accessMethod = pstrdup(from->accessMethod);
2020 Node_Copy(from, newnode, indexParams);
2021 Node_Copy(from, newnode, withClause);
2022 Node_Copy(from, newnode, whereClause);
2023 Node_Copy(from, newnode, rangetable);
2024 newnode->unique = from->unique;
2025 newnode->primary = from->primary;
2030 static ProcedureStmt *
2031 _copyProcedureStmt(ProcedureStmt *from)
2033 ProcedureStmt *newnode = makeNode(ProcedureStmt);
2035 newnode->funcname = pstrdup(from->funcname);
2036 Node_Copy(from, newnode, defArgs);
2037 Node_Copy(from, newnode, returnType);
2038 Node_Copy(from, newnode, withClause);
2039 Node_Copy(from, newnode, as);
2040 newnode->language = pstrdup(from->language);
2045 static RemoveAggrStmt *
2046 _copyRemoveAggrStmt(RemoveAggrStmt *from)
2048 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
2050 newnode->aggname = pstrdup(from->aggname);
2051 newnode->aggtype = pstrdup(from->aggtype);
2056 static RemoveFuncStmt *
2057 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2059 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2061 newnode->funcname = pstrdup(from->funcname);
2062 Node_Copy(from, newnode, args);
2067 static RemoveOperStmt *
2068 _copyRemoveOperStmt(RemoveOperStmt *from)
2070 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2072 newnode->opname = pstrdup(from->opname);
2073 Node_Copy(from, newnode, args);
2079 _copyRemoveStmt(RemoveStmt *from)
2081 RemoveStmt *newnode = makeNode(RemoveStmt);
2083 newnode->removeType = from->removeType;
2084 newnode->name = pstrdup(from->name);
2090 _copyRenameStmt(RenameStmt *from)
2092 RenameStmt *newnode = makeNode(RenameStmt);
2094 newnode->relname = pstrdup(from->relname);
2095 newnode->inh = from->inh;
2097 newnode->column = pstrdup(from->column);
2099 newnode->newname = pstrdup(from->newname);
2105 _copyRuleStmt(RuleStmt *from)
2107 RuleStmt *newnode = makeNode(RuleStmt);
2109 newnode->rulename = pstrdup(from->rulename);
2110 Node_Copy(from, newnode, whereClause);
2111 newnode->event = from->event;
2112 Node_Copy(from, newnode, object);
2113 newnode->instead = from->instead;
2114 Node_Copy(from, newnode, actions);
2120 _copyNotifyStmt(NotifyStmt *from)
2122 NotifyStmt *newnode = makeNode(NotifyStmt);
2125 newnode->relname = pstrdup(from->relname);
2131 _copyListenStmt(ListenStmt *from)
2133 ListenStmt *newnode = makeNode(ListenStmt);
2136 newnode->relname = pstrdup(from->relname);
2141 static UnlistenStmt *
2142 _copyUnlistenStmt(UnlistenStmt *from)
2144 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2147 newnode->relname = pstrdup(from->relname);
2152 static TransactionStmt *
2153 _copyTransactionStmt(TransactionStmt *from)
2155 TransactionStmt *newnode = makeNode(TransactionStmt);
2157 newnode->command = from->command;
2163 _copyViewStmt(ViewStmt *from)
2165 ViewStmt *newnode = makeNode(ViewStmt);
2168 newnode->viewname = pstrdup(from->viewname);
2169 Node_Copy(from, newnode, aliases);
2170 Node_Copy(from, newnode, query);
2176 _copyLoadStmt(LoadStmt *from)
2178 LoadStmt *newnode = makeNode(LoadStmt);
2181 newnode->filename = pstrdup(from->filename);
2186 static CreatedbStmt *
2187 _copyCreatedbStmt(CreatedbStmt *from)
2189 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2192 newnode->dbname = pstrdup(from->dbname);
2194 newnode->dbpath = pstrdup(from->dbpath);
2195 newnode->encoding = from->encoding;
2201 _copyDropdbStmt(DropdbStmt *from)
2203 DropdbStmt *newnode = makeNode(DropdbStmt);
2206 newnode->dbname = pstrdup(from->dbname);
2212 _copyVacuumStmt(VacuumStmt *from)
2214 VacuumStmt *newnode = makeNode(VacuumStmt);
2216 newnode->verbose = from->verbose;
2217 newnode->analyze = from->analyze;
2219 newnode->vacrel = pstrdup(from->vacrel);
2220 Node_Copy(from, newnode, va_spec);
2225 static ExplainStmt *
2226 _copyExplainStmt(ExplainStmt *from)
2228 ExplainStmt *newnode = makeNode(ExplainStmt);
2230 Node_Copy(from, newnode, query);
2231 newnode->verbose = from->verbose;
2236 static CreateSeqStmt *
2237 _copyCreateSeqStmt(CreateSeqStmt *from)
2239 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2242 newnode->seqname = pstrdup(from->seqname);
2243 Node_Copy(from, newnode, options);
2248 static VariableSetStmt *
2249 _copyVariableSetStmt(VariableSetStmt *from)
2251 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2254 newnode->name = pstrdup(from->name);
2256 newnode->value = pstrdup(from->value);
2261 static VariableShowStmt *
2262 _copyVariableShowStmt(VariableShowStmt *from)
2264 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2267 newnode->name = pstrdup(from->name);
2272 static VariableResetStmt *
2273 _copyVariableResetStmt(VariableResetStmt *from)
2275 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2278 newnode->name = pstrdup(from->name);
2283 static CreateTrigStmt *
2284 _copyCreateTrigStmt(CreateTrigStmt *from)
2286 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2289 newnode->trigname = pstrdup(from->trigname);
2291 newnode->relname = pstrdup(from->relname);
2293 newnode->funcname = pstrdup(from->funcname);
2294 Node_Copy(from, newnode, args);
2295 newnode->before = from->before;
2296 newnode->row = from->row;
2297 memcpy(newnode->actions, from->actions, sizeof(from->actions));
2299 newnode->lang = pstrdup(from->lang);
2301 newnode->text = pstrdup(from->text);
2302 Node_Copy(from, newnode, attr);
2304 newnode->when = pstrdup(from->when);
2305 newnode->isconstraint = from->isconstraint;
2306 newnode->deferrable = from->deferrable;
2307 newnode->initdeferred = from->initdeferred;
2308 if (from->constrrelname)
2309 newnode->constrrelname = pstrdup(from->constrrelname);
2314 static DropTrigStmt *
2315 _copyDropTrigStmt(DropTrigStmt *from)
2317 DropTrigStmt *newnode = makeNode(DropTrigStmt);
2320 newnode->trigname = pstrdup(from->trigname);
2322 newnode->relname = pstrdup(from->relname);
2327 static CreatePLangStmt *
2328 _copyCreatePLangStmt(CreatePLangStmt *from)
2330 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2333 newnode->plname = pstrdup(from->plname);
2334 if (from->plhandler)
2335 newnode->plhandler = pstrdup(from->plhandler);
2336 if (from->plcompiler)
2337 newnode->plcompiler = pstrdup(from->plcompiler);
2338 newnode->pltrusted = from->pltrusted;
2343 static DropPLangStmt *
2344 _copyDropPLangStmt(DropPLangStmt *from)
2346 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2349 newnode->plname = pstrdup(from->plname);
2354 static CreateUserStmt *
2355 _copyCreateUserStmt(CreateUserStmt *from)
2357 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2360 newnode->user = pstrdup(from->user);
2362 newnode->password = pstrdup(from->password);
2363 newnode->sysid = from->sysid;
2364 newnode->createdb = from->createdb;
2365 newnode->createuser = from->createuser;
2366 Node_Copy(from, newnode, groupElts);
2367 if (from->validUntil)
2368 newnode->validUntil = pstrdup(from->validUntil);
2373 static AlterUserStmt *
2374 _copyAlterUserStmt(AlterUserStmt *from)
2376 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2379 newnode->user = pstrdup(from->user);
2381 newnode->password = pstrdup(from->password);
2382 newnode->createdb = from->createdb;
2383 newnode->createuser = from->createuser;
2384 if (from->validUntil)
2385 newnode->validUntil = pstrdup(from->validUntil);
2390 static DropUserStmt *
2391 _copyDropUserStmt(DropUserStmt *from)
2393 DropUserStmt *newnode = makeNode(DropUserStmt);
2395 Node_Copy(from, newnode, users);
2401 _copyLockStmt(LockStmt *from)
2403 LockStmt *newnode = makeNode(LockStmt);
2406 newnode->relname = pstrdup(from->relname);
2407 newnode->mode = from->mode;
2412 static ConstraintsSetStmt *
2413 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2415 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2417 Node_Copy(from, newnode, constraints);
2418 newnode->deferred = from->deferred;
2423 static CreateGroupStmt *
2424 _copyCreateGroupStmt(CreateGroupStmt *from)
2426 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2429 newnode->name = pstrdup(from->name);
2430 newnode->sysid = from->sysid;
2431 Node_Copy(from, newnode, initUsers);
2436 static AlterGroupStmt *
2437 _copyAlterGroupStmt(AlterGroupStmt *from)
2439 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2442 newnode->name = pstrdup(from->name);
2443 newnode->action = from->action;
2444 newnode->sysid = from->sysid;
2445 Node_Copy(from, newnode, listUsers);
2450 static DropGroupStmt *
2451 _copyDropGroupStmt(DropGroupStmt *from)
2453 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2456 newnode->name = pstrdup(from->name);
2461 static ReindexStmt *
2462 _copyReindexStmt(ReindexStmt *from)
2464 ReindexStmt *newnode = makeNode(ReindexStmt);
2466 newnode->reindexType = from->reindexType;
2468 newnode->name = pstrdup(from->name);
2469 newnode->force = from->force;
2470 newnode->all = from->all;
2475 static SetSessionStmt *
2476 _copySetSessionStmt(SetSessionStmt *from)
2478 SetSessionStmt *newnode = makeNode(SetSessionStmt);
2480 Node_Copy(from, newnode, args);
2486 /* ****************************************************************
2487 * pg_list.h copy functions
2488 * ****************************************************************
2492 _copyValue(Value *from)
2494 Value *newnode = makeNode(Value);
2496 newnode->type = from->type;
2500 newnode->val.ival = from->val.ival;
2504 newnode->val.str = pstrdup(from->val.str);
2513 * copyObject returns a copy of the node or list. If it is a list, it
2514 * recursively copies its items.
2518 copyObject(void *from)
2525 switch (nodeTag(from))
2532 retval = _copyPlan(from);
2535 retval = _copyResult(from);
2538 retval = _copyAppend(from);
2541 retval = _copyScan(from);
2544 retval = _copySeqScan(from);
2547 retval = _copyIndexScan(from);
2550 retval = _copyTidScan(from);
2552 case T_SubqueryScan:
2553 retval = _copySubqueryScan(from);
2556 retval = _copyJoin(from);
2559 retval = _copyNestLoop(from);
2562 retval = _copyMergeJoin(from);
2565 retval = _copyHashJoin(from);
2568 retval = _copyMaterial(from);
2571 retval = _copySort(from);
2574 retval = _copyGroup(from);
2577 retval = _copyAgg(from);
2580 retval = _copyUnique(from);
2583 retval = _copySetOp(from);
2586 retval = _copyHash(from);
2589 retval = _copySubPlan(from);
2596 retval = _copyResdom(from);
2599 retval = _copyFjoin(from);
2602 retval = _copyExpr(from);
2605 retval = _copyVar(from);
2608 retval = _copyOper(from);
2611 retval = _copyConst(from);
2614 retval = _copyParam(from);
2617 retval = _copyAggref(from);
2620 retval = _copySubLink(from);
2623 retval = _copyFunc(from);
2626 retval = _copyArrayRef(from);
2629 retval = _copyIter(from);
2632 retval = _copyFieldSelect(from);
2635 retval = _copyRelabelType(from);
2638 retval = _copyRangeTblRef(from);
2641 retval = _copyFromExpr(from);
2644 retval = _copyJoinExpr(from);
2651 retval = _copyRelOptInfo(from);
2654 retval = _copyPath(from);
2657 retval = _copyIndexPath(from);
2660 retval = _copyTidPath(from);
2663 retval = _copyNestPath(from);
2666 retval = _copyMergePath(from);
2669 retval = _copyHashPath(from);
2672 retval = _copyPathKeyItem(from);
2674 case T_RestrictInfo:
2675 retval = _copyRestrictInfo(from);
2678 retval = _copyJoinInfo(from);
2681 retval = _copyStream(from);
2683 case T_IndexOptInfo:
2684 retval = _copyIndexOptInfo(from);
2693 retval = _copyValue(from);
2701 /* rather ugly coding for speed... */
2702 /* Note the input list cannot be NIL if we got here. */
2703 nl = lcons(copyObject(lfirst(list)), NIL);
2706 foreach(l, lnext(list))
2708 lnext(nl) = lcons(copyObject(lfirst(l)), NIL);
2718 retval = _copyQuery(from);
2721 retval = _copyInsertStmt(from);
2724 retval = _copyDeleteStmt(from);
2727 retval = _copyUpdateStmt(from);
2730 retval = _copySelectStmt(from);
2732 case T_SetOperationStmt:
2733 retval = _copySetOperationStmt(from);
2735 case T_AlterTableStmt:
2736 retval = _copyAlterTableStmt(from);
2738 case T_ChangeACLStmt:
2739 retval = _copyChangeACLStmt(from);
2741 case T_ClosePortalStmt:
2742 retval = _copyClosePortalStmt(from);
2745 retval = _copyClusterStmt(from);
2748 retval = _copyCopyStmt(from);
2751 retval = _copyCreateStmt(from);
2754 retval = _copyVersionStmt(from);
2757 retval = _copyDefineStmt(from);
2760 retval = _copyDropStmt(from);
2762 case T_TruncateStmt:
2763 retval = _copyTruncateStmt(from);
2766 retval = _copyCommentStmt(from);
2769 retval = _copyExtendStmt(from);
2772 retval = _copyFetchStmt(from);
2775 retval = _copyIndexStmt(from);
2777 case T_ProcedureStmt:
2778 retval = _copyProcedureStmt(from);
2780 case T_RemoveAggrStmt:
2781 retval = _copyRemoveAggrStmt(from);
2783 case T_RemoveFuncStmt:
2784 retval = _copyRemoveFuncStmt(from);
2786 case T_RemoveOperStmt:
2787 retval = _copyRemoveOperStmt(from);
2790 retval = _copyRemoveStmt(from);
2793 retval = _copyRenameStmt(from);
2796 retval = _copyRuleStmt(from);
2799 retval = _copyNotifyStmt(from);
2802 retval = _copyListenStmt(from);
2804 case T_UnlistenStmt:
2805 retval = _copyUnlistenStmt(from);
2807 case T_TransactionStmt:
2808 retval = _copyTransactionStmt(from);
2811 retval = _copyViewStmt(from);
2814 retval = _copyLoadStmt(from);
2816 case T_CreatedbStmt:
2817 retval = _copyCreatedbStmt(from);
2820 retval = _copyDropdbStmt(from);
2823 retval = _copyVacuumStmt(from);
2826 retval = _copyExplainStmt(from);
2828 case T_CreateSeqStmt:
2829 retval = _copyCreateSeqStmt(from);
2831 case T_VariableSetStmt:
2832 retval = _copyVariableSetStmt(from);
2834 case T_VariableShowStmt:
2835 retval = _copyVariableShowStmt(from);
2837 case T_VariableResetStmt:
2838 retval = _copyVariableResetStmt(from);
2840 case T_CreateTrigStmt:
2841 retval = _copyCreateTrigStmt(from);
2843 case T_DropTrigStmt:
2844 retval = _copyDropTrigStmt(from);
2846 case T_CreatePLangStmt:
2847 retval = _copyCreatePLangStmt(from);
2849 case T_DropPLangStmt:
2850 retval = _copyDropPLangStmt(from);
2852 case T_CreateUserStmt:
2853 retval = _copyCreateUserStmt(from);
2855 case T_AlterUserStmt:
2856 retval = _copyAlterUserStmt(from);
2858 case T_DropUserStmt:
2859 retval = _copyDropUserStmt(from);
2862 retval = _copyLockStmt(from);
2864 case T_ConstraintsSetStmt:
2865 retval = _copyConstraintsSetStmt(from);
2867 case T_CreateGroupStmt:
2868 retval = _copyCreateGroupStmt(from);
2870 case T_AlterGroupStmt:
2871 retval = _copyAlterGroupStmt(from);
2873 case T_DropGroupStmt:
2874 retval = _copyDropGroupStmt(from);
2877 retval = _copyReindexStmt(from);
2879 case T_SetSessionStmt:
2880 retval = _copySetSessionStmt(from);
2884 retval = _copyAExpr(from);
2887 retval = _copyAttr(from);
2890 retval = _copyAConst(from);
2893 retval = _copyParamNo(from);
2896 retval = _copyIdent(from);
2899 retval = _copyFuncCall(from);
2902 retval = _copyAIndices(from);
2905 retval = _copyResTarget(from);
2908 retval = _copyTypeCast(from);
2911 retval = _copySortGroupBy(from);
2914 retval = _copyRangeVar(from);
2916 case T_RangeSubselect:
2917 retval = _copyRangeSubselect(from);
2920 retval = _copyTypeName(from);
2923 retval = _copyIndexElem(from);
2926 retval = _copyColumnDef(from);
2929 retval = _copyConstraint(from);
2932 retval = _copyDefElem(from);
2935 retval = _copyTargetEntry(from);
2937 case T_RangeTblEntry:
2938 retval = _copyRangeTblEntry(from);
2941 retval = _copySortClause(from);
2944 retval = _copyGroupClause(from);
2947 retval = _copyCaseExpr(from);
2950 retval = _copyCaseWhen(from);
2952 case T_FkConstraint:
2953 retval = _copyFkConstraint(from);
2957 elog(ERROR, "copyObject: don't know how to copy node type %d",
2959 retval = from; /* keep compiler quiet */