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.113 2000/04/12 17:15:16 momjian Exp $
13 *-------------------------------------------------------------------------
18 #include "optimizer/clauses.h"
19 #include "optimizer/planmain.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 /* subPlan list must point to subplans in the new subtree, not the old */
92 if (from->subPlan != NIL)
93 newnode->subPlan = nconc(pull_subplans((Node *) newnode->targetlist),
94 pull_subplans((Node *) newnode->qual));
96 newnode->subPlan = NIL;
97 newnode->nParamExec = from->nParamExec;
105 _copyPlan(Plan *from)
107 Plan *newnode = makeNode(Plan);
110 * copy the node superclass fields
113 CopyPlanFields(from, newnode);
124 _copyResult(Result *from)
126 Result *newnode = makeNode(Result);
129 * copy node superclass fields
132 CopyPlanFields((Plan *) from, (Plan *) newnode);
135 * copy remainder of node
138 Node_Copy(from, newnode, resconstantqual);
141 * We must add subplans in resconstantqual to the new plan's subPlan
144 if (from->plan.subPlan != NIL)
145 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
146 pull_subplans(newnode->resconstantqual));
156 _copyAppend(Append *from)
158 Append *newnode = makeNode(Append);
161 * copy node superclass fields
164 CopyPlanFields((Plan *) from, (Plan *) newnode);
167 * copy remainder of node
170 Node_Copy(from, newnode, appendplans);
171 Node_Copy(from, newnode, unionrtables);
172 newnode->inheritrelid = from->inheritrelid;
173 Node_Copy(from, newnode, inheritrtable);
182 * This function copies the fields of the Scan node. It is used by
183 * all the copy functions for classes which inherit from Scan.
187 CopyScanFields(Scan *from, Scan *newnode)
189 newnode->scanrelid = from->scanrelid;
198 _copyScan(Scan *from)
200 Scan *newnode = makeNode(Scan);
203 * copy node superclass fields
206 CopyPlanFields((Plan *) from, (Plan *) newnode);
207 CopyScanFields((Scan *) from, (Scan *) newnode);
217 _copySeqScan(SeqScan *from)
219 SeqScan *newnode = makeNode(SeqScan);
222 * copy node superclass fields
225 CopyPlanFields((Plan *) from, (Plan *) newnode);
226 CopyScanFields((Scan *) from, (Scan *) newnode);
236 _copyIndexScan(IndexScan *from)
238 IndexScan *newnode = makeNode(IndexScan);
241 * copy node superclass fields
244 CopyPlanFields((Plan *) from, (Plan *) newnode);
245 CopyScanFields((Scan *) from, (Scan *) newnode);
248 * copy remainder of node
251 newnode->indxid = listCopy(from->indxid);
252 Node_Copy(from, newnode, indxqual);
253 Node_Copy(from, newnode, indxqualorig);
254 newnode->indxorderdir = from->indxorderdir;
257 * We must add subplans in index quals to the new plan's subPlan list
259 if (from->scan.plan.subPlan != NIL)
261 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
262 pull_subplans((Node *) newnode->indxqual));
263 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
264 pull_subplans((Node *) newnode->indxqualorig));
275 _copyTidScan(TidScan *from)
277 TidScan *newnode = makeNode(TidScan);
280 * copy node superclass fields
283 CopyPlanFields((Plan *) from, (Plan *) newnode);
284 CopyScanFields((Scan *) from, (Scan *) newnode);
286 * copy remainder of node
289 newnode->needRescan = from->needRescan;
290 Node_Copy(from, newnode, tideval);
299 * This function copies the fields of the Join node. It is used by
300 * all the copy functions for classes which inherit from Join.
304 CopyJoinFields(Join *from, Join *newnode)
316 _copyJoin(Join *from)
318 Join *newnode = makeNode(Join);
321 * copy node superclass fields
324 CopyPlanFields((Plan *) from, (Plan *) newnode);
325 CopyJoinFields(from, newnode);
336 _copyNestLoop(NestLoop *from)
338 NestLoop *newnode = makeNode(NestLoop);
341 * copy node superclass fields
344 CopyPlanFields((Plan *) from, (Plan *) newnode);
345 CopyJoinFields((Join *) from, (Join *) newnode);
356 _copyMergeJoin(MergeJoin *from)
358 MergeJoin *newnode = makeNode(MergeJoin);
361 * copy node superclass fields
364 CopyPlanFields((Plan *) from, (Plan *) newnode);
365 CopyJoinFields((Join *) from, (Join *) newnode);
368 * copy remainder of node
371 Node_Copy(from, newnode, mergeclauses);
374 * We must add subplans in mergeclauses to the new plan's subPlan list
376 if (from->join.subPlan != NIL)
377 newnode->join.subPlan = nconc(newnode->join.subPlan,
378 pull_subplans((Node *) newnode->mergeclauses));
388 _copyHashJoin(HashJoin *from)
390 HashJoin *newnode = makeNode(HashJoin);
393 * copy node superclass fields
396 CopyPlanFields((Plan *) from, (Plan *) newnode);
397 CopyJoinFields((Join *) from, (Join *) newnode);
400 * copy remainder of node
403 Node_Copy(from, newnode, hashclauses);
404 newnode->hashjoinop = from->hashjoinop;
407 * We must add subplans in hashclauses to the new plan's subPlan list
409 if (from->join.subPlan != NIL)
410 newnode->join.subPlan = nconc(newnode->join.subPlan,
411 pull_subplans((Node *) newnode->hashclauses));
420 * This function copies the fields of the Noname node. It is used by
421 * all the copy functions for classes which inherit from Noname.
425 CopyNonameFields(Noname *from, Noname *newnode)
427 newnode->nonameid = from->nonameid;
428 newnode->keycount = from->keycount;
438 _copyNoname(Noname *from)
440 Noname *newnode = makeNode(Noname);
443 * copy node superclass fields
446 CopyPlanFields((Plan *) from, (Plan *) newnode);
447 CopyNonameFields(from, newnode);
457 _copyMaterial(Material *from)
459 Material *newnode = makeNode(Material);
462 * copy node superclass fields
465 CopyPlanFields((Plan *) from, (Plan *) newnode);
466 CopyNonameFields((Noname *) from, (Noname *) newnode);
477 _copySort(Sort *from)
479 Sort *newnode = makeNode(Sort);
482 * copy node superclass fields
485 CopyPlanFields((Plan *) from, (Plan *) newnode);
486 CopyNonameFields((Noname *) from, (Noname *) newnode);
497 _copyGroup(Group *from)
499 Group *newnode = makeNode(Group);
501 CopyPlanFields((Plan *) from, (Plan *) newnode);
503 newnode->tuplePerGroup = from->tuplePerGroup;
504 newnode->numCols = from->numCols;
505 newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
506 memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
518 Agg *newnode = makeNode(Agg);
520 CopyPlanFields((Plan *) from, (Plan *) newnode);
530 _copyGroupClause(GroupClause *from)
532 GroupClause *newnode = makeNode(GroupClause);
534 newnode->tleSortGroupRef = from->tleSortGroupRef;
535 newnode->sortop = from->sortop;
546 _copyUnique(Unique *from)
548 Unique *newnode = makeNode(Unique);
551 * copy node superclass fields
554 CopyPlanFields((Plan *) from, (Plan *) newnode);
555 CopyNonameFields((Noname *) from, (Noname *) newnode);
558 * copy remainder of node
561 newnode->numCols = from->numCols;
562 newnode->uniqColIdx = palloc(from->numCols * sizeof(AttrNumber));
563 memcpy(newnode->uniqColIdx, from->uniqColIdx, from->numCols * sizeof(AttrNumber));
574 _copyHash(Hash *from)
576 Hash *newnode = makeNode(Hash);
579 * copy node superclass fields
582 CopyPlanFields((Plan *) from, (Plan *) newnode);
585 * copy remainder of node
588 Node_Copy(from, newnode, hashkey);
594 _copySubPlan(SubPlan *from)
596 SubPlan *newnode = makeNode(SubPlan);
598 Node_Copy(from, newnode, plan);
599 newnode->plan_id = from->plan_id;
600 Node_Copy(from, newnode, rtable);
601 newnode->setParam = listCopy(from->setParam);
602 newnode->parParam = listCopy(from->parParam);
603 Node_Copy(from, newnode, sublink);
605 /* do not copy execution state */
606 newnode->shutdown = false;
607 newnode->curTuple = NULL;
612 /* ****************************************************************
613 * primnodes.h copy functions
614 * ****************************************************************
622 _copyResdom(Resdom *from)
624 Resdom *newnode = makeNode(Resdom);
626 newnode->resno = from->resno;
627 newnode->restype = from->restype;
628 newnode->restypmod = from->restypmod;
629 if (from->resname != NULL)
630 newnode->resname = pstrdup(from->resname);
631 newnode->ressortgroupref = from->ressortgroupref;
632 newnode->reskey = from->reskey;
633 newnode->reskeyop = from->reskeyop;
634 newnode->resjunk = from->resjunk;
640 _copyFjoin(Fjoin *from)
642 Fjoin *newnode = makeNode(Fjoin);
645 * copy node superclass fields
649 newnode->fj_initialized = from->fj_initialized;
650 newnode->fj_nNodes = from->fj_nNodes;
652 Node_Copy(from, newnode, fj_innerNode);
654 newnode->fj_results = (DatumPtr)
655 palloc((from->fj_nNodes) * sizeof(Datum));
656 memmove(from->fj_results,
658 (from->fj_nNodes) * sizeof(Datum));
660 newnode->fj_alwaysDone = (BoolPtr)
661 palloc((from->fj_nNodes) * sizeof(bool));
662 memmove(from->fj_alwaysDone,
663 newnode->fj_alwaysDone,
664 (from->fj_nNodes) * sizeof(bool));
675 _copyExpr(Expr *from)
677 Expr *newnode = makeNode(Expr);
680 * copy node superclass fields
683 newnode->typeOid = from->typeOid;
684 newnode->opType = from->opType;
686 Node_Copy(from, newnode, oper);
687 Node_Copy(from, newnode, args);
699 Var *newnode = makeNode(Var);
702 * copy remainder of node
705 newnode->varno = from->varno;
706 newnode->varattno = from->varattno;
707 newnode->vartype = from->vartype;
708 newnode->vartypmod = from->vartypmod;
709 newnode->varlevelsup = from->varlevelsup;
711 newnode->varnoold = from->varnoold;
712 newnode->varoattno = from->varoattno;
718 _copyAttr(Attr *from)
720 Attr *newnode = makeNode(Attr);
723 newnode->relname = pstrdup(from->relname);
724 Node_Copy(from, newnode, attrs);
734 _copyOper(Oper *from)
736 Oper *newnode = makeNode(Oper);
739 * copy remainder of node
742 newnode->opno = from->opno;
743 newnode->opid = from->opid;
744 newnode->opresulttype = from->opresulttype;
745 newnode->opsize = from->opsize;
748 * NOTE: shall we copy the cache structure or just the pointer ?
749 * Alternatively we can set 'op_fcache' to NULL, in which case the
750 * executor will initialize it when it needs it...
752 newnode->op_fcache = from->op_fcache;
762 _copyConst(Const *from)
764 Const *newnode = makeNode(Const);
767 * copy remainder of node
770 newnode->consttype = from->consttype;
771 newnode->constlen = from->constlen;
773 if (from->constbyval || from->constisnull)
776 * passed by value so just copy the datum.
777 * Also, don't try to copy struct when value is null!
780 newnode->constvalue = from->constvalue;
785 * not passed by value. datum contains a pointer.
788 int length = from->constlen;
790 if (length == -1) /* variable-length type? */
791 length = VARSIZE(from->constvalue);
792 newnode->constvalue = PointerGetDatum(palloc(length));
793 memcpy(DatumGetPointer(newnode->constvalue),
794 DatumGetPointer(from->constvalue),
798 newnode->constisnull = from->constisnull;
799 newnode->constbyval = from->constbyval;
800 newnode->constisset = from->constisset;
801 newnode->constiscast = from->constiscast;
811 _copyParam(Param *from)
813 Param *newnode = makeNode(Param);
816 * copy remainder of node
819 newnode->paramkind = from->paramkind;
820 newnode->paramid = from->paramid;
822 if (from->paramname != NULL)
823 newnode->paramname = pstrdup(from->paramname);
824 newnode->paramtype = from->paramtype;
825 Node_Copy(from, newnode, param_tlist);
835 _copyFunc(Func *from)
837 Func *newnode = makeNode(Func);
840 * copy remainder of node
843 newnode->funcid = from->funcid;
844 newnode->functype = from->functype;
845 newnode->funcisindex = from->funcisindex;
846 newnode->funcsize = from->funcsize;
847 newnode->func_fcache = from->func_fcache;
848 Node_Copy(from, newnode, func_tlist);
849 Node_Copy(from, newnode, func_planlist);
859 _copyAggref(Aggref *from)
861 Aggref *newnode = makeNode(Aggref);
864 * copy remainder of node
867 newnode->aggname = pstrdup(from->aggname);
868 newnode->basetype = from->basetype;
869 newnode->aggtype = from->aggtype;
870 Node_Copy(from, newnode, target);
871 newnode->usenulls = from->usenulls;
872 newnode->aggstar = from->aggstar;
873 newnode->aggdistinct = from->aggdistinct;
874 newnode->aggno = from->aggno; /* probably not needed */
884 _copySubLink(SubLink *from)
886 SubLink *newnode = makeNode(SubLink);
889 * copy remainder of node
892 newnode->subLinkType = from->subLinkType;
893 newnode->useor = from->useor;
894 Node_Copy(from, newnode, lefthand);
895 Node_Copy(from, newnode, oper);
896 Node_Copy(from, newnode, subselect);
906 _copyRelabelType(RelabelType *from)
908 RelabelType *newnode = makeNode(RelabelType);
911 * copy remainder of node
914 Node_Copy(from, newnode, arg);
915 newnode->resulttype = from->resulttype;
916 newnode->resulttypmod = from->resulttypmod;
926 _copyCaseExpr(CaseExpr *from)
928 CaseExpr *newnode = makeNode(CaseExpr);
931 * copy remainder of node
934 newnode->casetype = from->casetype;
936 Node_Copy(from, newnode, arg);
937 Node_Copy(from, newnode, args);
938 Node_Copy(from, newnode, defresult);
948 _copyCaseWhen(CaseWhen *from)
950 CaseWhen *newnode = makeNode(CaseWhen);
953 * copy remainder of node
956 Node_Copy(from, newnode, expr);
957 Node_Copy(from, newnode, result);
963 _copyArray(Array *from)
965 Array *newnode = makeNode(Array);
968 * copy remainder of node
971 newnode->arrayelemtype = from->arrayelemtype;
972 newnode->arrayelemlength = from->arrayelemlength;
973 newnode->arrayelembyval = from->arrayelembyval;
974 newnode->arrayndim = from->arrayndim;
975 newnode->arraylow = from->arraylow;
976 newnode->arrayhigh = from->arrayhigh;
977 newnode->arraylen = from->arraylen;
983 _copyArrayRef(ArrayRef *from)
985 ArrayRef *newnode = makeNode(ArrayRef);
988 * copy remainder of node
991 newnode->refattrlength = from->refattrlength;
992 newnode->refelemlength = from->refelemlength;
993 newnode->refelemtype = from->refelemtype;
994 newnode->refelembyval = from->refelembyval;
996 Node_Copy(from, newnode, refupperindexpr);
997 Node_Copy(from, newnode, reflowerindexpr);
998 Node_Copy(from, newnode, refexpr);
999 Node_Copy(from, newnode, refassgnexpr);
1004 /* ****************************************************************
1005 * relation.h copy functions
1006 * ****************************************************************
1014 * when you change this, also make sure to fix up xfunc_copyRelOptInfo in
1015 * planner/path/xfunc.c accordingly!!!
1019 _copyRelOptInfo(RelOptInfo *from)
1021 RelOptInfo *newnode = makeNode(RelOptInfo);
1023 newnode->relids = listCopy(from->relids);
1025 newnode->rows = from->rows;
1026 newnode->width = from->width;
1028 Node_Copy(from, newnode, targetlist);
1029 Node_Copy(from, newnode, pathlist);
1030 /* XXX cheapest-path fields should point to members of pathlist? */
1031 Node_Copy(from, newnode, cheapest_startup_path);
1032 Node_Copy(from, newnode, cheapest_total_path);
1033 newnode->pruneable = from->pruneable;
1035 newnode->indexed = from->indexed;
1036 newnode->pages = from->pages;
1037 newnode->tuples = from->tuples;
1039 Node_Copy(from, newnode, baserestrictinfo);
1040 newnode->baserestrictcost = from->baserestrictcost;
1041 Node_Copy(from, newnode, joininfo);
1042 Node_Copy(from, newnode, innerjoin);
1051 static IndexOptInfo *
1052 _copyIndexOptInfo(IndexOptInfo *from)
1054 IndexOptInfo *newnode = makeNode(IndexOptInfo);
1058 newnode->indexoid = from->indexoid;
1059 newnode->pages = from->pages;
1060 newnode->tuples = from->tuples;
1062 if (from->classlist)
1064 for (len = 0; from->classlist[len] != 0; len++)
1066 newnode->classlist = (Oid *) palloc(sizeof(Oid) * (len + 1));
1067 for (i = 0; i < len; i++)
1068 newnode->classlist[i] = from->classlist[i];
1069 newnode->classlist[len] = 0;
1072 if (from->indexkeys)
1074 for (len = 0; from->indexkeys[len] != 0; len++)
1076 newnode->indexkeys = (int *) palloc(sizeof(int) * (len + 1));
1077 for (i = 0; i < len; i++)
1078 newnode->indexkeys[i] = from->indexkeys[i];
1079 newnode->indexkeys[len] = 0;
1084 for (len = 0; from->ordering[len] != 0; len++)
1086 newnode->ordering = (Oid *) palloc(sizeof(Oid) * (len + 1));
1087 for (i = 0; i < len; i++)
1088 newnode->ordering[i] = from->ordering[i];
1089 newnode->ordering[len] = 0;
1092 newnode->relam = from->relam;
1093 newnode->amcostestimate = from->amcostestimate;
1094 newnode->indproc = from->indproc;
1095 Node_Copy(from, newnode, indpred);
1096 newnode->lossy = from->lossy;
1104 * This function copies the fields of the Path node. It is used by
1105 * all the copy functions for classes which inherit from Path.
1109 CopyPathFields(Path *from, Path *newnode)
1113 * Modify the next line, since it causes the copying to cycle (i.e.
1114 * the parent points right back here! -- JMH, 7/7/92. Old version:
1115 * Node_Copy(from, newnode, parent);
1117 newnode->parent = from->parent;
1119 newnode->startup_cost = from->startup_cost;
1120 newnode->total_cost = from->total_cost;
1122 newnode->pathtype = from->pathtype;
1124 Node_Copy(from, newnode, pathkeys);
1132 _copyPath(Path *from)
1134 Path *newnode = makeNode(Path);
1136 CopyPathFields(from, newnode);
1146 _copyIndexPath(IndexPath *from)
1148 IndexPath *newnode = makeNode(IndexPath);
1151 * copy the node superclass fields
1154 CopyPathFields((Path *) from, (Path *) newnode);
1157 * copy remainder of node
1160 newnode->indexid = listCopy(from->indexid);
1161 Node_Copy(from, newnode, indexqual);
1162 newnode->indexscandir = from->indexscandir;
1163 newnode->joinrelids = listCopy(from->joinrelids);
1164 newnode->rows = from->rows;
1174 _copyTidPath(TidPath *from)
1176 TidPath *newnode = makeNode(TidPath);
1179 * copy the node superclass fields
1182 CopyPathFields((Path *) from, (Path *) newnode);
1185 * copy remainder of node
1188 Node_Copy(from, newnode, tideval);
1189 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1195 * CopyJoinPathFields
1197 * This function copies the fields of the JoinPath node. It is used by
1198 * all the copy functions for classes which inherit from JoinPath.
1202 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1204 Node_Copy(from, newnode, outerjoinpath);
1205 Node_Copy(from, newnode, innerjoinpath);
1206 Node_Copy(from, newnode, joinrestrictinfo);
1214 _copyNestPath(NestPath *from)
1216 NestPath *newnode = makeNode(NestPath);
1219 * copy the node superclass fields
1222 CopyPathFields((Path *) from, (Path *) newnode);
1223 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1233 _copyMergePath(MergePath *from)
1235 MergePath *newnode = makeNode(MergePath);
1238 * copy the node superclass fields
1241 CopyPathFields((Path *) from, (Path *) newnode);
1242 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1245 * copy the remainder of the node
1248 Node_Copy(from, newnode, path_mergeclauses);
1249 Node_Copy(from, newnode, outersortkeys);
1250 Node_Copy(from, newnode, innersortkeys);
1260 _copyHashPath(HashPath *from)
1262 HashPath *newnode = makeNode(HashPath);
1265 * copy the node superclass fields
1268 CopyPathFields((Path *) from, (Path *) newnode);
1269 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1272 * copy remainder of node
1275 Node_Copy(from, newnode, path_hashclauses);
1284 static PathKeyItem *
1285 _copyPathKeyItem(PathKeyItem *from)
1287 PathKeyItem *newnode = makeNode(PathKeyItem);
1290 * copy remainder of node
1293 Node_Copy(from, newnode, key);
1294 newnode->sortop = from->sortop;
1303 static RestrictInfo *
1304 _copyRestrictInfo(RestrictInfo *from)
1306 RestrictInfo *newnode = makeNode(RestrictInfo);
1309 * copy remainder of node
1312 Node_Copy(from, newnode, clause);
1313 Node_Copy(from, newnode, subclauseindices);
1314 newnode->mergejoinoperator = from->mergejoinoperator;
1315 newnode->left_sortop = from->left_sortop;
1316 newnode->right_sortop = from->right_sortop;
1317 newnode->hashjoinoperator = from->hashjoinoperator;
1327 _copyJoinInfo(JoinInfo *from)
1329 JoinInfo *newnode = makeNode(JoinInfo);
1332 * copy remainder of node
1335 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1336 Node_Copy(from, newnode, jinfo_restrictinfo);
1342 _copyIter(Iter *from)
1344 Iter *newnode = makeNode(Iter);
1346 Node_Copy(from, newnode, iterexpr);
1347 newnode->itertype = from->itertype;
1353 _copyStream(Stream *from)
1355 Stream *newnode = makeNode(Stream);
1357 newnode->pathptr = from->pathptr;
1358 newnode->cinfo = from->cinfo;
1359 newnode->clausetype = from->clausetype;
1361 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1363 Node_Copy(from, newnode, downstream);
1364 if (newnode->downstream)
1365 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1367 newnode->groupup = from->groupup;
1368 newnode->groupcost = from->groupcost;
1369 newnode->groupsel = from->groupsel;
1374 /* ****************************************************************
1375 * parsenodes.h copy functions
1376 * ****************************************************************
1379 static TargetEntry *
1380 _copyTargetEntry(TargetEntry *from)
1382 TargetEntry *newnode = makeNode(TargetEntry);
1384 Node_Copy(from, newnode, resdom);
1385 Node_Copy(from, newnode, fjoin);
1386 Node_Copy(from, newnode, expr);
1390 static RangeTblEntry *
1391 _copyRangeTblEntry(RangeTblEntry *from)
1393 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1396 newnode->relname = pstrdup(from->relname);
1397 Node_Copy(from, newnode, ref);
1398 Node_Copy(from, newnode, eref);
1399 newnode->relid = from->relid;
1400 newnode->inh = from->inh;
1401 newnode->inFromCl = from->inFromCl;
1402 newnode->inJoinSet = from->inJoinSet;
1403 newnode->skipAcl = from->skipAcl;
1409 _copyRowMark(RowMark *from)
1411 RowMark *newnode = makeNode(RowMark);
1413 newnode->rti = from->rti;
1414 newnode->info = from->info;
1420 _copySortClause(SortClause *from)
1422 SortClause *newnode = makeNode(SortClause);
1424 newnode->tleSortGroupRef = from->tleSortGroupRef;
1425 newnode->sortop = from->sortop;
1431 _copyAConst(A_Const *from)
1433 A_Const *newnode = makeNode(A_Const);
1435 newnode->val = *((Value *) (copyObject(&(from->val))));
1436 Node_Copy(from, newnode, typename);
1442 _copyTypeName(TypeName *from)
1444 TypeName *newnode = makeNode(TypeName);
1447 newnode->name = pstrdup(from->name);
1448 newnode->timezone = from->timezone;
1449 newnode->setof = from->setof;
1450 newnode->typmod = from->typmod;
1451 Node_Copy(from, newnode, arrayBounds);
1457 _copyTypeCast(TypeCast *from)
1459 TypeCast *newnode = makeNode(TypeCast);
1461 Node_Copy(from, newnode, arg);
1462 Node_Copy(from, newnode, typename);
1468 _copyQuery(Query *from)
1470 Query *newnode = makeNode(Query);
1472 newnode->commandType = from->commandType;
1473 Node_Copy(from, newnode, utilityStmt);
1474 newnode->resultRelation = from->resultRelation;
1476 newnode->into = pstrdup(from->into);
1477 newnode->isPortal = from->isPortal;
1478 newnode->isBinary = from->isBinary;
1479 newnode->isTemp = from->isTemp;
1480 newnode->unionall = from->unionall;
1481 newnode->hasAggs = from->hasAggs;
1482 newnode->hasSubLinks = from->hasSubLinks;
1484 Node_Copy(from, newnode, rtable);
1485 Node_Copy(from, newnode, targetList);
1486 Node_Copy(from, newnode, qual);
1487 Node_Copy(from, newnode, rowMark);
1489 Node_Copy(from, newnode, distinctClause);
1490 Node_Copy(from, newnode, sortClause);
1491 Node_Copy(from, newnode, groupClause);
1492 Node_Copy(from, newnode, havingQual);
1494 /* why is intersectClause missing? */
1495 Node_Copy(from, newnode, unionClause);
1497 Node_Copy(from, newnode, limitOffset);
1498 Node_Copy(from, newnode, limitCount);
1501 * We do not copy the planner internal fields: base_rel_list,
1502 * join_rel_list, equi_key_list, query_pathkeys. Not entirely clear if
1509 static ClosePortalStmt *
1510 _copyClosePortalStmt(ClosePortalStmt *from)
1512 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1514 if (from->portalname)
1515 newnode->portalname = pstrdup(from->portalname);
1520 static TruncateStmt *
1521 _copyTruncateStmt(TruncateStmt *from)
1523 TruncateStmt *newnode = makeNode(TruncateStmt);
1525 newnode->relName = pstrdup(from->relName);
1531 _copyNotifyStmt(NotifyStmt *from)
1533 NotifyStmt *newnode = makeNode(NotifyStmt);
1536 newnode->relname = pstrdup(from->relname);
1542 _copyListenStmt(ListenStmt *from)
1544 ListenStmt *newnode = makeNode(ListenStmt);
1547 newnode->relname = pstrdup(from->relname);
1552 static UnlistenStmt *
1553 _copyUnlistenStmt(UnlistenStmt *from)
1555 UnlistenStmt *newnode = makeNode(UnlistenStmt);
1558 newnode->relname = pstrdup(from->relname);
1563 static TransactionStmt *
1564 _copyTransactionStmt(TransactionStmt *from)
1566 TransactionStmt *newnode = makeNode(TransactionStmt);
1568 newnode->command = from->command;
1574 _copyLoadStmt(LoadStmt *from)
1576 LoadStmt *newnode = makeNode(LoadStmt);
1579 newnode->filename = pstrdup(from->filename);
1584 static VariableSetStmt *
1585 _copyVariableSetStmt(VariableSetStmt *from)
1587 VariableSetStmt *newnode = makeNode(VariableSetStmt);
1590 newnode->name = pstrdup(from->name);
1592 newnode->value = pstrdup(from->value);
1597 static VariableResetStmt *
1598 _copyVariableResetStmt(VariableResetStmt *from)
1600 VariableResetStmt *newnode = makeNode(VariableResetStmt);
1603 newnode->name = pstrdup(from->name);
1609 _copyLockStmt(LockStmt *from)
1611 LockStmt *newnode = makeNode(LockStmt);
1614 newnode->relname = pstrdup(from->relname);
1615 newnode->mode = from->mode;
1621 /* ****************************************************************
1622 * pg_list.h copy functions
1623 * ****************************************************************
1627 _copyValue(Value *from)
1629 Value *newnode = makeNode(Value);
1631 newnode->type = from->type;
1635 newnode->val.ival = from->val.ival;
1639 newnode->val.str = pstrdup(from->val.str);
1648 * copyObject returns a copy of the node or list. If it is a list, it
1649 * recursively copies its items.
1653 copyObject(void *from)
1659 switch (nodeTag(from))
1666 retval = _copyPlan(from);
1669 retval = _copyResult(from);
1672 retval = _copyAppend(from);
1675 retval = _copyScan(from);
1678 retval = _copySeqScan(from);
1681 retval = _copyIndexScan(from);
1684 retval = _copyTidScan(from);
1687 retval = _copyJoin(from);
1690 retval = _copyNestLoop(from);
1693 retval = _copyMergeJoin(from);
1696 retval = _copyHashJoin(from);
1699 retval = _copyNoname(from);
1702 retval = _copyMaterial(from);
1705 retval = _copySort(from);
1708 retval = _copyGroup(from);
1711 retval = _copyAgg(from);
1714 retval = _copyGroupClause(from);
1717 retval = _copyUnique(from);
1720 retval = _copyHash(from);
1723 retval = _copySubPlan(from);
1730 retval = _copyResdom(from);
1733 retval = _copyFjoin(from);
1736 retval = _copyExpr(from);
1739 retval = _copyVar(from);
1742 retval = _copyAttr(from);
1745 retval = _copyOper(from);
1748 retval = _copyConst(from);
1751 retval = _copyParam(from);
1754 retval = _copyFunc(from);
1757 retval = _copyArray(from);
1760 retval = _copyArrayRef(from);
1763 retval = _copyAggref(from);
1766 retval = _copySubLink(from);
1769 retval = _copyRelabelType(from);
1772 retval = _copyCaseExpr(from);
1775 retval = _copyCaseWhen(from);
1782 retval = _copyRelOptInfo(from);
1785 retval = _copyPath(from);
1788 retval = _copyIndexPath(from);
1791 retval = _copyTidPath(from);
1794 retval = _copyNestPath(from);
1797 retval = _copyMergePath(from);
1800 retval = _copyHashPath(from);
1803 retval = _copyPathKeyItem(from);
1805 case T_RestrictInfo:
1806 retval = _copyRestrictInfo(from);
1809 retval = _copyJoinInfo(from);
1812 retval = _copyIter(from);
1815 retval = _copyStream(from);
1817 case T_IndexOptInfo:
1818 retval = _copyIndexOptInfo(from);
1825 retval = _copyTargetEntry(from);
1827 case T_RangeTblEntry:
1828 retval = _copyRangeTblEntry(from);
1831 retval = _copyRowMark(from);
1834 retval = _copySortClause(from);
1837 retval = _copyAConst(from);
1840 retval = _copyTypeName(from);
1843 retval = _copyTypeCast(from);
1846 retval = _copyQuery(from);
1848 case T_ClosePortalStmt:
1849 retval = _copyClosePortalStmt(from);
1851 case T_TruncateStmt:
1852 retval = _copyTruncateStmt(from);
1855 retval = _copyNotifyStmt(from);
1858 retval = _copyListenStmt(from);
1860 case T_UnlistenStmt:
1861 retval = _copyUnlistenStmt(from);
1863 case T_TransactionStmt:
1864 retval = _copyTransactionStmt(from);
1867 retval = _copyLoadStmt(from);
1869 case T_VariableSetStmt:
1870 retval = _copyVariableSetStmt(from);
1872 case T_VariableResetStmt:
1873 retval = _copyVariableResetStmt(from);
1876 retval = _copyLockStmt(from);
1885 retval = _copyValue(from);
1893 /* rather ugly coding for speed... */
1894 /* Note the input list cannot be NIL if we got here. */
1895 nl = lcons(copyObject(lfirst(list)), NIL);
1898 foreach(l, lnext(list))
1900 lnext(nl) = lcons(copyObject(lfirst(l)), NIL);
1906 elog(ERROR, "copyObject: don't know how to copy %d", nodeTag(from));