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.184 2002/05/12 23:43:02 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 static FunctionScan *
318 _copyFunctionScan(FunctionScan *from)
320 FunctionScan *newnode = makeNode(FunctionScan);
323 * copy node superclass fields
325 CopyPlanFields((Plan *) from, (Plan *) newnode);
326 CopyScanFields((Scan *) from, (Scan *) newnode);
334 * This function copies the fields of the Join node. It is used by
335 * all the copy functions for classes which inherit from Join.
339 CopyJoinFields(Join *from, Join *newnode)
341 newnode->jointype = from->jointype;
342 Node_Copy(from, newnode, joinqual);
343 /* subPlan list must point to subplans in the new subtree, not the old */
344 if (from->plan.subPlan != NIL)
345 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
346 pull_subplans((Node *) newnode->joinqual));
355 _copyJoin(Join *from)
357 Join *newnode = makeNode(Join);
360 * copy node superclass fields
362 CopyPlanFields((Plan *) from, (Plan *) newnode);
363 CopyJoinFields(from, newnode);
374 _copyNestLoop(NestLoop *from)
376 NestLoop *newnode = makeNode(NestLoop);
379 * copy node superclass fields
381 CopyPlanFields((Plan *) from, (Plan *) newnode);
382 CopyJoinFields((Join *) from, (Join *) newnode);
393 _copyMergeJoin(MergeJoin *from)
395 MergeJoin *newnode = makeNode(MergeJoin);
398 * copy node superclass fields
400 CopyPlanFields((Plan *) from, (Plan *) newnode);
401 CopyJoinFields((Join *) from, (Join *) newnode);
404 * copy remainder of node
406 Node_Copy(from, newnode, mergeclauses);
409 * We must add subplans in mergeclauses to the new plan's subPlan list
411 if (from->join.plan.subPlan != NIL)
412 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
413 pull_subplans((Node *) newnode->mergeclauses));
423 _copyHashJoin(HashJoin *from)
425 HashJoin *newnode = makeNode(HashJoin);
428 * copy node superclass fields
430 CopyPlanFields((Plan *) from, (Plan *) newnode);
431 CopyJoinFields((Join *) from, (Join *) newnode);
434 * copy remainder of node
436 Node_Copy(from, newnode, hashclauses);
437 newnode->hashjoinop = from->hashjoinop;
440 * We must add subplans in hashclauses to the new plan's subPlan list
442 if (from->join.plan.subPlan != NIL)
443 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
444 pull_subplans((Node *) newnode->hashclauses));
455 _copyMaterial(Material *from)
457 Material *newnode = makeNode(Material);
460 * copy node superclass fields
462 CopyPlanFields((Plan *) from, (Plan *) newnode);
473 _copySort(Sort *from)
475 Sort *newnode = makeNode(Sort);
478 * copy node superclass fields
480 CopyPlanFields((Plan *) from, (Plan *) newnode);
482 newnode->keycount = from->keycount;
493 _copyGroup(Group *from)
495 Group *newnode = makeNode(Group);
497 CopyPlanFields((Plan *) from, (Plan *) newnode);
499 newnode->tuplePerGroup = from->tuplePerGroup;
500 newnode->numCols = from->numCols;
501 newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
502 memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
514 Agg *newnode = makeNode(Agg);
516 CopyPlanFields((Plan *) from, (Plan *) newnode);
526 _copyGroupClause(GroupClause *from)
528 GroupClause *newnode = makeNode(GroupClause);
530 newnode->tleSortGroupRef = from->tleSortGroupRef;
531 newnode->sortop = from->sortop;
541 _copyUnique(Unique *from)
543 Unique *newnode = makeNode(Unique);
546 * copy node superclass fields
548 CopyPlanFields((Plan *) from, (Plan *) newnode);
551 * copy remainder of node
553 newnode->numCols = from->numCols;
554 newnode->uniqColIdx = palloc(from->numCols * sizeof(AttrNumber));
555 memcpy(newnode->uniqColIdx, from->uniqColIdx, from->numCols * sizeof(AttrNumber));
565 _copySetOp(SetOp *from)
567 SetOp *newnode = makeNode(SetOp);
570 * copy node superclass fields
572 CopyPlanFields((Plan *) from, (Plan *) newnode);
575 * copy remainder of node
577 newnode->cmd = from->cmd;
578 newnode->numCols = from->numCols;
579 newnode->dupColIdx = palloc(from->numCols * sizeof(AttrNumber));
580 memcpy(newnode->dupColIdx, from->dupColIdx, from->numCols * sizeof(AttrNumber));
581 newnode->flagColIdx = from->flagColIdx;
591 _copyLimit(Limit *from)
593 Limit *newnode = makeNode(Limit);
596 * copy node superclass fields
598 CopyPlanFields((Plan *) from, (Plan *) newnode);
601 * copy remainder of node
603 Node_Copy(from, newnode, limitOffset);
604 Node_Copy(from, newnode, limitCount);
614 _copyHash(Hash *from)
616 Hash *newnode = makeNode(Hash);
619 * copy node superclass fields
621 CopyPlanFields((Plan *) from, (Plan *) newnode);
624 * copy remainder of node
626 Node_Copy(from, newnode, hashkey);
632 _copySubPlan(SubPlan *from)
634 SubPlan *newnode = makeNode(SubPlan);
636 Node_Copy(from, newnode, plan);
637 newnode->plan_id = from->plan_id;
638 Node_Copy(from, newnode, rtable);
639 newnode->setParam = listCopy(from->setParam);
640 newnode->parParam = listCopy(from->parParam);
641 Node_Copy(from, newnode, sublink);
643 /* do not copy execution state */
644 newnode->needShutdown = false;
645 newnode->curTuple = NULL;
650 /* ****************************************************************
651 * primnodes.h copy functions
652 * ****************************************************************
660 _copyResdom(Resdom *from)
662 Resdom *newnode = makeNode(Resdom);
664 newnode->resno = from->resno;
665 newnode->restype = from->restype;
666 newnode->restypmod = from->restypmod;
667 if (from->resname != NULL)
668 newnode->resname = pstrdup(from->resname);
669 newnode->ressortgroupref = from->ressortgroupref;
670 newnode->reskey = from->reskey;
671 newnode->reskeyop = from->reskeyop;
672 newnode->resjunk = from->resjunk;
678 _copyFjoin(Fjoin *from)
680 Fjoin *newnode = makeNode(Fjoin);
683 * copy node superclass fields
686 newnode->fj_initialized = from->fj_initialized;
687 newnode->fj_nNodes = from->fj_nNodes;
689 Node_Copy(from, newnode, fj_innerNode);
691 newnode->fj_results = (DatumPtr)
692 palloc((from->fj_nNodes) * sizeof(Datum));
693 memmove(from->fj_results,
695 (from->fj_nNodes) * sizeof(Datum));
697 newnode->fj_alwaysDone = (BoolPtr)
698 palloc((from->fj_nNodes) * sizeof(bool));
699 memmove(from->fj_alwaysDone,
700 newnode->fj_alwaysDone,
701 (from->fj_nNodes) * sizeof(bool));
712 _copyExpr(Expr *from)
714 Expr *newnode = makeNode(Expr);
717 * copy node superclass fields
719 newnode->typeOid = from->typeOid;
720 newnode->opType = from->opType;
722 Node_Copy(from, newnode, oper);
723 Node_Copy(from, newnode, args);
735 Var *newnode = makeNode(Var);
738 * copy remainder of node
740 newnode->varno = from->varno;
741 newnode->varattno = from->varattno;
742 newnode->vartype = from->vartype;
743 newnode->vartypmod = from->vartypmod;
744 newnode->varlevelsup = from->varlevelsup;
746 newnode->varnoold = from->varnoold;
747 newnode->varoattno = from->varoattno;
757 _copyOper(Oper *from)
759 Oper *newnode = makeNode(Oper);
762 * copy remainder of node
764 newnode->opno = from->opno;
765 newnode->opid = from->opid;
766 newnode->opresulttype = from->opresulttype;
767 newnode->opretset = from->opretset;
768 /* Do not copy the run-time state, if any */
769 newnode->op_fcache = NULL;
779 _copyConst(Const *from)
781 Const *newnode = makeNode(Const);
784 * copy remainder of node
786 newnode->consttype = from->consttype;
787 newnode->constlen = from->constlen;
789 if (from->constbyval || from->constisnull)
792 * passed by value so just copy the datum. Also, don't try to copy
793 * struct when value is null!
796 newnode->constvalue = from->constvalue;
801 * not passed by value. datum contains a pointer.
803 int length = from->constlen;
805 if (length == -1) /* variable-length type? */
806 length = VARSIZE(from->constvalue);
807 newnode->constvalue = PointerGetDatum(palloc(length));
808 memcpy(DatumGetPointer(newnode->constvalue),
809 DatumGetPointer(from->constvalue),
813 newnode->constisnull = from->constisnull;
814 newnode->constbyval = from->constbyval;
815 newnode->constisset = from->constisset;
816 newnode->constiscast = from->constiscast;
826 _copyParam(Param *from)
828 Param *newnode = makeNode(Param);
831 * copy remainder of node
833 newnode->paramkind = from->paramkind;
834 newnode->paramid = from->paramid;
836 if (from->paramname != NULL)
837 newnode->paramname = pstrdup(from->paramname);
838 newnode->paramtype = from->paramtype;
848 _copyFunc(Func *from)
850 Func *newnode = makeNode(Func);
853 * copy remainder of node
855 newnode->funcid = from->funcid;
856 newnode->funcresulttype = from->funcresulttype;
857 newnode->funcretset = from->funcretset;
858 /* Do not copy the run-time state, if any */
859 newnode->func_fcache = NULL;
869 _copyAggref(Aggref *from)
871 Aggref *newnode = makeNode(Aggref);
873 newnode->aggfnoid = from->aggfnoid;
874 newnode->aggtype = from->aggtype;
875 Node_Copy(from, newnode, target);
876 newnode->aggstar = from->aggstar;
877 newnode->aggdistinct = from->aggdistinct;
878 newnode->aggno = from->aggno; /* probably not needed */
888 _copySubLink(SubLink *from)
890 SubLink *newnode = makeNode(SubLink);
893 * copy remainder of node
895 newnode->subLinkType = from->subLinkType;
896 newnode->useor = from->useor;
897 Node_Copy(from, newnode, lefthand);
898 Node_Copy(from, newnode, oper);
899 Node_Copy(from, newnode, subselect);
909 _copyFieldSelect(FieldSelect *from)
911 FieldSelect *newnode = makeNode(FieldSelect);
914 * copy remainder of node
916 Node_Copy(from, newnode, arg);
917 newnode->fieldnum = from->fieldnum;
918 newnode->resulttype = from->resulttype;
919 newnode->resulttypmod = from->resulttypmod;
929 _copyRelabelType(RelabelType *from)
931 RelabelType *newnode = makeNode(RelabelType);
934 * copy remainder of node
936 Node_Copy(from, newnode, arg);
937 newnode->resulttype = from->resulttype;
938 newnode->resulttypmod = from->resulttypmod;
944 _copyRangeTblRef(RangeTblRef *from)
946 RangeTblRef *newnode = makeNode(RangeTblRef);
948 newnode->rtindex = from->rtindex;
954 _copyFromExpr(FromExpr *from)
956 FromExpr *newnode = makeNode(FromExpr);
958 Node_Copy(from, newnode, fromlist);
959 Node_Copy(from, newnode, quals);
965 _copyJoinExpr(JoinExpr *from)
967 JoinExpr *newnode = makeNode(JoinExpr);
969 newnode->jointype = from->jointype;
970 newnode->isNatural = from->isNatural;
971 Node_Copy(from, newnode, larg);
972 Node_Copy(from, newnode, rarg);
973 Node_Copy(from, newnode, using);
974 Node_Copy(from, newnode, quals);
975 Node_Copy(from, newnode, alias);
976 newnode->rtindex = from->rtindex;
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 _copyRelOptInfo(RelOptInfo *from)
1089 RelOptInfo *newnode = makeNode(RelOptInfo);
1091 newnode->reloptkind = from->reloptkind;
1093 newnode->relids = listCopy(from->relids);
1095 newnode->rows = from->rows;
1096 newnode->width = from->width;
1098 Node_Copy(from, newnode, targetlist);
1099 Node_Copy(from, newnode, pathlist);
1100 /* XXX cheapest-path fields should point to members of pathlist? */
1101 Node_Copy(from, newnode, cheapest_startup_path);
1102 Node_Copy(from, newnode, cheapest_total_path);
1103 newnode->pruneable = from->pruneable;
1105 newnode->rtekind = from->rtekind;
1106 Node_Copy(from, newnode, indexlist);
1107 newnode->pages = from->pages;
1108 newnode->tuples = from->tuples;
1109 Node_Copy(from, newnode, subplan);
1111 newnode->joinrti = from->joinrti;
1112 newnode->joinrteids = listCopy(from->joinrteids);
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;
1176 * This function copies the fields of the Path node. It is used by
1177 * all the copy functions for classes which inherit from Path.
1181 CopyPathFields(Path *from, Path *newnode)
1184 * Modify the next line, since it causes the copying to cycle (i.e.
1185 * the parent points right back here! -- JMH, 7/7/92. Old version:
1186 * Node_Copy(from, newnode, parent);
1188 newnode->parent = from->parent;
1190 newnode->startup_cost = from->startup_cost;
1191 newnode->total_cost = from->total_cost;
1193 newnode->pathtype = from->pathtype;
1195 Node_Copy(from, newnode, pathkeys);
1203 _copyPath(Path *from)
1205 Path *newnode = makeNode(Path);
1207 CopyPathFields(from, newnode);
1217 _copyIndexPath(IndexPath *from)
1219 IndexPath *newnode = makeNode(IndexPath);
1222 * copy the node superclass fields
1224 CopyPathFields((Path *) from, (Path *) newnode);
1227 * copy remainder of node
1229 Node_Copy(from, newnode, indexinfo);
1230 Node_Copy(from, newnode, indexqual);
1231 newnode->indexscandir = from->indexscandir;
1232 newnode->joinrelids = listCopy(from->joinrelids);
1233 newnode->alljoinquals = from->alljoinquals;
1234 newnode->rows = from->rows;
1244 _copyTidPath(TidPath *from)
1246 TidPath *newnode = makeNode(TidPath);
1249 * copy the node superclass fields
1251 CopyPathFields((Path *) from, (Path *) newnode);
1254 * copy remainder of node
1256 Node_Copy(from, newnode, tideval);
1257 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1267 _copyAppendPath(AppendPath *from)
1269 AppendPath *newnode = makeNode(AppendPath);
1272 * copy the node superclass fields
1274 CopyPathFields((Path *) from, (Path *) newnode);
1277 * copy remainder of node
1279 Node_Copy(from, newnode, subpaths);
1285 * CopyJoinPathFields
1287 * This function copies the fields of the JoinPath node. It is used by
1288 * all the copy functions for classes which inherit from JoinPath.
1292 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1294 newnode->jointype = from->jointype;
1295 Node_Copy(from, newnode, outerjoinpath);
1296 Node_Copy(from, newnode, innerjoinpath);
1297 Node_Copy(from, newnode, joinrestrictinfo);
1305 _copyNestPath(NestPath *from)
1307 NestPath *newnode = makeNode(NestPath);
1310 * copy the node superclass fields
1312 CopyPathFields((Path *) from, (Path *) newnode);
1313 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1323 _copyMergePath(MergePath *from)
1325 MergePath *newnode = makeNode(MergePath);
1328 * copy the node superclass fields
1330 CopyPathFields((Path *) from, (Path *) newnode);
1331 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1334 * copy the remainder of the node
1336 Node_Copy(from, newnode, path_mergeclauses);
1337 Node_Copy(from, newnode, outersortkeys);
1338 Node_Copy(from, newnode, innersortkeys);
1348 _copyHashPath(HashPath *from)
1350 HashPath *newnode = makeNode(HashPath);
1353 * copy the node superclass fields
1355 CopyPathFields((Path *) from, (Path *) newnode);
1356 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1359 * copy remainder of node
1361 Node_Copy(from, newnode, path_hashclauses);
1370 static PathKeyItem *
1371 _copyPathKeyItem(PathKeyItem *from)
1373 PathKeyItem *newnode = makeNode(PathKeyItem);
1376 * 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
1396 Node_Copy(from, newnode, clause);
1397 newnode->ispusheddown = from->ispusheddown;
1398 Node_Copy(from, newnode, subclauseindices);
1399 newnode->eval_cost = from->eval_cost;
1400 newnode->this_selec = from->this_selec;
1401 newnode->mergejoinoperator = from->mergejoinoperator;
1402 newnode->left_sortop = from->left_sortop;
1403 newnode->right_sortop = from->right_sortop;
1406 * Do not copy pathkeys, since they'd not be canonical in a copied
1409 newnode->left_pathkey = NIL;
1410 newnode->right_pathkey = NIL;
1411 newnode->left_mergescansel = from->left_mergescansel;
1412 newnode->right_mergescansel = from->right_mergescansel;
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 _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);
1481 newnode->rtekind = from->rtekind;
1482 newnode->relid = from->relid;
1483 Node_Copy(from, newnode, subquery);
1484 Node_Copy(from, newnode, funcexpr);
1485 newnode->jointype = from->jointype;
1486 Node_Copy(from, newnode, joinaliasvars);
1487 Node_Copy(from, newnode, alias);
1488 Node_Copy(from, newnode, eref);
1489 newnode->inh = from->inh;
1490 newnode->inFromCl = from->inFromCl;
1491 newnode->checkForRead = from->checkForRead;
1492 newnode->checkForWrite = from->checkForWrite;
1493 newnode->checkAsUser = from->checkAsUser;
1498 static FkConstraint *
1499 _copyFkConstraint(FkConstraint *from)
1501 FkConstraint *newnode = makeNode(FkConstraint);
1503 if (from->constr_name)
1504 newnode->constr_name = pstrdup(from->constr_name);
1505 Node_Copy(from, newnode, pktable);
1506 Node_Copy(from, newnode, fk_attrs);
1507 Node_Copy(from, newnode, pk_attrs);
1508 if (from->match_type)
1509 newnode->match_type = pstrdup(from->match_type);
1510 newnode->actions = from->actions;
1511 newnode->deferrable = from->deferrable;
1512 newnode->initdeferred = from->initdeferred;
1518 _copySortClause(SortClause *from)
1520 SortClause *newnode = makeNode(SortClause);
1522 newnode->tleSortGroupRef = from->tleSortGroupRef;
1523 newnode->sortop = from->sortop;
1529 _copyAExpr(A_Expr *from)
1531 A_Expr *newnode = makeNode(A_Expr);
1533 newnode->oper = from->oper;
1534 Node_Copy(from, newnode, name);
1535 Node_Copy(from, newnode, lexpr);
1536 Node_Copy(from, newnode, rexpr);
1542 _copyColumnRef(ColumnRef *from)
1544 ColumnRef *newnode = makeNode(ColumnRef);
1546 Node_Copy(from, newnode, fields);
1547 Node_Copy(from, newnode, indirection);
1553 _copyParamRef(ParamRef *from)
1555 ParamRef *newnode = makeNode(ParamRef);
1557 newnode->number = from->number;
1558 Node_Copy(from, newnode, fields);
1559 Node_Copy(from, newnode, indirection);
1565 _copyAConst(A_Const *from)
1567 A_Const *newnode = makeNode(A_Const);
1569 newnode->val = *((Value *) (copyObject(&(from->val))));
1570 Node_Copy(from, newnode, typename);
1576 _copyIdent(Ident *from)
1578 Ident *newnode = makeNode(Ident);
1580 newnode->name = pstrdup(from->name);
1586 _copyFuncCall(FuncCall *from)
1588 FuncCall *newnode = makeNode(FuncCall);
1590 Node_Copy(from, newnode, funcname);
1591 Node_Copy(from, newnode, args);
1592 newnode->agg_star = from->agg_star;
1593 newnode->agg_distinct = from->agg_distinct;
1599 _copyAIndices(A_Indices *from)
1601 A_Indices *newnode = makeNode(A_Indices);
1603 Node_Copy(from, newnode, lidx);
1604 Node_Copy(from, newnode, uidx);
1609 static ExprFieldSelect *
1610 _copyExprFieldSelect(ExprFieldSelect *from)
1612 ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
1614 Node_Copy(from, newnode, arg);
1615 Node_Copy(from, newnode, fields);
1616 Node_Copy(from, newnode, indirection);
1622 _copyResTarget(ResTarget *from)
1624 ResTarget *newnode = makeNode(ResTarget);
1627 newnode->name = pstrdup(from->name);
1628 Node_Copy(from, newnode, indirection);
1629 Node_Copy(from, newnode, val);
1635 _copyTypeName(TypeName *from)
1637 TypeName *newnode = makeNode(TypeName);
1639 Node_Copy(from, newnode, names);
1640 newnode->typeid = from->typeid;
1641 newnode->timezone = from->timezone;
1642 newnode->setof = from->setof;
1643 newnode->pct_type = from->pct_type;
1644 newnode->typmod = from->typmod;
1645 Node_Copy(from, newnode, arrayBounds);
1650 static SortGroupBy *
1651 _copySortGroupBy(SortGroupBy *from)
1653 SortGroupBy *newnode = makeNode(SortGroupBy);
1655 Node_Copy(from, newnode, useOp);
1656 Node_Copy(from, newnode, node);
1662 _copyAlias(Alias *from)
1664 Alias *newnode = makeNode(Alias);
1666 if (from->aliasname)
1667 newnode->aliasname = pstrdup(from->aliasname);
1668 Node_Copy(from, newnode, colnames);
1674 _copyRangeVar(RangeVar *from)
1676 RangeVar *newnode = makeNode(RangeVar);
1678 if (from->catalogname)
1679 newnode->catalogname = pstrdup(from->catalogname);
1680 if (from->schemaname)
1681 newnode->schemaname = pstrdup(from->schemaname);
1683 newnode->relname = pstrdup(from->relname);
1684 newnode->inhOpt = from->inhOpt;
1685 newnode->istemp = from->istemp;
1686 Node_Copy(from, newnode, alias);
1691 static RangeSubselect *
1692 _copyRangeSubselect(RangeSubselect *from)
1694 RangeSubselect *newnode = makeNode(RangeSubselect);
1696 Node_Copy(from, newnode, subquery);
1697 Node_Copy(from, newnode, alias);
1702 static RangeFunction *
1703 _copyRangeFunction(RangeFunction *from)
1705 RangeFunction *newnode = makeNode(RangeFunction);
1707 Node_Copy(from, newnode, funccallnode);
1708 Node_Copy(from, newnode, alias);
1714 _copyTypeCast(TypeCast *from)
1716 TypeCast *newnode = makeNode(TypeCast);
1718 Node_Copy(from, newnode, arg);
1719 Node_Copy(from, newnode, typename);
1725 _copyIndexElem(IndexElem *from)
1727 IndexElem *newnode = makeNode(IndexElem);
1730 newnode->name = pstrdup(from->name);
1731 Node_Copy(from, newnode, funcname);
1732 Node_Copy(from, newnode, args);
1733 Node_Copy(from, newnode, opclass);
1739 _copyColumnDef(ColumnDef *from)
1741 ColumnDef *newnode = makeNode(ColumnDef);
1744 newnode->colname = pstrdup(from->colname);
1745 Node_Copy(from, newnode, typename);
1746 newnode->is_not_null = from->is_not_null;
1747 Node_Copy(from, newnode, raw_default);
1748 if (from->cooked_default)
1749 newnode->cooked_default = pstrdup(from->cooked_default);
1750 Node_Copy(from, newnode, constraints);
1756 _copyConstraint(Constraint *from)
1758 Constraint *newnode = makeNode(Constraint);
1760 newnode->contype = from->contype;
1762 newnode->name = pstrdup(from->name);
1763 Node_Copy(from, newnode, raw_expr);
1764 if (from->cooked_expr)
1765 newnode->cooked_expr = pstrdup(from->cooked_expr);
1766 Node_Copy(from, newnode, keys);
1772 _copyDefElem(DefElem *from)
1774 DefElem *newnode = makeNode(DefElem);
1777 newnode->defname = pstrdup(from->defname);
1778 Node_Copy(from, newnode, arg);
1784 _copyQuery(Query *from)
1786 Query *newnode = makeNode(Query);
1788 newnode->commandType = from->commandType;
1789 Node_Copy(from, newnode, utilityStmt);
1790 newnode->resultRelation = from->resultRelation;
1791 Node_Copy(from, newnode, into);
1792 newnode->isPortal = from->isPortal;
1793 newnode->isBinary = from->isBinary;
1794 newnode->hasAggs = from->hasAggs;
1795 newnode->hasSubLinks = from->hasSubLinks;
1796 newnode->originalQuery = from->originalQuery;
1798 Node_Copy(from, newnode, rtable);
1799 Node_Copy(from, newnode, jointree);
1801 newnode->rowMarks = listCopy(from->rowMarks);
1803 Node_Copy(from, newnode, targetList);
1805 Node_Copy(from, newnode, groupClause);
1806 Node_Copy(from, newnode, havingQual);
1807 Node_Copy(from, newnode, distinctClause);
1808 Node_Copy(from, newnode, sortClause);
1810 Node_Copy(from, newnode, limitOffset);
1811 Node_Copy(from, newnode, limitCount);
1813 Node_Copy(from, newnode, setOperations);
1815 newnode->resultRelations = listCopy(from->resultRelations);
1818 * We do not copy the planner internal fields: base_rel_list,
1819 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. Not
1820 * entirely clear if this is right?
1827 _copyInsertStmt(InsertStmt *from)
1829 InsertStmt *newnode = makeNode(InsertStmt);
1831 Node_Copy(from, newnode, relation);
1832 Node_Copy(from, newnode, cols);
1833 Node_Copy(from, newnode, targetList);
1834 Node_Copy(from, newnode, selectStmt);
1840 _copyDeleteStmt(DeleteStmt *from)
1842 DeleteStmt *newnode = makeNode(DeleteStmt);
1844 Node_Copy(from, newnode, relation);
1845 Node_Copy(from, newnode, whereClause);
1851 _copyUpdateStmt(UpdateStmt *from)
1853 UpdateStmt *newnode = makeNode(UpdateStmt);
1855 Node_Copy(from, newnode, relation);
1856 Node_Copy(from, newnode, targetList);
1857 Node_Copy(from, newnode, whereClause);
1858 Node_Copy(from, newnode, fromClause);
1864 _copySelectStmt(SelectStmt *from)
1866 SelectStmt *newnode = makeNode(SelectStmt);
1868 Node_Copy(from, newnode, distinctClause);
1869 Node_Copy(from, newnode, into);
1870 Node_Copy(from, newnode, intoColNames);
1871 Node_Copy(from, newnode, targetList);
1872 Node_Copy(from, newnode, fromClause);
1873 Node_Copy(from, newnode, whereClause);
1874 Node_Copy(from, newnode, groupClause);
1875 Node_Copy(from, newnode, havingClause);
1876 Node_Copy(from, newnode, sortClause);
1877 if (from->portalname)
1878 newnode->portalname = pstrdup(from->portalname);
1879 newnode->binary = from->binary;
1880 Node_Copy(from, newnode, limitOffset);
1881 Node_Copy(from, newnode, limitCount);
1882 Node_Copy(from, newnode, forUpdate);
1883 newnode->op = from->op;
1884 newnode->all = from->all;
1885 Node_Copy(from, newnode, larg);
1886 Node_Copy(from, newnode, rarg);
1891 static SetOperationStmt *
1892 _copySetOperationStmt(SetOperationStmt *from)
1894 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1896 newnode->op = from->op;
1897 newnode->all = from->all;
1898 Node_Copy(from, newnode, larg);
1899 Node_Copy(from, newnode, rarg);
1900 newnode->colTypes = listCopy(from->colTypes);
1905 static AlterTableStmt *
1906 _copyAlterTableStmt(AlterTableStmt *from)
1908 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1910 newnode->subtype = from->subtype;
1911 Node_Copy(from, newnode, relation);
1913 newnode->name = pstrdup(from->name);
1914 Node_Copy(from, newnode, def);
1915 newnode->behavior = from->behavior;
1921 _copyGrantStmt(GrantStmt *from)
1923 GrantStmt *newnode = makeNode(GrantStmt);
1925 newnode->is_grant = from->is_grant;
1926 newnode->objtype = from->objtype;
1927 Node_Copy(from, newnode, objects);
1928 newnode->privileges = listCopy(from->privileges);
1929 Node_Copy(from, newnode, grantees);
1934 static PrivGrantee *
1935 _copyPrivGrantee(PrivGrantee *from)
1937 PrivGrantee *newnode = makeNode(PrivGrantee);
1940 newnode->username = pstrdup(from->username);
1941 if (from->groupname)
1942 newnode->groupname = pstrdup(from->groupname);
1947 static FuncWithArgs *
1948 _copyFuncWithArgs(FuncWithArgs *from)
1950 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1952 Node_Copy(from, newnode, funcname);
1953 Node_Copy(from, newnode, funcargs);
1958 static InsertDefault *
1959 _copyInsertDefault(InsertDefault *from)
1961 InsertDefault *newnode = makeNode(InsertDefault);
1967 static ClosePortalStmt *
1968 _copyClosePortalStmt(ClosePortalStmt *from)
1970 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1972 if (from->portalname)
1973 newnode->portalname = pstrdup(from->portalname);
1978 static ClusterStmt *
1979 _copyClusterStmt(ClusterStmt *from)
1981 ClusterStmt *newnode = makeNode(ClusterStmt);
1983 Node_Copy(from, newnode, relation);
1984 if (from->indexname)
1985 newnode->indexname = pstrdup(from->indexname);
1991 _copyCopyStmt(CopyStmt *from)
1993 CopyStmt *newnode = makeNode(CopyStmt);
1995 newnode->binary = from->binary;
1996 Node_Copy(from, newnode, relation);
1997 newnode->oids = from->oids;
1998 newnode->direction = from->direction;
2000 newnode->filename = pstrdup(from->filename);
2001 if (from->delimiter)
2002 newnode->delimiter = pstrdup(from->delimiter);
2003 if (from->null_print)
2004 newnode->null_print = pstrdup(from->null_print);
2010 _copyCreateStmt(CreateStmt *from)
2012 CreateStmt *newnode = makeNode(CreateStmt);
2014 Node_Copy(from, newnode, relation);
2015 Node_Copy(from, newnode, tableElts);
2016 Node_Copy(from, newnode, inhRelations);
2017 Node_Copy(from, newnode, constraints);
2018 newnode->hasoids = from->hasoids;
2024 _copyDefineStmt(DefineStmt *from)
2026 DefineStmt *newnode = makeNode(DefineStmt);
2028 newnode->defType = from->defType;
2029 Node_Copy(from, newnode, defnames);
2030 Node_Copy(from, newnode, definition);
2036 _copyDropStmt(DropStmt *from)
2038 DropStmt *newnode = makeNode(DropStmt);
2040 Node_Copy(from, newnode, objects);
2041 newnode->removeType = from->removeType;
2042 newnode->behavior = from->behavior;
2047 static TruncateStmt *
2048 _copyTruncateStmt(TruncateStmt *from)
2050 TruncateStmt *newnode = makeNode(TruncateStmt);
2052 Node_Copy(from, newnode, relation);
2057 static CommentStmt *
2058 _copyCommentStmt(CommentStmt *from)
2060 CommentStmt *newnode = makeNode(CommentStmt);
2062 newnode->objtype = from->objtype;
2063 Node_Copy(from, newnode, objname);
2064 Node_Copy(from, newnode, objargs);
2066 newnode->comment = pstrdup(from->comment);
2072 _copyFetchStmt(FetchStmt *from)
2074 FetchStmt *newnode = makeNode(FetchStmt);
2076 newnode->direction = from->direction;
2077 newnode->howMany = from->howMany;
2078 newnode->portalname = pstrdup(from->portalname);
2079 newnode->ismove = from->ismove;
2085 _copyIndexStmt(IndexStmt *from)
2087 IndexStmt *newnode = makeNode(IndexStmt);
2089 newnode->idxname = pstrdup(from->idxname);
2090 Node_Copy(from, newnode, relation);
2091 newnode->accessMethod = pstrdup(from->accessMethod);
2092 Node_Copy(from, newnode, indexParams);
2093 Node_Copy(from, newnode, whereClause);
2094 Node_Copy(from, newnode, rangetable);
2095 newnode->unique = from->unique;
2096 newnode->primary = from->primary;
2101 static ProcedureStmt *
2102 _copyProcedureStmt(ProcedureStmt *from)
2104 ProcedureStmt *newnode = makeNode(ProcedureStmt);
2106 newnode->replace = from->replace;
2107 Node_Copy(from, newnode, funcname);
2108 Node_Copy(from, newnode, argTypes);
2109 Node_Copy(from, newnode, returnType);
2110 Node_Copy(from, newnode, withClause);
2111 Node_Copy(from, newnode, as);
2112 newnode->language = pstrdup(from->language);
2117 static RemoveAggrStmt *
2118 _copyRemoveAggrStmt(RemoveAggrStmt *from)
2120 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
2122 Node_Copy(from, newnode, aggname);
2123 Node_Copy(from, newnode, aggtype);
2128 static RemoveFuncStmt *
2129 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2131 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2133 Node_Copy(from, newnode, funcname);
2134 Node_Copy(from, newnode, args);
2139 static RemoveOperStmt *
2140 _copyRemoveOperStmt(RemoveOperStmt *from)
2142 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2144 Node_Copy(from, newnode, opname);
2145 Node_Copy(from, newnode, args);
2151 _copyRenameStmt(RenameStmt *from)
2153 RenameStmt *newnode = makeNode(RenameStmt);
2155 Node_Copy(from, newnode, relation);
2157 newnode->oldname = pstrdup(from->oldname);
2159 newnode->newname = pstrdup(from->newname);
2160 newnode->renameType = from->renameType;
2166 _copyRuleStmt(RuleStmt *from)
2168 RuleStmt *newnode = makeNode(RuleStmt);
2170 Node_Copy(from, newnode, relation);
2171 newnode->rulename = pstrdup(from->rulename);
2172 Node_Copy(from, newnode, whereClause);
2173 newnode->event = from->event;
2174 newnode->instead = from->instead;
2175 Node_Copy(from, newnode, actions);
2181 _copyNotifyStmt(NotifyStmt *from)
2183 NotifyStmt *newnode = makeNode(NotifyStmt);
2185 Node_Copy(from, newnode, relation);
2191 _copyListenStmt(ListenStmt *from)
2193 ListenStmt *newnode = makeNode(ListenStmt);
2195 Node_Copy(from, newnode, relation);
2200 static UnlistenStmt *
2201 _copyUnlistenStmt(UnlistenStmt *from)
2203 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2205 Node_Copy(from, newnode, relation);
2210 static TransactionStmt *
2211 _copyTransactionStmt(TransactionStmt *from)
2213 TransactionStmt *newnode = makeNode(TransactionStmt);
2215 newnode->command = from->command;
2221 _copyViewStmt(ViewStmt *from)
2223 ViewStmt *newnode = makeNode(ViewStmt);
2225 Node_Copy(from, newnode, view);
2226 Node_Copy(from, newnode, aliases);
2227 Node_Copy(from, newnode, query);
2233 _copyLoadStmt(LoadStmt *from)
2235 LoadStmt *newnode = makeNode(LoadStmt);
2238 newnode->filename = pstrdup(from->filename);
2243 static CreateDomainStmt *
2244 _copyCreateDomainStmt(CreateDomainStmt *from)
2246 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2248 Node_Copy(from, newnode, domainname);
2249 Node_Copy(from, newnode, typename);
2250 Node_Copy(from, newnode, constraints);
2255 static CreatedbStmt *
2256 _copyCreatedbStmt(CreatedbStmt *from)
2258 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2261 newnode->dbname = pstrdup(from->dbname);
2263 newnode->dbowner = pstrdup(from->dbowner);
2265 newnode->dbpath = pstrdup(from->dbpath);
2266 if (from->dbtemplate)
2267 newnode->dbtemplate = pstrdup(from->dbtemplate);
2268 newnode->encoding = from->encoding;
2273 static AlterDatabaseSetStmt *
2274 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2276 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2279 newnode->dbname = pstrdup(from->dbname);
2281 newnode->variable = pstrdup(from->variable);
2282 Node_Copy(from, newnode, value);
2288 _copyDropdbStmt(DropdbStmt *from)
2290 DropdbStmt *newnode = makeNode(DropdbStmt);
2293 newnode->dbname = pstrdup(from->dbname);
2299 _copyVacuumStmt(VacuumStmt *from)
2301 VacuumStmt *newnode = makeNode(VacuumStmt);
2303 newnode->vacuum = from->vacuum;
2304 newnode->full = from->full;
2305 newnode->analyze = from->analyze;
2306 newnode->freeze = from->freeze;
2307 newnode->verbose = from->verbose;
2308 Node_Copy(from, newnode, relation);
2309 Node_Copy(from, newnode, va_cols);
2314 static ExplainStmt *
2315 _copyExplainStmt(ExplainStmt *from)
2317 ExplainStmt *newnode = makeNode(ExplainStmt);
2319 Node_Copy(from, newnode, query);
2320 newnode->verbose = from->verbose;
2321 newnode->analyze = from->analyze;
2326 static CreateSeqStmt *
2327 _copyCreateSeqStmt(CreateSeqStmt *from)
2329 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2331 Node_Copy(from, newnode, sequence);
2332 Node_Copy(from, newnode, options);
2337 static VariableSetStmt *
2338 _copyVariableSetStmt(VariableSetStmt *from)
2340 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2343 newnode->name = pstrdup(from->name);
2344 Node_Copy(from, newnode, args);
2349 static VariableShowStmt *
2350 _copyVariableShowStmt(VariableShowStmt *from)
2352 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2355 newnode->name = pstrdup(from->name);
2360 static VariableResetStmt *
2361 _copyVariableResetStmt(VariableResetStmt *from)
2363 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2366 newnode->name = pstrdup(from->name);
2371 static CreateTrigStmt *
2372 _copyCreateTrigStmt(CreateTrigStmt *from)
2374 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2377 newnode->trigname = pstrdup(from->trigname);
2378 Node_Copy(from, newnode, relation);
2379 Node_Copy(from, newnode, funcname);
2380 Node_Copy(from, newnode, args);
2381 newnode->before = from->before;
2382 newnode->row = from->row;
2383 memcpy(newnode->actions, from->actions, sizeof(from->actions));
2385 newnode->lang = pstrdup(from->lang);
2387 newnode->text = pstrdup(from->text);
2389 Node_Copy(from, newnode, attr);
2391 newnode->when = pstrdup(from->when);
2392 newnode->isconstraint = from->isconstraint;
2393 newnode->deferrable = from->deferrable;
2394 newnode->initdeferred = from->initdeferred;
2395 Node_Copy(from, newnode, constrrel);
2400 static DropPropertyStmt *
2401 _copyDropPropertyStmt(DropPropertyStmt *from)
2403 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2405 Node_Copy(from, newnode, relation);
2407 newnode->property = pstrdup(from->property);
2408 newnode->removeType = from->removeType;
2413 static CreatePLangStmt *
2414 _copyCreatePLangStmt(CreatePLangStmt *from)
2416 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2419 newnode->plname = pstrdup(from->plname);
2420 Node_Copy(from, newnode, plhandler);
2421 if (from->plcompiler)
2422 newnode->plcompiler = pstrdup(from->plcompiler);
2423 newnode->pltrusted = from->pltrusted;
2428 static DropPLangStmt *
2429 _copyDropPLangStmt(DropPLangStmt *from)
2431 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2434 newnode->plname = pstrdup(from->plname);
2439 static CreateUserStmt *
2440 _copyCreateUserStmt(CreateUserStmt *from)
2442 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2445 newnode->user = pstrdup(from->user);
2446 Node_Copy(from, newnode, options);
2451 static AlterUserStmt *
2452 _copyAlterUserStmt(AlterUserStmt *from)
2454 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2457 newnode->user = pstrdup(from->user);
2458 Node_Copy(from, newnode, options);
2463 static AlterUserSetStmt *
2464 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2466 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2469 newnode->user = pstrdup(from->user);
2471 newnode->user = pstrdup(from->variable);
2472 Node_Copy(from, newnode, value);
2477 static DropUserStmt *
2478 _copyDropUserStmt(DropUserStmt *from)
2480 DropUserStmt *newnode = makeNode(DropUserStmt);
2482 Node_Copy(from, newnode, users);
2488 _copyLockStmt(LockStmt *from)
2490 LockStmt *newnode = makeNode(LockStmt);
2492 Node_Copy(from, newnode, relations);
2494 newnode->mode = from->mode;
2499 static ConstraintsSetStmt *
2500 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2502 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2504 Node_Copy(from, newnode, constraints);
2505 newnode->deferred = from->deferred;
2510 static CreateGroupStmt *
2511 _copyCreateGroupStmt(CreateGroupStmt *from)
2513 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2516 newnode->name = pstrdup(from->name);
2517 Node_Copy(from, newnode, options);
2522 static AlterGroupStmt *
2523 _copyAlterGroupStmt(AlterGroupStmt *from)
2525 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2528 newnode->name = pstrdup(from->name);
2529 newnode->action = from->action;
2530 Node_Copy(from, newnode, listUsers);
2535 static DropGroupStmt *
2536 _copyDropGroupStmt(DropGroupStmt *from)
2538 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2541 newnode->name = pstrdup(from->name);
2546 static ReindexStmt *
2547 _copyReindexStmt(ReindexStmt *from)
2549 ReindexStmt *newnode = makeNode(ReindexStmt);
2551 newnode->reindexType = from->reindexType;
2552 Node_Copy(from, newnode, relation);
2554 newnode->name = pstrdup(from->name);
2555 newnode->force = from->force;
2556 newnode->all = from->all;
2561 static CreateSchemaStmt *
2562 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2564 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2566 newnode->schemaname = pstrdup(from->schemaname);
2568 newnode->authid = pstrdup(from->authid);
2569 Node_Copy(from, newnode, schemaElts);
2575 /* ****************************************************************
2576 * pg_list.h copy functions
2577 * ****************************************************************
2581 _copyValue(Value *from)
2583 Value *newnode = makeNode(Value);
2585 newnode->type = from->type;
2589 newnode->val.ival = from->val.ival;
2594 newnode->val.str = pstrdup(from->val.str);
2603 * copyObject returns a copy of the node or list. If it is a list, it
2604 * recursively copies its items.
2608 copyObject(void *from)
2615 switch (nodeTag(from))
2621 retval = _copyPlan(from);
2624 retval = _copyResult(from);
2627 retval = _copyAppend(from);
2630 retval = _copyScan(from);
2633 retval = _copySeqScan(from);
2636 retval = _copyIndexScan(from);
2639 retval = _copyTidScan(from);
2641 case T_SubqueryScan:
2642 retval = _copySubqueryScan(from);
2644 case T_FunctionScan:
2645 retval = _copyFunctionScan(from);
2648 retval = _copyJoin(from);
2651 retval = _copyNestLoop(from);
2654 retval = _copyMergeJoin(from);
2657 retval = _copyHashJoin(from);
2660 retval = _copyMaterial(from);
2663 retval = _copySort(from);
2666 retval = _copyGroup(from);
2669 retval = _copyAgg(from);
2672 retval = _copyUnique(from);
2675 retval = _copySetOp(from);
2678 retval = _copyLimit(from);
2681 retval = _copyHash(from);
2684 retval = _copySubPlan(from);
2691 retval = _copyResdom(from);
2694 retval = _copyFjoin(from);
2697 retval = _copyExpr(from);
2700 retval = _copyVar(from);
2703 retval = _copyOper(from);
2706 retval = _copyConst(from);
2709 retval = _copyParam(from);
2712 retval = _copyAggref(from);
2715 retval = _copySubLink(from);
2718 retval = _copyFunc(from);
2721 retval = _copyArrayRef(from);
2724 retval = _copyFieldSelect(from);
2727 retval = _copyRelabelType(from);
2730 retval = _copyRangeTblRef(from);
2733 retval = _copyFromExpr(from);
2736 retval = _copyJoinExpr(from);
2743 retval = _copyRelOptInfo(from);
2746 retval = _copyPath(from);
2749 retval = _copyIndexPath(from);
2752 retval = _copyTidPath(from);
2755 retval = _copyAppendPath(from);
2758 retval = _copyNestPath(from);
2761 retval = _copyMergePath(from);
2764 retval = _copyHashPath(from);
2767 retval = _copyPathKeyItem(from);
2769 case T_RestrictInfo:
2770 retval = _copyRestrictInfo(from);
2773 retval = _copyJoinInfo(from);
2776 retval = _copyStream(from);
2778 case T_IndexOptInfo:
2779 retval = _copyIndexOptInfo(from);
2789 retval = _copyValue(from);
2797 /* rather ugly coding for speed... */
2798 /* Note the input list cannot be NIL if we got here. */
2799 nl = makeList1(copyObject(lfirst(list)));
2802 foreach(l, lnext(list))
2804 lnext(nl) = makeList1(copyObject(lfirst(l)));
2814 retval = _copyQuery(from);
2817 retval = _copyInsertStmt(from);
2820 retval = _copyDeleteStmt(from);
2823 retval = _copyUpdateStmt(from);
2826 retval = _copySelectStmt(from);
2828 case T_SetOperationStmt:
2829 retval = _copySetOperationStmt(from);
2831 case T_AlterTableStmt:
2832 retval = _copyAlterTableStmt(from);
2835 retval = _copyGrantStmt(from);
2837 case T_ClosePortalStmt:
2838 retval = _copyClosePortalStmt(from);
2841 retval = _copyClusterStmt(from);
2844 retval = _copyCopyStmt(from);
2847 retval = _copyCreateStmt(from);
2850 retval = _copyDefineStmt(from);
2853 retval = _copyDropStmt(from);
2855 case T_TruncateStmt:
2856 retval = _copyTruncateStmt(from);
2859 retval = _copyCommentStmt(from);
2862 retval = _copyFetchStmt(from);
2865 retval = _copyIndexStmt(from);
2867 case T_ProcedureStmt:
2868 retval = _copyProcedureStmt(from);
2870 case T_RemoveAggrStmt:
2871 retval = _copyRemoveAggrStmt(from);
2873 case T_RemoveFuncStmt:
2874 retval = _copyRemoveFuncStmt(from);
2876 case T_RemoveOperStmt:
2877 retval = _copyRemoveOperStmt(from);
2880 retval = _copyRenameStmt(from);
2883 retval = _copyRuleStmt(from);
2886 retval = _copyNotifyStmt(from);
2889 retval = _copyListenStmt(from);
2891 case T_UnlistenStmt:
2892 retval = _copyUnlistenStmt(from);
2894 case T_TransactionStmt:
2895 retval = _copyTransactionStmt(from);
2898 retval = _copyViewStmt(from);
2901 retval = _copyLoadStmt(from);
2903 case T_CreateDomainStmt:
2904 retval = _copyCreateDomainStmt(from);
2906 case T_CreatedbStmt:
2907 retval = _copyCreatedbStmt(from);
2909 case T_AlterDatabaseSetStmt:
2910 retval = _copyAlterDatabaseSetStmt(from);
2913 retval = _copyDropdbStmt(from);
2916 retval = _copyVacuumStmt(from);
2919 retval = _copyExplainStmt(from);
2921 case T_CreateSeqStmt:
2922 retval = _copyCreateSeqStmt(from);
2924 case T_VariableSetStmt:
2925 retval = _copyVariableSetStmt(from);
2927 case T_VariableShowStmt:
2928 retval = _copyVariableShowStmt(from);
2930 case T_VariableResetStmt:
2931 retval = _copyVariableResetStmt(from);
2933 case T_CreateTrigStmt:
2934 retval = _copyCreateTrigStmt(from);
2936 case T_DropPropertyStmt:
2937 retval = _copyDropPropertyStmt(from);
2939 case T_CreatePLangStmt:
2940 retval = _copyCreatePLangStmt(from);
2942 case T_DropPLangStmt:
2943 retval = _copyDropPLangStmt(from);
2945 case T_CreateUserStmt:
2946 retval = _copyCreateUserStmt(from);
2948 case T_AlterUserStmt:
2949 retval = _copyAlterUserStmt(from);
2951 case T_AlterUserSetStmt:
2952 retval = _copyAlterUserSetStmt(from);
2954 case T_DropUserStmt:
2955 retval = _copyDropUserStmt(from);
2958 retval = _copyLockStmt(from);
2960 case T_ConstraintsSetStmt:
2961 retval = _copyConstraintsSetStmt(from);
2963 case T_CreateGroupStmt:
2964 retval = _copyCreateGroupStmt(from);
2966 case T_AlterGroupStmt:
2967 retval = _copyAlterGroupStmt(from);
2969 case T_DropGroupStmt:
2970 retval = _copyDropGroupStmt(from);
2973 retval = _copyReindexStmt(from);
2975 case T_CheckPointStmt:
2976 retval = (void *) makeNode(CheckPointStmt);
2978 case T_CreateSchemaStmt:
2979 retval = _copyCreateSchemaStmt(from);
2983 retval = _copyAExpr(from);
2986 retval = _copyColumnRef(from);
2989 retval = _copyParamRef(from);
2992 retval = _copyAConst(from);
2995 retval = _copyIdent(from);
2998 retval = _copyFuncCall(from);
3001 retval = _copyAIndices(from);
3003 case T_ExprFieldSelect:
3004 retval = _copyExprFieldSelect(from);
3007 retval = _copyResTarget(from);
3010 retval = _copyTypeCast(from);
3013 retval = _copySortGroupBy(from);
3016 retval = _copyAlias(from);
3019 retval = _copyRangeVar(from);
3021 case T_RangeSubselect:
3022 retval = _copyRangeSubselect(from);
3024 case T_RangeFunction:
3025 retval = _copyRangeFunction(from);
3028 retval = _copyTypeName(from);
3031 retval = _copyIndexElem(from);
3034 retval = _copyColumnDef(from);
3037 retval = _copyConstraint(from);
3040 retval = _copyDefElem(from);
3043 retval = _copyTargetEntry(from);
3045 case T_RangeTblEntry:
3046 retval = _copyRangeTblEntry(from);
3049 retval = _copySortClause(from);
3052 retval = _copyGroupClause(from);
3055 retval = _copyCaseExpr(from);
3058 retval = _copyCaseWhen(from);
3061 retval = _copyNullTest(from);
3064 retval = _copyBooleanTest(from);
3066 case T_FkConstraint:
3067 retval = _copyFkConstraint(from);
3070 retval = _copyPrivGrantee(from);
3072 case T_FuncWithArgs:
3073 retval = _copyFuncWithArgs(from);
3075 case T_InsertDefault:
3076 retval = _copyInsertDefault(from);
3080 elog(ERROR, "copyObject: don't know how to copy node type %d",
3082 retval = from; /* keep compiler quiet */