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.139 2001/03/22 03:59:31 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;
1429 * Do not copy pathkeys, since they'd not be canonical in a copied
1432 newnode->left_pathkey = NIL;
1433 newnode->right_pathkey = NIL;
1434 newnode->hashjoinoperator = from->hashjoinoperator;
1435 newnode->left_dispersion = from->left_dispersion;
1436 newnode->right_dispersion = from->right_dispersion;
1446 _copyJoinInfo(JoinInfo *from)
1448 JoinInfo *newnode = makeNode(JoinInfo);
1451 * copy remainder of node
1454 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1455 Node_Copy(from, newnode, jinfo_restrictinfo);
1461 _copyIter(Iter *from)
1463 Iter *newnode = makeNode(Iter);
1465 Node_Copy(from, newnode, iterexpr);
1466 newnode->itertype = from->itertype;
1472 _copyStream(Stream *from)
1474 Stream *newnode = makeNode(Stream);
1476 newnode->pathptr = from->pathptr;
1477 newnode->cinfo = from->cinfo;
1478 newnode->clausetype = from->clausetype;
1480 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1482 Node_Copy(from, newnode, downstream);
1483 if (newnode->downstream)
1484 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1486 newnode->groupup = from->groupup;
1487 newnode->groupcost = from->groupcost;
1488 newnode->groupsel = from->groupsel;
1493 /* ****************************************************************
1494 * parsenodes.h copy functions
1495 * ****************************************************************
1498 static TargetEntry *
1499 _copyTargetEntry(TargetEntry *from)
1501 TargetEntry *newnode = makeNode(TargetEntry);
1503 Node_Copy(from, newnode, resdom);
1504 Node_Copy(from, newnode, fjoin);
1505 Node_Copy(from, newnode, expr);
1509 static RangeTblEntry *
1510 _copyRangeTblEntry(RangeTblEntry *from)
1512 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1515 newnode->relname = pstrdup(from->relname);
1516 newnode->relid = from->relid;
1517 Node_Copy(from, newnode, subquery);
1518 Node_Copy(from, newnode, alias);
1519 Node_Copy(from, newnode, eref);
1520 newnode->inh = from->inh;
1521 newnode->inFromCl = from->inFromCl;
1522 newnode->checkForRead = from->checkForRead;
1523 newnode->checkForWrite = from->checkForWrite;
1524 newnode->checkAsUser = from->checkAsUser;
1529 static FkConstraint *
1530 _copyFkConstraint(FkConstraint *from)
1532 FkConstraint *newnode = makeNode(FkConstraint);
1534 if (from->constr_name)
1535 newnode->constr_name = pstrdup(from->constr_name);
1536 if (from->pktable_name)
1537 newnode->pktable_name = pstrdup(from->pktable_name);
1538 Node_Copy(from, newnode, fk_attrs);
1539 Node_Copy(from, newnode, pk_attrs);
1540 if (from->match_type)
1541 newnode->match_type = pstrdup(from->match_type);
1542 newnode->actions = from->actions;
1543 newnode->deferrable = from->deferrable;
1544 newnode->initdeferred = from->initdeferred;
1550 _copySortClause(SortClause *from)
1552 SortClause *newnode = makeNode(SortClause);
1554 newnode->tleSortGroupRef = from->tleSortGroupRef;
1555 newnode->sortop = from->sortop;
1561 _copyAExpr(A_Expr *from)
1563 A_Expr *newnode = makeNode(A_Expr);
1565 newnode->oper = from->oper;
1567 newnode->opname = pstrdup(from->opname);
1568 Node_Copy(from, newnode, lexpr);
1569 Node_Copy(from, newnode, rexpr);
1575 _copyAConst(A_Const *from)
1577 A_Const *newnode = makeNode(A_Const);
1579 newnode->val = *((Value *) (copyObject(&(from->val))));
1580 Node_Copy(from, newnode, typename);
1586 _copyParamNo(ParamNo *from)
1588 ParamNo *newnode = makeNode(ParamNo);
1590 newnode->number = from->number;
1591 Node_Copy(from, newnode, typename);
1592 Node_Copy(from, newnode, indirection);
1598 _copyIdent(Ident *from)
1600 Ident *newnode = makeNode(Ident);
1603 newnode->name = pstrdup(from->name);
1604 Node_Copy(from, newnode, indirection);
1605 newnode->isRel = from->isRel;
1611 _copyFuncCall(FuncCall *from)
1613 FuncCall *newnode = makeNode(FuncCall);
1616 newnode->funcname = pstrdup(from->funcname);
1617 Node_Copy(from, newnode, args);
1618 newnode->agg_star = from->agg_star;
1619 newnode->agg_distinct = from->agg_distinct;
1625 _copyAIndices(A_Indices *from)
1627 A_Indices *newnode = makeNode(A_Indices);
1629 Node_Copy(from, newnode, lidx);
1630 Node_Copy(from, newnode, uidx);
1636 _copyResTarget(ResTarget *from)
1638 ResTarget *newnode = makeNode(ResTarget);
1641 newnode->name = pstrdup(from->name);
1642 Node_Copy(from, newnode, indirection);
1643 Node_Copy(from, newnode, val);
1649 _copyTypeName(TypeName *from)
1651 TypeName *newnode = makeNode(TypeName);
1654 newnode->name = pstrdup(from->name);
1655 newnode->timezone = from->timezone;
1656 newnode->setof = from->setof;
1657 newnode->typmod = from->typmod;
1658 Node_Copy(from, newnode, arrayBounds);
1663 static SortGroupBy *
1664 _copySortGroupBy(SortGroupBy *from)
1666 SortGroupBy *newnode = makeNode(SortGroupBy);
1669 newnode->useOp = pstrdup(from->useOp);
1670 Node_Copy(from, newnode, node);
1676 _copyRangeVar(RangeVar *from)
1678 RangeVar *newnode = makeNode(RangeVar);
1681 newnode->relname = pstrdup(from->relname);
1682 newnode->inhOpt = from->inhOpt;
1683 Node_Copy(from, newnode, name);
1688 static RangeSubselect *
1689 _copyRangeSubselect(RangeSubselect *from)
1691 RangeSubselect *newnode = makeNode(RangeSubselect);
1693 Node_Copy(from, newnode, subquery);
1694 Node_Copy(from, newnode, name);
1700 _copyTypeCast(TypeCast *from)
1702 TypeCast *newnode = makeNode(TypeCast);
1704 Node_Copy(from, newnode, arg);
1705 Node_Copy(from, newnode, typename);
1711 _copyIndexElem(IndexElem *from)
1713 IndexElem *newnode = makeNode(IndexElem);
1716 newnode->name = pstrdup(from->name);
1717 Node_Copy(from, newnode, args);
1719 newnode->class = pstrdup(from->class);
1725 _copyColumnDef(ColumnDef *from)
1727 ColumnDef *newnode = makeNode(ColumnDef);
1730 newnode->colname = pstrdup(from->colname);
1731 Node_Copy(from, newnode, typename);
1732 newnode->is_not_null = from->is_not_null;
1733 newnode->is_sequence = from->is_sequence;
1734 Node_Copy(from, newnode, raw_default);
1735 if (from->cooked_default)
1736 newnode->cooked_default = pstrdup(from->cooked_default);
1737 Node_Copy(from, newnode, constraints);
1743 _copyConstraint(Constraint *from)
1745 Constraint *newnode = makeNode(Constraint);
1747 newnode->contype = from->contype;
1749 newnode->name = pstrdup(from->name);
1750 Node_Copy(from, newnode, raw_expr);
1751 if (from->cooked_expr)
1752 newnode->cooked_expr = pstrdup(from->cooked_expr);
1753 Node_Copy(from, newnode, keys);
1759 _copyDefElem(DefElem *from)
1761 DefElem *newnode = makeNode(DefElem);
1764 newnode->defname = pstrdup(from->defname);
1765 Node_Copy(from, newnode, arg);
1771 _copyQuery(Query *from)
1773 Query *newnode = makeNode(Query);
1775 newnode->commandType = from->commandType;
1776 Node_Copy(from, newnode, utilityStmt);
1777 newnode->resultRelation = from->resultRelation;
1779 newnode->into = pstrdup(from->into);
1780 newnode->isPortal = from->isPortal;
1781 newnode->isBinary = from->isBinary;
1782 newnode->isTemp = from->isTemp;
1783 newnode->hasAggs = from->hasAggs;
1784 newnode->hasSubLinks = from->hasSubLinks;
1786 Node_Copy(from, newnode, rtable);
1787 Node_Copy(from, newnode, jointree);
1789 newnode->rowMarks = listCopy(from->rowMarks);
1791 Node_Copy(from, newnode, targetList);
1793 Node_Copy(from, newnode, groupClause);
1794 Node_Copy(from, newnode, havingQual);
1795 Node_Copy(from, newnode, distinctClause);
1796 Node_Copy(from, newnode, sortClause);
1798 Node_Copy(from, newnode, limitOffset);
1799 Node_Copy(from, newnode, limitCount);
1801 Node_Copy(from, newnode, setOperations);
1803 newnode->resultRelations = listCopy(from->resultRelations);
1806 * We do not copy the planner internal fields: base_rel_list,
1807 * join_rel_list, equi_key_list, query_pathkeys. Not entirely clear if
1815 _copyInsertStmt(InsertStmt *from)
1817 InsertStmt *newnode = makeNode(InsertStmt);
1820 newnode->relname = pstrdup(from->relname);
1821 Node_Copy(from, newnode, cols);
1822 Node_Copy(from, newnode, targetList);
1823 Node_Copy(from, newnode, selectStmt);
1829 _copyDeleteStmt(DeleteStmt *from)
1831 DeleteStmt *newnode = makeNode(DeleteStmt);
1834 newnode->relname = pstrdup(from->relname);
1835 Node_Copy(from, newnode, whereClause);
1836 newnode->inhOpt = from->inhOpt;
1842 _copyUpdateStmt(UpdateStmt *from)
1844 UpdateStmt *newnode = makeNode(UpdateStmt);
1847 newnode->relname = pstrdup(from->relname);
1848 Node_Copy(from, newnode, targetList);
1849 Node_Copy(from, newnode, whereClause);
1850 Node_Copy(from, newnode, fromClause);
1851 newnode->inhOpt = from->inhOpt;
1857 _copySelectStmt(SelectStmt *from)
1859 SelectStmt *newnode = makeNode(SelectStmt);
1861 Node_Copy(from, newnode, distinctClause);
1863 newnode->into = pstrdup(from->into);
1864 newnode->istemp = from->istemp;
1865 Node_Copy(from, newnode, targetList);
1866 Node_Copy(from, newnode, fromClause);
1867 Node_Copy(from, newnode, whereClause);
1868 Node_Copy(from, newnode, groupClause);
1869 Node_Copy(from, newnode, havingClause);
1870 Node_Copy(from, newnode, sortClause);
1871 if (from->portalname)
1872 newnode->portalname = pstrdup(from->portalname);
1873 newnode->binary = from->binary;
1874 Node_Copy(from, newnode, limitOffset);
1875 Node_Copy(from, newnode, limitCount);
1876 Node_Copy(from, newnode, forUpdate);
1877 newnode->op = from->op;
1878 newnode->all = from->all;
1879 Node_Copy(from, newnode, larg);
1880 Node_Copy(from, newnode, rarg);
1885 static SetOperationStmt *
1886 _copySetOperationStmt(SetOperationStmt *from)
1888 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1890 newnode->op = from->op;
1891 newnode->all = from->all;
1892 Node_Copy(from, newnode, larg);
1893 Node_Copy(from, newnode, rarg);
1894 newnode->colTypes = listCopy(from->colTypes);
1899 static AlterTableStmt *
1900 _copyAlterTableStmt(AlterTableStmt *from)
1902 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1904 newnode->subtype = from->subtype;
1906 newnode->relname = pstrdup(from->relname);
1907 newnode->inhOpt = from->inhOpt;
1909 newnode->name = pstrdup(from->name);
1910 Node_Copy(from, newnode, def);
1911 newnode->behavior = from->behavior;
1916 static ChangeACLStmt *
1917 _copyChangeACLStmt(ChangeACLStmt *from)
1919 ChangeACLStmt *newnode = makeNode(ChangeACLStmt);
1921 Node_Copy(from, newnode, relNames);
1922 if (from->aclString)
1923 newnode->aclString = pstrdup(from->aclString);
1928 static ClosePortalStmt *
1929 _copyClosePortalStmt(ClosePortalStmt *from)
1931 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1933 if (from->portalname)
1934 newnode->portalname = pstrdup(from->portalname);
1939 static ClusterStmt *
1940 _copyClusterStmt(ClusterStmt *from)
1942 ClusterStmt *newnode = makeNode(ClusterStmt);
1945 newnode->relname = pstrdup(from->relname);
1946 if (from->indexname)
1947 newnode->indexname = pstrdup(from->indexname);
1953 _copyCopyStmt(CopyStmt *from)
1955 CopyStmt *newnode = makeNode(CopyStmt);
1957 newnode->binary = from->binary;
1959 newnode->relname = pstrdup(from->relname);
1960 newnode->oids = from->oids;
1961 newnode->direction = from->direction;
1963 newnode->filename = pstrdup(from->filename);
1964 if (from->delimiter)
1965 newnode->delimiter = pstrdup(from->delimiter);
1966 if (from->null_print)
1967 newnode->null_print = pstrdup(from->null_print);
1973 _copyCreateStmt(CreateStmt *from)
1975 CreateStmt *newnode = makeNode(CreateStmt);
1977 newnode->istemp = from->istemp;
1978 newnode->relname = pstrdup(from->relname);
1979 Node_Copy(from, newnode, tableElts);
1980 Node_Copy(from, newnode, inhRelnames);
1981 Node_Copy(from, newnode, constraints);
1986 static VersionStmt *
1987 _copyVersionStmt(VersionStmt *from)
1989 VersionStmt *newnode = makeNode(VersionStmt);
1991 newnode->relname = pstrdup(from->relname);
1992 newnode->direction = from->direction;
1993 newnode->fromRelname = pstrdup(from->fromRelname);
1994 newnode->date = pstrdup(from->date);
2000 _copyDefineStmt(DefineStmt *from)
2002 DefineStmt *newnode = makeNode(DefineStmt);
2004 newnode->defType = from->defType;
2005 newnode->defname = pstrdup(from->defname);
2006 Node_Copy(from, newnode, definition);
2012 _copyDropStmt(DropStmt *from)
2014 DropStmt *newnode = makeNode(DropStmt);
2016 Node_Copy(from, newnode, names);
2017 newnode->removeType = from->removeType;
2022 static TruncateStmt *
2023 _copyTruncateStmt(TruncateStmt *from)
2025 TruncateStmt *newnode = makeNode(TruncateStmt);
2027 newnode->relName = pstrdup(from->relName);
2032 static CommentStmt *
2033 _copyCommentStmt(CommentStmt *from)
2035 CommentStmt *newnode = makeNode(CommentStmt);
2037 newnode->objtype = from->objtype;
2038 newnode->objname = pstrdup(from->objname);
2039 if (from->objproperty)
2040 newnode->objproperty = pstrdup(from->objproperty);
2041 Node_Copy(from, newnode, objlist);
2042 newnode->comment = pstrdup(from->comment);
2048 _copyExtendStmt(ExtendStmt *from)
2050 ExtendStmt *newnode = makeNode(ExtendStmt);
2052 newnode->idxname = pstrdup(from->idxname);
2053 Node_Copy(from, newnode, whereClause);
2054 Node_Copy(from, newnode, rangetable);
2060 _copyFetchStmt(FetchStmt *from)
2062 FetchStmt *newnode = makeNode(FetchStmt);
2064 newnode->direction = from->direction;
2065 newnode->howMany = from->howMany;
2066 newnode->portalname = pstrdup(from->portalname);
2067 newnode->ismove = from->ismove;
2073 _copyIndexStmt(IndexStmt *from)
2075 IndexStmt *newnode = makeNode(IndexStmt);
2077 newnode->idxname = pstrdup(from->idxname);
2078 newnode->relname = pstrdup(from->relname);
2079 newnode->accessMethod = pstrdup(from->accessMethod);
2080 Node_Copy(from, newnode, indexParams);
2081 Node_Copy(from, newnode, withClause);
2082 Node_Copy(from, newnode, whereClause);
2083 Node_Copy(from, newnode, rangetable);
2084 newnode->unique = from->unique;
2085 newnode->primary = from->primary;
2090 static ProcedureStmt *
2091 _copyProcedureStmt(ProcedureStmt *from)
2093 ProcedureStmt *newnode = makeNode(ProcedureStmt);
2095 newnode->funcname = pstrdup(from->funcname);
2096 Node_Copy(from, newnode, argTypes);
2097 Node_Copy(from, newnode, returnType);
2098 Node_Copy(from, newnode, withClause);
2099 Node_Copy(from, newnode, as);
2100 newnode->language = pstrdup(from->language);
2105 static RemoveAggrStmt *
2106 _copyRemoveAggrStmt(RemoveAggrStmt *from)
2108 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
2110 newnode->aggname = pstrdup(from->aggname);
2111 Node_Copy(from, newnode, aggtype);
2116 static RemoveFuncStmt *
2117 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2119 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2121 newnode->funcname = pstrdup(from->funcname);
2122 Node_Copy(from, newnode, args);
2127 static RemoveOperStmt *
2128 _copyRemoveOperStmt(RemoveOperStmt *from)
2130 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2132 newnode->opname = pstrdup(from->opname);
2133 Node_Copy(from, newnode, args);
2139 _copyRenameStmt(RenameStmt *from)
2141 RenameStmt *newnode = makeNode(RenameStmt);
2143 newnode->relname = pstrdup(from->relname);
2144 newnode->inhOpt = from->inhOpt;
2146 newnode->column = pstrdup(from->column);
2148 newnode->newname = pstrdup(from->newname);
2154 _copyRuleStmt(RuleStmt *from)
2156 RuleStmt *newnode = makeNode(RuleStmt);
2158 newnode->rulename = pstrdup(from->rulename);
2159 Node_Copy(from, newnode, whereClause);
2160 newnode->event = from->event;
2161 Node_Copy(from, newnode, object);
2162 newnode->instead = from->instead;
2163 Node_Copy(from, newnode, actions);
2169 _copyNotifyStmt(NotifyStmt *from)
2171 NotifyStmt *newnode = makeNode(NotifyStmt);
2174 newnode->relname = pstrdup(from->relname);
2180 _copyListenStmt(ListenStmt *from)
2182 ListenStmt *newnode = makeNode(ListenStmt);
2185 newnode->relname = pstrdup(from->relname);
2190 static UnlistenStmt *
2191 _copyUnlistenStmt(UnlistenStmt *from)
2193 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2196 newnode->relname = pstrdup(from->relname);
2201 static TransactionStmt *
2202 _copyTransactionStmt(TransactionStmt *from)
2204 TransactionStmt *newnode = makeNode(TransactionStmt);
2206 newnode->command = from->command;
2212 _copyViewStmt(ViewStmt *from)
2214 ViewStmt *newnode = makeNode(ViewStmt);
2217 newnode->viewname = pstrdup(from->viewname);
2218 Node_Copy(from, newnode, aliases);
2219 Node_Copy(from, newnode, query);
2225 _copyLoadStmt(LoadStmt *from)
2227 LoadStmt *newnode = makeNode(LoadStmt);
2230 newnode->filename = pstrdup(from->filename);
2235 static CreatedbStmt *
2236 _copyCreatedbStmt(CreatedbStmt *from)
2238 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2241 newnode->dbname = pstrdup(from->dbname);
2243 newnode->dbpath = pstrdup(from->dbpath);
2244 if (from->dbtemplate)
2245 newnode->dbtemplate = pstrdup(from->dbtemplate);
2246 newnode->encoding = from->encoding;
2252 _copyDropdbStmt(DropdbStmt *from)
2254 DropdbStmt *newnode = makeNode(DropdbStmt);
2257 newnode->dbname = pstrdup(from->dbname);
2263 _copyVacuumStmt(VacuumStmt *from)
2265 VacuumStmt *newnode = makeNode(VacuumStmt);
2267 newnode->verbose = from->verbose;
2268 newnode->analyze = from->analyze;
2270 newnode->vacrel = pstrdup(from->vacrel);
2271 Node_Copy(from, newnode, va_spec);
2276 static ExplainStmt *
2277 _copyExplainStmt(ExplainStmt *from)
2279 ExplainStmt *newnode = makeNode(ExplainStmt);
2281 Node_Copy(from, newnode, query);
2282 newnode->verbose = from->verbose;
2287 static CreateSeqStmt *
2288 _copyCreateSeqStmt(CreateSeqStmt *from)
2290 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2293 newnode->seqname = pstrdup(from->seqname);
2294 Node_Copy(from, newnode, options);
2299 static VariableSetStmt *
2300 _copyVariableSetStmt(VariableSetStmt *from)
2302 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2305 newnode->name = pstrdup(from->name);
2307 newnode->value = pstrdup(from->value);
2312 static VariableShowStmt *
2313 _copyVariableShowStmt(VariableShowStmt *from)
2315 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2318 newnode->name = pstrdup(from->name);
2323 static VariableResetStmt *
2324 _copyVariableResetStmt(VariableResetStmt *from)
2326 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2329 newnode->name = pstrdup(from->name);
2334 static CreateTrigStmt *
2335 _copyCreateTrigStmt(CreateTrigStmt *from)
2337 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2340 newnode->trigname = pstrdup(from->trigname);
2342 newnode->relname = pstrdup(from->relname);
2344 newnode->funcname = pstrdup(from->funcname);
2345 Node_Copy(from, newnode, args);
2346 newnode->before = from->before;
2347 newnode->row = from->row;
2348 memcpy(newnode->actions, from->actions, sizeof(from->actions));
2350 newnode->lang = pstrdup(from->lang);
2352 newnode->text = pstrdup(from->text);
2354 Node_Copy(from, newnode, attr);
2356 newnode->when = pstrdup(from->when);
2357 newnode->isconstraint = from->isconstraint;
2358 newnode->deferrable = from->deferrable;
2359 newnode->initdeferred = from->initdeferred;
2360 if (from->constrrelname)
2361 newnode->constrrelname = pstrdup(from->constrrelname);
2366 static DropTrigStmt *
2367 _copyDropTrigStmt(DropTrigStmt *from)
2369 DropTrigStmt *newnode = makeNode(DropTrigStmt);
2372 newnode->trigname = pstrdup(from->trigname);
2374 newnode->relname = pstrdup(from->relname);
2379 static CreatePLangStmt *
2380 _copyCreatePLangStmt(CreatePLangStmt *from)
2382 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2385 newnode->plname = pstrdup(from->plname);
2386 if (from->plhandler)
2387 newnode->plhandler = pstrdup(from->plhandler);
2388 if (from->plcompiler)
2389 newnode->plcompiler = pstrdup(from->plcompiler);
2390 newnode->pltrusted = from->pltrusted;
2395 static DropPLangStmt *
2396 _copyDropPLangStmt(DropPLangStmt *from)
2398 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2401 newnode->plname = pstrdup(from->plname);
2406 static CreateUserStmt *
2407 _copyCreateUserStmt(CreateUserStmt *from)
2409 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2412 newnode->user = pstrdup(from->user);
2414 newnode->password = pstrdup(from->password);
2415 newnode->sysid = from->sysid;
2416 newnode->createdb = from->createdb;
2417 newnode->createuser = from->createuser;
2418 Node_Copy(from, newnode, groupElts);
2419 if (from->validUntil)
2420 newnode->validUntil = pstrdup(from->validUntil);
2425 static AlterUserStmt *
2426 _copyAlterUserStmt(AlterUserStmt *from)
2428 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2431 newnode->user = pstrdup(from->user);
2433 newnode->password = pstrdup(from->password);
2434 newnode->createdb = from->createdb;
2435 newnode->createuser = from->createuser;
2436 if (from->validUntil)
2437 newnode->validUntil = pstrdup(from->validUntil);
2442 static DropUserStmt *
2443 _copyDropUserStmt(DropUserStmt *from)
2445 DropUserStmt *newnode = makeNode(DropUserStmt);
2447 Node_Copy(from, newnode, users);
2453 _copyLockStmt(LockStmt *from)
2455 LockStmt *newnode = makeNode(LockStmt);
2458 newnode->relname = pstrdup(from->relname);
2459 newnode->mode = from->mode;
2464 static ConstraintsSetStmt *
2465 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2467 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2469 Node_Copy(from, newnode, constraints);
2470 newnode->deferred = from->deferred;
2475 static CreateGroupStmt *
2476 _copyCreateGroupStmt(CreateGroupStmt *from)
2478 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2481 newnode->name = pstrdup(from->name);
2482 newnode->sysid = from->sysid;
2483 Node_Copy(from, newnode, initUsers);
2488 static AlterGroupStmt *
2489 _copyAlterGroupStmt(AlterGroupStmt *from)
2491 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2494 newnode->name = pstrdup(from->name);
2495 newnode->action = from->action;
2496 newnode->sysid = from->sysid;
2497 Node_Copy(from, newnode, listUsers);
2502 static DropGroupStmt *
2503 _copyDropGroupStmt(DropGroupStmt *from)
2505 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2508 newnode->name = pstrdup(from->name);
2513 static ReindexStmt *
2514 _copyReindexStmt(ReindexStmt *from)
2516 ReindexStmt *newnode = makeNode(ReindexStmt);
2518 newnode->reindexType = from->reindexType;
2520 newnode->name = pstrdup(from->name);
2521 newnode->force = from->force;
2522 newnode->all = from->all;
2528 /* ****************************************************************
2529 * pg_list.h copy functions
2530 * ****************************************************************
2534 _copyValue(Value *from)
2536 Value *newnode = makeNode(Value);
2538 newnode->type = from->type;
2542 newnode->val.ival = from->val.ival;
2547 newnode->val.str = pstrdup(from->val.str);
2556 * copyObject returns a copy of the node or list. If it is a list, it
2557 * recursively copies its items.
2561 copyObject(void *from)
2568 switch (nodeTag(from))
2575 retval = _copyPlan(from);
2578 retval = _copyResult(from);
2581 retval = _copyAppend(from);
2584 retval = _copyScan(from);
2587 retval = _copySeqScan(from);
2590 retval = _copyIndexScan(from);
2593 retval = _copyTidScan(from);
2595 case T_SubqueryScan:
2596 retval = _copySubqueryScan(from);
2599 retval = _copyJoin(from);
2602 retval = _copyNestLoop(from);
2605 retval = _copyMergeJoin(from);
2608 retval = _copyHashJoin(from);
2611 retval = _copyMaterial(from);
2614 retval = _copySort(from);
2617 retval = _copyGroup(from);
2620 retval = _copyAgg(from);
2623 retval = _copyUnique(from);
2626 retval = _copySetOp(from);
2629 retval = _copyLimit(from);
2632 retval = _copyHash(from);
2635 retval = _copySubPlan(from);
2642 retval = _copyResdom(from);
2645 retval = _copyFjoin(from);
2648 retval = _copyExpr(from);
2651 retval = _copyVar(from);
2654 retval = _copyOper(from);
2657 retval = _copyConst(from);
2660 retval = _copyParam(from);
2663 retval = _copyAggref(from);
2666 retval = _copySubLink(from);
2669 retval = _copyFunc(from);
2672 retval = _copyArrayRef(from);
2675 retval = _copyIter(from);
2678 retval = _copyFieldSelect(from);
2681 retval = _copyRelabelType(from);
2684 retval = _copyRangeTblRef(from);
2687 retval = _copyFromExpr(from);
2690 retval = _copyJoinExpr(from);
2697 retval = _copyRelOptInfo(from);
2700 retval = _copyPath(from);
2703 retval = _copyIndexPath(from);
2706 retval = _copyTidPath(from);
2709 retval = _copyAppendPath(from);
2712 retval = _copyNestPath(from);
2715 retval = _copyMergePath(from);
2718 retval = _copyHashPath(from);
2721 retval = _copyPathKeyItem(from);
2723 case T_RestrictInfo:
2724 retval = _copyRestrictInfo(from);
2727 retval = _copyJoinInfo(from);
2730 retval = _copyStream(from);
2732 case T_IndexOptInfo:
2733 retval = _copyIndexOptInfo(from);
2743 retval = _copyValue(from);
2751 /* rather ugly coding for speed... */
2752 /* Note the input list cannot be NIL if we got here. */
2753 nl = makeList1(copyObject(lfirst(list)));
2756 foreach(l, lnext(list))
2758 lnext(nl) = makeList1(copyObject(lfirst(l)));
2768 retval = _copyQuery(from);
2771 retval = _copyInsertStmt(from);
2774 retval = _copyDeleteStmt(from);
2777 retval = _copyUpdateStmt(from);
2780 retval = _copySelectStmt(from);
2782 case T_SetOperationStmt:
2783 retval = _copySetOperationStmt(from);
2785 case T_AlterTableStmt:
2786 retval = _copyAlterTableStmt(from);
2788 case T_ChangeACLStmt:
2789 retval = _copyChangeACLStmt(from);
2791 case T_ClosePortalStmt:
2792 retval = _copyClosePortalStmt(from);
2795 retval = _copyClusterStmt(from);
2798 retval = _copyCopyStmt(from);
2801 retval = _copyCreateStmt(from);
2804 retval = _copyVersionStmt(from);
2807 retval = _copyDefineStmt(from);
2810 retval = _copyDropStmt(from);
2812 case T_TruncateStmt:
2813 retval = _copyTruncateStmt(from);
2816 retval = _copyCommentStmt(from);
2819 retval = _copyExtendStmt(from);
2822 retval = _copyFetchStmt(from);
2825 retval = _copyIndexStmt(from);
2827 case T_ProcedureStmt:
2828 retval = _copyProcedureStmt(from);
2830 case T_RemoveAggrStmt:
2831 retval = _copyRemoveAggrStmt(from);
2833 case T_RemoveFuncStmt:
2834 retval = _copyRemoveFuncStmt(from);
2836 case T_RemoveOperStmt:
2837 retval = _copyRemoveOperStmt(from);
2840 retval = _copyRenameStmt(from);
2843 retval = _copyRuleStmt(from);
2846 retval = _copyNotifyStmt(from);
2849 retval = _copyListenStmt(from);
2851 case T_UnlistenStmt:
2852 retval = _copyUnlistenStmt(from);
2854 case T_TransactionStmt:
2855 retval = _copyTransactionStmt(from);
2858 retval = _copyViewStmt(from);
2861 retval = _copyLoadStmt(from);
2863 case T_CreatedbStmt:
2864 retval = _copyCreatedbStmt(from);
2867 retval = _copyDropdbStmt(from);
2870 retval = _copyVacuumStmt(from);
2873 retval = _copyExplainStmt(from);
2875 case T_CreateSeqStmt:
2876 retval = _copyCreateSeqStmt(from);
2878 case T_VariableSetStmt:
2879 retval = _copyVariableSetStmt(from);
2881 case T_VariableShowStmt:
2882 retval = _copyVariableShowStmt(from);
2884 case T_VariableResetStmt:
2885 retval = _copyVariableResetStmt(from);
2887 case T_CreateTrigStmt:
2888 retval = _copyCreateTrigStmt(from);
2890 case T_DropTrigStmt:
2891 retval = _copyDropTrigStmt(from);
2893 case T_CreatePLangStmt:
2894 retval = _copyCreatePLangStmt(from);
2896 case T_DropPLangStmt:
2897 retval = _copyDropPLangStmt(from);
2899 case T_CreateUserStmt:
2900 retval = _copyCreateUserStmt(from);
2902 case T_AlterUserStmt:
2903 retval = _copyAlterUserStmt(from);
2905 case T_DropUserStmt:
2906 retval = _copyDropUserStmt(from);
2909 retval = _copyLockStmt(from);
2911 case T_ConstraintsSetStmt:
2912 retval = _copyConstraintsSetStmt(from);
2914 case T_CreateGroupStmt:
2915 retval = _copyCreateGroupStmt(from);
2917 case T_AlterGroupStmt:
2918 retval = _copyAlterGroupStmt(from);
2920 case T_DropGroupStmt:
2921 retval = _copyDropGroupStmt(from);
2924 retval = _copyReindexStmt(from);
2926 case T_CheckPointStmt:
2927 retval = (void *) makeNode(CheckPointStmt);
2931 retval = _copyAExpr(from);
2934 retval = _copyAttr(from);
2937 retval = _copyAConst(from);
2940 retval = _copyParamNo(from);
2943 retval = _copyIdent(from);
2946 retval = _copyFuncCall(from);
2949 retval = _copyAIndices(from);
2952 retval = _copyResTarget(from);
2955 retval = _copyTypeCast(from);
2958 retval = _copySortGroupBy(from);
2961 retval = _copyRangeVar(from);
2963 case T_RangeSubselect:
2964 retval = _copyRangeSubselect(from);
2967 retval = _copyTypeName(from);
2970 retval = _copyIndexElem(from);
2973 retval = _copyColumnDef(from);
2976 retval = _copyConstraint(from);
2979 retval = _copyDefElem(from);
2982 retval = _copyTargetEntry(from);
2984 case T_RangeTblEntry:
2985 retval = _copyRangeTblEntry(from);
2988 retval = _copySortClause(from);
2991 retval = _copyGroupClause(from);
2994 retval = _copyCaseExpr(from);
2997 retval = _copyCaseWhen(from);
2999 case T_FkConstraint:
3000 retval = _copyFkConstraint(from);
3004 elog(ERROR, "copyObject: don't know how to copy node type %d",
3006 retval = from; /* keep compiler quiet */