1 /*-------------------------------------------------------------------------
4 * Copy functions for Postgres tree nodes.
6 * NOTE: a general convention when copying or comparing plan nodes is
7 * that we ignore the executor state subnode. We do not need to look
8 * at it because no current uses of copyObject() or equal() need to
9 * deal with already-executing plan trees. By leaving the state subnodes
10 * out, we avoid needing to write copy/compare routines for all the
11 * different executor state node types.
14 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
15 * Portions Copyright (c) 1994, Regents of the University of California
18 * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.138 2001/01/24 19:42:56 momjian 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 = makeList1(lfirst(list));
63 foreach(l, lnext(list))
65 lnext(nl) = makeList1(lfirst(l));
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 newnode->isTarget = from->isTarget;
188 * This function copies the fields of the Scan node. It is used by
189 * all the copy functions for classes which inherit from Scan.
193 CopyScanFields(Scan *from, Scan *newnode)
195 newnode->scanrelid = from->scanrelid;
204 _copyScan(Scan *from)
206 Scan *newnode = makeNode(Scan);
209 * copy node superclass fields
212 CopyPlanFields((Plan *) from, (Plan *) newnode);
213 CopyScanFields((Scan *) from, (Scan *) newnode);
223 _copySeqScan(SeqScan *from)
225 SeqScan *newnode = makeNode(SeqScan);
228 * copy node superclass fields
231 CopyPlanFields((Plan *) from, (Plan *) newnode);
232 CopyScanFields((Scan *) from, (Scan *) newnode);
242 _copyIndexScan(IndexScan *from)
244 IndexScan *newnode = makeNode(IndexScan);
247 * copy node superclass fields
250 CopyPlanFields((Plan *) from, (Plan *) newnode);
251 CopyScanFields((Scan *) from, (Scan *) newnode);
254 * copy remainder of node
257 newnode->indxid = listCopy(from->indxid);
258 Node_Copy(from, newnode, indxqual);
259 Node_Copy(from, newnode, indxqualorig);
260 newnode->indxorderdir = from->indxorderdir;
263 * We must add subplans in index quals to the new plan's subPlan list
265 if (from->scan.plan.subPlan != NIL)
267 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
268 pull_subplans((Node *) newnode->indxqual));
269 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
270 pull_subplans((Node *) newnode->indxqualorig));
281 _copyTidScan(TidScan *from)
283 TidScan *newnode = makeNode(TidScan);
286 * copy node superclass fields
289 CopyPlanFields((Plan *) from, (Plan *) newnode);
290 CopyScanFields((Scan *) from, (Scan *) newnode);
292 * copy remainder of node
295 newnode->needRescan = from->needRescan;
296 Node_Copy(from, newnode, tideval);
305 static SubqueryScan *
306 _copySubqueryScan(SubqueryScan *from)
308 SubqueryScan *newnode = makeNode(SubqueryScan);
311 * copy node superclass fields
314 CopyPlanFields((Plan *) from, (Plan *) newnode);
315 CopyScanFields((Scan *) from, (Scan *) newnode);
318 * copy remainder of node
321 Node_Copy(from, newnode, subplan);
330 * This function copies the fields of the Join node. It is used by
331 * all the copy functions for classes which inherit from Join.
335 CopyJoinFields(Join *from, Join *newnode)
337 newnode->jointype = from->jointype;
338 Node_Copy(from, newnode, joinqual);
339 /* subPlan list must point to subplans in the new subtree, not the old */
340 if (from->plan.subPlan != NIL)
341 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
342 pull_subplans((Node *) newnode->joinqual));
351 _copyJoin(Join *from)
353 Join *newnode = makeNode(Join);
356 * copy node superclass fields
359 CopyPlanFields((Plan *) from, (Plan *) newnode);
360 CopyJoinFields(from, newnode);
371 _copyNestLoop(NestLoop *from)
373 NestLoop *newnode = makeNode(NestLoop);
376 * copy node superclass fields
379 CopyPlanFields((Plan *) from, (Plan *) newnode);
380 CopyJoinFields((Join *) from, (Join *) newnode);
391 _copyMergeJoin(MergeJoin *from)
393 MergeJoin *newnode = makeNode(MergeJoin);
396 * copy node superclass fields
399 CopyPlanFields((Plan *) from, (Plan *) newnode);
400 CopyJoinFields((Join *) from, (Join *) newnode);
403 * copy remainder of node
406 Node_Copy(from, newnode, mergeclauses);
409 * We must add subplans in mergeclauses to the new plan's subPlan list
411 if (from->join.plan.subPlan != NIL)
412 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
413 pull_subplans((Node *) newnode->mergeclauses));
423 _copyHashJoin(HashJoin *from)
425 HashJoin *newnode = makeNode(HashJoin);
428 * copy node superclass fields
431 CopyPlanFields((Plan *) from, (Plan *) newnode);
432 CopyJoinFields((Join *) from, (Join *) newnode);
435 * copy remainder of node
438 Node_Copy(from, newnode, hashclauses);
439 newnode->hashjoinop = from->hashjoinop;
442 * We must add subplans in hashclauses to the new plan's subPlan list
444 if (from->join.plan.subPlan != NIL)
445 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
446 pull_subplans((Node *) newnode->hashclauses));
457 _copyMaterial(Material *from)
459 Material *newnode = makeNode(Material);
462 * copy node superclass fields
465 CopyPlanFields((Plan *) from, (Plan *) newnode);
476 _copySort(Sort *from)
478 Sort *newnode = makeNode(Sort);
481 * copy node superclass fields
484 CopyPlanFields((Plan *) from, (Plan *) newnode);
486 newnode->keycount = from->keycount;
497 _copyGroup(Group *from)
499 Group *newnode = makeNode(Group);
501 CopyPlanFields((Plan *) from, (Plan *) newnode);
503 newnode->tuplePerGroup = from->tuplePerGroup;
504 newnode->numCols = from->numCols;
505 newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
506 memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
518 Agg *newnode = makeNode(Agg);
520 CopyPlanFields((Plan *) from, (Plan *) newnode);
530 _copyGroupClause(GroupClause *from)
532 GroupClause *newnode = makeNode(GroupClause);
534 newnode->tleSortGroupRef = from->tleSortGroupRef;
535 newnode->sortop = from->sortop;
545 _copyUnique(Unique *from)
547 Unique *newnode = makeNode(Unique);
550 * copy node superclass fields
553 CopyPlanFields((Plan *) from, (Plan *) newnode);
556 * copy remainder of node
559 newnode->numCols = from->numCols;
560 newnode->uniqColIdx = palloc(from->numCols * sizeof(AttrNumber));
561 memcpy(newnode->uniqColIdx, from->uniqColIdx, from->numCols * sizeof(AttrNumber));
571 _copySetOp(SetOp *from)
573 SetOp *newnode = makeNode(SetOp);
576 * copy node superclass fields
579 CopyPlanFields((Plan *) from, (Plan *) newnode);
582 * copy remainder of node
585 newnode->cmd = from->cmd;
586 newnode->numCols = from->numCols;
587 newnode->dupColIdx = palloc(from->numCols * sizeof(AttrNumber));
588 memcpy(newnode->dupColIdx, from->dupColIdx, from->numCols * sizeof(AttrNumber));
589 newnode->flagColIdx = from->flagColIdx;
599 _copyLimit(Limit *from)
601 Limit *newnode = makeNode(Limit);
604 * copy node superclass fields
607 CopyPlanFields((Plan *) from, (Plan *) newnode);
610 * copy remainder of node
613 Node_Copy(from, newnode, limitOffset);
614 Node_Copy(from, newnode, limitCount);
624 _copyHash(Hash *from)
626 Hash *newnode = makeNode(Hash);
629 * copy node superclass fields
632 CopyPlanFields((Plan *) from, (Plan *) newnode);
635 * copy remainder of node
638 Node_Copy(from, newnode, hashkey);
644 _copySubPlan(SubPlan *from)
646 SubPlan *newnode = makeNode(SubPlan);
648 Node_Copy(from, newnode, plan);
649 newnode->plan_id = from->plan_id;
650 Node_Copy(from, newnode, rtable);
651 newnode->setParam = listCopy(from->setParam);
652 newnode->parParam = listCopy(from->parParam);
653 Node_Copy(from, newnode, sublink);
655 /* do not copy execution state */
656 newnode->needShutdown = false;
657 newnode->curTuple = NULL;
662 /* ****************************************************************
663 * primnodes.h copy functions
664 * ****************************************************************
672 _copyResdom(Resdom *from)
674 Resdom *newnode = makeNode(Resdom);
676 newnode->resno = from->resno;
677 newnode->restype = from->restype;
678 newnode->restypmod = from->restypmod;
679 if (from->resname != NULL)
680 newnode->resname = pstrdup(from->resname);
681 newnode->ressortgroupref = from->ressortgroupref;
682 newnode->reskey = from->reskey;
683 newnode->reskeyop = from->reskeyop;
684 newnode->resjunk = from->resjunk;
690 _copyFjoin(Fjoin *from)
692 Fjoin *newnode = makeNode(Fjoin);
695 * copy node superclass fields
699 newnode->fj_initialized = from->fj_initialized;
700 newnode->fj_nNodes = from->fj_nNodes;
702 Node_Copy(from, newnode, fj_innerNode);
704 newnode->fj_results = (DatumPtr)
705 palloc((from->fj_nNodes) * sizeof(Datum));
706 memmove(from->fj_results,
708 (from->fj_nNodes) * sizeof(Datum));
710 newnode->fj_alwaysDone = (BoolPtr)
711 palloc((from->fj_nNodes) * sizeof(bool));
712 memmove(from->fj_alwaysDone,
713 newnode->fj_alwaysDone,
714 (from->fj_nNodes) * sizeof(bool));
725 _copyExpr(Expr *from)
727 Expr *newnode = makeNode(Expr);
730 * copy node superclass fields
733 newnode->typeOid = from->typeOid;
734 newnode->opType = from->opType;
736 Node_Copy(from, newnode, oper);
737 Node_Copy(from, newnode, args);
749 Var *newnode = makeNode(Var);
752 * copy remainder of node
755 newnode->varno = from->varno;
756 newnode->varattno = from->varattno;
757 newnode->vartype = from->vartype;
758 newnode->vartypmod = from->vartypmod;
759 newnode->varlevelsup = from->varlevelsup;
761 newnode->varnoold = from->varnoold;
762 newnode->varoattno = from->varoattno;
768 _copyAttr(Attr *from)
770 Attr *newnode = makeNode(Attr);
773 newnode->relname = pstrdup(from->relname);
774 Node_Copy(from, newnode, attrs);
784 _copyOper(Oper *from)
786 Oper *newnode = makeNode(Oper);
789 * copy remainder of node
792 newnode->opno = from->opno;
793 newnode->opid = from->opid;
794 newnode->opresulttype = from->opresulttype;
795 /* Do not copy the run-time state, if any */
796 newnode->op_fcache = NULL;
806 _copyConst(Const *from)
808 Const *newnode = makeNode(Const);
811 * copy remainder of node
814 newnode->consttype = from->consttype;
815 newnode->constlen = from->constlen;
817 if (from->constbyval || from->constisnull)
820 * passed by value so just copy the datum.
821 * Also, don't try to copy struct when value is null!
824 newnode->constvalue = from->constvalue;
829 * not passed by value. datum contains a pointer.
832 int length = from->constlen;
834 if (length == -1) /* variable-length type? */
835 length = VARSIZE(from->constvalue);
836 newnode->constvalue = PointerGetDatum(palloc(length));
837 memcpy(DatumGetPointer(newnode->constvalue),
838 DatumGetPointer(from->constvalue),
842 newnode->constisnull = from->constisnull;
843 newnode->constbyval = from->constbyval;
844 newnode->constisset = from->constisset;
845 newnode->constiscast = from->constiscast;
855 _copyParam(Param *from)
857 Param *newnode = makeNode(Param);
860 * copy remainder of node
863 newnode->paramkind = from->paramkind;
864 newnode->paramid = from->paramid;
866 if (from->paramname != NULL)
867 newnode->paramname = pstrdup(from->paramname);
868 newnode->paramtype = from->paramtype;
878 _copyFunc(Func *from)
880 Func *newnode = makeNode(Func);
883 * copy remainder of node
886 newnode->funcid = from->funcid;
887 newnode->functype = from->functype;
888 /* Do not copy the run-time state, if any */
889 newnode->func_fcache = NULL;
899 _copyAggref(Aggref *from)
901 Aggref *newnode = makeNode(Aggref);
904 * copy remainder of node
907 newnode->aggname = pstrdup(from->aggname);
908 newnode->basetype = from->basetype;
909 newnode->aggtype = from->aggtype;
910 Node_Copy(from, newnode, target);
911 newnode->aggstar = from->aggstar;
912 newnode->aggdistinct = from->aggdistinct;
913 newnode->aggno = from->aggno; /* probably not needed */
923 _copySubLink(SubLink *from)
925 SubLink *newnode = makeNode(SubLink);
928 * copy remainder of node
931 newnode->subLinkType = from->subLinkType;
932 newnode->useor = from->useor;
933 Node_Copy(from, newnode, lefthand);
934 Node_Copy(from, newnode, oper);
935 Node_Copy(from, newnode, subselect);
945 _copyFieldSelect(FieldSelect *from)
947 FieldSelect *newnode = makeNode(FieldSelect);
950 * copy remainder of node
953 Node_Copy(from, newnode, arg);
954 newnode->fieldnum = from->fieldnum;
955 newnode->resulttype = from->resulttype;
956 newnode->resulttypmod = from->resulttypmod;
966 _copyRelabelType(RelabelType *from)
968 RelabelType *newnode = makeNode(RelabelType);
971 * copy remainder of node
974 Node_Copy(from, newnode, arg);
975 newnode->resulttype = from->resulttype;
976 newnode->resulttypmod = from->resulttypmod;
982 _copyRangeTblRef(RangeTblRef *from)
984 RangeTblRef *newnode = makeNode(RangeTblRef);
986 newnode->rtindex = from->rtindex;
992 _copyFromExpr(FromExpr *from)
994 FromExpr *newnode = makeNode(FromExpr);
996 Node_Copy(from, newnode, fromlist);
997 Node_Copy(from, newnode, quals);
1003 _copyJoinExpr(JoinExpr *from)
1005 JoinExpr *newnode = makeNode(JoinExpr);
1007 newnode->jointype = from->jointype;
1008 newnode->isNatural = from->isNatural;
1009 Node_Copy(from, newnode, larg);
1010 Node_Copy(from, newnode, rarg);
1011 Node_Copy(from, newnode, using);
1012 Node_Copy(from, newnode, quals);
1013 Node_Copy(from, newnode, alias);
1014 Node_Copy(from, newnode, colnames);
1015 Node_Copy(from, newnode, colvars);
1025 _copyCaseExpr(CaseExpr *from)
1027 CaseExpr *newnode = makeNode(CaseExpr);
1030 * copy remainder of node
1033 newnode->casetype = from->casetype;
1035 Node_Copy(from, newnode, arg);
1036 Node_Copy(from, newnode, args);
1037 Node_Copy(from, newnode, defresult);
1047 _copyCaseWhen(CaseWhen *from)
1049 CaseWhen *newnode = makeNode(CaseWhen);
1052 * copy remainder of node
1055 Node_Copy(from, newnode, expr);
1056 Node_Copy(from, newnode, result);
1062 _copyArrayRef(ArrayRef *from)
1064 ArrayRef *newnode = makeNode(ArrayRef);
1067 * copy remainder of node
1070 newnode->refattrlength = from->refattrlength;
1071 newnode->refelemlength = from->refelemlength;
1072 newnode->refelemtype = from->refelemtype;
1073 newnode->refelembyval = from->refelembyval;
1075 Node_Copy(from, newnode, refupperindexpr);
1076 Node_Copy(from, newnode, reflowerindexpr);
1077 Node_Copy(from, newnode, refexpr);
1078 Node_Copy(from, newnode, refassgnexpr);
1083 /* ****************************************************************
1084 * relation.h copy functions
1085 * ****************************************************************
1093 * when you change this, also make sure to fix up xfunc_copyRelOptInfo in
1094 * planner/path/xfunc.c accordingly!!!
1098 _copyRelOptInfo(RelOptInfo *from)
1100 RelOptInfo *newnode = makeNode(RelOptInfo);
1102 newnode->relids = listCopy(from->relids);
1104 newnode->rows = from->rows;
1105 newnode->width = from->width;
1107 Node_Copy(from, newnode, targetlist);
1108 Node_Copy(from, newnode, pathlist);
1109 /* XXX cheapest-path fields should point to members of pathlist? */
1110 Node_Copy(from, newnode, cheapest_startup_path);
1111 Node_Copy(from, newnode, cheapest_total_path);
1112 newnode->pruneable = from->pruneable;
1114 newnode->issubquery = from->issubquery;
1115 newnode->indexed = from->indexed;
1116 newnode->pages = from->pages;
1117 newnode->tuples = from->tuples;
1118 Node_Copy(from, newnode, subplan);
1120 Node_Copy(from, newnode, baserestrictinfo);
1121 newnode->baserestrictcost = from->baserestrictcost;
1122 newnode->outerjoinset = listCopy(from->outerjoinset);
1123 Node_Copy(from, newnode, joininfo);
1124 Node_Copy(from, newnode, innerjoin);
1133 static IndexOptInfo *
1134 _copyIndexOptInfo(IndexOptInfo *from)
1136 IndexOptInfo *newnode = makeNode(IndexOptInfo);
1140 newnode->indexoid = from->indexoid;
1141 newnode->pages = from->pages;
1142 newnode->tuples = from->tuples;
1144 if (from->classlist)
1146 for (len = 0; from->classlist[len] != 0; len++)
1148 newnode->classlist = (Oid *) palloc(sizeof(Oid) * (len + 1));
1149 for (i = 0; i < len; i++)
1150 newnode->classlist[i] = from->classlist[i];
1151 newnode->classlist[len] = 0;
1154 if (from->indexkeys)
1156 for (len = 0; from->indexkeys[len] != 0; len++)
1158 newnode->indexkeys = (int *) palloc(sizeof(int) * (len + 1));
1159 for (i = 0; i < len; i++)
1160 newnode->indexkeys[i] = from->indexkeys[i];
1161 newnode->indexkeys[len] = 0;
1166 for (len = 0; from->ordering[len] != 0; len++)
1168 newnode->ordering = (Oid *) palloc(sizeof(Oid) * (len + 1));
1169 for (i = 0; i < len; i++)
1170 newnode->ordering[i] = from->ordering[i];
1171 newnode->ordering[len] = 0;
1174 newnode->relam = from->relam;
1175 newnode->amcostestimate = from->amcostestimate;
1176 newnode->indproc = from->indproc;
1177 Node_Copy(from, newnode, indpred);
1178 newnode->lossy = from->lossy;
1186 * This function copies the fields of the Path node. It is used by
1187 * all the copy functions for classes which inherit from Path.
1191 CopyPathFields(Path *from, Path *newnode)
1195 * Modify the next line, since it causes the copying to cycle (i.e.
1196 * the parent points right back here! -- JMH, 7/7/92. Old version:
1197 * Node_Copy(from, newnode, parent);
1199 newnode->parent = from->parent;
1201 newnode->startup_cost = from->startup_cost;
1202 newnode->total_cost = from->total_cost;
1204 newnode->pathtype = from->pathtype;
1206 Node_Copy(from, newnode, pathkeys);
1214 _copyPath(Path *from)
1216 Path *newnode = makeNode(Path);
1218 CopyPathFields(from, newnode);
1228 _copyIndexPath(IndexPath *from)
1230 IndexPath *newnode = makeNode(IndexPath);
1233 * copy the node superclass fields
1236 CopyPathFields((Path *) from, (Path *) newnode);
1239 * copy remainder of node
1242 newnode->indexid = listCopy(from->indexid);
1243 Node_Copy(from, newnode, indexqual);
1244 newnode->indexscandir = from->indexscandir;
1245 newnode->joinrelids = listCopy(from->joinrelids);
1246 newnode->alljoinquals = from->alljoinquals;
1247 newnode->rows = from->rows;
1257 _copyTidPath(TidPath *from)
1259 TidPath *newnode = makeNode(TidPath);
1262 * copy the node superclass fields
1265 CopyPathFields((Path *) from, (Path *) newnode);
1268 * copy remainder of node
1271 Node_Copy(from, newnode, tideval);
1272 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1282 _copyAppendPath(AppendPath *from)
1284 AppendPath *newnode = makeNode(AppendPath);
1287 * copy the node superclass fields
1290 CopyPathFields((Path *) from, (Path *) newnode);
1293 * copy remainder of node
1296 Node_Copy(from, newnode, subpaths);
1302 * CopyJoinPathFields
1304 * This function copies the fields of the JoinPath node. It is used by
1305 * all the copy functions for classes which inherit from JoinPath.
1309 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1311 newnode->jointype = from->jointype;
1312 Node_Copy(from, newnode, outerjoinpath);
1313 Node_Copy(from, newnode, innerjoinpath);
1314 Node_Copy(from, newnode, joinrestrictinfo);
1322 _copyNestPath(NestPath *from)
1324 NestPath *newnode = makeNode(NestPath);
1327 * copy the node superclass fields
1330 CopyPathFields((Path *) from, (Path *) newnode);
1331 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1341 _copyMergePath(MergePath *from)
1343 MergePath *newnode = makeNode(MergePath);
1346 * copy the node superclass fields
1349 CopyPathFields((Path *) from, (Path *) newnode);
1350 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1353 * copy the remainder of the node
1356 Node_Copy(from, newnode, path_mergeclauses);
1357 Node_Copy(from, newnode, outersortkeys);
1358 Node_Copy(from, newnode, innersortkeys);
1368 _copyHashPath(HashPath *from)
1370 HashPath *newnode = makeNode(HashPath);
1373 * copy the node superclass fields
1376 CopyPathFields((Path *) from, (Path *) newnode);
1377 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1380 * copy remainder of node
1383 Node_Copy(from, newnode, path_hashclauses);
1392 static PathKeyItem *
1393 _copyPathKeyItem(PathKeyItem *from)
1395 PathKeyItem *newnode = makeNode(PathKeyItem);
1398 * copy remainder of node
1401 Node_Copy(from, newnode, key);
1402 newnode->sortop = from->sortop;
1411 static RestrictInfo *
1412 _copyRestrictInfo(RestrictInfo *from)
1414 RestrictInfo *newnode = makeNode(RestrictInfo);
1417 * copy remainder of node
1420 Node_Copy(from, newnode, clause);
1421 newnode->eval_cost = from->eval_cost;
1422 newnode->ispusheddown = from->ispusheddown;
1423 Node_Copy(from, newnode, subclauseindices);
1424 newnode->mergejoinoperator = from->mergejoinoperator;
1425 newnode->left_sortop = from->left_sortop;
1426 newnode->right_sortop = from->right_sortop;
1427 /* Do not copy pathkeys, since they'd not be canonical in a copied query */
1428 newnode->left_pathkey = NIL;
1429 newnode->right_pathkey = NIL;
1430 newnode->hashjoinoperator = from->hashjoinoperator;
1431 newnode->left_dispersion = from->left_dispersion;
1432 newnode->right_dispersion = from->right_dispersion;
1442 _copyJoinInfo(JoinInfo *from)
1444 JoinInfo *newnode = makeNode(JoinInfo);
1447 * copy remainder of node
1450 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1451 Node_Copy(from, newnode, jinfo_restrictinfo);
1457 _copyIter(Iter *from)
1459 Iter *newnode = makeNode(Iter);
1461 Node_Copy(from, newnode, iterexpr);
1462 newnode->itertype = from->itertype;
1468 _copyStream(Stream *from)
1470 Stream *newnode = makeNode(Stream);
1472 newnode->pathptr = from->pathptr;
1473 newnode->cinfo = from->cinfo;
1474 newnode->clausetype = from->clausetype;
1476 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1478 Node_Copy(from, newnode, downstream);
1479 if (newnode->downstream)
1480 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1482 newnode->groupup = from->groupup;
1483 newnode->groupcost = from->groupcost;
1484 newnode->groupsel = from->groupsel;
1489 /* ****************************************************************
1490 * parsenodes.h copy functions
1491 * ****************************************************************
1494 static TargetEntry *
1495 _copyTargetEntry(TargetEntry *from)
1497 TargetEntry *newnode = makeNode(TargetEntry);
1499 Node_Copy(from, newnode, resdom);
1500 Node_Copy(from, newnode, fjoin);
1501 Node_Copy(from, newnode, expr);
1505 static RangeTblEntry *
1506 _copyRangeTblEntry(RangeTblEntry *from)
1508 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1511 newnode->relname = pstrdup(from->relname);
1512 newnode->relid = from->relid;
1513 Node_Copy(from, newnode, subquery);
1514 Node_Copy(from, newnode, alias);
1515 Node_Copy(from, newnode, eref);
1516 newnode->inh = from->inh;
1517 newnode->inFromCl = from->inFromCl;
1518 newnode->checkForRead = from->checkForRead;
1519 newnode->checkForWrite = from->checkForWrite;
1520 newnode->checkAsUser = from->checkAsUser;
1525 static FkConstraint *
1526 _copyFkConstraint(FkConstraint *from)
1528 FkConstraint *newnode = makeNode(FkConstraint);
1530 if (from->constr_name)
1531 newnode->constr_name = pstrdup(from->constr_name);
1532 if (from->pktable_name)
1533 newnode->pktable_name = pstrdup(from->pktable_name);
1534 Node_Copy(from, newnode, fk_attrs);
1535 Node_Copy(from, newnode, pk_attrs);
1536 if (from->match_type)
1537 newnode->match_type = pstrdup(from->match_type);
1538 newnode->actions = from->actions;
1539 newnode->deferrable = from->deferrable;
1540 newnode->initdeferred = from->initdeferred;
1546 _copySortClause(SortClause *from)
1548 SortClause *newnode = makeNode(SortClause);
1550 newnode->tleSortGroupRef = from->tleSortGroupRef;
1551 newnode->sortop = from->sortop;
1557 _copyAExpr(A_Expr *from)
1559 A_Expr *newnode = makeNode(A_Expr);
1561 newnode->oper = from->oper;
1563 newnode->opname = pstrdup(from->opname);
1564 Node_Copy(from, newnode, lexpr);
1565 Node_Copy(from, newnode, rexpr);
1571 _copyAConst(A_Const *from)
1573 A_Const *newnode = makeNode(A_Const);
1575 newnode->val = *((Value *) (copyObject(&(from->val))));
1576 Node_Copy(from, newnode, typename);
1582 _copyParamNo(ParamNo *from)
1584 ParamNo *newnode = makeNode(ParamNo);
1586 newnode->number = from->number;
1587 Node_Copy(from, newnode, typename);
1588 Node_Copy(from, newnode, indirection);
1594 _copyIdent(Ident *from)
1596 Ident *newnode = makeNode(Ident);
1599 newnode->name = pstrdup(from->name);
1600 Node_Copy(from, newnode, indirection);
1601 newnode->isRel = from->isRel;
1607 _copyFuncCall(FuncCall *from)
1609 FuncCall *newnode = makeNode(FuncCall);
1612 newnode->funcname = pstrdup(from->funcname);
1613 Node_Copy(from, newnode, args);
1614 newnode->agg_star = from->agg_star;
1615 newnode->agg_distinct = from->agg_distinct;
1621 _copyAIndices(A_Indices *from)
1623 A_Indices *newnode = makeNode(A_Indices);
1625 Node_Copy(from, newnode, lidx);
1626 Node_Copy(from, newnode, uidx);
1632 _copyResTarget(ResTarget *from)
1634 ResTarget *newnode = makeNode(ResTarget);
1637 newnode->name = pstrdup(from->name);
1638 Node_Copy(from, newnode, indirection);
1639 Node_Copy(from, newnode, val);
1645 _copyTypeName(TypeName *from)
1647 TypeName *newnode = makeNode(TypeName);
1650 newnode->name = pstrdup(from->name);
1651 newnode->timezone = from->timezone;
1652 newnode->setof = from->setof;
1653 newnode->typmod = from->typmod;
1654 Node_Copy(from, newnode, arrayBounds);
1659 static SortGroupBy *
1660 _copySortGroupBy(SortGroupBy *from)
1662 SortGroupBy *newnode = makeNode(SortGroupBy);
1665 newnode->useOp = pstrdup(from->useOp);
1666 Node_Copy(from, newnode, node);
1672 _copyRangeVar(RangeVar *from)
1674 RangeVar *newnode = makeNode(RangeVar);
1677 newnode->relname = pstrdup(from->relname);
1678 newnode->inhOpt = from->inhOpt;
1679 Node_Copy(from, newnode, name);
1684 static RangeSubselect *
1685 _copyRangeSubselect(RangeSubselect *from)
1687 RangeSubselect *newnode = makeNode(RangeSubselect);
1689 Node_Copy(from, newnode, subquery);
1690 Node_Copy(from, newnode, name);
1696 _copyTypeCast(TypeCast *from)
1698 TypeCast *newnode = makeNode(TypeCast);
1700 Node_Copy(from, newnode, arg);
1701 Node_Copy(from, newnode, typename);
1707 _copyIndexElem(IndexElem *from)
1709 IndexElem *newnode = makeNode(IndexElem);
1712 newnode->name = pstrdup(from->name);
1713 Node_Copy(from, newnode, args);
1715 newnode->class = pstrdup(from->class);
1721 _copyColumnDef(ColumnDef *from)
1723 ColumnDef *newnode = makeNode(ColumnDef);
1726 newnode->colname = pstrdup(from->colname);
1727 Node_Copy(from, newnode, typename);
1728 newnode->is_not_null = from->is_not_null;
1729 newnode->is_sequence = from->is_sequence;
1730 Node_Copy(from, newnode, raw_default);
1731 if (from->cooked_default)
1732 newnode->cooked_default = pstrdup(from->cooked_default);
1733 Node_Copy(from, newnode, constraints);
1739 _copyConstraint(Constraint *from)
1741 Constraint *newnode = makeNode(Constraint);
1743 newnode->contype = from->contype;
1745 newnode->name = pstrdup(from->name);
1746 Node_Copy(from, newnode, raw_expr);
1747 if (from->cooked_expr)
1748 newnode->cooked_expr = pstrdup(from->cooked_expr);
1749 Node_Copy(from, newnode, keys);
1755 _copyDefElem(DefElem *from)
1757 DefElem *newnode = makeNode(DefElem);
1760 newnode->defname = pstrdup(from->defname);
1761 Node_Copy(from, newnode, arg);
1767 _copyQuery(Query *from)
1769 Query *newnode = makeNode(Query);
1771 newnode->commandType = from->commandType;
1772 Node_Copy(from, newnode, utilityStmt);
1773 newnode->resultRelation = from->resultRelation;
1775 newnode->into = pstrdup(from->into);
1776 newnode->isPortal = from->isPortal;
1777 newnode->isBinary = from->isBinary;
1778 newnode->isTemp = from->isTemp;
1779 newnode->hasAggs = from->hasAggs;
1780 newnode->hasSubLinks = from->hasSubLinks;
1782 Node_Copy(from, newnode, rtable);
1783 Node_Copy(from, newnode, jointree);
1785 newnode->rowMarks = listCopy(from->rowMarks);
1787 Node_Copy(from, newnode, targetList);
1789 Node_Copy(from, newnode, groupClause);
1790 Node_Copy(from, newnode, havingQual);
1791 Node_Copy(from, newnode, distinctClause);
1792 Node_Copy(from, newnode, sortClause);
1794 Node_Copy(from, newnode, limitOffset);
1795 Node_Copy(from, newnode, limitCount);
1797 Node_Copy(from, newnode, setOperations);
1799 newnode->resultRelations = listCopy(from->resultRelations);
1802 * We do not copy the planner internal fields: base_rel_list,
1803 * join_rel_list, equi_key_list, query_pathkeys. Not entirely clear if
1811 _copyInsertStmt(InsertStmt *from)
1813 InsertStmt *newnode = makeNode(InsertStmt);
1816 newnode->relname = pstrdup(from->relname);
1817 Node_Copy(from, newnode, cols);
1818 Node_Copy(from, newnode, targetList);
1819 Node_Copy(from, newnode, selectStmt);
1825 _copyDeleteStmt(DeleteStmt *from)
1827 DeleteStmt *newnode = makeNode(DeleteStmt);
1830 newnode->relname = pstrdup(from->relname);
1831 Node_Copy(from, newnode, whereClause);
1832 newnode->inhOpt = from->inhOpt;
1838 _copyUpdateStmt(UpdateStmt *from)
1840 UpdateStmt *newnode = makeNode(UpdateStmt);
1843 newnode->relname = pstrdup(from->relname);
1844 Node_Copy(from, newnode, targetList);
1845 Node_Copy(from, newnode, whereClause);
1846 Node_Copy(from, newnode, fromClause);
1847 newnode->inhOpt = from->inhOpt;
1853 _copySelectStmt(SelectStmt *from)
1855 SelectStmt *newnode = makeNode(SelectStmt);
1857 Node_Copy(from, newnode, distinctClause);
1859 newnode->into = pstrdup(from->into);
1860 newnode->istemp = from->istemp;
1861 Node_Copy(from, newnode, targetList);
1862 Node_Copy(from, newnode, fromClause);
1863 Node_Copy(from, newnode, whereClause);
1864 Node_Copy(from, newnode, groupClause);
1865 Node_Copy(from, newnode, havingClause);
1866 Node_Copy(from, newnode, sortClause);
1867 if (from->portalname)
1868 newnode->portalname = pstrdup(from->portalname);
1869 newnode->binary = from->binary;
1870 Node_Copy(from, newnode, limitOffset);
1871 Node_Copy(from, newnode, limitCount);
1872 Node_Copy(from, newnode, forUpdate);
1873 newnode->op = from->op;
1874 newnode->all = from->all;
1875 Node_Copy(from, newnode, larg);
1876 Node_Copy(from, newnode, rarg);
1881 static SetOperationStmt *
1882 _copySetOperationStmt(SetOperationStmt *from)
1884 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1886 newnode->op = from->op;
1887 newnode->all = from->all;
1888 Node_Copy(from, newnode, larg);
1889 Node_Copy(from, newnode, rarg);
1890 newnode->colTypes = listCopy(from->colTypes);
1895 static AlterTableStmt *
1896 _copyAlterTableStmt(AlterTableStmt *from)
1898 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1900 newnode->subtype = from->subtype;
1902 newnode->relname = pstrdup(from->relname);
1903 newnode->inhOpt = from->inhOpt;
1905 newnode->name = pstrdup(from->name);
1906 Node_Copy(from, newnode, def);
1907 newnode->behavior = from->behavior;
1912 static ChangeACLStmt *
1913 _copyChangeACLStmt(ChangeACLStmt *from)
1915 ChangeACLStmt *newnode = makeNode(ChangeACLStmt);
1917 Node_Copy(from, newnode, relNames);
1918 if (from->aclString)
1919 newnode->aclString = pstrdup(from->aclString);
1924 static ClosePortalStmt *
1925 _copyClosePortalStmt(ClosePortalStmt *from)
1927 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1929 if (from->portalname)
1930 newnode->portalname = pstrdup(from->portalname);
1935 static ClusterStmt *
1936 _copyClusterStmt(ClusterStmt *from)
1938 ClusterStmt *newnode = makeNode(ClusterStmt);
1941 newnode->relname = pstrdup(from->relname);
1942 if (from->indexname)
1943 newnode->indexname = pstrdup(from->indexname);
1949 _copyCopyStmt(CopyStmt *from)
1951 CopyStmt *newnode = makeNode(CopyStmt);
1953 newnode->binary = from->binary;
1955 newnode->relname = pstrdup(from->relname);
1956 newnode->oids = from->oids;
1957 newnode->direction = from->direction;
1959 newnode->filename = pstrdup(from->filename);
1960 if (from->delimiter)
1961 newnode->delimiter = pstrdup(from->delimiter);
1962 if (from->null_print)
1963 newnode->null_print = pstrdup(from->null_print);
1969 _copyCreateStmt(CreateStmt *from)
1971 CreateStmt *newnode = makeNode(CreateStmt);
1973 newnode->istemp = from->istemp;
1974 newnode->relname = pstrdup(from->relname);
1975 Node_Copy(from, newnode, tableElts);
1976 Node_Copy(from, newnode, inhRelnames);
1977 Node_Copy(from, newnode, constraints);
1982 static VersionStmt *
1983 _copyVersionStmt(VersionStmt *from)
1985 VersionStmt *newnode = makeNode(VersionStmt);
1987 newnode->relname = pstrdup(from->relname);
1988 newnode->direction = from->direction;
1989 newnode->fromRelname = pstrdup(from->fromRelname);
1990 newnode->date = pstrdup(from->date);
1996 _copyDefineStmt(DefineStmt *from)
1998 DefineStmt *newnode = makeNode(DefineStmt);
2000 newnode->defType = from->defType;
2001 newnode->defname = pstrdup(from->defname);
2002 Node_Copy(from, newnode, definition);
2008 _copyDropStmt(DropStmt *from)
2010 DropStmt *newnode = makeNode(DropStmt);
2012 Node_Copy(from, newnode, names);
2013 newnode->removeType = from->removeType;
2018 static TruncateStmt *
2019 _copyTruncateStmt(TruncateStmt *from)
2021 TruncateStmt *newnode = makeNode(TruncateStmt);
2023 newnode->relName = pstrdup(from->relName);
2028 static CommentStmt *
2029 _copyCommentStmt(CommentStmt *from)
2031 CommentStmt *newnode = makeNode(CommentStmt);
2033 newnode->objtype = from->objtype;
2034 newnode->objname = pstrdup(from->objname);
2035 if (from->objproperty)
2036 newnode->objproperty = pstrdup(from->objproperty);
2037 Node_Copy(from, newnode, objlist);
2038 newnode->comment = pstrdup(from->comment);
2044 _copyExtendStmt(ExtendStmt *from)
2046 ExtendStmt *newnode = makeNode(ExtendStmt);
2048 newnode->idxname = pstrdup(from->idxname);
2049 Node_Copy(from, newnode, whereClause);
2050 Node_Copy(from, newnode, rangetable);
2056 _copyFetchStmt(FetchStmt *from)
2058 FetchStmt *newnode = makeNode(FetchStmt);
2060 newnode->direction = from->direction;
2061 newnode->howMany = from->howMany;
2062 newnode->portalname = pstrdup(from->portalname);
2063 newnode->ismove = from->ismove;
2069 _copyIndexStmt(IndexStmt *from)
2071 IndexStmt *newnode = makeNode(IndexStmt);
2073 newnode->idxname = pstrdup(from->idxname);
2074 newnode->relname = pstrdup(from->relname);
2075 newnode->accessMethod = pstrdup(from->accessMethod);
2076 Node_Copy(from, newnode, indexParams);
2077 Node_Copy(from, newnode, withClause);
2078 Node_Copy(from, newnode, whereClause);
2079 Node_Copy(from, newnode, rangetable);
2080 newnode->unique = from->unique;
2081 newnode->primary = from->primary;
2086 static ProcedureStmt *
2087 _copyProcedureStmt(ProcedureStmt *from)
2089 ProcedureStmt *newnode = makeNode(ProcedureStmt);
2091 newnode->funcname = pstrdup(from->funcname);
2092 Node_Copy(from, newnode, argTypes);
2093 Node_Copy(from, newnode, returnType);
2094 Node_Copy(from, newnode, withClause);
2095 Node_Copy(from, newnode, as);
2096 newnode->language = pstrdup(from->language);
2101 static RemoveAggrStmt *
2102 _copyRemoveAggrStmt(RemoveAggrStmt *from)
2104 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
2106 newnode->aggname = pstrdup(from->aggname);
2107 Node_Copy(from, newnode, aggtype);
2112 static RemoveFuncStmt *
2113 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2115 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2117 newnode->funcname = pstrdup(from->funcname);
2118 Node_Copy(from, newnode, args);
2123 static RemoveOperStmt *
2124 _copyRemoveOperStmt(RemoveOperStmt *from)
2126 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2128 newnode->opname = pstrdup(from->opname);
2129 Node_Copy(from, newnode, args);
2135 _copyRenameStmt(RenameStmt *from)
2137 RenameStmt *newnode = makeNode(RenameStmt);
2139 newnode->relname = pstrdup(from->relname);
2140 newnode->inhOpt = from->inhOpt;
2142 newnode->column = pstrdup(from->column);
2144 newnode->newname = pstrdup(from->newname);
2150 _copyRuleStmt(RuleStmt *from)
2152 RuleStmt *newnode = makeNode(RuleStmt);
2154 newnode->rulename = pstrdup(from->rulename);
2155 Node_Copy(from, newnode, whereClause);
2156 newnode->event = from->event;
2157 Node_Copy(from, newnode, object);
2158 newnode->instead = from->instead;
2159 Node_Copy(from, newnode, actions);
2165 _copyNotifyStmt(NotifyStmt *from)
2167 NotifyStmt *newnode = makeNode(NotifyStmt);
2170 newnode->relname = pstrdup(from->relname);
2176 _copyListenStmt(ListenStmt *from)
2178 ListenStmt *newnode = makeNode(ListenStmt);
2181 newnode->relname = pstrdup(from->relname);
2186 static UnlistenStmt *
2187 _copyUnlistenStmt(UnlistenStmt *from)
2189 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2192 newnode->relname = pstrdup(from->relname);
2197 static TransactionStmt *
2198 _copyTransactionStmt(TransactionStmt *from)
2200 TransactionStmt *newnode = makeNode(TransactionStmt);
2202 newnode->command = from->command;
2208 _copyViewStmt(ViewStmt *from)
2210 ViewStmt *newnode = makeNode(ViewStmt);
2213 newnode->viewname = pstrdup(from->viewname);
2214 Node_Copy(from, newnode, aliases);
2215 Node_Copy(from, newnode, query);
2221 _copyLoadStmt(LoadStmt *from)
2223 LoadStmt *newnode = makeNode(LoadStmt);
2226 newnode->filename = pstrdup(from->filename);
2231 static CreatedbStmt *
2232 _copyCreatedbStmt(CreatedbStmt *from)
2234 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2237 newnode->dbname = pstrdup(from->dbname);
2239 newnode->dbpath = pstrdup(from->dbpath);
2240 if (from->dbtemplate)
2241 newnode->dbtemplate = pstrdup(from->dbtemplate);
2242 newnode->encoding = from->encoding;
2248 _copyDropdbStmt(DropdbStmt *from)
2250 DropdbStmt *newnode = makeNode(DropdbStmt);
2253 newnode->dbname = pstrdup(from->dbname);
2259 _copyVacuumStmt(VacuumStmt *from)
2261 VacuumStmt *newnode = makeNode(VacuumStmt);
2263 newnode->verbose = from->verbose;
2264 newnode->analyze = from->analyze;
2266 newnode->vacrel = pstrdup(from->vacrel);
2267 Node_Copy(from, newnode, va_spec);
2272 static ExplainStmt *
2273 _copyExplainStmt(ExplainStmt *from)
2275 ExplainStmt *newnode = makeNode(ExplainStmt);
2277 Node_Copy(from, newnode, query);
2278 newnode->verbose = from->verbose;
2283 static CreateSeqStmt *
2284 _copyCreateSeqStmt(CreateSeqStmt *from)
2286 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2289 newnode->seqname = pstrdup(from->seqname);
2290 Node_Copy(from, newnode, options);
2295 static VariableSetStmt *
2296 _copyVariableSetStmt(VariableSetStmt *from)
2298 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2301 newnode->name = pstrdup(from->name);
2303 newnode->value = pstrdup(from->value);
2308 static VariableShowStmt *
2309 _copyVariableShowStmt(VariableShowStmt *from)
2311 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2314 newnode->name = pstrdup(from->name);
2319 static VariableResetStmt *
2320 _copyVariableResetStmt(VariableResetStmt *from)
2322 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2325 newnode->name = pstrdup(from->name);
2330 static CreateTrigStmt *
2331 _copyCreateTrigStmt(CreateTrigStmt *from)
2333 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2336 newnode->trigname = pstrdup(from->trigname);
2338 newnode->relname = pstrdup(from->relname);
2340 newnode->funcname = pstrdup(from->funcname);
2341 Node_Copy(from, newnode, args);
2342 newnode->before = from->before;
2343 newnode->row = from->row;
2344 memcpy(newnode->actions, from->actions, sizeof(from->actions));
2346 newnode->lang = pstrdup(from->lang);
2348 newnode->text = pstrdup(from->text);
2349 Node_Copy(from, newnode, attr);
2351 newnode->when = pstrdup(from->when);
2352 newnode->isconstraint = from->isconstraint;
2353 newnode->deferrable = from->deferrable;
2354 newnode->initdeferred = from->initdeferred;
2355 if (from->constrrelname)
2356 newnode->constrrelname = pstrdup(from->constrrelname);
2361 static DropTrigStmt *
2362 _copyDropTrigStmt(DropTrigStmt *from)
2364 DropTrigStmt *newnode = makeNode(DropTrigStmt);
2367 newnode->trigname = pstrdup(from->trigname);
2369 newnode->relname = pstrdup(from->relname);
2374 static CreatePLangStmt *
2375 _copyCreatePLangStmt(CreatePLangStmt *from)
2377 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2380 newnode->plname = pstrdup(from->plname);
2381 if (from->plhandler)
2382 newnode->plhandler = pstrdup(from->plhandler);
2383 if (from->plcompiler)
2384 newnode->plcompiler = pstrdup(from->plcompiler);
2385 newnode->pltrusted = from->pltrusted;
2390 static DropPLangStmt *
2391 _copyDropPLangStmt(DropPLangStmt *from)
2393 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2396 newnode->plname = pstrdup(from->plname);
2401 static CreateUserStmt *
2402 _copyCreateUserStmt(CreateUserStmt *from)
2404 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2407 newnode->user = pstrdup(from->user);
2409 newnode->password = pstrdup(from->password);
2410 newnode->sysid = from->sysid;
2411 newnode->createdb = from->createdb;
2412 newnode->createuser = from->createuser;
2413 Node_Copy(from, newnode, groupElts);
2414 if (from->validUntil)
2415 newnode->validUntil = pstrdup(from->validUntil);
2420 static AlterUserStmt *
2421 _copyAlterUserStmt(AlterUserStmt *from)
2423 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2426 newnode->user = pstrdup(from->user);
2428 newnode->password = pstrdup(from->password);
2429 newnode->createdb = from->createdb;
2430 newnode->createuser = from->createuser;
2431 if (from->validUntil)
2432 newnode->validUntil = pstrdup(from->validUntil);
2437 static DropUserStmt *
2438 _copyDropUserStmt(DropUserStmt *from)
2440 DropUserStmt *newnode = makeNode(DropUserStmt);
2442 Node_Copy(from, newnode, users);
2448 _copyLockStmt(LockStmt *from)
2450 LockStmt *newnode = makeNode(LockStmt);
2453 newnode->relname = pstrdup(from->relname);
2454 newnode->mode = from->mode;
2459 static ConstraintsSetStmt *
2460 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2462 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2464 Node_Copy(from, newnode, constraints);
2465 newnode->deferred = from->deferred;
2470 static CreateGroupStmt *
2471 _copyCreateGroupStmt(CreateGroupStmt *from)
2473 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2476 newnode->name = pstrdup(from->name);
2477 newnode->sysid = from->sysid;
2478 Node_Copy(from, newnode, initUsers);
2483 static AlterGroupStmt *
2484 _copyAlterGroupStmt(AlterGroupStmt *from)
2486 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2489 newnode->name = pstrdup(from->name);
2490 newnode->action = from->action;
2491 newnode->sysid = from->sysid;
2492 Node_Copy(from, newnode, listUsers);
2497 static DropGroupStmt *
2498 _copyDropGroupStmt(DropGroupStmt *from)
2500 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2503 newnode->name = pstrdup(from->name);
2508 static ReindexStmt *
2509 _copyReindexStmt(ReindexStmt *from)
2511 ReindexStmt *newnode = makeNode(ReindexStmt);
2513 newnode->reindexType = from->reindexType;
2515 newnode->name = pstrdup(from->name);
2516 newnode->force = from->force;
2517 newnode->all = from->all;
2523 /* ****************************************************************
2524 * pg_list.h copy functions
2525 * ****************************************************************
2529 _copyValue(Value *from)
2531 Value *newnode = makeNode(Value);
2533 newnode->type = from->type;
2537 newnode->val.ival = from->val.ival;
2542 newnode->val.str = pstrdup(from->val.str);
2551 * copyObject returns a copy of the node or list. If it is a list, it
2552 * recursively copies its items.
2556 copyObject(void *from)
2563 switch (nodeTag(from))
2570 retval = _copyPlan(from);
2573 retval = _copyResult(from);
2576 retval = _copyAppend(from);
2579 retval = _copyScan(from);
2582 retval = _copySeqScan(from);
2585 retval = _copyIndexScan(from);
2588 retval = _copyTidScan(from);
2590 case T_SubqueryScan:
2591 retval = _copySubqueryScan(from);
2594 retval = _copyJoin(from);
2597 retval = _copyNestLoop(from);
2600 retval = _copyMergeJoin(from);
2603 retval = _copyHashJoin(from);
2606 retval = _copyMaterial(from);
2609 retval = _copySort(from);
2612 retval = _copyGroup(from);
2615 retval = _copyAgg(from);
2618 retval = _copyUnique(from);
2621 retval = _copySetOp(from);
2624 retval = _copyLimit(from);
2627 retval = _copyHash(from);
2630 retval = _copySubPlan(from);
2637 retval = _copyResdom(from);
2640 retval = _copyFjoin(from);
2643 retval = _copyExpr(from);
2646 retval = _copyVar(from);
2649 retval = _copyOper(from);
2652 retval = _copyConst(from);
2655 retval = _copyParam(from);
2658 retval = _copyAggref(from);
2661 retval = _copySubLink(from);
2664 retval = _copyFunc(from);
2667 retval = _copyArrayRef(from);
2670 retval = _copyIter(from);
2673 retval = _copyFieldSelect(from);
2676 retval = _copyRelabelType(from);
2679 retval = _copyRangeTblRef(from);
2682 retval = _copyFromExpr(from);
2685 retval = _copyJoinExpr(from);
2692 retval = _copyRelOptInfo(from);
2695 retval = _copyPath(from);
2698 retval = _copyIndexPath(from);
2701 retval = _copyTidPath(from);
2704 retval = _copyAppendPath(from);
2707 retval = _copyNestPath(from);
2710 retval = _copyMergePath(from);
2713 retval = _copyHashPath(from);
2716 retval = _copyPathKeyItem(from);
2718 case T_RestrictInfo:
2719 retval = _copyRestrictInfo(from);
2722 retval = _copyJoinInfo(from);
2725 retval = _copyStream(from);
2727 case T_IndexOptInfo:
2728 retval = _copyIndexOptInfo(from);
2738 retval = _copyValue(from);
2746 /* rather ugly coding for speed... */
2747 /* Note the input list cannot be NIL if we got here. */
2748 nl = makeList1(copyObject(lfirst(list)));
2751 foreach(l, lnext(list))
2753 lnext(nl) = makeList1(copyObject(lfirst(l)));
2763 retval = _copyQuery(from);
2766 retval = _copyInsertStmt(from);
2769 retval = _copyDeleteStmt(from);
2772 retval = _copyUpdateStmt(from);
2775 retval = _copySelectStmt(from);
2777 case T_SetOperationStmt:
2778 retval = _copySetOperationStmt(from);
2780 case T_AlterTableStmt:
2781 retval = _copyAlterTableStmt(from);
2783 case T_ChangeACLStmt:
2784 retval = _copyChangeACLStmt(from);
2786 case T_ClosePortalStmt:
2787 retval = _copyClosePortalStmt(from);
2790 retval = _copyClusterStmt(from);
2793 retval = _copyCopyStmt(from);
2796 retval = _copyCreateStmt(from);
2799 retval = _copyVersionStmt(from);
2802 retval = _copyDefineStmt(from);
2805 retval = _copyDropStmt(from);
2807 case T_TruncateStmt:
2808 retval = _copyTruncateStmt(from);
2811 retval = _copyCommentStmt(from);
2814 retval = _copyExtendStmt(from);
2817 retval = _copyFetchStmt(from);
2820 retval = _copyIndexStmt(from);
2822 case T_ProcedureStmt:
2823 retval = _copyProcedureStmt(from);
2825 case T_RemoveAggrStmt:
2826 retval = _copyRemoveAggrStmt(from);
2828 case T_RemoveFuncStmt:
2829 retval = _copyRemoveFuncStmt(from);
2831 case T_RemoveOperStmt:
2832 retval = _copyRemoveOperStmt(from);
2835 retval = _copyRenameStmt(from);
2838 retval = _copyRuleStmt(from);
2841 retval = _copyNotifyStmt(from);
2844 retval = _copyListenStmt(from);
2846 case T_UnlistenStmt:
2847 retval = _copyUnlistenStmt(from);
2849 case T_TransactionStmt:
2850 retval = _copyTransactionStmt(from);
2853 retval = _copyViewStmt(from);
2856 retval = _copyLoadStmt(from);
2858 case T_CreatedbStmt:
2859 retval = _copyCreatedbStmt(from);
2862 retval = _copyDropdbStmt(from);
2865 retval = _copyVacuumStmt(from);
2868 retval = _copyExplainStmt(from);
2870 case T_CreateSeqStmt:
2871 retval = _copyCreateSeqStmt(from);
2873 case T_VariableSetStmt:
2874 retval = _copyVariableSetStmt(from);
2876 case T_VariableShowStmt:
2877 retval = _copyVariableShowStmt(from);
2879 case T_VariableResetStmt:
2880 retval = _copyVariableResetStmt(from);
2882 case T_CreateTrigStmt:
2883 retval = _copyCreateTrigStmt(from);
2885 case T_DropTrigStmt:
2886 retval = _copyDropTrigStmt(from);
2888 case T_CreatePLangStmt:
2889 retval = _copyCreatePLangStmt(from);
2891 case T_DropPLangStmt:
2892 retval = _copyDropPLangStmt(from);
2894 case T_CreateUserStmt:
2895 retval = _copyCreateUserStmt(from);
2897 case T_AlterUserStmt:
2898 retval = _copyAlterUserStmt(from);
2900 case T_DropUserStmt:
2901 retval = _copyDropUserStmt(from);
2904 retval = _copyLockStmt(from);
2906 case T_ConstraintsSetStmt:
2907 retval = _copyConstraintsSetStmt(from);
2909 case T_CreateGroupStmt:
2910 retval = _copyCreateGroupStmt(from);
2912 case T_AlterGroupStmt:
2913 retval = _copyAlterGroupStmt(from);
2915 case T_DropGroupStmt:
2916 retval = _copyDropGroupStmt(from);
2919 retval = _copyReindexStmt(from);
2921 case T_CheckPointStmt:
2922 retval = (void*)makeNode(CheckPointStmt);
2926 retval = _copyAExpr(from);
2929 retval = _copyAttr(from);
2932 retval = _copyAConst(from);
2935 retval = _copyParamNo(from);
2938 retval = _copyIdent(from);
2941 retval = _copyFuncCall(from);
2944 retval = _copyAIndices(from);
2947 retval = _copyResTarget(from);
2950 retval = _copyTypeCast(from);
2953 retval = _copySortGroupBy(from);
2956 retval = _copyRangeVar(from);
2958 case T_RangeSubselect:
2959 retval = _copyRangeSubselect(from);
2962 retval = _copyTypeName(from);
2965 retval = _copyIndexElem(from);
2968 retval = _copyColumnDef(from);
2971 retval = _copyConstraint(from);
2974 retval = _copyDefElem(from);
2977 retval = _copyTargetEntry(from);
2979 case T_RangeTblEntry:
2980 retval = _copyRangeTblEntry(from);
2983 retval = _copySortClause(from);
2986 retval = _copyGroupClause(from);
2989 retval = _copyCaseExpr(from);
2992 retval = _copyCaseWhen(from);
2994 case T_FkConstraint:
2995 retval = _copyFkConstraint(from);
2999 elog(ERROR, "copyObject: don't know how to copy node type %d",
3001 retval = from; /* keep compiler quiet */