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.93 1999/10/07 04:23:03 tgl Exp $
12 *-------------------------------------------------------------------------
17 #include "catalog/pg_type.h"
18 #include "optimizer/planmain.h"
19 #include "optimizer/subselect.h"
20 #include "utils/syscache.h"
24 * this copy function only copies the "lcons-cells" of the list but not
25 * its contents. (good for list of pointers as well as list of integers).
37 newlist = nl = lcons(lfirst(l), NIL);
40 lnext(nl) = lcons(lfirst(l), NIL);
49 * a macro to simplify calling of copyObject on the specified field
51 #define Node_Copy(from, newnode, field) \
52 newnode->field = copyObject(from->field)
54 /* ****************************************************************
55 * plannodes.h copy functions
56 * ****************************************************************
62 * This function copies the fields of the Plan node. It is used by
63 * all the copy functions for classes which inherit from Plan.
67 CopyPlanFields(Plan *from, Plan *newnode)
69 newnode->cost = from->cost;
70 newnode->plan_size = from->plan_size;
71 newnode->plan_width = from->plan_width;
72 newnode->plan_tupperpage = from->plan_tupperpage;
73 newnode->targetlist = copyObject(from->targetlist);
74 newnode->qual = copyObject(from->qual);
75 newnode->lefttree = copyObject(from->lefttree);
76 newnode->righttree = copyObject(from->righttree);
77 newnode->extParam = listCopy(from->extParam);
78 newnode->locParam = listCopy(from->locParam);
79 newnode->chgParam = listCopy(from->chgParam);
80 Node_Copy(from, newnode, initPlan);
81 if (from->subPlan != NULL)
82 newnode->subPlan = SS_pull_subplan((Node *) newnode->qual);
84 newnode->subPlan = NULL;
85 newnode->nParamExec = from->nParamExec;
95 Plan *newnode = makeNode(Plan);
98 * copy the node superclass fields
101 CopyPlanFields(from, newnode);
112 _copyResult(Result *from)
114 Result *newnode = makeNode(Result);
117 * copy node superclass fields
120 CopyPlanFields((Plan *) from, (Plan *) newnode);
123 * copy remainder of node
126 Node_Copy(from, newnode, resconstantqual);
129 * We must add subplans in resconstantqual to the new plan's subPlan
132 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
133 SS_pull_subplan(newnode->resconstantqual));
143 _copyAppend(Append *from)
145 Append *newnode = makeNode(Append);
148 * copy node superclass fields
151 CopyPlanFields((Plan *) from, (Plan *) newnode);
154 * copy remainder of node
157 Node_Copy(from, newnode, appendplans);
158 Node_Copy(from, newnode, unionrtables);
159 newnode->inheritrelid = from->inheritrelid;
160 Node_Copy(from, newnode, inheritrtable);
169 * This function copies the fields of the Scan node. It is used by
170 * all the copy functions for classes which inherit from Scan.
174 CopyScanFields(Scan *from, Scan *newnode)
176 newnode->scanrelid = from->scanrelid;
185 _copyScan(Scan *from)
187 Scan *newnode = makeNode(Scan);
190 * copy node superclass fields
193 CopyPlanFields((Plan *) from, (Plan *) newnode);
194 CopyScanFields((Scan *) from, (Scan *) newnode);
204 _copySeqScan(SeqScan *from)
206 SeqScan *newnode = makeNode(SeqScan);
209 * copy node superclass fields
212 CopyPlanFields((Plan *) from, (Plan *) newnode);
213 CopyScanFields((Scan *) from, (Scan *) newnode);
223 _copyIndexScan(IndexScan *from)
225 IndexScan *newnode = makeNode(IndexScan);
228 * copy node superclass fields
231 CopyPlanFields((Plan *) from, (Plan *) newnode);
232 CopyScanFields((Scan *) from, (Scan *) newnode);
235 * copy remainder of node
238 newnode->indxid = listCopy(from->indxid);
239 Node_Copy(from, newnode, indxqual);
240 Node_Copy(from, newnode, indxqualorig);
241 newnode->indxorderdir = from->indxorderdir;
249 * This function copies the fields of the Join node. It is used by
250 * all the copy functions for classes which inherit from Join.
254 CopyJoinFields(Join *from, Join *newnode)
266 _copyJoin(Join *from)
268 Join *newnode = makeNode(Join);
271 * copy node superclass fields
274 CopyPlanFields((Plan *) from, (Plan *) newnode);
275 CopyJoinFields(from, newnode);
286 _copyNestLoop(NestLoop *from)
288 NestLoop *newnode = makeNode(NestLoop);
291 * copy node superclass fields
294 CopyPlanFields((Plan *) from, (Plan *) newnode);
295 CopyJoinFields((Join *) from, (Join *) newnode);
306 _copyMergeJoin(MergeJoin *from)
308 MergeJoin *newnode = makeNode(MergeJoin);
311 * copy node superclass fields
314 CopyPlanFields((Plan *) from, (Plan *) newnode);
315 CopyJoinFields((Join *) from, (Join *) newnode);
318 * copy remainder of node
321 Node_Copy(from, newnode, mergeclauses);
331 _copyHashJoin(HashJoin *from)
333 HashJoin *newnode = makeNode(HashJoin);
336 * copy node superclass fields
339 CopyPlanFields((Plan *) from, (Plan *) newnode);
340 CopyJoinFields((Join *) from, (Join *) newnode);
343 * copy remainder of node
346 Node_Copy(from, newnode, hashclauses);
348 newnode->hashjoinop = from->hashjoinop;
357 * This function copies the fields of the Noname node. It is used by
358 * all the copy functions for classes which inherit from Noname.
362 CopyNonameFields(Noname *from, Noname *newnode)
364 newnode->nonameid = from->nonameid;
365 newnode->keycount = from->keycount;
375 _copyNoname(Noname *from)
377 Noname *newnode = makeNode(Noname);
380 * copy node superclass fields
383 CopyPlanFields((Plan *) from, (Plan *) newnode);
384 CopyNonameFields(from, newnode);
394 _copyMaterial(Material *from)
396 Material *newnode = makeNode(Material);
399 * copy node superclass fields
402 CopyPlanFields((Plan *) from, (Plan *) newnode);
403 CopyNonameFields((Noname *) from, (Noname *) newnode);
414 _copySort(Sort *from)
416 Sort *newnode = makeNode(Sort);
419 * copy node superclass fields
422 CopyPlanFields((Plan *) from, (Plan *) newnode);
423 CopyNonameFields((Noname *) from, (Noname *) newnode);
434 _copyGroup(Group *from)
436 Group *newnode = makeNode(Group);
438 CopyPlanFields((Plan *) from, (Plan *) newnode);
440 newnode->tuplePerGroup = from->tuplePerGroup;
441 newnode->numCols = from->numCols;
442 newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
443 memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
455 Agg *newnode = makeNode(Agg);
457 CopyPlanFields((Plan *) from, (Plan *) newnode);
467 _copyGroupClause(GroupClause *from)
469 GroupClause *newnode = makeNode(GroupClause);
471 newnode->tleSortGroupRef = from->tleSortGroupRef;
472 newnode->sortop = from->sortop;
483 _copyUnique(Unique *from)
485 Unique *newnode = makeNode(Unique);
488 * copy node superclass fields
491 CopyPlanFields((Plan *) from, (Plan *) newnode);
492 CopyNonameFields((Noname *) from, (Noname *) newnode);
495 * copy remainder of node
498 if (from->uniqueAttr)
499 newnode->uniqueAttr = pstrdup(from->uniqueAttr);
501 newnode->uniqueAttr = NULL;
502 newnode->uniqueAttrNum = from->uniqueAttrNum;
513 _copyHash(Hash *from)
515 Hash *newnode = makeNode(Hash);
518 * copy node superclass fields
521 CopyPlanFields((Plan *) from, (Plan *) newnode);
524 * copy remainder of node
527 Node_Copy(from, newnode, hashkey);
533 _copySubPlan(SubPlan *from)
535 SubPlan *newnode = makeNode(SubPlan);
537 Node_Copy(from, newnode, plan);
538 newnode->plan_id = from->plan_id;
539 Node_Copy(from, newnode, rtable);
540 newnode->setParam = listCopy(from->setParam);
541 newnode->parParam = listCopy(from->parParam);
542 Node_Copy(from, newnode, sublink);
547 /* ****************************************************************
548 * primnodes.h copy functions
549 * ****************************************************************
557 _copyResdom(Resdom *from)
559 Resdom *newnode = makeNode(Resdom);
561 newnode->resno = from->resno;
562 newnode->restype = from->restype;
563 newnode->restypmod = from->restypmod;
564 if (from->resname != NULL)
565 newnode->resname = pstrdup(from->resname);
566 newnode->ressortgroupref = from->ressortgroupref;
567 newnode->reskey = from->reskey;
568 newnode->reskeyop = from->reskeyop;
569 newnode->resjunk = from->resjunk;
575 _copyFjoin(Fjoin *from)
577 Fjoin *newnode = makeNode(Fjoin);
580 * copy node superclass fields
584 newnode->fj_initialized = from->fj_initialized;
585 newnode->fj_nNodes = from->fj_nNodes;
587 Node_Copy(from, newnode, fj_innerNode);
589 newnode->fj_results = (DatumPtr)
590 palloc((from->fj_nNodes) * sizeof(Datum));
591 memmove(from->fj_results,
593 (from->fj_nNodes) * sizeof(Datum));
595 newnode->fj_alwaysDone = (BoolPtr)
596 palloc((from->fj_nNodes) * sizeof(bool));
597 memmove(from->fj_alwaysDone,
598 newnode->fj_alwaysDone,
599 (from->fj_nNodes) * sizeof(bool));
610 _copyExpr(Expr *from)
612 Expr *newnode = makeNode(Expr);
615 * copy node superclass fields
618 newnode->typeOid = from->typeOid;
619 newnode->opType = from->opType;
621 Node_Copy(from, newnode, oper);
622 Node_Copy(from, newnode, args);
634 Var *newnode = makeNode(Var);
637 * copy remainder of node
640 newnode->varno = from->varno;
641 newnode->varattno = from->varattno;
642 newnode->vartype = from->vartype;
643 newnode->vartypmod = from->vartypmod;
644 newnode->varlevelsup = from->varlevelsup;
646 newnode->varnoold = from->varnoold;
647 newnode->varoattno = from->varoattno;
657 _copyOper(Oper *from)
659 Oper *newnode = makeNode(Oper);
662 * copy remainder of node
665 newnode->opno = from->opno;
666 newnode->opid = from->opid;
667 newnode->opresulttype = from->opresulttype;
668 newnode->opsize = from->opsize;
671 * NOTE: shall we copy the cache structure or just the pointer ?
672 * Alternatively we can set 'op_fcache' to NULL, in which case the
673 * executor will initialize it when it needs it...
675 newnode->op_fcache = from->op_fcache;
685 _copyConst(Const *from)
687 static Oid cached_type;
688 static bool cached_typbyval;
690 Const *newnode = makeNode(Const);
693 * copy remainder of node
696 newnode->consttype = from->consttype;
697 newnode->constlen = from->constlen;
700 * XXX super cheesy hack until parser/planner
701 * puts in the right values here.
706 if (!from->constisnull && cached_type != from->consttype)
709 Form_pg_type typeStruct;
712 * get the type tuple corresponding to the paramList->type,
713 * If this fails, returnValue has been pre-initialized
714 * to "null" so we just return it.
717 typeTuple = SearchSysCacheTuple(TYPOID,
718 ObjectIdGetDatum(from->consttype),
722 * get the type length and by-value from the type tuple and
723 * save the information in our one element cache.
726 Assert(PointerIsValid(typeTuple));
728 typeStruct = (Form_pg_type) GETSTRUCT(typeTuple);
729 cached_typbyval = (typeStruct)->typbyval ? true : false;
730 cached_type = from->consttype;
733 from->constbyval = cached_typbyval;
735 if (!from->constisnull)
738 * copying the Datum in a const node is a bit trickier
739 * because it might be a pointer and it might also be of
743 if (from->constbyval == true)
746 * passed by value so just copy the datum.
749 newnode->constvalue = from->constvalue;
754 * not passed by value. datum contains a pointer.
757 if (from->constlen != -1)
760 * fixed length structure
763 newnode->constvalue = PointerGetDatum(palloc(from->constlen));
764 memmove((char *) newnode->constvalue,
765 (char *) from->constvalue, from->constlen);
770 * variable length structure. here the length is stored
771 * in the first int pointed to by the constval.
776 length = VARSIZE(from->constvalue);
777 newnode->constvalue = PointerGetDatum(palloc(length));
778 memmove((char *) newnode->constvalue,
779 (char *) from->constvalue, length);
784 newnode->constvalue = from->constvalue;
785 newnode->constisnull = from->constisnull;
786 newnode->constbyval = from->constbyval;
787 newnode->constisset = from->constisset;
788 newnode->constiscast = from->constiscast;
798 _copyParam(Param *from)
800 Param *newnode = makeNode(Param);
803 * copy remainder of node
806 newnode->paramkind = from->paramkind;
807 newnode->paramid = from->paramid;
809 if (from->paramname != NULL)
810 newnode->paramname = pstrdup(from->paramname);
811 newnode->paramtype = from->paramtype;
812 Node_Copy(from, newnode, param_tlist);
822 _copyFunc(Func *from)
824 Func *newnode = makeNode(Func);
827 * copy remainder of node
830 newnode->funcid = from->funcid;
831 newnode->functype = from->functype;
832 newnode->funcisindex = from->funcisindex;
833 newnode->funcsize = from->funcsize;
834 newnode->func_fcache = from->func_fcache;
835 Node_Copy(from, newnode, func_tlist);
836 Node_Copy(from, newnode, func_planlist);
846 _copyAggref(Aggref *from)
848 Aggref *newnode = makeNode(Aggref);
851 * copy remainder of node
854 newnode->aggname = pstrdup(from->aggname);
855 newnode->basetype = from->basetype;
856 newnode->aggtype = from->aggtype;
857 Node_Copy(from, newnode, target);
858 newnode->usenulls = from->usenulls;
859 newnode->aggno = from->aggno; /* probably not needed */
869 _copySubLink(SubLink *from)
871 SubLink *newnode = makeNode(SubLink);
874 * copy remainder of node
877 newnode->subLinkType = from->subLinkType;
878 newnode->useor = from->useor;
879 Node_Copy(from, newnode, lefthand);
880 Node_Copy(from, newnode, oper);
881 Node_Copy(from, newnode, subselect);
891 _copyCaseExpr(CaseExpr *from)
893 CaseExpr *newnode = makeNode(CaseExpr);
896 * copy remainder of node
899 newnode->casetype = from->casetype;
901 Node_Copy(from, newnode, arg);
902 Node_Copy(from, newnode, args);
903 Node_Copy(from, newnode, defresult);
913 _copyCaseWhen(CaseWhen *from)
915 CaseWhen *newnode = makeNode(CaseWhen);
918 * copy remainder of node
921 Node_Copy(from, newnode, expr);
922 Node_Copy(from, newnode, result);
928 _copyArray(Array *from)
930 Array *newnode = makeNode(Array);
933 * copy remainder of node
936 newnode->arrayelemtype = from->arrayelemtype;
937 newnode->arrayelemlength = from->arrayelemlength;
938 newnode->arrayelembyval = from->arrayelembyval;
939 newnode->arrayndim = from->arrayndim;
940 newnode->arraylow = from->arraylow;
941 newnode->arrayhigh = from->arrayhigh;
942 newnode->arraylen = from->arraylen;
948 _copyArrayRef(ArrayRef *from)
950 ArrayRef *newnode = makeNode(ArrayRef);
953 * copy remainder of node
956 newnode->refattrlength = from->refattrlength;
957 newnode->refelemlength = from->refelemlength;
958 newnode->refelemtype = from->refelemtype;
959 newnode->refelembyval = from->refelembyval;
961 Node_Copy(from, newnode, refupperindexpr);
962 Node_Copy(from, newnode, reflowerindexpr);
963 Node_Copy(from, newnode, refexpr);
964 Node_Copy(from, newnode, refassgnexpr);
969 /* ****************************************************************
970 * relation.h copy functions
971 * ****************************************************************
979 * when you change this, also make sure to fix up xfunc_copyRelOptInfo in
980 * planner/path/xfunc.c accordingly!!!
984 _copyRelOptInfo(RelOptInfo *from)
986 RelOptInfo *newnode = makeNode(RelOptInfo);
991 * copy remainder of node
994 newnode->relids = listCopy(from->relids);
996 newnode->indexed = from->indexed;
997 newnode->pages = from->pages;
998 newnode->tuples = from->tuples;
999 newnode->size = from->size;
1000 newnode->width = from->width;
1001 Node_Copy(from, newnode, targetlist);
1002 Node_Copy(from, newnode, pathlist);
1003 Node_Copy(from, newnode, cheapestpath);
1004 newnode->pruneable = from->pruneable;
1006 if (from->classlist)
1008 for (len = 0; from->classlist[len] != 0; len++)
1010 newnode->classlist = (Oid *) palloc(sizeof(Oid) * (len + 1));
1011 for (i = 0; i < len; i++)
1012 newnode->classlist[i] = from->classlist[i];
1013 newnode->classlist[len] = 0;
1016 if (from->indexkeys)
1018 for (len = 0; from->indexkeys[len] != 0; len++)
1020 newnode->indexkeys = (int *) palloc(sizeof(int) * (len + 1));
1021 for (i = 0; i < len; i++)
1022 newnode->indexkeys[i] = from->indexkeys[i];
1023 newnode->indexkeys[len] = 0;
1028 for (len = 0; from->ordering[len] != 0; len++)
1030 newnode->ordering = (Oid *) palloc(sizeof(Oid) * (len + 1));
1031 for (i = 0; i < len; i++)
1032 newnode->ordering[i] = from->ordering[i];
1033 newnode->ordering[len] = 0;
1036 newnode->relam = from->relam;
1037 newnode->indproc = from->indproc;
1038 Node_Copy(from, newnode, indpred);
1040 Node_Copy(from, newnode, restrictinfo);
1041 Node_Copy(from, newnode, joininfo);
1042 Node_Copy(from, newnode, innerjoin);
1050 * This function copies the fields of the Path node. It is used by
1051 * all the copy functions for classes which inherit from Path.
1055 CopyPathFields(Path *from, Path *newnode)
1058 * Modify the next line, since it causes the copying to cycle (i.e.
1059 * the parent points right back here! -- JMH, 7/7/92. Old version:
1060 * Node_Copy(from, newnode, parent);
1062 newnode->parent = from->parent;
1064 newnode->path_cost = from->path_cost;
1066 newnode->pathtype = from->pathtype;
1068 Node_Copy(from, newnode, pathkeys);
1076 _copyPath(Path *from)
1078 Path *newnode = makeNode(Path);
1080 CopyPathFields(from, newnode);
1090 _copyIndexPath(IndexPath *from)
1092 IndexPath *newnode = makeNode(IndexPath);
1095 * copy the node superclass fields
1098 CopyPathFields((Path *) from, (Path *) newnode);
1101 * copy remainder of node
1104 newnode->indexid = listCopy(from->indexid);
1105 Node_Copy(from, newnode, indexqual);
1106 newnode->joinrelids = listCopy(from->joinrelids);
1112 * CopyJoinPathFields
1114 * This function copies the fields of the JoinPath node. It is used by
1115 * all the copy functions for classes which inherit from JoinPath.
1119 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1121 Node_Copy(from, newnode, pathinfo);
1122 Node_Copy(from, newnode, outerjoinpath);
1123 Node_Copy(from, newnode, innerjoinpath);
1131 _copyNestPath(NestPath *from)
1133 NestPath *newnode = makeNode(NestPath);
1136 * copy the node superclass fields
1139 CopyPathFields((Path *) from, (Path *) newnode);
1140 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1150 _copyMergePath(MergePath *from)
1152 MergePath *newnode = makeNode(MergePath);
1155 * copy the node superclass fields
1158 CopyPathFields((Path *) from, (Path *) newnode);
1159 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1162 * copy the remainder of the node
1165 Node_Copy(from, newnode, path_mergeclauses);
1166 Node_Copy(from, newnode, outersortkeys);
1167 Node_Copy(from, newnode, innersortkeys);
1177 _copyHashPath(HashPath *from)
1179 HashPath *newnode = makeNode(HashPath);
1182 * copy the node superclass fields
1185 CopyPathFields((Path *) from, (Path *) newnode);
1186 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1189 * copy remainder of node
1192 Node_Copy(from, newnode, path_hashclauses);
1201 static PathKeyItem *
1202 _copyPathKeyItem(PathKeyItem *from)
1204 PathKeyItem *newnode = makeNode(PathKeyItem);
1207 * copy remainder of node
1210 Node_Copy(from, newnode, key);
1211 newnode->sortop = from->sortop;
1220 static RestrictInfo *
1221 _copyRestrictInfo(RestrictInfo *from)
1223 RestrictInfo *newnode = makeNode(RestrictInfo);
1226 * copy remainder of node
1229 Node_Copy(from, newnode, clause);
1230 newnode->selectivity = from->selectivity;
1231 Node_Copy(from, newnode, subclauseindices);
1232 newnode->mergejoinoperator = from->mergejoinoperator;
1233 newnode->left_sortop = from->left_sortop;
1234 newnode->right_sortop = from->right_sortop;
1235 newnode->hashjoinoperator = from->hashjoinoperator;
1245 _copyJoinInfo(JoinInfo *from)
1247 JoinInfo *newnode = makeNode(JoinInfo);
1250 * copy remainder of node
1253 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1254 Node_Copy(from, newnode, jinfo_restrictinfo);
1260 _copyIter(Iter *from)
1262 Iter *newnode = makeNode(Iter);
1264 Node_Copy(from, newnode, iterexpr);
1265 newnode->itertype = from->itertype;
1271 _copyStream(Stream *from)
1273 Stream *newnode = makeNode(Stream);
1275 newnode->pathptr = from->pathptr;
1276 newnode->cinfo = from->cinfo;
1277 newnode->clausetype = from->clausetype;
1279 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1281 Node_Copy(from, newnode, downstream);
1282 if (newnode->downstream)
1283 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1285 newnode->groupup = from->groupup;
1286 newnode->groupcost = from->groupcost;
1287 newnode->groupsel = from->groupsel;
1293 * parsenodes.h routines have no copy functions
1296 static TargetEntry *
1297 _copyTargetEntry(TargetEntry *from)
1299 TargetEntry *newnode = makeNode(TargetEntry);
1301 Node_Copy(from, newnode, resdom);
1302 Node_Copy(from, newnode, fjoin);
1303 Node_Copy(from, newnode, expr);
1307 static RangeTblEntry *
1308 _copyRangeTblEntry(RangeTblEntry *from)
1310 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1313 newnode->relname = pstrdup(from->relname);
1315 newnode->refname = pstrdup(from->refname);
1316 newnode->relid = from->relid;
1317 newnode->inh = from->inh;
1318 newnode->inFromCl = from->inFromCl;
1319 newnode->inJoinSet = from->inJoinSet;
1320 newnode->skipAcl = from->skipAcl;
1326 _copyRowMark(RowMark *from)
1328 RowMark *newnode = makeNode(RowMark);
1330 newnode->rti = from->rti;
1331 newnode->info = from->info;
1337 _copySortClause(SortClause *from)
1339 SortClause *newnode = makeNode(SortClause);
1341 newnode->tleSortGroupRef = from->tleSortGroupRef;
1342 newnode->sortop = from->sortop;
1348 _copyAConst(A_Const *from)
1350 A_Const *newnode = makeNode(A_Const);
1352 newnode->val = *((Value *) (copyObject(&(from->val))));
1353 Node_Copy(from, newnode, typename);
1359 _copyTypeName(TypeName *from)
1361 TypeName *newnode = makeNode(TypeName);
1364 newnode->name = pstrdup(from->name);
1365 newnode->timezone = from->timezone;
1366 newnode->setof = from->setof;
1367 newnode->typmod = from->typmod;
1368 Node_Copy(from, newnode, arrayBounds);
1374 _copyQuery(Query *from)
1376 Query *newnode = makeNode(Query);
1378 newnode->commandType = from->commandType;
1379 if (from->utilityStmt && nodeTag(from->utilityStmt) == T_NotifyStmt)
1381 NotifyStmt *from_notify = (NotifyStmt *) from->utilityStmt;
1382 NotifyStmt *n = makeNode(NotifyStmt);
1384 n->relname = pstrdup(from_notify->relname);
1385 newnode->utilityStmt = (Node *) n;
1387 newnode->resultRelation = from->resultRelation;
1389 newnode->into = pstrdup(from->into);
1390 newnode->isPortal = from->isPortal;
1391 newnode->isBinary = from->isBinary;
1392 newnode->isTemp = from->isTemp;
1393 newnode->unionall = from->unionall;
1394 newnode->hasAggs = from->hasAggs;
1395 newnode->hasSubLinks = from->hasSubLinks;
1397 Node_Copy(from, newnode, rtable);
1398 Node_Copy(from, newnode, targetList);
1399 Node_Copy(from, newnode, qual);
1400 Node_Copy(from, newnode, rowMark);
1402 if (from->uniqueFlag)
1403 newnode->uniqueFlag = pstrdup(from->uniqueFlag);
1404 Node_Copy(from, newnode, sortClause);
1405 Node_Copy(from, newnode, groupClause);
1406 Node_Copy(from, newnode, havingQual);
1408 /* why is intersectClause missing? */
1409 Node_Copy(from, newnode, unionClause);
1411 Node_Copy(from, newnode, limitOffset);
1412 Node_Copy(from, newnode, limitCount);
1414 /* we do not copy the planner internal fields: base_rel_list,
1415 * join_rel_list, query_pathkeys. Not entirely clear if this is right?
1423 * mnodes.h routines have no copy functions
1426 /* ****************************************************************
1427 * pg_list.h copy functions
1428 * ****************************************************************
1432 _copyValue(Value *from)
1434 Value *newnode = makeNode(Value);
1436 newnode->type = from->type;
1440 newnode->val.str = pstrdup(from->val.str);
1443 newnode->val.ival = from->val.ival;
1446 newnode->val.dval = from->val.dval;
1455 * copyObject returns a copy of the node or list. If it is a list, it
1456 * recursively copies its items.
1460 copyObject(void *from)
1466 switch (nodeTag(from))
1473 retval = _copyPlan(from);
1476 retval = _copyResult(from);
1479 retval = _copyAppend(from);
1482 retval = _copyScan(from);
1485 retval = _copySeqScan(from);
1488 retval = _copyIndexScan(from);
1491 retval = _copyJoin(from);
1494 retval = _copyNestLoop(from);
1497 retval = _copyMergeJoin(from);
1500 retval = _copyHashJoin(from);
1503 retval = _copyNoname(from);
1506 retval = _copyMaterial(from);
1509 retval = _copySort(from);
1512 retval = _copyGroup(from);
1515 retval = _copyAgg(from);
1518 retval = _copyGroupClause(from);
1521 retval = _copyUnique(from);
1524 retval = _copyHash(from);
1527 retval = _copySubPlan(from);
1534 retval = _copyResdom(from);
1537 retval = _copyFjoin(from);
1540 retval = _copyExpr(from);
1543 retval = _copyVar(from);
1546 retval = _copyOper(from);
1549 retval = _copyConst(from);
1552 retval = _copyParam(from);
1555 retval = _copyFunc(from);
1558 retval = _copyArray(from);
1561 retval = _copyArrayRef(from);
1564 retval = _copyAggref(from);
1567 retval = _copySubLink(from);
1570 retval = _copyCaseExpr(from);
1573 retval = _copyCaseWhen(from);
1580 retval = _copyRelOptInfo(from);
1583 retval = _copyPath(from);
1586 retval = _copyIndexPath(from);
1589 retval = _copyNestPath(from);
1592 retval = _copyMergePath(from);
1595 retval = _copyHashPath(from);
1598 retval = _copyPathKeyItem(from);
1600 case T_RestrictInfo:
1601 retval = _copyRestrictInfo(from);
1604 retval = _copyJoinInfo(from);
1607 retval = _copyIter(from);
1610 retval = _copyStream(from);
1617 retval = _copyQuery(from);
1620 retval = _copyTargetEntry(from);
1622 case T_RangeTblEntry:
1623 retval = _copyRangeTblEntry(from);
1626 retval = _copyRowMark(from);
1629 retval = _copySortClause(from);
1632 retval = _copyAConst(from);
1635 retval = _copyTypeName(from);
1644 retval = _copyValue(from);
1650 List *newlist = NIL,
1656 newlist = nl = lcons(copyObject(lfirst(l)), NIL);
1659 lnext(nl) = lcons(copyObject(lfirst(l)), NIL);
1667 elog(ERROR, "copyObject: don't know how to copy %d", nodeTag(from));