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.158 2001/10/18 17:30:14 thomas 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;
1176 * This function copies the fields of the Path node. It is used by
1177 * all the copy functions for classes which inherit from Path.
1181 CopyPathFields(Path *from, Path *newnode)
1185 * Modify the next line, since it causes the copying to cycle (i.e.
1186 * the parent points right back here! -- JMH, 7/7/92. Old version:
1187 * Node_Copy(from, newnode, parent);
1189 newnode->parent = from->parent;
1191 newnode->startup_cost = from->startup_cost;
1192 newnode->total_cost = from->total_cost;
1194 newnode->pathtype = from->pathtype;
1196 Node_Copy(from, newnode, pathkeys);
1204 _copyPath(Path *from)
1206 Path *newnode = makeNode(Path);
1208 CopyPathFields(from, newnode);
1218 _copyIndexPath(IndexPath *from)
1220 IndexPath *newnode = makeNode(IndexPath);
1223 * copy the node superclass fields
1225 CopyPathFields((Path *) from, (Path *) newnode);
1228 * copy remainder of node
1230 Node_Copy(from, newnode, indexinfo);
1231 Node_Copy(from, newnode, indexqual);
1232 newnode->indexscandir = from->indexscandir;
1233 newnode->joinrelids = listCopy(from->joinrelids);
1234 newnode->alljoinquals = from->alljoinquals;
1235 newnode->rows = from->rows;
1245 _copyTidPath(TidPath *from)
1247 TidPath *newnode = makeNode(TidPath);
1250 * copy the node superclass fields
1252 CopyPathFields((Path *) from, (Path *) newnode);
1255 * copy remainder of node
1257 Node_Copy(from, newnode, tideval);
1258 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1268 _copyAppendPath(AppendPath *from)
1270 AppendPath *newnode = makeNode(AppendPath);
1273 * copy the node superclass fields
1275 CopyPathFields((Path *) from, (Path *) newnode);
1278 * copy remainder of node
1280 Node_Copy(from, newnode, subpaths);
1286 * CopyJoinPathFields
1288 * This function copies the fields of the JoinPath node. It is used by
1289 * all the copy functions for classes which inherit from JoinPath.
1293 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1295 newnode->jointype = from->jointype;
1296 Node_Copy(from, newnode, outerjoinpath);
1297 Node_Copy(from, newnode, innerjoinpath);
1298 Node_Copy(from, newnode, joinrestrictinfo);
1306 _copyNestPath(NestPath *from)
1308 NestPath *newnode = makeNode(NestPath);
1311 * copy the node superclass fields
1313 CopyPathFields((Path *) from, (Path *) newnode);
1314 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1324 _copyMergePath(MergePath *from)
1326 MergePath *newnode = makeNode(MergePath);
1329 * copy the node superclass fields
1331 CopyPathFields((Path *) from, (Path *) newnode);
1332 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1335 * copy the remainder of the node
1337 Node_Copy(from, newnode, path_mergeclauses);
1338 Node_Copy(from, newnode, outersortkeys);
1339 Node_Copy(from, newnode, innersortkeys);
1349 _copyHashPath(HashPath *from)
1351 HashPath *newnode = makeNode(HashPath);
1354 * copy the node superclass fields
1356 CopyPathFields((Path *) from, (Path *) newnode);
1357 CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1360 * copy remainder of node
1362 Node_Copy(from, newnode, path_hashclauses);
1371 static PathKeyItem *
1372 _copyPathKeyItem(PathKeyItem *from)
1374 PathKeyItem *newnode = makeNode(PathKeyItem);
1377 * copy remainder of node
1379 Node_Copy(from, newnode, key);
1380 newnode->sortop = from->sortop;
1389 static RestrictInfo *
1390 _copyRestrictInfo(RestrictInfo *from)
1392 RestrictInfo *newnode = makeNode(RestrictInfo);
1395 * copy remainder of node
1397 Node_Copy(from, newnode, clause);
1398 newnode->ispusheddown = from->ispusheddown;
1399 Node_Copy(from, newnode, subclauseindices);
1400 newnode->eval_cost = from->eval_cost;
1401 newnode->this_selec = from->this_selec;
1402 newnode->mergejoinoperator = from->mergejoinoperator;
1403 newnode->left_sortop = from->left_sortop;
1404 newnode->right_sortop = from->right_sortop;
1407 * Do not copy pathkeys, since they'd not be canonical in a copied
1410 newnode->left_pathkey = NIL;
1411 newnode->right_pathkey = NIL;
1412 newnode->hashjoinoperator = from->hashjoinoperator;
1413 newnode->left_bucketsize = from->left_bucketsize;
1414 newnode->right_bucketsize = from->right_bucketsize;
1424 _copyJoinInfo(JoinInfo *from)
1426 JoinInfo *newnode = makeNode(JoinInfo);
1429 * copy remainder of node
1431 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1432 Node_Copy(from, newnode, jinfo_restrictinfo);
1438 _copyIter(Iter *from)
1440 Iter *newnode = makeNode(Iter);
1442 Node_Copy(from, newnode, iterexpr);
1443 newnode->itertype = from->itertype;
1449 _copyStream(Stream *from)
1451 Stream *newnode = makeNode(Stream);
1453 newnode->pathptr = from->pathptr;
1454 newnode->cinfo = from->cinfo;
1455 newnode->clausetype = from->clausetype;
1457 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1459 Node_Copy(from, newnode, downstream);
1460 if (newnode->downstream)
1461 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1463 newnode->groupup = from->groupup;
1464 newnode->groupcost = from->groupcost;
1465 newnode->groupsel = from->groupsel;
1470 /* ****************************************************************
1471 * parsenodes.h copy functions
1472 * ****************************************************************
1475 static TargetEntry *
1476 _copyTargetEntry(TargetEntry *from)
1478 TargetEntry *newnode = makeNode(TargetEntry);
1480 Node_Copy(from, newnode, resdom);
1481 Node_Copy(from, newnode, fjoin);
1482 Node_Copy(from, newnode, expr);
1486 static RangeTblEntry *
1487 _copyRangeTblEntry(RangeTblEntry *from)
1489 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1492 newnode->relname = pstrdup(from->relname);
1493 newnode->relid = from->relid;
1494 Node_Copy(from, newnode, subquery);
1495 Node_Copy(from, newnode, alias);
1496 Node_Copy(from, newnode, eref);
1497 newnode->inh = from->inh;
1498 newnode->inFromCl = from->inFromCl;
1499 newnode->checkForRead = from->checkForRead;
1500 newnode->checkForWrite = from->checkForWrite;
1501 newnode->checkAsUser = from->checkAsUser;
1506 static FkConstraint *
1507 _copyFkConstraint(FkConstraint *from)
1509 FkConstraint *newnode = makeNode(FkConstraint);
1511 if (from->constr_name)
1512 newnode->constr_name = pstrdup(from->constr_name);
1513 if (from->pktable_name)
1514 newnode->pktable_name = pstrdup(from->pktable_name);
1515 Node_Copy(from, newnode, fk_attrs);
1516 Node_Copy(from, newnode, pk_attrs);
1517 if (from->match_type)
1518 newnode->match_type = pstrdup(from->match_type);
1519 newnode->actions = from->actions;
1520 newnode->deferrable = from->deferrable;
1521 newnode->initdeferred = from->initdeferred;
1527 _copySortClause(SortClause *from)
1529 SortClause *newnode = makeNode(SortClause);
1531 newnode->tleSortGroupRef = from->tleSortGroupRef;
1532 newnode->sortop = from->sortop;
1538 _copyAExpr(A_Expr *from)
1540 A_Expr *newnode = makeNode(A_Expr);
1542 newnode->oper = from->oper;
1544 newnode->opname = pstrdup(from->opname);
1545 Node_Copy(from, newnode, lexpr);
1546 Node_Copy(from, newnode, rexpr);
1552 _copyAConst(A_Const *from)
1554 A_Const *newnode = makeNode(A_Const);
1556 newnode->val = *((Value *) (copyObject(&(from->val))));
1557 Node_Copy(from, newnode, typename);
1563 _copyParamNo(ParamNo *from)
1565 ParamNo *newnode = makeNode(ParamNo);
1567 newnode->number = from->number;
1568 Node_Copy(from, newnode, typename);
1569 Node_Copy(from, newnode, indirection);
1575 _copyIdent(Ident *from)
1577 Ident *newnode = makeNode(Ident);
1580 newnode->name = pstrdup(from->name);
1581 Node_Copy(from, newnode, indirection);
1582 newnode->isRel = from->isRel;
1588 _copyFuncCall(FuncCall *from)
1590 FuncCall *newnode = makeNode(FuncCall);
1593 newnode->funcname = pstrdup(from->funcname);
1594 Node_Copy(from, newnode, args);
1595 newnode->agg_star = from->agg_star;
1596 newnode->agg_distinct = from->agg_distinct;
1602 _copyAIndices(A_Indices *from)
1604 A_Indices *newnode = makeNode(A_Indices);
1606 Node_Copy(from, newnode, lidx);
1607 Node_Copy(from, newnode, uidx);
1613 _copyResTarget(ResTarget *from)
1615 ResTarget *newnode = makeNode(ResTarget);
1618 newnode->name = pstrdup(from->name);
1619 Node_Copy(from, newnode, indirection);
1620 Node_Copy(from, newnode, val);
1626 _copyTypeName(TypeName *from)
1628 TypeName *newnode = makeNode(TypeName);
1631 newnode->name = pstrdup(from->name);
1632 newnode->timezone = from->timezone;
1633 newnode->setof = from->setof;
1634 newnode->typmod = from->typmod;
1635 Node_Copy(from, newnode, arrayBounds);
1640 static SortGroupBy *
1641 _copySortGroupBy(SortGroupBy *from)
1643 SortGroupBy *newnode = makeNode(SortGroupBy);
1646 newnode->useOp = pstrdup(from->useOp);
1647 Node_Copy(from, newnode, node);
1653 _copyRangeVar(RangeVar *from)
1655 RangeVar *newnode = makeNode(RangeVar);
1658 newnode->relname = pstrdup(from->relname);
1659 newnode->inhOpt = from->inhOpt;
1660 Node_Copy(from, newnode, name);
1665 static RangeSubselect *
1666 _copyRangeSubselect(RangeSubselect *from)
1668 RangeSubselect *newnode = makeNode(RangeSubselect);
1670 Node_Copy(from, newnode, subquery);
1671 Node_Copy(from, newnode, name);
1677 _copyTypeCast(TypeCast *from)
1679 TypeCast *newnode = makeNode(TypeCast);
1681 Node_Copy(from, newnode, arg);
1682 Node_Copy(from, newnode, typename);
1688 _copyIndexElem(IndexElem *from)
1690 IndexElem *newnode = makeNode(IndexElem);
1693 newnode->name = pstrdup(from->name);
1694 Node_Copy(from, newnode, args);
1696 newnode->class = pstrdup(from->class);
1702 _copyColumnDef(ColumnDef *from)
1704 ColumnDef *newnode = makeNode(ColumnDef);
1707 newnode->colname = pstrdup(from->colname);
1708 Node_Copy(from, newnode, typename);
1709 newnode->is_not_null = from->is_not_null;
1710 Node_Copy(from, newnode, raw_default);
1711 if (from->cooked_default)
1712 newnode->cooked_default = pstrdup(from->cooked_default);
1713 Node_Copy(from, newnode, constraints);
1719 _copyConstraint(Constraint *from)
1721 Constraint *newnode = makeNode(Constraint);
1723 newnode->contype = from->contype;
1725 newnode->name = pstrdup(from->name);
1726 Node_Copy(from, newnode, raw_expr);
1727 if (from->cooked_expr)
1728 newnode->cooked_expr = pstrdup(from->cooked_expr);
1729 Node_Copy(from, newnode, keys);
1735 _copyDefElem(DefElem *from)
1737 DefElem *newnode = makeNode(DefElem);
1740 newnode->defname = pstrdup(from->defname);
1741 Node_Copy(from, newnode, arg);
1747 _copyQuery(Query *from)
1749 Query *newnode = makeNode(Query);
1751 newnode->commandType = from->commandType;
1752 Node_Copy(from, newnode, utilityStmt);
1753 newnode->resultRelation = from->resultRelation;
1755 newnode->into = pstrdup(from->into);
1756 newnode->isPortal = from->isPortal;
1757 newnode->isBinary = from->isBinary;
1758 newnode->isTemp = from->isTemp;
1759 newnode->hasAggs = from->hasAggs;
1760 newnode->hasSubLinks = from->hasSubLinks;
1762 Node_Copy(from, newnode, rtable);
1763 Node_Copy(from, newnode, jointree);
1765 newnode->rowMarks = listCopy(from->rowMarks);
1767 Node_Copy(from, newnode, targetList);
1769 Node_Copy(from, newnode, groupClause);
1770 Node_Copy(from, newnode, havingQual);
1771 Node_Copy(from, newnode, distinctClause);
1772 Node_Copy(from, newnode, sortClause);
1774 Node_Copy(from, newnode, limitOffset);
1775 Node_Copy(from, newnode, limitCount);
1777 Node_Copy(from, newnode, setOperations);
1779 newnode->resultRelations = listCopy(from->resultRelations);
1782 * We do not copy the planner internal fields: base_rel_list,
1783 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys.
1784 * Not entirely clear if this is right?
1791 _copyInsertStmt(InsertStmt *from)
1793 InsertStmt *newnode = makeNode(InsertStmt);
1796 newnode->relname = pstrdup(from->relname);
1797 Node_Copy(from, newnode, cols);
1798 Node_Copy(from, newnode, targetList);
1799 Node_Copy(from, newnode, selectStmt);
1805 _copyDeleteStmt(DeleteStmt *from)
1807 DeleteStmt *newnode = makeNode(DeleteStmt);
1810 newnode->relname = pstrdup(from->relname);
1811 Node_Copy(from, newnode, whereClause);
1812 newnode->inhOpt = from->inhOpt;
1818 _copyUpdateStmt(UpdateStmt *from)
1820 UpdateStmt *newnode = makeNode(UpdateStmt);
1823 newnode->relname = pstrdup(from->relname);
1824 Node_Copy(from, newnode, targetList);
1825 Node_Copy(from, newnode, whereClause);
1826 Node_Copy(from, newnode, fromClause);
1827 newnode->inhOpt = from->inhOpt;
1833 _copySelectStmt(SelectStmt *from)
1835 SelectStmt *newnode = makeNode(SelectStmt);
1837 Node_Copy(from, newnode, distinctClause);
1839 newnode->into = pstrdup(from->into);
1840 newnode->istemp = from->istemp;
1841 Node_Copy(from, newnode, targetList);
1842 Node_Copy(from, newnode, fromClause);
1843 Node_Copy(from, newnode, whereClause);
1844 Node_Copy(from, newnode, groupClause);
1845 Node_Copy(from, newnode, havingClause);
1846 Node_Copy(from, newnode, sortClause);
1847 if (from->portalname)
1848 newnode->portalname = pstrdup(from->portalname);
1849 newnode->binary = from->binary;
1850 Node_Copy(from, newnode, limitOffset);
1851 Node_Copy(from, newnode, limitCount);
1852 Node_Copy(from, newnode, forUpdate);
1853 newnode->op = from->op;
1854 newnode->all = from->all;
1855 Node_Copy(from, newnode, larg);
1856 Node_Copy(from, newnode, rarg);
1861 static SetOperationStmt *
1862 _copySetOperationStmt(SetOperationStmt *from)
1864 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1866 newnode->op = from->op;
1867 newnode->all = from->all;
1868 Node_Copy(from, newnode, larg);
1869 Node_Copy(from, newnode, rarg);
1870 newnode->colTypes = listCopy(from->colTypes);
1875 static AlterTableStmt *
1876 _copyAlterTableStmt(AlterTableStmt *from)
1878 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1880 newnode->subtype = from->subtype;
1882 newnode->relname = pstrdup(from->relname);
1883 newnode->inhOpt = from->inhOpt;
1885 newnode->name = pstrdup(from->name);
1886 Node_Copy(from, newnode, def);
1887 newnode->behavior = from->behavior;
1893 _copyGrantStmt(GrantStmt *from)
1895 GrantStmt *newnode = makeNode(GrantStmt);
1897 newnode->is_grant = from->is_grant;
1898 Node_Copy(from, newnode, relnames);
1899 if (from->privileges)
1900 newnode->privileges = pstrdup(from->privileges);
1901 Node_Copy(from, newnode, grantees);
1906 static PrivGrantee *
1907 _copyPrivGrantee(PrivGrantee *from)
1909 PrivGrantee *newnode = makeNode(PrivGrantee);
1912 newnode->username = pstrdup(from->username);
1913 if (from->groupname)
1914 newnode->groupname = pstrdup(from->groupname);
1919 static ClosePortalStmt *
1920 _copyClosePortalStmt(ClosePortalStmt *from)
1922 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1924 if (from->portalname)
1925 newnode->portalname = pstrdup(from->portalname);
1930 static ClusterStmt *
1931 _copyClusterStmt(ClusterStmt *from)
1933 ClusterStmt *newnode = makeNode(ClusterStmt);
1936 newnode->relname = pstrdup(from->relname);
1937 if (from->indexname)
1938 newnode->indexname = pstrdup(from->indexname);
1944 _copyCopyStmt(CopyStmt *from)
1946 CopyStmt *newnode = makeNode(CopyStmt);
1948 newnode->binary = from->binary;
1950 newnode->relname = pstrdup(from->relname);
1951 newnode->oids = from->oids;
1952 newnode->direction = from->direction;
1954 newnode->filename = pstrdup(from->filename);
1955 if (from->delimiter)
1956 newnode->delimiter = pstrdup(from->delimiter);
1957 if (from->null_print)
1958 newnode->null_print = pstrdup(from->null_print);
1964 _copyCreateStmt(CreateStmt *from)
1966 CreateStmt *newnode = makeNode(CreateStmt);
1968 newnode->relname = pstrdup(from->relname);
1969 Node_Copy(from, newnode, tableElts);
1970 Node_Copy(from, newnode, inhRelnames);
1971 Node_Copy(from, newnode, constraints);
1972 newnode->istemp = from->istemp;
1973 newnode->hasoids = from->hasoids;
1978 static VersionStmt *
1979 _copyVersionStmt(VersionStmt *from)
1981 VersionStmt *newnode = makeNode(VersionStmt);
1983 newnode->relname = pstrdup(from->relname);
1984 newnode->direction = from->direction;
1985 newnode->fromRelname = pstrdup(from->fromRelname);
1986 newnode->date = pstrdup(from->date);
1992 _copyDefineStmt(DefineStmt *from)
1994 DefineStmt *newnode = makeNode(DefineStmt);
1996 newnode->defType = from->defType;
1997 newnode->defname = pstrdup(from->defname);
1998 Node_Copy(from, newnode, definition);
2004 _copyDropStmt(DropStmt *from)
2006 DropStmt *newnode = makeNode(DropStmt);
2008 Node_Copy(from, newnode, names);
2009 newnode->removeType = from->removeType;
2014 static TruncateStmt *
2015 _copyTruncateStmt(TruncateStmt *from)
2017 TruncateStmt *newnode = makeNode(TruncateStmt);
2019 newnode->relName = pstrdup(from->relName);
2024 static CommentStmt *
2025 _copyCommentStmt(CommentStmt *from)
2027 CommentStmt *newnode = makeNode(CommentStmt);
2029 newnode->objtype = from->objtype;
2030 newnode->objname = pstrdup(from->objname);
2031 if (from->objproperty)
2032 newnode->objproperty = pstrdup(from->objproperty);
2033 Node_Copy(from, newnode, objlist);
2034 newnode->comment = pstrdup(from->comment);
2040 _copyFetchStmt(FetchStmt *from)
2042 FetchStmt *newnode = makeNode(FetchStmt);
2044 newnode->direction = from->direction;
2045 newnode->howMany = from->howMany;
2046 newnode->portalname = pstrdup(from->portalname);
2047 newnode->ismove = from->ismove;
2053 _copyIndexStmt(IndexStmt *from)
2055 IndexStmt *newnode = makeNode(IndexStmt);
2057 newnode->idxname = pstrdup(from->idxname);
2058 newnode->relname = pstrdup(from->relname);
2059 newnode->accessMethod = pstrdup(from->accessMethod);
2060 Node_Copy(from, newnode, indexParams);
2061 Node_Copy(from, newnode, whereClause);
2062 Node_Copy(from, newnode, rangetable);
2063 newnode->unique = from->unique;
2064 newnode->primary = from->primary;
2069 static ProcedureStmt *
2070 _copyProcedureStmt(ProcedureStmt *from)
2072 ProcedureStmt *newnode = makeNode(ProcedureStmt);
2074 newnode->replace = from->replace;
2075 newnode->funcname = pstrdup(from->funcname);
2076 Node_Copy(from, newnode, argTypes);
2077 Node_Copy(from, newnode, returnType);
2078 Node_Copy(from, newnode, withClause);
2079 Node_Copy(from, newnode, as);
2080 newnode->language = pstrdup(from->language);
2085 static RemoveAggrStmt *
2086 _copyRemoveAggrStmt(RemoveAggrStmt *from)
2088 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
2090 newnode->aggname = pstrdup(from->aggname);
2091 Node_Copy(from, newnode, aggtype);
2096 static RemoveFuncStmt *
2097 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2099 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2101 newnode->funcname = pstrdup(from->funcname);
2102 Node_Copy(from, newnode, args);
2107 static RemoveOperStmt *
2108 _copyRemoveOperStmt(RemoveOperStmt *from)
2110 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2112 newnode->opname = pstrdup(from->opname);
2113 Node_Copy(from, newnode, args);
2119 _copyRenameStmt(RenameStmt *from)
2121 RenameStmt *newnode = makeNode(RenameStmt);
2123 newnode->relname = pstrdup(from->relname);
2124 newnode->inhOpt = from->inhOpt;
2126 newnode->column = pstrdup(from->column);
2128 newnode->newname = pstrdup(from->newname);
2134 _copyRuleStmt(RuleStmt *from)
2136 RuleStmt *newnode = makeNode(RuleStmt);
2138 newnode->rulename = pstrdup(from->rulename);
2139 Node_Copy(from, newnode, whereClause);
2140 newnode->event = from->event;
2141 Node_Copy(from, newnode, object);
2142 newnode->instead = from->instead;
2143 Node_Copy(from, newnode, actions);
2149 _copyNotifyStmt(NotifyStmt *from)
2151 NotifyStmt *newnode = makeNode(NotifyStmt);
2154 newnode->relname = pstrdup(from->relname);
2160 _copyListenStmt(ListenStmt *from)
2162 ListenStmt *newnode = makeNode(ListenStmt);
2165 newnode->relname = pstrdup(from->relname);
2170 static UnlistenStmt *
2171 _copyUnlistenStmt(UnlistenStmt *from)
2173 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2176 newnode->relname = pstrdup(from->relname);
2181 static TransactionStmt *
2182 _copyTransactionStmt(TransactionStmt *from)
2184 TransactionStmt *newnode = makeNode(TransactionStmt);
2186 newnode->command = from->command;
2192 _copyViewStmt(ViewStmt *from)
2194 ViewStmt *newnode = makeNode(ViewStmt);
2197 newnode->viewname = pstrdup(from->viewname);
2198 Node_Copy(from, newnode, aliases);
2199 Node_Copy(from, newnode, query);
2205 _copyLoadStmt(LoadStmt *from)
2207 LoadStmt *newnode = makeNode(LoadStmt);
2210 newnode->filename = pstrdup(from->filename);
2215 static CreatedbStmt *
2216 _copyCreatedbStmt(CreatedbStmt *from)
2218 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2221 newnode->dbname = pstrdup(from->dbname);
2223 newnode->dbpath = pstrdup(from->dbpath);
2224 if (from->dbtemplate)
2225 newnode->dbtemplate = pstrdup(from->dbtemplate);
2226 newnode->encoding = from->encoding;
2232 _copyDropdbStmt(DropdbStmt *from)
2234 DropdbStmt *newnode = makeNode(DropdbStmt);
2237 newnode->dbname = pstrdup(from->dbname);
2243 _copyVacuumStmt(VacuumStmt *from)
2245 VacuumStmt *newnode = makeNode(VacuumStmt);
2247 newnode->vacuum = from->vacuum;
2248 newnode->full = from->full;
2249 newnode->analyze = from->analyze;
2250 newnode->freeze = from->freeze;
2251 newnode->verbose = from->verbose;
2253 newnode->vacrel = pstrdup(from->vacrel);
2254 Node_Copy(from, newnode, va_cols);
2259 static ExplainStmt *
2260 _copyExplainStmt(ExplainStmt *from)
2262 ExplainStmt *newnode = makeNode(ExplainStmt);
2264 Node_Copy(from, newnode, query);
2265 newnode->verbose = from->verbose;
2266 newnode->analyze = from->analyze;
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);
2290 Node_Copy(from, newnode, args);
2295 static VariableShowStmt *
2296 _copyVariableShowStmt(VariableShowStmt *from)
2298 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2301 newnode->name = pstrdup(from->name);
2306 static VariableResetStmt *
2307 _copyVariableResetStmt(VariableResetStmt *from)
2309 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2312 newnode->name = pstrdup(from->name);
2317 static CreateTrigStmt *
2318 _copyCreateTrigStmt(CreateTrigStmt *from)
2320 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2323 newnode->trigname = pstrdup(from->trigname);
2325 newnode->relname = pstrdup(from->relname);
2327 newnode->funcname = pstrdup(from->funcname);
2328 Node_Copy(from, newnode, args);
2329 newnode->before = from->before;
2330 newnode->row = from->row;
2331 memcpy(newnode->actions, from->actions, sizeof(from->actions));
2333 newnode->lang = pstrdup(from->lang);
2335 newnode->text = pstrdup(from->text);
2337 Node_Copy(from, newnode, attr);
2339 newnode->when = pstrdup(from->when);
2340 newnode->isconstraint = from->isconstraint;
2341 newnode->deferrable = from->deferrable;
2342 newnode->initdeferred = from->initdeferred;
2343 if (from->constrrelname)
2344 newnode->constrrelname = pstrdup(from->constrrelname);
2349 static DropTrigStmt *
2350 _copyDropTrigStmt(DropTrigStmt *from)
2352 DropTrigStmt *newnode = makeNode(DropTrigStmt);
2355 newnode->trigname = pstrdup(from->trigname);
2357 newnode->relname = pstrdup(from->relname);
2362 static CreatePLangStmt *
2363 _copyCreatePLangStmt(CreatePLangStmt *from)
2365 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2368 newnode->plname = pstrdup(from->plname);
2369 if (from->plhandler)
2370 newnode->plhandler = pstrdup(from->plhandler);
2371 if (from->plcompiler)
2372 newnode->plcompiler = pstrdup(from->plcompiler);
2373 newnode->pltrusted = from->pltrusted;
2378 static DropPLangStmt *
2379 _copyDropPLangStmt(DropPLangStmt *from)
2381 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2384 newnode->plname = pstrdup(from->plname);
2389 static CreateUserStmt *
2390 _copyCreateUserStmt(CreateUserStmt *from)
2392 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2395 newnode->user = pstrdup(from->user);
2396 Node_Copy(from, newnode, options);
2401 static AlterUserStmt *
2402 _copyAlterUserStmt(AlterUserStmt *from)
2404 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2407 newnode->user = pstrdup(from->user);
2408 Node_Copy(from, newnode, options);
2413 static DropUserStmt *
2414 _copyDropUserStmt(DropUserStmt *from)
2416 DropUserStmt *newnode = makeNode(DropUserStmt);
2418 Node_Copy(from, newnode, users);
2424 _copyLockStmt(LockStmt *from)
2426 LockStmt *newnode = makeNode(LockStmt);
2428 Node_Copy(from, newnode, rellist);
2430 newnode->mode = from->mode;
2435 static ConstraintsSetStmt *
2436 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2438 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2440 Node_Copy(from, newnode, constraints);
2441 newnode->deferred = from->deferred;
2446 static CreateGroupStmt *
2447 _copyCreateGroupStmt(CreateGroupStmt *from)
2449 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2452 newnode->name = pstrdup(from->name);
2453 Node_Copy(from, newnode, options);
2458 static AlterGroupStmt *
2459 _copyAlterGroupStmt(AlterGroupStmt *from)
2461 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2464 newnode->name = pstrdup(from->name);
2465 newnode->action = from->action;
2466 Node_Copy(from, newnode, listUsers);
2471 static DropGroupStmt *
2472 _copyDropGroupStmt(DropGroupStmt *from)
2474 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2477 newnode->name = pstrdup(from->name);
2482 static ReindexStmt *
2483 _copyReindexStmt(ReindexStmt *from)
2485 ReindexStmt *newnode = makeNode(ReindexStmt);
2487 newnode->reindexType = from->reindexType;
2489 newnode->name = pstrdup(from->name);
2490 newnode->force = from->force;
2491 newnode->all = from->all;
2497 /* ****************************************************************
2498 * pg_list.h copy functions
2499 * ****************************************************************
2503 _copyValue(Value *from)
2505 Value *newnode = makeNode(Value);
2507 newnode->type = from->type;
2511 newnode->val.ival = from->val.ival;
2516 newnode->val.str = pstrdup(from->val.str);
2525 * copyObject returns a copy of the node or list. If it is a list, it
2526 * recursively copies its items.
2530 copyObject(void *from)
2537 switch (nodeTag(from))
2544 retval = _copyPlan(from);
2547 retval = _copyResult(from);
2550 retval = _copyAppend(from);
2553 retval = _copyScan(from);
2556 retval = _copySeqScan(from);
2559 retval = _copyIndexScan(from);
2562 retval = _copyTidScan(from);
2564 case T_SubqueryScan:
2565 retval = _copySubqueryScan(from);
2568 retval = _copyJoin(from);
2571 retval = _copyNestLoop(from);
2574 retval = _copyMergeJoin(from);
2577 retval = _copyHashJoin(from);
2580 retval = _copyMaterial(from);
2583 retval = _copySort(from);
2586 retval = _copyGroup(from);
2589 retval = _copyAgg(from);
2592 retval = _copyUnique(from);
2595 retval = _copySetOp(from);
2598 retval = _copyLimit(from);
2601 retval = _copyHash(from);
2604 retval = _copySubPlan(from);
2611 retval = _copyResdom(from);
2614 retval = _copyFjoin(from);
2617 retval = _copyExpr(from);
2620 retval = _copyVar(from);
2623 retval = _copyOper(from);
2626 retval = _copyConst(from);
2629 retval = _copyParam(from);
2632 retval = _copyAggref(from);
2635 retval = _copySubLink(from);
2638 retval = _copyFunc(from);
2641 retval = _copyArrayRef(from);
2644 retval = _copyIter(from);
2647 retval = _copyFieldSelect(from);
2650 retval = _copyRelabelType(from);
2653 retval = _copyRangeTblRef(from);
2656 retval = _copyFromExpr(from);
2659 retval = _copyJoinExpr(from);
2666 retval = _copyRelOptInfo(from);
2669 retval = _copyPath(from);
2672 retval = _copyIndexPath(from);
2675 retval = _copyTidPath(from);
2678 retval = _copyAppendPath(from);
2681 retval = _copyNestPath(from);
2684 retval = _copyMergePath(from);
2687 retval = _copyHashPath(from);
2690 retval = _copyPathKeyItem(from);
2692 case T_RestrictInfo:
2693 retval = _copyRestrictInfo(from);
2696 retval = _copyJoinInfo(from);
2699 retval = _copyStream(from);
2701 case T_IndexOptInfo:
2702 retval = _copyIndexOptInfo(from);
2712 retval = _copyValue(from);
2720 /* rather ugly coding for speed... */
2721 /* Note the input list cannot be NIL if we got here. */
2722 nl = makeList1(copyObject(lfirst(list)));
2725 foreach(l, lnext(list))
2727 lnext(nl) = makeList1(copyObject(lfirst(l)));
2737 retval = _copyQuery(from);
2740 retval = _copyInsertStmt(from);
2743 retval = _copyDeleteStmt(from);
2746 retval = _copyUpdateStmt(from);
2749 retval = _copySelectStmt(from);
2751 case T_SetOperationStmt:
2752 retval = _copySetOperationStmt(from);
2754 case T_AlterTableStmt:
2755 retval = _copyAlterTableStmt(from);
2758 retval = _copyGrantStmt(from);
2760 case T_ClosePortalStmt:
2761 retval = _copyClosePortalStmt(from);
2764 retval = _copyClusterStmt(from);
2767 retval = _copyCopyStmt(from);
2770 retval = _copyCreateStmt(from);
2773 retval = _copyVersionStmt(from);
2776 retval = _copyDefineStmt(from);
2779 retval = _copyDropStmt(from);
2781 case T_TruncateStmt:
2782 retval = _copyTruncateStmt(from);
2785 retval = _copyCommentStmt(from);
2788 retval = _copyFetchStmt(from);
2791 retval = _copyIndexStmt(from);
2793 case T_ProcedureStmt:
2794 retval = _copyProcedureStmt(from);
2796 case T_RemoveAggrStmt:
2797 retval = _copyRemoveAggrStmt(from);
2799 case T_RemoveFuncStmt:
2800 retval = _copyRemoveFuncStmt(from);
2802 case T_RemoveOperStmt:
2803 retval = _copyRemoveOperStmt(from);
2806 retval = _copyRenameStmt(from);
2809 retval = _copyRuleStmt(from);
2812 retval = _copyNotifyStmt(from);
2815 retval = _copyListenStmt(from);
2817 case T_UnlistenStmt:
2818 retval = _copyUnlistenStmt(from);
2820 case T_TransactionStmt:
2821 retval = _copyTransactionStmt(from);
2824 retval = _copyViewStmt(from);
2827 retval = _copyLoadStmt(from);
2829 case T_CreatedbStmt:
2830 retval = _copyCreatedbStmt(from);
2833 retval = _copyDropdbStmt(from);
2836 retval = _copyVacuumStmt(from);
2839 retval = _copyExplainStmt(from);
2841 case T_CreateSeqStmt:
2842 retval = _copyCreateSeqStmt(from);
2844 case T_VariableSetStmt:
2845 retval = _copyVariableSetStmt(from);
2847 case T_VariableShowStmt:
2848 retval = _copyVariableShowStmt(from);
2850 case T_VariableResetStmt:
2851 retval = _copyVariableResetStmt(from);
2853 case T_CreateTrigStmt:
2854 retval = _copyCreateTrigStmt(from);
2856 case T_DropTrigStmt:
2857 retval = _copyDropTrigStmt(from);
2859 case T_CreatePLangStmt:
2860 retval = _copyCreatePLangStmt(from);
2862 case T_DropPLangStmt:
2863 retval = _copyDropPLangStmt(from);
2865 case T_CreateUserStmt:
2866 retval = _copyCreateUserStmt(from);
2868 case T_AlterUserStmt:
2869 retval = _copyAlterUserStmt(from);
2871 case T_DropUserStmt:
2872 retval = _copyDropUserStmt(from);
2875 retval = _copyLockStmt(from);
2877 case T_ConstraintsSetStmt:
2878 retval = _copyConstraintsSetStmt(from);
2880 case T_CreateGroupStmt:
2881 retval = _copyCreateGroupStmt(from);
2883 case T_AlterGroupStmt:
2884 retval = _copyAlterGroupStmt(from);
2886 case T_DropGroupStmt:
2887 retval = _copyDropGroupStmt(from);
2890 retval = _copyReindexStmt(from);
2892 case T_CheckPointStmt:
2893 retval = (void *) makeNode(CheckPointStmt);
2897 retval = _copyAExpr(from);
2900 retval = _copyAttr(from);
2903 retval = _copyAConst(from);
2906 retval = _copyParamNo(from);
2909 retval = _copyIdent(from);
2912 retval = _copyFuncCall(from);
2915 retval = _copyAIndices(from);
2918 retval = _copyResTarget(from);
2921 retval = _copyTypeCast(from);
2924 retval = _copySortGroupBy(from);
2927 retval = _copyRangeVar(from);
2929 case T_RangeSubselect:
2930 retval = _copyRangeSubselect(from);
2933 retval = _copyTypeName(from);
2936 retval = _copyIndexElem(from);
2939 retval = _copyColumnDef(from);
2942 retval = _copyConstraint(from);
2945 retval = _copyDefElem(from);
2948 retval = _copyTargetEntry(from);
2950 case T_RangeTblEntry:
2951 retval = _copyRangeTblEntry(from);
2954 retval = _copySortClause(from);
2957 retval = _copyGroupClause(from);
2960 retval = _copyCaseExpr(from);
2963 retval = _copyCaseWhen(from);
2966 retval = _copyNullTest(from);
2969 retval = _copyBooleanTest(from);
2971 case T_FkConstraint:
2972 retval = _copyFkConstraint(from);
2975 retval = _copyPrivGrantee(from);
2979 elog(ERROR, "copyObject: don't know how to copy node type %d",
2981 retval = from; /* keep compiler quiet */