1 /*-------------------------------------------------------------------------
4 * Copy functions for Postgres tree nodes.
6 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.107 2000/02/20 21:32:05 tgl Exp $
13 *-------------------------------------------------------------------------
18 #include "optimizer/planmain.h"
19 #include "optimizer/subselect.h"
24 * a macro to simplify calling of copyObject on the specified field
26 #define Node_Copy(from, newnode, field) \
27 ((newnode)->field = copyObject((from)->field))
32 * This copy function only copies the "cons-cells" of the list, not the
33 * pointed-to objects. (Use copyObject if you want a "deep" copy.)
35 * We also use this function for copying lists of integers, which is
36 * grotty but unlikely to break --- it could fail if sizeof(pointer)
37 * is less than sizeof(int), but I don't know any such machines...
39 * Note that copyObject will surely coredump if applied to a list
49 /* rather ugly coding for speed... */
53 newlist = nl = lcons(lfirst(list), NIL);
55 foreach(l, lnext(list))
57 lnext(nl) = lcons(lfirst(l), NIL);
63 /* ****************************************************************
64 * plannodes.h copy functions
65 * ****************************************************************
71 * This function copies the fields of the Plan node. It is used by
72 * all the copy functions for classes which inherit from Plan.
76 CopyPlanFields(Plan *from, Plan *newnode)
78 newnode->startup_cost = from->startup_cost;
79 newnode->total_cost = from->total_cost;
80 newnode->plan_rows = from->plan_rows;
81 newnode->plan_width = from->plan_width;
82 /* state is NOT copied */
83 newnode->targetlist = copyObject(from->targetlist);
84 newnode->qual = copyObject(from->qual);
85 newnode->lefttree = copyObject(from->lefttree);
86 newnode->righttree = copyObject(from->righttree);
87 newnode->extParam = listCopy(from->extParam);
88 newnode->locParam = listCopy(from->locParam);
89 newnode->chgParam = listCopy(from->chgParam);
90 Node_Copy(from, newnode, initPlan);
91 if (from->subPlan != NIL)
92 newnode->subPlan = nconc(SS_pull_subplan((Node *) newnode->targetlist),
93 SS_pull_subplan((Node *) newnode->qual));
95 newnode->subPlan = NIL;
96 newnode->nParamExec = from->nParamExec;
104 _copyPlan(Plan *from)
106 Plan *newnode = makeNode(Plan);
109 * copy the node superclass fields
112 CopyPlanFields(from, newnode);
123 _copyResult(Result *from)
125 Result *newnode = makeNode(Result);
128 * copy node superclass fields
131 CopyPlanFields((Plan *) from, (Plan *) newnode);
134 * copy remainder of node
137 Node_Copy(from, newnode, resconstantqual);
140 * We must add subplans in resconstantqual to the new plan's subPlan
143 if (from->plan.subPlan != NIL)
144 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
145 SS_pull_subplan(newnode->resconstantqual));
155 _copyAppend(Append *from)
157 Append *newnode = makeNode(Append);
160 * copy node superclass fields
163 CopyPlanFields((Plan *) from, (Plan *) newnode);
166 * copy remainder of node
169 Node_Copy(from, newnode, appendplans);
170 Node_Copy(from, newnode, unionrtables);
171 newnode->inheritrelid = from->inheritrelid;
172 Node_Copy(from, newnode, inheritrtable);
181 * This function copies the fields of the Scan node. It is used by
182 * all the copy functions for classes which inherit from Scan.
186 CopyScanFields(Scan *from, Scan *newnode)
188 newnode->scanrelid = from->scanrelid;
197 _copyScan(Scan *from)
199 Scan *newnode = makeNode(Scan);
202 * 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
224 CopyPlanFields((Plan *) from, (Plan *) newnode);
225 CopyScanFields((Scan *) from, (Scan *) newnode);
235 _copyIndexScan(IndexScan *from)
237 IndexScan *newnode = makeNode(IndexScan);
240 * copy node superclass fields
243 CopyPlanFields((Plan *) from, (Plan *) newnode);
244 CopyScanFields((Scan *) from, (Scan *) newnode);
247 * copy remainder of node
250 newnode->indxid = listCopy(from->indxid);
251 Node_Copy(from, newnode, indxqual);
252 Node_Copy(from, newnode, indxqualorig);
253 newnode->indxorderdir = from->indxorderdir;
263 _copyTidScan(TidScan *from)
265 TidScan *newnode = makeNode(TidScan);
268 * copy node superclass fields
271 CopyPlanFields((Plan *) from, (Plan *) newnode);
272 CopyScanFields((Scan *) from, (Scan *) newnode);
274 * copy remainder of node
277 newnode->needRescan = from->needRescan;
278 Node_Copy(from, newnode, tideval);
287 * This function copies the fields of the Join node. It is used by
288 * all the copy functions for classes which inherit from Join.
292 CopyJoinFields(Join *from, Join *newnode)
304 _copyJoin(Join *from)
306 Join *newnode = makeNode(Join);
309 * copy node superclass fields
312 CopyPlanFields((Plan *) from, (Plan *) newnode);
313 CopyJoinFields(from, newnode);
324 _copyNestLoop(NestLoop *from)
326 NestLoop *newnode = makeNode(NestLoop);
329 * copy node superclass fields
332 CopyPlanFields((Plan *) from, (Plan *) newnode);
333 CopyJoinFields((Join *) from, (Join *) newnode);
344 _copyMergeJoin(MergeJoin *from)
346 MergeJoin *newnode = makeNode(MergeJoin);
349 * copy node superclass fields
352 CopyPlanFields((Plan *) from, (Plan *) newnode);
353 CopyJoinFields((Join *) from, (Join *) newnode);
356 * copy remainder of node
359 Node_Copy(from, newnode, mergeclauses);
369 _copyHashJoin(HashJoin *from)
371 HashJoin *newnode = makeNode(HashJoin);
374 * copy node superclass fields
377 CopyPlanFields((Plan *) from, (Plan *) newnode);
378 CopyJoinFields((Join *) from, (Join *) newnode);
381 * copy remainder of node
384 Node_Copy(from, newnode, hashclauses);
386 newnode->hashjoinop = from->hashjoinop;
395 * This function copies the fields of the Noname node. It is used by
396 * all the copy functions for classes which inherit from Noname.
400 CopyNonameFields(Noname *from, Noname *newnode)
402 newnode->nonameid = from->nonameid;
403 newnode->keycount = from->keycount;
413 _copyNoname(Noname *from)
415 Noname *newnode = makeNode(Noname);
418 * copy node superclass fields
421 CopyPlanFields((Plan *) from, (Plan *) newnode);
422 CopyNonameFields(from, newnode);
432 _copyMaterial(Material *from)
434 Material *newnode = makeNode(Material);
437 * copy node superclass fields
440 CopyPlanFields((Plan *) from, (Plan *) newnode);
441 CopyNonameFields((Noname *) from, (Noname *) newnode);
452 _copySort(Sort *from)
454 Sort *newnode = makeNode(Sort);
457 * copy node superclass fields
460 CopyPlanFields((Plan *) from, (Plan *) newnode);
461 CopyNonameFields((Noname *) from, (Noname *) newnode);
472 _copyGroup(Group *from)
474 Group *newnode = makeNode(Group);
476 CopyPlanFields((Plan *) from, (Plan *) newnode);
478 newnode->tuplePerGroup = from->tuplePerGroup;
479 newnode->numCols = from->numCols;
480 newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
481 memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
493 Agg *newnode = makeNode(Agg);
495 CopyPlanFields((Plan *) from, (Plan *) newnode);
505 _copyGroupClause(GroupClause *from)
507 GroupClause *newnode = makeNode(GroupClause);
509 newnode->tleSortGroupRef = from->tleSortGroupRef;
510 newnode->sortop = from->sortop;
521 _copyUnique(Unique *from)
523 Unique *newnode = makeNode(Unique);
526 * copy node superclass fields
529 CopyPlanFields((Plan *) from, (Plan *) newnode);
530 CopyNonameFields((Noname *) from, (Noname *) 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->shutdown = 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)
1087 * Modify the next line, since it causes the copying to cycle (i.e.
1088 * the parent points right back here! -- JMH, 7/7/92. Old version:
1089 * Node_Copy(from, newnode, parent);
1091 newnode->parent = from->parent;
1093 newnode->startup_cost = from->startup_cost;
1094 newnode->total_cost = from->total_cost;
1096 newnode->pathtype = from->pathtype;
1098 Node_Copy(from, newnode, pathkeys);
1106 _copyPath(Path *from)
1108 Path *newnode = makeNode(Path);
1110 CopyPathFields(from, newnode);
1120 _copyIndexPath(IndexPath *from)
1122 IndexPath *newnode = makeNode(IndexPath);
1125 * copy the node superclass fields
1128 CopyPathFields((Path *) from, (Path *) newnode);
1131 * copy remainder of node
1134 newnode->indexid = listCopy(from->indexid);
1135 Node_Copy(from, newnode, indexqual);
1136 newnode->indexscandir = from->indexscandir;
1137 newnode->joinrelids = listCopy(from->joinrelids);
1147 _copyTidPath(TidPath *from)
1149 TidPath *newnode = makeNode(TidPath);
1152 * copy the node superclass fields
1155 CopyPathFields((Path *) from, (Path *) newnode);
1158 * copy remainder of node
1161 Node_Copy(from, newnode, tideval);
1162 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1167 * CopyJoinPathFields
1169 * This function copies the fields of the JoinPath node. It is used by
1170 * all the copy functions for classes which inherit from JoinPath.
1174 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1176 Node_Copy(from, newnode, outerjoinpath);
1177 Node_Copy(from, newnode, innerjoinpath);
1178 Node_Copy(from, newnode, joinrestrictinfo);
1186 _copyNestPath(NestPath *from)
1188 NestPath *newnode = makeNode(NestPath);
1191 * copy the node superclass fields
1194 CopyPathFields((Path *) from, (Path *) newnode);
1195 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1205 _copyMergePath(MergePath *from)
1207 MergePath *newnode = makeNode(MergePath);
1210 * copy the node superclass fields
1213 CopyPathFields((Path *) from, (Path *) newnode);
1214 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1217 * copy the remainder of the node
1220 Node_Copy(from, newnode, path_mergeclauses);
1221 Node_Copy(from, newnode, outersortkeys);
1222 Node_Copy(from, newnode, innersortkeys);
1232 _copyHashPath(HashPath *from)
1234 HashPath *newnode = makeNode(HashPath);
1237 * copy the node superclass fields
1240 CopyPathFields((Path *) from, (Path *) newnode);
1241 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1244 * copy remainder of node
1247 Node_Copy(from, newnode, path_hashclauses);
1256 static PathKeyItem *
1257 _copyPathKeyItem(PathKeyItem *from)
1259 PathKeyItem *newnode = makeNode(PathKeyItem);
1262 * copy remainder of node
1265 Node_Copy(from, newnode, key);
1266 newnode->sortop = from->sortop;
1275 static RestrictInfo *
1276 _copyRestrictInfo(RestrictInfo *from)
1278 RestrictInfo *newnode = makeNode(RestrictInfo);
1281 * copy remainder of node
1284 Node_Copy(from, newnode, clause);
1285 Node_Copy(from, newnode, subclauseindices);
1286 newnode->mergejoinoperator = from->mergejoinoperator;
1287 newnode->left_sortop = from->left_sortop;
1288 newnode->right_sortop = from->right_sortop;
1289 newnode->hashjoinoperator = from->hashjoinoperator;
1299 _copyJoinInfo(JoinInfo *from)
1301 JoinInfo *newnode = makeNode(JoinInfo);
1304 * copy remainder of node
1307 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1308 Node_Copy(from, newnode, jinfo_restrictinfo);
1314 _copyIter(Iter *from)
1316 Iter *newnode = makeNode(Iter);
1318 Node_Copy(from, newnode, iterexpr);
1319 newnode->itertype = from->itertype;
1325 _copyStream(Stream *from)
1327 Stream *newnode = makeNode(Stream);
1329 newnode->pathptr = from->pathptr;
1330 newnode->cinfo = from->cinfo;
1331 newnode->clausetype = from->clausetype;
1333 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1335 Node_Copy(from, newnode, downstream);
1336 if (newnode->downstream)
1337 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1339 newnode->groupup = from->groupup;
1340 newnode->groupcost = from->groupcost;
1341 newnode->groupsel = from->groupsel;
1347 * parsenodes.h routines have no copy functions
1350 static TargetEntry *
1351 _copyTargetEntry(TargetEntry *from)
1353 TargetEntry *newnode = makeNode(TargetEntry);
1355 Node_Copy(from, newnode, resdom);
1356 Node_Copy(from, newnode, fjoin);
1357 Node_Copy(from, newnode, expr);
1361 static RangeTblEntry *
1362 _copyRangeTblEntry(RangeTblEntry *from)
1364 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1367 newnode->relname = pstrdup(from->relname);
1368 Node_Copy(from, newnode, ref);
1369 newnode->relid = from->relid;
1370 newnode->inh = from->inh;
1371 newnode->inFromCl = from->inFromCl;
1372 newnode->inJoinSet = from->inJoinSet;
1373 newnode->skipAcl = from->skipAcl;
1379 _copyRowMark(RowMark *from)
1381 RowMark *newnode = makeNode(RowMark);
1383 newnode->rti = from->rti;
1384 newnode->info = from->info;
1390 _copySortClause(SortClause *from)
1392 SortClause *newnode = makeNode(SortClause);
1394 newnode->tleSortGroupRef = from->tleSortGroupRef;
1395 newnode->sortop = from->sortop;
1401 _copyAConst(A_Const *from)
1403 A_Const *newnode = makeNode(A_Const);
1405 newnode->val = *((Value *) (copyObject(&(from->val))));
1406 Node_Copy(from, newnode, typename);
1412 _copyTypeName(TypeName *from)
1414 TypeName *newnode = makeNode(TypeName);
1417 newnode->name = pstrdup(from->name);
1418 newnode->timezone = from->timezone;
1419 newnode->setof = from->setof;
1420 newnode->typmod = from->typmod;
1421 Node_Copy(from, newnode, arrayBounds);
1427 _copyTypeCast(TypeCast *from)
1429 TypeCast *newnode = makeNode(TypeCast);
1431 Node_Copy(from, newnode, arg);
1432 Node_Copy(from, newnode, typename);
1438 _copyQuery(Query *from)
1440 Query *newnode = makeNode(Query);
1442 newnode->commandType = from->commandType;
1443 if (from->utilityStmt && nodeTag(from->utilityStmt) == T_NotifyStmt)
1445 NotifyStmt *from_notify = (NotifyStmt *) from->utilityStmt;
1446 NotifyStmt *n = makeNode(NotifyStmt);
1448 n->relname = pstrdup(from_notify->relname);
1449 newnode->utilityStmt = (Node *) n;
1451 newnode->resultRelation = from->resultRelation;
1453 newnode->into = pstrdup(from->into);
1454 newnode->isPortal = from->isPortal;
1455 newnode->isBinary = from->isBinary;
1456 newnode->isTemp = from->isTemp;
1457 newnode->unionall = from->unionall;
1458 newnode->hasAggs = from->hasAggs;
1459 newnode->hasSubLinks = from->hasSubLinks;
1461 Node_Copy(from, newnode, rtable);
1462 Node_Copy(from, newnode, targetList);
1463 Node_Copy(from, newnode, qual);
1464 Node_Copy(from, newnode, rowMark);
1466 Node_Copy(from, newnode, distinctClause);
1467 Node_Copy(from, newnode, sortClause);
1468 Node_Copy(from, newnode, groupClause);
1469 Node_Copy(from, newnode, havingQual);
1471 /* why is intersectClause missing? */
1472 Node_Copy(from, newnode, unionClause);
1474 Node_Copy(from, newnode, limitOffset);
1475 Node_Copy(from, newnode, limitCount);
1478 * We do not copy the planner internal fields: base_rel_list,
1479 * join_rel_list, equi_key_list, query_pathkeys.
1480 * Not entirely clear if this is right?
1488 * mnodes.h routines have no copy functions
1491 /* ****************************************************************
1492 * pg_list.h copy functions
1493 * ****************************************************************
1497 _copyValue(Value *from)
1499 Value *newnode = makeNode(Value);
1501 newnode->type = from->type;
1505 newnode->val.str = pstrdup(from->val.str);
1508 newnode->val.ival = from->val.ival;
1511 newnode->val.dval = from->val.dval;
1520 * copyObject returns a copy of the node or list. If it is a list, it
1521 * recursively copies its items.
1525 copyObject(void *from)
1531 switch (nodeTag(from))
1538 retval = _copyPlan(from);
1541 retval = _copyResult(from);
1544 retval = _copyAppend(from);
1547 retval = _copyScan(from);
1550 retval = _copySeqScan(from);
1553 retval = _copyIndexScan(from);
1556 retval = _copyTidScan(from);
1559 retval = _copyJoin(from);
1562 retval = _copyNestLoop(from);
1565 retval = _copyMergeJoin(from);
1568 retval = _copyHashJoin(from);
1571 retval = _copyNoname(from);
1574 retval = _copyMaterial(from);
1577 retval = _copySort(from);
1580 retval = _copyGroup(from);
1583 retval = _copyAgg(from);
1586 retval = _copyGroupClause(from);
1589 retval = _copyUnique(from);
1592 retval = _copyHash(from);
1595 retval = _copySubPlan(from);
1602 retval = _copyResdom(from);
1605 retval = _copyFjoin(from);
1608 retval = _copyExpr(from);
1611 retval = _copyVar(from);
1614 retval = _copyAttr(from);
1617 retval = _copyOper(from);
1620 retval = _copyConst(from);
1623 retval = _copyParam(from);
1626 retval = _copyFunc(from);
1629 retval = _copyArray(from);
1632 retval = _copyArrayRef(from);
1635 retval = _copyAggref(from);
1638 retval = _copySubLink(from);
1641 retval = _copyRelabelType(from);
1644 retval = _copyCaseExpr(from);
1647 retval = _copyCaseWhen(from);
1654 retval = _copyRelOptInfo(from);
1657 retval = _copyPath(from);
1660 retval = _copyIndexPath(from);
1663 retval = _copyTidPath(from);
1666 retval = _copyNestPath(from);
1669 retval = _copyMergePath(from);
1672 retval = _copyHashPath(from);
1675 retval = _copyPathKeyItem(from);
1677 case T_RestrictInfo:
1678 retval = _copyRestrictInfo(from);
1681 retval = _copyJoinInfo(from);
1684 retval = _copyIter(from);
1687 retval = _copyStream(from);
1689 case T_IndexOptInfo:
1690 retval = _copyIndexOptInfo(from);
1697 retval = _copyQuery(from);
1700 retval = _copyTargetEntry(from);
1702 case T_RangeTblEntry:
1703 retval = _copyRangeTblEntry(from);
1706 retval = _copyRowMark(from);
1709 retval = _copySortClause(from);
1712 retval = _copyAConst(from);
1715 retval = _copyTypeName(from);
1718 retval = _copyTypeCast(from);
1727 retval = _copyValue(from);
1735 /* rather ugly coding for speed... */
1736 /* Note the input list cannot be NIL if we got here. */
1737 nl = lcons(copyObject(lfirst(list)), NIL);
1740 foreach(l, lnext(list))
1742 lnext(nl) = lcons(copyObject(lfirst(l)), NIL);
1748 elog(ERROR, "copyObject: don't know how to copy %d", nodeTag(from));