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.175 2002/04/05 11:56:48 momjian 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);
1640 Node_Copy(from, newnode, names);
1641 newnode->typeid = from->typeid;
1642 newnode->timezone = from->timezone;
1643 newnode->setof = from->setof;
1644 newnode->pct_type = from->pct_type;
1645 newnode->typmod = from->typmod;
1646 Node_Copy(from, newnode, arrayBounds);
1651 static SortGroupBy *
1652 _copySortGroupBy(SortGroupBy *from)
1654 SortGroupBy *newnode = makeNode(SortGroupBy);
1657 newnode->useOp = pstrdup(from->useOp);
1658 Node_Copy(from, newnode, node);
1664 _copyAlias(Alias *from)
1666 Alias *newnode = makeNode(Alias);
1668 if (from->aliasname)
1669 newnode->aliasname = pstrdup(from->aliasname);
1670 Node_Copy(from, newnode, colnames);
1676 _copyRangeVar(RangeVar *from)
1678 RangeVar *newnode = makeNode(RangeVar);
1680 if (from->catalogname)
1681 newnode->catalogname = pstrdup(from->catalogname);
1682 if (from->schemaname)
1683 newnode->schemaname = pstrdup(from->schemaname);
1685 newnode->relname = pstrdup(from->relname);
1686 newnode->inhOpt = from->inhOpt;
1687 newnode->istemp = from->istemp;
1688 Node_Copy(from, newnode, alias);
1693 static RangeSubselect *
1694 _copyRangeSubselect(RangeSubselect *from)
1696 RangeSubselect *newnode = makeNode(RangeSubselect);
1698 Node_Copy(from, newnode, subquery);
1699 Node_Copy(from, newnode, alias);
1705 _copyTypeCast(TypeCast *from)
1707 TypeCast *newnode = makeNode(TypeCast);
1709 Node_Copy(from, newnode, arg);
1710 Node_Copy(from, newnode, typename);
1716 _copyIndexElem(IndexElem *from)
1718 IndexElem *newnode = makeNode(IndexElem);
1721 newnode->name = pstrdup(from->name);
1722 Node_Copy(from, newnode, args);
1724 newnode->class = pstrdup(from->class);
1730 _copyColumnDef(ColumnDef *from)
1732 ColumnDef *newnode = makeNode(ColumnDef);
1735 newnode->colname = pstrdup(from->colname);
1736 Node_Copy(from, newnode, typename);
1737 newnode->is_not_null = from->is_not_null;
1738 Node_Copy(from, newnode, raw_default);
1739 if (from->cooked_default)
1740 newnode->cooked_default = pstrdup(from->cooked_default);
1741 Node_Copy(from, newnode, constraints);
1747 _copyConstraint(Constraint *from)
1749 Constraint *newnode = makeNode(Constraint);
1751 newnode->contype = from->contype;
1753 newnode->name = pstrdup(from->name);
1754 Node_Copy(from, newnode, raw_expr);
1755 if (from->cooked_expr)
1756 newnode->cooked_expr = pstrdup(from->cooked_expr);
1757 Node_Copy(from, newnode, keys);
1763 _copyDefElem(DefElem *from)
1765 DefElem *newnode = makeNode(DefElem);
1768 newnode->defname = pstrdup(from->defname);
1769 Node_Copy(from, newnode, arg);
1775 _copyQuery(Query *from)
1777 Query *newnode = makeNode(Query);
1779 newnode->commandType = from->commandType;
1780 Node_Copy(from, newnode, utilityStmt);
1781 newnode->resultRelation = from->resultRelation;
1782 Node_Copy(from, newnode, into);
1783 newnode->isPortal = from->isPortal;
1784 newnode->isBinary = from->isBinary;
1785 newnode->hasAggs = from->hasAggs;
1786 newnode->hasSubLinks = from->hasSubLinks;
1787 newnode->originalQuery = from->originalQuery;
1789 Node_Copy(from, newnode, rtable);
1790 Node_Copy(from, newnode, jointree);
1792 newnode->rowMarks = listCopy(from->rowMarks);
1794 Node_Copy(from, newnode, targetList);
1796 Node_Copy(from, newnode, groupClause);
1797 Node_Copy(from, newnode, havingQual);
1798 Node_Copy(from, newnode, distinctClause);
1799 Node_Copy(from, newnode, sortClause);
1801 Node_Copy(from, newnode, limitOffset);
1802 Node_Copy(from, newnode, limitCount);
1804 Node_Copy(from, newnode, setOperations);
1806 newnode->resultRelations = listCopy(from->resultRelations);
1809 * We do not copy the planner internal fields: base_rel_list,
1810 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. Not
1811 * entirely clear if this is right?
1818 _copyInsertStmt(InsertStmt *from)
1820 InsertStmt *newnode = makeNode(InsertStmt);
1822 Node_Copy(from, newnode, relation);
1823 Node_Copy(from, newnode, cols);
1824 Node_Copy(from, newnode, targetList);
1825 Node_Copy(from, newnode, selectStmt);
1831 _copyDeleteStmt(DeleteStmt *from)
1833 DeleteStmt *newnode = makeNode(DeleteStmt);
1835 Node_Copy(from, newnode, relation);
1836 Node_Copy(from, newnode, whereClause);
1842 _copyUpdateStmt(UpdateStmt *from)
1844 UpdateStmt *newnode = makeNode(UpdateStmt);
1846 Node_Copy(from, newnode, relation);
1847 Node_Copy(from, newnode, targetList);
1848 Node_Copy(from, newnode, whereClause);
1849 Node_Copy(from, newnode, fromClause);
1855 _copySelectStmt(SelectStmt *from)
1857 SelectStmt *newnode = makeNode(SelectStmt);
1859 Node_Copy(from, newnode, distinctClause);
1860 Node_Copy(from, newnode, into);
1861 Node_Copy(from, newnode, intoColNames);
1862 Node_Copy(from, newnode, targetList);
1863 Node_Copy(from, newnode, fromClause);
1864 Node_Copy(from, newnode, whereClause);
1865 Node_Copy(from, newnode, groupClause);
1866 Node_Copy(from, newnode, havingClause);
1867 Node_Copy(from, newnode, sortClause);
1868 if (from->portalname)
1869 newnode->portalname = pstrdup(from->portalname);
1870 newnode->binary = from->binary;
1871 Node_Copy(from, newnode, limitOffset);
1872 Node_Copy(from, newnode, limitCount);
1873 Node_Copy(from, newnode, forUpdate);
1874 newnode->op = from->op;
1875 newnode->all = from->all;
1876 Node_Copy(from, newnode, larg);
1877 Node_Copy(from, newnode, rarg);
1882 static SetOperationStmt *
1883 _copySetOperationStmt(SetOperationStmt *from)
1885 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1887 newnode->op = from->op;
1888 newnode->all = from->all;
1889 Node_Copy(from, newnode, larg);
1890 Node_Copy(from, newnode, rarg);
1891 newnode->colTypes = listCopy(from->colTypes);
1896 static AlterTableStmt *
1897 _copyAlterTableStmt(AlterTableStmt *from)
1899 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1901 newnode->subtype = from->subtype;
1902 Node_Copy(from, newnode, relation);
1904 newnode->name = pstrdup(from->name);
1905 Node_Copy(from, newnode, def);
1906 newnode->behavior = from->behavior;
1912 _copyGrantStmt(GrantStmt *from)
1914 GrantStmt *newnode = makeNode(GrantStmt);
1916 newnode->is_grant = from->is_grant;
1917 newnode->objtype = from->objtype;
1918 Node_Copy(from, newnode, objects);
1919 newnode->privileges = listCopy(from->privileges);
1920 Node_Copy(from, newnode, grantees);
1925 static PrivGrantee *
1926 _copyPrivGrantee(PrivGrantee *from)
1928 PrivGrantee *newnode = makeNode(PrivGrantee);
1931 newnode->username = pstrdup(from->username);
1932 if (from->groupname)
1933 newnode->groupname = pstrdup(from->groupname);
1938 static FuncWithArgs *
1939 _copyFuncWithArgs(FuncWithArgs *from)
1941 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1944 newnode->funcname = pstrdup(from->funcname);
1945 Node_Copy(from, newnode, funcargs);
1950 static InsertDefault *
1951 _copyInsertDefault(InsertDefault *from)
1953 InsertDefault *newnode = makeNode(InsertDefault);
1959 static ClosePortalStmt *
1960 _copyClosePortalStmt(ClosePortalStmt *from)
1962 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1964 if (from->portalname)
1965 newnode->portalname = pstrdup(from->portalname);
1970 static ClusterStmt *
1971 _copyClusterStmt(ClusterStmt *from)
1973 ClusterStmt *newnode = makeNode(ClusterStmt);
1975 Node_Copy(from, newnode, relation);
1976 if (from->indexname)
1977 newnode->indexname = pstrdup(from->indexname);
1983 _copyCopyStmt(CopyStmt *from)
1985 CopyStmt *newnode = makeNode(CopyStmt);
1987 newnode->binary = from->binary;
1988 Node_Copy(from, newnode, relation);
1989 newnode->oids = from->oids;
1990 newnode->direction = from->direction;
1992 newnode->filename = pstrdup(from->filename);
1993 if (from->delimiter)
1994 newnode->delimiter = pstrdup(from->delimiter);
1995 if (from->null_print)
1996 newnode->null_print = pstrdup(from->null_print);
2002 _copyCreateStmt(CreateStmt *from)
2004 CreateStmt *newnode = makeNode(CreateStmt);
2006 Node_Copy(from, newnode, relation);
2007 Node_Copy(from, newnode, tableElts);
2008 Node_Copy(from, newnode, inhRelations);
2009 Node_Copy(from, newnode, constraints);
2010 newnode->hasoids = from->hasoids;
2016 _copyDefineStmt(DefineStmt *from)
2018 DefineStmt *newnode = makeNode(DefineStmt);
2020 newnode->defType = from->defType;
2021 Node_Copy(from, newnode, defnames);
2022 Node_Copy(from, newnode, definition);
2028 _copyDropStmt(DropStmt *from)
2030 DropStmt *newnode = makeNode(DropStmt);
2032 Node_Copy(from, newnode, objects);
2033 newnode->removeType = from->removeType;
2034 newnode->behavior = from->behavior;
2039 static TruncateStmt *
2040 _copyTruncateStmt(TruncateStmt *from)
2042 TruncateStmt *newnode = makeNode(TruncateStmt);
2044 Node_Copy(from, newnode, relation);
2049 static CommentStmt *
2050 _copyCommentStmt(CommentStmt *from)
2052 CommentStmt *newnode = makeNode(CommentStmt);
2054 newnode->objtype = from->objtype;
2055 if (from->objschema)
2056 newnode->objschema = pstrdup(from->objschema);
2057 newnode->objname = pstrdup(from->objname);
2058 if (from->objproperty)
2059 newnode->objproperty = pstrdup(from->objproperty);
2060 Node_Copy(from, newnode, objlist);
2061 newnode->comment = pstrdup(from->comment);
2067 _copyFetchStmt(FetchStmt *from)
2069 FetchStmt *newnode = makeNode(FetchStmt);
2071 newnode->direction = from->direction;
2072 newnode->howMany = from->howMany;
2073 newnode->portalname = pstrdup(from->portalname);
2074 newnode->ismove = from->ismove;
2080 _copyIndexStmt(IndexStmt *from)
2082 IndexStmt *newnode = makeNode(IndexStmt);
2084 newnode->idxname = pstrdup(from->idxname);
2085 Node_Copy(from, newnode, relation);
2086 newnode->accessMethod = pstrdup(from->accessMethod);
2087 Node_Copy(from, newnode, indexParams);
2088 Node_Copy(from, newnode, whereClause);
2089 Node_Copy(from, newnode, rangetable);
2090 newnode->unique = from->unique;
2091 newnode->primary = from->primary;
2096 static ProcedureStmt *
2097 _copyProcedureStmt(ProcedureStmt *from)
2099 ProcedureStmt *newnode = makeNode(ProcedureStmt);
2101 newnode->replace = from->replace;
2102 Node_Copy(from, newnode, funcname);
2103 Node_Copy(from, newnode, argTypes);
2104 Node_Copy(from, newnode, returnType);
2105 Node_Copy(from, newnode, withClause);
2106 Node_Copy(from, newnode, as);
2107 newnode->language = pstrdup(from->language);
2112 static RemoveAggrStmt *
2113 _copyRemoveAggrStmt(RemoveAggrStmt *from)
2115 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
2117 newnode->aggname = pstrdup(from->aggname);
2118 Node_Copy(from, newnode, aggtype);
2123 static RemoveFuncStmt *
2124 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2126 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2128 newnode->funcname = pstrdup(from->funcname);
2129 Node_Copy(from, newnode, args);
2134 static RemoveOperStmt *
2135 _copyRemoveOperStmt(RemoveOperStmt *from)
2137 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2139 newnode->opname = pstrdup(from->opname);
2140 Node_Copy(from, newnode, args);
2146 _copyRenameStmt(RenameStmt *from)
2148 RenameStmt *newnode = makeNode(RenameStmt);
2150 Node_Copy(from, newnode, relation);
2152 newnode->column = pstrdup(from->column);
2154 newnode->newname = pstrdup(from->newname);
2160 _copyRuleStmt(RuleStmt *from)
2162 RuleStmt *newnode = makeNode(RuleStmt);
2164 Node_Copy(from, newnode, relation);
2165 newnode->rulename = pstrdup(from->rulename);
2166 Node_Copy(from, newnode, whereClause);
2167 newnode->event = from->event;
2168 newnode->instead = from->instead;
2169 Node_Copy(from, newnode, actions);
2175 _copyNotifyStmt(NotifyStmt *from)
2177 NotifyStmt *newnode = makeNode(NotifyStmt);
2179 Node_Copy(from, newnode, relation);
2185 _copyListenStmt(ListenStmt *from)
2187 ListenStmt *newnode = makeNode(ListenStmt);
2189 Node_Copy(from, newnode, relation);
2194 static UnlistenStmt *
2195 _copyUnlistenStmt(UnlistenStmt *from)
2197 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2199 Node_Copy(from, newnode, relation);
2204 static TransactionStmt *
2205 _copyTransactionStmt(TransactionStmt *from)
2207 TransactionStmt *newnode = makeNode(TransactionStmt);
2209 newnode->command = from->command;
2215 _copyViewStmt(ViewStmt *from)
2217 ViewStmt *newnode = makeNode(ViewStmt);
2219 Node_Copy(from, newnode, view);
2220 Node_Copy(from, newnode, aliases);
2221 Node_Copy(from, newnode, query);
2227 _copyLoadStmt(LoadStmt *from)
2229 LoadStmt *newnode = makeNode(LoadStmt);
2232 newnode->filename = pstrdup(from->filename);
2237 static CreateDomainStmt *
2238 _copyCreateDomainStmt(CreateDomainStmt *from)
2240 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2242 Node_Copy(from, newnode, domainname);
2243 Node_Copy(from, newnode, typename);
2244 Node_Copy(from, newnode, constraints);
2249 static CreatedbStmt *
2250 _copyCreatedbStmt(CreatedbStmt *from)
2252 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2255 newnode->dbname = pstrdup(from->dbname);
2257 newnode->dbowner = pstrdup(from->dbowner);
2259 newnode->dbpath = pstrdup(from->dbpath);
2260 if (from->dbtemplate)
2261 newnode->dbtemplate = pstrdup(from->dbtemplate);
2262 newnode->encoding = from->encoding;
2267 static AlterDatabaseSetStmt *
2268 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2270 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2273 newnode->dbname = pstrdup(from->dbname);
2275 newnode->variable = pstrdup(from->variable);
2276 Node_Copy(from, newnode, value);
2282 _copyDropdbStmt(DropdbStmt *from)
2284 DropdbStmt *newnode = makeNode(DropdbStmt);
2287 newnode->dbname = pstrdup(from->dbname);
2293 _copyVacuumStmt(VacuumStmt *from)
2295 VacuumStmt *newnode = makeNode(VacuumStmt);
2297 newnode->vacuum = from->vacuum;
2298 newnode->full = from->full;
2299 newnode->analyze = from->analyze;
2300 newnode->freeze = from->freeze;
2301 newnode->verbose = from->verbose;
2302 Node_Copy(from, newnode, relation);
2303 Node_Copy(from, newnode, va_cols);
2308 static ExplainStmt *
2309 _copyExplainStmt(ExplainStmt *from)
2311 ExplainStmt *newnode = makeNode(ExplainStmt);
2313 Node_Copy(from, newnode, query);
2314 newnode->verbose = from->verbose;
2315 newnode->analyze = from->analyze;
2320 static CreateSeqStmt *
2321 _copyCreateSeqStmt(CreateSeqStmt *from)
2323 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2325 Node_Copy(from, newnode, sequence);
2326 Node_Copy(from, newnode, options);
2331 static VariableSetStmt *
2332 _copyVariableSetStmt(VariableSetStmt *from)
2334 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2337 newnode->name = pstrdup(from->name);
2338 Node_Copy(from, newnode, args);
2343 static VariableShowStmt *
2344 _copyVariableShowStmt(VariableShowStmt *from)
2346 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2349 newnode->name = pstrdup(from->name);
2354 static VariableResetStmt *
2355 _copyVariableResetStmt(VariableResetStmt *from)
2357 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2360 newnode->name = pstrdup(from->name);
2365 static CreateTrigStmt *
2366 _copyCreateTrigStmt(CreateTrigStmt *from)
2368 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2371 newnode->trigname = pstrdup(from->trigname);
2372 Node_Copy(from, newnode, relation);
2374 newnode->funcname = pstrdup(from->funcname);
2375 Node_Copy(from, newnode, args);
2376 newnode->before = from->before;
2377 newnode->row = from->row;
2378 memcpy(newnode->actions, from->actions, sizeof(from->actions));
2380 newnode->lang = pstrdup(from->lang);
2382 newnode->text = pstrdup(from->text);
2384 Node_Copy(from, newnode, attr);
2386 newnode->when = pstrdup(from->when);
2387 newnode->isconstraint = from->isconstraint;
2388 newnode->deferrable = from->deferrable;
2389 newnode->initdeferred = from->initdeferred;
2390 Node_Copy(from, newnode, constrrel);
2395 static DropTrigStmt *
2396 _copyDropTrigStmt(DropTrigStmt *from)
2398 DropTrigStmt *newnode = makeNode(DropTrigStmt);
2401 newnode->trigname = pstrdup(from->trigname);
2402 Node_Copy(from, newnode, relation);
2407 static CreatePLangStmt *
2408 _copyCreatePLangStmt(CreatePLangStmt *from)
2410 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2413 newnode->plname = pstrdup(from->plname);
2414 if (from->plhandler)
2415 newnode->plhandler = pstrdup(from->plhandler);
2416 if (from->plcompiler)
2417 newnode->plcompiler = pstrdup(from->plcompiler);
2418 newnode->pltrusted = from->pltrusted;
2423 static DropPLangStmt *
2424 _copyDropPLangStmt(DropPLangStmt *from)
2426 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2429 newnode->plname = pstrdup(from->plname);
2434 static CreateUserStmt *
2435 _copyCreateUserStmt(CreateUserStmt *from)
2437 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2440 newnode->user = pstrdup(from->user);
2441 Node_Copy(from, newnode, options);
2446 static AlterUserStmt *
2447 _copyAlterUserStmt(AlterUserStmt *from)
2449 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2452 newnode->user = pstrdup(from->user);
2453 Node_Copy(from, newnode, options);
2458 static AlterUserSetStmt *
2459 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2461 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2464 newnode->user = pstrdup(from->user);
2466 newnode->user = pstrdup(from->variable);
2467 Node_Copy(from, newnode, value);
2472 static DropUserStmt *
2473 _copyDropUserStmt(DropUserStmt *from)
2475 DropUserStmt *newnode = makeNode(DropUserStmt);
2477 Node_Copy(from, newnode, users);
2483 _copyLockStmt(LockStmt *from)
2485 LockStmt *newnode = makeNode(LockStmt);
2487 Node_Copy(from, newnode, relations);
2489 newnode->mode = from->mode;
2494 static ConstraintsSetStmt *
2495 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2497 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2499 Node_Copy(from, newnode, constraints);
2500 newnode->deferred = from->deferred;
2505 static CreateGroupStmt *
2506 _copyCreateGroupStmt(CreateGroupStmt *from)
2508 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2511 newnode->name = pstrdup(from->name);
2512 Node_Copy(from, newnode, options);
2517 static AlterGroupStmt *
2518 _copyAlterGroupStmt(AlterGroupStmt *from)
2520 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2523 newnode->name = pstrdup(from->name);
2524 newnode->action = from->action;
2525 Node_Copy(from, newnode, listUsers);
2530 static DropGroupStmt *
2531 _copyDropGroupStmt(DropGroupStmt *from)
2533 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2536 newnode->name = pstrdup(from->name);
2541 static ReindexStmt *
2542 _copyReindexStmt(ReindexStmt *from)
2544 ReindexStmt *newnode = makeNode(ReindexStmt);
2546 newnode->reindexType = from->reindexType;
2547 Node_Copy(from, newnode, relation);
2549 newnode->name = pstrdup(from->name);
2550 newnode->force = from->force;
2551 newnode->all = from->all;
2556 static CreateSchemaStmt *
2557 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2559 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2561 newnode->schemaname = pstrdup(from->schemaname);
2563 newnode->authid = pstrdup(from->authid);
2564 Node_Copy(from, newnode, schemaElts);
2570 /* ****************************************************************
2571 * pg_list.h copy functions
2572 * ****************************************************************
2576 _copyValue(Value *from)
2578 Value *newnode = makeNode(Value);
2580 newnode->type = from->type;
2584 newnode->val.ival = from->val.ival;
2589 newnode->val.str = pstrdup(from->val.str);
2598 * copyObject returns a copy of the node or list. If it is a list, it
2599 * recursively copies its items.
2603 copyObject(void *from)
2610 switch (nodeTag(from))
2616 retval = _copyPlan(from);
2619 retval = _copyResult(from);
2622 retval = _copyAppend(from);
2625 retval = _copyScan(from);
2628 retval = _copySeqScan(from);
2631 retval = _copyIndexScan(from);
2634 retval = _copyTidScan(from);
2636 case T_SubqueryScan:
2637 retval = _copySubqueryScan(from);
2640 retval = _copyJoin(from);
2643 retval = _copyNestLoop(from);
2646 retval = _copyMergeJoin(from);
2649 retval = _copyHashJoin(from);
2652 retval = _copyMaterial(from);
2655 retval = _copySort(from);
2658 retval = _copyGroup(from);
2661 retval = _copyAgg(from);
2664 retval = _copyUnique(from);
2667 retval = _copySetOp(from);
2670 retval = _copyLimit(from);
2673 retval = _copyHash(from);
2676 retval = _copySubPlan(from);
2683 retval = _copyResdom(from);
2686 retval = _copyFjoin(from);
2689 retval = _copyExpr(from);
2692 retval = _copyVar(from);
2695 retval = _copyOper(from);
2698 retval = _copyConst(from);
2701 retval = _copyParam(from);
2704 retval = _copyAggref(from);
2707 retval = _copySubLink(from);
2710 retval = _copyFunc(from);
2713 retval = _copyArrayRef(from);
2716 retval = _copyIter(from);
2719 retval = _copyFieldSelect(from);
2722 retval = _copyRelabelType(from);
2725 retval = _copyRangeTblRef(from);
2728 retval = _copyFromExpr(from);
2731 retval = _copyJoinExpr(from);
2738 retval = _copyRelOptInfo(from);
2741 retval = _copyPath(from);
2744 retval = _copyIndexPath(from);
2747 retval = _copyTidPath(from);
2750 retval = _copyAppendPath(from);
2753 retval = _copyNestPath(from);
2756 retval = _copyMergePath(from);
2759 retval = _copyHashPath(from);
2762 retval = _copyPathKeyItem(from);
2764 case T_RestrictInfo:
2765 retval = _copyRestrictInfo(from);
2768 retval = _copyJoinInfo(from);
2771 retval = _copyStream(from);
2773 case T_IndexOptInfo:
2774 retval = _copyIndexOptInfo(from);
2784 retval = _copyValue(from);
2792 /* rather ugly coding for speed... */
2793 /* Note the input list cannot be NIL if we got here. */
2794 nl = makeList1(copyObject(lfirst(list)));
2797 foreach(l, lnext(list))
2799 lnext(nl) = makeList1(copyObject(lfirst(l)));
2809 retval = _copyQuery(from);
2812 retval = _copyInsertStmt(from);
2815 retval = _copyDeleteStmt(from);
2818 retval = _copyUpdateStmt(from);
2821 retval = _copySelectStmt(from);
2823 case T_SetOperationStmt:
2824 retval = _copySetOperationStmt(from);
2826 case T_AlterTableStmt:
2827 retval = _copyAlterTableStmt(from);
2830 retval = _copyGrantStmt(from);
2832 case T_ClosePortalStmt:
2833 retval = _copyClosePortalStmt(from);
2836 retval = _copyClusterStmt(from);
2839 retval = _copyCopyStmt(from);
2842 retval = _copyCreateStmt(from);
2845 retval = _copyDefineStmt(from);
2848 retval = _copyDropStmt(from);
2850 case T_TruncateStmt:
2851 retval = _copyTruncateStmt(from);
2854 retval = _copyCommentStmt(from);
2857 retval = _copyFetchStmt(from);
2860 retval = _copyIndexStmt(from);
2862 case T_ProcedureStmt:
2863 retval = _copyProcedureStmt(from);
2865 case T_RemoveAggrStmt:
2866 retval = _copyRemoveAggrStmt(from);
2868 case T_RemoveFuncStmt:
2869 retval = _copyRemoveFuncStmt(from);
2871 case T_RemoveOperStmt:
2872 retval = _copyRemoveOperStmt(from);
2875 retval = _copyRenameStmt(from);
2878 retval = _copyRuleStmt(from);
2881 retval = _copyNotifyStmt(from);
2884 retval = _copyListenStmt(from);
2886 case T_UnlistenStmt:
2887 retval = _copyUnlistenStmt(from);
2889 case T_TransactionStmt:
2890 retval = _copyTransactionStmt(from);
2893 retval = _copyViewStmt(from);
2896 retval = _copyLoadStmt(from);
2898 case T_CreateDomainStmt:
2899 retval = _copyCreateDomainStmt(from);
2901 case T_CreatedbStmt:
2902 retval = _copyCreatedbStmt(from);
2904 case T_AlterDatabaseSetStmt:
2905 retval = _copyAlterDatabaseSetStmt(from);
2908 retval = _copyDropdbStmt(from);
2911 retval = _copyVacuumStmt(from);
2914 retval = _copyExplainStmt(from);
2916 case T_CreateSeqStmt:
2917 retval = _copyCreateSeqStmt(from);
2919 case T_VariableSetStmt:
2920 retval = _copyVariableSetStmt(from);
2922 case T_VariableShowStmt:
2923 retval = _copyVariableShowStmt(from);
2925 case T_VariableResetStmt:
2926 retval = _copyVariableResetStmt(from);
2928 case T_CreateTrigStmt:
2929 retval = _copyCreateTrigStmt(from);
2931 case T_DropTrigStmt:
2932 retval = _copyDropTrigStmt(from);
2934 case T_CreatePLangStmt:
2935 retval = _copyCreatePLangStmt(from);
2937 case T_DropPLangStmt:
2938 retval = _copyDropPLangStmt(from);
2940 case T_CreateUserStmt:
2941 retval = _copyCreateUserStmt(from);
2943 case T_AlterUserStmt:
2944 retval = _copyAlterUserStmt(from);
2946 case T_AlterUserSetStmt:
2947 retval = _copyAlterUserSetStmt(from);
2949 case T_DropUserStmt:
2950 retval = _copyDropUserStmt(from);
2953 retval = _copyLockStmt(from);
2955 case T_ConstraintsSetStmt:
2956 retval = _copyConstraintsSetStmt(from);
2958 case T_CreateGroupStmt:
2959 retval = _copyCreateGroupStmt(from);
2961 case T_AlterGroupStmt:
2962 retval = _copyAlterGroupStmt(from);
2964 case T_DropGroupStmt:
2965 retval = _copyDropGroupStmt(from);
2968 retval = _copyReindexStmt(from);
2970 case T_CheckPointStmt:
2971 retval = (void *) makeNode(CheckPointStmt);
2973 case T_CreateSchemaStmt:
2974 retval = _copyCreateSchemaStmt(from);
2978 retval = _copyAExpr(from);
2981 retval = _copyColumnRef(from);
2984 retval = _copyParamRef(from);
2987 retval = _copyAConst(from);
2990 retval = _copyIdent(from);
2993 retval = _copyFuncCall(from);
2996 retval = _copyAIndices(from);
2998 case T_ExprFieldSelect:
2999 retval = _copyExprFieldSelect(from);
3002 retval = _copyResTarget(from);
3005 retval = _copyTypeCast(from);
3008 retval = _copySortGroupBy(from);
3011 retval = _copyAlias(from);
3014 retval = _copyRangeVar(from);
3016 case T_RangeSubselect:
3017 retval = _copyRangeSubselect(from);
3020 retval = _copyTypeName(from);
3023 retval = _copyIndexElem(from);
3026 retval = _copyColumnDef(from);
3029 retval = _copyConstraint(from);
3032 retval = _copyDefElem(from);
3035 retval = _copyTargetEntry(from);
3037 case T_RangeTblEntry:
3038 retval = _copyRangeTblEntry(from);
3041 retval = _copySortClause(from);
3044 retval = _copyGroupClause(from);
3047 retval = _copyCaseExpr(from);
3050 retval = _copyCaseWhen(from);
3053 retval = _copyNullTest(from);
3056 retval = _copyBooleanTest(from);
3058 case T_FkConstraint:
3059 retval = _copyFkConstraint(from);
3062 retval = _copyPrivGrantee(from);
3064 case T_FuncWithArgs:
3065 retval = _copyFuncWithArgs(from);
3067 case T_InsertDefault:
3068 retval = _copyInsertDefault(from);
3072 elog(ERROR, "copyObject: don't know how to copy node type %d",
3074 retval = from; /* keep compiler quiet */