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.173 2002/03/22 02:56:31 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 newnode->joinrti = from->joinrti;
327 /* subPlan list must point to subplans in the new subtree, not the old */
328 if (from->plan.subPlan != NIL)
329 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
330 pull_subplans((Node *) newnode->joinqual));
339 _copyJoin(Join *from)
341 Join *newnode = makeNode(Join);
344 * copy node superclass fields
346 CopyPlanFields((Plan *) from, (Plan *) newnode);
347 CopyJoinFields(from, newnode);
358 _copyNestLoop(NestLoop *from)
360 NestLoop *newnode = makeNode(NestLoop);
363 * copy node superclass fields
365 CopyPlanFields((Plan *) from, (Plan *) newnode);
366 CopyJoinFields((Join *) from, (Join *) newnode);
377 _copyMergeJoin(MergeJoin *from)
379 MergeJoin *newnode = makeNode(MergeJoin);
382 * copy node superclass fields
384 CopyPlanFields((Plan *) from, (Plan *) newnode);
385 CopyJoinFields((Join *) from, (Join *) newnode);
388 * copy remainder of node
390 Node_Copy(from, newnode, mergeclauses);
393 * We must add subplans in mergeclauses to the new plan's subPlan list
395 if (from->join.plan.subPlan != NIL)
396 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
397 pull_subplans((Node *) newnode->mergeclauses));
407 _copyHashJoin(HashJoin *from)
409 HashJoin *newnode = makeNode(HashJoin);
412 * copy node superclass fields
414 CopyPlanFields((Plan *) from, (Plan *) newnode);
415 CopyJoinFields((Join *) from, (Join *) newnode);
418 * copy remainder of node
420 Node_Copy(from, newnode, hashclauses);
421 newnode->hashjoinop = from->hashjoinop;
424 * We must add subplans in hashclauses to the new plan's subPlan list
426 if (from->join.plan.subPlan != NIL)
427 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
428 pull_subplans((Node *) newnode->hashclauses));
439 _copyMaterial(Material *from)
441 Material *newnode = makeNode(Material);
444 * copy node superclass fields
446 CopyPlanFields((Plan *) from, (Plan *) newnode);
457 _copySort(Sort *from)
459 Sort *newnode = makeNode(Sort);
462 * copy node superclass fields
464 CopyPlanFields((Plan *) from, (Plan *) newnode);
466 newnode->keycount = from->keycount;
477 _copyGroup(Group *from)
479 Group *newnode = makeNode(Group);
481 CopyPlanFields((Plan *) from, (Plan *) newnode);
483 newnode->tuplePerGroup = from->tuplePerGroup;
484 newnode->numCols = from->numCols;
485 newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
486 memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
498 Agg *newnode = makeNode(Agg);
500 CopyPlanFields((Plan *) from, (Plan *) newnode);
510 _copyGroupClause(GroupClause *from)
512 GroupClause *newnode = makeNode(GroupClause);
514 newnode->tleSortGroupRef = from->tleSortGroupRef;
515 newnode->sortop = from->sortop;
525 _copyUnique(Unique *from)
527 Unique *newnode = makeNode(Unique);
530 * copy node superclass fields
532 CopyPlanFields((Plan *) from, (Plan *) newnode);
535 * copy remainder of node
537 newnode->numCols = from->numCols;
538 newnode->uniqColIdx = palloc(from->numCols * sizeof(AttrNumber));
539 memcpy(newnode->uniqColIdx, from->uniqColIdx, from->numCols * sizeof(AttrNumber));
549 _copySetOp(SetOp *from)
551 SetOp *newnode = makeNode(SetOp);
554 * copy node superclass fields
556 CopyPlanFields((Plan *) from, (Plan *) newnode);
559 * copy remainder of node
561 newnode->cmd = from->cmd;
562 newnode->numCols = from->numCols;
563 newnode->dupColIdx = palloc(from->numCols * sizeof(AttrNumber));
564 memcpy(newnode->dupColIdx, from->dupColIdx, from->numCols * sizeof(AttrNumber));
565 newnode->flagColIdx = from->flagColIdx;
575 _copyLimit(Limit *from)
577 Limit *newnode = makeNode(Limit);
580 * copy node superclass fields
582 CopyPlanFields((Plan *) from, (Plan *) newnode);
585 * copy remainder of node
587 Node_Copy(from, newnode, limitOffset);
588 Node_Copy(from, newnode, limitCount);
598 _copyHash(Hash *from)
600 Hash *newnode = makeNode(Hash);
603 * copy node superclass fields
605 CopyPlanFields((Plan *) from, (Plan *) newnode);
608 * copy remainder of node
610 Node_Copy(from, newnode, hashkey);
616 _copySubPlan(SubPlan *from)
618 SubPlan *newnode = makeNode(SubPlan);
620 Node_Copy(from, newnode, plan);
621 newnode->plan_id = from->plan_id;
622 Node_Copy(from, newnode, rtable);
623 newnode->setParam = listCopy(from->setParam);
624 newnode->parParam = listCopy(from->parParam);
625 Node_Copy(from, newnode, sublink);
627 /* do not copy execution state */
628 newnode->needShutdown = false;
629 newnode->curTuple = NULL;
634 /* ****************************************************************
635 * primnodes.h copy functions
636 * ****************************************************************
644 _copyResdom(Resdom *from)
646 Resdom *newnode = makeNode(Resdom);
648 newnode->resno = from->resno;
649 newnode->restype = from->restype;
650 newnode->restypmod = from->restypmod;
651 if (from->resname != NULL)
652 newnode->resname = pstrdup(from->resname);
653 newnode->ressortgroupref = from->ressortgroupref;
654 newnode->reskey = from->reskey;
655 newnode->reskeyop = from->reskeyop;
656 newnode->resjunk = from->resjunk;
662 _copyFjoin(Fjoin *from)
664 Fjoin *newnode = makeNode(Fjoin);
667 * copy node superclass fields
670 newnode->fj_initialized = from->fj_initialized;
671 newnode->fj_nNodes = from->fj_nNodes;
673 Node_Copy(from, newnode, fj_innerNode);
675 newnode->fj_results = (DatumPtr)
676 palloc((from->fj_nNodes) * sizeof(Datum));
677 memmove(from->fj_results,
679 (from->fj_nNodes) * sizeof(Datum));
681 newnode->fj_alwaysDone = (BoolPtr)
682 palloc((from->fj_nNodes) * sizeof(bool));
683 memmove(from->fj_alwaysDone,
684 newnode->fj_alwaysDone,
685 (from->fj_nNodes) * sizeof(bool));
696 _copyExpr(Expr *from)
698 Expr *newnode = makeNode(Expr);
701 * copy node superclass fields
703 newnode->typeOid = from->typeOid;
704 newnode->opType = from->opType;
706 Node_Copy(from, newnode, oper);
707 Node_Copy(from, newnode, args);
719 Var *newnode = makeNode(Var);
722 * copy remainder of node
724 newnode->varno = from->varno;
725 newnode->varattno = from->varattno;
726 newnode->vartype = from->vartype;
727 newnode->vartypmod = from->vartypmod;
728 newnode->varlevelsup = from->varlevelsup;
730 newnode->varnoold = from->varnoold;
731 newnode->varoattno = from->varoattno;
741 _copyOper(Oper *from)
743 Oper *newnode = makeNode(Oper);
746 * copy remainder of node
748 newnode->opno = from->opno;
749 newnode->opid = from->opid;
750 newnode->opresulttype = from->opresulttype;
751 /* Do not copy the run-time state, if any */
752 newnode->op_fcache = NULL;
762 _copyConst(Const *from)
764 Const *newnode = makeNode(Const);
767 * copy remainder of node
769 newnode->consttype = from->consttype;
770 newnode->constlen = from->constlen;
772 if (from->constbyval || from->constisnull)
775 * passed by value so just copy the datum. Also, don't try to copy
776 * struct when value is null!
779 newnode->constvalue = from->constvalue;
784 * not passed by value. datum contains a pointer.
786 int length = from->constlen;
788 if (length == -1) /* variable-length type? */
789 length = VARSIZE(from->constvalue);
790 newnode->constvalue = PointerGetDatum(palloc(length));
791 memcpy(DatumGetPointer(newnode->constvalue),
792 DatumGetPointer(from->constvalue),
796 newnode->constisnull = from->constisnull;
797 newnode->constbyval = from->constbyval;
798 newnode->constisset = from->constisset;
799 newnode->constiscast = from->constiscast;
809 _copyParam(Param *from)
811 Param *newnode = makeNode(Param);
814 * copy remainder of node
816 newnode->paramkind = from->paramkind;
817 newnode->paramid = from->paramid;
819 if (from->paramname != NULL)
820 newnode->paramname = pstrdup(from->paramname);
821 newnode->paramtype = from->paramtype;
831 _copyFunc(Func *from)
833 Func *newnode = makeNode(Func);
836 * copy remainder of node
838 newnode->funcid = from->funcid;
839 newnode->functype = from->functype;
840 /* Do not copy the run-time state, if any */
841 newnode->func_fcache = NULL;
851 _copyAggref(Aggref *from)
853 Aggref *newnode = makeNode(Aggref);
856 * copy remainder of node
858 newnode->aggname = pstrdup(from->aggname);
859 newnode->basetype = from->basetype;
860 newnode->aggtype = from->aggtype;
861 Node_Copy(from, newnode, target);
862 newnode->aggstar = from->aggstar;
863 newnode->aggdistinct = from->aggdistinct;
864 newnode->aggno = from->aggno; /* probably not needed */
874 _copySubLink(SubLink *from)
876 SubLink *newnode = makeNode(SubLink);
879 * copy remainder of node
881 newnode->subLinkType = from->subLinkType;
882 newnode->useor = from->useor;
883 Node_Copy(from, newnode, lefthand);
884 Node_Copy(from, newnode, oper);
885 Node_Copy(from, newnode, subselect);
895 _copyFieldSelect(FieldSelect *from)
897 FieldSelect *newnode = makeNode(FieldSelect);
900 * copy remainder of node
902 Node_Copy(from, newnode, arg);
903 newnode->fieldnum = from->fieldnum;
904 newnode->resulttype = from->resulttype;
905 newnode->resulttypmod = from->resulttypmod;
915 _copyRelabelType(RelabelType *from)
917 RelabelType *newnode = makeNode(RelabelType);
920 * copy remainder of node
922 Node_Copy(from, newnode, arg);
923 newnode->resulttype = from->resulttype;
924 newnode->resulttypmod = from->resulttypmod;
930 _copyRangeTblRef(RangeTblRef *from)
932 RangeTblRef *newnode = makeNode(RangeTblRef);
934 newnode->rtindex = from->rtindex;
940 _copyFromExpr(FromExpr *from)
942 FromExpr *newnode = makeNode(FromExpr);
944 Node_Copy(from, newnode, fromlist);
945 Node_Copy(from, newnode, quals);
951 _copyJoinExpr(JoinExpr *from)
953 JoinExpr *newnode = makeNode(JoinExpr);
955 newnode->jointype = from->jointype;
956 newnode->isNatural = from->isNatural;
957 Node_Copy(from, newnode, larg);
958 Node_Copy(from, newnode, rarg);
959 Node_Copy(from, newnode, using);
960 Node_Copy(from, newnode, quals);
961 Node_Copy(from, newnode, alias);
962 newnode->rtindex = from->rtindex;
972 _copyCaseExpr(CaseExpr *from)
974 CaseExpr *newnode = makeNode(CaseExpr);
977 * copy remainder of node
979 newnode->casetype = from->casetype;
981 Node_Copy(from, newnode, arg);
982 Node_Copy(from, newnode, args);
983 Node_Copy(from, newnode, defresult);
993 _copyCaseWhen(CaseWhen *from)
995 CaseWhen *newnode = makeNode(CaseWhen);
998 * copy remainder of node
1000 Node_Copy(from, newnode, expr);
1001 Node_Copy(from, newnode, result);
1011 _copyNullTest(NullTest *from)
1013 NullTest *newnode = makeNode(NullTest);
1016 * copy remainder of node
1018 Node_Copy(from, newnode, arg);
1019 newnode->nulltesttype = from->nulltesttype;
1028 static BooleanTest *
1029 _copyBooleanTest(BooleanTest *from)
1031 BooleanTest *newnode = makeNode(BooleanTest);
1034 * copy remainder of node
1036 Node_Copy(from, newnode, arg);
1037 newnode->booltesttype = from->booltesttype;
1043 _copyArrayRef(ArrayRef *from)
1045 ArrayRef *newnode = makeNode(ArrayRef);
1048 * copy remainder of node
1050 newnode->refattrlength = from->refattrlength;
1051 newnode->refelemlength = from->refelemlength;
1052 newnode->refelemtype = from->refelemtype;
1053 newnode->refelembyval = from->refelembyval;
1055 Node_Copy(from, newnode, refupperindexpr);
1056 Node_Copy(from, newnode, reflowerindexpr);
1057 Node_Copy(from, newnode, refexpr);
1058 Node_Copy(from, newnode, refassgnexpr);
1063 /* ****************************************************************
1064 * relation.h copy functions
1065 * ****************************************************************
1073 _copyRelOptInfo(RelOptInfo *from)
1075 RelOptInfo *newnode = makeNode(RelOptInfo);
1077 newnode->reloptkind = from->reloptkind;
1079 newnode->relids = listCopy(from->relids);
1081 newnode->rows = from->rows;
1082 newnode->width = from->width;
1084 Node_Copy(from, newnode, targetlist);
1085 Node_Copy(from, newnode, pathlist);
1086 /* XXX cheapest-path fields should point to members of pathlist? */
1087 Node_Copy(from, newnode, cheapest_startup_path);
1088 Node_Copy(from, newnode, cheapest_total_path);
1089 newnode->pruneable = from->pruneable;
1091 newnode->issubquery = from->issubquery;
1092 Node_Copy(from, newnode, indexlist);
1093 newnode->pages = from->pages;
1094 newnode->tuples = from->tuples;
1095 Node_Copy(from, newnode, subplan);
1097 newnode->joinrti = from->joinrti;
1098 newnode->joinrteids = listCopy(from->joinrteids);
1100 Node_Copy(from, newnode, baserestrictinfo);
1101 newnode->baserestrictcost = from->baserestrictcost;
1102 newnode->outerjoinset = listCopy(from->outerjoinset);
1103 Node_Copy(from, newnode, joininfo);
1104 Node_Copy(from, newnode, innerjoin);
1113 static IndexOptInfo *
1114 _copyIndexOptInfo(IndexOptInfo *from)
1116 IndexOptInfo *newnode = makeNode(IndexOptInfo);
1119 newnode->indexoid = from->indexoid;
1120 newnode->pages = from->pages;
1121 newnode->tuples = from->tuples;
1123 newnode->ncolumns = from->ncolumns;
1124 newnode->nkeys = from->nkeys;
1126 if (from->classlist)
1128 /* copy the trailing zero too */
1129 len = (from->ncolumns + 1) * sizeof(Oid);
1130 newnode->classlist = (Oid *) palloc(len);
1131 memcpy(newnode->classlist, from->classlist, len);
1134 if (from->indexkeys)
1136 /* copy the trailing zero too */
1137 len = (from->nkeys + 1) * sizeof(int);
1138 newnode->indexkeys = (int *) palloc(len);
1139 memcpy(newnode->indexkeys, from->indexkeys, len);
1144 /* copy the trailing zero too */
1145 len = (from->ncolumns + 1) * sizeof(Oid);
1146 newnode->ordering = (Oid *) palloc(len);
1147 memcpy(newnode->ordering, from->ordering, len);
1150 newnode->relam = from->relam;
1151 newnode->amcostestimate = from->amcostestimate;
1152 newnode->indproc = from->indproc;
1153 Node_Copy(from, newnode, indpred);
1154 newnode->unique = from->unique;
1162 * This function copies the fields of the Path node. It is used by
1163 * all the copy functions for classes which inherit from Path.
1167 CopyPathFields(Path *from, Path *newnode)
1170 * Modify the next line, since it causes the copying to cycle (i.e.
1171 * the parent points right back here! -- JMH, 7/7/92. Old version:
1172 * Node_Copy(from, newnode, parent);
1174 newnode->parent = from->parent;
1176 newnode->startup_cost = from->startup_cost;
1177 newnode->total_cost = from->total_cost;
1179 newnode->pathtype = from->pathtype;
1181 Node_Copy(from, newnode, pathkeys);
1189 _copyPath(Path *from)
1191 Path *newnode = makeNode(Path);
1193 CopyPathFields(from, newnode);
1203 _copyIndexPath(IndexPath *from)
1205 IndexPath *newnode = makeNode(IndexPath);
1208 * copy the node superclass fields
1210 CopyPathFields((Path *) from, (Path *) newnode);
1213 * copy remainder of node
1215 Node_Copy(from, newnode, indexinfo);
1216 Node_Copy(from, newnode, indexqual);
1217 newnode->indexscandir = from->indexscandir;
1218 newnode->joinrelids = listCopy(from->joinrelids);
1219 newnode->alljoinquals = from->alljoinquals;
1220 newnode->rows = from->rows;
1230 _copyTidPath(TidPath *from)
1232 TidPath *newnode = makeNode(TidPath);
1235 * copy the node superclass fields
1237 CopyPathFields((Path *) from, (Path *) newnode);
1240 * copy remainder of node
1242 Node_Copy(from, newnode, tideval);
1243 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1253 _copyAppendPath(AppendPath *from)
1255 AppendPath *newnode = makeNode(AppendPath);
1258 * copy the node superclass fields
1260 CopyPathFields((Path *) from, (Path *) newnode);
1263 * copy remainder of node
1265 Node_Copy(from, newnode, subpaths);
1271 * CopyJoinPathFields
1273 * This function copies the fields of the JoinPath node. It is used by
1274 * all the copy functions for classes which inherit from JoinPath.
1278 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1280 newnode->jointype = from->jointype;
1281 Node_Copy(from, newnode, outerjoinpath);
1282 Node_Copy(from, newnode, innerjoinpath);
1283 Node_Copy(from, newnode, joinrestrictinfo);
1291 _copyNestPath(NestPath *from)
1293 NestPath *newnode = makeNode(NestPath);
1296 * copy the node superclass fields
1298 CopyPathFields((Path *) from, (Path *) newnode);
1299 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1309 _copyMergePath(MergePath *from)
1311 MergePath *newnode = makeNode(MergePath);
1314 * copy the node superclass fields
1316 CopyPathFields((Path *) from, (Path *) newnode);
1317 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1320 * copy the remainder of the node
1322 Node_Copy(from, newnode, path_mergeclauses);
1323 Node_Copy(from, newnode, outersortkeys);
1324 Node_Copy(from, newnode, innersortkeys);
1334 _copyHashPath(HashPath *from)
1336 HashPath *newnode = makeNode(HashPath);
1339 * copy the node superclass fields
1341 CopyPathFields((Path *) from, (Path *) newnode);
1342 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1345 * copy remainder of node
1347 Node_Copy(from, newnode, path_hashclauses);
1356 static PathKeyItem *
1357 _copyPathKeyItem(PathKeyItem *from)
1359 PathKeyItem *newnode = makeNode(PathKeyItem);
1362 * copy remainder of node
1364 Node_Copy(from, newnode, key);
1365 newnode->sortop = from->sortop;
1374 static RestrictInfo *
1375 _copyRestrictInfo(RestrictInfo *from)
1377 RestrictInfo *newnode = makeNode(RestrictInfo);
1380 * copy remainder of node
1382 Node_Copy(from, newnode, clause);
1383 newnode->ispusheddown = from->ispusheddown;
1384 Node_Copy(from, newnode, subclauseindices);
1385 newnode->eval_cost = from->eval_cost;
1386 newnode->this_selec = from->this_selec;
1387 newnode->mergejoinoperator = from->mergejoinoperator;
1388 newnode->left_sortop = from->left_sortop;
1389 newnode->right_sortop = from->right_sortop;
1392 * Do not copy pathkeys, since they'd not be canonical in a copied
1395 newnode->left_pathkey = NIL;
1396 newnode->right_pathkey = NIL;
1397 newnode->left_mergescansel = from->left_mergescansel;
1398 newnode->right_mergescansel = from->right_mergescansel;
1399 newnode->hashjoinoperator = from->hashjoinoperator;
1400 newnode->left_bucketsize = from->left_bucketsize;
1401 newnode->right_bucketsize = from->right_bucketsize;
1411 _copyJoinInfo(JoinInfo *from)
1413 JoinInfo *newnode = makeNode(JoinInfo);
1416 * copy remainder of node
1418 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1419 Node_Copy(from, newnode, jinfo_restrictinfo);
1425 _copyIter(Iter *from)
1427 Iter *newnode = makeNode(Iter);
1429 Node_Copy(from, newnode, iterexpr);
1430 newnode->itertype = from->itertype;
1436 _copyStream(Stream *from)
1438 Stream *newnode = makeNode(Stream);
1440 newnode->pathptr = from->pathptr;
1441 newnode->cinfo = from->cinfo;
1442 newnode->clausetype = from->clausetype;
1444 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1446 Node_Copy(from, newnode, downstream);
1447 if (newnode->downstream)
1448 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1450 newnode->groupup = from->groupup;
1451 newnode->groupcost = from->groupcost;
1452 newnode->groupsel = from->groupsel;
1457 /* ****************************************************************
1458 * parsenodes.h copy functions
1459 * ****************************************************************
1462 static TargetEntry *
1463 _copyTargetEntry(TargetEntry *from)
1465 TargetEntry *newnode = makeNode(TargetEntry);
1467 Node_Copy(from, newnode, resdom);
1468 Node_Copy(from, newnode, fjoin);
1469 Node_Copy(from, newnode, expr);
1473 static RangeTblEntry *
1474 _copyRangeTblEntry(RangeTblEntry *from)
1476 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1478 newnode->rtekind = from->rtekind;
1479 newnode->relid = from->relid;
1480 Node_Copy(from, newnode, subquery);
1481 newnode->jointype = from->jointype;
1482 newnode->joincoltypes = listCopy(from->joincoltypes);
1483 newnode->joincoltypmods = listCopy(from->joincoltypmods);
1484 newnode->joinleftcols = listCopy(from->joinleftcols);
1485 newnode->joinrightcols = listCopy(from->joinrightcols);
1486 Node_Copy(from, newnode, alias);
1487 Node_Copy(from, newnode, eref);
1488 newnode->inh = from->inh;
1489 newnode->inFromCl = from->inFromCl;
1490 newnode->checkForRead = from->checkForRead;
1491 newnode->checkForWrite = from->checkForWrite;
1492 newnode->checkAsUser = from->checkAsUser;
1497 static FkConstraint *
1498 _copyFkConstraint(FkConstraint *from)
1500 FkConstraint *newnode = makeNode(FkConstraint);
1502 if (from->constr_name)
1503 newnode->constr_name = pstrdup(from->constr_name);
1504 Node_Copy(from, newnode, pktable);
1505 Node_Copy(from, newnode, fk_attrs);
1506 Node_Copy(from, newnode, pk_attrs);
1507 if (from->match_type)
1508 newnode->match_type = pstrdup(from->match_type);
1509 newnode->actions = from->actions;
1510 newnode->deferrable = from->deferrable;
1511 newnode->initdeferred = from->initdeferred;
1517 _copySortClause(SortClause *from)
1519 SortClause *newnode = makeNode(SortClause);
1521 newnode->tleSortGroupRef = from->tleSortGroupRef;
1522 newnode->sortop = from->sortop;
1528 _copyAExpr(A_Expr *from)
1530 A_Expr *newnode = makeNode(A_Expr);
1532 newnode->oper = from->oper;
1534 newnode->opname = pstrdup(from->opname);
1535 Node_Copy(from, newnode, lexpr);
1536 Node_Copy(from, newnode, rexpr);
1542 _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);
1591 newnode->funcname = pstrdup(from->funcname);
1592 Node_Copy(from, newnode, args);
1593 newnode->agg_star = from->agg_star;
1594 newnode->agg_distinct = from->agg_distinct;
1600 _copyAIndices(A_Indices *from)
1602 A_Indices *newnode = makeNode(A_Indices);
1604 Node_Copy(from, newnode, lidx);
1605 Node_Copy(from, newnode, uidx);
1610 static ExprFieldSelect *
1611 _copyExprFieldSelect(ExprFieldSelect *from)
1613 ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
1615 Node_Copy(from, newnode, arg);
1616 Node_Copy(from, newnode, fields);
1617 Node_Copy(from, newnode, indirection);
1623 _copyResTarget(ResTarget *from)
1625 ResTarget *newnode = makeNode(ResTarget);
1628 newnode->name = pstrdup(from->name);
1629 Node_Copy(from, newnode, indirection);
1630 Node_Copy(from, newnode, val);
1636 _copyTypeName(TypeName *from)
1638 TypeName *newnode = makeNode(TypeName);
1641 newnode->name = pstrdup(from->name);
1642 newnode->timezone = from->timezone;
1643 newnode->setof = from->setof;
1644 newnode->typmod = from->typmod;
1645 Node_Copy(from, newnode, arrayBounds);
1650 static SortGroupBy *
1651 _copySortGroupBy(SortGroupBy *from)
1653 SortGroupBy *newnode = makeNode(SortGroupBy);
1656 newnode->useOp = pstrdup(from->useOp);
1657 Node_Copy(from, newnode, node);
1663 _copyAlias(Alias *from)
1665 Alias *newnode = makeNode(Alias);
1667 if (from->aliasname)
1668 newnode->aliasname = pstrdup(from->aliasname);
1669 Node_Copy(from, newnode, colnames);
1675 _copyRangeVar(RangeVar *from)
1677 RangeVar *newnode = makeNode(RangeVar);
1679 if (from->catalogname)
1680 newnode->catalogname = pstrdup(from->catalogname);
1681 if (from->schemaname)
1682 newnode->schemaname = pstrdup(from->schemaname);
1684 newnode->relname = pstrdup(from->relname);
1685 newnode->inhOpt = from->inhOpt;
1686 newnode->istemp = from->istemp;
1687 Node_Copy(from, newnode, alias);
1692 static RangeSubselect *
1693 _copyRangeSubselect(RangeSubselect *from)
1695 RangeSubselect *newnode = makeNode(RangeSubselect);
1697 Node_Copy(from, newnode, subquery);
1698 Node_Copy(from, newnode, alias);
1704 _copyTypeCast(TypeCast *from)
1706 TypeCast *newnode = makeNode(TypeCast);
1708 Node_Copy(from, newnode, arg);
1709 Node_Copy(from, newnode, typename);
1715 _copyIndexElem(IndexElem *from)
1717 IndexElem *newnode = makeNode(IndexElem);
1720 newnode->name = pstrdup(from->name);
1721 Node_Copy(from, newnode, args);
1723 newnode->class = pstrdup(from->class);
1729 _copyColumnDef(ColumnDef *from)
1731 ColumnDef *newnode = makeNode(ColumnDef);
1734 newnode->colname = pstrdup(from->colname);
1735 Node_Copy(from, newnode, typename);
1736 newnode->is_not_null = from->is_not_null;
1737 Node_Copy(from, newnode, raw_default);
1738 if (from->cooked_default)
1739 newnode->cooked_default = pstrdup(from->cooked_default);
1740 Node_Copy(from, newnode, constraints);
1746 _copyConstraint(Constraint *from)
1748 Constraint *newnode = makeNode(Constraint);
1750 newnode->contype = from->contype;
1752 newnode->name = pstrdup(from->name);
1753 Node_Copy(from, newnode, raw_expr);
1754 if (from->cooked_expr)
1755 newnode->cooked_expr = pstrdup(from->cooked_expr);
1756 Node_Copy(from, newnode, keys);
1762 _copyDefElem(DefElem *from)
1764 DefElem *newnode = makeNode(DefElem);
1767 newnode->defname = pstrdup(from->defname);
1768 Node_Copy(from, newnode, arg);
1774 _copyQuery(Query *from)
1776 Query *newnode = makeNode(Query);
1778 newnode->commandType = from->commandType;
1779 Node_Copy(from, newnode, utilityStmt);
1780 newnode->resultRelation = from->resultRelation;
1781 Node_Copy(from, newnode, into);
1782 newnode->isPortal = from->isPortal;
1783 newnode->isBinary = from->isBinary;
1784 newnode->hasAggs = from->hasAggs;
1785 newnode->hasSubLinks = from->hasSubLinks;
1786 newnode->originalQuery = from->originalQuery;
1788 Node_Copy(from, newnode, rtable);
1789 Node_Copy(from, newnode, jointree);
1791 newnode->rowMarks = listCopy(from->rowMarks);
1793 Node_Copy(from, newnode, targetList);
1795 Node_Copy(from, newnode, groupClause);
1796 Node_Copy(from, newnode, havingQual);
1797 Node_Copy(from, newnode, distinctClause);
1798 Node_Copy(from, newnode, sortClause);
1800 Node_Copy(from, newnode, limitOffset);
1801 Node_Copy(from, newnode, limitCount);
1803 Node_Copy(from, newnode, setOperations);
1805 newnode->resultRelations = listCopy(from->resultRelations);
1808 * We do not copy the planner internal fields: base_rel_list,
1809 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. Not
1810 * entirely clear if this is right?
1817 _copyInsertStmt(InsertStmt *from)
1819 InsertStmt *newnode = makeNode(InsertStmt);
1821 Node_Copy(from, newnode, relation);
1822 Node_Copy(from, newnode, cols);
1823 Node_Copy(from, newnode, targetList);
1824 Node_Copy(from, newnode, selectStmt);
1830 _copyDeleteStmt(DeleteStmt *from)
1832 DeleteStmt *newnode = makeNode(DeleteStmt);
1834 Node_Copy(from, newnode, relation);
1835 Node_Copy(from, newnode, whereClause);
1841 _copyUpdateStmt(UpdateStmt *from)
1843 UpdateStmt *newnode = makeNode(UpdateStmt);
1845 Node_Copy(from, newnode, relation);
1846 Node_Copy(from, newnode, targetList);
1847 Node_Copy(from, newnode, whereClause);
1848 Node_Copy(from, newnode, fromClause);
1854 _copySelectStmt(SelectStmt *from)
1856 SelectStmt *newnode = makeNode(SelectStmt);
1858 Node_Copy(from, newnode, distinctClause);
1859 Node_Copy(from, newnode, into);
1860 Node_Copy(from, newnode, intoColNames);
1861 Node_Copy(from, newnode, targetList);
1862 Node_Copy(from, newnode, fromClause);
1863 Node_Copy(from, newnode, whereClause);
1864 Node_Copy(from, newnode, groupClause);
1865 Node_Copy(from, newnode, havingClause);
1866 Node_Copy(from, newnode, sortClause);
1867 if (from->portalname)
1868 newnode->portalname = pstrdup(from->portalname);
1869 newnode->binary = from->binary;
1870 Node_Copy(from, newnode, limitOffset);
1871 Node_Copy(from, newnode, limitCount);
1872 Node_Copy(from, newnode, forUpdate);
1873 newnode->op = from->op;
1874 newnode->all = from->all;
1875 Node_Copy(from, newnode, larg);
1876 Node_Copy(from, newnode, rarg);
1881 static SetOperationStmt *
1882 _copySetOperationStmt(SetOperationStmt *from)
1884 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1886 newnode->op = from->op;
1887 newnode->all = from->all;
1888 Node_Copy(from, newnode, larg);
1889 Node_Copy(from, newnode, rarg);
1890 newnode->colTypes = listCopy(from->colTypes);
1895 static AlterTableStmt *
1896 _copyAlterTableStmt(AlterTableStmt *from)
1898 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1900 newnode->subtype = from->subtype;
1901 Node_Copy(from, newnode, relation);
1903 newnode->name = pstrdup(from->name);
1904 Node_Copy(from, newnode, def);
1905 newnode->behavior = from->behavior;
1911 _copyGrantStmt(GrantStmt *from)
1913 GrantStmt *newnode = makeNode(GrantStmt);
1915 newnode->is_grant = from->is_grant;
1916 newnode->objtype = from->objtype;
1917 Node_Copy(from, newnode, objects);
1918 newnode->privileges = listCopy(from->privileges);
1919 Node_Copy(from, newnode, grantees);
1924 static PrivGrantee *
1925 _copyPrivGrantee(PrivGrantee *from)
1927 PrivGrantee *newnode = makeNode(PrivGrantee);
1930 newnode->username = pstrdup(from->username);
1931 if (from->groupname)
1932 newnode->groupname = pstrdup(from->groupname);
1937 static FuncWithArgs *
1938 _copyFuncWithArgs(FuncWithArgs *from)
1940 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1943 newnode->funcname = pstrdup(from->funcname);
1944 Node_Copy(from, newnode, funcargs);
1949 static ClosePortalStmt *
1950 _copyClosePortalStmt(ClosePortalStmt *from)
1952 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1954 if (from->portalname)
1955 newnode->portalname = pstrdup(from->portalname);
1960 static ClusterStmt *
1961 _copyClusterStmt(ClusterStmt *from)
1963 ClusterStmt *newnode = makeNode(ClusterStmt);
1965 Node_Copy(from, newnode, relation);
1966 if (from->indexname)
1967 newnode->indexname = pstrdup(from->indexname);
1973 _copyCopyStmt(CopyStmt *from)
1975 CopyStmt *newnode = makeNode(CopyStmt);
1977 newnode->binary = from->binary;
1978 Node_Copy(from, newnode, relation);
1979 newnode->oids = from->oids;
1980 newnode->direction = from->direction;
1982 newnode->filename = pstrdup(from->filename);
1983 if (from->delimiter)
1984 newnode->delimiter = pstrdup(from->delimiter);
1985 if (from->null_print)
1986 newnode->null_print = pstrdup(from->null_print);
1992 _copyCreateStmt(CreateStmt *from)
1994 CreateStmt *newnode = makeNode(CreateStmt);
1996 Node_Copy(from, newnode, relation);
1997 Node_Copy(from, newnode, tableElts);
1998 Node_Copy(from, newnode, inhRelations);
1999 Node_Copy(from, newnode, constraints);
2000 newnode->hasoids = from->hasoids;
2006 _copyDefineStmt(DefineStmt *from)
2008 DefineStmt *newnode = makeNode(DefineStmt);
2010 newnode->defType = from->defType;
2011 newnode->defname = pstrdup(from->defname);
2012 Node_Copy(from, newnode, definition);
2018 _copyDropStmt(DropStmt *from)
2020 DropStmt *newnode = makeNode(DropStmt);
2022 Node_Copy(from, newnode, objects);
2023 newnode->removeType = from->removeType;
2024 newnode->behavior = from->behavior;
2029 static TruncateStmt *
2030 _copyTruncateStmt(TruncateStmt *from)
2032 TruncateStmt *newnode = makeNode(TruncateStmt);
2034 Node_Copy(from, newnode, relation);
2039 static CommentStmt *
2040 _copyCommentStmt(CommentStmt *from)
2042 CommentStmt *newnode = makeNode(CommentStmt);
2044 newnode->objtype = from->objtype;
2045 if (from->objschema)
2046 newnode->objschema = pstrdup(from->objschema);
2047 newnode->objname = pstrdup(from->objname);
2048 if (from->objproperty)
2049 newnode->objproperty = pstrdup(from->objproperty);
2050 Node_Copy(from, newnode, objlist);
2051 newnode->comment = pstrdup(from->comment);
2057 _copyFetchStmt(FetchStmt *from)
2059 FetchStmt *newnode = makeNode(FetchStmt);
2061 newnode->direction = from->direction;
2062 newnode->howMany = from->howMany;
2063 newnode->portalname = pstrdup(from->portalname);
2064 newnode->ismove = from->ismove;
2070 _copyIndexStmt(IndexStmt *from)
2072 IndexStmt *newnode = makeNode(IndexStmt);
2074 newnode->idxname = pstrdup(from->idxname);
2075 Node_Copy(from, newnode, relation);
2076 newnode->accessMethod = pstrdup(from->accessMethod);
2077 Node_Copy(from, newnode, indexParams);
2078 Node_Copy(from, newnode, whereClause);
2079 Node_Copy(from, newnode, rangetable);
2080 newnode->unique = from->unique;
2081 newnode->primary = from->primary;
2086 static ProcedureStmt *
2087 _copyProcedureStmt(ProcedureStmt *from)
2089 ProcedureStmt *newnode = makeNode(ProcedureStmt);
2091 newnode->replace = from->replace;
2092 newnode->funcname = pstrdup(from->funcname);
2093 Node_Copy(from, newnode, argTypes);
2094 Node_Copy(from, newnode, returnType);
2095 Node_Copy(from, newnode, withClause);
2096 Node_Copy(from, newnode, as);
2097 newnode->language = pstrdup(from->language);
2102 static RemoveAggrStmt *
2103 _copyRemoveAggrStmt(RemoveAggrStmt *from)
2105 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
2107 newnode->aggname = pstrdup(from->aggname);
2108 Node_Copy(from, newnode, aggtype);
2113 static RemoveFuncStmt *
2114 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2116 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2118 newnode->funcname = pstrdup(from->funcname);
2119 Node_Copy(from, newnode, args);
2124 static RemoveOperStmt *
2125 _copyRemoveOperStmt(RemoveOperStmt *from)
2127 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2129 newnode->opname = pstrdup(from->opname);
2130 Node_Copy(from, newnode, args);
2136 _copyRenameStmt(RenameStmt *from)
2138 RenameStmt *newnode = makeNode(RenameStmt);
2140 Node_Copy(from, newnode, relation);
2142 newnode->column = pstrdup(from->column);
2144 newnode->newname = pstrdup(from->newname);
2150 _copyRuleStmt(RuleStmt *from)
2152 RuleStmt *newnode = makeNode(RuleStmt);
2154 Node_Copy(from, newnode, relation);
2155 newnode->rulename = pstrdup(from->rulename);
2156 Node_Copy(from, newnode, whereClause);
2157 newnode->event = from->event;
2158 newnode->instead = from->instead;
2159 Node_Copy(from, newnode, actions);
2165 _copyNotifyStmt(NotifyStmt *from)
2167 NotifyStmt *newnode = makeNode(NotifyStmt);
2169 Node_Copy(from, newnode, relation);
2175 _copyListenStmt(ListenStmt *from)
2177 ListenStmt *newnode = makeNode(ListenStmt);
2179 Node_Copy(from, newnode, relation);
2184 static UnlistenStmt *
2185 _copyUnlistenStmt(UnlistenStmt *from)
2187 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2189 Node_Copy(from, newnode, relation);
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);
2209 Node_Copy(from, newnode, view);
2210 Node_Copy(from, newnode, aliases);
2211 Node_Copy(from, newnode, query);
2217 _copyLoadStmt(LoadStmt *from)
2219 LoadStmt *newnode = makeNode(LoadStmt);
2222 newnode->filename = pstrdup(from->filename);
2227 static CreateDomainStmt *
2228 _copyCreateDomainStmt(CreateDomainStmt *from)
2230 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2232 if (from->domainname)
2233 newnode->domainname = pstrdup(from->domainname);
2234 Node_Copy(from, newnode, typename);
2235 Node_Copy(from, newnode, constraints);
2240 static CreatedbStmt *
2241 _copyCreatedbStmt(CreatedbStmt *from)
2243 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2246 newnode->dbname = pstrdup(from->dbname);
2248 newnode->dbowner = pstrdup(from->dbowner);
2250 newnode->dbpath = pstrdup(from->dbpath);
2251 if (from->dbtemplate)
2252 newnode->dbtemplate = pstrdup(from->dbtemplate);
2253 newnode->encoding = from->encoding;
2258 static AlterDatabaseSetStmt *
2259 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2261 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2264 newnode->dbname = pstrdup(from->dbname);
2266 newnode->variable = pstrdup(from->variable);
2267 Node_Copy(from, newnode, value);
2273 _copyDropdbStmt(DropdbStmt *from)
2275 DropdbStmt *newnode = makeNode(DropdbStmt);
2278 newnode->dbname = pstrdup(from->dbname);
2284 _copyVacuumStmt(VacuumStmt *from)
2286 VacuumStmt *newnode = makeNode(VacuumStmt);
2288 newnode->vacuum = from->vacuum;
2289 newnode->full = from->full;
2290 newnode->analyze = from->analyze;
2291 newnode->freeze = from->freeze;
2292 newnode->verbose = from->verbose;
2293 Node_Copy(from, newnode, relation);
2294 Node_Copy(from, newnode, va_cols);
2299 static ExplainStmt *
2300 _copyExplainStmt(ExplainStmt *from)
2302 ExplainStmt *newnode = makeNode(ExplainStmt);
2304 Node_Copy(from, newnode, query);
2305 newnode->verbose = from->verbose;
2306 newnode->analyze = from->analyze;
2311 static CreateSeqStmt *
2312 _copyCreateSeqStmt(CreateSeqStmt *from)
2314 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2316 Node_Copy(from, newnode, sequence);
2317 Node_Copy(from, newnode, options);
2322 static VariableSetStmt *
2323 _copyVariableSetStmt(VariableSetStmt *from)
2325 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2328 newnode->name = pstrdup(from->name);
2329 Node_Copy(from, newnode, args);
2334 static VariableShowStmt *
2335 _copyVariableShowStmt(VariableShowStmt *from)
2337 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2340 newnode->name = pstrdup(from->name);
2345 static VariableResetStmt *
2346 _copyVariableResetStmt(VariableResetStmt *from)
2348 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2351 newnode->name = pstrdup(from->name);
2356 static CreateTrigStmt *
2357 _copyCreateTrigStmt(CreateTrigStmt *from)
2359 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2362 newnode->trigname = pstrdup(from->trigname);
2363 Node_Copy(from, newnode, relation);
2365 newnode->funcname = pstrdup(from->funcname);
2366 Node_Copy(from, newnode, args);
2367 newnode->before = from->before;
2368 newnode->row = from->row;
2369 memcpy(newnode->actions, from->actions, sizeof(from->actions));
2371 newnode->lang = pstrdup(from->lang);
2373 newnode->text = pstrdup(from->text);
2375 Node_Copy(from, newnode, attr);
2377 newnode->when = pstrdup(from->when);
2378 newnode->isconstraint = from->isconstraint;
2379 newnode->deferrable = from->deferrable;
2380 newnode->initdeferred = from->initdeferred;
2381 Node_Copy(from, newnode, constrrel);
2386 static DropTrigStmt *
2387 _copyDropTrigStmt(DropTrigStmt *from)
2389 DropTrigStmt *newnode = makeNode(DropTrigStmt);
2392 newnode->trigname = pstrdup(from->trigname);
2393 Node_Copy(from, newnode, relation);
2398 static CreatePLangStmt *
2399 _copyCreatePLangStmt(CreatePLangStmt *from)
2401 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2404 newnode->plname = pstrdup(from->plname);
2405 if (from->plhandler)
2406 newnode->plhandler = pstrdup(from->plhandler);
2407 if (from->plcompiler)
2408 newnode->plcompiler = pstrdup(from->plcompiler);
2409 newnode->pltrusted = from->pltrusted;
2414 static DropPLangStmt *
2415 _copyDropPLangStmt(DropPLangStmt *from)
2417 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2420 newnode->plname = pstrdup(from->plname);
2425 static CreateUserStmt *
2426 _copyCreateUserStmt(CreateUserStmt *from)
2428 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2431 newnode->user = pstrdup(from->user);
2432 Node_Copy(from, newnode, options);
2437 static AlterUserStmt *
2438 _copyAlterUserStmt(AlterUserStmt *from)
2440 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2443 newnode->user = pstrdup(from->user);
2444 Node_Copy(from, newnode, options);
2449 static AlterUserSetStmt *
2450 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2452 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2455 newnode->user = pstrdup(from->user);
2457 newnode->user = pstrdup(from->variable);
2458 Node_Copy(from, newnode, value);
2463 static DropUserStmt *
2464 _copyDropUserStmt(DropUserStmt *from)
2466 DropUserStmt *newnode = makeNode(DropUserStmt);
2468 Node_Copy(from, newnode, users);
2474 _copyLockStmt(LockStmt *from)
2476 LockStmt *newnode = makeNode(LockStmt);
2478 Node_Copy(from, newnode, relations);
2480 newnode->mode = from->mode;
2485 static ConstraintsSetStmt *
2486 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2488 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2490 Node_Copy(from, newnode, constraints);
2491 newnode->deferred = from->deferred;
2496 static CreateGroupStmt *
2497 _copyCreateGroupStmt(CreateGroupStmt *from)
2499 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2502 newnode->name = pstrdup(from->name);
2503 Node_Copy(from, newnode, options);
2508 static AlterGroupStmt *
2509 _copyAlterGroupStmt(AlterGroupStmt *from)
2511 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2514 newnode->name = pstrdup(from->name);
2515 newnode->action = from->action;
2516 Node_Copy(from, newnode, listUsers);
2521 static DropGroupStmt *
2522 _copyDropGroupStmt(DropGroupStmt *from)
2524 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2527 newnode->name = pstrdup(from->name);
2532 static ReindexStmt *
2533 _copyReindexStmt(ReindexStmt *from)
2535 ReindexStmt *newnode = makeNode(ReindexStmt);
2537 newnode->reindexType = from->reindexType;
2538 Node_Copy(from, newnode, relation);
2540 newnode->name = pstrdup(from->name);
2541 newnode->force = from->force;
2542 newnode->all = from->all;
2547 static CreateSchemaStmt *
2548 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2550 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2552 newnode->schemaname = pstrdup(from->schemaname);
2554 newnode->authid = pstrdup(from->authid);
2555 Node_Copy(from, newnode, schemaElts);
2561 /* ****************************************************************
2562 * pg_list.h copy functions
2563 * ****************************************************************
2567 _copyValue(Value *from)
2569 Value *newnode = makeNode(Value);
2571 newnode->type = from->type;
2575 newnode->val.ival = from->val.ival;
2580 newnode->val.str = pstrdup(from->val.str);
2589 * copyObject returns a copy of the node or list. If it is a list, it
2590 * recursively copies its items.
2594 copyObject(void *from)
2601 switch (nodeTag(from))
2607 retval = _copyPlan(from);
2610 retval = _copyResult(from);
2613 retval = _copyAppend(from);
2616 retval = _copyScan(from);
2619 retval = _copySeqScan(from);
2622 retval = _copyIndexScan(from);
2625 retval = _copyTidScan(from);
2627 case T_SubqueryScan:
2628 retval = _copySubqueryScan(from);
2631 retval = _copyJoin(from);
2634 retval = _copyNestLoop(from);
2637 retval = _copyMergeJoin(from);
2640 retval = _copyHashJoin(from);
2643 retval = _copyMaterial(from);
2646 retval = _copySort(from);
2649 retval = _copyGroup(from);
2652 retval = _copyAgg(from);
2655 retval = _copyUnique(from);
2658 retval = _copySetOp(from);
2661 retval = _copyLimit(from);
2664 retval = _copyHash(from);
2667 retval = _copySubPlan(from);
2674 retval = _copyResdom(from);
2677 retval = _copyFjoin(from);
2680 retval = _copyExpr(from);
2683 retval = _copyVar(from);
2686 retval = _copyOper(from);
2689 retval = _copyConst(from);
2692 retval = _copyParam(from);
2695 retval = _copyAggref(from);
2698 retval = _copySubLink(from);
2701 retval = _copyFunc(from);
2704 retval = _copyArrayRef(from);
2707 retval = _copyIter(from);
2710 retval = _copyFieldSelect(from);
2713 retval = _copyRelabelType(from);
2716 retval = _copyRangeTblRef(from);
2719 retval = _copyFromExpr(from);
2722 retval = _copyJoinExpr(from);
2729 retval = _copyRelOptInfo(from);
2732 retval = _copyPath(from);
2735 retval = _copyIndexPath(from);
2738 retval = _copyTidPath(from);
2741 retval = _copyAppendPath(from);
2744 retval = _copyNestPath(from);
2747 retval = _copyMergePath(from);
2750 retval = _copyHashPath(from);
2753 retval = _copyPathKeyItem(from);
2755 case T_RestrictInfo:
2756 retval = _copyRestrictInfo(from);
2759 retval = _copyJoinInfo(from);
2762 retval = _copyStream(from);
2764 case T_IndexOptInfo:
2765 retval = _copyIndexOptInfo(from);
2775 retval = _copyValue(from);
2783 /* rather ugly coding for speed... */
2784 /* Note the input list cannot be NIL if we got here. */
2785 nl = makeList1(copyObject(lfirst(list)));
2788 foreach(l, lnext(list))
2790 lnext(nl) = makeList1(copyObject(lfirst(l)));
2800 retval = _copyQuery(from);
2803 retval = _copyInsertStmt(from);
2806 retval = _copyDeleteStmt(from);
2809 retval = _copyUpdateStmt(from);
2812 retval = _copySelectStmt(from);
2814 case T_SetOperationStmt:
2815 retval = _copySetOperationStmt(from);
2817 case T_AlterTableStmt:
2818 retval = _copyAlterTableStmt(from);
2821 retval = _copyGrantStmt(from);
2823 case T_ClosePortalStmt:
2824 retval = _copyClosePortalStmt(from);
2827 retval = _copyClusterStmt(from);
2830 retval = _copyCopyStmt(from);
2833 retval = _copyCreateStmt(from);
2836 retval = _copyDefineStmt(from);
2839 retval = _copyDropStmt(from);
2841 case T_TruncateStmt:
2842 retval = _copyTruncateStmt(from);
2845 retval = _copyCommentStmt(from);
2848 retval = _copyFetchStmt(from);
2851 retval = _copyIndexStmt(from);
2853 case T_ProcedureStmt:
2854 retval = _copyProcedureStmt(from);
2856 case T_RemoveAggrStmt:
2857 retval = _copyRemoveAggrStmt(from);
2859 case T_RemoveFuncStmt:
2860 retval = _copyRemoveFuncStmt(from);
2862 case T_RemoveOperStmt:
2863 retval = _copyRemoveOperStmt(from);
2866 retval = _copyRenameStmt(from);
2869 retval = _copyRuleStmt(from);
2872 retval = _copyNotifyStmt(from);
2875 retval = _copyListenStmt(from);
2877 case T_UnlistenStmt:
2878 retval = _copyUnlistenStmt(from);
2880 case T_TransactionStmt:
2881 retval = _copyTransactionStmt(from);
2884 retval = _copyViewStmt(from);
2887 retval = _copyLoadStmt(from);
2889 case T_CreateDomainStmt:
2890 retval = _copyCreateDomainStmt(from);
2892 case T_CreatedbStmt:
2893 retval = _copyCreatedbStmt(from);
2895 case T_AlterDatabaseSetStmt:
2896 retval = _copyAlterDatabaseSetStmt(from);
2899 retval = _copyDropdbStmt(from);
2902 retval = _copyVacuumStmt(from);
2905 retval = _copyExplainStmt(from);
2907 case T_CreateSeqStmt:
2908 retval = _copyCreateSeqStmt(from);
2910 case T_VariableSetStmt:
2911 retval = _copyVariableSetStmt(from);
2913 case T_VariableShowStmt:
2914 retval = _copyVariableShowStmt(from);
2916 case T_VariableResetStmt:
2917 retval = _copyVariableResetStmt(from);
2919 case T_CreateTrigStmt:
2920 retval = _copyCreateTrigStmt(from);
2922 case T_DropTrigStmt:
2923 retval = _copyDropTrigStmt(from);
2925 case T_CreatePLangStmt:
2926 retval = _copyCreatePLangStmt(from);
2928 case T_DropPLangStmt:
2929 retval = _copyDropPLangStmt(from);
2931 case T_CreateUserStmt:
2932 retval = _copyCreateUserStmt(from);
2934 case T_AlterUserStmt:
2935 retval = _copyAlterUserStmt(from);
2937 case T_AlterUserSetStmt:
2938 retval = _copyAlterUserSetStmt(from);
2940 case T_DropUserStmt:
2941 retval = _copyDropUserStmt(from);
2944 retval = _copyLockStmt(from);
2946 case T_ConstraintsSetStmt:
2947 retval = _copyConstraintsSetStmt(from);
2949 case T_CreateGroupStmt:
2950 retval = _copyCreateGroupStmt(from);
2952 case T_AlterGroupStmt:
2953 retval = _copyAlterGroupStmt(from);
2955 case T_DropGroupStmt:
2956 retval = _copyDropGroupStmt(from);
2959 retval = _copyReindexStmt(from);
2961 case T_CheckPointStmt:
2962 retval = (void *) makeNode(CheckPointStmt);
2964 case T_CreateSchemaStmt:
2965 retval = _copyCreateSchemaStmt(from);
2969 retval = _copyAExpr(from);
2972 retval = _copyColumnRef(from);
2975 retval = _copyParamRef(from);
2978 retval = _copyAConst(from);
2981 retval = _copyIdent(from);
2984 retval = _copyFuncCall(from);
2987 retval = _copyAIndices(from);
2989 case T_ExprFieldSelect:
2990 retval = _copyExprFieldSelect(from);
2993 retval = _copyResTarget(from);
2996 retval = _copyTypeCast(from);
2999 retval = _copySortGroupBy(from);
3002 retval = _copyAlias(from);
3005 retval = _copyRangeVar(from);
3007 case T_RangeSubselect:
3008 retval = _copyRangeSubselect(from);
3011 retval = _copyTypeName(from);
3014 retval = _copyIndexElem(from);
3017 retval = _copyColumnDef(from);
3020 retval = _copyConstraint(from);
3023 retval = _copyDefElem(from);
3026 retval = _copyTargetEntry(from);
3028 case T_RangeTblEntry:
3029 retval = _copyRangeTblEntry(from);
3032 retval = _copySortClause(from);
3035 retval = _copyGroupClause(from);
3038 retval = _copyCaseExpr(from);
3041 retval = _copyCaseWhen(from);
3044 retval = _copyNullTest(from);
3047 retval = _copyBooleanTest(from);
3049 case T_FkConstraint:
3050 retval = _copyFkConstraint(from);
3053 retval = _copyPrivGrantee(from);
3055 case T_FuncWithArgs:
3056 retval = _copyFuncWithArgs(from);
3060 elog(ERROR, "copyObject: don't know how to copy node type %d",
3062 retval = from; /* keep compiler quiet */