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.171 2002/03/20 19:43:58 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 newnode->joinrti = from->joinrti;
327 /* subPlan list must point to subplans in the new subtree, not the old */
328 if (from->plan.subPlan != NIL)
329 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
330 pull_subplans((Node *) newnode->joinqual));
339 _copyJoin(Join *from)
341 Join *newnode = makeNode(Join);
344 * copy node superclass fields
346 CopyPlanFields((Plan *) from, (Plan *) newnode);
347 CopyJoinFields(from, newnode);
358 _copyNestLoop(NestLoop *from)
360 NestLoop *newnode = makeNode(NestLoop);
363 * copy node superclass fields
365 CopyPlanFields((Plan *) from, (Plan *) newnode);
366 CopyJoinFields((Join *) from, (Join *) newnode);
377 _copyMergeJoin(MergeJoin *from)
379 MergeJoin *newnode = makeNode(MergeJoin);
382 * copy node superclass fields
384 CopyPlanFields((Plan *) from, (Plan *) newnode);
385 CopyJoinFields((Join *) from, (Join *) newnode);
388 * copy remainder of node
390 Node_Copy(from, newnode, mergeclauses);
393 * We must add subplans in mergeclauses to the new plan's subPlan list
395 if (from->join.plan.subPlan != NIL)
396 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
397 pull_subplans((Node *) newnode->mergeclauses));
407 _copyHashJoin(HashJoin *from)
409 HashJoin *newnode = makeNode(HashJoin);
412 * copy node superclass fields
414 CopyPlanFields((Plan *) from, (Plan *) newnode);
415 CopyJoinFields((Join *) from, (Join *) newnode);
418 * copy remainder of node
420 Node_Copy(from, newnode, hashclauses);
421 newnode->hashjoinop = from->hashjoinop;
424 * We must add subplans in hashclauses to the new plan's subPlan list
426 if (from->join.plan.subPlan != NIL)
427 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
428 pull_subplans((Node *) newnode->hashclauses));
439 _copyMaterial(Material *from)
441 Material *newnode = makeNode(Material);
444 * copy node superclass fields
446 CopyPlanFields((Plan *) from, (Plan *) newnode);
457 _copySort(Sort *from)
459 Sort *newnode = makeNode(Sort);
462 * copy node superclass fields
464 CopyPlanFields((Plan *) from, (Plan *) newnode);
466 newnode->keycount = from->keycount;
477 _copyGroup(Group *from)
479 Group *newnode = makeNode(Group);
481 CopyPlanFields((Plan *) from, (Plan *) newnode);
483 newnode->tuplePerGroup = from->tuplePerGroup;
484 newnode->numCols = from->numCols;
485 newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
486 memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
498 Agg *newnode = makeNode(Agg);
500 CopyPlanFields((Plan *) from, (Plan *) newnode);
510 _copyGroupClause(GroupClause *from)
512 GroupClause *newnode = makeNode(GroupClause);
514 newnode->tleSortGroupRef = from->tleSortGroupRef;
515 newnode->sortop = from->sortop;
525 _copyUnique(Unique *from)
527 Unique *newnode = makeNode(Unique);
530 * copy node superclass fields
532 CopyPlanFields((Plan *) from, (Plan *) newnode);
535 * copy remainder of node
537 newnode->numCols = from->numCols;
538 newnode->uniqColIdx = palloc(from->numCols * sizeof(AttrNumber));
539 memcpy(newnode->uniqColIdx, from->uniqColIdx, from->numCols * sizeof(AttrNumber));
549 _copySetOp(SetOp *from)
551 SetOp *newnode = makeNode(SetOp);
554 * copy node superclass fields
556 CopyPlanFields((Plan *) from, (Plan *) newnode);
559 * copy remainder of node
561 newnode->cmd = from->cmd;
562 newnode->numCols = from->numCols;
563 newnode->dupColIdx = palloc(from->numCols * sizeof(AttrNumber));
564 memcpy(newnode->dupColIdx, from->dupColIdx, from->numCols * sizeof(AttrNumber));
565 newnode->flagColIdx = from->flagColIdx;
575 _copyLimit(Limit *from)
577 Limit *newnode = makeNode(Limit);
580 * copy node superclass fields
582 CopyPlanFields((Plan *) from, (Plan *) newnode);
585 * copy remainder of node
587 Node_Copy(from, newnode, limitOffset);
588 Node_Copy(from, newnode, limitCount);
598 _copyHash(Hash *from)
600 Hash *newnode = makeNode(Hash);
603 * copy node superclass fields
605 CopyPlanFields((Plan *) from, (Plan *) newnode);
608 * copy remainder of node
610 Node_Copy(from, newnode, hashkey);
616 _copySubPlan(SubPlan *from)
618 SubPlan *newnode = makeNode(SubPlan);
620 Node_Copy(from, newnode, plan);
621 newnode->plan_id = from->plan_id;
622 Node_Copy(from, newnode, rtable);
623 newnode->setParam = listCopy(from->setParam);
624 newnode->parParam = listCopy(from->parParam);
625 Node_Copy(from, newnode, sublink);
627 /* do not copy execution state */
628 newnode->needShutdown = false;
629 newnode->curTuple = NULL;
634 /* ****************************************************************
635 * primnodes.h copy functions
636 * ****************************************************************
644 _copyResdom(Resdom *from)
646 Resdom *newnode = makeNode(Resdom);
648 newnode->resno = from->resno;
649 newnode->restype = from->restype;
650 newnode->restypmod = from->restypmod;
651 if (from->resname != NULL)
652 newnode->resname = pstrdup(from->resname);
653 newnode->ressortgroupref = from->ressortgroupref;
654 newnode->reskey = from->reskey;
655 newnode->reskeyop = from->reskeyop;
656 newnode->resjunk = from->resjunk;
662 _copyFjoin(Fjoin *from)
664 Fjoin *newnode = makeNode(Fjoin);
667 * copy node superclass fields
670 newnode->fj_initialized = from->fj_initialized;
671 newnode->fj_nNodes = from->fj_nNodes;
673 Node_Copy(from, newnode, fj_innerNode);
675 newnode->fj_results = (DatumPtr)
676 palloc((from->fj_nNodes) * sizeof(Datum));
677 memmove(from->fj_results,
679 (from->fj_nNodes) * sizeof(Datum));
681 newnode->fj_alwaysDone = (BoolPtr)
682 palloc((from->fj_nNodes) * sizeof(bool));
683 memmove(from->fj_alwaysDone,
684 newnode->fj_alwaysDone,
685 (from->fj_nNodes) * sizeof(bool));
696 _copyExpr(Expr *from)
698 Expr *newnode = makeNode(Expr);
701 * copy node superclass fields
703 newnode->typeOid = from->typeOid;
704 newnode->opType = from->opType;
706 Node_Copy(from, newnode, oper);
707 Node_Copy(from, newnode, args);
719 Var *newnode = makeNode(Var);
722 * copy remainder of node
724 newnode->varno = from->varno;
725 newnode->varattno = from->varattno;
726 newnode->vartype = from->vartype;
727 newnode->vartypmod = from->vartypmod;
728 newnode->varlevelsup = from->varlevelsup;
730 newnode->varnoold = from->varnoold;
731 newnode->varoattno = from->varoattno;
737 _copyAttr(Attr *from)
739 Attr *newnode = makeNode(Attr);
742 newnode->relname = pstrdup(from->relname);
743 Node_Copy(from, newnode, attrs);
753 _copyOper(Oper *from)
755 Oper *newnode = makeNode(Oper);
758 * copy remainder of node
760 newnode->opno = from->opno;
761 newnode->opid = from->opid;
762 newnode->opresulttype = from->opresulttype;
763 /* Do not copy the run-time state, if any */
764 newnode->op_fcache = NULL;
774 _copyConst(Const *from)
776 Const *newnode = makeNode(Const);
779 * copy remainder of node
781 newnode->consttype = from->consttype;
782 newnode->constlen = from->constlen;
784 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;
796 * not passed by value. datum contains a pointer.
798 int length = from->constlen;
800 if (length == -1) /* variable-length type? */
801 length = VARSIZE(from->constvalue);
802 newnode->constvalue = PointerGetDatum(palloc(length));
803 memcpy(DatumGetPointer(newnode->constvalue),
804 DatumGetPointer(from->constvalue),
808 newnode->constisnull = from->constisnull;
809 newnode->constbyval = from->constbyval;
810 newnode->constisset = from->constisset;
811 newnode->constiscast = from->constiscast;
821 _copyParam(Param *from)
823 Param *newnode = makeNode(Param);
826 * copy remainder of node
828 newnode->paramkind = from->paramkind;
829 newnode->paramid = from->paramid;
831 if (from->paramname != NULL)
832 newnode->paramname = pstrdup(from->paramname);
833 newnode->paramtype = from->paramtype;
843 _copyFunc(Func *from)
845 Func *newnode = makeNode(Func);
848 * copy remainder of node
850 newnode->funcid = from->funcid;
851 newnode->functype = from->functype;
852 /* Do not copy the run-time state, if any */
853 newnode->func_fcache = NULL;
863 _copyAggref(Aggref *from)
865 Aggref *newnode = makeNode(Aggref);
868 * copy remainder of node
870 newnode->aggname = pstrdup(from->aggname);
871 newnode->basetype = from->basetype;
872 newnode->aggtype = from->aggtype;
873 Node_Copy(from, newnode, target);
874 newnode->aggstar = from->aggstar;
875 newnode->aggdistinct = from->aggdistinct;
876 newnode->aggno = from->aggno; /* probably not needed */
886 _copySubLink(SubLink *from)
888 SubLink *newnode = makeNode(SubLink);
891 * copy remainder of node
893 newnode->subLinkType = from->subLinkType;
894 newnode->useor = from->useor;
895 Node_Copy(from, newnode, lefthand);
896 Node_Copy(from, newnode, oper);
897 Node_Copy(from, newnode, subselect);
907 _copyFieldSelect(FieldSelect *from)
909 FieldSelect *newnode = makeNode(FieldSelect);
912 * copy remainder of node
914 Node_Copy(from, newnode, arg);
915 newnode->fieldnum = from->fieldnum;
916 newnode->resulttype = from->resulttype;
917 newnode->resulttypmod = from->resulttypmod;
927 _copyRelabelType(RelabelType *from)
929 RelabelType *newnode = makeNode(RelabelType);
932 * copy remainder of node
934 Node_Copy(from, newnode, arg);
935 newnode->resulttype = from->resulttype;
936 newnode->resulttypmod = from->resulttypmod;
942 _copyRangeTblRef(RangeTblRef *from)
944 RangeTblRef *newnode = makeNode(RangeTblRef);
946 newnode->rtindex = from->rtindex;
952 _copyFromExpr(FromExpr *from)
954 FromExpr *newnode = makeNode(FromExpr);
956 Node_Copy(from, newnode, fromlist);
957 Node_Copy(from, newnode, quals);
963 _copyJoinExpr(JoinExpr *from)
965 JoinExpr *newnode = makeNode(JoinExpr);
967 newnode->jointype = from->jointype;
968 newnode->isNatural = from->isNatural;
969 Node_Copy(from, newnode, larg);
970 Node_Copy(from, newnode, rarg);
971 Node_Copy(from, newnode, using);
972 Node_Copy(from, newnode, quals);
973 Node_Copy(from, newnode, alias);
974 newnode->rtindex = from->rtindex;
984 _copyCaseExpr(CaseExpr *from)
986 CaseExpr *newnode = makeNode(CaseExpr);
989 * copy remainder of node
991 newnode->casetype = from->casetype;
993 Node_Copy(from, newnode, arg);
994 Node_Copy(from, newnode, args);
995 Node_Copy(from, newnode, defresult);
1005 _copyCaseWhen(CaseWhen *from)
1007 CaseWhen *newnode = makeNode(CaseWhen);
1010 * copy remainder of node
1012 Node_Copy(from, newnode, expr);
1013 Node_Copy(from, newnode, result);
1023 _copyNullTest(NullTest *from)
1025 NullTest *newnode = makeNode(NullTest);
1028 * copy remainder of node
1030 Node_Copy(from, newnode, arg);
1031 newnode->nulltesttype = from->nulltesttype;
1040 static BooleanTest *
1041 _copyBooleanTest(BooleanTest *from)
1043 BooleanTest *newnode = makeNode(BooleanTest);
1046 * copy remainder of node
1048 Node_Copy(from, newnode, arg);
1049 newnode->booltesttype = from->booltesttype;
1055 _copyArrayRef(ArrayRef *from)
1057 ArrayRef *newnode = makeNode(ArrayRef);
1060 * copy remainder of node
1062 newnode->refattrlength = from->refattrlength;
1063 newnode->refelemlength = from->refelemlength;
1064 newnode->refelemtype = from->refelemtype;
1065 newnode->refelembyval = from->refelembyval;
1067 Node_Copy(from, newnode, refupperindexpr);
1068 Node_Copy(from, newnode, reflowerindexpr);
1069 Node_Copy(from, newnode, refexpr);
1070 Node_Copy(from, newnode, refassgnexpr);
1075 /* ****************************************************************
1076 * relation.h copy functions
1077 * ****************************************************************
1085 _copyRelOptInfo(RelOptInfo *from)
1087 RelOptInfo *newnode = makeNode(RelOptInfo);
1089 newnode->reloptkind = from->reloptkind;
1091 newnode->relids = listCopy(from->relids);
1093 newnode->rows = from->rows;
1094 newnode->width = from->width;
1096 Node_Copy(from, newnode, targetlist);
1097 Node_Copy(from, newnode, pathlist);
1098 /* XXX cheapest-path fields should point to members of pathlist? */
1099 Node_Copy(from, newnode, cheapest_startup_path);
1100 Node_Copy(from, newnode, cheapest_total_path);
1101 newnode->pruneable = from->pruneable;
1103 newnode->issubquery = from->issubquery;
1104 Node_Copy(from, newnode, indexlist);
1105 newnode->pages = from->pages;
1106 newnode->tuples = from->tuples;
1107 Node_Copy(from, newnode, subplan);
1109 newnode->joinrti = from->joinrti;
1110 newnode->joinrteids = listCopy(from->joinrteids);
1112 Node_Copy(from, newnode, baserestrictinfo);
1113 newnode->baserestrictcost = from->baserestrictcost;
1114 newnode->outerjoinset = listCopy(from->outerjoinset);
1115 Node_Copy(from, newnode, joininfo);
1116 Node_Copy(from, newnode, innerjoin);
1125 static IndexOptInfo *
1126 _copyIndexOptInfo(IndexOptInfo *from)
1128 IndexOptInfo *newnode = makeNode(IndexOptInfo);
1131 newnode->indexoid = from->indexoid;
1132 newnode->pages = from->pages;
1133 newnode->tuples = from->tuples;
1135 newnode->ncolumns = from->ncolumns;
1136 newnode->nkeys = from->nkeys;
1138 if (from->classlist)
1140 /* copy the trailing zero too */
1141 len = (from->ncolumns + 1) * sizeof(Oid);
1142 newnode->classlist = (Oid *) palloc(len);
1143 memcpy(newnode->classlist, from->classlist, len);
1146 if (from->indexkeys)
1148 /* copy the trailing zero too */
1149 len = (from->nkeys + 1) * sizeof(int);
1150 newnode->indexkeys = (int *) palloc(len);
1151 memcpy(newnode->indexkeys, from->indexkeys, len);
1156 /* copy the trailing zero too */
1157 len = (from->ncolumns + 1) * sizeof(Oid);
1158 newnode->ordering = (Oid *) palloc(len);
1159 memcpy(newnode->ordering, from->ordering, len);
1162 newnode->relam = from->relam;
1163 newnode->amcostestimate = from->amcostestimate;
1164 newnode->indproc = from->indproc;
1165 Node_Copy(from, newnode, indpred);
1166 newnode->unique = from->unique;
1174 * This function copies the fields of the Path node. It is used by
1175 * all the copy functions for classes which inherit from Path.
1179 CopyPathFields(Path *from, Path *newnode)
1182 * Modify the next line, since it causes the copying to cycle (i.e.
1183 * the parent points right back here! -- JMH, 7/7/92. Old version:
1184 * Node_Copy(from, newnode, parent);
1186 newnode->parent = from->parent;
1188 newnode->startup_cost = from->startup_cost;
1189 newnode->total_cost = from->total_cost;
1191 newnode->pathtype = from->pathtype;
1193 Node_Copy(from, newnode, pathkeys);
1201 _copyPath(Path *from)
1203 Path *newnode = makeNode(Path);
1205 CopyPathFields(from, newnode);
1215 _copyIndexPath(IndexPath *from)
1217 IndexPath *newnode = makeNode(IndexPath);
1220 * copy the node superclass fields
1222 CopyPathFields((Path *) from, (Path *) newnode);
1225 * copy remainder of node
1227 Node_Copy(from, newnode, indexinfo);
1228 Node_Copy(from, newnode, indexqual);
1229 newnode->indexscandir = from->indexscandir;
1230 newnode->joinrelids = listCopy(from->joinrelids);
1231 newnode->alljoinquals = from->alljoinquals;
1232 newnode->rows = from->rows;
1242 _copyTidPath(TidPath *from)
1244 TidPath *newnode = makeNode(TidPath);
1247 * copy the node superclass fields
1249 CopyPathFields((Path *) from, (Path *) newnode);
1252 * copy remainder of node
1254 Node_Copy(from, newnode, tideval);
1255 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1265 _copyAppendPath(AppendPath *from)
1267 AppendPath *newnode = makeNode(AppendPath);
1270 * copy the node superclass fields
1272 CopyPathFields((Path *) from, (Path *) newnode);
1275 * copy remainder of node
1277 Node_Copy(from, newnode, subpaths);
1283 * CopyJoinPathFields
1285 * This function copies the fields of the JoinPath node. It is used by
1286 * all the copy functions for classes which inherit from JoinPath.
1290 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1292 newnode->jointype = from->jointype;
1293 Node_Copy(from, newnode, outerjoinpath);
1294 Node_Copy(from, newnode, innerjoinpath);
1295 Node_Copy(from, newnode, joinrestrictinfo);
1303 _copyNestPath(NestPath *from)
1305 NestPath *newnode = makeNode(NestPath);
1308 * copy the node superclass fields
1310 CopyPathFields((Path *) from, (Path *) newnode);
1311 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1321 _copyMergePath(MergePath *from)
1323 MergePath *newnode = makeNode(MergePath);
1326 * copy the node superclass fields
1328 CopyPathFields((Path *) from, (Path *) newnode);
1329 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1332 * copy the remainder of the node
1334 Node_Copy(from, newnode, path_mergeclauses);
1335 Node_Copy(from, newnode, outersortkeys);
1336 Node_Copy(from, newnode, innersortkeys);
1346 _copyHashPath(HashPath *from)
1348 HashPath *newnode = makeNode(HashPath);
1351 * copy the node superclass fields
1353 CopyPathFields((Path *) from, (Path *) newnode);
1354 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1357 * copy remainder of node
1359 Node_Copy(from, newnode, path_hashclauses);
1368 static PathKeyItem *
1369 _copyPathKeyItem(PathKeyItem *from)
1371 PathKeyItem *newnode = makeNode(PathKeyItem);
1374 * copy remainder of node
1376 Node_Copy(from, newnode, key);
1377 newnode->sortop = from->sortop;
1386 static RestrictInfo *
1387 _copyRestrictInfo(RestrictInfo *from)
1389 RestrictInfo *newnode = makeNode(RestrictInfo);
1392 * copy remainder of node
1394 Node_Copy(from, newnode, clause);
1395 newnode->ispusheddown = from->ispusheddown;
1396 Node_Copy(from, newnode, subclauseindices);
1397 newnode->eval_cost = from->eval_cost;
1398 newnode->this_selec = from->this_selec;
1399 newnode->mergejoinoperator = from->mergejoinoperator;
1400 newnode->left_sortop = from->left_sortop;
1401 newnode->right_sortop = from->right_sortop;
1404 * Do not copy pathkeys, since they'd not be canonical in a copied
1407 newnode->left_pathkey = NIL;
1408 newnode->right_pathkey = NIL;
1409 newnode->left_mergescansel = from->left_mergescansel;
1410 newnode->right_mergescansel = from->right_mergescansel;
1411 newnode->hashjoinoperator = from->hashjoinoperator;
1412 newnode->left_bucketsize = from->left_bucketsize;
1413 newnode->right_bucketsize = from->right_bucketsize;
1423 _copyJoinInfo(JoinInfo *from)
1425 JoinInfo *newnode = makeNode(JoinInfo);
1428 * copy remainder of node
1430 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1431 Node_Copy(from, newnode, jinfo_restrictinfo);
1437 _copyIter(Iter *from)
1439 Iter *newnode = makeNode(Iter);
1441 Node_Copy(from, newnode, iterexpr);
1442 newnode->itertype = from->itertype;
1448 _copyStream(Stream *from)
1450 Stream *newnode = makeNode(Stream);
1452 newnode->pathptr = from->pathptr;
1453 newnode->cinfo = from->cinfo;
1454 newnode->clausetype = from->clausetype;
1456 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1458 Node_Copy(from, newnode, downstream);
1459 if (newnode->downstream)
1460 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1462 newnode->groupup = from->groupup;
1463 newnode->groupcost = from->groupcost;
1464 newnode->groupsel = from->groupsel;
1469 /* ****************************************************************
1470 * parsenodes.h copy functions
1471 * ****************************************************************
1474 static TargetEntry *
1475 _copyTargetEntry(TargetEntry *from)
1477 TargetEntry *newnode = makeNode(TargetEntry);
1479 Node_Copy(from, newnode, resdom);
1480 Node_Copy(from, newnode, fjoin);
1481 Node_Copy(from, newnode, expr);
1485 static RangeTblEntry *
1486 _copyRangeTblEntry(RangeTblEntry *from)
1488 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1490 newnode->rtekind = from->rtekind;
1492 newnode->relname = pstrdup(from->relname);
1493 newnode->relid = from->relid;
1494 Node_Copy(from, newnode, subquery);
1495 newnode->jointype = from->jointype;
1496 newnode->joincoltypes = listCopy(from->joincoltypes);
1497 newnode->joincoltypmods = listCopy(from->joincoltypmods);
1498 newnode->joinleftcols = listCopy(from->joinleftcols);
1499 newnode->joinrightcols = listCopy(from->joinrightcols);
1500 Node_Copy(from, newnode, alias);
1501 Node_Copy(from, newnode, eref);
1502 newnode->inh = from->inh;
1503 newnode->inFromCl = from->inFromCl;
1504 newnode->checkForRead = from->checkForRead;
1505 newnode->checkForWrite = from->checkForWrite;
1506 newnode->checkAsUser = from->checkAsUser;
1511 static FkConstraint *
1512 _copyFkConstraint(FkConstraint *from)
1514 FkConstraint *newnode = makeNode(FkConstraint);
1516 if (from->constr_name)
1517 newnode->constr_name = pstrdup(from->constr_name);
1518 if (from->pktable_name)
1519 newnode->pktable_name = pstrdup(from->pktable_name);
1520 Node_Copy(from, newnode, fk_attrs);
1521 Node_Copy(from, newnode, pk_attrs);
1522 if (from->match_type)
1523 newnode->match_type = pstrdup(from->match_type);
1524 newnode->actions = from->actions;
1525 newnode->deferrable = from->deferrable;
1526 newnode->initdeferred = from->initdeferred;
1532 _copySortClause(SortClause *from)
1534 SortClause *newnode = makeNode(SortClause);
1536 newnode->tleSortGroupRef = from->tleSortGroupRef;
1537 newnode->sortop = from->sortop;
1543 _copyAExpr(A_Expr *from)
1545 A_Expr *newnode = makeNode(A_Expr);
1547 newnode->oper = from->oper;
1549 newnode->opname = pstrdup(from->opname);
1550 Node_Copy(from, newnode, lexpr);
1551 Node_Copy(from, newnode, rexpr);
1557 _copyAConst(A_Const *from)
1559 A_Const *newnode = makeNode(A_Const);
1561 newnode->val = *((Value *) (copyObject(&(from->val))));
1562 Node_Copy(from, newnode, typename);
1568 _copyParamNo(ParamNo *from)
1570 ParamNo *newnode = makeNode(ParamNo);
1572 newnode->number = from->number;
1573 Node_Copy(from, newnode, typename);
1574 Node_Copy(from, newnode, indirection);
1580 _copyIdent(Ident *from)
1582 Ident *newnode = makeNode(Ident);
1585 newnode->name = pstrdup(from->name);
1586 Node_Copy(from, newnode, indirection);
1587 newnode->isRel = from->isRel;
1593 _copyFuncCall(FuncCall *from)
1595 FuncCall *newnode = makeNode(FuncCall);
1598 newnode->funcname = pstrdup(from->funcname);
1599 Node_Copy(from, newnode, args);
1600 newnode->agg_star = from->agg_star;
1601 newnode->agg_distinct = from->agg_distinct;
1607 _copyAIndices(A_Indices *from)
1609 A_Indices *newnode = makeNode(A_Indices);
1611 Node_Copy(from, newnode, lidx);
1612 Node_Copy(from, newnode, uidx);
1618 _copyResTarget(ResTarget *from)
1620 ResTarget *newnode = makeNode(ResTarget);
1623 newnode->name = pstrdup(from->name);
1624 Node_Copy(from, newnode, indirection);
1625 Node_Copy(from, newnode, val);
1631 _copyTypeName(TypeName *from)
1633 TypeName *newnode = makeNode(TypeName);
1636 newnode->name = pstrdup(from->name);
1637 newnode->timezone = from->timezone;
1638 newnode->setof = from->setof;
1639 newnode->typmod = from->typmod;
1640 Node_Copy(from, newnode, arrayBounds);
1645 static SortGroupBy *
1646 _copySortGroupBy(SortGroupBy *from)
1648 SortGroupBy *newnode = makeNode(SortGroupBy);
1651 newnode->useOp = pstrdup(from->useOp);
1652 Node_Copy(from, newnode, node);
1658 _copyRangeVar(RangeVar *from)
1660 RangeVar *newnode = makeNode(RangeVar);
1663 newnode->relname = pstrdup(from->relname);
1664 newnode->inhOpt = from->inhOpt;
1665 Node_Copy(from, newnode, name);
1670 static RangeSubselect *
1671 _copyRangeSubselect(RangeSubselect *from)
1673 RangeSubselect *newnode = makeNode(RangeSubselect);
1675 Node_Copy(from, newnode, subquery);
1676 Node_Copy(from, newnode, name);
1682 _copyTypeCast(TypeCast *from)
1684 TypeCast *newnode = makeNode(TypeCast);
1686 Node_Copy(from, newnode, arg);
1687 Node_Copy(from, newnode, typename);
1693 _copyIndexElem(IndexElem *from)
1695 IndexElem *newnode = makeNode(IndexElem);
1698 newnode->name = pstrdup(from->name);
1699 Node_Copy(from, newnode, args);
1701 newnode->class = pstrdup(from->class);
1707 _copyColumnDef(ColumnDef *from)
1709 ColumnDef *newnode = makeNode(ColumnDef);
1712 newnode->colname = pstrdup(from->colname);
1713 Node_Copy(from, newnode, typename);
1714 newnode->is_not_null = from->is_not_null;
1715 Node_Copy(from, newnode, raw_default);
1716 if (from->cooked_default)
1717 newnode->cooked_default = pstrdup(from->cooked_default);
1718 Node_Copy(from, newnode, constraints);
1724 _copyConstraint(Constraint *from)
1726 Constraint *newnode = makeNode(Constraint);
1728 newnode->contype = from->contype;
1730 newnode->name = pstrdup(from->name);
1731 Node_Copy(from, newnode, raw_expr);
1732 if (from->cooked_expr)
1733 newnode->cooked_expr = pstrdup(from->cooked_expr);
1734 Node_Copy(from, newnode, keys);
1740 _copyDefElem(DefElem *from)
1742 DefElem *newnode = makeNode(DefElem);
1745 newnode->defname = pstrdup(from->defname);
1746 Node_Copy(from, newnode, arg);
1752 _copyQuery(Query *from)
1754 Query *newnode = makeNode(Query);
1756 newnode->commandType = from->commandType;
1757 Node_Copy(from, newnode, utilityStmt);
1758 newnode->resultRelation = from->resultRelation;
1760 newnode->into = pstrdup(from->into);
1761 newnode->isPortal = from->isPortal;
1762 newnode->isBinary = from->isBinary;
1763 newnode->isTemp = from->isTemp;
1764 newnode->hasAggs = from->hasAggs;
1765 newnode->hasSubLinks = from->hasSubLinks;
1766 newnode->originalQuery = from->originalQuery;
1768 Node_Copy(from, newnode, rtable);
1769 Node_Copy(from, newnode, jointree);
1771 newnode->rowMarks = listCopy(from->rowMarks);
1773 Node_Copy(from, newnode, targetList);
1775 Node_Copy(from, newnode, groupClause);
1776 Node_Copy(from, newnode, havingQual);
1777 Node_Copy(from, newnode, distinctClause);
1778 Node_Copy(from, newnode, sortClause);
1780 Node_Copy(from, newnode, limitOffset);
1781 Node_Copy(from, newnode, limitCount);
1783 Node_Copy(from, newnode, setOperations);
1785 newnode->resultRelations = listCopy(from->resultRelations);
1788 * We do not copy the planner internal fields: base_rel_list,
1789 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. Not
1790 * entirely clear if this is right?
1797 _copyInsertStmt(InsertStmt *from)
1799 InsertStmt *newnode = makeNode(InsertStmt);
1802 newnode->relname = pstrdup(from->relname);
1803 Node_Copy(from, newnode, cols);
1804 Node_Copy(from, newnode, targetList);
1805 Node_Copy(from, newnode, selectStmt);
1811 _copyDeleteStmt(DeleteStmt *from)
1813 DeleteStmt *newnode = makeNode(DeleteStmt);
1816 newnode->relname = pstrdup(from->relname);
1817 Node_Copy(from, newnode, whereClause);
1818 newnode->inhOpt = from->inhOpt;
1824 _copyUpdateStmt(UpdateStmt *from)
1826 UpdateStmt *newnode = makeNode(UpdateStmt);
1829 newnode->relname = pstrdup(from->relname);
1830 Node_Copy(from, newnode, targetList);
1831 Node_Copy(from, newnode, whereClause);
1832 Node_Copy(from, newnode, fromClause);
1833 newnode->inhOpt = from->inhOpt;
1839 _copySelectStmt(SelectStmt *from)
1841 SelectStmt *newnode = makeNode(SelectStmt);
1843 Node_Copy(from, newnode, distinctClause);
1845 newnode->into = pstrdup(from->into);
1846 newnode->istemp = from->istemp;
1847 Node_Copy(from, newnode, intoColNames);
1848 Node_Copy(from, newnode, targetList);
1849 Node_Copy(from, newnode, fromClause);
1850 Node_Copy(from, newnode, whereClause);
1851 Node_Copy(from, newnode, groupClause);
1852 Node_Copy(from, newnode, havingClause);
1853 Node_Copy(from, newnode, sortClause);
1854 if (from->portalname)
1855 newnode->portalname = pstrdup(from->portalname);
1856 newnode->binary = from->binary;
1857 Node_Copy(from, newnode, limitOffset);
1858 Node_Copy(from, newnode, limitCount);
1859 Node_Copy(from, newnode, forUpdate);
1860 newnode->op = from->op;
1861 newnode->all = from->all;
1862 Node_Copy(from, newnode, larg);
1863 Node_Copy(from, newnode, rarg);
1868 static SetOperationStmt *
1869 _copySetOperationStmt(SetOperationStmt *from)
1871 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1873 newnode->op = from->op;
1874 newnode->all = from->all;
1875 Node_Copy(from, newnode, larg);
1876 Node_Copy(from, newnode, rarg);
1877 newnode->colTypes = listCopy(from->colTypes);
1882 static AlterTableStmt *
1883 _copyAlterTableStmt(AlterTableStmt *from)
1885 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1887 newnode->subtype = from->subtype;
1889 newnode->relname = pstrdup(from->relname);
1890 newnode->inhOpt = from->inhOpt;
1892 newnode->name = pstrdup(from->name);
1893 Node_Copy(from, newnode, def);
1894 newnode->behavior = from->behavior;
1900 _copyGrantStmt(GrantStmt *from)
1902 GrantStmt *newnode = makeNode(GrantStmt);
1904 newnode->is_grant = from->is_grant;
1905 newnode->objtype = from->objtype;
1906 Node_Copy(from, newnode, objects);
1907 newnode->privileges = listCopy(from->privileges);
1908 Node_Copy(from, newnode, grantees);
1913 static PrivGrantee *
1914 _copyPrivGrantee(PrivGrantee *from)
1916 PrivGrantee *newnode = makeNode(PrivGrantee);
1919 newnode->username = pstrdup(from->username);
1920 if (from->groupname)
1921 newnode->groupname = pstrdup(from->groupname);
1926 static FuncWithArgs *
1927 _copyFuncWithArgs(FuncWithArgs *from)
1929 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1932 newnode->funcname = pstrdup(from->funcname);
1933 Node_Copy(from, newnode, funcargs);
1938 static ClosePortalStmt *
1939 _copyClosePortalStmt(ClosePortalStmt *from)
1941 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1943 if (from->portalname)
1944 newnode->portalname = pstrdup(from->portalname);
1949 static ClusterStmt *
1950 _copyClusterStmt(ClusterStmt *from)
1952 ClusterStmt *newnode = makeNode(ClusterStmt);
1955 newnode->relname = pstrdup(from->relname);
1956 if (from->indexname)
1957 newnode->indexname = pstrdup(from->indexname);
1963 _copyCopyStmt(CopyStmt *from)
1965 CopyStmt *newnode = makeNode(CopyStmt);
1967 newnode->binary = from->binary;
1969 newnode->relname = pstrdup(from->relname);
1970 newnode->oids = from->oids;
1971 newnode->direction = from->direction;
1973 newnode->filename = pstrdup(from->filename);
1974 if (from->delimiter)
1975 newnode->delimiter = pstrdup(from->delimiter);
1976 if (from->null_print)
1977 newnode->null_print = pstrdup(from->null_print);
1983 _copyCreateStmt(CreateStmt *from)
1985 CreateStmt *newnode = makeNode(CreateStmt);
1987 newnode->relname = pstrdup(from->relname);
1988 Node_Copy(from, newnode, tableElts);
1989 Node_Copy(from, newnode, inhRelnames);
1990 Node_Copy(from, newnode, constraints);
1991 newnode->istemp = from->istemp;
1992 newnode->hasoids = from->hasoids;
1997 static VersionStmt *
1998 _copyVersionStmt(VersionStmt *from)
2000 VersionStmt *newnode = makeNode(VersionStmt);
2002 newnode->relname = pstrdup(from->relname);
2003 newnode->direction = from->direction;
2004 newnode->fromRelname = pstrdup(from->fromRelname);
2005 newnode->date = pstrdup(from->date);
2011 _copyDefineStmt(DefineStmt *from)
2013 DefineStmt *newnode = makeNode(DefineStmt);
2015 newnode->defType = from->defType;
2016 newnode->defname = pstrdup(from->defname);
2017 Node_Copy(from, newnode, definition);
2023 _copyDropStmt(DropStmt *from)
2025 DropStmt *newnode = makeNode(DropStmt);
2027 Node_Copy(from, newnode, names);
2028 newnode->removeType = from->removeType;
2029 newnode->behavior = from->behavior;
2034 static TruncateStmt *
2035 _copyTruncateStmt(TruncateStmt *from)
2037 TruncateStmt *newnode = makeNode(TruncateStmt);
2039 newnode->relName = pstrdup(from->relName);
2044 static CommentStmt *
2045 _copyCommentStmt(CommentStmt *from)
2047 CommentStmt *newnode = makeNode(CommentStmt);
2049 newnode->objtype = from->objtype;
2050 newnode->objname = pstrdup(from->objname);
2051 if (from->objproperty)
2052 newnode->objproperty = pstrdup(from->objproperty);
2053 Node_Copy(from, newnode, objlist);
2054 newnode->comment = pstrdup(from->comment);
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, whereClause);
2082 Node_Copy(from, newnode, rangetable);
2083 newnode->unique = from->unique;
2084 newnode->primary = from->primary;
2089 static ProcedureStmt *
2090 _copyProcedureStmt(ProcedureStmt *from)
2092 ProcedureStmt *newnode = makeNode(ProcedureStmt);
2094 newnode->replace = from->replace;
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 CreateDomainStmt *
2236 _copyCreateDomainStmt(CreateDomainStmt *from)
2238 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2240 if (from->domainname)
2241 newnode->domainname = pstrdup(from->domainname);
2242 Node_Copy(from, newnode, typename);
2243 Node_Copy(from, newnode, constraints);
2248 static CreatedbStmt *
2249 _copyCreatedbStmt(CreatedbStmt *from)
2251 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2254 newnode->dbname = pstrdup(from->dbname);
2256 newnode->dbowner = pstrdup(from->dbowner);
2258 newnode->dbpath = pstrdup(from->dbpath);
2259 if (from->dbtemplate)
2260 newnode->dbtemplate = pstrdup(from->dbtemplate);
2261 newnode->encoding = from->encoding;
2266 static AlterDatabaseSetStmt *
2267 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2269 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2272 newnode->dbname = pstrdup(from->dbname);
2274 newnode->variable = pstrdup(from->variable);
2275 Node_Copy(from, newnode, value);
2281 _copyDropdbStmt(DropdbStmt *from)
2283 DropdbStmt *newnode = makeNode(DropdbStmt);
2286 newnode->dbname = pstrdup(from->dbname);
2292 _copyVacuumStmt(VacuumStmt *from)
2294 VacuumStmt *newnode = makeNode(VacuumStmt);
2296 newnode->vacuum = from->vacuum;
2297 newnode->full = from->full;
2298 newnode->analyze = from->analyze;
2299 newnode->freeze = from->freeze;
2300 newnode->verbose = from->verbose;
2302 newnode->vacrel = pstrdup(from->vacrel);
2303 Node_Copy(from, newnode, va_cols);
2308 static ExplainStmt *
2309 _copyExplainStmt(ExplainStmt *from)
2311 ExplainStmt *newnode = makeNode(ExplainStmt);
2313 Node_Copy(from, newnode, query);
2314 newnode->verbose = from->verbose;
2315 newnode->analyze = from->analyze;
2320 static CreateSeqStmt *
2321 _copyCreateSeqStmt(CreateSeqStmt *from)
2323 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2326 newnode->seqname = pstrdup(from->seqname);
2327 Node_Copy(from, newnode, options);
2332 static VariableSetStmt *
2333 _copyVariableSetStmt(VariableSetStmt *from)
2335 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2338 newnode->name = pstrdup(from->name);
2339 Node_Copy(from, newnode, args);
2344 static VariableShowStmt *
2345 _copyVariableShowStmt(VariableShowStmt *from)
2347 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2350 newnode->name = pstrdup(from->name);
2355 static VariableResetStmt *
2356 _copyVariableResetStmt(VariableResetStmt *from)
2358 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2361 newnode->name = pstrdup(from->name);
2366 static CreateTrigStmt *
2367 _copyCreateTrigStmt(CreateTrigStmt *from)
2369 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2372 newnode->trigname = pstrdup(from->trigname);
2374 newnode->relname = pstrdup(from->relname);
2376 newnode->funcname = pstrdup(from->funcname);
2377 Node_Copy(from, newnode, args);
2378 newnode->before = from->before;
2379 newnode->row = from->row;
2380 memcpy(newnode->actions, from->actions, sizeof(from->actions));
2382 newnode->lang = pstrdup(from->lang);
2384 newnode->text = pstrdup(from->text);
2386 Node_Copy(from, newnode, attr);
2388 newnode->when = pstrdup(from->when);
2389 newnode->isconstraint = from->isconstraint;
2390 newnode->deferrable = from->deferrable;
2391 newnode->initdeferred = from->initdeferred;
2392 if (from->constrrelname)
2393 newnode->constrrelname = pstrdup(from->constrrelname);
2398 static DropTrigStmt *
2399 _copyDropTrigStmt(DropTrigStmt *from)
2401 DropTrigStmt *newnode = makeNode(DropTrigStmt);
2404 newnode->trigname = pstrdup(from->trigname);
2406 newnode->relname = pstrdup(from->relname);
2411 static CreatePLangStmt *
2412 _copyCreatePLangStmt(CreatePLangStmt *from)
2414 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2417 newnode->plname = pstrdup(from->plname);
2418 if (from->plhandler)
2419 newnode->plhandler = pstrdup(from->plhandler);
2420 if (from->plcompiler)
2421 newnode->plcompiler = pstrdup(from->plcompiler);
2422 newnode->pltrusted = from->pltrusted;
2427 static DropPLangStmt *
2428 _copyDropPLangStmt(DropPLangStmt *from)
2430 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2433 newnode->plname = pstrdup(from->plname);
2438 static CreateUserStmt *
2439 _copyCreateUserStmt(CreateUserStmt *from)
2441 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2444 newnode->user = pstrdup(from->user);
2445 Node_Copy(from, newnode, options);
2450 static AlterUserStmt *
2451 _copyAlterUserStmt(AlterUserStmt *from)
2453 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2456 newnode->user = pstrdup(from->user);
2457 Node_Copy(from, newnode, options);
2462 static AlterUserSetStmt *
2463 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2465 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2468 newnode->user = pstrdup(from->user);
2470 newnode->user = pstrdup(from->variable);
2471 Node_Copy(from, newnode, value);
2476 static DropUserStmt *
2477 _copyDropUserStmt(DropUserStmt *from)
2479 DropUserStmt *newnode = makeNode(DropUserStmt);
2481 Node_Copy(from, newnode, users);
2487 _copyLockStmt(LockStmt *from)
2489 LockStmt *newnode = makeNode(LockStmt);
2491 Node_Copy(from, newnode, rellist);
2493 newnode->mode = from->mode;
2498 static ConstraintsSetStmt *
2499 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2501 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2503 Node_Copy(from, newnode, constraints);
2504 newnode->deferred = from->deferred;
2509 static CreateGroupStmt *
2510 _copyCreateGroupStmt(CreateGroupStmt *from)
2512 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2515 newnode->name = pstrdup(from->name);
2516 Node_Copy(from, newnode, options);
2521 static AlterGroupStmt *
2522 _copyAlterGroupStmt(AlterGroupStmt *from)
2524 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2527 newnode->name = pstrdup(from->name);
2528 newnode->action = from->action;
2529 Node_Copy(from, newnode, listUsers);
2534 static DropGroupStmt *
2535 _copyDropGroupStmt(DropGroupStmt *from)
2537 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2540 newnode->name = pstrdup(from->name);
2545 static ReindexStmt *
2546 _copyReindexStmt(ReindexStmt *from)
2548 ReindexStmt *newnode = makeNode(ReindexStmt);
2550 newnode->reindexType = from->reindexType;
2552 newnode->name = pstrdup(from->name);
2553 newnode->force = from->force;
2554 newnode->all = from->all;
2560 /* ****************************************************************
2561 * pg_list.h copy functions
2562 * ****************************************************************
2566 _copyValue(Value *from)
2568 Value *newnode = makeNode(Value);
2570 newnode->type = from->type;
2574 newnode->val.ival = from->val.ival;
2579 newnode->val.str = pstrdup(from->val.str);
2588 * copyObject returns a copy of the node or list. If it is a list, it
2589 * recursively copies its items.
2593 copyObject(void *from)
2600 switch (nodeTag(from))
2606 retval = _copyPlan(from);
2609 retval = _copyResult(from);
2612 retval = _copyAppend(from);
2615 retval = _copyScan(from);
2618 retval = _copySeqScan(from);
2621 retval = _copyIndexScan(from);
2624 retval = _copyTidScan(from);
2626 case T_SubqueryScan:
2627 retval = _copySubqueryScan(from);
2630 retval = _copyJoin(from);
2633 retval = _copyNestLoop(from);
2636 retval = _copyMergeJoin(from);
2639 retval = _copyHashJoin(from);
2642 retval = _copyMaterial(from);
2645 retval = _copySort(from);
2648 retval = _copyGroup(from);
2651 retval = _copyAgg(from);
2654 retval = _copyUnique(from);
2657 retval = _copySetOp(from);
2660 retval = _copyLimit(from);
2663 retval = _copyHash(from);
2666 retval = _copySubPlan(from);
2673 retval = _copyResdom(from);
2676 retval = _copyFjoin(from);
2679 retval = _copyExpr(from);
2682 retval = _copyVar(from);
2685 retval = _copyOper(from);
2688 retval = _copyConst(from);
2691 retval = _copyParam(from);
2694 retval = _copyAggref(from);
2697 retval = _copySubLink(from);
2700 retval = _copyFunc(from);
2703 retval = _copyArrayRef(from);
2706 retval = _copyIter(from);
2709 retval = _copyFieldSelect(from);
2712 retval = _copyRelabelType(from);
2715 retval = _copyRangeTblRef(from);
2718 retval = _copyFromExpr(from);
2721 retval = _copyJoinExpr(from);
2728 retval = _copyRelOptInfo(from);
2731 retval = _copyPath(from);
2734 retval = _copyIndexPath(from);
2737 retval = _copyTidPath(from);
2740 retval = _copyAppendPath(from);
2743 retval = _copyNestPath(from);
2746 retval = _copyMergePath(from);
2749 retval = _copyHashPath(from);
2752 retval = _copyPathKeyItem(from);
2754 case T_RestrictInfo:
2755 retval = _copyRestrictInfo(from);
2758 retval = _copyJoinInfo(from);
2761 retval = _copyStream(from);
2763 case T_IndexOptInfo:
2764 retval = _copyIndexOptInfo(from);
2774 retval = _copyValue(from);
2782 /* rather ugly coding for speed... */
2783 /* Note the input list cannot be NIL if we got here. */
2784 nl = makeList1(copyObject(lfirst(list)));
2787 foreach(l, lnext(list))
2789 lnext(nl) = makeList1(copyObject(lfirst(l)));
2799 retval = _copyQuery(from);
2802 retval = _copyInsertStmt(from);
2805 retval = _copyDeleteStmt(from);
2808 retval = _copyUpdateStmt(from);
2811 retval = _copySelectStmt(from);
2813 case T_SetOperationStmt:
2814 retval = _copySetOperationStmt(from);
2816 case T_AlterTableStmt:
2817 retval = _copyAlterTableStmt(from);
2820 retval = _copyGrantStmt(from);
2822 case T_ClosePortalStmt:
2823 retval = _copyClosePortalStmt(from);
2826 retval = _copyClusterStmt(from);
2829 retval = _copyCopyStmt(from);
2832 retval = _copyCreateStmt(from);
2835 retval = _copyVersionStmt(from);
2838 retval = _copyDefineStmt(from);
2841 retval = _copyDropStmt(from);
2843 case T_TruncateStmt:
2844 retval = _copyTruncateStmt(from);
2847 retval = _copyCommentStmt(from);
2850 retval = _copyFetchStmt(from);
2853 retval = _copyIndexStmt(from);
2855 case T_ProcedureStmt:
2856 retval = _copyProcedureStmt(from);
2858 case T_RemoveAggrStmt:
2859 retval = _copyRemoveAggrStmt(from);
2861 case T_RemoveFuncStmt:
2862 retval = _copyRemoveFuncStmt(from);
2864 case T_RemoveOperStmt:
2865 retval = _copyRemoveOperStmt(from);
2868 retval = _copyRenameStmt(from);
2871 retval = _copyRuleStmt(from);
2874 retval = _copyNotifyStmt(from);
2877 retval = _copyListenStmt(from);
2879 case T_UnlistenStmt:
2880 retval = _copyUnlistenStmt(from);
2882 case T_TransactionStmt:
2883 retval = _copyTransactionStmt(from);
2886 retval = _copyViewStmt(from);
2889 retval = _copyLoadStmt(from);
2891 case T_CreatedbStmt:
2892 retval = _copyCreatedbStmt(from);
2894 case T_AlterDatabaseSetStmt:
2895 retval = _copyAlterDatabaseSetStmt(from);
2898 retval = _copyDropdbStmt(from);
2901 retval = _copyVacuumStmt(from);
2904 retval = _copyExplainStmt(from);
2906 case T_CreateSeqStmt:
2907 retval = _copyCreateSeqStmt(from);
2909 case T_VariableSetStmt:
2910 retval = _copyVariableSetStmt(from);
2912 case T_VariableShowStmt:
2913 retval = _copyVariableShowStmt(from);
2915 case T_VariableResetStmt:
2916 retval = _copyVariableResetStmt(from);
2918 case T_CreateTrigStmt:
2919 retval = _copyCreateTrigStmt(from);
2921 case T_DropTrigStmt:
2922 retval = _copyDropTrigStmt(from);
2924 case T_CreatePLangStmt:
2925 retval = _copyCreatePLangStmt(from);
2927 case T_DropPLangStmt:
2928 retval = _copyDropPLangStmt(from);
2930 case T_CreateUserStmt:
2931 retval = _copyCreateUserStmt(from);
2933 case T_AlterUserStmt:
2934 retval = _copyAlterUserStmt(from);
2936 case T_AlterUserSetStmt:
2937 retval = _copyAlterUserSetStmt(from);
2939 case T_DropUserStmt:
2940 retval = _copyDropUserStmt(from);
2943 retval = _copyLockStmt(from);
2945 case T_ConstraintsSetStmt:
2946 retval = _copyConstraintsSetStmt(from);
2948 case T_CreateGroupStmt:
2949 retval = _copyCreateGroupStmt(from);
2951 case T_AlterGroupStmt:
2952 retval = _copyAlterGroupStmt(from);
2954 case T_DropGroupStmt:
2955 retval = _copyDropGroupStmt(from);
2958 retval = _copyReindexStmt(from);
2960 case T_CheckPointStmt:
2961 retval = (void *) makeNode(CheckPointStmt);
2965 retval = _copyAExpr(from);
2968 retval = _copyAttr(from);
2971 retval = _copyAConst(from);
2974 retval = _copyParamNo(from);
2977 retval = _copyIdent(from);
2980 retval = _copyFuncCall(from);
2983 retval = _copyAIndices(from);
2986 retval = _copyResTarget(from);
2989 retval = _copyTypeCast(from);
2992 retval = _copySortGroupBy(from);
2995 retval = _copyRangeVar(from);
2997 case T_RangeSubselect:
2998 retval = _copyRangeSubselect(from);
3001 retval = _copyTypeName(from);
3004 retval = _copyIndexElem(from);
3007 retval = _copyColumnDef(from);
3010 retval = _copyConstraint(from);
3013 retval = _copyDefElem(from);
3016 retval = _copyTargetEntry(from);
3018 case T_RangeTblEntry:
3019 retval = _copyRangeTblEntry(from);
3022 retval = _copySortClause(from);
3025 retval = _copyGroupClause(from);
3028 retval = _copyCaseExpr(from);
3031 retval = _copyCaseWhen(from);
3034 retval = _copyNullTest(from);
3037 retval = _copyBooleanTest(from);
3039 case T_FkConstraint:
3040 retval = _copyFkConstraint(from);
3043 retval = _copyPrivGrantee(from);
3045 case T_FuncWithArgs:
3046 retval = _copyFuncWithArgs(from);
3048 case T_CreateDomainStmt:
3049 retval = _copyCreateDomainStmt(from);
3053 elog(ERROR, "copyObject: don't know how to copy node type %d",
3055 retval = from; /* keep compiler quiet */