1 /*-------------------------------------------------------------------------
4 * Copy functions for Postgres tree nodes.
6 * NOTE: a general convention when copying or comparing plan nodes is
7 * that we ignore the executor state subnode. We do not need to look
8 * at it because no current uses of copyObject() or equal() need to
9 * deal with already-executing plan trees. By leaving the state subnodes
10 * out, we avoid needing to write copy/compare routines for all the
11 * different executor state node types.
14 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
15 * Portions Copyright (c) 1994, Regents of the University of California
18 * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.120 2000/08/11 23:45:31 tgl Exp $
20 *-------------------------------------------------------------------------
25 #include "optimizer/clauses.h"
26 #include "optimizer/planmain.h"
27 #include "utils/acl.h"
32 * a macro to simplify calling of copyObject on the specified field
34 #define Node_Copy(from, newnode, field) \
35 ((newnode)->field = copyObject((from)->field))
40 * This copy function only copies the "cons-cells" of the list, not the
41 * pointed-to objects. (Use copyObject if you want a "deep" copy.)
43 * We also use this function for copying lists of integers, which is
44 * grotty but unlikely to break --- it could fail if sizeof(pointer)
45 * is less than sizeof(int), but I don't know any such machines...
47 * Note that copyObject will surely coredump if applied to a list
57 /* rather ugly coding for speed... */
61 newlist = nl = lcons(lfirst(list), NIL);
63 foreach(l, lnext(list))
65 lnext(nl) = lcons(lfirst(l), NIL);
71 /* ****************************************************************
72 * plannodes.h copy functions
73 * ****************************************************************
79 * This function copies the fields of the Plan node. It is used by
80 * all the copy functions for classes which inherit from Plan.
84 CopyPlanFields(Plan *from, Plan *newnode)
86 newnode->startup_cost = from->startup_cost;
87 newnode->total_cost = from->total_cost;
88 newnode->plan_rows = from->plan_rows;
89 newnode->plan_width = from->plan_width;
90 /* state is NOT copied */
91 Node_Copy(from, newnode, targetlist);
92 Node_Copy(from, newnode, qual);
93 Node_Copy(from, newnode, lefttree);
94 Node_Copy(from, newnode, righttree);
95 newnode->extParam = listCopy(from->extParam);
96 newnode->locParam = listCopy(from->locParam);
97 newnode->chgParam = listCopy(from->chgParam);
98 Node_Copy(from, newnode, initPlan);
99 /* subPlan list must point to subplans in the new subtree, not the old */
100 if (from->subPlan != NIL)
101 newnode->subPlan = nconc(pull_subplans((Node *) newnode->targetlist),
102 pull_subplans((Node *) newnode->qual));
104 newnode->subPlan = NIL;
105 newnode->nParamExec = from->nParamExec;
113 _copyPlan(Plan *from)
115 Plan *newnode = makeNode(Plan);
118 * copy the node superclass fields
121 CopyPlanFields(from, newnode);
132 _copyResult(Result *from)
134 Result *newnode = makeNode(Result);
137 * copy node superclass fields
140 CopyPlanFields((Plan *) from, (Plan *) newnode);
143 * copy remainder of node
146 Node_Copy(from, newnode, resconstantqual);
149 * We must add subplans in resconstantqual to the new plan's subPlan
152 if (from->plan.subPlan != NIL)
153 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
154 pull_subplans(newnode->resconstantqual));
164 _copyAppend(Append *from)
166 Append *newnode = makeNode(Append);
169 * copy node superclass fields
172 CopyPlanFields((Plan *) from, (Plan *) newnode);
175 * copy remainder of node
178 Node_Copy(from, newnode, appendplans);
179 Node_Copy(from, newnode, unionrtables);
180 newnode->inheritrelid = from->inheritrelid;
181 Node_Copy(from, newnode, inheritrtable);
190 * This function copies the fields of the Scan node. It is used by
191 * all the copy functions for classes which inherit from Scan.
195 CopyScanFields(Scan *from, Scan *newnode)
197 newnode->scanrelid = from->scanrelid;
206 _copyScan(Scan *from)
208 Scan *newnode = makeNode(Scan);
211 * copy node superclass fields
214 CopyPlanFields((Plan *) from, (Plan *) newnode);
215 CopyScanFields((Scan *) from, (Scan *) newnode);
225 _copySeqScan(SeqScan *from)
227 SeqScan *newnode = makeNode(SeqScan);
230 * copy node superclass fields
233 CopyPlanFields((Plan *) from, (Plan *) newnode);
234 CopyScanFields((Scan *) from, (Scan *) newnode);
244 _copyIndexScan(IndexScan *from)
246 IndexScan *newnode = makeNode(IndexScan);
249 * copy node superclass fields
252 CopyPlanFields((Plan *) from, (Plan *) newnode);
253 CopyScanFields((Scan *) from, (Scan *) newnode);
256 * copy remainder of node
259 newnode->indxid = listCopy(from->indxid);
260 Node_Copy(from, newnode, indxqual);
261 Node_Copy(from, newnode, indxqualorig);
262 newnode->indxorderdir = from->indxorderdir;
265 * We must add subplans in index quals to the new plan's subPlan list
267 if (from->scan.plan.subPlan != NIL)
269 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
270 pull_subplans((Node *) newnode->indxqual));
271 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
272 pull_subplans((Node *) newnode->indxqualorig));
283 _copyTidScan(TidScan *from)
285 TidScan *newnode = makeNode(TidScan);
288 * copy node superclass fields
291 CopyPlanFields((Plan *) from, (Plan *) newnode);
292 CopyScanFields((Scan *) from, (Scan *) newnode);
294 * copy remainder of node
297 newnode->needRescan = from->needRescan;
298 Node_Copy(from, newnode, tideval);
307 * This function copies the fields of the Join node. It is used by
308 * all the copy functions for classes which inherit from Join.
312 CopyJoinFields(Join *from, Join *newnode)
324 _copyJoin(Join *from)
326 Join *newnode = makeNode(Join);
329 * copy node superclass fields
332 CopyPlanFields((Plan *) from, (Plan *) newnode);
333 CopyJoinFields(from, newnode);
344 _copyNestLoop(NestLoop *from)
346 NestLoop *newnode = makeNode(NestLoop);
349 * copy node superclass fields
352 CopyPlanFields((Plan *) from, (Plan *) newnode);
353 CopyJoinFields((Join *) from, (Join *) newnode);
364 _copyMergeJoin(MergeJoin *from)
366 MergeJoin *newnode = makeNode(MergeJoin);
369 * copy node superclass fields
372 CopyPlanFields((Plan *) from, (Plan *) newnode);
373 CopyJoinFields((Join *) from, (Join *) newnode);
376 * copy remainder of node
379 Node_Copy(from, newnode, mergeclauses);
382 * We must add subplans in mergeclauses to the new plan's subPlan list
384 if (from->join.subPlan != NIL)
385 newnode->join.subPlan = nconc(newnode->join.subPlan,
386 pull_subplans((Node *) newnode->mergeclauses));
396 _copyHashJoin(HashJoin *from)
398 HashJoin *newnode = makeNode(HashJoin);
401 * copy node superclass fields
404 CopyPlanFields((Plan *) from, (Plan *) newnode);
405 CopyJoinFields((Join *) from, (Join *) newnode);
408 * copy remainder of node
411 Node_Copy(from, newnode, hashclauses);
412 newnode->hashjoinop = from->hashjoinop;
415 * We must add subplans in hashclauses to the new plan's subPlan list
417 if (from->join.subPlan != NIL)
418 newnode->join.subPlan = nconc(newnode->join.subPlan,
419 pull_subplans((Node *) newnode->hashclauses));
430 _copyMaterial(Material *from)
432 Material *newnode = makeNode(Material);
435 * copy node superclass fields
438 CopyPlanFields((Plan *) from, (Plan *) newnode);
449 _copySort(Sort *from)
451 Sort *newnode = makeNode(Sort);
454 * copy node superclass fields
457 CopyPlanFields((Plan *) from, (Plan *) newnode);
459 newnode->keycount = from->keycount;
470 _copyGroup(Group *from)
472 Group *newnode = makeNode(Group);
474 CopyPlanFields((Plan *) from, (Plan *) newnode);
476 newnode->tuplePerGroup = from->tuplePerGroup;
477 newnode->numCols = from->numCols;
478 newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
479 memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
491 Agg *newnode = makeNode(Agg);
493 CopyPlanFields((Plan *) from, (Plan *) newnode);
503 _copyGroupClause(GroupClause *from)
505 GroupClause *newnode = makeNode(GroupClause);
507 newnode->tleSortGroupRef = from->tleSortGroupRef;
508 newnode->sortop = from->sortop;
514 _copyJoinExpr(JoinExpr *from)
516 JoinExpr *newnode = makeNode(JoinExpr);
518 newnode->jointype = from->jointype;
519 newnode->isNatural = from->isNatural;
520 Node_Copy(from, newnode, larg);
521 Node_Copy(from, newnode, rarg);
522 Node_Copy(from, newnode, alias);
523 Node_Copy(from, newnode, quals);
533 _copyUnique(Unique *from)
535 Unique *newnode = makeNode(Unique);
538 * copy node superclass fields
541 CopyPlanFields((Plan *) from, (Plan *) newnode);
544 * copy remainder of node
547 newnode->numCols = from->numCols;
548 newnode->uniqColIdx = palloc(from->numCols * sizeof(AttrNumber));
549 memcpy(newnode->uniqColIdx, from->uniqColIdx, from->numCols * sizeof(AttrNumber));
560 _copyHash(Hash *from)
562 Hash *newnode = makeNode(Hash);
565 * copy node superclass fields
568 CopyPlanFields((Plan *) from, (Plan *) newnode);
571 * copy remainder of node
574 Node_Copy(from, newnode, hashkey);
580 _copySubPlan(SubPlan *from)
582 SubPlan *newnode = makeNode(SubPlan);
584 Node_Copy(from, newnode, plan);
585 newnode->plan_id = from->plan_id;
586 Node_Copy(from, newnode, rtable);
587 newnode->setParam = listCopy(from->setParam);
588 newnode->parParam = listCopy(from->parParam);
589 Node_Copy(from, newnode, sublink);
591 /* do not copy execution state */
592 newnode->needShutdown = false;
593 newnode->curTuple = NULL;
598 /* ****************************************************************
599 * primnodes.h copy functions
600 * ****************************************************************
608 _copyResdom(Resdom *from)
610 Resdom *newnode = makeNode(Resdom);
612 newnode->resno = from->resno;
613 newnode->restype = from->restype;
614 newnode->restypmod = from->restypmod;
615 if (from->resname != NULL)
616 newnode->resname = pstrdup(from->resname);
617 newnode->ressortgroupref = from->ressortgroupref;
618 newnode->reskey = from->reskey;
619 newnode->reskeyop = from->reskeyop;
620 newnode->resjunk = from->resjunk;
626 _copyFjoin(Fjoin *from)
628 Fjoin *newnode = makeNode(Fjoin);
631 * copy node superclass fields
635 newnode->fj_initialized = from->fj_initialized;
636 newnode->fj_nNodes = from->fj_nNodes;
638 Node_Copy(from, newnode, fj_innerNode);
640 newnode->fj_results = (DatumPtr)
641 palloc((from->fj_nNodes) * sizeof(Datum));
642 memmove(from->fj_results,
644 (from->fj_nNodes) * sizeof(Datum));
646 newnode->fj_alwaysDone = (BoolPtr)
647 palloc((from->fj_nNodes) * sizeof(bool));
648 memmove(from->fj_alwaysDone,
649 newnode->fj_alwaysDone,
650 (from->fj_nNodes) * sizeof(bool));
661 _copyExpr(Expr *from)
663 Expr *newnode = makeNode(Expr);
666 * copy node superclass fields
669 newnode->typeOid = from->typeOid;
670 newnode->opType = from->opType;
672 Node_Copy(from, newnode, oper);
673 Node_Copy(from, newnode, args);
685 Var *newnode = makeNode(Var);
688 * copy remainder of node
691 newnode->varno = from->varno;
692 newnode->varattno = from->varattno;
693 newnode->vartype = from->vartype;
694 newnode->vartypmod = from->vartypmod;
695 newnode->varlevelsup = from->varlevelsup;
697 newnode->varnoold = from->varnoold;
698 newnode->varoattno = from->varoattno;
704 _copyAttr(Attr *from)
706 Attr *newnode = makeNode(Attr);
709 newnode->relname = pstrdup(from->relname);
710 Node_Copy(from, newnode, attrs);
720 _copyOper(Oper *from)
722 Oper *newnode = makeNode(Oper);
725 * copy remainder of node
728 newnode->opno = from->opno;
729 newnode->opid = from->opid;
730 newnode->opresulttype = from->opresulttype;
731 /* Do not copy the run-time state, if any */
732 newnode->op_fcache = NULL;
742 _copyConst(Const *from)
744 Const *newnode = makeNode(Const);
747 * copy remainder of node
750 newnode->consttype = from->consttype;
751 newnode->constlen = from->constlen;
753 if (from->constbyval || from->constisnull)
756 * passed by value so just copy the datum.
757 * Also, don't try to copy struct when value is null!
760 newnode->constvalue = from->constvalue;
765 * not passed by value. datum contains a pointer.
768 int length = from->constlen;
770 if (length == -1) /* variable-length type? */
771 length = VARSIZE(from->constvalue);
772 newnode->constvalue = PointerGetDatum(palloc(length));
773 memcpy(DatumGetPointer(newnode->constvalue),
774 DatumGetPointer(from->constvalue),
778 newnode->constisnull = from->constisnull;
779 newnode->constbyval = from->constbyval;
780 newnode->constisset = from->constisset;
781 newnode->constiscast = from->constiscast;
791 _copyParam(Param *from)
793 Param *newnode = makeNode(Param);
796 * copy remainder of node
799 newnode->paramkind = from->paramkind;
800 newnode->paramid = from->paramid;
802 if (from->paramname != NULL)
803 newnode->paramname = pstrdup(from->paramname);
804 newnode->paramtype = from->paramtype;
814 _copyFunc(Func *from)
816 Func *newnode = makeNode(Func);
819 * copy remainder of node
822 newnode->funcid = from->funcid;
823 newnode->functype = from->functype;
824 /* Do not copy the run-time state, if any */
825 newnode->func_fcache = NULL;
835 _copyAggref(Aggref *from)
837 Aggref *newnode = makeNode(Aggref);
840 * copy remainder of node
843 newnode->aggname = pstrdup(from->aggname);
844 newnode->basetype = from->basetype;
845 newnode->aggtype = from->aggtype;
846 Node_Copy(from, newnode, target);
847 newnode->aggstar = from->aggstar;
848 newnode->aggdistinct = from->aggdistinct;
849 newnode->aggno = from->aggno; /* probably not needed */
859 _copySubLink(SubLink *from)
861 SubLink *newnode = makeNode(SubLink);
864 * copy remainder of node
867 newnode->subLinkType = from->subLinkType;
868 newnode->useor = from->useor;
869 Node_Copy(from, newnode, lefthand);
870 Node_Copy(from, newnode, oper);
871 Node_Copy(from, newnode, subselect);
881 _copyFieldSelect(FieldSelect *from)
883 FieldSelect *newnode = makeNode(FieldSelect);
886 * copy remainder of node
889 Node_Copy(from, newnode, arg);
890 newnode->fieldnum = from->fieldnum;
891 newnode->resulttype = from->resulttype;
892 newnode->resulttypmod = from->resulttypmod;
902 _copyRelabelType(RelabelType *from)
904 RelabelType *newnode = makeNode(RelabelType);
907 * copy remainder of node
910 Node_Copy(from, newnode, arg);
911 newnode->resulttype = from->resulttype;
912 newnode->resulttypmod = from->resulttypmod;
922 _copyCaseExpr(CaseExpr *from)
924 CaseExpr *newnode = makeNode(CaseExpr);
927 * copy remainder of node
930 newnode->casetype = from->casetype;
932 Node_Copy(from, newnode, arg);
933 Node_Copy(from, newnode, args);
934 Node_Copy(from, newnode, defresult);
944 _copyCaseWhen(CaseWhen *from)
946 CaseWhen *newnode = makeNode(CaseWhen);
949 * copy remainder of node
952 Node_Copy(from, newnode, expr);
953 Node_Copy(from, newnode, result);
959 _copyArrayRef(ArrayRef *from)
961 ArrayRef *newnode = makeNode(ArrayRef);
964 * copy remainder of node
967 newnode->refattrlength = from->refattrlength;
968 newnode->refelemlength = from->refelemlength;
969 newnode->refelemtype = from->refelemtype;
970 newnode->refelembyval = from->refelembyval;
972 Node_Copy(from, newnode, refupperindexpr);
973 Node_Copy(from, newnode, reflowerindexpr);
974 Node_Copy(from, newnode, refexpr);
975 Node_Copy(from, newnode, refassgnexpr);
980 /* ****************************************************************
981 * relation.h copy functions
982 * ****************************************************************
990 * when you change this, also make sure to fix up xfunc_copyRelOptInfo in
991 * planner/path/xfunc.c accordingly!!!
995 _copyRelOptInfo(RelOptInfo *from)
997 RelOptInfo *newnode = makeNode(RelOptInfo);
999 newnode->relids = listCopy(from->relids);
1001 newnode->rows = from->rows;
1002 newnode->width = from->width;
1004 Node_Copy(from, newnode, targetlist);
1005 Node_Copy(from, newnode, pathlist);
1006 /* XXX cheapest-path fields should point to members of pathlist? */
1007 Node_Copy(from, newnode, cheapest_startup_path);
1008 Node_Copy(from, newnode, cheapest_total_path);
1009 newnode->pruneable = from->pruneable;
1011 newnode->indexed = from->indexed;
1012 newnode->pages = from->pages;
1013 newnode->tuples = from->tuples;
1015 Node_Copy(from, newnode, baserestrictinfo);
1016 newnode->baserestrictcost = from->baserestrictcost;
1017 Node_Copy(from, newnode, joininfo);
1018 Node_Copy(from, newnode, innerjoin);
1027 static IndexOptInfo *
1028 _copyIndexOptInfo(IndexOptInfo *from)
1030 IndexOptInfo *newnode = makeNode(IndexOptInfo);
1034 newnode->indexoid = from->indexoid;
1035 newnode->pages = from->pages;
1036 newnode->tuples = from->tuples;
1038 if (from->classlist)
1040 for (len = 0; from->classlist[len] != 0; len++)
1042 newnode->classlist = (Oid *) palloc(sizeof(Oid) * (len + 1));
1043 for (i = 0; i < len; i++)
1044 newnode->classlist[i] = from->classlist[i];
1045 newnode->classlist[len] = 0;
1048 if (from->indexkeys)
1050 for (len = 0; from->indexkeys[len] != 0; len++)
1052 newnode->indexkeys = (int *) palloc(sizeof(int) * (len + 1));
1053 for (i = 0; i < len; i++)
1054 newnode->indexkeys[i] = from->indexkeys[i];
1055 newnode->indexkeys[len] = 0;
1060 for (len = 0; from->ordering[len] != 0; len++)
1062 newnode->ordering = (Oid *) palloc(sizeof(Oid) * (len + 1));
1063 for (i = 0; i < len; i++)
1064 newnode->ordering[i] = from->ordering[i];
1065 newnode->ordering[len] = 0;
1068 newnode->relam = from->relam;
1069 newnode->amcostestimate = from->amcostestimate;
1070 newnode->indproc = from->indproc;
1071 Node_Copy(from, newnode, indpred);
1072 newnode->lossy = from->lossy;
1080 * This function copies the fields of the Path node. It is used by
1081 * all the copy functions for classes which inherit from Path.
1085 CopyPathFields(Path *from, Path *newnode)
1089 * Modify the next line, since it causes the copying to cycle (i.e.
1090 * the parent points right back here! -- JMH, 7/7/92. Old version:
1091 * Node_Copy(from, newnode, parent);
1093 newnode->parent = from->parent;
1095 newnode->startup_cost = from->startup_cost;
1096 newnode->total_cost = from->total_cost;
1098 newnode->pathtype = from->pathtype;
1100 Node_Copy(from, newnode, pathkeys);
1108 _copyPath(Path *from)
1110 Path *newnode = makeNode(Path);
1112 CopyPathFields(from, newnode);
1122 _copyIndexPath(IndexPath *from)
1124 IndexPath *newnode = makeNode(IndexPath);
1127 * copy the node superclass fields
1130 CopyPathFields((Path *) from, (Path *) newnode);
1133 * copy remainder of node
1136 newnode->indexid = listCopy(from->indexid);
1137 Node_Copy(from, newnode, indexqual);
1138 newnode->indexscandir = from->indexscandir;
1139 newnode->joinrelids = listCopy(from->joinrelids);
1140 newnode->rows = from->rows;
1150 _copyTidPath(TidPath *from)
1152 TidPath *newnode = makeNode(TidPath);
1155 * copy the node superclass fields
1158 CopyPathFields((Path *) from, (Path *) newnode);
1161 * copy remainder of node
1164 Node_Copy(from, newnode, tideval);
1165 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1171 * CopyJoinPathFields
1173 * This function copies the fields of the JoinPath node. It is used by
1174 * all the copy functions for classes which inherit from JoinPath.
1178 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1180 Node_Copy(from, newnode, outerjoinpath);
1181 Node_Copy(from, newnode, innerjoinpath);
1182 Node_Copy(from, newnode, joinrestrictinfo);
1190 _copyNestPath(NestPath *from)
1192 NestPath *newnode = makeNode(NestPath);
1195 * copy the node superclass fields
1198 CopyPathFields((Path *) from, (Path *) newnode);
1199 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1209 _copyMergePath(MergePath *from)
1211 MergePath *newnode = makeNode(MergePath);
1214 * copy the node superclass fields
1217 CopyPathFields((Path *) from, (Path *) newnode);
1218 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1221 * copy the remainder of the node
1224 Node_Copy(from, newnode, path_mergeclauses);
1225 Node_Copy(from, newnode, outersortkeys);
1226 Node_Copy(from, newnode, innersortkeys);
1236 _copyHashPath(HashPath *from)
1238 HashPath *newnode = makeNode(HashPath);
1241 * copy the node superclass fields
1244 CopyPathFields((Path *) from, (Path *) newnode);
1245 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1248 * copy remainder of node
1251 Node_Copy(from, newnode, path_hashclauses);
1260 static PathKeyItem *
1261 _copyPathKeyItem(PathKeyItem *from)
1263 PathKeyItem *newnode = makeNode(PathKeyItem);
1266 * copy remainder of node
1269 Node_Copy(from, newnode, key);
1270 newnode->sortop = from->sortop;
1279 static RestrictInfo *
1280 _copyRestrictInfo(RestrictInfo *from)
1282 RestrictInfo *newnode = makeNode(RestrictInfo);
1285 * copy remainder of node
1288 Node_Copy(from, newnode, clause);
1289 Node_Copy(from, newnode, subclauseindices);
1290 newnode->mergejoinoperator = from->mergejoinoperator;
1291 newnode->left_sortop = from->left_sortop;
1292 newnode->right_sortop = from->right_sortop;
1293 newnode->hashjoinoperator = from->hashjoinoperator;
1303 _copyJoinInfo(JoinInfo *from)
1305 JoinInfo *newnode = makeNode(JoinInfo);
1308 * copy remainder of node
1311 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1312 Node_Copy(from, newnode, jinfo_restrictinfo);
1318 _copyIter(Iter *from)
1320 Iter *newnode = makeNode(Iter);
1322 Node_Copy(from, newnode, iterexpr);
1323 newnode->itertype = from->itertype;
1329 _copyStream(Stream *from)
1331 Stream *newnode = makeNode(Stream);
1333 newnode->pathptr = from->pathptr;
1334 newnode->cinfo = from->cinfo;
1335 newnode->clausetype = from->clausetype;
1337 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1339 Node_Copy(from, newnode, downstream);
1340 if (newnode->downstream)
1341 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1343 newnode->groupup = from->groupup;
1344 newnode->groupcost = from->groupcost;
1345 newnode->groupsel = from->groupsel;
1350 /* ****************************************************************
1351 * parsenodes.h copy functions
1352 * ****************************************************************
1355 static TargetEntry *
1356 _copyTargetEntry(TargetEntry *from)
1358 TargetEntry *newnode = makeNode(TargetEntry);
1360 Node_Copy(from, newnode, resdom);
1361 Node_Copy(from, newnode, fjoin);
1362 Node_Copy(from, newnode, expr);
1366 static RangeTblEntry *
1367 _copyRangeTblEntry(RangeTblEntry *from)
1369 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1372 newnode->relname = pstrdup(from->relname);
1373 Node_Copy(from, newnode, ref);
1374 Node_Copy(from, newnode, eref);
1375 newnode->relid = from->relid;
1376 newnode->inh = from->inh;
1377 newnode->inFromCl = from->inFromCl;
1378 newnode->inJoinSet = from->inJoinSet;
1379 newnode->skipAcl = from->skipAcl;
1385 _copyRowMark(RowMark *from)
1387 RowMark *newnode = makeNode(RowMark);
1389 newnode->rti = from->rti;
1390 newnode->info = from->info;
1395 static FkConstraint *
1396 _copyFkConstraint(FkConstraint *from)
1398 FkConstraint *newnode = makeNode(FkConstraint);
1400 if (from->constr_name)
1401 newnode->constr_name = pstrdup(from->constr_name);
1402 if (from->pktable_name)
1403 newnode->pktable_name = pstrdup(from->pktable_name);
1404 Node_Copy(from, newnode, fk_attrs);
1405 Node_Copy(from, newnode, pk_attrs);
1406 if (from->match_type)
1407 newnode->match_type = pstrdup(from->match_type);
1408 newnode->actions = from->actions;
1409 newnode->deferrable = from->deferrable;
1410 newnode->initdeferred = from->initdeferred;
1416 _copySortClause(SortClause *from)
1418 SortClause *newnode = makeNode(SortClause);
1420 newnode->tleSortGroupRef = from->tleSortGroupRef;
1421 newnode->sortop = from->sortop;
1427 _copyAExpr(A_Expr *from)
1429 A_Expr *newnode = makeNode(A_Expr);
1431 newnode->oper = from->oper;
1433 newnode->opname = pstrdup(from->opname);
1434 Node_Copy(from, newnode, lexpr);
1435 Node_Copy(from, newnode, rexpr);
1441 _copyAConst(A_Const *from)
1443 A_Const *newnode = makeNode(A_Const);
1445 newnode->val = *((Value *) (copyObject(&(from->val))));
1446 Node_Copy(from, newnode, typename);
1452 _copyParamNo(ParamNo *from)
1454 ParamNo *newnode = makeNode(ParamNo);
1456 newnode->number = from->number;
1457 Node_Copy(from, newnode, typename);
1458 Node_Copy(from, newnode, indirection);
1464 _copyIdent(Ident *from)
1466 Ident *newnode = makeNode(Ident);
1469 newnode->name = pstrdup(from->name);
1470 Node_Copy(from, newnode, indirection);
1471 newnode->isRel = from->isRel;
1477 _copyFuncCall(FuncCall *from)
1479 FuncCall *newnode = makeNode(FuncCall);
1482 newnode->funcname = pstrdup(from->funcname);
1483 Node_Copy(from, newnode, args);
1484 newnode->agg_star = from->agg_star;
1485 newnode->agg_distinct = from->agg_distinct;
1491 _copyAIndices(A_Indices *from)
1493 A_Indices *newnode = makeNode(A_Indices);
1495 Node_Copy(from, newnode, lidx);
1496 Node_Copy(from, newnode, uidx);
1502 _copyResTarget(ResTarget *from)
1504 ResTarget *newnode = makeNode(ResTarget);
1507 newnode->name = pstrdup(from->name);
1508 Node_Copy(from, newnode, indirection);
1509 Node_Copy(from, newnode, val);
1515 _copyTypeName(TypeName *from)
1517 TypeName *newnode = makeNode(TypeName);
1520 newnode->name = pstrdup(from->name);
1521 newnode->timezone = from->timezone;
1522 newnode->setof = from->setof;
1523 newnode->typmod = from->typmod;
1524 Node_Copy(from, newnode, arrayBounds);
1530 _copyRelExpr(RelExpr *from)
1532 RelExpr *newnode = makeNode(RelExpr);
1535 newnode->relname = pstrdup(from->relname);
1536 newnode->inh = from->inh;
1541 static SortGroupBy *
1542 _copySortGroupBy(SortGroupBy *from)
1544 SortGroupBy *newnode = makeNode(SortGroupBy);
1547 newnode->useOp = pstrdup(from->useOp);
1548 Node_Copy(from, newnode, node);
1554 _copyRangeVar(RangeVar *from)
1556 RangeVar *newnode = makeNode(RangeVar);
1558 Node_Copy(from, newnode, relExpr);
1559 Node_Copy(from, newnode, name);
1565 _copyTypeCast(TypeCast *from)
1567 TypeCast *newnode = makeNode(TypeCast);
1569 Node_Copy(from, newnode, arg);
1570 Node_Copy(from, newnode, typename);
1576 _copyIndexElem(IndexElem *from)
1578 IndexElem *newnode = makeNode(IndexElem);
1581 newnode->name = pstrdup(from->name);
1582 Node_Copy(from, newnode, args);
1584 newnode->class = pstrdup(from->class);
1590 _copyColumnDef(ColumnDef *from)
1592 ColumnDef *newnode = makeNode(ColumnDef);
1595 newnode->colname = pstrdup(from->colname);
1596 Node_Copy(from, newnode, typename);
1597 newnode->is_not_null = from->is_not_null;
1598 newnode->is_sequence = from->is_sequence;
1599 Node_Copy(from, newnode, raw_default);
1600 if (from->cooked_default)
1601 newnode->cooked_default = pstrdup(from->cooked_default);
1602 Node_Copy(from, newnode, constraints);
1608 _copyConstraint(Constraint *from)
1610 Constraint *newnode = makeNode(Constraint);
1612 newnode->contype = from->contype;
1614 newnode->name = pstrdup(from->name);
1615 Node_Copy(from, newnode, raw_expr);
1616 if (from->cooked_expr)
1617 newnode->cooked_expr = pstrdup(from->cooked_expr);
1618 Node_Copy(from, newnode, keys);
1624 _copyDefElem(DefElem *from)
1626 DefElem *newnode = makeNode(DefElem);
1629 newnode->defname = pstrdup(from->defname);
1630 Node_Copy(from, newnode, arg);
1636 _copyQuery(Query *from)
1638 Query *newnode = makeNode(Query);
1640 newnode->commandType = from->commandType;
1641 Node_Copy(from, newnode, utilityStmt);
1642 newnode->resultRelation = from->resultRelation;
1644 newnode->into = pstrdup(from->into);
1645 newnode->isPortal = from->isPortal;
1646 newnode->isBinary = from->isBinary;
1647 newnode->isTemp = from->isTemp;
1648 newnode->unionall = from->unionall;
1649 newnode->hasAggs = from->hasAggs;
1650 newnode->hasSubLinks = from->hasSubLinks;
1652 Node_Copy(from, newnode, rtable);
1653 Node_Copy(from, newnode, targetList);
1654 Node_Copy(from, newnode, qual);
1655 Node_Copy(from, newnode, rowMark);
1657 Node_Copy(from, newnode, distinctClause);
1658 Node_Copy(from, newnode, sortClause);
1659 Node_Copy(from, newnode, groupClause);
1660 Node_Copy(from, newnode, havingQual);
1662 /* why is intersectClause missing? */
1663 Node_Copy(from, newnode, unionClause);
1665 Node_Copy(from, newnode, limitOffset);
1666 Node_Copy(from, newnode, limitCount);
1669 * We do not copy the planner internal fields: base_rel_list,
1670 * join_rel_list, equi_key_list, query_pathkeys. Not entirely clear if
1678 _copyInsertStmt(InsertStmt *from)
1680 InsertStmt *newnode = makeNode(InsertStmt);
1683 newnode->relname = pstrdup(from->relname);
1684 Node_Copy(from, newnode, distinctClause);
1685 Node_Copy(from, newnode, cols);
1686 Node_Copy(from, newnode, targetList);
1687 Node_Copy(from, newnode, fromClause);
1688 Node_Copy(from, newnode, whereClause);
1689 Node_Copy(from, newnode, groupClause);
1690 Node_Copy(from, newnode, havingClause);
1691 Node_Copy(from, newnode, unionClause);
1692 newnode->unionall = from->unionall;
1693 Node_Copy(from, newnode, intersectClause);
1694 Node_Copy(from, newnode, forUpdate);
1700 _copyDeleteStmt(DeleteStmt *from)
1702 DeleteStmt *newnode = makeNode(DeleteStmt);
1705 newnode->relname = pstrdup(from->relname);
1706 Node_Copy(from, newnode, whereClause);
1707 newnode->inh = from->inh;
1713 _copyUpdateStmt(UpdateStmt *from)
1715 UpdateStmt *newnode = makeNode(UpdateStmt);
1718 newnode->relname = pstrdup(from->relname);
1719 Node_Copy(from, newnode, targetList);
1720 Node_Copy(from, newnode, whereClause);
1721 Node_Copy(from, newnode, fromClause);
1722 newnode->inh = from->inh;
1728 _copySelectStmt(SelectStmt *from)
1730 SelectStmt *newnode = makeNode(SelectStmt);
1732 Node_Copy(from, newnode, distinctClause);
1734 newnode->into = pstrdup(from->into);
1735 Node_Copy(from, newnode, targetList);
1736 Node_Copy(from, newnode, fromClause);
1737 Node_Copy(from, newnode, whereClause);
1738 Node_Copy(from, newnode, groupClause);
1739 Node_Copy(from, newnode, havingClause);
1740 Node_Copy(from, newnode, intersectClause);
1741 Node_Copy(from, newnode, exceptClause);
1742 Node_Copy(from, newnode, unionClause);
1743 Node_Copy(from, newnode, sortClause);
1744 if (from->portalname)
1745 newnode->portalname = pstrdup(from->portalname);
1746 newnode->binary = from->binary;
1747 newnode->istemp = from->istemp;
1748 newnode->unionall = from->unionall;
1749 Node_Copy(from, newnode, limitOffset);
1750 Node_Copy(from, newnode, limitCount);
1751 Node_Copy(from, newnode, forUpdate);
1756 static AlterTableStmt *
1757 _copyAlterTableStmt(AlterTableStmt *from)
1759 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1761 newnode->subtype = from->subtype;
1763 newnode->relname = pstrdup(from->relname);
1764 newnode->inh = from->inh;
1766 newnode->name = pstrdup(from->name);
1767 Node_Copy(from, newnode, def);
1768 newnode->behavior = from->behavior;
1773 static ChangeACLStmt *
1774 _copyChangeACLStmt(ChangeACLStmt *from)
1776 ChangeACLStmt *newnode = makeNode(ChangeACLStmt);
1780 newnode->aclitem = (struct AclItem *) palloc(sizeof(struct AclItem));
1781 memcpy(newnode->aclitem, from->aclitem, sizeof(struct AclItem));
1783 newnode->modechg = from->modechg;
1784 Node_Copy(from, newnode, relNames);
1789 static ClosePortalStmt *
1790 _copyClosePortalStmt(ClosePortalStmt *from)
1792 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1794 if (from->portalname)
1795 newnode->portalname = pstrdup(from->portalname);
1800 static ClusterStmt *
1801 _copyClusterStmt(ClusterStmt *from)
1803 ClusterStmt *newnode = makeNode(ClusterStmt);
1806 newnode->relname = pstrdup(from->relname);
1807 if (from->indexname)
1808 newnode->indexname = pstrdup(from->indexname);
1814 _copyCopyStmt(CopyStmt *from)
1816 CopyStmt *newnode = makeNode(CopyStmt);
1818 newnode->binary = from->binary;
1820 newnode->relname = pstrdup(from->relname);
1821 newnode->oids = from->oids;
1822 newnode->direction = from->direction;
1824 newnode->filename = pstrdup(from->filename);
1825 if (from->delimiter)
1826 newnode->delimiter = pstrdup(from->delimiter);
1827 if (from->null_print)
1828 newnode->null_print = pstrdup(from->null_print);
1834 _copyCreateStmt(CreateStmt *from)
1836 CreateStmt *newnode = makeNode(CreateStmt);
1838 newnode->istemp = from->istemp;
1839 newnode->relname = pstrdup(from->relname);
1840 Node_Copy(from, newnode, tableElts);
1841 Node_Copy(from, newnode, inhRelnames);
1842 Node_Copy(from, newnode, constraints);
1847 static VersionStmt *
1848 _copyVersionStmt(VersionStmt *from)
1850 VersionStmt *newnode = makeNode(VersionStmt);
1852 newnode->relname = pstrdup(from->relname);
1853 newnode->direction = from->direction;
1854 newnode->fromRelname = pstrdup(from->fromRelname);
1855 newnode->date = pstrdup(from->date);
1861 _copyDefineStmt(DefineStmt *from)
1863 DefineStmt *newnode = makeNode(DefineStmt);
1865 newnode->defType = from->defType;
1866 newnode->defname = pstrdup(from->defname);
1867 Node_Copy(from, newnode, definition);
1873 _copyDropStmt(DropStmt *from)
1875 DropStmt *newnode = makeNode(DropStmt);
1877 Node_Copy(from, newnode, relNames);
1878 newnode->sequence = from->sequence;
1883 static TruncateStmt *
1884 _copyTruncateStmt(TruncateStmt *from)
1886 TruncateStmt *newnode = makeNode(TruncateStmt);
1888 newnode->relName = pstrdup(from->relName);
1893 static CommentStmt *
1894 _copyCommentStmt(CommentStmt *from)
1896 CommentStmt *newnode = makeNode(CommentStmt);
1898 newnode->objtype = from->objtype;
1899 newnode->objname = pstrdup(from->objname);
1900 newnode->objproperty = pstrdup(from->objproperty);
1901 Node_Copy(from, newnode, objlist);
1902 newnode->comment = pstrdup(from->comment);
1908 _copyExtendStmt(ExtendStmt *from)
1910 ExtendStmt *newnode = makeNode(ExtendStmt);
1912 newnode->idxname = pstrdup(from->idxname);
1913 Node_Copy(from, newnode, whereClause);
1914 Node_Copy(from, newnode, rangetable);
1920 _copyFetchStmt(FetchStmt *from)
1922 FetchStmt *newnode = makeNode(FetchStmt);
1924 newnode->direction = from->direction;
1925 newnode->howMany = from->howMany;
1926 newnode->portalname = pstrdup(from->portalname);
1927 newnode->ismove = from->ismove;
1933 _copyIndexStmt(IndexStmt *from)
1935 IndexStmt *newnode = makeNode(IndexStmt);
1937 newnode->idxname = pstrdup(from->idxname);
1938 newnode->relname = pstrdup(from->relname);
1939 newnode->accessMethod = pstrdup(from->accessMethod);
1940 Node_Copy(from, newnode, indexParams);
1941 Node_Copy(from, newnode, withClause);
1942 Node_Copy(from, newnode, whereClause);
1943 Node_Copy(from, newnode, rangetable);
1944 newnode->unique = from->unique;
1945 newnode->primary = from->primary;
1950 static ProcedureStmt *
1951 _copyProcedureStmt(ProcedureStmt *from)
1953 ProcedureStmt *newnode = makeNode(ProcedureStmt);
1955 newnode->funcname = pstrdup(from->funcname);
1956 Node_Copy(from, newnode, defArgs);
1957 Node_Copy(from, newnode, returnType);
1958 Node_Copy(from, newnode, withClause);
1959 Node_Copy(from, newnode, as);
1960 newnode->language = pstrdup(from->language);
1965 static RemoveAggrStmt *
1966 _copyRemoveAggrStmt(RemoveAggrStmt *from)
1968 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1970 newnode->aggname = pstrdup(from->aggname);
1971 newnode->aggtype = pstrdup(from->aggtype);
1976 static RemoveFuncStmt *
1977 _copyRemoveFuncStmt(RemoveFuncStmt *from)
1979 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
1981 newnode->funcname = pstrdup(from->funcname);
1982 Node_Copy(from, newnode, args);
1987 static RemoveOperStmt *
1988 _copyRemoveOperStmt(RemoveOperStmt *from)
1990 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
1992 newnode->opname = pstrdup(from->opname);
1993 Node_Copy(from, newnode, args);
1999 _copyRemoveStmt(RemoveStmt *from)
2001 RemoveStmt *newnode = makeNode(RemoveStmt);
2003 newnode->removeType = from->removeType;
2004 newnode->name = pstrdup(from->name);
2010 _copyRenameStmt(RenameStmt *from)
2012 RenameStmt *newnode = makeNode(RenameStmt);
2014 newnode->relname = pstrdup(from->relname);
2015 newnode->inh = from->inh;
2017 newnode->column = pstrdup(from->column);
2019 newnode->newname = pstrdup(from->newname);
2025 _copyRuleStmt(RuleStmt *from)
2027 RuleStmt *newnode = makeNode(RuleStmt);
2029 newnode->rulename = pstrdup(from->rulename);
2030 Node_Copy(from, newnode, whereClause);
2031 newnode->event = from->event;
2032 Node_Copy(from, newnode, object);
2033 newnode->instead = from->instead;
2034 Node_Copy(from, newnode, actions);
2040 _copyNotifyStmt(NotifyStmt *from)
2042 NotifyStmt *newnode = makeNode(NotifyStmt);
2045 newnode->relname = pstrdup(from->relname);
2051 _copyListenStmt(ListenStmt *from)
2053 ListenStmt *newnode = makeNode(ListenStmt);
2056 newnode->relname = pstrdup(from->relname);
2061 static UnlistenStmt *
2062 _copyUnlistenStmt(UnlistenStmt *from)
2064 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2067 newnode->relname = pstrdup(from->relname);
2072 static TransactionStmt *
2073 _copyTransactionStmt(TransactionStmt *from)
2075 TransactionStmt *newnode = makeNode(TransactionStmt);
2077 newnode->command = from->command;
2083 _copyViewStmt(ViewStmt *from)
2085 ViewStmt *newnode = makeNode(ViewStmt);
2088 newnode->viewname = pstrdup(from->viewname);
2089 Node_Copy(from, newnode, aliases);
2090 Node_Copy(from, newnode, query);
2096 _copyLoadStmt(LoadStmt *from)
2098 LoadStmt *newnode = makeNode(LoadStmt);
2101 newnode->filename = pstrdup(from->filename);
2106 static CreatedbStmt *
2107 _copyCreatedbStmt(CreatedbStmt *from)
2109 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2112 newnode->dbname = pstrdup(from->dbname);
2114 newnode->dbpath = pstrdup(from->dbpath);
2115 newnode->encoding = from->encoding;
2121 _copyDropdbStmt(DropdbStmt *from)
2123 DropdbStmt *newnode = makeNode(DropdbStmt);
2126 newnode->dbname = pstrdup(from->dbname);
2132 _copyVacuumStmt(VacuumStmt *from)
2134 VacuumStmt *newnode = makeNode(VacuumStmt);
2136 newnode->verbose = from->verbose;
2137 newnode->analyze = from->analyze;
2139 newnode->vacrel = pstrdup(from->vacrel);
2140 Node_Copy(from, newnode, va_spec);
2145 static ExplainStmt *
2146 _copyExplainStmt(ExplainStmt *from)
2148 ExplainStmt *newnode = makeNode(ExplainStmt);
2150 Node_Copy(from, newnode, query);
2151 newnode->verbose = from->verbose;
2156 static CreateSeqStmt *
2157 _copyCreateSeqStmt(CreateSeqStmt *from)
2159 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2162 newnode->seqname = pstrdup(from->seqname);
2163 Node_Copy(from, newnode, options);
2168 static VariableSetStmt *
2169 _copyVariableSetStmt(VariableSetStmt *from)
2171 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2174 newnode->name = pstrdup(from->name);
2176 newnode->value = pstrdup(from->value);
2181 static VariableShowStmt *
2182 _copyVariableShowStmt(VariableShowStmt *from)
2184 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2187 newnode->name = pstrdup(from->name);
2192 static VariableResetStmt *
2193 _copyVariableResetStmt(VariableResetStmt *from)
2195 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2198 newnode->name = pstrdup(from->name);
2203 static CreateTrigStmt *
2204 _copyCreateTrigStmt(CreateTrigStmt *from)
2206 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2209 newnode->trigname = pstrdup(from->trigname);
2211 newnode->relname = pstrdup(from->relname);
2213 newnode->funcname = pstrdup(from->funcname);
2214 Node_Copy(from, newnode, args);
2215 newnode->before = from->before;
2216 newnode->row = from->row;
2217 memcpy(newnode->actions, from->actions, sizeof(from->actions));
2219 newnode->lang = pstrdup(from->lang);
2221 newnode->text = pstrdup(from->text);
2222 Node_Copy(from, newnode, attr);
2224 newnode->when = pstrdup(from->when);
2225 newnode->isconstraint = from->isconstraint;
2226 newnode->deferrable = from->deferrable;
2227 newnode->initdeferred = from->initdeferred;
2228 if (from->constrrelname)
2229 newnode->constrrelname = pstrdup(from->constrrelname);
2234 static DropTrigStmt *
2235 _copyDropTrigStmt(DropTrigStmt *from)
2237 DropTrigStmt *newnode = makeNode(DropTrigStmt);
2240 newnode->trigname = pstrdup(from->trigname);
2242 newnode->relname = pstrdup(from->relname);
2247 static CreatePLangStmt *
2248 _copyCreatePLangStmt(CreatePLangStmt *from)
2250 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2253 newnode->plname = pstrdup(from->plname);
2254 if (from->plhandler)
2255 newnode->plhandler = pstrdup(from->plhandler);
2256 if (from->plcompiler)
2257 newnode->plcompiler = pstrdup(from->plcompiler);
2258 newnode->pltrusted = from->pltrusted;
2263 static DropPLangStmt *
2264 _copyDropPLangStmt(DropPLangStmt *from)
2266 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2269 newnode->plname = pstrdup(from->plname);
2274 static CreateUserStmt *
2275 _copyCreateUserStmt(CreateUserStmt *from)
2277 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2280 newnode->user = pstrdup(from->user);
2282 newnode->password = pstrdup(from->password);
2283 newnode->sysid = from->sysid;
2284 newnode->createdb = from->createdb;
2285 newnode->createuser = from->createuser;
2286 Node_Copy(from, newnode, groupElts);
2287 if (from->validUntil)
2288 newnode->validUntil = pstrdup(from->validUntil);
2293 static AlterUserStmt *
2294 _copyAlterUserStmt(AlterUserStmt *from)
2296 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2299 newnode->user = pstrdup(from->user);
2301 newnode->password = pstrdup(from->password);
2302 newnode->createdb = from->createdb;
2303 newnode->createuser = from->createuser;
2304 if (from->validUntil)
2305 newnode->validUntil = pstrdup(from->validUntil);
2310 static DropUserStmt *
2311 _copyDropUserStmt(DropUserStmt *from)
2313 DropUserStmt *newnode = makeNode(DropUserStmt);
2315 Node_Copy(from, newnode, users);
2321 _copyLockStmt(LockStmt *from)
2323 LockStmt *newnode = makeNode(LockStmt);
2326 newnode->relname = pstrdup(from->relname);
2327 newnode->mode = from->mode;
2332 static ConstraintsSetStmt *
2333 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2335 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2337 Node_Copy(from, newnode, constraints);
2338 newnode->deferred = from->deferred;
2343 static CreateGroupStmt *
2344 _copyCreateGroupStmt(CreateGroupStmt *from)
2346 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2349 newnode->name = pstrdup(from->name);
2350 newnode->sysid = from->sysid;
2351 Node_Copy(from, newnode, initUsers);
2356 static AlterGroupStmt *
2357 _copyAlterGroupStmt(AlterGroupStmt *from)
2359 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2362 newnode->name = pstrdup(from->name);
2363 newnode->action = from->action;
2364 newnode->sysid = from->sysid;
2365 Node_Copy(from, newnode, listUsers);
2370 static DropGroupStmt *
2371 _copyDropGroupStmt(DropGroupStmt *from)
2373 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2376 newnode->name = pstrdup(from->name);
2381 static ReindexStmt *
2382 _copyReindexStmt(ReindexStmt *from)
2384 ReindexStmt *newnode = makeNode(ReindexStmt);
2386 newnode->reindexType = from->reindexType;
2388 newnode->name = pstrdup(from->name);
2389 newnode->force = from->force;
2390 newnode->all = from->all;
2395 static SetSessionStmt *
2396 _copySetSessionStmt(SetSessionStmt *from)
2398 SetSessionStmt *newnode = makeNode(SetSessionStmt);
2400 Node_Copy(from, newnode, args);
2406 /* ****************************************************************
2407 * pg_list.h copy functions
2408 * ****************************************************************
2412 _copyValue(Value *from)
2414 Value *newnode = makeNode(Value);
2416 newnode->type = from->type;
2420 newnode->val.ival = from->val.ival;
2424 newnode->val.str = pstrdup(from->val.str);
2433 * copyObject returns a copy of the node or list. If it is a list, it
2434 * recursively copies its items.
2438 copyObject(void *from)
2445 switch (nodeTag(from))
2452 retval = _copyPlan(from);
2455 retval = _copyResult(from);
2458 retval = _copyAppend(from);
2461 retval = _copyScan(from);
2464 retval = _copySeqScan(from);
2467 retval = _copyIndexScan(from);
2470 retval = _copyTidScan(from);
2473 retval = _copyJoin(from);
2476 retval = _copyNestLoop(from);
2479 retval = _copyMergeJoin(from);
2482 retval = _copyHashJoin(from);
2485 retval = _copyMaterial(from);
2488 retval = _copySort(from);
2491 retval = _copyGroup(from);
2494 retval = _copyAgg(from);
2497 retval = _copyUnique(from);
2500 retval = _copyHash(from);
2503 retval = _copySubPlan(from);
2510 retval = _copyResdom(from);
2513 retval = _copyFjoin(from);
2516 retval = _copyExpr(from);
2519 retval = _copyVar(from);
2522 retval = _copyOper(from);
2525 retval = _copyConst(from);
2528 retval = _copyParam(from);
2531 retval = _copyAggref(from);
2534 retval = _copySubLink(from);
2537 retval = _copyFunc(from);
2540 retval = _copyArrayRef(from);
2543 retval = _copyIter(from);
2546 retval = _copyFieldSelect(from);
2549 retval = _copyRelabelType(from);
2556 retval = _copyRelOptInfo(from);
2559 retval = _copyPath(from);
2562 retval = _copyIndexPath(from);
2565 retval = _copyTidPath(from);
2568 retval = _copyNestPath(from);
2571 retval = _copyMergePath(from);
2574 retval = _copyHashPath(from);
2577 retval = _copyPathKeyItem(from);
2579 case T_RestrictInfo:
2580 retval = _copyRestrictInfo(from);
2583 retval = _copyJoinInfo(from);
2586 retval = _copyStream(from);
2588 case T_IndexOptInfo:
2589 retval = _copyIndexOptInfo(from);
2598 retval = _copyValue(from);
2606 /* rather ugly coding for speed... */
2607 /* Note the input list cannot be NIL if we got here. */
2608 nl = lcons(copyObject(lfirst(list)), NIL);
2611 foreach(l, lnext(list))
2613 lnext(nl) = lcons(copyObject(lfirst(l)), NIL);
2623 retval = _copyQuery(from);
2626 retval = _copyInsertStmt(from);
2629 retval = _copyDeleteStmt(from);
2632 retval = _copyUpdateStmt(from);
2635 retval = _copySelectStmt(from);
2637 case T_AlterTableStmt:
2638 retval = _copyAlterTableStmt(from);
2640 case T_ChangeACLStmt:
2641 retval = _copyChangeACLStmt(from);
2643 case T_ClosePortalStmt:
2644 retval = _copyClosePortalStmt(from);
2647 retval = _copyClusterStmt(from);
2650 retval = _copyCopyStmt(from);
2653 retval = _copyCreateStmt(from);
2656 retval = _copyVersionStmt(from);
2659 retval = _copyDefineStmt(from);
2662 retval = _copyDropStmt(from);
2664 case T_TruncateStmt:
2665 retval = _copyTruncateStmt(from);
2668 retval = _copyCommentStmt(from);
2671 retval = _copyExtendStmt(from);
2674 retval = _copyFetchStmt(from);
2677 retval = _copyIndexStmt(from);
2679 case T_ProcedureStmt:
2680 retval = _copyProcedureStmt(from);
2682 case T_RemoveAggrStmt:
2683 retval = _copyRemoveAggrStmt(from);
2685 case T_RemoveFuncStmt:
2686 retval = _copyRemoveFuncStmt(from);
2688 case T_RemoveOperStmt:
2689 retval = _copyRemoveOperStmt(from);
2692 retval = _copyRemoveStmt(from);
2695 retval = _copyRenameStmt(from);
2698 retval = _copyRuleStmt(from);
2701 retval = _copyNotifyStmt(from);
2704 retval = _copyListenStmt(from);
2706 case T_UnlistenStmt:
2707 retval = _copyUnlistenStmt(from);
2709 case T_TransactionStmt:
2710 retval = _copyTransactionStmt(from);
2713 retval = _copyViewStmt(from);
2716 retval = _copyLoadStmt(from);
2718 case T_CreatedbStmt:
2719 retval = _copyCreatedbStmt(from);
2722 retval = _copyDropdbStmt(from);
2725 retval = _copyVacuumStmt(from);
2728 retval = _copyExplainStmt(from);
2730 case T_CreateSeqStmt:
2731 retval = _copyCreateSeqStmt(from);
2733 case T_VariableSetStmt:
2734 retval = _copyVariableSetStmt(from);
2736 case T_VariableShowStmt:
2737 retval = _copyVariableShowStmt(from);
2739 case T_VariableResetStmt:
2740 retval = _copyVariableResetStmt(from);
2742 case T_CreateTrigStmt:
2743 retval = _copyCreateTrigStmt(from);
2745 case T_DropTrigStmt:
2746 retval = _copyDropTrigStmt(from);
2748 case T_CreatePLangStmt:
2749 retval = _copyCreatePLangStmt(from);
2751 case T_DropPLangStmt:
2752 retval = _copyDropPLangStmt(from);
2754 case T_CreateUserStmt:
2755 retval = _copyCreateUserStmt(from);
2757 case T_AlterUserStmt:
2758 retval = _copyAlterUserStmt(from);
2760 case T_DropUserStmt:
2761 retval = _copyDropUserStmt(from);
2764 retval = _copyLockStmt(from);
2766 case T_ConstraintsSetStmt:
2767 retval = _copyConstraintsSetStmt(from);
2769 case T_CreateGroupStmt:
2770 retval = _copyCreateGroupStmt(from);
2772 case T_AlterGroupStmt:
2773 retval = _copyAlterGroupStmt(from);
2775 case T_DropGroupStmt:
2776 retval = _copyDropGroupStmt(from);
2779 retval = _copyReindexStmt(from);
2781 case T_SetSessionStmt:
2782 retval = _copySetSessionStmt(from);
2786 retval = _copyAExpr(from);
2789 retval = _copyAttr(from);
2792 retval = _copyAConst(from);
2795 retval = _copyParamNo(from);
2798 retval = _copyIdent(from);
2801 retval = _copyFuncCall(from);
2804 retval = _copyAIndices(from);
2807 retval = _copyResTarget(from);
2810 retval = _copyTypeCast(from);
2813 retval = _copyRelExpr(from);
2816 retval = _copySortGroupBy(from);
2819 retval = _copyRangeVar(from);
2822 retval = _copyTypeName(from);
2825 retval = _copyIndexElem(from);
2828 retval = _copyColumnDef(from);
2831 retval = _copyConstraint(from);
2834 retval = _copyDefElem(from);
2837 retval = _copyTargetEntry(from);
2839 case T_RangeTblEntry:
2840 retval = _copyRangeTblEntry(from);
2843 retval = _copySortClause(from);
2846 retval = _copyGroupClause(from);
2849 retval = _copyJoinExpr(from);
2852 retval = _copyCaseExpr(from);
2855 retval = _copyCaseWhen(from);
2858 retval = _copyRowMark(from);
2860 case T_FkConstraint:
2861 retval = _copyFkConstraint(from);
2865 elog(ERROR, "copyObject: don't know how to copy node type %d",
2867 retval = from; /* keep compiler quiet */