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.152 2001/08/10 18:57:36 tgl Exp $
20 *-------------------------------------------------------------------------
25 #include "optimizer/clauses.h"
26 #include "optimizer/planmain.h"
31 * a macro to simplify calling of copyObject on the specified field
33 #define Node_Copy(from, newnode, field) \
34 ((newnode)->field = copyObject((from)->field))
39 * This copy function only copies the "cons-cells" of the list, not the
40 * pointed-to objects. (Use copyObject if you want a "deep" copy.)
42 * We also use this function for copying lists of integers, which is
43 * grotty but unlikely to break --- it could fail if sizeof(pointer)
44 * is less than sizeof(int), but I don't know any such machines...
46 * Note that copyObject will surely coredump if applied to a list
56 /* rather ugly coding for speed... */
60 newlist = nl = makeList1(lfirst(list));
62 foreach(l, lnext(list))
64 lnext(nl) = makeList1(lfirst(l));
70 /* ****************************************************************
71 * plannodes.h copy functions
72 * ****************************************************************
78 * This function copies the fields of the Plan node. It is used by
79 * all the copy functions for classes which inherit from Plan.
83 CopyPlanFields(Plan *from, Plan *newnode)
85 newnode->startup_cost = from->startup_cost;
86 newnode->total_cost = from->total_cost;
87 newnode->plan_rows = from->plan_rows;
88 newnode->plan_width = from->plan_width;
89 /* state is NOT copied */
90 Node_Copy(from, newnode, targetlist);
91 Node_Copy(from, newnode, qual);
92 Node_Copy(from, newnode, lefttree);
93 Node_Copy(from, newnode, righttree);
94 newnode->extParam = listCopy(from->extParam);
95 newnode->locParam = listCopy(from->locParam);
96 newnode->chgParam = listCopy(from->chgParam);
97 Node_Copy(from, newnode, initPlan);
98 /* subPlan list must point to subplans in the new subtree, not the old */
99 if (from->subPlan != NIL)
100 newnode->subPlan = nconc(pull_subplans((Node *) newnode->targetlist),
101 pull_subplans((Node *) newnode->qual));
103 newnode->subPlan = NIL;
104 newnode->nParamExec = from->nParamExec;
112 _copyPlan(Plan *from)
114 Plan *newnode = makeNode(Plan);
117 * copy the node superclass fields
119 CopyPlanFields(from, newnode);
130 _copyResult(Result *from)
132 Result *newnode = makeNode(Result);
135 * copy node superclass fields
137 CopyPlanFields((Plan *) from, (Plan *) newnode);
140 * copy remainder of node
142 Node_Copy(from, newnode, resconstantqual);
145 * We must add subplans in resconstantqual to the new plan's subPlan
148 if (from->plan.subPlan != NIL)
149 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
150 pull_subplans(newnode->resconstantqual));
160 _copyAppend(Append *from)
162 Append *newnode = makeNode(Append);
165 * copy node superclass fields
167 CopyPlanFields((Plan *) from, (Plan *) newnode);
170 * copy remainder of node
172 Node_Copy(from, newnode, appendplans);
173 newnode->isTarget = from->isTarget;
182 * This function copies the fields of the Scan node. It is used by
183 * all the copy functions for classes which inherit from Scan.
187 CopyScanFields(Scan *from, Scan *newnode)
189 newnode->scanrelid = from->scanrelid;
198 _copyScan(Scan *from)
200 Scan *newnode = makeNode(Scan);
203 * copy node superclass fields
205 CopyPlanFields((Plan *) from, (Plan *) newnode);
206 CopyScanFields((Scan *) from, (Scan *) newnode);
216 _copySeqScan(SeqScan *from)
218 SeqScan *newnode = makeNode(SeqScan);
221 * copy node superclass fields
223 CopyPlanFields((Plan *) from, (Plan *) newnode);
224 CopyScanFields((Scan *) from, (Scan *) newnode);
234 _copyIndexScan(IndexScan *from)
236 IndexScan *newnode = makeNode(IndexScan);
239 * copy node superclass fields
241 CopyPlanFields((Plan *) from, (Plan *) newnode);
242 CopyScanFields((Scan *) from, (Scan *) newnode);
245 * copy remainder of node
247 newnode->indxid = listCopy(from->indxid);
248 Node_Copy(from, newnode, indxqual);
249 Node_Copy(from, newnode, indxqualorig);
250 newnode->indxorderdir = from->indxorderdir;
253 * We must add subplans in index quals to the new plan's subPlan list
255 if (from->scan.plan.subPlan != NIL)
257 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
258 pull_subplans((Node *) newnode->indxqual));
259 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
260 pull_subplans((Node *) newnode->indxqualorig));
271 _copyTidScan(TidScan *from)
273 TidScan *newnode = makeNode(TidScan);
276 * copy node superclass fields
278 CopyPlanFields((Plan *) from, (Plan *) newnode);
279 CopyScanFields((Scan *) from, (Scan *) newnode);
282 * copy remainder of node
284 newnode->needRescan = from->needRescan;
285 Node_Copy(from, newnode, tideval);
294 static SubqueryScan *
295 _copySubqueryScan(SubqueryScan *from)
297 SubqueryScan *newnode = makeNode(SubqueryScan);
300 * copy node superclass fields
302 CopyPlanFields((Plan *) from, (Plan *) newnode);
303 CopyScanFields((Scan *) from, (Scan *) newnode);
306 * copy remainder of node
308 Node_Copy(from, newnode, subplan);
317 * This function copies the fields of the Join node. It is used by
318 * all the copy functions for classes which inherit from Join.
322 CopyJoinFields(Join *from, Join *newnode)
324 newnode->jointype = from->jointype;
325 Node_Copy(from, newnode, joinqual);
326 /* subPlan list must point to subplans in the new subtree, not the old */
327 if (from->plan.subPlan != NIL)
328 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
329 pull_subplans((Node *) newnode->joinqual));
338 _copyJoin(Join *from)
340 Join *newnode = makeNode(Join);
343 * copy node superclass fields
345 CopyPlanFields((Plan *) from, (Plan *) newnode);
346 CopyJoinFields(from, newnode);
357 _copyNestLoop(NestLoop *from)
359 NestLoop *newnode = makeNode(NestLoop);
362 * copy node superclass fields
364 CopyPlanFields((Plan *) from, (Plan *) newnode);
365 CopyJoinFields((Join *) from, (Join *) newnode);
376 _copyMergeJoin(MergeJoin *from)
378 MergeJoin *newnode = makeNode(MergeJoin);
381 * copy node superclass fields
383 CopyPlanFields((Plan *) from, (Plan *) newnode);
384 CopyJoinFields((Join *) from, (Join *) newnode);
387 * copy remainder of node
389 Node_Copy(from, newnode, mergeclauses);
392 * We must add subplans in mergeclauses to the new plan's subPlan list
394 if (from->join.plan.subPlan != NIL)
395 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
396 pull_subplans((Node *) newnode->mergeclauses));
406 _copyHashJoin(HashJoin *from)
408 HashJoin *newnode = makeNode(HashJoin);
411 * copy node superclass fields
413 CopyPlanFields((Plan *) from, (Plan *) newnode);
414 CopyJoinFields((Join *) from, (Join *) newnode);
417 * copy remainder of node
419 Node_Copy(from, newnode, hashclauses);
420 newnode->hashjoinop = from->hashjoinop;
423 * We must add subplans in hashclauses to the new plan's subPlan list
425 if (from->join.plan.subPlan != NIL)
426 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
427 pull_subplans((Node *) newnode->hashclauses));
438 _copyMaterial(Material *from)
440 Material *newnode = makeNode(Material);
443 * copy node superclass fields
445 CopyPlanFields((Plan *) from, (Plan *) newnode);
456 _copySort(Sort *from)
458 Sort *newnode = makeNode(Sort);
461 * copy node superclass fields
463 CopyPlanFields((Plan *) from, (Plan *) newnode);
465 newnode->keycount = from->keycount;
476 _copyGroup(Group *from)
478 Group *newnode = makeNode(Group);
480 CopyPlanFields((Plan *) from, (Plan *) newnode);
482 newnode->tuplePerGroup = from->tuplePerGroup;
483 newnode->numCols = from->numCols;
484 newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
485 memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
497 Agg *newnode = makeNode(Agg);
499 CopyPlanFields((Plan *) from, (Plan *) newnode);
509 _copyGroupClause(GroupClause *from)
511 GroupClause *newnode = makeNode(GroupClause);
513 newnode->tleSortGroupRef = from->tleSortGroupRef;
514 newnode->sortop = from->sortop;
524 _copyUnique(Unique *from)
526 Unique *newnode = makeNode(Unique);
529 * copy node superclass fields
531 CopyPlanFields((Plan *) from, (Plan *) newnode);
534 * copy remainder of node
536 newnode->numCols = from->numCols;
537 newnode->uniqColIdx = palloc(from->numCols * sizeof(AttrNumber));
538 memcpy(newnode->uniqColIdx, from->uniqColIdx, from->numCols * sizeof(AttrNumber));
548 _copySetOp(SetOp *from)
550 SetOp *newnode = makeNode(SetOp);
553 * copy node superclass fields
555 CopyPlanFields((Plan *) from, (Plan *) newnode);
558 * copy remainder of node
560 newnode->cmd = from->cmd;
561 newnode->numCols = from->numCols;
562 newnode->dupColIdx = palloc(from->numCols * sizeof(AttrNumber));
563 memcpy(newnode->dupColIdx, from->dupColIdx, from->numCols * sizeof(AttrNumber));
564 newnode->flagColIdx = from->flagColIdx;
574 _copyLimit(Limit *from)
576 Limit *newnode = makeNode(Limit);
579 * copy node superclass fields
581 CopyPlanFields((Plan *) from, (Plan *) newnode);
584 * copy remainder of node
586 Node_Copy(from, newnode, limitOffset);
587 Node_Copy(from, newnode, limitCount);
597 _copyHash(Hash *from)
599 Hash *newnode = makeNode(Hash);
602 * copy node superclass fields
604 CopyPlanFields((Plan *) from, (Plan *) newnode);
607 * copy remainder of node
609 Node_Copy(from, newnode, hashkey);
615 _copySubPlan(SubPlan *from)
617 SubPlan *newnode = makeNode(SubPlan);
619 Node_Copy(from, newnode, plan);
620 newnode->plan_id = from->plan_id;
621 Node_Copy(from, newnode, rtable);
622 newnode->setParam = listCopy(from->setParam);
623 newnode->parParam = listCopy(from->parParam);
624 Node_Copy(from, newnode, sublink);
626 /* do not copy execution state */
627 newnode->needShutdown = false;
628 newnode->curTuple = NULL;
633 /* ****************************************************************
634 * primnodes.h copy functions
635 * ****************************************************************
643 _copyResdom(Resdom *from)
645 Resdom *newnode = makeNode(Resdom);
647 newnode->resno = from->resno;
648 newnode->restype = from->restype;
649 newnode->restypmod = from->restypmod;
650 if (from->resname != NULL)
651 newnode->resname = pstrdup(from->resname);
652 newnode->ressortgroupref = from->ressortgroupref;
653 newnode->reskey = from->reskey;
654 newnode->reskeyop = from->reskeyop;
655 newnode->resjunk = from->resjunk;
661 _copyFjoin(Fjoin *from)
663 Fjoin *newnode = makeNode(Fjoin);
666 * copy node superclass fields
669 newnode->fj_initialized = from->fj_initialized;
670 newnode->fj_nNodes = from->fj_nNodes;
672 Node_Copy(from, newnode, fj_innerNode);
674 newnode->fj_results = (DatumPtr)
675 palloc((from->fj_nNodes) * sizeof(Datum));
676 memmove(from->fj_results,
678 (from->fj_nNodes) * sizeof(Datum));
680 newnode->fj_alwaysDone = (BoolPtr)
681 palloc((from->fj_nNodes) * sizeof(bool));
682 memmove(from->fj_alwaysDone,
683 newnode->fj_alwaysDone,
684 (from->fj_nNodes) * sizeof(bool));
695 _copyExpr(Expr *from)
697 Expr *newnode = makeNode(Expr);
700 * copy node superclass fields
702 newnode->typeOid = from->typeOid;
703 newnode->opType = from->opType;
705 Node_Copy(from, newnode, oper);
706 Node_Copy(from, newnode, args);
718 Var *newnode = makeNode(Var);
721 * copy remainder of node
723 newnode->varno = from->varno;
724 newnode->varattno = from->varattno;
725 newnode->vartype = from->vartype;
726 newnode->vartypmod = from->vartypmod;
727 newnode->varlevelsup = from->varlevelsup;
729 newnode->varnoold = from->varnoold;
730 newnode->varoattno = from->varoattno;
736 _copyAttr(Attr *from)
738 Attr *newnode = makeNode(Attr);
741 newnode->relname = pstrdup(from->relname);
742 Node_Copy(from, newnode, attrs);
752 _copyOper(Oper *from)
754 Oper *newnode = makeNode(Oper);
757 * copy remainder of node
759 newnode->opno = from->opno;
760 newnode->opid = from->opid;
761 newnode->opresulttype = from->opresulttype;
762 /* Do not copy the run-time state, if any */
763 newnode->op_fcache = NULL;
773 _copyConst(Const *from)
775 Const *newnode = makeNode(Const);
778 * copy remainder of node
780 newnode->consttype = from->consttype;
781 newnode->constlen = from->constlen;
783 if (from->constbyval || from->constisnull)
787 * passed by value so just copy the datum. Also, don't try to copy
788 * struct when value is null!
791 newnode->constvalue = from->constvalue;
797 * not passed by value. datum contains a pointer.
799 int length = from->constlen;
801 if (length == -1) /* variable-length type? */
802 length = VARSIZE(from->constvalue);
803 newnode->constvalue = PointerGetDatum(palloc(length));
804 memcpy(DatumGetPointer(newnode->constvalue),
805 DatumGetPointer(from->constvalue),
809 newnode->constisnull = from->constisnull;
810 newnode->constbyval = from->constbyval;
811 newnode->constisset = from->constisset;
812 newnode->constiscast = from->constiscast;
822 _copyParam(Param *from)
824 Param *newnode = makeNode(Param);
827 * copy remainder of node
829 newnode->paramkind = from->paramkind;
830 newnode->paramid = from->paramid;
832 if (from->paramname != NULL)
833 newnode->paramname = pstrdup(from->paramname);
834 newnode->paramtype = from->paramtype;
844 _copyFunc(Func *from)
846 Func *newnode = makeNode(Func);
849 * copy remainder of node
851 newnode->funcid = from->funcid;
852 newnode->functype = from->functype;
853 /* Do not copy the run-time state, if any */
854 newnode->func_fcache = NULL;
864 _copyAggref(Aggref *from)
866 Aggref *newnode = makeNode(Aggref);
869 * copy remainder of node
871 newnode->aggname = pstrdup(from->aggname);
872 newnode->basetype = from->basetype;
873 newnode->aggtype = from->aggtype;
874 Node_Copy(from, newnode, target);
875 newnode->aggstar = from->aggstar;
876 newnode->aggdistinct = from->aggdistinct;
877 newnode->aggno = from->aggno; /* probably not needed */
887 _copySubLink(SubLink *from)
889 SubLink *newnode = makeNode(SubLink);
892 * copy remainder of node
894 newnode->subLinkType = from->subLinkType;
895 newnode->useor = from->useor;
896 Node_Copy(from, newnode, lefthand);
897 Node_Copy(from, newnode, oper);
898 Node_Copy(from, newnode, subselect);
908 _copyFieldSelect(FieldSelect *from)
910 FieldSelect *newnode = makeNode(FieldSelect);
913 * copy remainder of node
915 Node_Copy(from, newnode, arg);
916 newnode->fieldnum = from->fieldnum;
917 newnode->resulttype = from->resulttype;
918 newnode->resulttypmod = from->resulttypmod;
928 _copyRelabelType(RelabelType *from)
930 RelabelType *newnode = makeNode(RelabelType);
933 * copy remainder of node
935 Node_Copy(from, newnode, arg);
936 newnode->resulttype = from->resulttype;
937 newnode->resulttypmod = from->resulttypmod;
943 _copyRangeTblRef(RangeTblRef *from)
945 RangeTblRef *newnode = makeNode(RangeTblRef);
947 newnode->rtindex = from->rtindex;
953 _copyFromExpr(FromExpr *from)
955 FromExpr *newnode = makeNode(FromExpr);
957 Node_Copy(from, newnode, fromlist);
958 Node_Copy(from, newnode, quals);
964 _copyJoinExpr(JoinExpr *from)
966 JoinExpr *newnode = makeNode(JoinExpr);
968 newnode->jointype = from->jointype;
969 newnode->isNatural = from->isNatural;
970 Node_Copy(from, newnode, larg);
971 Node_Copy(from, newnode, rarg);
972 Node_Copy(from, newnode, using);
973 Node_Copy(from, newnode, quals);
974 Node_Copy(from, newnode, alias);
975 Node_Copy(from, newnode, colnames);
976 Node_Copy(from, newnode, colvars);
986 _copyCaseExpr(CaseExpr *from)
988 CaseExpr *newnode = makeNode(CaseExpr);
991 * copy remainder of node
993 newnode->casetype = from->casetype;
995 Node_Copy(from, newnode, arg);
996 Node_Copy(from, newnode, args);
997 Node_Copy(from, newnode, defresult);
1007 _copyCaseWhen(CaseWhen *from)
1009 CaseWhen *newnode = makeNode(CaseWhen);
1012 * copy remainder of node
1014 Node_Copy(from, newnode, expr);
1015 Node_Copy(from, newnode, result);
1025 _copyNullTest(NullTest *from)
1027 NullTest *newnode = makeNode(NullTest);
1030 * copy remainder of node
1032 Node_Copy(from, newnode, arg);
1033 newnode->nulltesttype = from->nulltesttype;
1042 static BooleanTest *
1043 _copyBooleanTest(BooleanTest *from)
1045 BooleanTest *newnode = makeNode(BooleanTest);
1048 * copy remainder of node
1050 Node_Copy(from, newnode, arg);
1051 newnode->booltesttype = from->booltesttype;
1057 _copyArrayRef(ArrayRef *from)
1059 ArrayRef *newnode = makeNode(ArrayRef);
1062 * copy remainder of node
1064 newnode->refattrlength = from->refattrlength;
1065 newnode->refelemlength = from->refelemlength;
1066 newnode->refelemtype = from->refelemtype;
1067 newnode->refelembyval = from->refelembyval;
1069 Node_Copy(from, newnode, refupperindexpr);
1070 Node_Copy(from, newnode, reflowerindexpr);
1071 Node_Copy(from, newnode, refexpr);
1072 Node_Copy(from, newnode, refassgnexpr);
1077 /* ****************************************************************
1078 * relation.h copy functions
1079 * ****************************************************************
1087 * when you change this, also make sure to fix up xfunc_copyRelOptInfo in
1088 * planner/path/xfunc.c accordingly!!!
1092 _copyRelOptInfo(RelOptInfo *from)
1094 RelOptInfo *newnode = makeNode(RelOptInfo);
1096 newnode->relids = listCopy(from->relids);
1098 newnode->rows = from->rows;
1099 newnode->width = from->width;
1101 Node_Copy(from, newnode, targetlist);
1102 Node_Copy(from, newnode, pathlist);
1103 /* XXX cheapest-path fields should point to members of pathlist? */
1104 Node_Copy(from, newnode, cheapest_startup_path);
1105 Node_Copy(from, newnode, cheapest_total_path);
1106 newnode->pruneable = from->pruneable;
1108 newnode->issubquery = from->issubquery;
1109 Node_Copy(from, newnode, indexlist);
1110 newnode->pages = from->pages;
1111 newnode->tuples = from->tuples;
1112 Node_Copy(from, newnode, subplan);
1114 Node_Copy(from, newnode, baserestrictinfo);
1115 newnode->baserestrictcost = from->baserestrictcost;
1116 newnode->outerjoinset = listCopy(from->outerjoinset);
1117 Node_Copy(from, newnode, joininfo);
1118 Node_Copy(from, newnode, innerjoin);
1127 static IndexOptInfo *
1128 _copyIndexOptInfo(IndexOptInfo *from)
1130 IndexOptInfo *newnode = makeNode(IndexOptInfo);
1133 newnode->indexoid = from->indexoid;
1134 newnode->pages = from->pages;
1135 newnode->tuples = from->tuples;
1137 newnode->ncolumns = from->ncolumns;
1138 newnode->nkeys = from->nkeys;
1140 if (from->classlist)
1142 /* copy the trailing zero too */
1143 len = (from->ncolumns + 1) * sizeof(Oid);
1144 newnode->classlist = (Oid *) palloc(len);
1145 memcpy(newnode->classlist, from->classlist, len);
1148 if (from->indexkeys)
1150 /* copy the trailing zero too */
1151 len = (from->nkeys + 1) * sizeof(int);
1152 newnode->indexkeys = (int *) palloc(len);
1153 memcpy(newnode->indexkeys, from->indexkeys, len);
1158 /* copy the trailing zero too */
1159 len = (from->ncolumns + 1) * sizeof(Oid);
1160 newnode->ordering = (Oid *) palloc(len);
1161 memcpy(newnode->ordering, from->ordering, len);
1164 newnode->relam = from->relam;
1165 newnode->amcostestimate = from->amcostestimate;
1166 newnode->indproc = from->indproc;
1167 Node_Copy(from, newnode, indpred);
1168 newnode->unique = from->unique;
1169 newnode->lossy = from->lossy;
1177 * This function copies the fields of the Path node. It is used by
1178 * all the copy functions for classes which inherit from Path.
1182 CopyPathFields(Path *from, Path *newnode)
1186 * Modify the next line, since it causes the copying to cycle (i.e.
1187 * the parent points right back here! -- JMH, 7/7/92. Old version:
1188 * Node_Copy(from, newnode, parent);
1190 newnode->parent = from->parent;
1192 newnode->startup_cost = from->startup_cost;
1193 newnode->total_cost = from->total_cost;
1195 newnode->pathtype = from->pathtype;
1197 Node_Copy(from, newnode, pathkeys);
1205 _copyPath(Path *from)
1207 Path *newnode = makeNode(Path);
1209 CopyPathFields(from, newnode);
1219 _copyIndexPath(IndexPath *from)
1221 IndexPath *newnode = makeNode(IndexPath);
1224 * copy the node superclass fields
1226 CopyPathFields((Path *) from, (Path *) newnode);
1229 * copy remainder of node
1231 Node_Copy(from, newnode, indexinfo);
1232 Node_Copy(from, newnode, indexqual);
1233 newnode->indexscandir = from->indexscandir;
1234 newnode->joinrelids = listCopy(from->joinrelids);
1235 newnode->alljoinquals = from->alljoinquals;
1236 newnode->rows = from->rows;
1246 _copyTidPath(TidPath *from)
1248 TidPath *newnode = makeNode(TidPath);
1251 * copy the node superclass fields
1253 CopyPathFields((Path *) from, (Path *) newnode);
1256 * copy remainder of node
1258 Node_Copy(from, newnode, tideval);
1259 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1269 _copyAppendPath(AppendPath *from)
1271 AppendPath *newnode = makeNode(AppendPath);
1274 * copy the node superclass fields
1276 CopyPathFields((Path *) from, (Path *) newnode);
1279 * copy remainder of node
1281 Node_Copy(from, newnode, subpaths);
1287 * CopyJoinPathFields
1289 * This function copies the fields of the JoinPath node. It is used by
1290 * all the copy functions for classes which inherit from JoinPath.
1294 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1296 newnode->jointype = from->jointype;
1297 Node_Copy(from, newnode, outerjoinpath);
1298 Node_Copy(from, newnode, innerjoinpath);
1299 Node_Copy(from, newnode, joinrestrictinfo);
1307 _copyNestPath(NestPath *from)
1309 NestPath *newnode = makeNode(NestPath);
1312 * copy the node superclass fields
1314 CopyPathFields((Path *) from, (Path *) newnode);
1315 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1325 _copyMergePath(MergePath *from)
1327 MergePath *newnode = makeNode(MergePath);
1330 * copy the node superclass fields
1332 CopyPathFields((Path *) from, (Path *) newnode);
1333 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1336 * copy the remainder of the node
1338 Node_Copy(from, newnode, path_mergeclauses);
1339 Node_Copy(from, newnode, outersortkeys);
1340 Node_Copy(from, newnode, innersortkeys);
1350 _copyHashPath(HashPath *from)
1352 HashPath *newnode = makeNode(HashPath);
1355 * copy the node superclass fields
1357 CopyPathFields((Path *) from, (Path *) newnode);
1358 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1361 * copy remainder of node
1363 Node_Copy(from, newnode, path_hashclauses);
1372 static PathKeyItem *
1373 _copyPathKeyItem(PathKeyItem *from)
1375 PathKeyItem *newnode = makeNode(PathKeyItem);
1378 * copy remainder of node
1380 Node_Copy(from, newnode, key);
1381 newnode->sortop = from->sortop;
1390 static RestrictInfo *
1391 _copyRestrictInfo(RestrictInfo *from)
1393 RestrictInfo *newnode = makeNode(RestrictInfo);
1396 * copy remainder of node
1398 Node_Copy(from, newnode, clause);
1399 newnode->ispusheddown = from->ispusheddown;
1400 Node_Copy(from, newnode, subclauseindices);
1401 newnode->eval_cost = from->eval_cost;
1402 newnode->this_selec = from->this_selec;
1403 newnode->mergejoinoperator = from->mergejoinoperator;
1404 newnode->left_sortop = from->left_sortop;
1405 newnode->right_sortop = from->right_sortop;
1408 * Do not copy pathkeys, since they'd not be canonical in a copied
1411 newnode->left_pathkey = NIL;
1412 newnode->right_pathkey = NIL;
1413 newnode->hashjoinoperator = from->hashjoinoperator;
1414 newnode->left_bucketsize = from->left_bucketsize;
1415 newnode->right_bucketsize = from->right_bucketsize;
1425 _copyJoinInfo(JoinInfo *from)
1427 JoinInfo *newnode = makeNode(JoinInfo);
1430 * copy remainder of node
1432 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1433 Node_Copy(from, newnode, jinfo_restrictinfo);
1439 _copyIter(Iter *from)
1441 Iter *newnode = makeNode(Iter);
1443 Node_Copy(from, newnode, iterexpr);
1444 newnode->itertype = from->itertype;
1450 _copyStream(Stream *from)
1452 Stream *newnode = makeNode(Stream);
1454 newnode->pathptr = from->pathptr;
1455 newnode->cinfo = from->cinfo;
1456 newnode->clausetype = from->clausetype;
1458 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1460 Node_Copy(from, newnode, downstream);
1461 if (newnode->downstream)
1462 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1464 newnode->groupup = from->groupup;
1465 newnode->groupcost = from->groupcost;
1466 newnode->groupsel = from->groupsel;
1471 /* ****************************************************************
1472 * parsenodes.h copy functions
1473 * ****************************************************************
1476 static TargetEntry *
1477 _copyTargetEntry(TargetEntry *from)
1479 TargetEntry *newnode = makeNode(TargetEntry);
1481 Node_Copy(from, newnode, resdom);
1482 Node_Copy(from, newnode, fjoin);
1483 Node_Copy(from, newnode, expr);
1487 static RangeTblEntry *
1488 _copyRangeTblEntry(RangeTblEntry *from)
1490 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1493 newnode->relname = pstrdup(from->relname);
1494 newnode->relid = from->relid;
1495 Node_Copy(from, newnode, subquery);
1496 Node_Copy(from, newnode, alias);
1497 Node_Copy(from, newnode, eref);
1498 newnode->inh = from->inh;
1499 newnode->inFromCl = from->inFromCl;
1500 newnode->checkForRead = from->checkForRead;
1501 newnode->checkForWrite = from->checkForWrite;
1502 newnode->checkAsUser = from->checkAsUser;
1507 static FkConstraint *
1508 _copyFkConstraint(FkConstraint *from)
1510 FkConstraint *newnode = makeNode(FkConstraint);
1512 if (from->constr_name)
1513 newnode->constr_name = pstrdup(from->constr_name);
1514 if (from->pktable_name)
1515 newnode->pktable_name = pstrdup(from->pktable_name);
1516 Node_Copy(from, newnode, fk_attrs);
1517 Node_Copy(from, newnode, pk_attrs);
1518 if (from->match_type)
1519 newnode->match_type = pstrdup(from->match_type);
1520 newnode->actions = from->actions;
1521 newnode->deferrable = from->deferrable;
1522 newnode->initdeferred = from->initdeferred;
1528 _copySortClause(SortClause *from)
1530 SortClause *newnode = makeNode(SortClause);
1532 newnode->tleSortGroupRef = from->tleSortGroupRef;
1533 newnode->sortop = from->sortop;
1539 _copyAExpr(A_Expr *from)
1541 A_Expr *newnode = makeNode(A_Expr);
1543 newnode->oper = from->oper;
1545 newnode->opname = pstrdup(from->opname);
1546 Node_Copy(from, newnode, lexpr);
1547 Node_Copy(from, newnode, rexpr);
1553 _copyAConst(A_Const *from)
1555 A_Const *newnode = makeNode(A_Const);
1557 newnode->val = *((Value *) (copyObject(&(from->val))));
1558 Node_Copy(from, newnode, typename);
1564 _copyParamNo(ParamNo *from)
1566 ParamNo *newnode = makeNode(ParamNo);
1568 newnode->number = from->number;
1569 Node_Copy(from, newnode, typename);
1570 Node_Copy(from, newnode, indirection);
1576 _copyIdent(Ident *from)
1578 Ident *newnode = makeNode(Ident);
1581 newnode->name = pstrdup(from->name);
1582 Node_Copy(from, newnode, indirection);
1583 newnode->isRel = from->isRel;
1589 _copyFuncCall(FuncCall *from)
1591 FuncCall *newnode = makeNode(FuncCall);
1594 newnode->funcname = pstrdup(from->funcname);
1595 Node_Copy(from, newnode, args);
1596 newnode->agg_star = from->agg_star;
1597 newnode->agg_distinct = from->agg_distinct;
1603 _copyAIndices(A_Indices *from)
1605 A_Indices *newnode = makeNode(A_Indices);
1607 Node_Copy(from, newnode, lidx);
1608 Node_Copy(from, newnode, uidx);
1614 _copyResTarget(ResTarget *from)
1616 ResTarget *newnode = makeNode(ResTarget);
1619 newnode->name = pstrdup(from->name);
1620 Node_Copy(from, newnode, indirection);
1621 Node_Copy(from, newnode, val);
1627 _copyTypeName(TypeName *from)
1629 TypeName *newnode = makeNode(TypeName);
1632 newnode->name = pstrdup(from->name);
1633 newnode->timezone = from->timezone;
1634 newnode->setof = from->setof;
1635 newnode->typmod = from->typmod;
1636 Node_Copy(from, newnode, arrayBounds);
1641 static SortGroupBy *
1642 _copySortGroupBy(SortGroupBy *from)
1644 SortGroupBy *newnode = makeNode(SortGroupBy);
1647 newnode->useOp = pstrdup(from->useOp);
1648 Node_Copy(from, newnode, node);
1654 _copyRangeVar(RangeVar *from)
1656 RangeVar *newnode = makeNode(RangeVar);
1659 newnode->relname = pstrdup(from->relname);
1660 newnode->inhOpt = from->inhOpt;
1661 Node_Copy(from, newnode, name);
1666 static RangeSubselect *
1667 _copyRangeSubselect(RangeSubselect *from)
1669 RangeSubselect *newnode = makeNode(RangeSubselect);
1671 Node_Copy(from, newnode, subquery);
1672 Node_Copy(from, newnode, name);
1678 _copyTypeCast(TypeCast *from)
1680 TypeCast *newnode = makeNode(TypeCast);
1682 Node_Copy(from, newnode, arg);
1683 Node_Copy(from, newnode, typename);
1689 _copyIndexElem(IndexElem *from)
1691 IndexElem *newnode = makeNode(IndexElem);
1694 newnode->name = pstrdup(from->name);
1695 Node_Copy(from, newnode, args);
1697 newnode->class = pstrdup(from->class);
1703 _copyColumnDef(ColumnDef *from)
1705 ColumnDef *newnode = makeNode(ColumnDef);
1708 newnode->colname = pstrdup(from->colname);
1709 Node_Copy(from, newnode, typename);
1710 newnode->is_not_null = from->is_not_null;
1711 newnode->is_sequence = from->is_sequence;
1712 Node_Copy(from, newnode, raw_default);
1713 if (from->cooked_default)
1714 newnode->cooked_default = pstrdup(from->cooked_default);
1715 Node_Copy(from, newnode, constraints);
1721 _copyConstraint(Constraint *from)
1723 Constraint *newnode = makeNode(Constraint);
1725 newnode->contype = from->contype;
1727 newnode->name = pstrdup(from->name);
1728 Node_Copy(from, newnode, raw_expr);
1729 if (from->cooked_expr)
1730 newnode->cooked_expr = pstrdup(from->cooked_expr);
1731 Node_Copy(from, newnode, keys);
1737 _copyDefElem(DefElem *from)
1739 DefElem *newnode = makeNode(DefElem);
1742 newnode->defname = pstrdup(from->defname);
1743 Node_Copy(from, newnode, arg);
1749 _copyQuery(Query *from)
1751 Query *newnode = makeNode(Query);
1753 newnode->commandType = from->commandType;
1754 Node_Copy(from, newnode, utilityStmt);
1755 newnode->resultRelation = from->resultRelation;
1757 newnode->into = pstrdup(from->into);
1758 newnode->isPortal = from->isPortal;
1759 newnode->isBinary = from->isBinary;
1760 newnode->isTemp = from->isTemp;
1761 newnode->hasAggs = from->hasAggs;
1762 newnode->hasSubLinks = from->hasSubLinks;
1764 Node_Copy(from, newnode, rtable);
1765 Node_Copy(from, newnode, jointree);
1767 newnode->rowMarks = listCopy(from->rowMarks);
1769 Node_Copy(from, newnode, targetList);
1771 Node_Copy(from, newnode, groupClause);
1772 Node_Copy(from, newnode, havingQual);
1773 Node_Copy(from, newnode, distinctClause);
1774 Node_Copy(from, newnode, sortClause);
1776 Node_Copy(from, newnode, limitOffset);
1777 Node_Copy(from, newnode, limitCount);
1779 Node_Copy(from, newnode, setOperations);
1781 newnode->resultRelations = listCopy(from->resultRelations);
1784 * We do not copy the planner internal fields: base_rel_list,
1785 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys.
1786 * Not entirely clear if this is right?
1793 _copyInsertStmt(InsertStmt *from)
1795 InsertStmt *newnode = makeNode(InsertStmt);
1798 newnode->relname = pstrdup(from->relname);
1799 Node_Copy(from, newnode, cols);
1800 Node_Copy(from, newnode, targetList);
1801 Node_Copy(from, newnode, selectStmt);
1807 _copyDeleteStmt(DeleteStmt *from)
1809 DeleteStmt *newnode = makeNode(DeleteStmt);
1812 newnode->relname = pstrdup(from->relname);
1813 Node_Copy(from, newnode, whereClause);
1814 newnode->inhOpt = from->inhOpt;
1820 _copyUpdateStmt(UpdateStmt *from)
1822 UpdateStmt *newnode = makeNode(UpdateStmt);
1825 newnode->relname = pstrdup(from->relname);
1826 Node_Copy(from, newnode, targetList);
1827 Node_Copy(from, newnode, whereClause);
1828 Node_Copy(from, newnode, fromClause);
1829 newnode->inhOpt = from->inhOpt;
1835 _copySelectStmt(SelectStmt *from)
1837 SelectStmt *newnode = makeNode(SelectStmt);
1839 Node_Copy(from, newnode, distinctClause);
1841 newnode->into = pstrdup(from->into);
1842 newnode->istemp = from->istemp;
1843 Node_Copy(from, newnode, targetList);
1844 Node_Copy(from, newnode, fromClause);
1845 Node_Copy(from, newnode, whereClause);
1846 Node_Copy(from, newnode, groupClause);
1847 Node_Copy(from, newnode, havingClause);
1848 Node_Copy(from, newnode, sortClause);
1849 if (from->portalname)
1850 newnode->portalname = pstrdup(from->portalname);
1851 newnode->binary = from->binary;
1852 Node_Copy(from, newnode, limitOffset);
1853 Node_Copy(from, newnode, limitCount);
1854 Node_Copy(from, newnode, forUpdate);
1855 newnode->op = from->op;
1856 newnode->all = from->all;
1857 Node_Copy(from, newnode, larg);
1858 Node_Copy(from, newnode, rarg);
1863 static SetOperationStmt *
1864 _copySetOperationStmt(SetOperationStmt *from)
1866 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1868 newnode->op = from->op;
1869 newnode->all = from->all;
1870 Node_Copy(from, newnode, larg);
1871 Node_Copy(from, newnode, rarg);
1872 newnode->colTypes = listCopy(from->colTypes);
1877 static AlterTableStmt *
1878 _copyAlterTableStmt(AlterTableStmt *from)
1880 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1882 newnode->subtype = from->subtype;
1884 newnode->relname = pstrdup(from->relname);
1885 newnode->inhOpt = from->inhOpt;
1887 newnode->name = pstrdup(from->name);
1888 Node_Copy(from, newnode, def);
1889 newnode->behavior = from->behavior;
1895 _copyGrantStmt(GrantStmt *from)
1897 GrantStmt *newnode = makeNode(GrantStmt);
1899 newnode->is_grant = from->is_grant;
1900 Node_Copy(from, newnode, relnames);
1901 if (from->privileges)
1902 newnode->privileges = pstrdup(from->privileges);
1903 Node_Copy(from, newnode, grantees);
1908 static PrivGrantee *
1909 _copyPrivGrantee(PrivGrantee *from)
1911 PrivGrantee *newnode = makeNode(PrivGrantee);
1914 newnode->username = pstrdup(from->username);
1915 if (from->groupname)
1916 newnode->groupname = pstrdup(from->groupname);
1921 static ClosePortalStmt *
1922 _copyClosePortalStmt(ClosePortalStmt *from)
1924 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1926 if (from->portalname)
1927 newnode->portalname = pstrdup(from->portalname);
1932 static ClusterStmt *
1933 _copyClusterStmt(ClusterStmt *from)
1935 ClusterStmt *newnode = makeNode(ClusterStmt);
1938 newnode->relname = pstrdup(from->relname);
1939 if (from->indexname)
1940 newnode->indexname = pstrdup(from->indexname);
1946 _copyCopyStmt(CopyStmt *from)
1948 CopyStmt *newnode = makeNode(CopyStmt);
1950 newnode->binary = from->binary;
1952 newnode->relname = pstrdup(from->relname);
1953 newnode->oids = from->oids;
1954 newnode->direction = from->direction;
1956 newnode->filename = pstrdup(from->filename);
1957 if (from->delimiter)
1958 newnode->delimiter = pstrdup(from->delimiter);
1959 if (from->null_print)
1960 newnode->null_print = pstrdup(from->null_print);
1966 _copyCreateStmt(CreateStmt *from)
1968 CreateStmt *newnode = makeNode(CreateStmt);
1970 newnode->relname = pstrdup(from->relname);
1971 Node_Copy(from, newnode, tableElts);
1972 Node_Copy(from, newnode, inhRelnames);
1973 Node_Copy(from, newnode, constraints);
1974 newnode->istemp = from->istemp;
1975 newnode->hasoids = from->hasoids;
1980 static VersionStmt *
1981 _copyVersionStmt(VersionStmt *from)
1983 VersionStmt *newnode = makeNode(VersionStmt);
1985 newnode->relname = pstrdup(from->relname);
1986 newnode->direction = from->direction;
1987 newnode->fromRelname = pstrdup(from->fromRelname);
1988 newnode->date = pstrdup(from->date);
1994 _copyDefineStmt(DefineStmt *from)
1996 DefineStmt *newnode = makeNode(DefineStmt);
1998 newnode->defType = from->defType;
1999 newnode->defname = pstrdup(from->defname);
2000 Node_Copy(from, newnode, definition);
2006 _copyDropStmt(DropStmt *from)
2008 DropStmt *newnode = makeNode(DropStmt);
2010 Node_Copy(from, newnode, names);
2011 newnode->removeType = from->removeType;
2016 static TruncateStmt *
2017 _copyTruncateStmt(TruncateStmt *from)
2019 TruncateStmt *newnode = makeNode(TruncateStmt);
2021 newnode->relName = pstrdup(from->relName);
2026 static CommentStmt *
2027 _copyCommentStmt(CommentStmt *from)
2029 CommentStmt *newnode = makeNode(CommentStmt);
2031 newnode->objtype = from->objtype;
2032 newnode->objname = pstrdup(from->objname);
2033 if (from->objproperty)
2034 newnode->objproperty = pstrdup(from->objproperty);
2035 Node_Copy(from, newnode, objlist);
2036 newnode->comment = pstrdup(from->comment);
2042 _copyFetchStmt(FetchStmt *from)
2044 FetchStmt *newnode = makeNode(FetchStmt);
2046 newnode->direction = from->direction;
2047 newnode->howMany = from->howMany;
2048 newnode->portalname = pstrdup(from->portalname);
2049 newnode->ismove = from->ismove;
2055 _copyIndexStmt(IndexStmt *from)
2057 IndexStmt *newnode = makeNode(IndexStmt);
2059 newnode->idxname = pstrdup(from->idxname);
2060 newnode->relname = pstrdup(from->relname);
2061 newnode->accessMethod = pstrdup(from->accessMethod);
2062 Node_Copy(from, newnode, indexParams);
2063 Node_Copy(from, newnode, withClause);
2064 Node_Copy(from, newnode, whereClause);
2065 Node_Copy(from, newnode, rangetable);
2066 newnode->unique = from->unique;
2067 newnode->primary = from->primary;
2072 static ProcedureStmt *
2073 _copyProcedureStmt(ProcedureStmt *from)
2075 ProcedureStmt *newnode = makeNode(ProcedureStmt);
2077 newnode->funcname = pstrdup(from->funcname);
2078 Node_Copy(from, newnode, argTypes);
2079 Node_Copy(from, newnode, returnType);
2080 Node_Copy(from, newnode, withClause);
2081 Node_Copy(from, newnode, as);
2082 newnode->language = pstrdup(from->language);
2087 static RemoveAggrStmt *
2088 _copyRemoveAggrStmt(RemoveAggrStmt *from)
2090 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
2092 newnode->aggname = pstrdup(from->aggname);
2093 Node_Copy(from, newnode, aggtype);
2098 static RemoveFuncStmt *
2099 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2101 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2103 newnode->funcname = pstrdup(from->funcname);
2104 Node_Copy(from, newnode, args);
2109 static RemoveOperStmt *
2110 _copyRemoveOperStmt(RemoveOperStmt *from)
2112 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2114 newnode->opname = pstrdup(from->opname);
2115 Node_Copy(from, newnode, args);
2121 _copyRenameStmt(RenameStmt *from)
2123 RenameStmt *newnode = makeNode(RenameStmt);
2125 newnode->relname = pstrdup(from->relname);
2126 newnode->inhOpt = from->inhOpt;
2128 newnode->column = pstrdup(from->column);
2130 newnode->newname = pstrdup(from->newname);
2136 _copyRuleStmt(RuleStmt *from)
2138 RuleStmt *newnode = makeNode(RuleStmt);
2140 newnode->rulename = pstrdup(from->rulename);
2141 Node_Copy(from, newnode, whereClause);
2142 newnode->event = from->event;
2143 Node_Copy(from, newnode, object);
2144 newnode->instead = from->instead;
2145 Node_Copy(from, newnode, actions);
2151 _copyNotifyStmt(NotifyStmt *from)
2153 NotifyStmt *newnode = makeNode(NotifyStmt);
2156 newnode->relname = pstrdup(from->relname);
2162 _copyListenStmt(ListenStmt *from)
2164 ListenStmt *newnode = makeNode(ListenStmt);
2167 newnode->relname = pstrdup(from->relname);
2172 static UnlistenStmt *
2173 _copyUnlistenStmt(UnlistenStmt *from)
2175 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2178 newnode->relname = pstrdup(from->relname);
2183 static TransactionStmt *
2184 _copyTransactionStmt(TransactionStmt *from)
2186 TransactionStmt *newnode = makeNode(TransactionStmt);
2188 newnode->command = from->command;
2194 _copyViewStmt(ViewStmt *from)
2196 ViewStmt *newnode = makeNode(ViewStmt);
2199 newnode->viewname = pstrdup(from->viewname);
2200 Node_Copy(from, newnode, aliases);
2201 Node_Copy(from, newnode, query);
2207 _copyLoadStmt(LoadStmt *from)
2209 LoadStmt *newnode = makeNode(LoadStmt);
2212 newnode->filename = pstrdup(from->filename);
2217 static CreatedbStmt *
2218 _copyCreatedbStmt(CreatedbStmt *from)
2220 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2223 newnode->dbname = pstrdup(from->dbname);
2225 newnode->dbpath = pstrdup(from->dbpath);
2226 if (from->dbtemplate)
2227 newnode->dbtemplate = pstrdup(from->dbtemplate);
2228 newnode->encoding = from->encoding;
2234 _copyDropdbStmt(DropdbStmt *from)
2236 DropdbStmt *newnode = makeNode(DropdbStmt);
2239 newnode->dbname = pstrdup(from->dbname);
2245 _copyVacuumStmt(VacuumStmt *from)
2247 VacuumStmt *newnode = makeNode(VacuumStmt);
2249 newnode->vacuum = from->vacuum;
2250 newnode->full = from->full;
2251 newnode->analyze = from->analyze;
2252 newnode->verbose = from->verbose;
2254 newnode->vacrel = pstrdup(from->vacrel);
2255 Node_Copy(from, newnode, va_cols);
2260 static ExplainStmt *
2261 _copyExplainStmt(ExplainStmt *from)
2263 ExplainStmt *newnode = makeNode(ExplainStmt);
2265 Node_Copy(from, newnode, query);
2266 newnode->verbose = from->verbose;
2271 static CreateSeqStmt *
2272 _copyCreateSeqStmt(CreateSeqStmt *from)
2274 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2277 newnode->seqname = pstrdup(from->seqname);
2278 Node_Copy(from, newnode, options);
2283 static VariableSetStmt *
2284 _copyVariableSetStmt(VariableSetStmt *from)
2286 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2289 newnode->name = pstrdup(from->name);
2291 newnode->value = pstrdup(from->value);
2296 static VariableShowStmt *
2297 _copyVariableShowStmt(VariableShowStmt *from)
2299 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2302 newnode->name = pstrdup(from->name);
2307 static VariableResetStmt *
2308 _copyVariableResetStmt(VariableResetStmt *from)
2310 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2313 newnode->name = pstrdup(from->name);
2318 static CreateTrigStmt *
2319 _copyCreateTrigStmt(CreateTrigStmt *from)
2321 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2324 newnode->trigname = pstrdup(from->trigname);
2326 newnode->relname = pstrdup(from->relname);
2328 newnode->funcname = pstrdup(from->funcname);
2329 Node_Copy(from, newnode, args);
2330 newnode->before = from->before;
2331 newnode->row = from->row;
2332 memcpy(newnode->actions, from->actions, sizeof(from->actions));
2334 newnode->lang = pstrdup(from->lang);
2336 newnode->text = pstrdup(from->text);
2338 Node_Copy(from, newnode, attr);
2340 newnode->when = pstrdup(from->when);
2341 newnode->isconstraint = from->isconstraint;
2342 newnode->deferrable = from->deferrable;
2343 newnode->initdeferred = from->initdeferred;
2344 if (from->constrrelname)
2345 newnode->constrrelname = pstrdup(from->constrrelname);
2350 static DropTrigStmt *
2351 _copyDropTrigStmt(DropTrigStmt *from)
2353 DropTrigStmt *newnode = makeNode(DropTrigStmt);
2356 newnode->trigname = pstrdup(from->trigname);
2358 newnode->relname = pstrdup(from->relname);
2363 static CreatePLangStmt *
2364 _copyCreatePLangStmt(CreatePLangStmt *from)
2366 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2369 newnode->plname = pstrdup(from->plname);
2370 if (from->plhandler)
2371 newnode->plhandler = pstrdup(from->plhandler);
2372 if (from->plcompiler)
2373 newnode->plcompiler = pstrdup(from->plcompiler);
2374 newnode->pltrusted = from->pltrusted;
2379 static DropPLangStmt *
2380 _copyDropPLangStmt(DropPLangStmt *from)
2382 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2385 newnode->plname = pstrdup(from->plname);
2390 static CreateUserStmt *
2391 _copyCreateUserStmt(CreateUserStmt *from)
2393 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2396 newnode->user = pstrdup(from->user);
2397 Node_Copy(from, newnode, options);
2402 static AlterUserStmt *
2403 _copyAlterUserStmt(AlterUserStmt *from)
2405 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2408 newnode->user = pstrdup(from->user);
2409 Node_Copy(from, newnode, options);
2414 static DropUserStmt *
2415 _copyDropUserStmt(DropUserStmt *from)
2417 DropUserStmt *newnode = makeNode(DropUserStmt);
2419 Node_Copy(from, newnode, users);
2425 _copyLockStmt(LockStmt *from)
2427 LockStmt *newnode = makeNode(LockStmt);
2429 Node_Copy(from, newnode, rellist);
2431 newnode->mode = from->mode;
2436 static ConstraintsSetStmt *
2437 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2439 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2441 Node_Copy(from, newnode, constraints);
2442 newnode->deferred = from->deferred;
2447 static CreateGroupStmt *
2448 _copyCreateGroupStmt(CreateGroupStmt *from)
2450 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2453 newnode->name = pstrdup(from->name);
2454 Node_Copy(from, newnode, options);
2459 static AlterGroupStmt *
2460 _copyAlterGroupStmt(AlterGroupStmt *from)
2462 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2465 newnode->name = pstrdup(from->name);
2466 newnode->action = from->action;
2467 Node_Copy(from, newnode, listUsers);
2472 static DropGroupStmt *
2473 _copyDropGroupStmt(DropGroupStmt *from)
2475 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2478 newnode->name = pstrdup(from->name);
2483 static ReindexStmt *
2484 _copyReindexStmt(ReindexStmt *from)
2486 ReindexStmt *newnode = makeNode(ReindexStmt);
2488 newnode->reindexType = from->reindexType;
2490 newnode->name = pstrdup(from->name);
2491 newnode->force = from->force;
2492 newnode->all = from->all;
2498 /* ****************************************************************
2499 * pg_list.h copy functions
2500 * ****************************************************************
2504 _copyValue(Value *from)
2506 Value *newnode = makeNode(Value);
2508 newnode->type = from->type;
2512 newnode->val.ival = from->val.ival;
2517 newnode->val.str = pstrdup(from->val.str);
2526 * copyObject returns a copy of the node or list. If it is a list, it
2527 * recursively copies its items.
2531 copyObject(void *from)
2538 switch (nodeTag(from))
2545 retval = _copyPlan(from);
2548 retval = _copyResult(from);
2551 retval = _copyAppend(from);
2554 retval = _copyScan(from);
2557 retval = _copySeqScan(from);
2560 retval = _copyIndexScan(from);
2563 retval = _copyTidScan(from);
2565 case T_SubqueryScan:
2566 retval = _copySubqueryScan(from);
2569 retval = _copyJoin(from);
2572 retval = _copyNestLoop(from);
2575 retval = _copyMergeJoin(from);
2578 retval = _copyHashJoin(from);
2581 retval = _copyMaterial(from);
2584 retval = _copySort(from);
2587 retval = _copyGroup(from);
2590 retval = _copyAgg(from);
2593 retval = _copyUnique(from);
2596 retval = _copySetOp(from);
2599 retval = _copyLimit(from);
2602 retval = _copyHash(from);
2605 retval = _copySubPlan(from);
2612 retval = _copyResdom(from);
2615 retval = _copyFjoin(from);
2618 retval = _copyExpr(from);
2621 retval = _copyVar(from);
2624 retval = _copyOper(from);
2627 retval = _copyConst(from);
2630 retval = _copyParam(from);
2633 retval = _copyAggref(from);
2636 retval = _copySubLink(from);
2639 retval = _copyFunc(from);
2642 retval = _copyArrayRef(from);
2645 retval = _copyIter(from);
2648 retval = _copyFieldSelect(from);
2651 retval = _copyRelabelType(from);
2654 retval = _copyRangeTblRef(from);
2657 retval = _copyFromExpr(from);
2660 retval = _copyJoinExpr(from);
2667 retval = _copyRelOptInfo(from);
2670 retval = _copyPath(from);
2673 retval = _copyIndexPath(from);
2676 retval = _copyTidPath(from);
2679 retval = _copyAppendPath(from);
2682 retval = _copyNestPath(from);
2685 retval = _copyMergePath(from);
2688 retval = _copyHashPath(from);
2691 retval = _copyPathKeyItem(from);
2693 case T_RestrictInfo:
2694 retval = _copyRestrictInfo(from);
2697 retval = _copyJoinInfo(from);
2700 retval = _copyStream(from);
2702 case T_IndexOptInfo:
2703 retval = _copyIndexOptInfo(from);
2713 retval = _copyValue(from);
2721 /* rather ugly coding for speed... */
2722 /* Note the input list cannot be NIL if we got here. */
2723 nl = makeList1(copyObject(lfirst(list)));
2726 foreach(l, lnext(list))
2728 lnext(nl) = makeList1(copyObject(lfirst(l)));
2738 retval = _copyQuery(from);
2741 retval = _copyInsertStmt(from);
2744 retval = _copyDeleteStmt(from);
2747 retval = _copyUpdateStmt(from);
2750 retval = _copySelectStmt(from);
2752 case T_SetOperationStmt:
2753 retval = _copySetOperationStmt(from);
2755 case T_AlterTableStmt:
2756 retval = _copyAlterTableStmt(from);
2759 retval = _copyGrantStmt(from);
2761 case T_ClosePortalStmt:
2762 retval = _copyClosePortalStmt(from);
2765 retval = _copyClusterStmt(from);
2768 retval = _copyCopyStmt(from);
2771 retval = _copyCreateStmt(from);
2774 retval = _copyVersionStmt(from);
2777 retval = _copyDefineStmt(from);
2780 retval = _copyDropStmt(from);
2782 case T_TruncateStmt:
2783 retval = _copyTruncateStmt(from);
2786 retval = _copyCommentStmt(from);
2789 retval = _copyFetchStmt(from);
2792 retval = _copyIndexStmt(from);
2794 case T_ProcedureStmt:
2795 retval = _copyProcedureStmt(from);
2797 case T_RemoveAggrStmt:
2798 retval = _copyRemoveAggrStmt(from);
2800 case T_RemoveFuncStmt:
2801 retval = _copyRemoveFuncStmt(from);
2803 case T_RemoveOperStmt:
2804 retval = _copyRemoveOperStmt(from);
2807 retval = _copyRenameStmt(from);
2810 retval = _copyRuleStmt(from);
2813 retval = _copyNotifyStmt(from);
2816 retval = _copyListenStmt(from);
2818 case T_UnlistenStmt:
2819 retval = _copyUnlistenStmt(from);
2821 case T_TransactionStmt:
2822 retval = _copyTransactionStmt(from);
2825 retval = _copyViewStmt(from);
2828 retval = _copyLoadStmt(from);
2830 case T_CreatedbStmt:
2831 retval = _copyCreatedbStmt(from);
2834 retval = _copyDropdbStmt(from);
2837 retval = _copyVacuumStmt(from);
2840 retval = _copyExplainStmt(from);
2842 case T_CreateSeqStmt:
2843 retval = _copyCreateSeqStmt(from);
2845 case T_VariableSetStmt:
2846 retval = _copyVariableSetStmt(from);
2848 case T_VariableShowStmt:
2849 retval = _copyVariableShowStmt(from);
2851 case T_VariableResetStmt:
2852 retval = _copyVariableResetStmt(from);
2854 case T_CreateTrigStmt:
2855 retval = _copyCreateTrigStmt(from);
2857 case T_DropTrigStmt:
2858 retval = _copyDropTrigStmt(from);
2860 case T_CreatePLangStmt:
2861 retval = _copyCreatePLangStmt(from);
2863 case T_DropPLangStmt:
2864 retval = _copyDropPLangStmt(from);
2866 case T_CreateUserStmt:
2867 retval = _copyCreateUserStmt(from);
2869 case T_AlterUserStmt:
2870 retval = _copyAlterUserStmt(from);
2872 case T_DropUserStmt:
2873 retval = _copyDropUserStmt(from);
2876 retval = _copyLockStmt(from);
2878 case T_ConstraintsSetStmt:
2879 retval = _copyConstraintsSetStmt(from);
2881 case T_CreateGroupStmt:
2882 retval = _copyCreateGroupStmt(from);
2884 case T_AlterGroupStmt:
2885 retval = _copyAlterGroupStmt(from);
2887 case T_DropGroupStmt:
2888 retval = _copyDropGroupStmt(from);
2891 retval = _copyReindexStmt(from);
2893 case T_CheckPointStmt:
2894 retval = (void *) makeNode(CheckPointStmt);
2898 retval = _copyAExpr(from);
2901 retval = _copyAttr(from);
2904 retval = _copyAConst(from);
2907 retval = _copyParamNo(from);
2910 retval = _copyIdent(from);
2913 retval = _copyFuncCall(from);
2916 retval = _copyAIndices(from);
2919 retval = _copyResTarget(from);
2922 retval = _copyTypeCast(from);
2925 retval = _copySortGroupBy(from);
2928 retval = _copyRangeVar(from);
2930 case T_RangeSubselect:
2931 retval = _copyRangeSubselect(from);
2934 retval = _copyTypeName(from);
2937 retval = _copyIndexElem(from);
2940 retval = _copyColumnDef(from);
2943 retval = _copyConstraint(from);
2946 retval = _copyDefElem(from);
2949 retval = _copyTargetEntry(from);
2951 case T_RangeTblEntry:
2952 retval = _copyRangeTblEntry(from);
2955 retval = _copySortClause(from);
2958 retval = _copyGroupClause(from);
2961 retval = _copyCaseExpr(from);
2964 retval = _copyCaseWhen(from);
2967 retval = _copyNullTest(from);
2970 retval = _copyBooleanTest(from);
2972 case T_FkConstraint:
2973 retval = _copyFkConstraint(from);
2976 retval = _copyPrivGrantee(from);
2980 elog(ERROR, "copyObject: don't know how to copy node type %d",
2982 retval = from; /* keep compiler quiet */