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.
13 * Another class of nodes not currently handled is nodes that appear
14 * only in "raw" parsetrees (gram.y output not yet analyzed by the parser).
15 * Perhaps some day that will need to be supported.
18 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
19 * Portions Copyright (c) 1994, Regents of the University of California
22 * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.116 2000/07/12 02:37:04 tgl Exp $
24 *-------------------------------------------------------------------------
29 #include "optimizer/clauses.h"
30 #include "optimizer/planmain.h"
35 * a macro to simplify calling of copyObject on the specified field
37 #define Node_Copy(from, newnode, field) \
38 ((newnode)->field = copyObject((from)->field))
43 * This copy function only copies the "cons-cells" of the list, not the
44 * pointed-to objects. (Use copyObject if you want a "deep" copy.)
46 * We also use this function for copying lists of integers, which is
47 * grotty but unlikely to break --- it could fail if sizeof(pointer)
48 * is less than sizeof(int), but I don't know any such machines...
50 * Note that copyObject will surely coredump if applied to a list
60 /* rather ugly coding for speed... */
64 newlist = nl = lcons(lfirst(list), NIL);
66 foreach(l, lnext(list))
68 lnext(nl) = lcons(lfirst(l), NIL);
74 /* ****************************************************************
75 * plannodes.h copy functions
76 * ****************************************************************
82 * This function copies the fields of the Plan node. It is used by
83 * all the copy functions for classes which inherit from Plan.
87 CopyPlanFields(Plan *from, Plan *newnode)
89 newnode->startup_cost = from->startup_cost;
90 newnode->total_cost = from->total_cost;
91 newnode->plan_rows = from->plan_rows;
92 newnode->plan_width = from->plan_width;
93 /* state is NOT copied */
94 newnode->targetlist = copyObject(from->targetlist);
95 newnode->qual = copyObject(from->qual);
96 newnode->lefttree = copyObject(from->lefttree);
97 newnode->righttree = copyObject(from->righttree);
98 newnode->extParam = listCopy(from->extParam);
99 newnode->locParam = listCopy(from->locParam);
100 newnode->chgParam = listCopy(from->chgParam);
101 Node_Copy(from, newnode, initPlan);
102 /* subPlan list must point to subplans in the new subtree, not the old */
103 if (from->subPlan != NIL)
104 newnode->subPlan = nconc(pull_subplans((Node *) newnode->targetlist),
105 pull_subplans((Node *) newnode->qual));
107 newnode->subPlan = NIL;
108 newnode->nParamExec = from->nParamExec;
116 _copyPlan(Plan *from)
118 Plan *newnode = makeNode(Plan);
121 * copy the node superclass fields
124 CopyPlanFields(from, newnode);
135 _copyResult(Result *from)
137 Result *newnode = makeNode(Result);
140 * copy node superclass fields
143 CopyPlanFields((Plan *) from, (Plan *) newnode);
146 * copy remainder of node
149 Node_Copy(from, newnode, resconstantqual);
152 * We must add subplans in resconstantqual to the new plan's subPlan
155 if (from->plan.subPlan != NIL)
156 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
157 pull_subplans(newnode->resconstantqual));
167 _copyAppend(Append *from)
169 Append *newnode = makeNode(Append);
172 * copy node superclass fields
175 CopyPlanFields((Plan *) from, (Plan *) newnode);
178 * copy remainder of node
181 Node_Copy(from, newnode, appendplans);
182 Node_Copy(from, newnode, unionrtables);
183 newnode->inheritrelid = from->inheritrelid;
184 Node_Copy(from, newnode, inheritrtable);
193 * This function copies the fields of the Scan node. It is used by
194 * all the copy functions for classes which inherit from Scan.
198 CopyScanFields(Scan *from, Scan *newnode)
200 newnode->scanrelid = from->scanrelid;
209 _copyScan(Scan *from)
211 Scan *newnode = makeNode(Scan);
214 * copy node superclass fields
217 CopyPlanFields((Plan *) from, (Plan *) newnode);
218 CopyScanFields((Scan *) from, (Scan *) newnode);
228 _copySeqScan(SeqScan *from)
230 SeqScan *newnode = makeNode(SeqScan);
233 * copy node superclass fields
236 CopyPlanFields((Plan *) from, (Plan *) newnode);
237 CopyScanFields((Scan *) from, (Scan *) newnode);
247 _copyIndexScan(IndexScan *from)
249 IndexScan *newnode = makeNode(IndexScan);
252 * copy node superclass fields
255 CopyPlanFields((Plan *) from, (Plan *) newnode);
256 CopyScanFields((Scan *) from, (Scan *) newnode);
259 * copy remainder of node
262 newnode->indxid = listCopy(from->indxid);
263 Node_Copy(from, newnode, indxqual);
264 Node_Copy(from, newnode, indxqualorig);
265 newnode->indxorderdir = from->indxorderdir;
268 * We must add subplans in index quals to the new plan's subPlan list
270 if (from->scan.plan.subPlan != NIL)
272 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
273 pull_subplans((Node *) newnode->indxqual));
274 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
275 pull_subplans((Node *) newnode->indxqualorig));
286 _copyTidScan(TidScan *from)
288 TidScan *newnode = makeNode(TidScan);
291 * copy node superclass fields
294 CopyPlanFields((Plan *) from, (Plan *) newnode);
295 CopyScanFields((Scan *) from, (Scan *) newnode);
297 * copy remainder of node
300 newnode->needRescan = from->needRescan;
301 Node_Copy(from, newnode, tideval);
310 * This function copies the fields of the Join node. It is used by
311 * all the copy functions for classes which inherit from Join.
315 CopyJoinFields(Join *from, Join *newnode)
327 _copyJoin(Join *from)
329 Join *newnode = makeNode(Join);
332 * copy node superclass fields
335 CopyPlanFields((Plan *) from, (Plan *) newnode);
336 CopyJoinFields(from, newnode);
347 _copyNestLoop(NestLoop *from)
349 NestLoop *newnode = makeNode(NestLoop);
352 * copy node superclass fields
355 CopyPlanFields((Plan *) from, (Plan *) newnode);
356 CopyJoinFields((Join *) from, (Join *) newnode);
367 _copyMergeJoin(MergeJoin *from)
369 MergeJoin *newnode = makeNode(MergeJoin);
372 * copy node superclass fields
375 CopyPlanFields((Plan *) from, (Plan *) newnode);
376 CopyJoinFields((Join *) from, (Join *) newnode);
379 * copy remainder of node
382 Node_Copy(from, newnode, mergeclauses);
385 * We must add subplans in mergeclauses to the new plan's subPlan list
387 if (from->join.subPlan != NIL)
388 newnode->join.subPlan = nconc(newnode->join.subPlan,
389 pull_subplans((Node *) newnode->mergeclauses));
399 _copyHashJoin(HashJoin *from)
401 HashJoin *newnode = makeNode(HashJoin);
404 * copy node superclass fields
407 CopyPlanFields((Plan *) from, (Plan *) newnode);
408 CopyJoinFields((Join *) from, (Join *) newnode);
411 * copy remainder of node
414 Node_Copy(from, newnode, hashclauses);
415 newnode->hashjoinop = from->hashjoinop;
418 * We must add subplans in hashclauses to the new plan's subPlan list
420 if (from->join.subPlan != NIL)
421 newnode->join.subPlan = nconc(newnode->join.subPlan,
422 pull_subplans((Node *) newnode->hashclauses));
433 _copyMaterial(Material *from)
435 Material *newnode = makeNode(Material);
438 * copy node superclass fields
441 CopyPlanFields((Plan *) from, (Plan *) newnode);
452 _copySort(Sort *from)
454 Sort *newnode = makeNode(Sort);
457 * copy node superclass fields
460 CopyPlanFields((Plan *) from, (Plan *) newnode);
462 newnode->keycount = from->keycount;
473 _copyGroup(Group *from)
475 Group *newnode = makeNode(Group);
477 CopyPlanFields((Plan *) from, (Plan *) newnode);
479 newnode->tuplePerGroup = from->tuplePerGroup;
480 newnode->numCols = from->numCols;
481 newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
482 memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
494 Agg *newnode = makeNode(Agg);
496 CopyPlanFields((Plan *) from, (Plan *) newnode);
506 _copyGroupClause(GroupClause *from)
508 GroupClause *newnode = makeNode(GroupClause);
510 newnode->tleSortGroupRef = from->tleSortGroupRef;
511 newnode->sortop = from->sortop;
522 _copyUnique(Unique *from)
524 Unique *newnode = makeNode(Unique);
527 * copy node superclass fields
530 CopyPlanFields((Plan *) from, (Plan *) newnode);
533 * copy remainder of node
536 newnode->numCols = from->numCols;
537 newnode->uniqColIdx = palloc(from->numCols * sizeof(AttrNumber));
538 memcpy(newnode->uniqColIdx, from->uniqColIdx, from->numCols * sizeof(AttrNumber));
549 _copyHash(Hash *from)
551 Hash *newnode = makeNode(Hash);
554 * copy node superclass fields
557 CopyPlanFields((Plan *) from, (Plan *) newnode);
560 * copy remainder of node
563 Node_Copy(from, newnode, hashkey);
569 _copySubPlan(SubPlan *from)
571 SubPlan *newnode = makeNode(SubPlan);
573 Node_Copy(from, newnode, plan);
574 newnode->plan_id = from->plan_id;
575 Node_Copy(from, newnode, rtable);
576 newnode->setParam = listCopy(from->setParam);
577 newnode->parParam = listCopy(from->parParam);
578 Node_Copy(from, newnode, sublink);
580 /* do not copy execution state */
581 newnode->needShutdown = false;
582 newnode->curTuple = NULL;
587 /* ****************************************************************
588 * primnodes.h copy functions
589 * ****************************************************************
597 _copyResdom(Resdom *from)
599 Resdom *newnode = makeNode(Resdom);
601 newnode->resno = from->resno;
602 newnode->restype = from->restype;
603 newnode->restypmod = from->restypmod;
604 if (from->resname != NULL)
605 newnode->resname = pstrdup(from->resname);
606 newnode->ressortgroupref = from->ressortgroupref;
607 newnode->reskey = from->reskey;
608 newnode->reskeyop = from->reskeyop;
609 newnode->resjunk = from->resjunk;
615 _copyFjoin(Fjoin *from)
617 Fjoin *newnode = makeNode(Fjoin);
620 * copy node superclass fields
624 newnode->fj_initialized = from->fj_initialized;
625 newnode->fj_nNodes = from->fj_nNodes;
627 Node_Copy(from, newnode, fj_innerNode);
629 newnode->fj_results = (DatumPtr)
630 palloc((from->fj_nNodes) * sizeof(Datum));
631 memmove(from->fj_results,
633 (from->fj_nNodes) * sizeof(Datum));
635 newnode->fj_alwaysDone = (BoolPtr)
636 palloc((from->fj_nNodes) * sizeof(bool));
637 memmove(from->fj_alwaysDone,
638 newnode->fj_alwaysDone,
639 (from->fj_nNodes) * sizeof(bool));
650 _copyExpr(Expr *from)
652 Expr *newnode = makeNode(Expr);
655 * copy node superclass fields
658 newnode->typeOid = from->typeOid;
659 newnode->opType = from->opType;
661 Node_Copy(from, newnode, oper);
662 Node_Copy(from, newnode, args);
674 Var *newnode = makeNode(Var);
677 * copy remainder of node
680 newnode->varno = from->varno;
681 newnode->varattno = from->varattno;
682 newnode->vartype = from->vartype;
683 newnode->vartypmod = from->vartypmod;
684 newnode->varlevelsup = from->varlevelsup;
686 newnode->varnoold = from->varnoold;
687 newnode->varoattno = from->varoattno;
693 _copyAttr(Attr *from)
695 Attr *newnode = makeNode(Attr);
698 newnode->relname = pstrdup(from->relname);
699 Node_Copy(from, newnode, attrs);
709 _copyOper(Oper *from)
711 Oper *newnode = makeNode(Oper);
714 * copy remainder of node
717 newnode->opno = from->opno;
718 newnode->opid = from->opid;
719 newnode->opresulttype = from->opresulttype;
720 newnode->opsize = from->opsize;
723 * NOTE: shall we copy the cache structure or just the pointer ?
724 * Alternatively we can set 'op_fcache' to NULL, in which case the
725 * executor will initialize it when it needs it...
727 newnode->op_fcache = from->op_fcache;
737 _copyConst(Const *from)
739 Const *newnode = makeNode(Const);
742 * copy remainder of node
745 newnode->consttype = from->consttype;
746 newnode->constlen = from->constlen;
748 if (from->constbyval || from->constisnull)
751 * passed by value so just copy the datum.
752 * Also, don't try to copy struct when value is null!
755 newnode->constvalue = from->constvalue;
760 * not passed by value. datum contains a pointer.
763 int length = from->constlen;
765 if (length == -1) /* variable-length type? */
766 length = VARSIZE(from->constvalue);
767 newnode->constvalue = PointerGetDatum(palloc(length));
768 memcpy(DatumGetPointer(newnode->constvalue),
769 DatumGetPointer(from->constvalue),
773 newnode->constisnull = from->constisnull;
774 newnode->constbyval = from->constbyval;
775 newnode->constisset = from->constisset;
776 newnode->constiscast = from->constiscast;
786 _copyParam(Param *from)
788 Param *newnode = makeNode(Param);
791 * copy remainder of node
794 newnode->paramkind = from->paramkind;
795 newnode->paramid = from->paramid;
797 if (from->paramname != NULL)
798 newnode->paramname = pstrdup(from->paramname);
799 newnode->paramtype = from->paramtype;
800 Node_Copy(from, newnode, param_tlist);
810 _copyFunc(Func *from)
812 Func *newnode = makeNode(Func);
815 * copy remainder of node
818 newnode->funcid = from->funcid;
819 newnode->functype = from->functype;
820 newnode->funcisindex = from->funcisindex;
821 newnode->funcsize = from->funcsize;
822 newnode->func_fcache = from->func_fcache;
823 Node_Copy(from, newnode, func_tlist);
824 Node_Copy(from, newnode, func_planlist);
834 _copyAggref(Aggref *from)
836 Aggref *newnode = makeNode(Aggref);
839 * copy remainder of node
842 newnode->aggname = pstrdup(from->aggname);
843 newnode->basetype = from->basetype;
844 newnode->aggtype = from->aggtype;
845 Node_Copy(from, newnode, target);
846 newnode->usenulls = from->usenulls;
847 newnode->aggstar = from->aggstar;
848 newnode->aggdistinct = from->aggdistinct;
849 newnode->aggno = from->aggno; /* probably not needed */
859 _copySubLink(SubLink *from)
861 SubLink *newnode = makeNode(SubLink);
864 * copy remainder of node
867 newnode->subLinkType = from->subLinkType;
868 newnode->useor = from->useor;
869 Node_Copy(from, newnode, lefthand);
870 Node_Copy(from, newnode, oper);
871 Node_Copy(from, newnode, subselect);
881 _copyRelabelType(RelabelType *from)
883 RelabelType *newnode = makeNode(RelabelType);
886 * copy remainder of node
889 Node_Copy(from, newnode, arg);
890 newnode->resulttype = from->resulttype;
891 newnode->resulttypmod = from->resulttypmod;
901 _copyCaseExpr(CaseExpr *from)
903 CaseExpr *newnode = makeNode(CaseExpr);
906 * copy remainder of node
909 newnode->casetype = from->casetype;
911 Node_Copy(from, newnode, arg);
912 Node_Copy(from, newnode, args);
913 Node_Copy(from, newnode, defresult);
923 _copyCaseWhen(CaseWhen *from)
925 CaseWhen *newnode = makeNode(CaseWhen);
928 * copy remainder of node
931 Node_Copy(from, newnode, expr);
932 Node_Copy(from, newnode, result);
938 _copyArray(Array *from)
940 Array *newnode = makeNode(Array);
943 * copy remainder of node
946 newnode->arrayelemtype = from->arrayelemtype;
947 newnode->arrayelemlength = from->arrayelemlength;
948 newnode->arrayelembyval = from->arrayelembyval;
949 newnode->arrayndim = from->arrayndim;
950 newnode->arraylow = from->arraylow;
951 newnode->arrayhigh = from->arrayhigh;
952 newnode->arraylen = from->arraylen;
958 _copyArrayRef(ArrayRef *from)
960 ArrayRef *newnode = makeNode(ArrayRef);
963 * copy remainder of node
966 newnode->refattrlength = from->refattrlength;
967 newnode->refelemlength = from->refelemlength;
968 newnode->refelemtype = from->refelemtype;
969 newnode->refelembyval = from->refelembyval;
971 Node_Copy(from, newnode, refupperindexpr);
972 Node_Copy(from, newnode, reflowerindexpr);
973 Node_Copy(from, newnode, refexpr);
974 Node_Copy(from, newnode, refassgnexpr);
979 /* ****************************************************************
980 * relation.h copy functions
981 * ****************************************************************
989 * when you change this, also make sure to fix up xfunc_copyRelOptInfo in
990 * planner/path/xfunc.c accordingly!!!
994 _copyRelOptInfo(RelOptInfo *from)
996 RelOptInfo *newnode = makeNode(RelOptInfo);
998 newnode->relids = listCopy(from->relids);
1000 newnode->rows = from->rows;
1001 newnode->width = from->width;
1003 Node_Copy(from, newnode, targetlist);
1004 Node_Copy(from, newnode, pathlist);
1005 /* XXX cheapest-path fields should point to members of pathlist? */
1006 Node_Copy(from, newnode, cheapest_startup_path);
1007 Node_Copy(from, newnode, cheapest_total_path);
1008 newnode->pruneable = from->pruneable;
1010 newnode->indexed = from->indexed;
1011 newnode->pages = from->pages;
1012 newnode->tuples = from->tuples;
1014 Node_Copy(from, newnode, baserestrictinfo);
1015 newnode->baserestrictcost = from->baserestrictcost;
1016 Node_Copy(from, newnode, joininfo);
1017 Node_Copy(from, newnode, innerjoin);
1026 static IndexOptInfo *
1027 _copyIndexOptInfo(IndexOptInfo *from)
1029 IndexOptInfo *newnode = makeNode(IndexOptInfo);
1033 newnode->indexoid = from->indexoid;
1034 newnode->pages = from->pages;
1035 newnode->tuples = from->tuples;
1037 if (from->classlist)
1039 for (len = 0; from->classlist[len] != 0; len++)
1041 newnode->classlist = (Oid *) palloc(sizeof(Oid) * (len + 1));
1042 for (i = 0; i < len; i++)
1043 newnode->classlist[i] = from->classlist[i];
1044 newnode->classlist[len] = 0;
1047 if (from->indexkeys)
1049 for (len = 0; from->indexkeys[len] != 0; len++)
1051 newnode->indexkeys = (int *) palloc(sizeof(int) * (len + 1));
1052 for (i = 0; i < len; i++)
1053 newnode->indexkeys[i] = from->indexkeys[i];
1054 newnode->indexkeys[len] = 0;
1059 for (len = 0; from->ordering[len] != 0; len++)
1061 newnode->ordering = (Oid *) palloc(sizeof(Oid) * (len + 1));
1062 for (i = 0; i < len; i++)
1063 newnode->ordering[i] = from->ordering[i];
1064 newnode->ordering[len] = 0;
1067 newnode->relam = from->relam;
1068 newnode->amcostestimate = from->amcostestimate;
1069 newnode->indproc = from->indproc;
1070 Node_Copy(from, newnode, indpred);
1071 newnode->lossy = from->lossy;
1079 * This function copies the fields of the Path node. It is used by
1080 * all the copy functions for classes which inherit from Path.
1084 CopyPathFields(Path *from, Path *newnode)
1088 * Modify the next line, since it causes the copying to cycle (i.e.
1089 * the parent points right back here! -- JMH, 7/7/92. Old version:
1090 * Node_Copy(from, newnode, parent);
1092 newnode->parent = from->parent;
1094 newnode->startup_cost = from->startup_cost;
1095 newnode->total_cost = from->total_cost;
1097 newnode->pathtype = from->pathtype;
1099 Node_Copy(from, newnode, pathkeys);
1107 _copyPath(Path *from)
1109 Path *newnode = makeNode(Path);
1111 CopyPathFields(from, newnode);
1121 _copyIndexPath(IndexPath *from)
1123 IndexPath *newnode = makeNode(IndexPath);
1126 * copy the node superclass fields
1129 CopyPathFields((Path *) from, (Path *) newnode);
1132 * copy remainder of node
1135 newnode->indexid = listCopy(from->indexid);
1136 Node_Copy(from, newnode, indexqual);
1137 newnode->indexscandir = from->indexscandir;
1138 newnode->joinrelids = listCopy(from->joinrelids);
1139 newnode->rows = from->rows;
1149 _copyTidPath(TidPath *from)
1151 TidPath *newnode = makeNode(TidPath);
1154 * copy the node superclass fields
1157 CopyPathFields((Path *) from, (Path *) newnode);
1160 * copy remainder of node
1163 Node_Copy(from, newnode, tideval);
1164 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1170 * CopyJoinPathFields
1172 * This function copies the fields of the JoinPath node. It is used by
1173 * all the copy functions for classes which inherit from JoinPath.
1177 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1179 Node_Copy(from, newnode, outerjoinpath);
1180 Node_Copy(from, newnode, innerjoinpath);
1181 Node_Copy(from, newnode, joinrestrictinfo);
1189 _copyNestPath(NestPath *from)
1191 NestPath *newnode = makeNode(NestPath);
1194 * copy the node superclass fields
1197 CopyPathFields((Path *) from, (Path *) newnode);
1198 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1208 _copyMergePath(MergePath *from)
1210 MergePath *newnode = makeNode(MergePath);
1213 * copy the node superclass fields
1216 CopyPathFields((Path *) from, (Path *) newnode);
1217 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1220 * copy the remainder of the node
1223 Node_Copy(from, newnode, path_mergeclauses);
1224 Node_Copy(from, newnode, outersortkeys);
1225 Node_Copy(from, newnode, innersortkeys);
1235 _copyHashPath(HashPath *from)
1237 HashPath *newnode = makeNode(HashPath);
1240 * copy the node superclass fields
1243 CopyPathFields((Path *) from, (Path *) newnode);
1244 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1247 * copy remainder of node
1250 Node_Copy(from, newnode, path_hashclauses);
1259 static PathKeyItem *
1260 _copyPathKeyItem(PathKeyItem *from)
1262 PathKeyItem *newnode = makeNode(PathKeyItem);
1265 * copy remainder of node
1268 Node_Copy(from, newnode, key);
1269 newnode->sortop = from->sortop;
1278 static RestrictInfo *
1279 _copyRestrictInfo(RestrictInfo *from)
1281 RestrictInfo *newnode = makeNode(RestrictInfo);
1284 * copy remainder of node
1287 Node_Copy(from, newnode, clause);
1288 Node_Copy(from, newnode, subclauseindices);
1289 newnode->mergejoinoperator = from->mergejoinoperator;
1290 newnode->left_sortop = from->left_sortop;
1291 newnode->right_sortop = from->right_sortop;
1292 newnode->hashjoinoperator = from->hashjoinoperator;
1302 _copyJoinInfo(JoinInfo *from)
1304 JoinInfo *newnode = makeNode(JoinInfo);
1307 * copy remainder of node
1310 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1311 Node_Copy(from, newnode, jinfo_restrictinfo);
1317 _copyIter(Iter *from)
1319 Iter *newnode = makeNode(Iter);
1321 Node_Copy(from, newnode, iterexpr);
1322 newnode->itertype = from->itertype;
1328 _copyStream(Stream *from)
1330 Stream *newnode = makeNode(Stream);
1332 newnode->pathptr = from->pathptr;
1333 newnode->cinfo = from->cinfo;
1334 newnode->clausetype = from->clausetype;
1336 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1338 Node_Copy(from, newnode, downstream);
1339 if (newnode->downstream)
1340 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1342 newnode->groupup = from->groupup;
1343 newnode->groupcost = from->groupcost;
1344 newnode->groupsel = from->groupsel;
1349 /* ****************************************************************
1350 * parsenodes.h copy functions
1351 * ****************************************************************
1354 static TargetEntry *
1355 _copyTargetEntry(TargetEntry *from)
1357 TargetEntry *newnode = makeNode(TargetEntry);
1359 Node_Copy(from, newnode, resdom);
1360 Node_Copy(from, newnode, fjoin);
1361 Node_Copy(from, newnode, expr);
1365 static RangeTblEntry *
1366 _copyRangeTblEntry(RangeTblEntry *from)
1368 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1371 newnode->relname = pstrdup(from->relname);
1372 Node_Copy(from, newnode, ref);
1373 Node_Copy(from, newnode, eref);
1374 newnode->relid = from->relid;
1375 newnode->inh = from->inh;
1376 newnode->inFromCl = from->inFromCl;
1377 newnode->inJoinSet = from->inJoinSet;
1378 newnode->skipAcl = from->skipAcl;
1384 _copyRowMark(RowMark *from)
1386 RowMark *newnode = makeNode(RowMark);
1388 newnode->rti = from->rti;
1389 newnode->info = from->info;
1395 _copySortClause(SortClause *from)
1397 SortClause *newnode = makeNode(SortClause);
1399 newnode->tleSortGroupRef = from->tleSortGroupRef;
1400 newnode->sortop = from->sortop;
1406 _copyAConst(A_Const *from)
1408 A_Const *newnode = makeNode(A_Const);
1410 newnode->val = *((Value *) (copyObject(&(from->val))));
1411 Node_Copy(from, newnode, typename);
1417 _copyTypeName(TypeName *from)
1419 TypeName *newnode = makeNode(TypeName);
1422 newnode->name = pstrdup(from->name);
1423 newnode->timezone = from->timezone;
1424 newnode->setof = from->setof;
1425 newnode->typmod = from->typmod;
1426 Node_Copy(from, newnode, arrayBounds);
1432 _copyTypeCast(TypeCast *from)
1434 TypeCast *newnode = makeNode(TypeCast);
1436 Node_Copy(from, newnode, arg);
1437 Node_Copy(from, newnode, typename);
1443 _copyQuery(Query *from)
1445 Query *newnode = makeNode(Query);
1447 newnode->commandType = from->commandType;
1448 Node_Copy(from, newnode, utilityStmt);
1449 newnode->resultRelation = from->resultRelation;
1451 newnode->into = pstrdup(from->into);
1452 newnode->isPortal = from->isPortal;
1453 newnode->isBinary = from->isBinary;
1454 newnode->isTemp = from->isTemp;
1455 newnode->unionall = from->unionall;
1456 newnode->hasAggs = from->hasAggs;
1457 newnode->hasSubLinks = from->hasSubLinks;
1459 Node_Copy(from, newnode, rtable);
1460 Node_Copy(from, newnode, targetList);
1461 Node_Copy(from, newnode, qual);
1462 Node_Copy(from, newnode, rowMark);
1464 Node_Copy(from, newnode, distinctClause);
1465 Node_Copy(from, newnode, sortClause);
1466 Node_Copy(from, newnode, groupClause);
1467 Node_Copy(from, newnode, havingQual);
1469 /* why is intersectClause missing? */
1470 Node_Copy(from, newnode, unionClause);
1472 Node_Copy(from, newnode, limitOffset);
1473 Node_Copy(from, newnode, limitCount);
1476 * We do not copy the planner internal fields: base_rel_list,
1477 * join_rel_list, equi_key_list, query_pathkeys. Not entirely clear if
1484 static ClosePortalStmt *
1485 _copyClosePortalStmt(ClosePortalStmt *from)
1487 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1489 if (from->portalname)
1490 newnode->portalname = pstrdup(from->portalname);
1495 static TruncateStmt *
1496 _copyTruncateStmt(TruncateStmt *from)
1498 TruncateStmt *newnode = makeNode(TruncateStmt);
1500 newnode->relName = pstrdup(from->relName);
1506 _copyNotifyStmt(NotifyStmt *from)
1508 NotifyStmt *newnode = makeNode(NotifyStmt);
1511 newnode->relname = pstrdup(from->relname);
1517 _copyListenStmt(ListenStmt *from)
1519 ListenStmt *newnode = makeNode(ListenStmt);
1522 newnode->relname = pstrdup(from->relname);
1527 static UnlistenStmt *
1528 _copyUnlistenStmt(UnlistenStmt *from)
1530 UnlistenStmt *newnode = makeNode(UnlistenStmt);
1533 newnode->relname = pstrdup(from->relname);
1538 static TransactionStmt *
1539 _copyTransactionStmt(TransactionStmt *from)
1541 TransactionStmt *newnode = makeNode(TransactionStmt);
1543 newnode->command = from->command;
1549 _copyLoadStmt(LoadStmt *from)
1551 LoadStmt *newnode = makeNode(LoadStmt);
1554 newnode->filename = pstrdup(from->filename);
1559 static VariableSetStmt *
1560 _copyVariableSetStmt(VariableSetStmt *from)
1562 VariableSetStmt *newnode = makeNode(VariableSetStmt);
1565 newnode->name = pstrdup(from->name);
1567 newnode->value = pstrdup(from->value);
1572 static VariableResetStmt *
1573 _copyVariableResetStmt(VariableResetStmt *from)
1575 VariableResetStmt *newnode = makeNode(VariableResetStmt);
1578 newnode->name = pstrdup(from->name);
1584 _copyLockStmt(LockStmt *from)
1586 LockStmt *newnode = makeNode(LockStmt);
1589 newnode->relname = pstrdup(from->relname);
1590 newnode->mode = from->mode;
1596 /* ****************************************************************
1597 * pg_list.h copy functions
1598 * ****************************************************************
1602 _copyValue(Value *from)
1604 Value *newnode = makeNode(Value);
1606 newnode->type = from->type;
1610 newnode->val.ival = from->val.ival;
1614 newnode->val.str = pstrdup(from->val.str);
1623 * copyObject returns a copy of the node or list. If it is a list, it
1624 * recursively copies its items.
1628 copyObject(void *from)
1634 switch (nodeTag(from))
1641 retval = _copyPlan(from);
1644 retval = _copyResult(from);
1647 retval = _copyAppend(from);
1650 retval = _copyScan(from);
1653 retval = _copySeqScan(from);
1656 retval = _copyIndexScan(from);
1659 retval = _copyTidScan(from);
1662 retval = _copyJoin(from);
1665 retval = _copyNestLoop(from);
1668 retval = _copyMergeJoin(from);
1671 retval = _copyHashJoin(from);
1674 retval = _copyMaterial(from);
1677 retval = _copySort(from);
1680 retval = _copyGroup(from);
1683 retval = _copyAgg(from);
1686 retval = _copyUnique(from);
1689 retval = _copyHash(from);
1692 retval = _copySubPlan(from);
1699 retval = _copyResdom(from);
1702 retval = _copyFjoin(from);
1705 retval = _copyExpr(from);
1708 retval = _copyVar(from);
1711 retval = _copyOper(from);
1714 retval = _copyConst(from);
1717 retval = _copyParam(from);
1720 retval = _copyAggref(from);
1723 retval = _copySubLink(from);
1726 retval = _copyFunc(from);
1729 retval = _copyArray(from);
1732 retval = _copyArrayRef(from);
1735 retval = _copyIter(from);
1738 retval = _copyRelabelType(from);
1745 retval = _copyRelOptInfo(from);
1748 retval = _copyPath(from);
1751 retval = _copyIndexPath(from);
1754 retval = _copyTidPath(from);
1757 retval = _copyNestPath(from);
1760 retval = _copyMergePath(from);
1763 retval = _copyHashPath(from);
1766 retval = _copyPathKeyItem(from);
1768 case T_RestrictInfo:
1769 retval = _copyRestrictInfo(from);
1772 retval = _copyJoinInfo(from);
1775 retval = _copyStream(from);
1777 case T_IndexOptInfo:
1778 retval = _copyIndexOptInfo(from);
1787 retval = _copyValue(from);
1795 /* rather ugly coding for speed... */
1796 /* Note the input list cannot be NIL if we got here. */
1797 nl = lcons(copyObject(lfirst(list)), NIL);
1800 foreach(l, lnext(list))
1802 lnext(nl) = lcons(copyObject(lfirst(l)), NIL);
1812 retval = _copyQuery(from);
1814 case T_ClosePortalStmt:
1815 retval = _copyClosePortalStmt(from);
1817 case T_TruncateStmt:
1818 retval = _copyTruncateStmt(from);
1821 retval = _copyNotifyStmt(from);
1824 retval = _copyListenStmt(from);
1826 case T_UnlistenStmt:
1827 retval = _copyUnlistenStmt(from);
1829 case T_TransactionStmt:
1830 retval = _copyTransactionStmt(from);
1833 retval = _copyLoadStmt(from);
1835 case T_VariableSetStmt:
1836 retval = _copyVariableSetStmt(from);
1838 case T_VariableResetStmt:
1839 retval = _copyVariableResetStmt(from);
1842 retval = _copyLockStmt(from);
1846 retval = _copyAttr(from);
1849 retval = _copyAConst(from);
1852 retval = _copyTypeCast(from);
1855 retval = _copyTypeName(from);
1858 retval = _copyTargetEntry(from);
1860 case T_RangeTblEntry:
1861 retval = _copyRangeTblEntry(from);
1864 retval = _copySortClause(from);
1867 retval = _copyGroupClause(from);
1870 retval = _copyCaseExpr(from);
1873 retval = _copyCaseWhen(from);
1876 retval = _copyRowMark(from);
1880 elog(ERROR, "copyObject: don't know how to copy node type %d",
1882 retval = from; /* keep compiler quiet */