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.122 2000/09/20 15:28:01 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)
314 newnode->jointype = from->jointype;
315 Node_Copy(from, newnode, joinqual);
316 /* subPlan list must point to subplans in the new subtree, not the old */
317 if (from->plan.subPlan != NIL)
318 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
319 pull_subplans((Node *) newnode->joinqual));
328 _copyJoin(Join *from)
330 Join *newnode = makeNode(Join);
333 * copy node superclass fields
336 CopyPlanFields((Plan *) from, (Plan *) newnode);
337 CopyJoinFields(from, newnode);
348 _copyNestLoop(NestLoop *from)
350 NestLoop *newnode = makeNode(NestLoop);
353 * copy node superclass fields
356 CopyPlanFields((Plan *) from, (Plan *) newnode);
357 CopyJoinFields((Join *) from, (Join *) newnode);
368 _copyMergeJoin(MergeJoin *from)
370 MergeJoin *newnode = makeNode(MergeJoin);
373 * copy node superclass fields
376 CopyPlanFields((Plan *) from, (Plan *) newnode);
377 CopyJoinFields((Join *) from, (Join *) newnode);
380 * copy remainder of node
383 Node_Copy(from, newnode, mergeclauses);
386 * We must add subplans in mergeclauses to the new plan's subPlan list
388 if (from->join.plan.subPlan != NIL)
389 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
390 pull_subplans((Node *) newnode->mergeclauses));
400 _copyHashJoin(HashJoin *from)
402 HashJoin *newnode = makeNode(HashJoin);
405 * copy node superclass fields
408 CopyPlanFields((Plan *) from, (Plan *) newnode);
409 CopyJoinFields((Join *) from, (Join *) newnode);
412 * copy remainder of node
415 Node_Copy(from, newnode, hashclauses);
416 newnode->hashjoinop = from->hashjoinop;
419 * We must add subplans in hashclauses to the new plan's subPlan list
421 if (from->join.plan.subPlan != NIL)
422 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
423 pull_subplans((Node *) newnode->hashclauses));
434 _copyMaterial(Material *from)
436 Material *newnode = makeNode(Material);
439 * copy node superclass fields
442 CopyPlanFields((Plan *) from, (Plan *) newnode);
453 _copySort(Sort *from)
455 Sort *newnode = makeNode(Sort);
458 * copy node superclass fields
461 CopyPlanFields((Plan *) from, (Plan *) newnode);
463 newnode->keycount = from->keycount;
474 _copyGroup(Group *from)
476 Group *newnode = makeNode(Group);
478 CopyPlanFields((Plan *) from, (Plan *) newnode);
480 newnode->tuplePerGroup = from->tuplePerGroup;
481 newnode->numCols = from->numCols;
482 newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
483 memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
495 Agg *newnode = makeNode(Agg);
497 CopyPlanFields((Plan *) from, (Plan *) newnode);
507 _copyGroupClause(GroupClause *from)
509 GroupClause *newnode = makeNode(GroupClause);
511 newnode->tleSortGroupRef = from->tleSortGroupRef;
512 newnode->sortop = from->sortop;
522 _copyUnique(Unique *from)
524 Unique *newnode = makeNode(Unique);
527 * copy node superclass fields
530 CopyPlanFields((Plan *) from, (Plan *) newnode);
533 * copy remainder of node
536 newnode->numCols = from->numCols;
537 newnode->uniqColIdx = palloc(from->numCols * sizeof(AttrNumber));
538 memcpy(newnode->uniqColIdx, from->uniqColIdx, from->numCols * sizeof(AttrNumber));
549 _copyHash(Hash *from)
551 Hash *newnode = makeNode(Hash);
554 * copy node superclass fields
557 CopyPlanFields((Plan *) from, (Plan *) newnode);
560 * copy remainder of node
563 Node_Copy(from, newnode, hashkey);
569 _copySubPlan(SubPlan *from)
571 SubPlan *newnode = makeNode(SubPlan);
573 Node_Copy(from, newnode, plan);
574 newnode->plan_id = from->plan_id;
575 Node_Copy(from, newnode, rtable);
576 newnode->setParam = listCopy(from->setParam);
577 newnode->parParam = listCopy(from->parParam);
578 Node_Copy(from, newnode, sublink);
580 /* do not copy execution state */
581 newnode->needShutdown = false;
582 newnode->curTuple = NULL;
587 /* ****************************************************************
588 * primnodes.h copy functions
589 * ****************************************************************
597 _copyResdom(Resdom *from)
599 Resdom *newnode = makeNode(Resdom);
601 newnode->resno = from->resno;
602 newnode->restype = from->restype;
603 newnode->restypmod = from->restypmod;
604 if (from->resname != NULL)
605 newnode->resname = pstrdup(from->resname);
606 newnode->ressortgroupref = from->ressortgroupref;
607 newnode->reskey = from->reskey;
608 newnode->reskeyop = from->reskeyop;
609 newnode->resjunk = from->resjunk;
615 _copyFjoin(Fjoin *from)
617 Fjoin *newnode = makeNode(Fjoin);
620 * copy node superclass fields
624 newnode->fj_initialized = from->fj_initialized;
625 newnode->fj_nNodes = from->fj_nNodes;
627 Node_Copy(from, newnode, fj_innerNode);
629 newnode->fj_results = (DatumPtr)
630 palloc((from->fj_nNodes) * sizeof(Datum));
631 memmove(from->fj_results,
633 (from->fj_nNodes) * sizeof(Datum));
635 newnode->fj_alwaysDone = (BoolPtr)
636 palloc((from->fj_nNodes) * sizeof(bool));
637 memmove(from->fj_alwaysDone,
638 newnode->fj_alwaysDone,
639 (from->fj_nNodes) * sizeof(bool));
650 _copyExpr(Expr *from)
652 Expr *newnode = makeNode(Expr);
655 * copy node superclass fields
658 newnode->typeOid = from->typeOid;
659 newnode->opType = from->opType;
661 Node_Copy(from, newnode, oper);
662 Node_Copy(from, newnode, args);
674 Var *newnode = makeNode(Var);
677 * copy remainder of node
680 newnode->varno = from->varno;
681 newnode->varattno = from->varattno;
682 newnode->vartype = from->vartype;
683 newnode->vartypmod = from->vartypmod;
684 newnode->varlevelsup = from->varlevelsup;
686 newnode->varnoold = from->varnoold;
687 newnode->varoattno = from->varoattno;
693 _copyAttr(Attr *from)
695 Attr *newnode = makeNode(Attr);
698 newnode->relname = pstrdup(from->relname);
699 Node_Copy(from, newnode, attrs);
709 _copyOper(Oper *from)
711 Oper *newnode = makeNode(Oper);
714 * copy remainder of node
717 newnode->opno = from->opno;
718 newnode->opid = from->opid;
719 newnode->opresulttype = from->opresulttype;
720 /* Do not copy the run-time state, if any */
721 newnode->op_fcache = NULL;
731 _copyConst(Const *from)
733 Const *newnode = makeNode(Const);
736 * copy remainder of node
739 newnode->consttype = from->consttype;
740 newnode->constlen = from->constlen;
742 if (from->constbyval || from->constisnull)
745 * passed by value so just copy the datum.
746 * Also, don't try to copy struct when value is null!
749 newnode->constvalue = from->constvalue;
754 * not passed by value. datum contains a pointer.
757 int length = from->constlen;
759 if (length == -1) /* variable-length type? */
760 length = VARSIZE(from->constvalue);
761 newnode->constvalue = PointerGetDatum(palloc(length));
762 memcpy(DatumGetPointer(newnode->constvalue),
763 DatumGetPointer(from->constvalue),
767 newnode->constisnull = from->constisnull;
768 newnode->constbyval = from->constbyval;
769 newnode->constisset = from->constisset;
770 newnode->constiscast = from->constiscast;
780 _copyParam(Param *from)
782 Param *newnode = makeNode(Param);
785 * copy remainder of node
788 newnode->paramkind = from->paramkind;
789 newnode->paramid = from->paramid;
791 if (from->paramname != NULL)
792 newnode->paramname = pstrdup(from->paramname);
793 newnode->paramtype = from->paramtype;
803 _copyFunc(Func *from)
805 Func *newnode = makeNode(Func);
808 * copy remainder of node
811 newnode->funcid = from->funcid;
812 newnode->functype = from->functype;
813 /* Do not copy the run-time state, if any */
814 newnode->func_fcache = NULL;
824 _copyAggref(Aggref *from)
826 Aggref *newnode = makeNode(Aggref);
829 * copy remainder of node
832 newnode->aggname = pstrdup(from->aggname);
833 newnode->basetype = from->basetype;
834 newnode->aggtype = from->aggtype;
835 Node_Copy(from, newnode, target);
836 newnode->aggstar = from->aggstar;
837 newnode->aggdistinct = from->aggdistinct;
838 newnode->aggno = from->aggno; /* probably not needed */
848 _copySubLink(SubLink *from)
850 SubLink *newnode = makeNode(SubLink);
853 * copy remainder of node
856 newnode->subLinkType = from->subLinkType;
857 newnode->useor = from->useor;
858 Node_Copy(from, newnode, lefthand);
859 Node_Copy(from, newnode, oper);
860 Node_Copy(from, newnode, subselect);
870 _copyFieldSelect(FieldSelect *from)
872 FieldSelect *newnode = makeNode(FieldSelect);
875 * copy remainder of node
878 Node_Copy(from, newnode, arg);
879 newnode->fieldnum = from->fieldnum;
880 newnode->resulttype = from->resulttype;
881 newnode->resulttypmod = from->resulttypmod;
891 _copyRelabelType(RelabelType *from)
893 RelabelType *newnode = makeNode(RelabelType);
896 * copy remainder of node
899 Node_Copy(from, newnode, arg);
900 newnode->resulttype = from->resulttype;
901 newnode->resulttypmod = from->resulttypmod;
907 _copyRangeTblRef(RangeTblRef *from)
909 RangeTblRef *newnode = makeNode(RangeTblRef);
911 newnode->rtindex = from->rtindex;
917 _copyJoinExpr(JoinExpr *from)
919 JoinExpr *newnode = makeNode(JoinExpr);
921 newnode->jointype = from->jointype;
922 newnode->isNatural = from->isNatural;
923 Node_Copy(from, newnode, larg);
924 Node_Copy(from, newnode, rarg);
925 Node_Copy(from, newnode, using);
926 Node_Copy(from, newnode, quals);
927 Node_Copy(from, newnode, alias);
928 Node_Copy(from, newnode, colnames);
929 Node_Copy(from, newnode, colvars);
939 _copyCaseExpr(CaseExpr *from)
941 CaseExpr *newnode = makeNode(CaseExpr);
944 * copy remainder of node
947 newnode->casetype = from->casetype;
949 Node_Copy(from, newnode, arg);
950 Node_Copy(from, newnode, args);
951 Node_Copy(from, newnode, defresult);
961 _copyCaseWhen(CaseWhen *from)
963 CaseWhen *newnode = makeNode(CaseWhen);
966 * copy remainder of node
969 Node_Copy(from, newnode, expr);
970 Node_Copy(from, newnode, result);
976 _copyArrayRef(ArrayRef *from)
978 ArrayRef *newnode = makeNode(ArrayRef);
981 * copy remainder of node
984 newnode->refattrlength = from->refattrlength;
985 newnode->refelemlength = from->refelemlength;
986 newnode->refelemtype = from->refelemtype;
987 newnode->refelembyval = from->refelembyval;
989 Node_Copy(from, newnode, refupperindexpr);
990 Node_Copy(from, newnode, reflowerindexpr);
991 Node_Copy(from, newnode, refexpr);
992 Node_Copy(from, newnode, refassgnexpr);
997 /* ****************************************************************
998 * relation.h copy functions
999 * ****************************************************************
1007 * when you change this, also make sure to fix up xfunc_copyRelOptInfo in
1008 * planner/path/xfunc.c accordingly!!!
1012 _copyRelOptInfo(RelOptInfo *from)
1014 RelOptInfo *newnode = makeNode(RelOptInfo);
1016 newnode->relids = listCopy(from->relids);
1018 newnode->rows = from->rows;
1019 newnode->width = from->width;
1021 Node_Copy(from, newnode, targetlist);
1022 Node_Copy(from, newnode, pathlist);
1023 /* XXX cheapest-path fields should point to members of pathlist? */
1024 Node_Copy(from, newnode, cheapest_startup_path);
1025 Node_Copy(from, newnode, cheapest_total_path);
1026 newnode->pruneable = from->pruneable;
1028 newnode->indexed = from->indexed;
1029 newnode->pages = from->pages;
1030 newnode->tuples = from->tuples;
1032 Node_Copy(from, newnode, baserestrictinfo);
1033 newnode->baserestrictcost = from->baserestrictcost;
1034 newnode->outerjoinset = listCopy(from->outerjoinset);
1035 Node_Copy(from, newnode, joininfo);
1036 Node_Copy(from, newnode, innerjoin);
1045 static IndexOptInfo *
1046 _copyIndexOptInfo(IndexOptInfo *from)
1048 IndexOptInfo *newnode = makeNode(IndexOptInfo);
1052 newnode->indexoid = from->indexoid;
1053 newnode->pages = from->pages;
1054 newnode->tuples = from->tuples;
1056 if (from->classlist)
1058 for (len = 0; from->classlist[len] != 0; len++)
1060 newnode->classlist = (Oid *) palloc(sizeof(Oid) * (len + 1));
1061 for (i = 0; i < len; i++)
1062 newnode->classlist[i] = from->classlist[i];
1063 newnode->classlist[len] = 0;
1066 if (from->indexkeys)
1068 for (len = 0; from->indexkeys[len] != 0; len++)
1070 newnode->indexkeys = (int *) palloc(sizeof(int) * (len + 1));
1071 for (i = 0; i < len; i++)
1072 newnode->indexkeys[i] = from->indexkeys[i];
1073 newnode->indexkeys[len] = 0;
1078 for (len = 0; from->ordering[len] != 0; len++)
1080 newnode->ordering = (Oid *) palloc(sizeof(Oid) * (len + 1));
1081 for (i = 0; i < len; i++)
1082 newnode->ordering[i] = from->ordering[i];
1083 newnode->ordering[len] = 0;
1086 newnode->relam = from->relam;
1087 newnode->amcostestimate = from->amcostestimate;
1088 newnode->indproc = from->indproc;
1089 Node_Copy(from, newnode, indpred);
1090 newnode->lossy = from->lossy;
1098 * This function copies the fields of the Path node. It is used by
1099 * all the copy functions for classes which inherit from Path.
1103 CopyPathFields(Path *from, Path *newnode)
1107 * Modify the next line, since it causes the copying to cycle (i.e.
1108 * the parent points right back here! -- JMH, 7/7/92. Old version:
1109 * Node_Copy(from, newnode, parent);
1111 newnode->parent = from->parent;
1113 newnode->startup_cost = from->startup_cost;
1114 newnode->total_cost = from->total_cost;
1116 newnode->pathtype = from->pathtype;
1118 Node_Copy(from, newnode, pathkeys);
1126 _copyPath(Path *from)
1128 Path *newnode = makeNode(Path);
1130 CopyPathFields(from, newnode);
1140 _copyIndexPath(IndexPath *from)
1142 IndexPath *newnode = makeNode(IndexPath);
1145 * copy the node superclass fields
1148 CopyPathFields((Path *) from, (Path *) newnode);
1151 * copy remainder of node
1154 newnode->indexid = listCopy(from->indexid);
1155 Node_Copy(from, newnode, indexqual);
1156 newnode->indexscandir = from->indexscandir;
1157 newnode->joinrelids = listCopy(from->joinrelids);
1158 newnode->alljoinquals = from->alljoinquals;
1159 newnode->rows = from->rows;
1169 _copyTidPath(TidPath *from)
1171 TidPath *newnode = makeNode(TidPath);
1174 * copy the node superclass fields
1177 CopyPathFields((Path *) from, (Path *) newnode);
1180 * copy remainder of node
1183 Node_Copy(from, newnode, tideval);
1184 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1190 * CopyJoinPathFields
1192 * This function copies the fields of the JoinPath node. It is used by
1193 * all the copy functions for classes which inherit from JoinPath.
1197 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1199 newnode->jointype = from->jointype;
1200 Node_Copy(from, newnode, outerjoinpath);
1201 Node_Copy(from, newnode, innerjoinpath);
1202 Node_Copy(from, newnode, joinrestrictinfo);
1210 _copyNestPath(NestPath *from)
1212 NestPath *newnode = makeNode(NestPath);
1215 * copy the node superclass fields
1218 CopyPathFields((Path *) from, (Path *) newnode);
1219 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1229 _copyMergePath(MergePath *from)
1231 MergePath *newnode = makeNode(MergePath);
1234 * copy the node superclass fields
1237 CopyPathFields((Path *) from, (Path *) newnode);
1238 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1241 * copy the remainder of the node
1244 Node_Copy(from, newnode, path_mergeclauses);
1245 Node_Copy(from, newnode, outersortkeys);
1246 Node_Copy(from, newnode, innersortkeys);
1256 _copyHashPath(HashPath *from)
1258 HashPath *newnode = makeNode(HashPath);
1261 * copy the node superclass fields
1264 CopyPathFields((Path *) from, (Path *) newnode);
1265 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1268 * copy remainder of node
1271 Node_Copy(from, newnode, path_hashclauses);
1280 static PathKeyItem *
1281 _copyPathKeyItem(PathKeyItem *from)
1283 PathKeyItem *newnode = makeNode(PathKeyItem);
1286 * copy remainder of node
1289 Node_Copy(from, newnode, key);
1290 newnode->sortop = from->sortop;
1299 static RestrictInfo *
1300 _copyRestrictInfo(RestrictInfo *from)
1302 RestrictInfo *newnode = makeNode(RestrictInfo);
1305 * copy remainder of node
1308 Node_Copy(from, newnode, clause);
1309 newnode->isjoinqual = from->isjoinqual;
1310 Node_Copy(from, newnode, subclauseindices);
1311 newnode->mergejoinoperator = from->mergejoinoperator;
1312 newnode->left_sortop = from->left_sortop;
1313 newnode->right_sortop = from->right_sortop;
1314 newnode->hashjoinoperator = from->hashjoinoperator;
1324 _copyJoinInfo(JoinInfo *from)
1326 JoinInfo *newnode = makeNode(JoinInfo);
1329 * copy remainder of node
1332 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1333 Node_Copy(from, newnode, jinfo_restrictinfo);
1339 _copyIter(Iter *from)
1341 Iter *newnode = makeNode(Iter);
1343 Node_Copy(from, newnode, iterexpr);
1344 newnode->itertype = from->itertype;
1350 _copyStream(Stream *from)
1352 Stream *newnode = makeNode(Stream);
1354 newnode->pathptr = from->pathptr;
1355 newnode->cinfo = from->cinfo;
1356 newnode->clausetype = from->clausetype;
1358 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1360 Node_Copy(from, newnode, downstream);
1361 if (newnode->downstream)
1362 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1364 newnode->groupup = from->groupup;
1365 newnode->groupcost = from->groupcost;
1366 newnode->groupsel = from->groupsel;
1371 /* ****************************************************************
1372 * parsenodes.h copy functions
1373 * ****************************************************************
1376 static TargetEntry *
1377 _copyTargetEntry(TargetEntry *from)
1379 TargetEntry *newnode = makeNode(TargetEntry);
1381 Node_Copy(from, newnode, resdom);
1382 Node_Copy(from, newnode, fjoin);
1383 Node_Copy(from, newnode, expr);
1387 static RangeTblEntry *
1388 _copyRangeTblEntry(RangeTblEntry *from)
1390 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1393 newnode->relname = pstrdup(from->relname);
1394 newnode->relid = from->relid;
1395 Node_Copy(from, newnode, alias);
1396 Node_Copy(from, newnode, eref);
1397 newnode->inh = from->inh;
1398 newnode->inFromCl = from->inFromCl;
1399 newnode->skipAcl = from->skipAcl;
1405 _copyRowMark(RowMark *from)
1407 RowMark *newnode = makeNode(RowMark);
1409 newnode->rti = from->rti;
1410 newnode->info = from->info;
1415 static FkConstraint *
1416 _copyFkConstraint(FkConstraint *from)
1418 FkConstraint *newnode = makeNode(FkConstraint);
1420 if (from->constr_name)
1421 newnode->constr_name = pstrdup(from->constr_name);
1422 if (from->pktable_name)
1423 newnode->pktable_name = pstrdup(from->pktable_name);
1424 Node_Copy(from, newnode, fk_attrs);
1425 Node_Copy(from, newnode, pk_attrs);
1426 if (from->match_type)
1427 newnode->match_type = pstrdup(from->match_type);
1428 newnode->actions = from->actions;
1429 newnode->deferrable = from->deferrable;
1430 newnode->initdeferred = from->initdeferred;
1436 _copySortClause(SortClause *from)
1438 SortClause *newnode = makeNode(SortClause);
1440 newnode->tleSortGroupRef = from->tleSortGroupRef;
1441 newnode->sortop = from->sortop;
1447 _copyAExpr(A_Expr *from)
1449 A_Expr *newnode = makeNode(A_Expr);
1451 newnode->oper = from->oper;
1453 newnode->opname = pstrdup(from->opname);
1454 Node_Copy(from, newnode, lexpr);
1455 Node_Copy(from, newnode, rexpr);
1461 _copyAConst(A_Const *from)
1463 A_Const *newnode = makeNode(A_Const);
1465 newnode->val = *((Value *) (copyObject(&(from->val))));
1466 Node_Copy(from, newnode, typename);
1472 _copyParamNo(ParamNo *from)
1474 ParamNo *newnode = makeNode(ParamNo);
1476 newnode->number = from->number;
1477 Node_Copy(from, newnode, typename);
1478 Node_Copy(from, newnode, indirection);
1484 _copyIdent(Ident *from)
1486 Ident *newnode = makeNode(Ident);
1489 newnode->name = pstrdup(from->name);
1490 Node_Copy(from, newnode, indirection);
1491 newnode->isRel = from->isRel;
1497 _copyFuncCall(FuncCall *from)
1499 FuncCall *newnode = makeNode(FuncCall);
1502 newnode->funcname = pstrdup(from->funcname);
1503 Node_Copy(from, newnode, args);
1504 newnode->agg_star = from->agg_star;
1505 newnode->agg_distinct = from->agg_distinct;
1511 _copyAIndices(A_Indices *from)
1513 A_Indices *newnode = makeNode(A_Indices);
1515 Node_Copy(from, newnode, lidx);
1516 Node_Copy(from, newnode, uidx);
1522 _copyResTarget(ResTarget *from)
1524 ResTarget *newnode = makeNode(ResTarget);
1527 newnode->name = pstrdup(from->name);
1528 Node_Copy(from, newnode, indirection);
1529 Node_Copy(from, newnode, val);
1535 _copyTypeName(TypeName *from)
1537 TypeName *newnode = makeNode(TypeName);
1540 newnode->name = pstrdup(from->name);
1541 newnode->timezone = from->timezone;
1542 newnode->setof = from->setof;
1543 newnode->typmod = from->typmod;
1544 Node_Copy(from, newnode, arrayBounds);
1549 static SortGroupBy *
1550 _copySortGroupBy(SortGroupBy *from)
1552 SortGroupBy *newnode = makeNode(SortGroupBy);
1555 newnode->useOp = pstrdup(from->useOp);
1556 Node_Copy(from, newnode, node);
1562 _copyRangeVar(RangeVar *from)
1564 RangeVar *newnode = makeNode(RangeVar);
1567 newnode->relname = pstrdup(from->relname);
1568 newnode->inh = from->inh;
1569 Node_Copy(from, newnode, name);
1574 static RangeSubselect *
1575 _copyRangeSubselect(RangeSubselect *from)
1577 RangeSubselect *newnode = makeNode(RangeSubselect);
1579 Node_Copy(from, newnode, subquery);
1580 Node_Copy(from, newnode, name);
1586 _copyTypeCast(TypeCast *from)
1588 TypeCast *newnode = makeNode(TypeCast);
1590 Node_Copy(from, newnode, arg);
1591 Node_Copy(from, newnode, typename);
1597 _copyIndexElem(IndexElem *from)
1599 IndexElem *newnode = makeNode(IndexElem);
1602 newnode->name = pstrdup(from->name);
1603 Node_Copy(from, newnode, args);
1605 newnode->class = pstrdup(from->class);
1611 _copyColumnDef(ColumnDef *from)
1613 ColumnDef *newnode = makeNode(ColumnDef);
1616 newnode->colname = pstrdup(from->colname);
1617 Node_Copy(from, newnode, typename);
1618 newnode->is_not_null = from->is_not_null;
1619 newnode->is_sequence = from->is_sequence;
1620 Node_Copy(from, newnode, raw_default);
1621 if (from->cooked_default)
1622 newnode->cooked_default = pstrdup(from->cooked_default);
1623 Node_Copy(from, newnode, constraints);
1629 _copyConstraint(Constraint *from)
1631 Constraint *newnode = makeNode(Constraint);
1633 newnode->contype = from->contype;
1635 newnode->name = pstrdup(from->name);
1636 Node_Copy(from, newnode, raw_expr);
1637 if (from->cooked_expr)
1638 newnode->cooked_expr = pstrdup(from->cooked_expr);
1639 Node_Copy(from, newnode, keys);
1645 _copyDefElem(DefElem *from)
1647 DefElem *newnode = makeNode(DefElem);
1650 newnode->defname = pstrdup(from->defname);
1651 Node_Copy(from, newnode, arg);
1657 _copyQuery(Query *from)
1659 Query *newnode = makeNode(Query);
1661 newnode->commandType = from->commandType;
1662 Node_Copy(from, newnode, utilityStmt);
1663 newnode->resultRelation = from->resultRelation;
1665 newnode->into = pstrdup(from->into);
1666 newnode->isPortal = from->isPortal;
1667 newnode->isBinary = from->isBinary;
1668 newnode->isTemp = from->isTemp;
1669 newnode->unionall = from->unionall;
1670 newnode->hasAggs = from->hasAggs;
1671 newnode->hasSubLinks = from->hasSubLinks;
1673 Node_Copy(from, newnode, rtable);
1674 Node_Copy(from, newnode, jointree);
1676 Node_Copy(from, newnode, targetList);
1677 Node_Copy(from, newnode, qual);
1678 Node_Copy(from, newnode, rowMark);
1680 Node_Copy(from, newnode, distinctClause);
1681 Node_Copy(from, newnode, sortClause);
1682 Node_Copy(from, newnode, groupClause);
1683 Node_Copy(from, newnode, havingQual);
1685 /* why is intersectClause missing? */
1686 Node_Copy(from, newnode, unionClause);
1688 Node_Copy(from, newnode, limitOffset);
1689 Node_Copy(from, newnode, limitCount);
1692 * We do not copy the planner internal fields: base_rel_list,
1693 * join_rel_list, equi_key_list, query_pathkeys. Not entirely clear if
1701 _copyInsertStmt(InsertStmt *from)
1703 InsertStmt *newnode = makeNode(InsertStmt);
1706 newnode->relname = pstrdup(from->relname);
1707 Node_Copy(from, newnode, distinctClause);
1708 Node_Copy(from, newnode, cols);
1709 Node_Copy(from, newnode, targetList);
1710 Node_Copy(from, newnode, fromClause);
1711 Node_Copy(from, newnode, whereClause);
1712 Node_Copy(from, newnode, groupClause);
1713 Node_Copy(from, newnode, havingClause);
1714 Node_Copy(from, newnode, unionClause);
1715 newnode->unionall = from->unionall;
1716 Node_Copy(from, newnode, intersectClause);
1717 Node_Copy(from, newnode, forUpdate);
1723 _copyDeleteStmt(DeleteStmt *from)
1725 DeleteStmt *newnode = makeNode(DeleteStmt);
1728 newnode->relname = pstrdup(from->relname);
1729 Node_Copy(from, newnode, whereClause);
1730 newnode->inh = from->inh;
1736 _copyUpdateStmt(UpdateStmt *from)
1738 UpdateStmt *newnode = makeNode(UpdateStmt);
1741 newnode->relname = pstrdup(from->relname);
1742 Node_Copy(from, newnode, targetList);
1743 Node_Copy(from, newnode, whereClause);
1744 Node_Copy(from, newnode, fromClause);
1745 newnode->inh = from->inh;
1751 _copySelectStmt(SelectStmt *from)
1753 SelectStmt *newnode = makeNode(SelectStmt);
1755 Node_Copy(from, newnode, distinctClause);
1757 newnode->into = pstrdup(from->into);
1758 Node_Copy(from, newnode, targetList);
1759 Node_Copy(from, newnode, fromClause);
1760 Node_Copy(from, newnode, whereClause);
1761 Node_Copy(from, newnode, groupClause);
1762 Node_Copy(from, newnode, havingClause);
1763 Node_Copy(from, newnode, intersectClause);
1764 Node_Copy(from, newnode, exceptClause);
1765 Node_Copy(from, newnode, unionClause);
1766 Node_Copy(from, newnode, sortClause);
1767 if (from->portalname)
1768 newnode->portalname = pstrdup(from->portalname);
1769 newnode->binary = from->binary;
1770 newnode->istemp = from->istemp;
1771 newnode->unionall = from->unionall;
1772 Node_Copy(from, newnode, limitOffset);
1773 Node_Copy(from, newnode, limitCount);
1774 Node_Copy(from, newnode, forUpdate);
1779 static AlterTableStmt *
1780 _copyAlterTableStmt(AlterTableStmt *from)
1782 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1784 newnode->subtype = from->subtype;
1786 newnode->relname = pstrdup(from->relname);
1787 newnode->inh = from->inh;
1789 newnode->name = pstrdup(from->name);
1790 Node_Copy(from, newnode, def);
1791 newnode->behavior = from->behavior;
1796 static ChangeACLStmt *
1797 _copyChangeACLStmt(ChangeACLStmt *from)
1799 ChangeACLStmt *newnode = makeNode(ChangeACLStmt);
1803 newnode->aclitem = (struct AclItem *) palloc(sizeof(struct AclItem));
1804 memcpy(newnode->aclitem, from->aclitem, sizeof(struct AclItem));
1806 newnode->modechg = from->modechg;
1807 Node_Copy(from, newnode, relNames);
1812 static ClosePortalStmt *
1813 _copyClosePortalStmt(ClosePortalStmt *from)
1815 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1817 if (from->portalname)
1818 newnode->portalname = pstrdup(from->portalname);
1823 static ClusterStmt *
1824 _copyClusterStmt(ClusterStmt *from)
1826 ClusterStmt *newnode = makeNode(ClusterStmt);
1829 newnode->relname = pstrdup(from->relname);
1830 if (from->indexname)
1831 newnode->indexname = pstrdup(from->indexname);
1837 _copyCopyStmt(CopyStmt *from)
1839 CopyStmt *newnode = makeNode(CopyStmt);
1841 newnode->binary = from->binary;
1843 newnode->relname = pstrdup(from->relname);
1844 newnode->oids = from->oids;
1845 newnode->direction = from->direction;
1847 newnode->filename = pstrdup(from->filename);
1848 if (from->delimiter)
1849 newnode->delimiter = pstrdup(from->delimiter);
1850 if (from->null_print)
1851 newnode->null_print = pstrdup(from->null_print);
1857 _copyCreateStmt(CreateStmt *from)
1859 CreateStmt *newnode = makeNode(CreateStmt);
1861 newnode->istemp = from->istemp;
1862 newnode->relname = pstrdup(from->relname);
1863 Node_Copy(from, newnode, tableElts);
1864 Node_Copy(from, newnode, inhRelnames);
1865 Node_Copy(from, newnode, constraints);
1870 static VersionStmt *
1871 _copyVersionStmt(VersionStmt *from)
1873 VersionStmt *newnode = makeNode(VersionStmt);
1875 newnode->relname = pstrdup(from->relname);
1876 newnode->direction = from->direction;
1877 newnode->fromRelname = pstrdup(from->fromRelname);
1878 newnode->date = pstrdup(from->date);
1884 _copyDefineStmt(DefineStmt *from)
1886 DefineStmt *newnode = makeNode(DefineStmt);
1888 newnode->defType = from->defType;
1889 newnode->defname = pstrdup(from->defname);
1890 Node_Copy(from, newnode, definition);
1896 _copyDropStmt(DropStmt *from)
1898 DropStmt *newnode = makeNode(DropStmt);
1900 Node_Copy(from, newnode, relNames);
1901 newnode->sequence = from->sequence;
1906 static TruncateStmt *
1907 _copyTruncateStmt(TruncateStmt *from)
1909 TruncateStmt *newnode = makeNode(TruncateStmt);
1911 newnode->relName = pstrdup(from->relName);
1916 static CommentStmt *
1917 _copyCommentStmt(CommentStmt *from)
1919 CommentStmt *newnode = makeNode(CommentStmt);
1921 newnode->objtype = from->objtype;
1922 newnode->objname = pstrdup(from->objname);
1923 if (from->objproperty)
1924 newnode->objproperty = pstrdup(from->objproperty);
1925 Node_Copy(from, newnode, objlist);
1926 newnode->comment = pstrdup(from->comment);
1932 _copyExtendStmt(ExtendStmt *from)
1934 ExtendStmt *newnode = makeNode(ExtendStmt);
1936 newnode->idxname = pstrdup(from->idxname);
1937 Node_Copy(from, newnode, whereClause);
1938 Node_Copy(from, newnode, rangetable);
1944 _copyFetchStmt(FetchStmt *from)
1946 FetchStmt *newnode = makeNode(FetchStmt);
1948 newnode->direction = from->direction;
1949 newnode->howMany = from->howMany;
1950 newnode->portalname = pstrdup(from->portalname);
1951 newnode->ismove = from->ismove;
1957 _copyIndexStmt(IndexStmt *from)
1959 IndexStmt *newnode = makeNode(IndexStmt);
1961 newnode->idxname = pstrdup(from->idxname);
1962 newnode->relname = pstrdup(from->relname);
1963 newnode->accessMethod = pstrdup(from->accessMethod);
1964 Node_Copy(from, newnode, indexParams);
1965 Node_Copy(from, newnode, withClause);
1966 Node_Copy(from, newnode, whereClause);
1967 Node_Copy(from, newnode, rangetable);
1968 newnode->unique = from->unique;
1969 newnode->primary = from->primary;
1974 static ProcedureStmt *
1975 _copyProcedureStmt(ProcedureStmt *from)
1977 ProcedureStmt *newnode = makeNode(ProcedureStmt);
1979 newnode->funcname = pstrdup(from->funcname);
1980 Node_Copy(from, newnode, defArgs);
1981 Node_Copy(from, newnode, returnType);
1982 Node_Copy(from, newnode, withClause);
1983 Node_Copy(from, newnode, as);
1984 newnode->language = pstrdup(from->language);
1989 static RemoveAggrStmt *
1990 _copyRemoveAggrStmt(RemoveAggrStmt *from)
1992 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1994 newnode->aggname = pstrdup(from->aggname);
1995 newnode->aggtype = pstrdup(from->aggtype);
2000 static RemoveFuncStmt *
2001 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2003 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2005 newnode->funcname = pstrdup(from->funcname);
2006 Node_Copy(from, newnode, args);
2011 static RemoveOperStmt *
2012 _copyRemoveOperStmt(RemoveOperStmt *from)
2014 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2016 newnode->opname = pstrdup(from->opname);
2017 Node_Copy(from, newnode, args);
2023 _copyRemoveStmt(RemoveStmt *from)
2025 RemoveStmt *newnode = makeNode(RemoveStmt);
2027 newnode->removeType = from->removeType;
2028 newnode->name = pstrdup(from->name);
2034 _copyRenameStmt(RenameStmt *from)
2036 RenameStmt *newnode = makeNode(RenameStmt);
2038 newnode->relname = pstrdup(from->relname);
2039 newnode->inh = from->inh;
2041 newnode->column = pstrdup(from->column);
2043 newnode->newname = pstrdup(from->newname);
2049 _copyRuleStmt(RuleStmt *from)
2051 RuleStmt *newnode = makeNode(RuleStmt);
2053 newnode->rulename = pstrdup(from->rulename);
2054 Node_Copy(from, newnode, whereClause);
2055 newnode->event = from->event;
2056 Node_Copy(from, newnode, object);
2057 newnode->instead = from->instead;
2058 Node_Copy(from, newnode, actions);
2064 _copyNotifyStmt(NotifyStmt *from)
2066 NotifyStmt *newnode = makeNode(NotifyStmt);
2069 newnode->relname = pstrdup(from->relname);
2075 _copyListenStmt(ListenStmt *from)
2077 ListenStmt *newnode = makeNode(ListenStmt);
2080 newnode->relname = pstrdup(from->relname);
2085 static UnlistenStmt *
2086 _copyUnlistenStmt(UnlistenStmt *from)
2088 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2091 newnode->relname = pstrdup(from->relname);
2096 static TransactionStmt *
2097 _copyTransactionStmt(TransactionStmt *from)
2099 TransactionStmt *newnode = makeNode(TransactionStmt);
2101 newnode->command = from->command;
2107 _copyViewStmt(ViewStmt *from)
2109 ViewStmt *newnode = makeNode(ViewStmt);
2112 newnode->viewname = pstrdup(from->viewname);
2113 Node_Copy(from, newnode, aliases);
2114 Node_Copy(from, newnode, query);
2120 _copyLoadStmt(LoadStmt *from)
2122 LoadStmt *newnode = makeNode(LoadStmt);
2125 newnode->filename = pstrdup(from->filename);
2130 static CreatedbStmt *
2131 _copyCreatedbStmt(CreatedbStmt *from)
2133 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2136 newnode->dbname = pstrdup(from->dbname);
2138 newnode->dbpath = pstrdup(from->dbpath);
2139 newnode->encoding = from->encoding;
2145 _copyDropdbStmt(DropdbStmt *from)
2147 DropdbStmt *newnode = makeNode(DropdbStmt);
2150 newnode->dbname = pstrdup(from->dbname);
2156 _copyVacuumStmt(VacuumStmt *from)
2158 VacuumStmt *newnode = makeNode(VacuumStmt);
2160 newnode->verbose = from->verbose;
2161 newnode->analyze = from->analyze;
2163 newnode->vacrel = pstrdup(from->vacrel);
2164 Node_Copy(from, newnode, va_spec);
2169 static ExplainStmt *
2170 _copyExplainStmt(ExplainStmt *from)
2172 ExplainStmt *newnode = makeNode(ExplainStmt);
2174 Node_Copy(from, newnode, query);
2175 newnode->verbose = from->verbose;
2180 static CreateSeqStmt *
2181 _copyCreateSeqStmt(CreateSeqStmt *from)
2183 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2186 newnode->seqname = pstrdup(from->seqname);
2187 Node_Copy(from, newnode, options);
2192 static VariableSetStmt *
2193 _copyVariableSetStmt(VariableSetStmt *from)
2195 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2198 newnode->name = pstrdup(from->name);
2200 newnode->value = pstrdup(from->value);
2205 static VariableShowStmt *
2206 _copyVariableShowStmt(VariableShowStmt *from)
2208 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2211 newnode->name = pstrdup(from->name);
2216 static VariableResetStmt *
2217 _copyVariableResetStmt(VariableResetStmt *from)
2219 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2222 newnode->name = pstrdup(from->name);
2227 static CreateTrigStmt *
2228 _copyCreateTrigStmt(CreateTrigStmt *from)
2230 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2233 newnode->trigname = pstrdup(from->trigname);
2235 newnode->relname = pstrdup(from->relname);
2237 newnode->funcname = pstrdup(from->funcname);
2238 Node_Copy(from, newnode, args);
2239 newnode->before = from->before;
2240 newnode->row = from->row;
2241 memcpy(newnode->actions, from->actions, sizeof(from->actions));
2243 newnode->lang = pstrdup(from->lang);
2245 newnode->text = pstrdup(from->text);
2246 Node_Copy(from, newnode, attr);
2248 newnode->when = pstrdup(from->when);
2249 newnode->isconstraint = from->isconstraint;
2250 newnode->deferrable = from->deferrable;
2251 newnode->initdeferred = from->initdeferred;
2252 if (from->constrrelname)
2253 newnode->constrrelname = pstrdup(from->constrrelname);
2258 static DropTrigStmt *
2259 _copyDropTrigStmt(DropTrigStmt *from)
2261 DropTrigStmt *newnode = makeNode(DropTrigStmt);
2264 newnode->trigname = pstrdup(from->trigname);
2266 newnode->relname = pstrdup(from->relname);
2271 static CreatePLangStmt *
2272 _copyCreatePLangStmt(CreatePLangStmt *from)
2274 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2277 newnode->plname = pstrdup(from->plname);
2278 if (from->plhandler)
2279 newnode->plhandler = pstrdup(from->plhandler);
2280 if (from->plcompiler)
2281 newnode->plcompiler = pstrdup(from->plcompiler);
2282 newnode->pltrusted = from->pltrusted;
2287 static DropPLangStmt *
2288 _copyDropPLangStmt(DropPLangStmt *from)
2290 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2293 newnode->plname = pstrdup(from->plname);
2298 static CreateUserStmt *
2299 _copyCreateUserStmt(CreateUserStmt *from)
2301 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2304 newnode->user = pstrdup(from->user);
2306 newnode->password = pstrdup(from->password);
2307 newnode->sysid = from->sysid;
2308 newnode->createdb = from->createdb;
2309 newnode->createuser = from->createuser;
2310 Node_Copy(from, newnode, groupElts);
2311 if (from->validUntil)
2312 newnode->validUntil = pstrdup(from->validUntil);
2317 static AlterUserStmt *
2318 _copyAlterUserStmt(AlterUserStmt *from)
2320 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2323 newnode->user = pstrdup(from->user);
2325 newnode->password = pstrdup(from->password);
2326 newnode->createdb = from->createdb;
2327 newnode->createuser = from->createuser;
2328 if (from->validUntil)
2329 newnode->validUntil = pstrdup(from->validUntil);
2334 static DropUserStmt *
2335 _copyDropUserStmt(DropUserStmt *from)
2337 DropUserStmt *newnode = makeNode(DropUserStmt);
2339 Node_Copy(from, newnode, users);
2345 _copyLockStmt(LockStmt *from)
2347 LockStmt *newnode = makeNode(LockStmt);
2350 newnode->relname = pstrdup(from->relname);
2351 newnode->mode = from->mode;
2356 static ConstraintsSetStmt *
2357 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2359 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2361 Node_Copy(from, newnode, constraints);
2362 newnode->deferred = from->deferred;
2367 static CreateGroupStmt *
2368 _copyCreateGroupStmt(CreateGroupStmt *from)
2370 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2373 newnode->name = pstrdup(from->name);
2374 newnode->sysid = from->sysid;
2375 Node_Copy(from, newnode, initUsers);
2380 static AlterGroupStmt *
2381 _copyAlterGroupStmt(AlterGroupStmt *from)
2383 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2386 newnode->name = pstrdup(from->name);
2387 newnode->action = from->action;
2388 newnode->sysid = from->sysid;
2389 Node_Copy(from, newnode, listUsers);
2394 static DropGroupStmt *
2395 _copyDropGroupStmt(DropGroupStmt *from)
2397 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2400 newnode->name = pstrdup(from->name);
2405 static ReindexStmt *
2406 _copyReindexStmt(ReindexStmt *from)
2408 ReindexStmt *newnode = makeNode(ReindexStmt);
2410 newnode->reindexType = from->reindexType;
2412 newnode->name = pstrdup(from->name);
2413 newnode->force = from->force;
2414 newnode->all = from->all;
2419 static SetSessionStmt *
2420 _copySetSessionStmt(SetSessionStmt *from)
2422 SetSessionStmt *newnode = makeNode(SetSessionStmt);
2424 Node_Copy(from, newnode, args);
2430 /* ****************************************************************
2431 * pg_list.h copy functions
2432 * ****************************************************************
2436 _copyValue(Value *from)
2438 Value *newnode = makeNode(Value);
2440 newnode->type = from->type;
2444 newnode->val.ival = from->val.ival;
2448 newnode->val.str = pstrdup(from->val.str);
2457 * copyObject returns a copy of the node or list. If it is a list, it
2458 * recursively copies its items.
2462 copyObject(void *from)
2469 switch (nodeTag(from))
2476 retval = _copyPlan(from);
2479 retval = _copyResult(from);
2482 retval = _copyAppend(from);
2485 retval = _copyScan(from);
2488 retval = _copySeqScan(from);
2491 retval = _copyIndexScan(from);
2494 retval = _copyTidScan(from);
2497 retval = _copyJoin(from);
2500 retval = _copyNestLoop(from);
2503 retval = _copyMergeJoin(from);
2506 retval = _copyHashJoin(from);
2509 retval = _copyMaterial(from);
2512 retval = _copySort(from);
2515 retval = _copyGroup(from);
2518 retval = _copyAgg(from);
2521 retval = _copyUnique(from);
2524 retval = _copyHash(from);
2527 retval = _copySubPlan(from);
2534 retval = _copyResdom(from);
2537 retval = _copyFjoin(from);
2540 retval = _copyExpr(from);
2543 retval = _copyVar(from);
2546 retval = _copyOper(from);
2549 retval = _copyConst(from);
2552 retval = _copyParam(from);
2555 retval = _copyAggref(from);
2558 retval = _copySubLink(from);
2561 retval = _copyFunc(from);
2564 retval = _copyArrayRef(from);
2567 retval = _copyIter(from);
2570 retval = _copyFieldSelect(from);
2573 retval = _copyRelabelType(from);
2576 retval = _copyRangeTblRef(from);
2579 retval = _copyJoinExpr(from);
2586 retval = _copyRelOptInfo(from);
2589 retval = _copyPath(from);
2592 retval = _copyIndexPath(from);
2595 retval = _copyTidPath(from);
2598 retval = _copyNestPath(from);
2601 retval = _copyMergePath(from);
2604 retval = _copyHashPath(from);
2607 retval = _copyPathKeyItem(from);
2609 case T_RestrictInfo:
2610 retval = _copyRestrictInfo(from);
2613 retval = _copyJoinInfo(from);
2616 retval = _copyStream(from);
2618 case T_IndexOptInfo:
2619 retval = _copyIndexOptInfo(from);
2628 retval = _copyValue(from);
2636 /* rather ugly coding for speed... */
2637 /* Note the input list cannot be NIL if we got here. */
2638 nl = lcons(copyObject(lfirst(list)), NIL);
2641 foreach(l, lnext(list))
2643 lnext(nl) = lcons(copyObject(lfirst(l)), NIL);
2653 retval = _copyQuery(from);
2656 retval = _copyInsertStmt(from);
2659 retval = _copyDeleteStmt(from);
2662 retval = _copyUpdateStmt(from);
2665 retval = _copySelectStmt(from);
2667 case T_AlterTableStmt:
2668 retval = _copyAlterTableStmt(from);
2670 case T_ChangeACLStmt:
2671 retval = _copyChangeACLStmt(from);
2673 case T_ClosePortalStmt:
2674 retval = _copyClosePortalStmt(from);
2677 retval = _copyClusterStmt(from);
2680 retval = _copyCopyStmt(from);
2683 retval = _copyCreateStmt(from);
2686 retval = _copyVersionStmt(from);
2689 retval = _copyDefineStmt(from);
2692 retval = _copyDropStmt(from);
2694 case T_TruncateStmt:
2695 retval = _copyTruncateStmt(from);
2698 retval = _copyCommentStmt(from);
2701 retval = _copyExtendStmt(from);
2704 retval = _copyFetchStmt(from);
2707 retval = _copyIndexStmt(from);
2709 case T_ProcedureStmt:
2710 retval = _copyProcedureStmt(from);
2712 case T_RemoveAggrStmt:
2713 retval = _copyRemoveAggrStmt(from);
2715 case T_RemoveFuncStmt:
2716 retval = _copyRemoveFuncStmt(from);
2718 case T_RemoveOperStmt:
2719 retval = _copyRemoveOperStmt(from);
2722 retval = _copyRemoveStmt(from);
2725 retval = _copyRenameStmt(from);
2728 retval = _copyRuleStmt(from);
2731 retval = _copyNotifyStmt(from);
2734 retval = _copyListenStmt(from);
2736 case T_UnlistenStmt:
2737 retval = _copyUnlistenStmt(from);
2739 case T_TransactionStmt:
2740 retval = _copyTransactionStmt(from);
2743 retval = _copyViewStmt(from);
2746 retval = _copyLoadStmt(from);
2748 case T_CreatedbStmt:
2749 retval = _copyCreatedbStmt(from);
2752 retval = _copyDropdbStmt(from);
2755 retval = _copyVacuumStmt(from);
2758 retval = _copyExplainStmt(from);
2760 case T_CreateSeqStmt:
2761 retval = _copyCreateSeqStmt(from);
2763 case T_VariableSetStmt:
2764 retval = _copyVariableSetStmt(from);
2766 case T_VariableShowStmt:
2767 retval = _copyVariableShowStmt(from);
2769 case T_VariableResetStmt:
2770 retval = _copyVariableResetStmt(from);
2772 case T_CreateTrigStmt:
2773 retval = _copyCreateTrigStmt(from);
2775 case T_DropTrigStmt:
2776 retval = _copyDropTrigStmt(from);
2778 case T_CreatePLangStmt:
2779 retval = _copyCreatePLangStmt(from);
2781 case T_DropPLangStmt:
2782 retval = _copyDropPLangStmt(from);
2784 case T_CreateUserStmt:
2785 retval = _copyCreateUserStmt(from);
2787 case T_AlterUserStmt:
2788 retval = _copyAlterUserStmt(from);
2790 case T_DropUserStmt:
2791 retval = _copyDropUserStmt(from);
2794 retval = _copyLockStmt(from);
2796 case T_ConstraintsSetStmt:
2797 retval = _copyConstraintsSetStmt(from);
2799 case T_CreateGroupStmt:
2800 retval = _copyCreateGroupStmt(from);
2802 case T_AlterGroupStmt:
2803 retval = _copyAlterGroupStmt(from);
2805 case T_DropGroupStmt:
2806 retval = _copyDropGroupStmt(from);
2809 retval = _copyReindexStmt(from);
2811 case T_SetSessionStmt:
2812 retval = _copySetSessionStmt(from);
2816 retval = _copyAExpr(from);
2819 retval = _copyAttr(from);
2822 retval = _copyAConst(from);
2825 retval = _copyParamNo(from);
2828 retval = _copyIdent(from);
2831 retval = _copyFuncCall(from);
2834 retval = _copyAIndices(from);
2837 retval = _copyResTarget(from);
2840 retval = _copyTypeCast(from);
2843 retval = _copySortGroupBy(from);
2846 retval = _copyRangeVar(from);
2848 case T_RangeSubselect:
2849 retval = _copyRangeSubselect(from);
2852 retval = _copyTypeName(from);
2855 retval = _copyIndexElem(from);
2858 retval = _copyColumnDef(from);
2861 retval = _copyConstraint(from);
2864 retval = _copyDefElem(from);
2867 retval = _copyTargetEntry(from);
2869 case T_RangeTblEntry:
2870 retval = _copyRangeTblEntry(from);
2873 retval = _copySortClause(from);
2876 retval = _copyGroupClause(from);
2879 retval = _copyCaseExpr(from);
2882 retval = _copyCaseWhen(from);
2885 retval = _copyRowMark(from);
2887 case T_FkConstraint:
2888 retval = _copyFkConstraint(from);
2892 elog(ERROR, "copyObject: don't know how to copy node type %d",
2894 retval = from; /* keep compiler quiet */