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-2001, PostgreSQL Global Development Group
15 * Portions Copyright (c) 1994, Regents of the University of California
18 * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.146 2001/07/10 22:09:28 tgl Exp $
20 *-------------------------------------------------------------------------
25 #include "optimizer/clauses.h"
26 #include "optimizer/planmain.h"
31 * a macro to simplify calling of copyObject on the specified field
33 #define Node_Copy(from, newnode, field) \
34 ((newnode)->field = copyObject((from)->field))
39 * This copy function only copies the "cons-cells" of the list, not the
40 * pointed-to objects. (Use copyObject if you want a "deep" copy.)
42 * We also use this function for copying lists of integers, which is
43 * grotty but unlikely to break --- it could fail if sizeof(pointer)
44 * is less than sizeof(int), but I don't know any such machines...
46 * Note that copyObject will surely coredump if applied to a list
56 /* rather ugly coding for speed... */
60 newlist = nl = makeList1(lfirst(list));
62 foreach(l, lnext(list))
64 lnext(nl) = makeList1(lfirst(l));
70 /* ****************************************************************
71 * plannodes.h copy functions
72 * ****************************************************************
78 * This function copies the fields of the Plan node. It is used by
79 * all the copy functions for classes which inherit from Plan.
83 CopyPlanFields(Plan *from, Plan *newnode)
85 newnode->startup_cost = from->startup_cost;
86 newnode->total_cost = from->total_cost;
87 newnode->plan_rows = from->plan_rows;
88 newnode->plan_width = from->plan_width;
89 /* state is NOT copied */
90 Node_Copy(from, newnode, targetlist);
91 Node_Copy(from, newnode, qual);
92 Node_Copy(from, newnode, lefttree);
93 Node_Copy(from, newnode, righttree);
94 newnode->extParam = listCopy(from->extParam);
95 newnode->locParam = listCopy(from->locParam);
96 newnode->chgParam = listCopy(from->chgParam);
97 Node_Copy(from, newnode, initPlan);
98 /* subPlan list must point to subplans in the new subtree, not the old */
99 if (from->subPlan != NIL)
100 newnode->subPlan = nconc(pull_subplans((Node *) newnode->targetlist),
101 pull_subplans((Node *) newnode->qual));
103 newnode->subPlan = NIL;
104 newnode->nParamExec = from->nParamExec;
112 _copyPlan(Plan *from)
114 Plan *newnode = makeNode(Plan);
117 * copy the node superclass fields
119 CopyPlanFields(from, newnode);
130 _copyResult(Result *from)
132 Result *newnode = makeNode(Result);
135 * copy node superclass fields
137 CopyPlanFields((Plan *) from, (Plan *) newnode);
140 * copy remainder of node
142 Node_Copy(from, newnode, resconstantqual);
145 * We must add subplans in resconstantqual to the new plan's subPlan
148 if (from->plan.subPlan != NIL)
149 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
150 pull_subplans(newnode->resconstantqual));
160 _copyAppend(Append *from)
162 Append *newnode = makeNode(Append);
165 * copy node superclass fields
167 CopyPlanFields((Plan *) from, (Plan *) newnode);
170 * copy remainder of node
172 Node_Copy(from, newnode, appendplans);
173 newnode->isTarget = from->isTarget;
182 * This function copies the fields of the Scan node. It is used by
183 * all the copy functions for classes which inherit from Scan.
187 CopyScanFields(Scan *from, Scan *newnode)
189 newnode->scanrelid = from->scanrelid;
198 _copyScan(Scan *from)
200 Scan *newnode = makeNode(Scan);
203 * copy node superclass fields
205 CopyPlanFields((Plan *) from, (Plan *) newnode);
206 CopyScanFields((Scan *) from, (Scan *) newnode);
216 _copySeqScan(SeqScan *from)
218 SeqScan *newnode = makeNode(SeqScan);
221 * copy node superclass fields
223 CopyPlanFields((Plan *) from, (Plan *) newnode);
224 CopyScanFields((Scan *) from, (Scan *) newnode);
234 _copyIndexScan(IndexScan *from)
236 IndexScan *newnode = makeNode(IndexScan);
239 * copy node superclass fields
241 CopyPlanFields((Plan *) from, (Plan *) newnode);
242 CopyScanFields((Scan *) from, (Scan *) newnode);
245 * copy remainder of node
247 newnode->indxid = listCopy(from->indxid);
248 Node_Copy(from, newnode, indxqual);
249 Node_Copy(from, newnode, indxqualorig);
250 newnode->indxorderdir = from->indxorderdir;
253 * We must add subplans in index quals to the new plan's subPlan list
255 if (from->scan.plan.subPlan != NIL)
257 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
258 pull_subplans((Node *) newnode->indxqual));
259 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
260 pull_subplans((Node *) newnode->indxqualorig));
271 _copyTidScan(TidScan *from)
273 TidScan *newnode = makeNode(TidScan);
276 * copy node superclass fields
278 CopyPlanFields((Plan *) from, (Plan *) newnode);
279 CopyScanFields((Scan *) from, (Scan *) newnode);
282 * copy remainder of node
284 newnode->needRescan = from->needRescan;
285 Node_Copy(from, newnode, tideval);
294 static SubqueryScan *
295 _copySubqueryScan(SubqueryScan *from)
297 SubqueryScan *newnode = makeNode(SubqueryScan);
300 * copy node superclass fields
302 CopyPlanFields((Plan *) from, (Plan *) newnode);
303 CopyScanFields((Scan *) from, (Scan *) newnode);
306 * copy remainder of node
308 Node_Copy(from, newnode, subplan);
317 * This function copies the fields of the Join node. It is used by
318 * all the copy functions for classes which inherit from Join.
322 CopyJoinFields(Join *from, Join *newnode)
324 newnode->jointype = from->jointype;
325 Node_Copy(from, newnode, joinqual);
326 /* subPlan list must point to subplans in the new subtree, not the old */
327 if (from->plan.subPlan != NIL)
328 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
329 pull_subplans((Node *) newnode->joinqual));
338 _copyJoin(Join *from)
340 Join *newnode = makeNode(Join);
343 * copy node superclass fields
345 CopyPlanFields((Plan *) from, (Plan *) newnode);
346 CopyJoinFields(from, newnode);
357 _copyNestLoop(NestLoop *from)
359 NestLoop *newnode = makeNode(NestLoop);
362 * copy node superclass fields
364 CopyPlanFields((Plan *) from, (Plan *) newnode);
365 CopyJoinFields((Join *) from, (Join *) newnode);
376 _copyMergeJoin(MergeJoin *from)
378 MergeJoin *newnode = makeNode(MergeJoin);
381 * copy node superclass fields
383 CopyPlanFields((Plan *) from, (Plan *) newnode);
384 CopyJoinFields((Join *) from, (Join *) newnode);
387 * copy remainder of node
389 Node_Copy(from, newnode, mergeclauses);
392 * We must add subplans in mergeclauses to the new plan's subPlan list
394 if (from->join.plan.subPlan != NIL)
395 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
396 pull_subplans((Node *) newnode->mergeclauses));
406 _copyHashJoin(HashJoin *from)
408 HashJoin *newnode = makeNode(HashJoin);
411 * copy node superclass fields
413 CopyPlanFields((Plan *) from, (Plan *) newnode);
414 CopyJoinFields((Join *) from, (Join *) newnode);
417 * copy remainder of node
419 Node_Copy(from, newnode, hashclauses);
420 newnode->hashjoinop = from->hashjoinop;
423 * We must add subplans in hashclauses to the new plan's subPlan list
425 if (from->join.plan.subPlan != NIL)
426 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
427 pull_subplans((Node *) newnode->hashclauses));
438 _copyMaterial(Material *from)
440 Material *newnode = makeNode(Material);
443 * copy node superclass fields
445 CopyPlanFields((Plan *) from, (Plan *) newnode);
456 _copySort(Sort *from)
458 Sort *newnode = makeNode(Sort);
461 * copy node superclass fields
463 CopyPlanFields((Plan *) from, (Plan *) newnode);
465 newnode->keycount = from->keycount;
476 _copyGroup(Group *from)
478 Group *newnode = makeNode(Group);
480 CopyPlanFields((Plan *) from, (Plan *) newnode);
482 newnode->tuplePerGroup = from->tuplePerGroup;
483 newnode->numCols = from->numCols;
484 newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
485 memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
497 Agg *newnode = makeNode(Agg);
499 CopyPlanFields((Plan *) from, (Plan *) newnode);
509 _copyGroupClause(GroupClause *from)
511 GroupClause *newnode = makeNode(GroupClause);
513 newnode->tleSortGroupRef = from->tleSortGroupRef;
514 newnode->sortop = from->sortop;
524 _copyUnique(Unique *from)
526 Unique *newnode = makeNode(Unique);
529 * copy node superclass fields
531 CopyPlanFields((Plan *) from, (Plan *) newnode);
534 * copy remainder of node
536 newnode->numCols = from->numCols;
537 newnode->uniqColIdx = palloc(from->numCols * sizeof(AttrNumber));
538 memcpy(newnode->uniqColIdx, from->uniqColIdx, from->numCols * sizeof(AttrNumber));
548 _copySetOp(SetOp *from)
550 SetOp *newnode = makeNode(SetOp);
553 * copy node superclass fields
555 CopyPlanFields((Plan *) from, (Plan *) newnode);
558 * copy remainder of node
560 newnode->cmd = from->cmd;
561 newnode->numCols = from->numCols;
562 newnode->dupColIdx = palloc(from->numCols * sizeof(AttrNumber));
563 memcpy(newnode->dupColIdx, from->dupColIdx, from->numCols * sizeof(AttrNumber));
564 newnode->flagColIdx = from->flagColIdx;
574 _copyLimit(Limit *from)
576 Limit *newnode = makeNode(Limit);
579 * copy node superclass fields
581 CopyPlanFields((Plan *) from, (Plan *) newnode);
584 * copy remainder of node
586 Node_Copy(from, newnode, limitOffset);
587 Node_Copy(from, newnode, limitCount);
597 _copyHash(Hash *from)
599 Hash *newnode = makeNode(Hash);
602 * copy node superclass fields
604 CopyPlanFields((Plan *) from, (Plan *) newnode);
607 * copy remainder of node
609 Node_Copy(from, newnode, hashkey);
615 _copySubPlan(SubPlan *from)
617 SubPlan *newnode = makeNode(SubPlan);
619 Node_Copy(from, newnode, plan);
620 newnode->plan_id = from->plan_id;
621 Node_Copy(from, newnode, rtable);
622 newnode->setParam = listCopy(from->setParam);
623 newnode->parParam = listCopy(from->parParam);
624 Node_Copy(from, newnode, sublink);
626 /* do not copy execution state */
627 newnode->needShutdown = false;
628 newnode->curTuple = NULL;
633 /* ****************************************************************
634 * primnodes.h copy functions
635 * ****************************************************************
643 _copyResdom(Resdom *from)
645 Resdom *newnode = makeNode(Resdom);
647 newnode->resno = from->resno;
648 newnode->restype = from->restype;
649 newnode->restypmod = from->restypmod;
650 if (from->resname != NULL)
651 newnode->resname = pstrdup(from->resname);
652 newnode->ressortgroupref = from->ressortgroupref;
653 newnode->reskey = from->reskey;
654 newnode->reskeyop = from->reskeyop;
655 newnode->resjunk = from->resjunk;
661 _copyFjoin(Fjoin *from)
663 Fjoin *newnode = makeNode(Fjoin);
666 * copy node superclass fields
669 newnode->fj_initialized = from->fj_initialized;
670 newnode->fj_nNodes = from->fj_nNodes;
672 Node_Copy(from, newnode, fj_innerNode);
674 newnode->fj_results = (DatumPtr)
675 palloc((from->fj_nNodes) * sizeof(Datum));
676 memmove(from->fj_results,
678 (from->fj_nNodes) * sizeof(Datum));
680 newnode->fj_alwaysDone = (BoolPtr)
681 palloc((from->fj_nNodes) * sizeof(bool));
682 memmove(from->fj_alwaysDone,
683 newnode->fj_alwaysDone,
684 (from->fj_nNodes) * sizeof(bool));
695 _copyExpr(Expr *from)
697 Expr *newnode = makeNode(Expr);
700 * copy node superclass fields
702 newnode->typeOid = from->typeOid;
703 newnode->opType = from->opType;
705 Node_Copy(from, newnode, oper);
706 Node_Copy(from, newnode, args);
718 Var *newnode = makeNode(Var);
721 * copy remainder of node
723 newnode->varno = from->varno;
724 newnode->varattno = from->varattno;
725 newnode->vartype = from->vartype;
726 newnode->vartypmod = from->vartypmod;
727 newnode->varlevelsup = from->varlevelsup;
729 newnode->varnoold = from->varnoold;
730 newnode->varoattno = from->varoattno;
736 _copyAttr(Attr *from)
738 Attr *newnode = makeNode(Attr);
741 newnode->relname = pstrdup(from->relname);
742 Node_Copy(from, newnode, attrs);
752 _copyOper(Oper *from)
754 Oper *newnode = makeNode(Oper);
757 * copy remainder of node
759 newnode->opno = from->opno;
760 newnode->opid = from->opid;
761 newnode->opresulttype = from->opresulttype;
762 /* Do not copy the run-time state, if any */
763 newnode->op_fcache = NULL;
773 _copyConst(Const *from)
775 Const *newnode = makeNode(Const);
778 * copy remainder of node
780 newnode->consttype = from->consttype;
781 newnode->constlen = from->constlen;
783 if (from->constbyval || from->constisnull)
787 * passed by value so just copy the datum. Also, don't try to copy
788 * struct when value is null!
791 newnode->constvalue = from->constvalue;
797 * not passed by value. datum contains a pointer.
799 int length = from->constlen;
801 if (length == -1) /* variable-length type? */
802 length = VARSIZE(from->constvalue);
803 newnode->constvalue = PointerGetDatum(palloc(length));
804 memcpy(DatumGetPointer(newnode->constvalue),
805 DatumGetPointer(from->constvalue),
809 newnode->constisnull = from->constisnull;
810 newnode->constbyval = from->constbyval;
811 newnode->constisset = from->constisset;
812 newnode->constiscast = from->constiscast;
822 _copyParam(Param *from)
824 Param *newnode = makeNode(Param);
827 * copy remainder of node
829 newnode->paramkind = from->paramkind;
830 newnode->paramid = from->paramid;
832 if (from->paramname != NULL)
833 newnode->paramname = pstrdup(from->paramname);
834 newnode->paramtype = from->paramtype;
844 _copyFunc(Func *from)
846 Func *newnode = makeNode(Func);
849 * copy remainder of node
851 newnode->funcid = from->funcid;
852 newnode->functype = from->functype;
853 /* Do not copy the run-time state, if any */
854 newnode->func_fcache = NULL;
864 _copyAggref(Aggref *from)
866 Aggref *newnode = makeNode(Aggref);
869 * copy remainder of node
871 newnode->aggname = pstrdup(from->aggname);
872 newnode->basetype = from->basetype;
873 newnode->aggtype = from->aggtype;
874 Node_Copy(from, newnode, target);
875 newnode->aggstar = from->aggstar;
876 newnode->aggdistinct = from->aggdistinct;
877 newnode->aggno = from->aggno; /* probably not needed */
887 _copySubLink(SubLink *from)
889 SubLink *newnode = makeNode(SubLink);
892 * copy remainder of node
894 newnode->subLinkType = from->subLinkType;
895 newnode->useor = from->useor;
896 Node_Copy(from, newnode, lefthand);
897 Node_Copy(from, newnode, oper);
898 Node_Copy(from, newnode, subselect);
908 _copyFieldSelect(FieldSelect *from)
910 FieldSelect *newnode = makeNode(FieldSelect);
913 * copy remainder of node
915 Node_Copy(from, newnode, arg);
916 newnode->fieldnum = from->fieldnum;
917 newnode->resulttype = from->resulttype;
918 newnode->resulttypmod = from->resulttypmod;
928 _copyRelabelType(RelabelType *from)
930 RelabelType *newnode = makeNode(RelabelType);
933 * copy remainder of node
935 Node_Copy(from, newnode, arg);
936 newnode->resulttype = from->resulttype;
937 newnode->resulttypmod = from->resulttypmod;
943 _copyRangeTblRef(RangeTblRef *from)
945 RangeTblRef *newnode = makeNode(RangeTblRef);
947 newnode->rtindex = from->rtindex;
953 _copyFromExpr(FromExpr *from)
955 FromExpr *newnode = makeNode(FromExpr);
957 Node_Copy(from, newnode, fromlist);
958 Node_Copy(from, newnode, quals);
964 _copyJoinExpr(JoinExpr *from)
966 JoinExpr *newnode = makeNode(JoinExpr);
968 newnode->jointype = from->jointype;
969 newnode->isNatural = from->isNatural;
970 Node_Copy(from, newnode, larg);
971 Node_Copy(from, newnode, rarg);
972 Node_Copy(from, newnode, using);
973 Node_Copy(from, newnode, quals);
974 Node_Copy(from, newnode, alias);
975 Node_Copy(from, newnode, colnames);
976 Node_Copy(from, newnode, colvars);
986 _copyCaseExpr(CaseExpr *from)
988 CaseExpr *newnode = makeNode(CaseExpr);
991 * copy remainder of node
993 newnode->casetype = from->casetype;
995 Node_Copy(from, newnode, arg);
996 Node_Copy(from, newnode, args);
997 Node_Copy(from, newnode, defresult);
1007 _copyCaseWhen(CaseWhen *from)
1009 CaseWhen *newnode = makeNode(CaseWhen);
1012 * copy remainder of node
1014 Node_Copy(from, newnode, expr);
1015 Node_Copy(from, newnode, result);
1025 _copyNullTest(NullTest *from)
1027 NullTest *newnode = makeNode(NullTest);
1030 * copy remainder of node
1032 Node_Copy(from, newnode, arg);
1033 newnode->nulltesttype = from->nulltesttype;
1042 static BooleanTest *
1043 _copyBooleanTest(BooleanTest *from)
1045 BooleanTest *newnode = makeNode(BooleanTest);
1048 * copy remainder of node
1050 Node_Copy(from, newnode, arg);
1051 newnode->booltesttype = from->booltesttype;
1057 _copyArrayRef(ArrayRef *from)
1059 ArrayRef *newnode = makeNode(ArrayRef);
1062 * copy remainder of node
1064 newnode->refattrlength = from->refattrlength;
1065 newnode->refelemlength = from->refelemlength;
1066 newnode->refelemtype = from->refelemtype;
1067 newnode->refelembyval = from->refelembyval;
1069 Node_Copy(from, newnode, refupperindexpr);
1070 Node_Copy(from, newnode, reflowerindexpr);
1071 Node_Copy(from, newnode, refexpr);
1072 Node_Copy(from, newnode, refassgnexpr);
1077 /* ****************************************************************
1078 * relation.h copy functions
1079 * ****************************************************************
1087 * when you change this, also make sure to fix up xfunc_copyRelOptInfo in
1088 * planner/path/xfunc.c accordingly!!!
1092 _copyRelOptInfo(RelOptInfo *from)
1094 RelOptInfo *newnode = makeNode(RelOptInfo);
1096 newnode->relids = listCopy(from->relids);
1098 newnode->rows = from->rows;
1099 newnode->width = from->width;
1101 Node_Copy(from, newnode, targetlist);
1102 Node_Copy(from, newnode, pathlist);
1103 /* XXX cheapest-path fields should point to members of pathlist? */
1104 Node_Copy(from, newnode, cheapest_startup_path);
1105 Node_Copy(from, newnode, cheapest_total_path);
1106 newnode->pruneable = from->pruneable;
1108 newnode->issubquery = from->issubquery;
1109 Node_Copy(from, newnode, indexlist);
1110 newnode->pages = from->pages;
1111 newnode->tuples = from->tuples;
1112 Node_Copy(from, newnode, subplan);
1114 Node_Copy(from, newnode, baserestrictinfo);
1115 newnode->baserestrictcost = from->baserestrictcost;
1116 newnode->outerjoinset = listCopy(from->outerjoinset);
1117 Node_Copy(from, newnode, joininfo);
1118 Node_Copy(from, newnode, innerjoin);
1127 static IndexOptInfo *
1128 _copyIndexOptInfo(IndexOptInfo *from)
1130 IndexOptInfo *newnode = makeNode(IndexOptInfo);
1133 newnode->indexoid = from->indexoid;
1134 newnode->pages = from->pages;
1135 newnode->tuples = from->tuples;
1137 newnode->ncolumns = from->ncolumns;
1138 newnode->nkeys = from->nkeys;
1140 if (from->classlist)
1142 /* copy the trailing zero too */
1143 len = (from->ncolumns + 1) * sizeof(Oid);
1144 newnode->classlist = (Oid *) palloc(len);
1145 memcpy(newnode->classlist, from->classlist, len);
1148 if (from->indexkeys)
1150 /* copy the trailing zero too */
1151 len = (from->nkeys + 1) * sizeof(int);
1152 newnode->indexkeys = (int *) palloc(len);
1153 memcpy(newnode->indexkeys, from->indexkeys, len);
1158 /* copy the trailing zero too */
1159 len = (from->ncolumns + 1) * sizeof(Oid);
1160 newnode->ordering = (Oid *) palloc(len);
1161 memcpy(newnode->ordering, from->ordering, len);
1164 newnode->relam = from->relam;
1165 newnode->amcostestimate = from->amcostestimate;
1166 newnode->indproc = from->indproc;
1167 Node_Copy(from, newnode, indpred);
1168 newnode->unique = from->unique;
1169 newnode->lossy = from->lossy;
1177 * This function copies the fields of the Path node. It is used by
1178 * all the copy functions for classes which inherit from Path.
1182 CopyPathFields(Path *from, Path *newnode)
1186 * Modify the next line, since it causes the copying to cycle (i.e.
1187 * the parent points right back here! -- JMH, 7/7/92. Old version:
1188 * Node_Copy(from, newnode, parent);
1190 newnode->parent = from->parent;
1192 newnode->startup_cost = from->startup_cost;
1193 newnode->total_cost = from->total_cost;
1195 newnode->pathtype = from->pathtype;
1197 Node_Copy(from, newnode, pathkeys);
1205 _copyPath(Path *from)
1207 Path *newnode = makeNode(Path);
1209 CopyPathFields(from, newnode);
1219 _copyIndexPath(IndexPath *from)
1221 IndexPath *newnode = makeNode(IndexPath);
1224 * copy the node superclass fields
1226 CopyPathFields((Path *) from, (Path *) newnode);
1229 * copy remainder of node
1231 Node_Copy(from, newnode, indexinfo);
1232 Node_Copy(from, newnode, indexqual);
1233 newnode->indexscandir = from->indexscandir;
1234 newnode->joinrelids = listCopy(from->joinrelids);
1235 newnode->alljoinquals = from->alljoinquals;
1236 newnode->rows = from->rows;
1246 _copyTidPath(TidPath *from)
1248 TidPath *newnode = makeNode(TidPath);
1251 * copy the node superclass fields
1253 CopyPathFields((Path *) from, (Path *) newnode);
1256 * copy remainder of node
1258 Node_Copy(from, newnode, tideval);
1259 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1269 _copyAppendPath(AppendPath *from)
1271 AppendPath *newnode = makeNode(AppendPath);
1274 * copy the node superclass fields
1276 CopyPathFields((Path *) from, (Path *) newnode);
1279 * copy remainder of node
1281 Node_Copy(from, newnode, subpaths);
1287 * CopyJoinPathFields
1289 * This function copies the fields of the JoinPath node. It is used by
1290 * all the copy functions for classes which inherit from JoinPath.
1294 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1296 newnode->jointype = from->jointype;
1297 Node_Copy(from, newnode, outerjoinpath);
1298 Node_Copy(from, newnode, innerjoinpath);
1299 Node_Copy(from, newnode, joinrestrictinfo);
1307 _copyNestPath(NestPath *from)
1309 NestPath *newnode = makeNode(NestPath);
1312 * copy the node superclass fields
1314 CopyPathFields((Path *) from, (Path *) newnode);
1315 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1325 _copyMergePath(MergePath *from)
1327 MergePath *newnode = makeNode(MergePath);
1330 * copy the node superclass fields
1332 CopyPathFields((Path *) from, (Path *) newnode);
1333 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1336 * copy the remainder of the node
1338 Node_Copy(from, newnode, path_mergeclauses);
1339 Node_Copy(from, newnode, outersortkeys);
1340 Node_Copy(from, newnode, innersortkeys);
1350 _copyHashPath(HashPath *from)
1352 HashPath *newnode = makeNode(HashPath);
1355 * copy the node superclass fields
1357 CopyPathFields((Path *) from, (Path *) newnode);
1358 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1361 * copy remainder of node
1363 Node_Copy(from, newnode, path_hashclauses);
1372 static PathKeyItem *
1373 _copyPathKeyItem(PathKeyItem *from)
1375 PathKeyItem *newnode = makeNode(PathKeyItem);
1378 * copy remainder of node
1380 Node_Copy(from, newnode, key);
1381 newnode->sortop = from->sortop;
1390 static RestrictInfo *
1391 _copyRestrictInfo(RestrictInfo *from)
1393 RestrictInfo *newnode = makeNode(RestrictInfo);
1396 * copy remainder of node
1398 Node_Copy(from, newnode, clause);
1399 newnode->ispusheddown = from->ispusheddown;
1400 Node_Copy(from, newnode, subclauseindices);
1401 newnode->eval_cost = from->eval_cost;
1402 newnode->this_selec = from->this_selec;
1403 newnode->mergejoinoperator = from->mergejoinoperator;
1404 newnode->left_sortop = from->left_sortop;
1405 newnode->right_sortop = from->right_sortop;
1408 * Do not copy pathkeys, since they'd not be canonical in a copied
1411 newnode->left_pathkey = NIL;
1412 newnode->right_pathkey = NIL;
1413 newnode->hashjoinoperator = from->hashjoinoperator;
1414 newnode->left_bucketsize = from->left_bucketsize;
1415 newnode->right_bucketsize = from->right_bucketsize;
1425 _copyJoinInfo(JoinInfo *from)
1427 JoinInfo *newnode = makeNode(JoinInfo);
1430 * copy remainder of node
1432 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1433 Node_Copy(from, newnode, jinfo_restrictinfo);
1439 _copyIter(Iter *from)
1441 Iter *newnode = makeNode(Iter);
1443 Node_Copy(from, newnode, iterexpr);
1444 newnode->itertype = from->itertype;
1450 _copyStream(Stream *from)
1452 Stream *newnode = makeNode(Stream);
1454 newnode->pathptr = from->pathptr;
1455 newnode->cinfo = from->cinfo;
1456 newnode->clausetype = from->clausetype;
1458 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1460 Node_Copy(from, newnode, downstream);
1461 if (newnode->downstream)
1462 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1464 newnode->groupup = from->groupup;
1465 newnode->groupcost = from->groupcost;
1466 newnode->groupsel = from->groupsel;
1471 /* ****************************************************************
1472 * parsenodes.h copy functions
1473 * ****************************************************************
1476 static TargetEntry *
1477 _copyTargetEntry(TargetEntry *from)
1479 TargetEntry *newnode = makeNode(TargetEntry);
1481 Node_Copy(from, newnode, resdom);
1482 Node_Copy(from, newnode, fjoin);
1483 Node_Copy(from, newnode, expr);
1487 static RangeTblEntry *
1488 _copyRangeTblEntry(RangeTblEntry *from)
1490 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1493 newnode->relname = pstrdup(from->relname);
1494 newnode->relid = from->relid;
1495 Node_Copy(from, newnode, subquery);
1496 Node_Copy(from, newnode, alias);
1497 Node_Copy(from, newnode, eref);
1498 newnode->inh = from->inh;
1499 newnode->inFromCl = from->inFromCl;
1500 newnode->checkForRead = from->checkForRead;
1501 newnode->checkForWrite = from->checkForWrite;
1502 newnode->checkAsUser = from->checkAsUser;
1507 static FkConstraint *
1508 _copyFkConstraint(FkConstraint *from)
1510 FkConstraint *newnode = makeNode(FkConstraint);
1512 if (from->constr_name)
1513 newnode->constr_name = pstrdup(from->constr_name);
1514 if (from->pktable_name)
1515 newnode->pktable_name = pstrdup(from->pktable_name);
1516 Node_Copy(from, newnode, fk_attrs);
1517 Node_Copy(from, newnode, pk_attrs);
1518 if (from->match_type)
1519 newnode->match_type = pstrdup(from->match_type);
1520 newnode->actions = from->actions;
1521 newnode->deferrable = from->deferrable;
1522 newnode->initdeferred = from->initdeferred;
1528 _copySortClause(SortClause *from)
1530 SortClause *newnode = makeNode(SortClause);
1532 newnode->tleSortGroupRef = from->tleSortGroupRef;
1533 newnode->sortop = from->sortop;
1539 _copyAExpr(A_Expr *from)
1541 A_Expr *newnode = makeNode(A_Expr);
1543 newnode->oper = from->oper;
1545 newnode->opname = pstrdup(from->opname);
1546 Node_Copy(from, newnode, lexpr);
1547 Node_Copy(from, newnode, rexpr);
1553 _copyAConst(A_Const *from)
1555 A_Const *newnode = makeNode(A_Const);
1557 newnode->val = *((Value *) (copyObject(&(from->val))));
1558 Node_Copy(from, newnode, typename);
1564 _copyParamNo(ParamNo *from)
1566 ParamNo *newnode = makeNode(ParamNo);
1568 newnode->number = from->number;
1569 Node_Copy(from, newnode, typename);
1570 Node_Copy(from, newnode, indirection);
1576 _copyIdent(Ident *from)
1578 Ident *newnode = makeNode(Ident);
1581 newnode->name = pstrdup(from->name);
1582 Node_Copy(from, newnode, indirection);
1583 newnode->isRel = from->isRel;
1589 _copyFuncCall(FuncCall *from)
1591 FuncCall *newnode = makeNode(FuncCall);
1594 newnode->funcname = pstrdup(from->funcname);
1595 Node_Copy(from, newnode, args);
1596 newnode->agg_star = from->agg_star;
1597 newnode->agg_distinct = from->agg_distinct;
1603 _copyAIndices(A_Indices *from)
1605 A_Indices *newnode = makeNode(A_Indices);
1607 Node_Copy(from, newnode, lidx);
1608 Node_Copy(from, newnode, uidx);
1614 _copyResTarget(ResTarget *from)
1616 ResTarget *newnode = makeNode(ResTarget);
1619 newnode->name = pstrdup(from->name);
1620 Node_Copy(from, newnode, indirection);
1621 Node_Copy(from, newnode, val);
1627 _copyTypeName(TypeName *from)
1629 TypeName *newnode = makeNode(TypeName);
1632 newnode->name = pstrdup(from->name);
1633 newnode->timezone = from->timezone;
1634 newnode->setof = from->setof;
1635 newnode->typmod = from->typmod;
1636 Node_Copy(from, newnode, arrayBounds);
1641 static SortGroupBy *
1642 _copySortGroupBy(SortGroupBy *from)
1644 SortGroupBy *newnode = makeNode(SortGroupBy);
1647 newnode->useOp = pstrdup(from->useOp);
1648 Node_Copy(from, newnode, node);
1654 _copyRangeVar(RangeVar *from)
1656 RangeVar *newnode = makeNode(RangeVar);
1659 newnode->relname = pstrdup(from->relname);
1660 newnode->inhOpt = from->inhOpt;
1661 Node_Copy(from, newnode, name);
1666 static RangeSubselect *
1667 _copyRangeSubselect(RangeSubselect *from)
1669 RangeSubselect *newnode = makeNode(RangeSubselect);
1671 Node_Copy(from, newnode, subquery);
1672 Node_Copy(from, newnode, name);
1678 _copyTypeCast(TypeCast *from)
1680 TypeCast *newnode = makeNode(TypeCast);
1682 Node_Copy(from, newnode, arg);
1683 Node_Copy(from, newnode, typename);
1689 _copyIndexElem(IndexElem *from)
1691 IndexElem *newnode = makeNode(IndexElem);
1694 newnode->name = pstrdup(from->name);
1695 Node_Copy(from, newnode, args);
1697 newnode->class = pstrdup(from->class);
1703 _copyColumnDef(ColumnDef *from)
1705 ColumnDef *newnode = makeNode(ColumnDef);
1708 newnode->colname = pstrdup(from->colname);
1709 Node_Copy(from, newnode, typename);
1710 newnode->is_not_null = from->is_not_null;
1711 newnode->is_sequence = from->is_sequence;
1712 Node_Copy(from, newnode, raw_default);
1713 if (from->cooked_default)
1714 newnode->cooked_default = pstrdup(from->cooked_default);
1715 Node_Copy(from, newnode, constraints);
1721 _copyConstraint(Constraint *from)
1723 Constraint *newnode = makeNode(Constraint);
1725 newnode->contype = from->contype;
1727 newnode->name = pstrdup(from->name);
1728 Node_Copy(from, newnode, raw_expr);
1729 if (from->cooked_expr)
1730 newnode->cooked_expr = pstrdup(from->cooked_expr);
1731 Node_Copy(from, newnode, keys);
1737 _copyDefElem(DefElem *from)
1739 DefElem *newnode = makeNode(DefElem);
1742 newnode->defname = pstrdup(from->defname);
1743 Node_Copy(from, newnode, arg);
1749 _copyQuery(Query *from)
1751 Query *newnode = makeNode(Query);
1753 newnode->commandType = from->commandType;
1754 Node_Copy(from, newnode, utilityStmt);
1755 newnode->resultRelation = from->resultRelation;
1757 newnode->into = pstrdup(from->into);
1758 newnode->isPortal = from->isPortal;
1759 newnode->isBinary = from->isBinary;
1760 newnode->isTemp = from->isTemp;
1761 newnode->hasAggs = from->hasAggs;
1762 newnode->hasSubLinks = from->hasSubLinks;
1764 Node_Copy(from, newnode, rtable);
1765 Node_Copy(from, newnode, jointree);
1767 newnode->rowMarks = listCopy(from->rowMarks);
1769 Node_Copy(from, newnode, targetList);
1771 Node_Copy(from, newnode, groupClause);
1772 Node_Copy(from, newnode, havingQual);
1773 Node_Copy(from, newnode, distinctClause);
1774 Node_Copy(from, newnode, sortClause);
1776 Node_Copy(from, newnode, limitOffset);
1777 Node_Copy(from, newnode, limitCount);
1779 Node_Copy(from, newnode, setOperations);
1781 newnode->resultRelations = listCopy(from->resultRelations);
1784 * We do not copy the planner internal fields: base_rel_list,
1785 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys.
1786 * Not entirely clear if this is right?
1793 _copyInsertStmt(InsertStmt *from)
1795 InsertStmt *newnode = makeNode(InsertStmt);
1798 newnode->relname = pstrdup(from->relname);
1799 Node_Copy(from, newnode, cols);
1800 Node_Copy(from, newnode, targetList);
1801 Node_Copy(from, newnode, selectStmt);
1807 _copyDeleteStmt(DeleteStmt *from)
1809 DeleteStmt *newnode = makeNode(DeleteStmt);
1812 newnode->relname = pstrdup(from->relname);
1813 Node_Copy(from, newnode, whereClause);
1814 newnode->inhOpt = from->inhOpt;
1820 _copyUpdateStmt(UpdateStmt *from)
1822 UpdateStmt *newnode = makeNode(UpdateStmt);
1825 newnode->relname = pstrdup(from->relname);
1826 Node_Copy(from, newnode, targetList);
1827 Node_Copy(from, newnode, whereClause);
1828 Node_Copy(from, newnode, fromClause);
1829 newnode->inhOpt = from->inhOpt;
1835 _copySelectStmt(SelectStmt *from)
1837 SelectStmt *newnode = makeNode(SelectStmt);
1839 Node_Copy(from, newnode, distinctClause);
1841 newnode->into = pstrdup(from->into);
1842 newnode->istemp = from->istemp;
1843 Node_Copy(from, newnode, targetList);
1844 Node_Copy(from, newnode, fromClause);
1845 Node_Copy(from, newnode, whereClause);
1846 Node_Copy(from, newnode, groupClause);
1847 Node_Copy(from, newnode, havingClause);
1848 Node_Copy(from, newnode, sortClause);
1849 if (from->portalname)
1850 newnode->portalname = pstrdup(from->portalname);
1851 newnode->binary = from->binary;
1852 Node_Copy(from, newnode, limitOffset);
1853 Node_Copy(from, newnode, limitCount);
1854 Node_Copy(from, newnode, forUpdate);
1855 newnode->op = from->op;
1856 newnode->all = from->all;
1857 Node_Copy(from, newnode, larg);
1858 Node_Copy(from, newnode, rarg);
1863 static SetOperationStmt *
1864 _copySetOperationStmt(SetOperationStmt *from)
1866 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1868 newnode->op = from->op;
1869 newnode->all = from->all;
1870 Node_Copy(from, newnode, larg);
1871 Node_Copy(from, newnode, rarg);
1872 newnode->colTypes = listCopy(from->colTypes);
1877 static AlterTableStmt *
1878 _copyAlterTableStmt(AlterTableStmt *from)
1880 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1882 newnode->subtype = from->subtype;
1884 newnode->relname = pstrdup(from->relname);
1885 newnode->inhOpt = from->inhOpt;
1887 newnode->name = pstrdup(from->name);
1888 Node_Copy(from, newnode, def);
1889 newnode->behavior = from->behavior;
1895 _copyGrantStmt(GrantStmt *from)
1897 GrantStmt *newnode = makeNode(GrantStmt);
1899 newnode->is_grant = from->is_grant;
1900 Node_Copy(from, newnode, relnames);
1901 if (from->privileges)
1902 newnode->privileges = pstrdup(from->privileges);
1903 Node_Copy(from, newnode, grantees);
1908 static PrivGrantee *
1909 _copyPrivGrantee(PrivGrantee *from)
1911 PrivGrantee *newnode = makeNode(PrivGrantee);
1914 newnode->username = pstrdup(from->username);
1915 if (from->groupname)
1916 newnode->groupname = pstrdup(from->groupname);
1921 static ClosePortalStmt *
1922 _copyClosePortalStmt(ClosePortalStmt *from)
1924 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1926 if (from->portalname)
1927 newnode->portalname = pstrdup(from->portalname);
1932 static ClusterStmt *
1933 _copyClusterStmt(ClusterStmt *from)
1935 ClusterStmt *newnode = makeNode(ClusterStmt);
1938 newnode->relname = pstrdup(from->relname);
1939 if (from->indexname)
1940 newnode->indexname = pstrdup(from->indexname);
1946 _copyCopyStmt(CopyStmt *from)
1948 CopyStmt *newnode = makeNode(CopyStmt);
1950 newnode->binary = from->binary;
1952 newnode->relname = pstrdup(from->relname);
1953 newnode->oids = from->oids;
1954 newnode->direction = from->direction;
1956 newnode->filename = pstrdup(from->filename);
1957 if (from->delimiter)
1958 newnode->delimiter = pstrdup(from->delimiter);
1959 if (from->null_print)
1960 newnode->null_print = pstrdup(from->null_print);
1966 _copyCreateStmt(CreateStmt *from)
1968 CreateStmt *newnode = makeNode(CreateStmt);
1970 newnode->istemp = from->istemp;
1971 newnode->relname = pstrdup(from->relname);
1972 Node_Copy(from, newnode, tableElts);
1973 Node_Copy(from, newnode, inhRelnames);
1974 Node_Copy(from, newnode, constraints);
1979 static VersionStmt *
1980 _copyVersionStmt(VersionStmt *from)
1982 VersionStmt *newnode = makeNode(VersionStmt);
1984 newnode->relname = pstrdup(from->relname);
1985 newnode->direction = from->direction;
1986 newnode->fromRelname = pstrdup(from->fromRelname);
1987 newnode->date = pstrdup(from->date);
1993 _copyDefineStmt(DefineStmt *from)
1995 DefineStmt *newnode = makeNode(DefineStmt);
1997 newnode->defType = from->defType;
1998 newnode->defname = pstrdup(from->defname);
1999 Node_Copy(from, newnode, definition);
2005 _copyDropStmt(DropStmt *from)
2007 DropStmt *newnode = makeNode(DropStmt);
2009 Node_Copy(from, newnode, names);
2010 newnode->removeType = from->removeType;
2015 static TruncateStmt *
2016 _copyTruncateStmt(TruncateStmt *from)
2018 TruncateStmt *newnode = makeNode(TruncateStmt);
2020 newnode->relName = pstrdup(from->relName);
2025 static CommentStmt *
2026 _copyCommentStmt(CommentStmt *from)
2028 CommentStmt *newnode = makeNode(CommentStmt);
2030 newnode->objtype = from->objtype;
2031 newnode->objname = pstrdup(from->objname);
2032 if (from->objproperty)
2033 newnode->objproperty = pstrdup(from->objproperty);
2034 Node_Copy(from, newnode, objlist);
2035 newnode->comment = pstrdup(from->comment);
2041 _copyExtendStmt(ExtendStmt *from)
2043 ExtendStmt *newnode = makeNode(ExtendStmt);
2045 newnode->idxname = pstrdup(from->idxname);
2046 Node_Copy(from, newnode, whereClause);
2047 Node_Copy(from, newnode, rangetable);
2053 _copyFetchStmt(FetchStmt *from)
2055 FetchStmt *newnode = makeNode(FetchStmt);
2057 newnode->direction = from->direction;
2058 newnode->howMany = from->howMany;
2059 newnode->portalname = pstrdup(from->portalname);
2060 newnode->ismove = from->ismove;
2066 _copyIndexStmt(IndexStmt *from)
2068 IndexStmt *newnode = makeNode(IndexStmt);
2070 newnode->idxname = pstrdup(from->idxname);
2071 newnode->relname = pstrdup(from->relname);
2072 newnode->accessMethod = pstrdup(from->accessMethod);
2073 Node_Copy(from, newnode, indexParams);
2074 Node_Copy(from, newnode, withClause);
2075 Node_Copy(from, newnode, whereClause);
2076 Node_Copy(from, newnode, rangetable);
2077 newnode->unique = from->unique;
2078 newnode->primary = from->primary;
2083 static ProcedureStmt *
2084 _copyProcedureStmt(ProcedureStmt *from)
2086 ProcedureStmt *newnode = makeNode(ProcedureStmt);
2088 newnode->funcname = pstrdup(from->funcname);
2089 Node_Copy(from, newnode, argTypes);
2090 Node_Copy(from, newnode, returnType);
2091 Node_Copy(from, newnode, withClause);
2092 Node_Copy(from, newnode, as);
2093 newnode->language = pstrdup(from->language);
2098 static RemoveAggrStmt *
2099 _copyRemoveAggrStmt(RemoveAggrStmt *from)
2101 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
2103 newnode->aggname = pstrdup(from->aggname);
2104 Node_Copy(from, newnode, aggtype);
2109 static RemoveFuncStmt *
2110 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2112 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2114 newnode->funcname = pstrdup(from->funcname);
2115 Node_Copy(from, newnode, args);
2120 static RemoveOperStmt *
2121 _copyRemoveOperStmt(RemoveOperStmt *from)
2123 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2125 newnode->opname = pstrdup(from->opname);
2126 Node_Copy(from, newnode, args);
2132 _copyRenameStmt(RenameStmt *from)
2134 RenameStmt *newnode = makeNode(RenameStmt);
2136 newnode->relname = pstrdup(from->relname);
2137 newnode->inhOpt = from->inhOpt;
2139 newnode->column = pstrdup(from->column);
2141 newnode->newname = pstrdup(from->newname);
2147 _copyRuleStmt(RuleStmt *from)
2149 RuleStmt *newnode = makeNode(RuleStmt);
2151 newnode->rulename = pstrdup(from->rulename);
2152 Node_Copy(from, newnode, whereClause);
2153 newnode->event = from->event;
2154 Node_Copy(from, newnode, object);
2155 newnode->instead = from->instead;
2156 Node_Copy(from, newnode, actions);
2162 _copyNotifyStmt(NotifyStmt *from)
2164 NotifyStmt *newnode = makeNode(NotifyStmt);
2167 newnode->relname = pstrdup(from->relname);
2173 _copyListenStmt(ListenStmt *from)
2175 ListenStmt *newnode = makeNode(ListenStmt);
2178 newnode->relname = pstrdup(from->relname);
2183 static UnlistenStmt *
2184 _copyUnlistenStmt(UnlistenStmt *from)
2186 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2189 newnode->relname = pstrdup(from->relname);
2194 static TransactionStmt *
2195 _copyTransactionStmt(TransactionStmt *from)
2197 TransactionStmt *newnode = makeNode(TransactionStmt);
2199 newnode->command = from->command;
2205 _copyViewStmt(ViewStmt *from)
2207 ViewStmt *newnode = makeNode(ViewStmt);
2210 newnode->viewname = pstrdup(from->viewname);
2211 Node_Copy(from, newnode, aliases);
2212 Node_Copy(from, newnode, query);
2218 _copyLoadStmt(LoadStmt *from)
2220 LoadStmt *newnode = makeNode(LoadStmt);
2223 newnode->filename = pstrdup(from->filename);
2228 static CreatedbStmt *
2229 _copyCreatedbStmt(CreatedbStmt *from)
2231 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2234 newnode->dbname = pstrdup(from->dbname);
2236 newnode->dbpath = pstrdup(from->dbpath);
2237 if (from->dbtemplate)
2238 newnode->dbtemplate = pstrdup(from->dbtemplate);
2239 newnode->encoding = from->encoding;
2245 _copyDropdbStmt(DropdbStmt *from)
2247 DropdbStmt *newnode = makeNode(DropdbStmt);
2250 newnode->dbname = pstrdup(from->dbname);
2256 _copyVacuumStmt(VacuumStmt *from)
2258 VacuumStmt *newnode = makeNode(VacuumStmt);
2260 newnode->vacuum = from->vacuum;
2261 newnode->full = from->full;
2262 newnode->analyze = from->analyze;
2263 newnode->verbose = from->verbose;
2265 newnode->vacrel = pstrdup(from->vacrel);
2266 Node_Copy(from, newnode, va_cols);
2271 static ExplainStmt *
2272 _copyExplainStmt(ExplainStmt *from)
2274 ExplainStmt *newnode = makeNode(ExplainStmt);
2276 Node_Copy(from, newnode, query);
2277 newnode->verbose = from->verbose;
2282 static CreateSeqStmt *
2283 _copyCreateSeqStmt(CreateSeqStmt *from)
2285 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2288 newnode->seqname = pstrdup(from->seqname);
2289 Node_Copy(from, newnode, options);
2294 static VariableSetStmt *
2295 _copyVariableSetStmt(VariableSetStmt *from)
2297 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2300 newnode->name = pstrdup(from->name);
2302 newnode->value = pstrdup(from->value);
2307 static VariableShowStmt *
2308 _copyVariableShowStmt(VariableShowStmt *from)
2310 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2313 newnode->name = pstrdup(from->name);
2318 static VariableResetStmt *
2319 _copyVariableResetStmt(VariableResetStmt *from)
2321 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2324 newnode->name = pstrdup(from->name);
2329 static CreateTrigStmt *
2330 _copyCreateTrigStmt(CreateTrigStmt *from)
2332 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2335 newnode->trigname = pstrdup(from->trigname);
2337 newnode->relname = pstrdup(from->relname);
2339 newnode->funcname = pstrdup(from->funcname);
2340 Node_Copy(from, newnode, args);
2341 newnode->before = from->before;
2342 newnode->row = from->row;
2343 memcpy(newnode->actions, from->actions, sizeof(from->actions));
2345 newnode->lang = pstrdup(from->lang);
2347 newnode->text = pstrdup(from->text);
2349 Node_Copy(from, newnode, attr);
2351 newnode->when = pstrdup(from->when);
2352 newnode->isconstraint = from->isconstraint;
2353 newnode->deferrable = from->deferrable;
2354 newnode->initdeferred = from->initdeferred;
2355 if (from->constrrelname)
2356 newnode->constrrelname = pstrdup(from->constrrelname);
2361 static DropTrigStmt *
2362 _copyDropTrigStmt(DropTrigStmt *from)
2364 DropTrigStmt *newnode = makeNode(DropTrigStmt);
2367 newnode->trigname = pstrdup(from->trigname);
2369 newnode->relname = pstrdup(from->relname);
2374 static CreatePLangStmt *
2375 _copyCreatePLangStmt(CreatePLangStmt *from)
2377 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2380 newnode->plname = pstrdup(from->plname);
2381 if (from->plhandler)
2382 newnode->plhandler = pstrdup(from->plhandler);
2383 if (from->plcompiler)
2384 newnode->plcompiler = pstrdup(from->plcompiler);
2385 newnode->pltrusted = from->pltrusted;
2390 static DropPLangStmt *
2391 _copyDropPLangStmt(DropPLangStmt *from)
2393 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2396 newnode->plname = pstrdup(from->plname);
2401 static CreateUserStmt *
2402 _copyCreateUserStmt(CreateUserStmt *from)
2404 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2407 newnode->user = pstrdup(from->user);
2408 Node_Copy(from, newnode, options);
2413 static AlterUserStmt *
2414 _copyAlterUserStmt(AlterUserStmt *from)
2416 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2419 newnode->user = pstrdup(from->user);
2420 Node_Copy(from, newnode, options);
2425 static DropUserStmt *
2426 _copyDropUserStmt(DropUserStmt *from)
2428 DropUserStmt *newnode = makeNode(DropUserStmt);
2430 Node_Copy(from, newnode, users);
2436 _copyLockStmt(LockStmt *from)
2438 LockStmt *newnode = makeNode(LockStmt);
2441 newnode->relname = pstrdup(from->relname);
2442 newnode->mode = from->mode;
2447 static ConstraintsSetStmt *
2448 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2450 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2452 Node_Copy(from, newnode, constraints);
2453 newnode->deferred = from->deferred;
2458 static CreateGroupStmt *
2459 _copyCreateGroupStmt(CreateGroupStmt *from)
2461 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2464 newnode->name = pstrdup(from->name);
2465 newnode->sysid = from->sysid;
2466 Node_Copy(from, newnode, initUsers);
2471 static AlterGroupStmt *
2472 _copyAlterGroupStmt(AlterGroupStmt *from)
2474 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2477 newnode->name = pstrdup(from->name);
2478 newnode->action = from->action;
2479 newnode->sysid = from->sysid;
2480 Node_Copy(from, newnode, listUsers);
2485 static DropGroupStmt *
2486 _copyDropGroupStmt(DropGroupStmt *from)
2488 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2491 newnode->name = pstrdup(from->name);
2496 static ReindexStmt *
2497 _copyReindexStmt(ReindexStmt *from)
2499 ReindexStmt *newnode = makeNode(ReindexStmt);
2501 newnode->reindexType = from->reindexType;
2503 newnode->name = pstrdup(from->name);
2504 newnode->force = from->force;
2505 newnode->all = from->all;
2511 /* ****************************************************************
2512 * pg_list.h copy functions
2513 * ****************************************************************
2517 _copyValue(Value *from)
2519 Value *newnode = makeNode(Value);
2521 newnode->type = from->type;
2525 newnode->val.ival = from->val.ival;
2530 newnode->val.str = pstrdup(from->val.str);
2539 * copyObject returns a copy of the node or list. If it is a list, it
2540 * recursively copies its items.
2544 copyObject(void *from)
2551 switch (nodeTag(from))
2558 retval = _copyPlan(from);
2561 retval = _copyResult(from);
2564 retval = _copyAppend(from);
2567 retval = _copyScan(from);
2570 retval = _copySeqScan(from);
2573 retval = _copyIndexScan(from);
2576 retval = _copyTidScan(from);
2578 case T_SubqueryScan:
2579 retval = _copySubqueryScan(from);
2582 retval = _copyJoin(from);
2585 retval = _copyNestLoop(from);
2588 retval = _copyMergeJoin(from);
2591 retval = _copyHashJoin(from);
2594 retval = _copyMaterial(from);
2597 retval = _copySort(from);
2600 retval = _copyGroup(from);
2603 retval = _copyAgg(from);
2606 retval = _copyUnique(from);
2609 retval = _copySetOp(from);
2612 retval = _copyLimit(from);
2615 retval = _copyHash(from);
2618 retval = _copySubPlan(from);
2625 retval = _copyResdom(from);
2628 retval = _copyFjoin(from);
2631 retval = _copyExpr(from);
2634 retval = _copyVar(from);
2637 retval = _copyOper(from);
2640 retval = _copyConst(from);
2643 retval = _copyParam(from);
2646 retval = _copyAggref(from);
2649 retval = _copySubLink(from);
2652 retval = _copyFunc(from);
2655 retval = _copyArrayRef(from);
2658 retval = _copyIter(from);
2661 retval = _copyFieldSelect(from);
2664 retval = _copyRelabelType(from);
2667 retval = _copyRangeTblRef(from);
2670 retval = _copyFromExpr(from);
2673 retval = _copyJoinExpr(from);
2680 retval = _copyRelOptInfo(from);
2683 retval = _copyPath(from);
2686 retval = _copyIndexPath(from);
2689 retval = _copyTidPath(from);
2692 retval = _copyAppendPath(from);
2695 retval = _copyNestPath(from);
2698 retval = _copyMergePath(from);
2701 retval = _copyHashPath(from);
2704 retval = _copyPathKeyItem(from);
2706 case T_RestrictInfo:
2707 retval = _copyRestrictInfo(from);
2710 retval = _copyJoinInfo(from);
2713 retval = _copyStream(from);
2715 case T_IndexOptInfo:
2716 retval = _copyIndexOptInfo(from);
2726 retval = _copyValue(from);
2734 /* rather ugly coding for speed... */
2735 /* Note the input list cannot be NIL if we got here. */
2736 nl = makeList1(copyObject(lfirst(list)));
2739 foreach(l, lnext(list))
2741 lnext(nl) = makeList1(copyObject(lfirst(l)));
2751 retval = _copyQuery(from);
2754 retval = _copyInsertStmt(from);
2757 retval = _copyDeleteStmt(from);
2760 retval = _copyUpdateStmt(from);
2763 retval = _copySelectStmt(from);
2765 case T_SetOperationStmt:
2766 retval = _copySetOperationStmt(from);
2768 case T_AlterTableStmt:
2769 retval = _copyAlterTableStmt(from);
2772 retval = _copyGrantStmt(from);
2774 case T_ClosePortalStmt:
2775 retval = _copyClosePortalStmt(from);
2778 retval = _copyClusterStmt(from);
2781 retval = _copyCopyStmt(from);
2784 retval = _copyCreateStmt(from);
2787 retval = _copyVersionStmt(from);
2790 retval = _copyDefineStmt(from);
2793 retval = _copyDropStmt(from);
2795 case T_TruncateStmt:
2796 retval = _copyTruncateStmt(from);
2799 retval = _copyCommentStmt(from);
2802 retval = _copyExtendStmt(from);
2805 retval = _copyFetchStmt(from);
2808 retval = _copyIndexStmt(from);
2810 case T_ProcedureStmt:
2811 retval = _copyProcedureStmt(from);
2813 case T_RemoveAggrStmt:
2814 retval = _copyRemoveAggrStmt(from);
2816 case T_RemoveFuncStmt:
2817 retval = _copyRemoveFuncStmt(from);
2819 case T_RemoveOperStmt:
2820 retval = _copyRemoveOperStmt(from);
2823 retval = _copyRenameStmt(from);
2826 retval = _copyRuleStmt(from);
2829 retval = _copyNotifyStmt(from);
2832 retval = _copyListenStmt(from);
2834 case T_UnlistenStmt:
2835 retval = _copyUnlistenStmt(from);
2837 case T_TransactionStmt:
2838 retval = _copyTransactionStmt(from);
2841 retval = _copyViewStmt(from);
2844 retval = _copyLoadStmt(from);
2846 case T_CreatedbStmt:
2847 retval = _copyCreatedbStmt(from);
2850 retval = _copyDropdbStmt(from);
2853 retval = _copyVacuumStmt(from);
2856 retval = _copyExplainStmt(from);
2858 case T_CreateSeqStmt:
2859 retval = _copyCreateSeqStmt(from);
2861 case T_VariableSetStmt:
2862 retval = _copyVariableSetStmt(from);
2864 case T_VariableShowStmt:
2865 retval = _copyVariableShowStmt(from);
2867 case T_VariableResetStmt:
2868 retval = _copyVariableResetStmt(from);
2870 case T_CreateTrigStmt:
2871 retval = _copyCreateTrigStmt(from);
2873 case T_DropTrigStmt:
2874 retval = _copyDropTrigStmt(from);
2876 case T_CreatePLangStmt:
2877 retval = _copyCreatePLangStmt(from);
2879 case T_DropPLangStmt:
2880 retval = _copyDropPLangStmt(from);
2882 case T_CreateUserStmt:
2883 retval = _copyCreateUserStmt(from);
2885 case T_AlterUserStmt:
2886 retval = _copyAlterUserStmt(from);
2888 case T_DropUserStmt:
2889 retval = _copyDropUserStmt(from);
2892 retval = _copyLockStmt(from);
2894 case T_ConstraintsSetStmt:
2895 retval = _copyConstraintsSetStmt(from);
2897 case T_CreateGroupStmt:
2898 retval = _copyCreateGroupStmt(from);
2900 case T_AlterGroupStmt:
2901 retval = _copyAlterGroupStmt(from);
2903 case T_DropGroupStmt:
2904 retval = _copyDropGroupStmt(from);
2907 retval = _copyReindexStmt(from);
2909 case T_CheckPointStmt:
2910 retval = (void *) makeNode(CheckPointStmt);
2914 retval = _copyAExpr(from);
2917 retval = _copyAttr(from);
2920 retval = _copyAConst(from);
2923 retval = _copyParamNo(from);
2926 retval = _copyIdent(from);
2929 retval = _copyFuncCall(from);
2932 retval = _copyAIndices(from);
2935 retval = _copyResTarget(from);
2938 retval = _copyTypeCast(from);
2941 retval = _copySortGroupBy(from);
2944 retval = _copyRangeVar(from);
2946 case T_RangeSubselect:
2947 retval = _copyRangeSubselect(from);
2950 retval = _copyTypeName(from);
2953 retval = _copyIndexElem(from);
2956 retval = _copyColumnDef(from);
2959 retval = _copyConstraint(from);
2962 retval = _copyDefElem(from);
2965 retval = _copyTargetEntry(from);
2967 case T_RangeTblEntry:
2968 retval = _copyRangeTblEntry(from);
2971 retval = _copySortClause(from);
2974 retval = _copyGroupClause(from);
2977 retval = _copyCaseExpr(from);
2980 retval = _copyCaseWhen(from);
2983 retval = _copyNullTest(from);
2986 retval = _copyBooleanTest(from);
2988 case T_FkConstraint:
2989 retval = _copyFkConstraint(from);
2992 retval = _copyPrivGrantee(from);
2996 elog(ERROR, "copyObject: don't know how to copy node type %d",
2998 retval = from; /* keep compiler quiet */