1 /*-------------------------------------------------------------------------
4 * Copy functions for Postgres tree nodes.
6 * NOTE: a general convention when copying or comparing plan nodes is
7 * that we ignore the executor state subnode. We do not need to look
8 * at it because no current uses of copyObject() or equal() need to
9 * deal with already-executing plan trees. By leaving the state subnodes
10 * out, we avoid needing to write copy/compare routines for all the
11 * different executor state node types.
14 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
15 * Portions Copyright (c) 1994, Regents of the University of California
18 * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.127 2000/10/26 21:35:47 tgl Exp $
20 *-------------------------------------------------------------------------
25 #include "optimizer/clauses.h"
26 #include "optimizer/planmain.h"
27 #include "utils/acl.h"
32 * a macro to simplify calling of copyObject on the specified field
34 #define Node_Copy(from, newnode, field) \
35 ((newnode)->field = copyObject((from)->field))
40 * This copy function only copies the "cons-cells" of the list, not the
41 * pointed-to objects. (Use copyObject if you want a "deep" copy.)
43 * We also use this function for copying lists of integers, which is
44 * grotty but unlikely to break --- it could fail if sizeof(pointer)
45 * is less than sizeof(int), but I don't know any such machines...
47 * Note that copyObject will surely coredump if applied to a list
57 /* rather ugly coding for speed... */
61 newlist = nl = lcons(lfirst(list), NIL);
63 foreach(l, lnext(list))
65 lnext(nl) = lcons(lfirst(l), NIL);
71 /* ****************************************************************
72 * plannodes.h copy functions
73 * ****************************************************************
79 * This function copies the fields of the Plan node. It is used by
80 * all the copy functions for classes which inherit from Plan.
84 CopyPlanFields(Plan *from, Plan *newnode)
86 newnode->startup_cost = from->startup_cost;
87 newnode->total_cost = from->total_cost;
88 newnode->plan_rows = from->plan_rows;
89 newnode->plan_width = from->plan_width;
90 /* state is NOT copied */
91 Node_Copy(from, newnode, targetlist);
92 Node_Copy(from, newnode, qual);
93 Node_Copy(from, newnode, lefttree);
94 Node_Copy(from, newnode, righttree);
95 newnode->extParam = listCopy(from->extParam);
96 newnode->locParam = listCopy(from->locParam);
97 newnode->chgParam = listCopy(from->chgParam);
98 Node_Copy(from, newnode, initPlan);
99 /* subPlan list must point to subplans in the new subtree, not the old */
100 if (from->subPlan != NIL)
101 newnode->subPlan = nconc(pull_subplans((Node *) newnode->targetlist),
102 pull_subplans((Node *) newnode->qual));
104 newnode->subPlan = NIL;
105 newnode->nParamExec = from->nParamExec;
113 _copyPlan(Plan *from)
115 Plan *newnode = makeNode(Plan);
118 * copy the node superclass fields
121 CopyPlanFields(from, newnode);
132 _copyResult(Result *from)
134 Result *newnode = makeNode(Result);
137 * copy node superclass fields
140 CopyPlanFields((Plan *) from, (Plan *) newnode);
143 * copy remainder of node
146 Node_Copy(from, newnode, resconstantqual);
149 * We must add subplans in resconstantqual to the new plan's subPlan
152 if (from->plan.subPlan != NIL)
153 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
154 pull_subplans(newnode->resconstantqual));
164 _copyAppend(Append *from)
166 Append *newnode = makeNode(Append);
169 * copy node superclass fields
172 CopyPlanFields((Plan *) from, (Plan *) newnode);
175 * copy remainder of node
178 Node_Copy(from, newnode, appendplans);
179 newnode->inheritrelid = from->inheritrelid;
180 Node_Copy(from, newnode, inheritrtable);
189 * This function copies the fields of the Scan node. It is used by
190 * all the copy functions for classes which inherit from Scan.
194 CopyScanFields(Scan *from, Scan *newnode)
196 newnode->scanrelid = from->scanrelid;
205 _copyScan(Scan *from)
207 Scan *newnode = makeNode(Scan);
210 * copy node superclass fields
213 CopyPlanFields((Plan *) from, (Plan *) newnode);
214 CopyScanFields((Scan *) from, (Scan *) newnode);
224 _copySeqScan(SeqScan *from)
226 SeqScan *newnode = makeNode(SeqScan);
229 * copy node superclass fields
232 CopyPlanFields((Plan *) from, (Plan *) newnode);
233 CopyScanFields((Scan *) from, (Scan *) newnode);
243 _copyIndexScan(IndexScan *from)
245 IndexScan *newnode = makeNode(IndexScan);
248 * copy node superclass fields
251 CopyPlanFields((Plan *) from, (Plan *) newnode);
252 CopyScanFields((Scan *) from, (Scan *) newnode);
255 * copy remainder of node
258 newnode->indxid = listCopy(from->indxid);
259 Node_Copy(from, newnode, indxqual);
260 Node_Copy(from, newnode, indxqualorig);
261 newnode->indxorderdir = from->indxorderdir;
264 * We must add subplans in index quals to the new plan's subPlan list
266 if (from->scan.plan.subPlan != NIL)
268 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
269 pull_subplans((Node *) newnode->indxqual));
270 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
271 pull_subplans((Node *) newnode->indxqualorig));
282 _copyTidScan(TidScan *from)
284 TidScan *newnode = makeNode(TidScan);
287 * copy node superclass fields
290 CopyPlanFields((Plan *) from, (Plan *) newnode);
291 CopyScanFields((Scan *) from, (Scan *) newnode);
293 * copy remainder of node
296 newnode->needRescan = from->needRescan;
297 Node_Copy(from, newnode, tideval);
306 static SubqueryScan *
307 _copySubqueryScan(SubqueryScan *from)
309 SubqueryScan *newnode = makeNode(SubqueryScan);
312 * copy node superclass fields
315 CopyPlanFields((Plan *) from, (Plan *) newnode);
316 CopyScanFields((Scan *) from, (Scan *) newnode);
319 * copy remainder of node
322 Node_Copy(from, newnode, subplan);
331 * This function copies the fields of the Join node. It is used by
332 * all the copy functions for classes which inherit from Join.
336 CopyJoinFields(Join *from, Join *newnode)
338 newnode->jointype = from->jointype;
339 Node_Copy(from, newnode, joinqual);
340 /* subPlan list must point to subplans in the new subtree, not the old */
341 if (from->plan.subPlan != NIL)
342 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
343 pull_subplans((Node *) newnode->joinqual));
352 _copyJoin(Join *from)
354 Join *newnode = makeNode(Join);
357 * copy node superclass fields
360 CopyPlanFields((Plan *) from, (Plan *) newnode);
361 CopyJoinFields(from, newnode);
372 _copyNestLoop(NestLoop *from)
374 NestLoop *newnode = makeNode(NestLoop);
377 * copy node superclass fields
380 CopyPlanFields((Plan *) from, (Plan *) newnode);
381 CopyJoinFields((Join *) from, (Join *) newnode);
392 _copyMergeJoin(MergeJoin *from)
394 MergeJoin *newnode = makeNode(MergeJoin);
397 * copy node superclass fields
400 CopyPlanFields((Plan *) from, (Plan *) newnode);
401 CopyJoinFields((Join *) from, (Join *) newnode);
404 * copy remainder of node
407 Node_Copy(from, newnode, mergeclauses);
410 * We must add subplans in mergeclauses to the new plan's subPlan list
412 if (from->join.plan.subPlan != NIL)
413 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
414 pull_subplans((Node *) newnode->mergeclauses));
424 _copyHashJoin(HashJoin *from)
426 HashJoin *newnode = makeNode(HashJoin);
429 * copy node superclass fields
432 CopyPlanFields((Plan *) from, (Plan *) newnode);
433 CopyJoinFields((Join *) from, (Join *) newnode);
436 * copy remainder of node
439 Node_Copy(from, newnode, hashclauses);
440 newnode->hashjoinop = from->hashjoinop;
443 * We must add subplans in hashclauses to the new plan's subPlan list
445 if (from->join.plan.subPlan != NIL)
446 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
447 pull_subplans((Node *) newnode->hashclauses));
458 _copyMaterial(Material *from)
460 Material *newnode = makeNode(Material);
463 * copy node superclass fields
466 CopyPlanFields((Plan *) from, (Plan *) newnode);
477 _copySort(Sort *from)
479 Sort *newnode = makeNode(Sort);
482 * copy node superclass fields
485 CopyPlanFields((Plan *) from, (Plan *) newnode);
487 newnode->keycount = from->keycount;
498 _copyGroup(Group *from)
500 Group *newnode = makeNode(Group);
502 CopyPlanFields((Plan *) from, (Plan *) newnode);
504 newnode->tuplePerGroup = from->tuplePerGroup;
505 newnode->numCols = from->numCols;
506 newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
507 memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
519 Agg *newnode = makeNode(Agg);
521 CopyPlanFields((Plan *) from, (Plan *) newnode);
531 _copyGroupClause(GroupClause *from)
533 GroupClause *newnode = makeNode(GroupClause);
535 newnode->tleSortGroupRef = from->tleSortGroupRef;
536 newnode->sortop = from->sortop;
546 _copyUnique(Unique *from)
548 Unique *newnode = makeNode(Unique);
551 * copy node superclass fields
554 CopyPlanFields((Plan *) from, (Plan *) newnode);
557 * copy remainder of node
560 newnode->numCols = from->numCols;
561 newnode->uniqColIdx = palloc(from->numCols * sizeof(AttrNumber));
562 memcpy(newnode->uniqColIdx, from->uniqColIdx, from->numCols * sizeof(AttrNumber));
572 _copySetOp(SetOp *from)
574 SetOp *newnode = makeNode(SetOp);
577 * copy node superclass fields
580 CopyPlanFields((Plan *) from, (Plan *) newnode);
583 * copy remainder of node
586 newnode->cmd = from->cmd;
587 newnode->numCols = from->numCols;
588 newnode->dupColIdx = palloc(from->numCols * sizeof(AttrNumber));
589 memcpy(newnode->dupColIdx, from->dupColIdx, from->numCols * sizeof(AttrNumber));
590 newnode->flagColIdx = from->flagColIdx;
600 _copyLimit(Limit *from)
602 Limit *newnode = makeNode(Limit);
605 * copy node superclass fields
608 CopyPlanFields((Plan *) from, (Plan *) newnode);
611 * copy remainder of node
614 Node_Copy(from, newnode, limitOffset);
615 Node_Copy(from, newnode, limitCount);
625 _copyHash(Hash *from)
627 Hash *newnode = makeNode(Hash);
630 * copy node superclass fields
633 CopyPlanFields((Plan *) from, (Plan *) newnode);
636 * copy remainder of node
639 Node_Copy(from, newnode, hashkey);
645 _copySubPlan(SubPlan *from)
647 SubPlan *newnode = makeNode(SubPlan);
649 Node_Copy(from, newnode, plan);
650 newnode->plan_id = from->plan_id;
651 Node_Copy(from, newnode, rtable);
652 newnode->setParam = listCopy(from->setParam);
653 newnode->parParam = listCopy(from->parParam);
654 Node_Copy(from, newnode, sublink);
656 /* do not copy execution state */
657 newnode->needShutdown = false;
658 newnode->curTuple = NULL;
663 /* ****************************************************************
664 * primnodes.h copy functions
665 * ****************************************************************
673 _copyResdom(Resdom *from)
675 Resdom *newnode = makeNode(Resdom);
677 newnode->resno = from->resno;
678 newnode->restype = from->restype;
679 newnode->restypmod = from->restypmod;
680 if (from->resname != NULL)
681 newnode->resname = pstrdup(from->resname);
682 newnode->ressortgroupref = from->ressortgroupref;
683 newnode->reskey = from->reskey;
684 newnode->reskeyop = from->reskeyop;
685 newnode->resjunk = from->resjunk;
691 _copyFjoin(Fjoin *from)
693 Fjoin *newnode = makeNode(Fjoin);
696 * copy node superclass fields
700 newnode->fj_initialized = from->fj_initialized;
701 newnode->fj_nNodes = from->fj_nNodes;
703 Node_Copy(from, newnode, fj_innerNode);
705 newnode->fj_results = (DatumPtr)
706 palloc((from->fj_nNodes) * sizeof(Datum));
707 memmove(from->fj_results,
709 (from->fj_nNodes) * sizeof(Datum));
711 newnode->fj_alwaysDone = (BoolPtr)
712 palloc((from->fj_nNodes) * sizeof(bool));
713 memmove(from->fj_alwaysDone,
714 newnode->fj_alwaysDone,
715 (from->fj_nNodes) * sizeof(bool));
726 _copyExpr(Expr *from)
728 Expr *newnode = makeNode(Expr);
731 * copy node superclass fields
734 newnode->typeOid = from->typeOid;
735 newnode->opType = from->opType;
737 Node_Copy(from, newnode, oper);
738 Node_Copy(from, newnode, args);
750 Var *newnode = makeNode(Var);
753 * copy remainder of node
756 newnode->varno = from->varno;
757 newnode->varattno = from->varattno;
758 newnode->vartype = from->vartype;
759 newnode->vartypmod = from->vartypmod;
760 newnode->varlevelsup = from->varlevelsup;
762 newnode->varnoold = from->varnoold;
763 newnode->varoattno = from->varoattno;
769 _copyAttr(Attr *from)
771 Attr *newnode = makeNode(Attr);
774 newnode->relname = pstrdup(from->relname);
775 Node_Copy(from, newnode, attrs);
785 _copyOper(Oper *from)
787 Oper *newnode = makeNode(Oper);
790 * copy remainder of node
793 newnode->opno = from->opno;
794 newnode->opid = from->opid;
795 newnode->opresulttype = from->opresulttype;
796 /* Do not copy the run-time state, if any */
797 newnode->op_fcache = NULL;
807 _copyConst(Const *from)
809 Const *newnode = makeNode(Const);
812 * copy remainder of node
815 newnode->consttype = from->consttype;
816 newnode->constlen = from->constlen;
818 if (from->constbyval || from->constisnull)
821 * passed by value so just copy the datum.
822 * Also, don't try to copy struct when value is null!
825 newnode->constvalue = from->constvalue;
830 * not passed by value. datum contains a pointer.
833 int length = from->constlen;
835 if (length == -1) /* variable-length type? */
836 length = VARSIZE(from->constvalue);
837 newnode->constvalue = PointerGetDatum(palloc(length));
838 memcpy(DatumGetPointer(newnode->constvalue),
839 DatumGetPointer(from->constvalue),
843 newnode->constisnull = from->constisnull;
844 newnode->constbyval = from->constbyval;
845 newnode->constisset = from->constisset;
846 newnode->constiscast = from->constiscast;
856 _copyParam(Param *from)
858 Param *newnode = makeNode(Param);
861 * copy remainder of node
864 newnode->paramkind = from->paramkind;
865 newnode->paramid = from->paramid;
867 if (from->paramname != NULL)
868 newnode->paramname = pstrdup(from->paramname);
869 newnode->paramtype = from->paramtype;
879 _copyFunc(Func *from)
881 Func *newnode = makeNode(Func);
884 * copy remainder of node
887 newnode->funcid = from->funcid;
888 newnode->functype = from->functype;
889 /* Do not copy the run-time state, if any */
890 newnode->func_fcache = NULL;
900 _copyAggref(Aggref *from)
902 Aggref *newnode = makeNode(Aggref);
905 * copy remainder of node
908 newnode->aggname = pstrdup(from->aggname);
909 newnode->basetype = from->basetype;
910 newnode->aggtype = from->aggtype;
911 Node_Copy(from, newnode, target);
912 newnode->aggstar = from->aggstar;
913 newnode->aggdistinct = from->aggdistinct;
914 newnode->aggno = from->aggno; /* probably not needed */
924 _copySubLink(SubLink *from)
926 SubLink *newnode = makeNode(SubLink);
929 * copy remainder of node
932 newnode->subLinkType = from->subLinkType;
933 newnode->useor = from->useor;
934 Node_Copy(from, newnode, lefthand);
935 Node_Copy(from, newnode, oper);
936 Node_Copy(from, newnode, subselect);
946 _copyFieldSelect(FieldSelect *from)
948 FieldSelect *newnode = makeNode(FieldSelect);
951 * copy remainder of node
954 Node_Copy(from, newnode, arg);
955 newnode->fieldnum = from->fieldnum;
956 newnode->resulttype = from->resulttype;
957 newnode->resulttypmod = from->resulttypmod;
967 _copyRelabelType(RelabelType *from)
969 RelabelType *newnode = makeNode(RelabelType);
972 * copy remainder of node
975 Node_Copy(from, newnode, arg);
976 newnode->resulttype = from->resulttype;
977 newnode->resulttypmod = from->resulttypmod;
983 _copyRangeTblRef(RangeTblRef *from)
985 RangeTblRef *newnode = makeNode(RangeTblRef);
987 newnode->rtindex = from->rtindex;
993 _copyFromExpr(FromExpr *from)
995 FromExpr *newnode = makeNode(FromExpr);
997 Node_Copy(from, newnode, fromlist);
998 Node_Copy(from, newnode, quals);
1004 _copyJoinExpr(JoinExpr *from)
1006 JoinExpr *newnode = makeNode(JoinExpr);
1008 newnode->jointype = from->jointype;
1009 newnode->isNatural = from->isNatural;
1010 Node_Copy(from, newnode, larg);
1011 Node_Copy(from, newnode, rarg);
1012 Node_Copy(from, newnode, using);
1013 Node_Copy(from, newnode, quals);
1014 Node_Copy(from, newnode, alias);
1015 Node_Copy(from, newnode, colnames);
1016 Node_Copy(from, newnode, colvars);
1026 _copyCaseExpr(CaseExpr *from)
1028 CaseExpr *newnode = makeNode(CaseExpr);
1031 * copy remainder of node
1034 newnode->casetype = from->casetype;
1036 Node_Copy(from, newnode, arg);
1037 Node_Copy(from, newnode, args);
1038 Node_Copy(from, newnode, defresult);
1048 _copyCaseWhen(CaseWhen *from)
1050 CaseWhen *newnode = makeNode(CaseWhen);
1053 * copy remainder of node
1056 Node_Copy(from, newnode, expr);
1057 Node_Copy(from, newnode, result);
1063 _copyArrayRef(ArrayRef *from)
1065 ArrayRef *newnode = makeNode(ArrayRef);
1068 * copy remainder of node
1071 newnode->refattrlength = from->refattrlength;
1072 newnode->refelemlength = from->refelemlength;
1073 newnode->refelemtype = from->refelemtype;
1074 newnode->refelembyval = from->refelembyval;
1076 Node_Copy(from, newnode, refupperindexpr);
1077 Node_Copy(from, newnode, reflowerindexpr);
1078 Node_Copy(from, newnode, refexpr);
1079 Node_Copy(from, newnode, refassgnexpr);
1084 /* ****************************************************************
1085 * relation.h copy functions
1086 * ****************************************************************
1094 * when you change this, also make sure to fix up xfunc_copyRelOptInfo in
1095 * planner/path/xfunc.c accordingly!!!
1099 _copyRelOptInfo(RelOptInfo *from)
1101 RelOptInfo *newnode = makeNode(RelOptInfo);
1103 newnode->relids = listCopy(from->relids);
1105 newnode->rows = from->rows;
1106 newnode->width = from->width;
1108 Node_Copy(from, newnode, targetlist);
1109 Node_Copy(from, newnode, pathlist);
1110 /* XXX cheapest-path fields should point to members of pathlist? */
1111 Node_Copy(from, newnode, cheapest_startup_path);
1112 Node_Copy(from, newnode, cheapest_total_path);
1113 newnode->pruneable = from->pruneable;
1115 newnode->issubquery = from->issubquery;
1116 newnode->indexed = from->indexed;
1117 newnode->pages = from->pages;
1118 newnode->tuples = from->tuples;
1119 Node_Copy(from, newnode, subplan);
1121 Node_Copy(from, newnode, baserestrictinfo);
1122 newnode->baserestrictcost = from->baserestrictcost;
1123 newnode->outerjoinset = listCopy(from->outerjoinset);
1124 Node_Copy(from, newnode, joininfo);
1125 Node_Copy(from, newnode, innerjoin);
1134 static IndexOptInfo *
1135 _copyIndexOptInfo(IndexOptInfo *from)
1137 IndexOptInfo *newnode = makeNode(IndexOptInfo);
1141 newnode->indexoid = from->indexoid;
1142 newnode->pages = from->pages;
1143 newnode->tuples = from->tuples;
1145 if (from->classlist)
1147 for (len = 0; from->classlist[len] != 0; len++)
1149 newnode->classlist = (Oid *) palloc(sizeof(Oid) * (len + 1));
1150 for (i = 0; i < len; i++)
1151 newnode->classlist[i] = from->classlist[i];
1152 newnode->classlist[len] = 0;
1155 if (from->indexkeys)
1157 for (len = 0; from->indexkeys[len] != 0; len++)
1159 newnode->indexkeys = (int *) palloc(sizeof(int) * (len + 1));
1160 for (i = 0; i < len; i++)
1161 newnode->indexkeys[i] = from->indexkeys[i];
1162 newnode->indexkeys[len] = 0;
1167 for (len = 0; from->ordering[len] != 0; len++)
1169 newnode->ordering = (Oid *) palloc(sizeof(Oid) * (len + 1));
1170 for (i = 0; i < len; i++)
1171 newnode->ordering[i] = from->ordering[i];
1172 newnode->ordering[len] = 0;
1175 newnode->relam = from->relam;
1176 newnode->amcostestimate = from->amcostestimate;
1177 newnode->indproc = from->indproc;
1178 Node_Copy(from, newnode, indpred);
1179 newnode->lossy = from->lossy;
1187 * This function copies the fields of the Path node. It is used by
1188 * all the copy functions for classes which inherit from Path.
1192 CopyPathFields(Path *from, Path *newnode)
1196 * Modify the next line, since it causes the copying to cycle (i.e.
1197 * the parent points right back here! -- JMH, 7/7/92. Old version:
1198 * Node_Copy(from, newnode, parent);
1200 newnode->parent = from->parent;
1202 newnode->startup_cost = from->startup_cost;
1203 newnode->total_cost = from->total_cost;
1205 newnode->pathtype = from->pathtype;
1207 Node_Copy(from, newnode, pathkeys);
1215 _copyPath(Path *from)
1217 Path *newnode = makeNode(Path);
1219 CopyPathFields(from, newnode);
1229 _copyIndexPath(IndexPath *from)
1231 IndexPath *newnode = makeNode(IndexPath);
1234 * copy the node superclass fields
1237 CopyPathFields((Path *) from, (Path *) newnode);
1240 * copy remainder of node
1243 newnode->indexid = listCopy(from->indexid);
1244 Node_Copy(from, newnode, indexqual);
1245 newnode->indexscandir = from->indexscandir;
1246 newnode->joinrelids = listCopy(from->joinrelids);
1247 newnode->alljoinquals = from->alljoinquals;
1248 newnode->rows = from->rows;
1258 _copyTidPath(TidPath *from)
1260 TidPath *newnode = makeNode(TidPath);
1263 * copy the node superclass fields
1266 CopyPathFields((Path *) from, (Path *) newnode);
1269 * copy remainder of node
1272 Node_Copy(from, newnode, tideval);
1273 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1279 * CopyJoinPathFields
1281 * This function copies the fields of the JoinPath node. It is used by
1282 * all the copy functions for classes which inherit from JoinPath.
1286 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1288 newnode->jointype = from->jointype;
1289 Node_Copy(from, newnode, outerjoinpath);
1290 Node_Copy(from, newnode, innerjoinpath);
1291 Node_Copy(from, newnode, joinrestrictinfo);
1299 _copyNestPath(NestPath *from)
1301 NestPath *newnode = makeNode(NestPath);
1304 * copy the node superclass fields
1307 CopyPathFields((Path *) from, (Path *) newnode);
1308 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1318 _copyMergePath(MergePath *from)
1320 MergePath *newnode = makeNode(MergePath);
1323 * copy the node superclass fields
1326 CopyPathFields((Path *) from, (Path *) newnode);
1327 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1330 * copy the remainder of the node
1333 Node_Copy(from, newnode, path_mergeclauses);
1334 Node_Copy(from, newnode, outersortkeys);
1335 Node_Copy(from, newnode, innersortkeys);
1345 _copyHashPath(HashPath *from)
1347 HashPath *newnode = makeNode(HashPath);
1350 * copy the node superclass fields
1353 CopyPathFields((Path *) from, (Path *) newnode);
1354 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1357 * copy remainder of node
1360 Node_Copy(from, newnode, path_hashclauses);
1369 static PathKeyItem *
1370 _copyPathKeyItem(PathKeyItem *from)
1372 PathKeyItem *newnode = makeNode(PathKeyItem);
1375 * copy remainder of node
1378 Node_Copy(from, newnode, key);
1379 newnode->sortop = from->sortop;
1388 static RestrictInfo *
1389 _copyRestrictInfo(RestrictInfo *from)
1391 RestrictInfo *newnode = makeNode(RestrictInfo);
1394 * copy remainder of node
1397 Node_Copy(from, newnode, clause);
1398 newnode->ispusheddown = from->ispusheddown;
1399 Node_Copy(from, newnode, subclauseindices);
1400 newnode->mergejoinoperator = from->mergejoinoperator;
1401 newnode->left_sortop = from->left_sortop;
1402 newnode->right_sortop = from->right_sortop;
1403 newnode->hashjoinoperator = from->hashjoinoperator;
1413 _copyJoinInfo(JoinInfo *from)
1415 JoinInfo *newnode = makeNode(JoinInfo);
1418 * copy remainder of node
1421 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1422 Node_Copy(from, newnode, jinfo_restrictinfo);
1428 _copyIter(Iter *from)
1430 Iter *newnode = makeNode(Iter);
1432 Node_Copy(from, newnode, iterexpr);
1433 newnode->itertype = from->itertype;
1439 _copyStream(Stream *from)
1441 Stream *newnode = makeNode(Stream);
1443 newnode->pathptr = from->pathptr;
1444 newnode->cinfo = from->cinfo;
1445 newnode->clausetype = from->clausetype;
1447 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1449 Node_Copy(from, newnode, downstream);
1450 if (newnode->downstream)
1451 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1453 newnode->groupup = from->groupup;
1454 newnode->groupcost = from->groupcost;
1455 newnode->groupsel = from->groupsel;
1460 /* ****************************************************************
1461 * parsenodes.h copy functions
1462 * ****************************************************************
1465 static TargetEntry *
1466 _copyTargetEntry(TargetEntry *from)
1468 TargetEntry *newnode = makeNode(TargetEntry);
1470 Node_Copy(from, newnode, resdom);
1471 Node_Copy(from, newnode, fjoin);
1472 Node_Copy(from, newnode, expr);
1476 static RangeTblEntry *
1477 _copyRangeTblEntry(RangeTblEntry *from)
1479 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1482 newnode->relname = pstrdup(from->relname);
1483 newnode->relid = from->relid;
1484 Node_Copy(from, newnode, subquery);
1485 Node_Copy(from, newnode, alias);
1486 Node_Copy(from, newnode, eref);
1487 newnode->inh = from->inh;
1488 newnode->inFromCl = from->inFromCl;
1489 newnode->checkForRead = from->checkForRead;
1490 newnode->checkForWrite = from->checkForWrite;
1491 newnode->checkAsUser = from->checkAsUser;
1496 static FkConstraint *
1497 _copyFkConstraint(FkConstraint *from)
1499 FkConstraint *newnode = makeNode(FkConstraint);
1501 if (from->constr_name)
1502 newnode->constr_name = pstrdup(from->constr_name);
1503 if (from->pktable_name)
1504 newnode->pktable_name = pstrdup(from->pktable_name);
1505 Node_Copy(from, newnode, fk_attrs);
1506 Node_Copy(from, newnode, pk_attrs);
1507 if (from->match_type)
1508 newnode->match_type = pstrdup(from->match_type);
1509 newnode->actions = from->actions;
1510 newnode->deferrable = from->deferrable;
1511 newnode->initdeferred = from->initdeferred;
1517 _copySortClause(SortClause *from)
1519 SortClause *newnode = makeNode(SortClause);
1521 newnode->tleSortGroupRef = from->tleSortGroupRef;
1522 newnode->sortop = from->sortop;
1528 _copyAExpr(A_Expr *from)
1530 A_Expr *newnode = makeNode(A_Expr);
1532 newnode->oper = from->oper;
1534 newnode->opname = pstrdup(from->opname);
1535 Node_Copy(from, newnode, lexpr);
1536 Node_Copy(from, newnode, rexpr);
1542 _copyAConst(A_Const *from)
1544 A_Const *newnode = makeNode(A_Const);
1546 newnode->val = *((Value *) (copyObject(&(from->val))));
1547 Node_Copy(from, newnode, typename);
1553 _copyParamNo(ParamNo *from)
1555 ParamNo *newnode = makeNode(ParamNo);
1557 newnode->number = from->number;
1558 Node_Copy(from, newnode, typename);
1559 Node_Copy(from, newnode, indirection);
1565 _copyIdent(Ident *from)
1567 Ident *newnode = makeNode(Ident);
1570 newnode->name = pstrdup(from->name);
1571 Node_Copy(from, newnode, indirection);
1572 newnode->isRel = from->isRel;
1578 _copyFuncCall(FuncCall *from)
1580 FuncCall *newnode = makeNode(FuncCall);
1583 newnode->funcname = pstrdup(from->funcname);
1584 Node_Copy(from, newnode, args);
1585 newnode->agg_star = from->agg_star;
1586 newnode->agg_distinct = from->agg_distinct;
1592 _copyAIndices(A_Indices *from)
1594 A_Indices *newnode = makeNode(A_Indices);
1596 Node_Copy(from, newnode, lidx);
1597 Node_Copy(from, newnode, uidx);
1603 _copyResTarget(ResTarget *from)
1605 ResTarget *newnode = makeNode(ResTarget);
1608 newnode->name = pstrdup(from->name);
1609 Node_Copy(from, newnode, indirection);
1610 Node_Copy(from, newnode, val);
1616 _copyTypeName(TypeName *from)
1618 TypeName *newnode = makeNode(TypeName);
1621 newnode->name = pstrdup(from->name);
1622 newnode->timezone = from->timezone;
1623 newnode->setof = from->setof;
1624 newnode->typmod = from->typmod;
1625 Node_Copy(from, newnode, arrayBounds);
1630 static SortGroupBy *
1631 _copySortGroupBy(SortGroupBy *from)
1633 SortGroupBy *newnode = makeNode(SortGroupBy);
1636 newnode->useOp = pstrdup(from->useOp);
1637 Node_Copy(from, newnode, node);
1643 _copyRangeVar(RangeVar *from)
1645 RangeVar *newnode = makeNode(RangeVar);
1648 newnode->relname = pstrdup(from->relname);
1649 newnode->inh = from->inh;
1650 Node_Copy(from, newnode, name);
1655 static RangeSubselect *
1656 _copyRangeSubselect(RangeSubselect *from)
1658 RangeSubselect *newnode = makeNode(RangeSubselect);
1660 Node_Copy(from, newnode, subquery);
1661 Node_Copy(from, newnode, name);
1667 _copyTypeCast(TypeCast *from)
1669 TypeCast *newnode = makeNode(TypeCast);
1671 Node_Copy(from, newnode, arg);
1672 Node_Copy(from, newnode, typename);
1678 _copyIndexElem(IndexElem *from)
1680 IndexElem *newnode = makeNode(IndexElem);
1683 newnode->name = pstrdup(from->name);
1684 Node_Copy(from, newnode, args);
1686 newnode->class = pstrdup(from->class);
1692 _copyColumnDef(ColumnDef *from)
1694 ColumnDef *newnode = makeNode(ColumnDef);
1697 newnode->colname = pstrdup(from->colname);
1698 Node_Copy(from, newnode, typename);
1699 newnode->is_not_null = from->is_not_null;
1700 newnode->is_sequence = from->is_sequence;
1701 Node_Copy(from, newnode, raw_default);
1702 if (from->cooked_default)
1703 newnode->cooked_default = pstrdup(from->cooked_default);
1704 Node_Copy(from, newnode, constraints);
1710 _copyConstraint(Constraint *from)
1712 Constraint *newnode = makeNode(Constraint);
1714 newnode->contype = from->contype;
1716 newnode->name = pstrdup(from->name);
1717 Node_Copy(from, newnode, raw_expr);
1718 if (from->cooked_expr)
1719 newnode->cooked_expr = pstrdup(from->cooked_expr);
1720 Node_Copy(from, newnode, keys);
1726 _copyDefElem(DefElem *from)
1728 DefElem *newnode = makeNode(DefElem);
1731 newnode->defname = pstrdup(from->defname);
1732 Node_Copy(from, newnode, arg);
1738 _copyQuery(Query *from)
1740 Query *newnode = makeNode(Query);
1742 newnode->commandType = from->commandType;
1743 Node_Copy(from, newnode, utilityStmt);
1744 newnode->resultRelation = from->resultRelation;
1746 newnode->into = pstrdup(from->into);
1747 newnode->isPortal = from->isPortal;
1748 newnode->isBinary = from->isBinary;
1749 newnode->isTemp = from->isTemp;
1750 newnode->hasAggs = from->hasAggs;
1751 newnode->hasSubLinks = from->hasSubLinks;
1753 Node_Copy(from, newnode, rtable);
1754 Node_Copy(from, newnode, jointree);
1756 newnode->rowMarks = listCopy(from->rowMarks);
1758 Node_Copy(from, newnode, targetList);
1760 Node_Copy(from, newnode, groupClause);
1761 Node_Copy(from, newnode, havingQual);
1762 Node_Copy(from, newnode, distinctClause);
1763 Node_Copy(from, newnode, sortClause);
1765 Node_Copy(from, newnode, limitOffset);
1766 Node_Copy(from, newnode, limitCount);
1768 Node_Copy(from, newnode, setOperations);
1771 * We do not copy the planner internal fields: base_rel_list,
1772 * join_rel_list, equi_key_list, query_pathkeys. Not entirely clear if
1780 _copyInsertStmt(InsertStmt *from)
1782 InsertStmt *newnode = makeNode(InsertStmt);
1785 newnode->relname = pstrdup(from->relname);
1786 Node_Copy(from, newnode, cols);
1787 Node_Copy(from, newnode, targetList);
1788 Node_Copy(from, newnode, selectStmt);
1794 _copyDeleteStmt(DeleteStmt *from)
1796 DeleteStmt *newnode = makeNode(DeleteStmt);
1799 newnode->relname = pstrdup(from->relname);
1800 Node_Copy(from, newnode, whereClause);
1801 newnode->inh = from->inh;
1807 _copyUpdateStmt(UpdateStmt *from)
1809 UpdateStmt *newnode = makeNode(UpdateStmt);
1812 newnode->relname = pstrdup(from->relname);
1813 Node_Copy(from, newnode, targetList);
1814 Node_Copy(from, newnode, whereClause);
1815 Node_Copy(from, newnode, fromClause);
1816 newnode->inh = from->inh;
1822 _copySelectStmt(SelectStmt *from)
1824 SelectStmt *newnode = makeNode(SelectStmt);
1826 Node_Copy(from, newnode, distinctClause);
1828 newnode->into = pstrdup(from->into);
1829 Node_Copy(from, newnode, targetList);
1830 Node_Copy(from, newnode, fromClause);
1831 Node_Copy(from, newnode, whereClause);
1832 Node_Copy(from, newnode, groupClause);
1833 Node_Copy(from, newnode, havingClause);
1834 Node_Copy(from, newnode, sortClause);
1835 if (from->portalname)
1836 newnode->portalname = pstrdup(from->portalname);
1837 newnode->binary = from->binary;
1838 newnode->istemp = from->istemp;
1839 Node_Copy(from, newnode, limitOffset);
1840 Node_Copy(from, newnode, limitCount);
1841 Node_Copy(from, newnode, forUpdate);
1846 static SetOperationStmt *
1847 _copySetOperationStmt(SetOperationStmt *from)
1849 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1851 newnode->op = from->op;
1852 newnode->all = from->all;
1853 Node_Copy(from, newnode, larg);
1854 Node_Copy(from, newnode, rarg);
1855 newnode->colTypes = listCopy(from->colTypes);
1860 static AlterTableStmt *
1861 _copyAlterTableStmt(AlterTableStmt *from)
1863 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1865 newnode->subtype = from->subtype;
1867 newnode->relname = pstrdup(from->relname);
1868 newnode->inh = from->inh;
1870 newnode->name = pstrdup(from->name);
1871 Node_Copy(from, newnode, def);
1872 newnode->behavior = from->behavior;
1877 static ChangeACLStmt *
1878 _copyChangeACLStmt(ChangeACLStmt *from)
1880 ChangeACLStmt *newnode = makeNode(ChangeACLStmt);
1882 Node_Copy(from, newnode, relNames);
1883 if (from->aclString)
1884 newnode->aclString = pstrdup(from->aclString);
1889 static ClosePortalStmt *
1890 _copyClosePortalStmt(ClosePortalStmt *from)
1892 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1894 if (from->portalname)
1895 newnode->portalname = pstrdup(from->portalname);
1900 static ClusterStmt *
1901 _copyClusterStmt(ClusterStmt *from)
1903 ClusterStmt *newnode = makeNode(ClusterStmt);
1906 newnode->relname = pstrdup(from->relname);
1907 if (from->indexname)
1908 newnode->indexname = pstrdup(from->indexname);
1914 _copyCopyStmt(CopyStmt *from)
1916 CopyStmt *newnode = makeNode(CopyStmt);
1918 newnode->binary = from->binary;
1920 newnode->relname = pstrdup(from->relname);
1921 newnode->oids = from->oids;
1922 newnode->direction = from->direction;
1924 newnode->filename = pstrdup(from->filename);
1925 if (from->delimiter)
1926 newnode->delimiter = pstrdup(from->delimiter);
1927 if (from->null_print)
1928 newnode->null_print = pstrdup(from->null_print);
1934 _copyCreateStmt(CreateStmt *from)
1936 CreateStmt *newnode = makeNode(CreateStmt);
1938 newnode->istemp = from->istemp;
1939 newnode->relname = pstrdup(from->relname);
1940 Node_Copy(from, newnode, tableElts);
1941 Node_Copy(from, newnode, inhRelnames);
1942 Node_Copy(from, newnode, constraints);
1947 static VersionStmt *
1948 _copyVersionStmt(VersionStmt *from)
1950 VersionStmt *newnode = makeNode(VersionStmt);
1952 newnode->relname = pstrdup(from->relname);
1953 newnode->direction = from->direction;
1954 newnode->fromRelname = pstrdup(from->fromRelname);
1955 newnode->date = pstrdup(from->date);
1961 _copyDefineStmt(DefineStmt *from)
1963 DefineStmt *newnode = makeNode(DefineStmt);
1965 newnode->defType = from->defType;
1966 newnode->defname = pstrdup(from->defname);
1967 Node_Copy(from, newnode, definition);
1973 _copyDropStmt(DropStmt *from)
1975 DropStmt *newnode = makeNode(DropStmt);
1977 Node_Copy(from, newnode, names);
1978 newnode->removeType = from->removeType;
1983 static TruncateStmt *
1984 _copyTruncateStmt(TruncateStmt *from)
1986 TruncateStmt *newnode = makeNode(TruncateStmt);
1988 newnode->relName = pstrdup(from->relName);
1993 static CommentStmt *
1994 _copyCommentStmt(CommentStmt *from)
1996 CommentStmt *newnode = makeNode(CommentStmt);
1998 newnode->objtype = from->objtype;
1999 newnode->objname = pstrdup(from->objname);
2000 if (from->objproperty)
2001 newnode->objproperty = pstrdup(from->objproperty);
2002 Node_Copy(from, newnode, objlist);
2003 newnode->comment = pstrdup(from->comment);
2009 _copyExtendStmt(ExtendStmt *from)
2011 ExtendStmt *newnode = makeNode(ExtendStmt);
2013 newnode->idxname = pstrdup(from->idxname);
2014 Node_Copy(from, newnode, whereClause);
2015 Node_Copy(from, newnode, rangetable);
2021 _copyFetchStmt(FetchStmt *from)
2023 FetchStmt *newnode = makeNode(FetchStmt);
2025 newnode->direction = from->direction;
2026 newnode->howMany = from->howMany;
2027 newnode->portalname = pstrdup(from->portalname);
2028 newnode->ismove = from->ismove;
2034 _copyIndexStmt(IndexStmt *from)
2036 IndexStmt *newnode = makeNode(IndexStmt);
2038 newnode->idxname = pstrdup(from->idxname);
2039 newnode->relname = pstrdup(from->relname);
2040 newnode->accessMethod = pstrdup(from->accessMethod);
2041 Node_Copy(from, newnode, indexParams);
2042 Node_Copy(from, newnode, withClause);
2043 Node_Copy(from, newnode, whereClause);
2044 Node_Copy(from, newnode, rangetable);
2045 newnode->unique = from->unique;
2046 newnode->primary = from->primary;
2051 static ProcedureStmt *
2052 _copyProcedureStmt(ProcedureStmt *from)
2054 ProcedureStmt *newnode = makeNode(ProcedureStmt);
2056 newnode->funcname = pstrdup(from->funcname);
2057 Node_Copy(from, newnode, argTypes);
2058 Node_Copy(from, newnode, returnType);
2059 Node_Copy(from, newnode, withClause);
2060 Node_Copy(from, newnode, as);
2061 newnode->language = pstrdup(from->language);
2066 static RemoveAggrStmt *
2067 _copyRemoveAggrStmt(RemoveAggrStmt *from)
2069 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
2071 newnode->aggname = pstrdup(from->aggname);
2072 Node_Copy(from, newnode, aggtype);
2077 static RemoveFuncStmt *
2078 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2080 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2082 newnode->funcname = pstrdup(from->funcname);
2083 Node_Copy(from, newnode, args);
2088 static RemoveOperStmt *
2089 _copyRemoveOperStmt(RemoveOperStmt *from)
2091 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2093 newnode->opname = pstrdup(from->opname);
2094 Node_Copy(from, newnode, args);
2100 _copyRenameStmt(RenameStmt *from)
2102 RenameStmt *newnode = makeNode(RenameStmt);
2104 newnode->relname = pstrdup(from->relname);
2105 newnode->inh = from->inh;
2107 newnode->column = pstrdup(from->column);
2109 newnode->newname = pstrdup(from->newname);
2115 _copyRuleStmt(RuleStmt *from)
2117 RuleStmt *newnode = makeNode(RuleStmt);
2119 newnode->rulename = pstrdup(from->rulename);
2120 Node_Copy(from, newnode, whereClause);
2121 newnode->event = from->event;
2122 Node_Copy(from, newnode, object);
2123 newnode->instead = from->instead;
2124 Node_Copy(from, newnode, actions);
2130 _copyNotifyStmt(NotifyStmt *from)
2132 NotifyStmt *newnode = makeNode(NotifyStmt);
2135 newnode->relname = pstrdup(from->relname);
2141 _copyListenStmt(ListenStmt *from)
2143 ListenStmt *newnode = makeNode(ListenStmt);
2146 newnode->relname = pstrdup(from->relname);
2151 static UnlistenStmt *
2152 _copyUnlistenStmt(UnlistenStmt *from)
2154 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2157 newnode->relname = pstrdup(from->relname);
2162 static TransactionStmt *
2163 _copyTransactionStmt(TransactionStmt *from)
2165 TransactionStmt *newnode = makeNode(TransactionStmt);
2167 newnode->command = from->command;
2173 _copyViewStmt(ViewStmt *from)
2175 ViewStmt *newnode = makeNode(ViewStmt);
2178 newnode->viewname = pstrdup(from->viewname);
2179 Node_Copy(from, newnode, aliases);
2180 Node_Copy(from, newnode, query);
2186 _copyLoadStmt(LoadStmt *from)
2188 LoadStmt *newnode = makeNode(LoadStmt);
2191 newnode->filename = pstrdup(from->filename);
2196 static CreatedbStmt *
2197 _copyCreatedbStmt(CreatedbStmt *from)
2199 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2202 newnode->dbname = pstrdup(from->dbname);
2204 newnode->dbpath = pstrdup(from->dbpath);
2205 newnode->encoding = from->encoding;
2211 _copyDropdbStmt(DropdbStmt *from)
2213 DropdbStmt *newnode = makeNode(DropdbStmt);
2216 newnode->dbname = pstrdup(from->dbname);
2222 _copyVacuumStmt(VacuumStmt *from)
2224 VacuumStmt *newnode = makeNode(VacuumStmt);
2226 newnode->verbose = from->verbose;
2227 newnode->analyze = from->analyze;
2229 newnode->vacrel = pstrdup(from->vacrel);
2230 Node_Copy(from, newnode, va_spec);
2235 static ExplainStmt *
2236 _copyExplainStmt(ExplainStmt *from)
2238 ExplainStmt *newnode = makeNode(ExplainStmt);
2240 Node_Copy(from, newnode, query);
2241 newnode->verbose = from->verbose;
2246 static CreateSeqStmt *
2247 _copyCreateSeqStmt(CreateSeqStmt *from)
2249 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2252 newnode->seqname = pstrdup(from->seqname);
2253 Node_Copy(from, newnode, options);
2258 static VariableSetStmt *
2259 _copyVariableSetStmt(VariableSetStmt *from)
2261 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2264 newnode->name = pstrdup(from->name);
2266 newnode->value = pstrdup(from->value);
2271 static VariableShowStmt *
2272 _copyVariableShowStmt(VariableShowStmt *from)
2274 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2277 newnode->name = pstrdup(from->name);
2282 static VariableResetStmt *
2283 _copyVariableResetStmt(VariableResetStmt *from)
2285 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2288 newnode->name = pstrdup(from->name);
2293 static CreateTrigStmt *
2294 _copyCreateTrigStmt(CreateTrigStmt *from)
2296 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2299 newnode->trigname = pstrdup(from->trigname);
2301 newnode->relname = pstrdup(from->relname);
2303 newnode->funcname = pstrdup(from->funcname);
2304 Node_Copy(from, newnode, args);
2305 newnode->before = from->before;
2306 newnode->row = from->row;
2307 memcpy(newnode->actions, from->actions, sizeof(from->actions));
2309 newnode->lang = pstrdup(from->lang);
2311 newnode->text = pstrdup(from->text);
2312 Node_Copy(from, newnode, attr);
2314 newnode->when = pstrdup(from->when);
2315 newnode->isconstraint = from->isconstraint;
2316 newnode->deferrable = from->deferrable;
2317 newnode->initdeferred = from->initdeferred;
2318 if (from->constrrelname)
2319 newnode->constrrelname = pstrdup(from->constrrelname);
2324 static DropTrigStmt *
2325 _copyDropTrigStmt(DropTrigStmt *from)
2327 DropTrigStmt *newnode = makeNode(DropTrigStmt);
2330 newnode->trigname = pstrdup(from->trigname);
2332 newnode->relname = pstrdup(from->relname);
2337 static CreatePLangStmt *
2338 _copyCreatePLangStmt(CreatePLangStmt *from)
2340 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2343 newnode->plname = pstrdup(from->plname);
2344 if (from->plhandler)
2345 newnode->plhandler = pstrdup(from->plhandler);
2346 if (from->plcompiler)
2347 newnode->plcompiler = pstrdup(from->plcompiler);
2348 newnode->pltrusted = from->pltrusted;
2353 static DropPLangStmt *
2354 _copyDropPLangStmt(DropPLangStmt *from)
2356 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2359 newnode->plname = pstrdup(from->plname);
2364 static CreateUserStmt *
2365 _copyCreateUserStmt(CreateUserStmt *from)
2367 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2370 newnode->user = pstrdup(from->user);
2372 newnode->password = pstrdup(from->password);
2373 newnode->sysid = from->sysid;
2374 newnode->createdb = from->createdb;
2375 newnode->createuser = from->createuser;
2376 Node_Copy(from, newnode, groupElts);
2377 if (from->validUntil)
2378 newnode->validUntil = pstrdup(from->validUntil);
2383 static AlterUserStmt *
2384 _copyAlterUserStmt(AlterUserStmt *from)
2386 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2389 newnode->user = pstrdup(from->user);
2391 newnode->password = pstrdup(from->password);
2392 newnode->createdb = from->createdb;
2393 newnode->createuser = from->createuser;
2394 if (from->validUntil)
2395 newnode->validUntil = pstrdup(from->validUntil);
2400 static DropUserStmt *
2401 _copyDropUserStmt(DropUserStmt *from)
2403 DropUserStmt *newnode = makeNode(DropUserStmt);
2405 Node_Copy(from, newnode, users);
2411 _copyLockStmt(LockStmt *from)
2413 LockStmt *newnode = makeNode(LockStmt);
2416 newnode->relname = pstrdup(from->relname);
2417 newnode->mode = from->mode;
2422 static ConstraintsSetStmt *
2423 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2425 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2427 Node_Copy(from, newnode, constraints);
2428 newnode->deferred = from->deferred;
2433 static CreateGroupStmt *
2434 _copyCreateGroupStmt(CreateGroupStmt *from)
2436 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2439 newnode->name = pstrdup(from->name);
2440 newnode->sysid = from->sysid;
2441 Node_Copy(from, newnode, initUsers);
2446 static AlterGroupStmt *
2447 _copyAlterGroupStmt(AlterGroupStmt *from)
2449 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2452 newnode->name = pstrdup(from->name);
2453 newnode->action = from->action;
2454 newnode->sysid = from->sysid;
2455 Node_Copy(from, newnode, listUsers);
2460 static DropGroupStmt *
2461 _copyDropGroupStmt(DropGroupStmt *from)
2463 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2466 newnode->name = pstrdup(from->name);
2471 static ReindexStmt *
2472 _copyReindexStmt(ReindexStmt *from)
2474 ReindexStmt *newnode = makeNode(ReindexStmt);
2476 newnode->reindexType = from->reindexType;
2478 newnode->name = pstrdup(from->name);
2479 newnode->force = from->force;
2480 newnode->all = from->all;
2485 static SetSessionStmt *
2486 _copySetSessionStmt(SetSessionStmt *from)
2488 SetSessionStmt *newnode = makeNode(SetSessionStmt);
2490 Node_Copy(from, newnode, args);
2496 /* ****************************************************************
2497 * pg_list.h copy functions
2498 * ****************************************************************
2502 _copyValue(Value *from)
2504 Value *newnode = makeNode(Value);
2506 newnode->type = from->type;
2510 newnode->val.ival = from->val.ival;
2514 newnode->val.str = pstrdup(from->val.str);
2523 * copyObject returns a copy of the node or list. If it is a list, it
2524 * recursively copies its items.
2528 copyObject(void *from)
2535 switch (nodeTag(from))
2542 retval = _copyPlan(from);
2545 retval = _copyResult(from);
2548 retval = _copyAppend(from);
2551 retval = _copyScan(from);
2554 retval = _copySeqScan(from);
2557 retval = _copyIndexScan(from);
2560 retval = _copyTidScan(from);
2562 case T_SubqueryScan:
2563 retval = _copySubqueryScan(from);
2566 retval = _copyJoin(from);
2569 retval = _copyNestLoop(from);
2572 retval = _copyMergeJoin(from);
2575 retval = _copyHashJoin(from);
2578 retval = _copyMaterial(from);
2581 retval = _copySort(from);
2584 retval = _copyGroup(from);
2587 retval = _copyAgg(from);
2590 retval = _copyUnique(from);
2593 retval = _copySetOp(from);
2596 retval = _copyLimit(from);
2599 retval = _copyHash(from);
2602 retval = _copySubPlan(from);
2609 retval = _copyResdom(from);
2612 retval = _copyFjoin(from);
2615 retval = _copyExpr(from);
2618 retval = _copyVar(from);
2621 retval = _copyOper(from);
2624 retval = _copyConst(from);
2627 retval = _copyParam(from);
2630 retval = _copyAggref(from);
2633 retval = _copySubLink(from);
2636 retval = _copyFunc(from);
2639 retval = _copyArrayRef(from);
2642 retval = _copyIter(from);
2645 retval = _copyFieldSelect(from);
2648 retval = _copyRelabelType(from);
2651 retval = _copyRangeTblRef(from);
2654 retval = _copyFromExpr(from);
2657 retval = _copyJoinExpr(from);
2664 retval = _copyRelOptInfo(from);
2667 retval = _copyPath(from);
2670 retval = _copyIndexPath(from);
2673 retval = _copyTidPath(from);
2676 retval = _copyNestPath(from);
2679 retval = _copyMergePath(from);
2682 retval = _copyHashPath(from);
2685 retval = _copyPathKeyItem(from);
2687 case T_RestrictInfo:
2688 retval = _copyRestrictInfo(from);
2691 retval = _copyJoinInfo(from);
2694 retval = _copyStream(from);
2696 case T_IndexOptInfo:
2697 retval = _copyIndexOptInfo(from);
2706 retval = _copyValue(from);
2714 /* rather ugly coding for speed... */
2715 /* Note the input list cannot be NIL if we got here. */
2716 nl = lcons(copyObject(lfirst(list)), NIL);
2719 foreach(l, lnext(list))
2721 lnext(nl) = lcons(copyObject(lfirst(l)), NIL);
2731 retval = _copyQuery(from);
2734 retval = _copyInsertStmt(from);
2737 retval = _copyDeleteStmt(from);
2740 retval = _copyUpdateStmt(from);
2743 retval = _copySelectStmt(from);
2745 case T_SetOperationStmt:
2746 retval = _copySetOperationStmt(from);
2748 case T_AlterTableStmt:
2749 retval = _copyAlterTableStmt(from);
2751 case T_ChangeACLStmt:
2752 retval = _copyChangeACLStmt(from);
2754 case T_ClosePortalStmt:
2755 retval = _copyClosePortalStmt(from);
2758 retval = _copyClusterStmt(from);
2761 retval = _copyCopyStmt(from);
2764 retval = _copyCreateStmt(from);
2767 retval = _copyVersionStmt(from);
2770 retval = _copyDefineStmt(from);
2773 retval = _copyDropStmt(from);
2775 case T_TruncateStmt:
2776 retval = _copyTruncateStmt(from);
2779 retval = _copyCommentStmt(from);
2782 retval = _copyExtendStmt(from);
2785 retval = _copyFetchStmt(from);
2788 retval = _copyIndexStmt(from);
2790 case T_ProcedureStmt:
2791 retval = _copyProcedureStmt(from);
2793 case T_RemoveAggrStmt:
2794 retval = _copyRemoveAggrStmt(from);
2796 case T_RemoveFuncStmt:
2797 retval = _copyRemoveFuncStmt(from);
2799 case T_RemoveOperStmt:
2800 retval = _copyRemoveOperStmt(from);
2803 retval = _copyRenameStmt(from);
2806 retval = _copyRuleStmt(from);
2809 retval = _copyNotifyStmt(from);
2812 retval = _copyListenStmt(from);
2814 case T_UnlistenStmt:
2815 retval = _copyUnlistenStmt(from);
2817 case T_TransactionStmt:
2818 retval = _copyTransactionStmt(from);
2821 retval = _copyViewStmt(from);
2824 retval = _copyLoadStmt(from);
2826 case T_CreatedbStmt:
2827 retval = _copyCreatedbStmt(from);
2830 retval = _copyDropdbStmt(from);
2833 retval = _copyVacuumStmt(from);
2836 retval = _copyExplainStmt(from);
2838 case T_CreateSeqStmt:
2839 retval = _copyCreateSeqStmt(from);
2841 case T_VariableSetStmt:
2842 retval = _copyVariableSetStmt(from);
2844 case T_VariableShowStmt:
2845 retval = _copyVariableShowStmt(from);
2847 case T_VariableResetStmt:
2848 retval = _copyVariableResetStmt(from);
2850 case T_CreateTrigStmt:
2851 retval = _copyCreateTrigStmt(from);
2853 case T_DropTrigStmt:
2854 retval = _copyDropTrigStmt(from);
2856 case T_CreatePLangStmt:
2857 retval = _copyCreatePLangStmt(from);
2859 case T_DropPLangStmt:
2860 retval = _copyDropPLangStmt(from);
2862 case T_CreateUserStmt:
2863 retval = _copyCreateUserStmt(from);
2865 case T_AlterUserStmt:
2866 retval = _copyAlterUserStmt(from);
2868 case T_DropUserStmt:
2869 retval = _copyDropUserStmt(from);
2872 retval = _copyLockStmt(from);
2874 case T_ConstraintsSetStmt:
2875 retval = _copyConstraintsSetStmt(from);
2877 case T_CreateGroupStmt:
2878 retval = _copyCreateGroupStmt(from);
2880 case T_AlterGroupStmt:
2881 retval = _copyAlterGroupStmt(from);
2883 case T_DropGroupStmt:
2884 retval = _copyDropGroupStmt(from);
2887 retval = _copyReindexStmt(from);
2889 case T_SetSessionStmt:
2890 retval = _copySetSessionStmt(from);
2894 retval = _copyAExpr(from);
2897 retval = _copyAttr(from);
2900 retval = _copyAConst(from);
2903 retval = _copyParamNo(from);
2906 retval = _copyIdent(from);
2909 retval = _copyFuncCall(from);
2912 retval = _copyAIndices(from);
2915 retval = _copyResTarget(from);
2918 retval = _copyTypeCast(from);
2921 retval = _copySortGroupBy(from);
2924 retval = _copyRangeVar(from);
2926 case T_RangeSubselect:
2927 retval = _copyRangeSubselect(from);
2930 retval = _copyTypeName(from);
2933 retval = _copyIndexElem(from);
2936 retval = _copyColumnDef(from);
2939 retval = _copyConstraint(from);
2942 retval = _copyDefElem(from);
2945 retval = _copyTargetEntry(from);
2947 case T_RangeTblEntry:
2948 retval = _copyRangeTblEntry(from);
2951 retval = _copySortClause(from);
2954 retval = _copyGroupClause(from);
2957 retval = _copyCaseExpr(from);
2960 retval = _copyCaseWhen(from);
2962 case T_FkConstraint:
2963 retval = _copyFkConstraint(from);
2967 elog(ERROR, "copyObject: don't know how to copy node type %d",
2969 retval = from; /* keep compiler quiet */