1 /*-------------------------------------------------------------------------
4 * Copy functions for Postgres tree nodes.
6 * Copyright (c) 1994, Regents of the University of California
10 * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.99 2000/01/09 00:26:22 tgl Exp $
12 *-------------------------------------------------------------------------
17 #include "optimizer/planmain.h"
18 #include "optimizer/subselect.h"
23 * a macro to simplify calling of copyObject on the specified field
25 #define Node_Copy(from, newnode, field) \
26 ((newnode)->field = copyObject((from)->field))
31 * This copy function only copies the "cons-cells" of the list, not the
32 * pointed-to objects. (Use copyObject if you want a "deep" copy.)
34 * We also use this function for copying lists of integers, which is
35 * grotty but unlikely to break --- it could fail if sizeof(pointer)
36 * is less than sizeof(int), but I don't know any such machines...
38 * Note that copyObject will surely coredump if applied to a list
48 /* rather ugly coding for speed... */
52 newlist = nl = lcons(lfirst(list), NIL);
54 foreach(l, lnext(list))
56 lnext(nl) = lcons(lfirst(l), NIL);
62 /* ****************************************************************
63 * plannodes.h copy functions
64 * ****************************************************************
70 * This function copies the fields of the Plan node. It is used by
71 * all the copy functions for classes which inherit from Plan.
75 CopyPlanFields(Plan *from, Plan *newnode)
77 newnode->cost = from->cost;
78 newnode->plan_rows = from->plan_rows;
79 newnode->plan_width = from->plan_width;
80 /* state is NOT copied */
81 newnode->targetlist = copyObject(from->targetlist);
82 newnode->qual = copyObject(from->qual);
83 newnode->lefttree = copyObject(from->lefttree);
84 newnode->righttree = copyObject(from->righttree);
85 newnode->extParam = listCopy(from->extParam);
86 newnode->locParam = listCopy(from->locParam);
87 newnode->chgParam = listCopy(from->chgParam);
88 Node_Copy(from, newnode, initPlan);
89 if (from->subPlan != NIL)
90 newnode->subPlan = nconc(SS_pull_subplan((Node *) newnode->targetlist),
91 SS_pull_subplan((Node *) newnode->qual));
93 newnode->subPlan = NIL;
94 newnode->nParamExec = from->nParamExec;
102 _copyPlan(Plan *from)
104 Plan *newnode = makeNode(Plan);
107 * copy the node superclass fields
110 CopyPlanFields(from, newnode);
121 _copyResult(Result *from)
123 Result *newnode = makeNode(Result);
126 * copy node superclass fields
129 CopyPlanFields((Plan *) from, (Plan *) newnode);
132 * copy remainder of node
135 Node_Copy(from, newnode, resconstantqual);
138 * We must add subplans in resconstantqual to the new plan's subPlan
141 if (from->plan.subPlan != NIL)
142 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
143 SS_pull_subplan(newnode->resconstantqual));
153 _copyAppend(Append *from)
155 Append *newnode = makeNode(Append);
158 * copy node superclass fields
161 CopyPlanFields((Plan *) from, (Plan *) newnode);
164 * copy remainder of node
167 Node_Copy(from, newnode, appendplans);
168 Node_Copy(from, newnode, unionrtables);
169 newnode->inheritrelid = from->inheritrelid;
170 Node_Copy(from, newnode, inheritrtable);
179 * This function copies the fields of the Scan node. It is used by
180 * all the copy functions for classes which inherit from Scan.
184 CopyScanFields(Scan *from, Scan *newnode)
186 newnode->scanrelid = from->scanrelid;
195 _copyScan(Scan *from)
197 Scan *newnode = makeNode(Scan);
200 * copy node superclass fields
203 CopyPlanFields((Plan *) from, (Plan *) newnode);
204 CopyScanFields((Scan *) from, (Scan *) newnode);
214 _copySeqScan(SeqScan *from)
216 SeqScan *newnode = makeNode(SeqScan);
219 * copy node superclass fields
222 CopyPlanFields((Plan *) from, (Plan *) newnode);
223 CopyScanFields((Scan *) from, (Scan *) newnode);
233 _copyIndexScan(IndexScan *from)
235 IndexScan *newnode = makeNode(IndexScan);
238 * copy node superclass fields
241 CopyPlanFields((Plan *) from, (Plan *) newnode);
242 CopyScanFields((Scan *) from, (Scan *) newnode);
245 * copy remainder of node
248 newnode->indxid = listCopy(from->indxid);
249 Node_Copy(from, newnode, indxqual);
250 Node_Copy(from, newnode, indxqualorig);
251 newnode->indxorderdir = from->indxorderdir;
261 _copyTidScan(TidScan *from)
263 TidScan *newnode = makeNode(TidScan);
266 * copy node superclass fields
269 CopyPlanFields((Plan *) from, (Plan *) newnode);
270 CopyScanFields((Scan *) from, (Scan *) newnode);
272 * copy remainder of node
275 newnode->needRescan = from->needRescan;
276 Node_Copy(from, newnode, tideval);
285 * This function copies the fields of the Join node. It is used by
286 * all the copy functions for classes which inherit from Join.
290 CopyJoinFields(Join *from, Join *newnode)
302 _copyJoin(Join *from)
304 Join *newnode = makeNode(Join);
307 * copy node superclass fields
310 CopyPlanFields((Plan *) from, (Plan *) newnode);
311 CopyJoinFields(from, newnode);
322 _copyNestLoop(NestLoop *from)
324 NestLoop *newnode = makeNode(NestLoop);
327 * copy node superclass fields
330 CopyPlanFields((Plan *) from, (Plan *) newnode);
331 CopyJoinFields((Join *) from, (Join *) newnode);
342 _copyMergeJoin(MergeJoin *from)
344 MergeJoin *newnode = makeNode(MergeJoin);
347 * copy node superclass fields
350 CopyPlanFields((Plan *) from, (Plan *) newnode);
351 CopyJoinFields((Join *) from, (Join *) newnode);
354 * copy remainder of node
357 Node_Copy(from, newnode, mergeclauses);
367 _copyHashJoin(HashJoin *from)
369 HashJoin *newnode = makeNode(HashJoin);
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, hashclauses);
384 newnode->hashjoinop = from->hashjoinop;
393 * This function copies the fields of the Noname node. It is used by
394 * all the copy functions for classes which inherit from Noname.
398 CopyNonameFields(Noname *from, Noname *newnode)
400 newnode->nonameid = from->nonameid;
401 newnode->keycount = from->keycount;
411 _copyNoname(Noname *from)
413 Noname *newnode = makeNode(Noname);
416 * copy node superclass fields
419 CopyPlanFields((Plan *) from, (Plan *) newnode);
420 CopyNonameFields(from, newnode);
430 _copyMaterial(Material *from)
432 Material *newnode = makeNode(Material);
435 * copy node superclass fields
438 CopyPlanFields((Plan *) from, (Plan *) newnode);
439 CopyNonameFields((Noname *) from, (Noname *) newnode);
450 _copySort(Sort *from)
452 Sort *newnode = makeNode(Sort);
455 * copy node superclass fields
458 CopyPlanFields((Plan *) from, (Plan *) newnode);
459 CopyNonameFields((Noname *) from, (Noname *) newnode);
470 _copyGroup(Group *from)
472 Group *newnode = makeNode(Group);
474 CopyPlanFields((Plan *) from, (Plan *) newnode);
476 newnode->tuplePerGroup = from->tuplePerGroup;
477 newnode->numCols = from->numCols;
478 newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
479 memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
491 Agg *newnode = makeNode(Agg);
493 CopyPlanFields((Plan *) from, (Plan *) newnode);
503 _copyGroupClause(GroupClause *from)
505 GroupClause *newnode = makeNode(GroupClause);
507 newnode->tleSortGroupRef = from->tleSortGroupRef;
508 newnode->sortop = from->sortop;
519 _copyUnique(Unique *from)
521 Unique *newnode = makeNode(Unique);
524 * copy node superclass fields
527 CopyPlanFields((Plan *) from, (Plan *) newnode);
528 CopyNonameFields((Noname *) from, (Noname *) newnode);
531 * copy remainder of node
534 if (from->uniqueAttr)
535 newnode->uniqueAttr = pstrdup(from->uniqueAttr);
537 newnode->uniqueAttr = NULL;
538 newnode->uniqueAttrNum = from->uniqueAttrNum;
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;
697 _copyOper(Oper *from)
699 Oper *newnode = makeNode(Oper);
702 * copy remainder of node
705 newnode->opno = from->opno;
706 newnode->opid = from->opid;
707 newnode->opresulttype = from->opresulttype;
708 newnode->opsize = from->opsize;
711 * NOTE: shall we copy the cache structure or just the pointer ?
712 * Alternatively we can set 'op_fcache' to NULL, in which case the
713 * executor will initialize it when it needs it...
715 newnode->op_fcache = from->op_fcache;
725 _copyConst(Const *from)
727 Const *newnode = makeNode(Const);
730 * copy remainder of node
733 newnode->consttype = from->consttype;
734 newnode->constlen = from->constlen;
736 if (from->constbyval || from->constisnull)
739 * passed by value so just copy the datum.
740 * Also, don't try to copy struct when value is null!
743 newnode->constvalue = from->constvalue;
748 * not passed by value. datum contains a pointer.
751 int length = from->constlen;
753 if (length == -1) /* variable-length type? */
754 length = VARSIZE(from->constvalue);
755 newnode->constvalue = PointerGetDatum(palloc(length));
756 memcpy(DatumGetPointer(newnode->constvalue),
757 DatumGetPointer(from->constvalue),
761 newnode->constisnull = from->constisnull;
762 newnode->constbyval = from->constbyval;
763 newnode->constisset = from->constisset;
764 newnode->constiscast = from->constiscast;
774 _copyParam(Param *from)
776 Param *newnode = makeNode(Param);
779 * copy remainder of node
782 newnode->paramkind = from->paramkind;
783 newnode->paramid = from->paramid;
785 if (from->paramname != NULL)
786 newnode->paramname = pstrdup(from->paramname);
787 newnode->paramtype = from->paramtype;
788 Node_Copy(from, newnode, param_tlist);
798 _copyFunc(Func *from)
800 Func *newnode = makeNode(Func);
803 * copy remainder of node
806 newnode->funcid = from->funcid;
807 newnode->functype = from->functype;
808 newnode->funcisindex = from->funcisindex;
809 newnode->funcsize = from->funcsize;
810 newnode->func_fcache = from->func_fcache;
811 Node_Copy(from, newnode, func_tlist);
812 Node_Copy(from, newnode, func_planlist);
822 _copyAggref(Aggref *from)
824 Aggref *newnode = makeNode(Aggref);
827 * copy remainder of node
830 newnode->aggname = pstrdup(from->aggname);
831 newnode->basetype = from->basetype;
832 newnode->aggtype = from->aggtype;
833 Node_Copy(from, newnode, target);
834 newnode->usenulls = from->usenulls;
835 newnode->aggstar = from->aggstar;
836 newnode->aggdistinct = from->aggdistinct;
837 newnode->aggno = from->aggno; /* probably not needed */
847 _copySubLink(SubLink *from)
849 SubLink *newnode = makeNode(SubLink);
852 * copy remainder of node
855 newnode->subLinkType = from->subLinkType;
856 newnode->useor = from->useor;
857 Node_Copy(from, newnode, lefthand);
858 Node_Copy(from, newnode, oper);
859 Node_Copy(from, newnode, subselect);
869 _copyCaseExpr(CaseExpr *from)
871 CaseExpr *newnode = makeNode(CaseExpr);
874 * copy remainder of node
877 newnode->casetype = from->casetype;
879 Node_Copy(from, newnode, arg);
880 Node_Copy(from, newnode, args);
881 Node_Copy(from, newnode, defresult);
891 _copyCaseWhen(CaseWhen *from)
893 CaseWhen *newnode = makeNode(CaseWhen);
896 * copy remainder of node
899 Node_Copy(from, newnode, expr);
900 Node_Copy(from, newnode, result);
906 _copyArray(Array *from)
908 Array *newnode = makeNode(Array);
911 * copy remainder of node
914 newnode->arrayelemtype = from->arrayelemtype;
915 newnode->arrayelemlength = from->arrayelemlength;
916 newnode->arrayelembyval = from->arrayelembyval;
917 newnode->arrayndim = from->arrayndim;
918 newnode->arraylow = from->arraylow;
919 newnode->arrayhigh = from->arrayhigh;
920 newnode->arraylen = from->arraylen;
926 _copyArrayRef(ArrayRef *from)
928 ArrayRef *newnode = makeNode(ArrayRef);
931 * copy remainder of node
934 newnode->refattrlength = from->refattrlength;
935 newnode->refelemlength = from->refelemlength;
936 newnode->refelemtype = from->refelemtype;
937 newnode->refelembyval = from->refelembyval;
939 Node_Copy(from, newnode, refupperindexpr);
940 Node_Copy(from, newnode, reflowerindexpr);
941 Node_Copy(from, newnode, refexpr);
942 Node_Copy(from, newnode, refassgnexpr);
947 /* ****************************************************************
948 * relation.h copy functions
949 * ****************************************************************
957 * when you change this, also make sure to fix up xfunc_copyRelOptInfo in
958 * planner/path/xfunc.c accordingly!!!
962 _copyRelOptInfo(RelOptInfo *from)
964 RelOptInfo *newnode = makeNode(RelOptInfo);
966 newnode->relids = listCopy(from->relids);
968 newnode->rows = from->rows;
969 newnode->width = from->width;
971 Node_Copy(from, newnode, targetlist);
972 Node_Copy(from, newnode, pathlist);
973 /* XXX cheapestpath should point to a member of pathlist? */
974 Node_Copy(from, newnode, cheapestpath);
975 newnode->pruneable = from->pruneable;
977 newnode->indexed = from->indexed;
978 newnode->pages = from->pages;
979 newnode->tuples = from->tuples;
981 Node_Copy(from, newnode, restrictinfo);
982 Node_Copy(from, newnode, joininfo);
983 Node_Copy(from, newnode, innerjoin);
992 static IndexOptInfo *
993 _copyIndexOptInfo(IndexOptInfo *from)
995 IndexOptInfo *newnode = makeNode(IndexOptInfo);
999 newnode->indexoid = from->indexoid;
1000 newnode->pages = from->pages;
1001 newnode->tuples = from->tuples;
1003 if (from->classlist)
1005 for (len = 0; from->classlist[len] != 0; len++)
1007 newnode->classlist = (Oid *) palloc(sizeof(Oid) * (len + 1));
1008 for (i = 0; i < len; i++)
1009 newnode->classlist[i] = from->classlist[i];
1010 newnode->classlist[len] = 0;
1013 if (from->indexkeys)
1015 for (len = 0; from->indexkeys[len] != 0; len++)
1017 newnode->indexkeys = (int *) palloc(sizeof(int) * (len + 1));
1018 for (i = 0; i < len; i++)
1019 newnode->indexkeys[i] = from->indexkeys[i];
1020 newnode->indexkeys[len] = 0;
1025 for (len = 0; from->ordering[len] != 0; len++)
1027 newnode->ordering = (Oid *) palloc(sizeof(Oid) * (len + 1));
1028 for (i = 0; i < len; i++)
1029 newnode->ordering[i] = from->ordering[i];
1030 newnode->ordering[len] = 0;
1033 newnode->relam = from->relam;
1034 newnode->indproc = from->indproc;
1035 Node_Copy(from, newnode, indpred);
1043 * This function copies the fields of the Path node. It is used by
1044 * all the copy functions for classes which inherit from Path.
1048 CopyPathFields(Path *from, Path *newnode)
1051 * Modify the next line, since it causes the copying to cycle (i.e.
1052 * the parent points right back here! -- JMH, 7/7/92. Old version:
1053 * Node_Copy(from, newnode, parent);
1055 newnode->parent = from->parent;
1057 newnode->path_cost = from->path_cost;
1059 newnode->pathtype = from->pathtype;
1061 Node_Copy(from, newnode, pathkeys);
1069 _copyPath(Path *from)
1071 Path *newnode = makeNode(Path);
1073 CopyPathFields(from, newnode);
1083 _copyIndexPath(IndexPath *from)
1085 IndexPath *newnode = makeNode(IndexPath);
1088 * copy the node superclass fields
1091 CopyPathFields((Path *) from, (Path *) newnode);
1094 * copy remainder of node
1097 newnode->indexid = listCopy(from->indexid);
1098 Node_Copy(from, newnode, indexqual);
1099 newnode->joinrelids = listCopy(from->joinrelids);
1109 _copyTidPath(TidPath *from)
1111 TidPath *newnode = makeNode(TidPath);
1114 * copy the node superclass fields
1117 CopyPathFields((Path *) from, (Path *) newnode);
1120 * copy remainder of node
1123 Node_Copy(from, newnode, tideval);
1124 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1129 * CopyJoinPathFields
1131 * This function copies the fields of the JoinPath node. It is used by
1132 * all the copy functions for classes which inherit from JoinPath.
1136 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1138 Node_Copy(from, newnode, outerjoinpath);
1139 Node_Copy(from, newnode, innerjoinpath);
1147 _copyNestPath(NestPath *from)
1149 NestPath *newnode = makeNode(NestPath);
1152 * copy the node superclass fields
1155 CopyPathFields((Path *) from, (Path *) newnode);
1156 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1166 _copyMergePath(MergePath *from)
1168 MergePath *newnode = makeNode(MergePath);
1171 * copy the node superclass fields
1174 CopyPathFields((Path *) from, (Path *) newnode);
1175 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1178 * copy the remainder of the node
1181 Node_Copy(from, newnode, path_mergeclauses);
1182 Node_Copy(from, newnode, outersortkeys);
1183 Node_Copy(from, newnode, innersortkeys);
1193 _copyHashPath(HashPath *from)
1195 HashPath *newnode = makeNode(HashPath);
1198 * copy the node superclass fields
1201 CopyPathFields((Path *) from, (Path *) newnode);
1202 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1205 * copy remainder of node
1208 Node_Copy(from, newnode, path_hashclauses);
1217 static PathKeyItem *
1218 _copyPathKeyItem(PathKeyItem *from)
1220 PathKeyItem *newnode = makeNode(PathKeyItem);
1223 * copy remainder of node
1226 Node_Copy(from, newnode, key);
1227 newnode->sortop = from->sortop;
1236 static RestrictInfo *
1237 _copyRestrictInfo(RestrictInfo *from)
1239 RestrictInfo *newnode = makeNode(RestrictInfo);
1242 * copy remainder of node
1245 Node_Copy(from, newnode, clause);
1246 Node_Copy(from, newnode, subclauseindices);
1247 newnode->mergejoinoperator = from->mergejoinoperator;
1248 newnode->left_sortop = from->left_sortop;
1249 newnode->right_sortop = from->right_sortop;
1250 newnode->hashjoinoperator = from->hashjoinoperator;
1260 _copyJoinInfo(JoinInfo *from)
1262 JoinInfo *newnode = makeNode(JoinInfo);
1265 * copy remainder of node
1268 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1269 Node_Copy(from, newnode, jinfo_restrictinfo);
1275 _copyIter(Iter *from)
1277 Iter *newnode = makeNode(Iter);
1279 Node_Copy(from, newnode, iterexpr);
1280 newnode->itertype = from->itertype;
1286 _copyStream(Stream *from)
1288 Stream *newnode = makeNode(Stream);
1290 newnode->pathptr = from->pathptr;
1291 newnode->cinfo = from->cinfo;
1292 newnode->clausetype = from->clausetype;
1294 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1296 Node_Copy(from, newnode, downstream);
1297 if (newnode->downstream)
1298 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1300 newnode->groupup = from->groupup;
1301 newnode->groupcost = from->groupcost;
1302 newnode->groupsel = from->groupsel;
1308 * parsenodes.h routines have no copy functions
1311 static TargetEntry *
1312 _copyTargetEntry(TargetEntry *from)
1314 TargetEntry *newnode = makeNode(TargetEntry);
1316 Node_Copy(from, newnode, resdom);
1317 Node_Copy(from, newnode, fjoin);
1318 Node_Copy(from, newnode, expr);
1322 static RangeTblEntry *
1323 _copyRangeTblEntry(RangeTblEntry *from)
1325 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1328 newnode->relname = pstrdup(from->relname);
1330 newnode->refname = pstrdup(from->refname);
1331 newnode->relid = from->relid;
1332 newnode->inh = from->inh;
1333 newnode->inFromCl = from->inFromCl;
1334 newnode->inJoinSet = from->inJoinSet;
1335 newnode->skipAcl = from->skipAcl;
1341 _copyRowMark(RowMark *from)
1343 RowMark *newnode = makeNode(RowMark);
1345 newnode->rti = from->rti;
1346 newnode->info = from->info;
1352 _copySortClause(SortClause *from)
1354 SortClause *newnode = makeNode(SortClause);
1356 newnode->tleSortGroupRef = from->tleSortGroupRef;
1357 newnode->sortop = from->sortop;
1363 _copyAConst(A_Const *from)
1365 A_Const *newnode = makeNode(A_Const);
1367 newnode->val = *((Value *) (copyObject(&(from->val))));
1368 Node_Copy(from, newnode, typename);
1374 _copyTypeName(TypeName *from)
1376 TypeName *newnode = makeNode(TypeName);
1379 newnode->name = pstrdup(from->name);
1380 newnode->timezone = from->timezone;
1381 newnode->setof = from->setof;
1382 newnode->typmod = from->typmod;
1383 Node_Copy(from, newnode, arrayBounds);
1389 _copyQuery(Query *from)
1391 Query *newnode = makeNode(Query);
1393 newnode->commandType = from->commandType;
1394 if (from->utilityStmt && nodeTag(from->utilityStmt) == T_NotifyStmt)
1396 NotifyStmt *from_notify = (NotifyStmt *) from->utilityStmt;
1397 NotifyStmt *n = makeNode(NotifyStmt);
1399 n->relname = pstrdup(from_notify->relname);
1400 newnode->utilityStmt = (Node *) n;
1402 newnode->resultRelation = from->resultRelation;
1404 newnode->into = pstrdup(from->into);
1405 newnode->isPortal = from->isPortal;
1406 newnode->isBinary = from->isBinary;
1407 newnode->isTemp = from->isTemp;
1408 newnode->unionall = from->unionall;
1409 newnode->hasAggs = from->hasAggs;
1410 newnode->hasSubLinks = from->hasSubLinks;
1412 Node_Copy(from, newnode, rtable);
1413 Node_Copy(from, newnode, targetList);
1414 Node_Copy(from, newnode, qual);
1415 Node_Copy(from, newnode, rowMark);
1417 if (from->uniqueFlag)
1418 newnode->uniqueFlag = pstrdup(from->uniqueFlag);
1419 Node_Copy(from, newnode, sortClause);
1420 Node_Copy(from, newnode, groupClause);
1421 Node_Copy(from, newnode, havingQual);
1423 /* why is intersectClause missing? */
1424 Node_Copy(from, newnode, unionClause);
1426 Node_Copy(from, newnode, limitOffset);
1427 Node_Copy(from, newnode, limitCount);
1429 /* we do not copy the planner internal fields: base_rel_list,
1430 * join_rel_list, query_pathkeys. Not entirely clear if this is right?
1438 * mnodes.h routines have no copy functions
1441 /* ****************************************************************
1442 * pg_list.h copy functions
1443 * ****************************************************************
1447 _copyValue(Value *from)
1449 Value *newnode = makeNode(Value);
1451 newnode->type = from->type;
1455 newnode->val.str = pstrdup(from->val.str);
1458 newnode->val.ival = from->val.ival;
1461 newnode->val.dval = from->val.dval;
1470 * copyObject returns a copy of the node or list. If it is a list, it
1471 * recursively copies its items.
1475 copyObject(void *from)
1481 switch (nodeTag(from))
1488 retval = _copyPlan(from);
1491 retval = _copyResult(from);
1494 retval = _copyAppend(from);
1497 retval = _copyScan(from);
1500 retval = _copySeqScan(from);
1503 retval = _copyIndexScan(from);
1506 retval = _copyTidScan(from);
1509 retval = _copyJoin(from);
1512 retval = _copyNestLoop(from);
1515 retval = _copyMergeJoin(from);
1518 retval = _copyHashJoin(from);
1521 retval = _copyNoname(from);
1524 retval = _copyMaterial(from);
1527 retval = _copySort(from);
1530 retval = _copyGroup(from);
1533 retval = _copyAgg(from);
1536 retval = _copyGroupClause(from);
1539 retval = _copyUnique(from);
1542 retval = _copyHash(from);
1545 retval = _copySubPlan(from);
1552 retval = _copyResdom(from);
1555 retval = _copyFjoin(from);
1558 retval = _copyExpr(from);
1561 retval = _copyVar(from);
1564 retval = _copyOper(from);
1567 retval = _copyConst(from);
1570 retval = _copyParam(from);
1573 retval = _copyFunc(from);
1576 retval = _copyArray(from);
1579 retval = _copyArrayRef(from);
1582 retval = _copyAggref(from);
1585 retval = _copySubLink(from);
1588 retval = _copyCaseExpr(from);
1591 retval = _copyCaseWhen(from);
1598 retval = _copyRelOptInfo(from);
1601 retval = _copyPath(from);
1604 retval = _copyIndexPath(from);
1607 retval = _copyTidPath(from);
1610 retval = _copyNestPath(from);
1613 retval = _copyMergePath(from);
1616 retval = _copyHashPath(from);
1619 retval = _copyPathKeyItem(from);
1621 case T_RestrictInfo:
1622 retval = _copyRestrictInfo(from);
1625 retval = _copyJoinInfo(from);
1628 retval = _copyIter(from);
1631 retval = _copyStream(from);
1633 case T_IndexOptInfo:
1634 retval = _copyIndexOptInfo(from);
1641 retval = _copyQuery(from);
1644 retval = _copyTargetEntry(from);
1646 case T_RangeTblEntry:
1647 retval = _copyRangeTblEntry(from);
1650 retval = _copyRowMark(from);
1653 retval = _copySortClause(from);
1656 retval = _copyAConst(from);
1659 retval = _copyTypeName(from);
1668 retval = _copyValue(from);
1676 /* rather ugly coding for speed... */
1677 /* Note the input list cannot be NIL if we got here. */
1678 nl = lcons(copyObject(lfirst(list)), NIL);
1681 foreach(l, lnext(list))
1683 lnext(nl) = lcons(copyObject(lfirst(l)), NIL);
1689 elog(ERROR, "copyObject: don't know how to copy %d", nodeTag(from));