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.163 2002/02/26 22:47:05 tgl Exp $
20 *-------------------------------------------------------------------------
25 #include "optimizer/clauses.h"
26 #include "optimizer/planmain.h"
31 * a macro to simplify calling of copyObject on the specified field
33 #define Node_Copy(from, newnode, field) \
34 ((newnode)->field = copyObject((from)->field))
39 * This copy function only copies the "cons-cells" of the list, not the
40 * pointed-to objects. (Use copyObject if you want a "deep" copy.)
42 * We also use this function for copying lists of integers, which is
43 * grotty but unlikely to break --- it could fail if sizeof(pointer)
44 * is less than sizeof(int), but I don't know any such machines...
46 * Note that copyObject will surely coredump if applied to a list
56 /* rather ugly coding for speed... */
60 newlist = nl = makeList1(lfirst(list));
62 foreach(l, lnext(list))
64 lnext(nl) = makeList1(lfirst(l));
70 /* ****************************************************************
71 * plannodes.h copy functions
72 * ****************************************************************
78 * This function copies the fields of the Plan node. It is used by
79 * all the copy functions for classes which inherit from Plan.
83 CopyPlanFields(Plan *from, Plan *newnode)
85 newnode->startup_cost = from->startup_cost;
86 newnode->total_cost = from->total_cost;
87 newnode->plan_rows = from->plan_rows;
88 newnode->plan_width = from->plan_width;
89 /* state is NOT copied */
90 Node_Copy(from, newnode, targetlist);
91 Node_Copy(from, newnode, qual);
92 Node_Copy(from, newnode, lefttree);
93 Node_Copy(from, newnode, righttree);
94 newnode->extParam = listCopy(from->extParam);
95 newnode->locParam = listCopy(from->locParam);
96 newnode->chgParam = listCopy(from->chgParam);
97 Node_Copy(from, newnode, initPlan);
98 /* subPlan list must point to subplans in the new subtree, not the old */
99 if (from->subPlan != NIL)
100 newnode->subPlan = nconc(pull_subplans((Node *) newnode->targetlist),
101 pull_subplans((Node *) newnode->qual));
103 newnode->subPlan = NIL;
104 newnode->nParamExec = from->nParamExec;
112 _copyPlan(Plan *from)
114 Plan *newnode = makeNode(Plan);
117 * copy the node superclass fields
119 CopyPlanFields(from, newnode);
130 _copyResult(Result *from)
132 Result *newnode = makeNode(Result);
135 * copy node superclass fields
137 CopyPlanFields((Plan *) from, (Plan *) newnode);
140 * copy remainder of node
142 Node_Copy(from, newnode, resconstantqual);
145 * We must add subplans in resconstantqual to the new plan's subPlan
148 if (from->plan.subPlan != NIL)
149 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
150 pull_subplans(newnode->resconstantqual));
160 _copyAppend(Append *from)
162 Append *newnode = makeNode(Append);
165 * copy node superclass fields
167 CopyPlanFields((Plan *) from, (Plan *) newnode);
170 * copy remainder of node
172 Node_Copy(from, newnode, appendplans);
173 newnode->isTarget = from->isTarget;
182 * This function copies the fields of the Scan node. It is used by
183 * all the copy functions for classes which inherit from Scan.
187 CopyScanFields(Scan *from, Scan *newnode)
189 newnode->scanrelid = from->scanrelid;
198 _copyScan(Scan *from)
200 Scan *newnode = makeNode(Scan);
203 * copy node superclass fields
205 CopyPlanFields((Plan *) from, (Plan *) newnode);
206 CopyScanFields((Scan *) from, (Scan *) newnode);
216 _copySeqScan(SeqScan *from)
218 SeqScan *newnode = makeNode(SeqScan);
221 * copy node superclass fields
223 CopyPlanFields((Plan *) from, (Plan *) newnode);
224 CopyScanFields((Scan *) from, (Scan *) newnode);
234 _copyIndexScan(IndexScan *from)
236 IndexScan *newnode = makeNode(IndexScan);
239 * copy node superclass fields
241 CopyPlanFields((Plan *) from, (Plan *) newnode);
242 CopyScanFields((Scan *) from, (Scan *) newnode);
245 * copy remainder of node
247 newnode->indxid = listCopy(from->indxid);
248 Node_Copy(from, newnode, indxqual);
249 Node_Copy(from, newnode, indxqualorig);
250 newnode->indxorderdir = from->indxorderdir;
253 * We must add subplans in index quals to the new plan's subPlan list
255 if (from->scan.plan.subPlan != NIL)
257 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
258 pull_subplans((Node *) newnode->indxqual));
259 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
260 pull_subplans((Node *) newnode->indxqualorig));
271 _copyTidScan(TidScan *from)
273 TidScan *newnode = makeNode(TidScan);
276 * copy node superclass fields
278 CopyPlanFields((Plan *) from, (Plan *) newnode);
279 CopyScanFields((Scan *) from, (Scan *) newnode);
282 * copy remainder of node
284 newnode->needRescan = from->needRescan;
285 Node_Copy(from, newnode, tideval);
294 static SubqueryScan *
295 _copySubqueryScan(SubqueryScan *from)
297 SubqueryScan *newnode = makeNode(SubqueryScan);
300 * copy node superclass fields
302 CopyPlanFields((Plan *) from, (Plan *) newnode);
303 CopyScanFields((Scan *) from, (Scan *) newnode);
306 * copy remainder of node
308 Node_Copy(from, newnode, subplan);
317 * This function copies the fields of the Join node. It is used by
318 * all the copy functions for classes which inherit from Join.
322 CopyJoinFields(Join *from, Join *newnode)
324 newnode->jointype = from->jointype;
325 Node_Copy(from, newnode, joinqual);
326 /* subPlan list must point to subplans in the new subtree, not the old */
327 if (from->plan.subPlan != NIL)
328 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
329 pull_subplans((Node *) newnode->joinqual));
338 _copyJoin(Join *from)
340 Join *newnode = makeNode(Join);
343 * copy node superclass fields
345 CopyPlanFields((Plan *) from, (Plan *) newnode);
346 CopyJoinFields(from, newnode);
357 _copyNestLoop(NestLoop *from)
359 NestLoop *newnode = makeNode(NestLoop);
362 * copy node superclass fields
364 CopyPlanFields((Plan *) from, (Plan *) newnode);
365 CopyJoinFields((Join *) from, (Join *) newnode);
376 _copyMergeJoin(MergeJoin *from)
378 MergeJoin *newnode = makeNode(MergeJoin);
381 * copy node superclass fields
383 CopyPlanFields((Plan *) from, (Plan *) newnode);
384 CopyJoinFields((Join *) from, (Join *) newnode);
387 * copy remainder of node
389 Node_Copy(from, newnode, mergeclauses);
392 * We must add subplans in mergeclauses to the new plan's subPlan list
394 if (from->join.plan.subPlan != NIL)
395 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
396 pull_subplans((Node *) newnode->mergeclauses));
406 _copyHashJoin(HashJoin *from)
408 HashJoin *newnode = makeNode(HashJoin);
411 * copy node superclass fields
413 CopyPlanFields((Plan *) from, (Plan *) newnode);
414 CopyJoinFields((Join *) from, (Join *) newnode);
417 * copy remainder of node
419 Node_Copy(from, newnode, hashclauses);
420 newnode->hashjoinop = from->hashjoinop;
423 * We must add subplans in hashclauses to the new plan's subPlan list
425 if (from->join.plan.subPlan != NIL)
426 newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
427 pull_subplans((Node *) newnode->hashclauses));
438 _copyMaterial(Material *from)
440 Material *newnode = makeNode(Material);
443 * copy node superclass fields
445 CopyPlanFields((Plan *) from, (Plan *) newnode);
456 _copySort(Sort *from)
458 Sort *newnode = makeNode(Sort);
461 * copy node superclass fields
463 CopyPlanFields((Plan *) from, (Plan *) newnode);
465 newnode->keycount = from->keycount;
476 _copyGroup(Group *from)
478 Group *newnode = makeNode(Group);
480 CopyPlanFields((Plan *) from, (Plan *) newnode);
482 newnode->tuplePerGroup = from->tuplePerGroup;
483 newnode->numCols = from->numCols;
484 newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
485 memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
497 Agg *newnode = makeNode(Agg);
499 CopyPlanFields((Plan *) from, (Plan *) newnode);
509 _copyGroupClause(GroupClause *from)
511 GroupClause *newnode = makeNode(GroupClause);
513 newnode->tleSortGroupRef = from->tleSortGroupRef;
514 newnode->sortop = from->sortop;
524 _copyUnique(Unique *from)
526 Unique *newnode = makeNode(Unique);
529 * copy node superclass fields
531 CopyPlanFields((Plan *) from, (Plan *) newnode);
534 * copy remainder of node
536 newnode->numCols = from->numCols;
537 newnode->uniqColIdx = palloc(from->numCols * sizeof(AttrNumber));
538 memcpy(newnode->uniqColIdx, from->uniqColIdx, from->numCols * sizeof(AttrNumber));
548 _copySetOp(SetOp *from)
550 SetOp *newnode = makeNode(SetOp);
553 * copy node superclass fields
555 CopyPlanFields((Plan *) from, (Plan *) newnode);
558 * copy remainder of node
560 newnode->cmd = from->cmd;
561 newnode->numCols = from->numCols;
562 newnode->dupColIdx = palloc(from->numCols * sizeof(AttrNumber));
563 memcpy(newnode->dupColIdx, from->dupColIdx, from->numCols * sizeof(AttrNumber));
564 newnode->flagColIdx = from->flagColIdx;
574 _copyLimit(Limit *from)
576 Limit *newnode = makeNode(Limit);
579 * copy node superclass fields
581 CopyPlanFields((Plan *) from, (Plan *) newnode);
584 * copy remainder of node
586 Node_Copy(from, newnode, limitOffset);
587 Node_Copy(from, newnode, limitCount);
597 _copyHash(Hash *from)
599 Hash *newnode = makeNode(Hash);
602 * copy node superclass fields
604 CopyPlanFields((Plan *) from, (Plan *) newnode);
607 * copy remainder of node
609 Node_Copy(from, newnode, hashkey);
615 _copySubPlan(SubPlan *from)
617 SubPlan *newnode = makeNode(SubPlan);
619 Node_Copy(from, newnode, plan);
620 newnode->plan_id = from->plan_id;
621 Node_Copy(from, newnode, rtable);
622 newnode->setParam = listCopy(from->setParam);
623 newnode->parParam = listCopy(from->parParam);
624 Node_Copy(from, newnode, sublink);
626 /* do not copy execution state */
627 newnode->needShutdown = false;
628 newnode->curTuple = NULL;
633 /* ****************************************************************
634 * primnodes.h copy functions
635 * ****************************************************************
643 _copyResdom(Resdom *from)
645 Resdom *newnode = makeNode(Resdom);
647 newnode->resno = from->resno;
648 newnode->restype = from->restype;
649 newnode->restypmod = from->restypmod;
650 if (from->resname != NULL)
651 newnode->resname = pstrdup(from->resname);
652 newnode->ressortgroupref = from->ressortgroupref;
653 newnode->reskey = from->reskey;
654 newnode->reskeyop = from->reskeyop;
655 newnode->resjunk = from->resjunk;
661 _copyFjoin(Fjoin *from)
663 Fjoin *newnode = makeNode(Fjoin);
666 * copy node superclass fields
669 newnode->fj_initialized = from->fj_initialized;
670 newnode->fj_nNodes = from->fj_nNodes;
672 Node_Copy(from, newnode, fj_innerNode);
674 newnode->fj_results = (DatumPtr)
675 palloc((from->fj_nNodes) * sizeof(Datum));
676 memmove(from->fj_results,
678 (from->fj_nNodes) * sizeof(Datum));
680 newnode->fj_alwaysDone = (BoolPtr)
681 palloc((from->fj_nNodes) * sizeof(bool));
682 memmove(from->fj_alwaysDone,
683 newnode->fj_alwaysDone,
684 (from->fj_nNodes) * sizeof(bool));
695 _copyExpr(Expr *from)
697 Expr *newnode = makeNode(Expr);
700 * copy node superclass fields
702 newnode->typeOid = from->typeOid;
703 newnode->opType = from->opType;
705 Node_Copy(from, newnode, oper);
706 Node_Copy(from, newnode, args);
718 Var *newnode = makeNode(Var);
721 * copy remainder of node
723 newnode->varno = from->varno;
724 newnode->varattno = from->varattno;
725 newnode->vartype = from->vartype;
726 newnode->vartypmod = from->vartypmod;
727 newnode->varlevelsup = from->varlevelsup;
729 newnode->varnoold = from->varnoold;
730 newnode->varoattno = from->varoattno;
736 _copyAttr(Attr *from)
738 Attr *newnode = makeNode(Attr);
741 newnode->relname = pstrdup(from->relname);
742 Node_Copy(from, newnode, attrs);
752 _copyOper(Oper *from)
754 Oper *newnode = makeNode(Oper);
757 * copy remainder of node
759 newnode->opno = from->opno;
760 newnode->opid = from->opid;
761 newnode->opresulttype = from->opresulttype;
762 /* Do not copy the run-time state, if any */
763 newnode->op_fcache = NULL;
773 _copyConst(Const *from)
775 Const *newnode = makeNode(Const);
778 * copy remainder of node
780 newnode->consttype = from->consttype;
781 newnode->constlen = from->constlen;
783 if (from->constbyval || from->constisnull)
786 * passed by value so just copy the datum. Also, don't try to copy
787 * struct when value is null!
790 newnode->constvalue = from->constvalue;
795 * not passed by value. datum contains a pointer.
797 int length = from->constlen;
799 if (length == -1) /* variable-length type? */
800 length = VARSIZE(from->constvalue);
801 newnode->constvalue = PointerGetDatum(palloc(length));
802 memcpy(DatumGetPointer(newnode->constvalue),
803 DatumGetPointer(from->constvalue),
807 newnode->constisnull = from->constisnull;
808 newnode->constbyval = from->constbyval;
809 newnode->constisset = from->constisset;
810 newnode->constiscast = from->constiscast;
820 _copyParam(Param *from)
822 Param *newnode = makeNode(Param);
825 * copy remainder of node
827 newnode->paramkind = from->paramkind;
828 newnode->paramid = from->paramid;
830 if (from->paramname != NULL)
831 newnode->paramname = pstrdup(from->paramname);
832 newnode->paramtype = from->paramtype;
842 _copyFunc(Func *from)
844 Func *newnode = makeNode(Func);
847 * copy remainder of node
849 newnode->funcid = from->funcid;
850 newnode->functype = from->functype;
851 /* Do not copy the run-time state, if any */
852 newnode->func_fcache = NULL;
862 _copyAggref(Aggref *from)
864 Aggref *newnode = makeNode(Aggref);
867 * copy remainder of node
869 newnode->aggname = pstrdup(from->aggname);
870 newnode->basetype = from->basetype;
871 newnode->aggtype = from->aggtype;
872 Node_Copy(from, newnode, target);
873 newnode->aggstar = from->aggstar;
874 newnode->aggdistinct = from->aggdistinct;
875 newnode->aggno = from->aggno; /* probably not needed */
885 _copySubLink(SubLink *from)
887 SubLink *newnode = makeNode(SubLink);
890 * copy remainder of node
892 newnode->subLinkType = from->subLinkType;
893 newnode->useor = from->useor;
894 Node_Copy(from, newnode, lefthand);
895 Node_Copy(from, newnode, oper);
896 Node_Copy(from, newnode, subselect);
906 _copyFieldSelect(FieldSelect *from)
908 FieldSelect *newnode = makeNode(FieldSelect);
911 * copy remainder of node
913 Node_Copy(from, newnode, arg);
914 newnode->fieldnum = from->fieldnum;
915 newnode->resulttype = from->resulttype;
916 newnode->resulttypmod = from->resulttypmod;
926 _copyRelabelType(RelabelType *from)
928 RelabelType *newnode = makeNode(RelabelType);
931 * copy remainder of node
933 Node_Copy(from, newnode, arg);
934 newnode->resulttype = from->resulttype;
935 newnode->resulttypmod = from->resulttypmod;
941 _copyRangeTblRef(RangeTblRef *from)
943 RangeTblRef *newnode = makeNode(RangeTblRef);
945 newnode->rtindex = from->rtindex;
951 _copyFromExpr(FromExpr *from)
953 FromExpr *newnode = makeNode(FromExpr);
955 Node_Copy(from, newnode, fromlist);
956 Node_Copy(from, newnode, quals);
962 _copyJoinExpr(JoinExpr *from)
964 JoinExpr *newnode = makeNode(JoinExpr);
966 newnode->jointype = from->jointype;
967 newnode->isNatural = from->isNatural;
968 Node_Copy(from, newnode, larg);
969 Node_Copy(from, newnode, rarg);
970 Node_Copy(from, newnode, using);
971 Node_Copy(from, newnode, quals);
972 Node_Copy(from, newnode, alias);
973 Node_Copy(from, newnode, colnames);
974 Node_Copy(from, newnode, colvars);
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 * when you change this, also make sure to fix up xfunc_copyRelOptInfo in
1086 * planner/path/xfunc.c accordingly!!!
1090 _copyRelOptInfo(RelOptInfo *from)
1092 RelOptInfo *newnode = makeNode(RelOptInfo);
1094 newnode->relids = listCopy(from->relids);
1096 newnode->rows = from->rows;
1097 newnode->width = from->width;
1099 Node_Copy(from, newnode, targetlist);
1100 Node_Copy(from, newnode, pathlist);
1101 /* XXX cheapest-path fields should point to members of pathlist? */
1102 Node_Copy(from, newnode, cheapest_startup_path);
1103 Node_Copy(from, newnode, cheapest_total_path);
1104 newnode->pruneable = from->pruneable;
1106 newnode->issubquery = from->issubquery;
1107 Node_Copy(from, newnode, indexlist);
1108 newnode->pages = from->pages;
1109 newnode->tuples = from->tuples;
1110 Node_Copy(from, newnode, subplan);
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->hashjoinoperator = from->hashjoinoperator;
1410 newnode->left_bucketsize = from->left_bucketsize;
1411 newnode->right_bucketsize = from->right_bucketsize;
1421 _copyJoinInfo(JoinInfo *from)
1423 JoinInfo *newnode = makeNode(JoinInfo);
1426 * copy remainder of node
1428 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1429 Node_Copy(from, newnode, jinfo_restrictinfo);
1435 _copyIter(Iter *from)
1437 Iter *newnode = makeNode(Iter);
1439 Node_Copy(from, newnode, iterexpr);
1440 newnode->itertype = from->itertype;
1446 _copyStream(Stream *from)
1448 Stream *newnode = makeNode(Stream);
1450 newnode->pathptr = from->pathptr;
1451 newnode->cinfo = from->cinfo;
1452 newnode->clausetype = from->clausetype;
1454 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1456 Node_Copy(from, newnode, downstream);
1457 if (newnode->downstream)
1458 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1460 newnode->groupup = from->groupup;
1461 newnode->groupcost = from->groupcost;
1462 newnode->groupsel = from->groupsel;
1467 /* ****************************************************************
1468 * parsenodes.h copy functions
1469 * ****************************************************************
1472 static TargetEntry *
1473 _copyTargetEntry(TargetEntry *from)
1475 TargetEntry *newnode = makeNode(TargetEntry);
1477 Node_Copy(from, newnode, resdom);
1478 Node_Copy(from, newnode, fjoin);
1479 Node_Copy(from, newnode, expr);
1483 static RangeTblEntry *
1484 _copyRangeTblEntry(RangeTblEntry *from)
1486 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1489 newnode->relname = pstrdup(from->relname);
1490 newnode->relid = from->relid;
1491 Node_Copy(from, newnode, subquery);
1492 Node_Copy(from, newnode, alias);
1493 Node_Copy(from, newnode, eref);
1494 newnode->inh = from->inh;
1495 newnode->inFromCl = from->inFromCl;
1496 newnode->checkForRead = from->checkForRead;
1497 newnode->checkForWrite = from->checkForWrite;
1498 newnode->checkAsUser = from->checkAsUser;
1503 static FkConstraint *
1504 _copyFkConstraint(FkConstraint *from)
1506 FkConstraint *newnode = makeNode(FkConstraint);
1508 if (from->constr_name)
1509 newnode->constr_name = pstrdup(from->constr_name);
1510 if (from->pktable_name)
1511 newnode->pktable_name = pstrdup(from->pktable_name);
1512 Node_Copy(from, newnode, fk_attrs);
1513 Node_Copy(from, newnode, pk_attrs);
1514 if (from->match_type)
1515 newnode->match_type = pstrdup(from->match_type);
1516 newnode->actions = from->actions;
1517 newnode->deferrable = from->deferrable;
1518 newnode->initdeferred = from->initdeferred;
1524 _copySortClause(SortClause *from)
1526 SortClause *newnode = makeNode(SortClause);
1528 newnode->tleSortGroupRef = from->tleSortGroupRef;
1529 newnode->sortop = from->sortop;
1535 _copyAExpr(A_Expr *from)
1537 A_Expr *newnode = makeNode(A_Expr);
1539 newnode->oper = from->oper;
1541 newnode->opname = pstrdup(from->opname);
1542 Node_Copy(from, newnode, lexpr);
1543 Node_Copy(from, newnode, rexpr);
1549 _copyAConst(A_Const *from)
1551 A_Const *newnode = makeNode(A_Const);
1553 newnode->val = *((Value *) (copyObject(&(from->val))));
1554 Node_Copy(from, newnode, typename);
1560 _copyParamNo(ParamNo *from)
1562 ParamNo *newnode = makeNode(ParamNo);
1564 newnode->number = from->number;
1565 Node_Copy(from, newnode, typename);
1566 Node_Copy(from, newnode, indirection);
1572 _copyIdent(Ident *from)
1574 Ident *newnode = makeNode(Ident);
1577 newnode->name = pstrdup(from->name);
1578 Node_Copy(from, newnode, indirection);
1579 newnode->isRel = from->isRel;
1585 _copyFuncCall(FuncCall *from)
1587 FuncCall *newnode = makeNode(FuncCall);
1590 newnode->funcname = pstrdup(from->funcname);
1591 Node_Copy(from, newnode, args);
1592 newnode->agg_star = from->agg_star;
1593 newnode->agg_distinct = from->agg_distinct;
1599 _copyAIndices(A_Indices *from)
1601 A_Indices *newnode = makeNode(A_Indices);
1603 Node_Copy(from, newnode, lidx);
1604 Node_Copy(from, newnode, uidx);
1610 _copyResTarget(ResTarget *from)
1612 ResTarget *newnode = makeNode(ResTarget);
1615 newnode->name = pstrdup(from->name);
1616 Node_Copy(from, newnode, indirection);
1617 Node_Copy(from, newnode, val);
1623 _copyTypeName(TypeName *from)
1625 TypeName *newnode = makeNode(TypeName);
1628 newnode->name = pstrdup(from->name);
1629 newnode->timezone = from->timezone;
1630 newnode->setof = from->setof;
1631 newnode->typmod = from->typmod;
1632 Node_Copy(from, newnode, arrayBounds);
1637 static SortGroupBy *
1638 _copySortGroupBy(SortGroupBy *from)
1640 SortGroupBy *newnode = makeNode(SortGroupBy);
1643 newnode->useOp = pstrdup(from->useOp);
1644 Node_Copy(from, newnode, node);
1650 _copyRangeVar(RangeVar *from)
1652 RangeVar *newnode = makeNode(RangeVar);
1655 newnode->relname = pstrdup(from->relname);
1656 newnode->inhOpt = from->inhOpt;
1657 Node_Copy(from, newnode, name);
1662 static RangeSubselect *
1663 _copyRangeSubselect(RangeSubselect *from)
1665 RangeSubselect *newnode = makeNode(RangeSubselect);
1667 Node_Copy(from, newnode, subquery);
1668 Node_Copy(from, newnode, name);
1674 _copyTypeCast(TypeCast *from)
1676 TypeCast *newnode = makeNode(TypeCast);
1678 Node_Copy(from, newnode, arg);
1679 Node_Copy(from, newnode, typename);
1685 _copyIndexElem(IndexElem *from)
1687 IndexElem *newnode = makeNode(IndexElem);
1690 newnode->name = pstrdup(from->name);
1691 Node_Copy(from, newnode, args);
1693 newnode->class = pstrdup(from->class);
1699 _copyColumnDef(ColumnDef *from)
1701 ColumnDef *newnode = makeNode(ColumnDef);
1704 newnode->colname = pstrdup(from->colname);
1705 Node_Copy(from, newnode, typename);
1706 newnode->is_not_null = from->is_not_null;
1707 Node_Copy(from, newnode, raw_default);
1708 if (from->cooked_default)
1709 newnode->cooked_default = pstrdup(from->cooked_default);
1710 Node_Copy(from, newnode, constraints);
1716 _copyConstraint(Constraint *from)
1718 Constraint *newnode = makeNode(Constraint);
1720 newnode->contype = from->contype;
1722 newnode->name = pstrdup(from->name);
1723 Node_Copy(from, newnode, raw_expr);
1724 if (from->cooked_expr)
1725 newnode->cooked_expr = pstrdup(from->cooked_expr);
1726 Node_Copy(from, newnode, keys);
1732 _copyDefElem(DefElem *from)
1734 DefElem *newnode = makeNode(DefElem);
1737 newnode->defname = pstrdup(from->defname);
1738 Node_Copy(from, newnode, arg);
1744 _copyQuery(Query *from)
1746 Query *newnode = makeNode(Query);
1748 newnode->commandType = from->commandType;
1749 Node_Copy(from, newnode, utilityStmt);
1750 newnode->resultRelation = from->resultRelation;
1752 newnode->into = pstrdup(from->into);
1753 newnode->isPortal = from->isPortal;
1754 newnode->isBinary = from->isBinary;
1755 newnode->isTemp = from->isTemp;
1756 newnode->hasAggs = from->hasAggs;
1757 newnode->hasSubLinks = from->hasSubLinks;
1758 newnode->originalQuery = from->originalQuery;
1760 Node_Copy(from, newnode, rtable);
1761 Node_Copy(from, newnode, jointree);
1763 newnode->rowMarks = listCopy(from->rowMarks);
1765 Node_Copy(from, newnode, targetList);
1767 Node_Copy(from, newnode, groupClause);
1768 Node_Copy(from, newnode, havingQual);
1769 Node_Copy(from, newnode, distinctClause);
1770 Node_Copy(from, newnode, sortClause);
1772 Node_Copy(from, newnode, limitOffset);
1773 Node_Copy(from, newnode, limitCount);
1775 Node_Copy(from, newnode, setOperations);
1777 newnode->resultRelations = listCopy(from->resultRelations);
1780 * We do not copy the planner internal fields: base_rel_list,
1781 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. Not
1782 * entirely clear if this is right?
1789 _copyInsertStmt(InsertStmt *from)
1791 InsertStmt *newnode = makeNode(InsertStmt);
1794 newnode->relname = pstrdup(from->relname);
1795 Node_Copy(from, newnode, cols);
1796 Node_Copy(from, newnode, targetList);
1797 Node_Copy(from, newnode, selectStmt);
1803 _copyDeleteStmt(DeleteStmt *from)
1805 DeleteStmt *newnode = makeNode(DeleteStmt);
1808 newnode->relname = pstrdup(from->relname);
1809 Node_Copy(from, newnode, whereClause);
1810 newnode->inhOpt = from->inhOpt;
1816 _copyUpdateStmt(UpdateStmt *from)
1818 UpdateStmt *newnode = makeNode(UpdateStmt);
1821 newnode->relname = pstrdup(from->relname);
1822 Node_Copy(from, newnode, targetList);
1823 Node_Copy(from, newnode, whereClause);
1824 Node_Copy(from, newnode, fromClause);
1825 newnode->inhOpt = from->inhOpt;
1831 _copySelectStmt(SelectStmt *from)
1833 SelectStmt *newnode = makeNode(SelectStmt);
1835 Node_Copy(from, newnode, distinctClause);
1837 newnode->into = pstrdup(from->into);
1838 newnode->istemp = from->istemp;
1839 Node_Copy(from, newnode, intoColNames);
1840 Node_Copy(from, newnode, targetList);
1841 Node_Copy(from, newnode, fromClause);
1842 Node_Copy(from, newnode, whereClause);
1843 Node_Copy(from, newnode, groupClause);
1844 Node_Copy(from, newnode, havingClause);
1845 Node_Copy(from, newnode, sortClause);
1846 if (from->portalname)
1847 newnode->portalname = pstrdup(from->portalname);
1848 newnode->binary = from->binary;
1849 Node_Copy(from, newnode, limitOffset);
1850 Node_Copy(from, newnode, limitCount);
1851 Node_Copy(from, newnode, forUpdate);
1852 newnode->op = from->op;
1853 newnode->all = from->all;
1854 Node_Copy(from, newnode, larg);
1855 Node_Copy(from, newnode, rarg);
1860 static SetOperationStmt *
1861 _copySetOperationStmt(SetOperationStmt *from)
1863 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1865 newnode->op = from->op;
1866 newnode->all = from->all;
1867 Node_Copy(from, newnode, larg);
1868 Node_Copy(from, newnode, rarg);
1869 newnode->colTypes = listCopy(from->colTypes);
1874 static AlterTableStmt *
1875 _copyAlterTableStmt(AlterTableStmt *from)
1877 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1879 newnode->subtype = from->subtype;
1881 newnode->relname = pstrdup(from->relname);
1882 newnode->inhOpt = from->inhOpt;
1884 newnode->name = pstrdup(from->name);
1885 Node_Copy(from, newnode, def);
1886 newnode->behavior = from->behavior;
1892 _copyGrantStmt(GrantStmt *from)
1894 GrantStmt *newnode = makeNode(GrantStmt);
1896 newnode->is_grant = from->is_grant;
1897 newnode->objtype = from->objtype;
1898 Node_Copy(from, newnode, objects);
1899 Node_Copy(from, newnode, privileges);
1900 Node_Copy(from, newnode, grantees);
1905 static PrivGrantee *
1906 _copyPrivGrantee(PrivGrantee *from)
1908 PrivGrantee *newnode = makeNode(PrivGrantee);
1911 newnode->username = pstrdup(from->username);
1912 if (from->groupname)
1913 newnode->groupname = pstrdup(from->groupname);
1918 static FuncWithArgs *
1919 _copyFuncWithArgs(FuncWithArgs *from)
1921 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1924 newnode->funcname = pstrdup(from->funcname);
1926 newnode->funcname = NULL;
1927 Node_Copy(from, newnode, funcargs);
1932 static ClosePortalStmt *
1933 _copyClosePortalStmt(ClosePortalStmt *from)
1935 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1937 if (from->portalname)
1938 newnode->portalname = pstrdup(from->portalname);
1943 static ClusterStmt *
1944 _copyClusterStmt(ClusterStmt *from)
1946 ClusterStmt *newnode = makeNode(ClusterStmt);
1949 newnode->relname = pstrdup(from->relname);
1950 if (from->indexname)
1951 newnode->indexname = pstrdup(from->indexname);
1957 _copyCopyStmt(CopyStmt *from)
1959 CopyStmt *newnode = makeNode(CopyStmt);
1961 newnode->binary = from->binary;
1963 newnode->relname = pstrdup(from->relname);
1964 newnode->oids = from->oids;
1965 newnode->direction = from->direction;
1967 newnode->filename = pstrdup(from->filename);
1968 if (from->delimiter)
1969 newnode->delimiter = pstrdup(from->delimiter);
1970 if (from->null_print)
1971 newnode->null_print = pstrdup(from->null_print);
1977 _copyCreateStmt(CreateStmt *from)
1979 CreateStmt *newnode = makeNode(CreateStmt);
1981 newnode->relname = pstrdup(from->relname);
1982 Node_Copy(from, newnode, tableElts);
1983 Node_Copy(from, newnode, inhRelnames);
1984 Node_Copy(from, newnode, constraints);
1985 newnode->istemp = from->istemp;
1986 newnode->hasoids = from->hasoids;
1991 static VersionStmt *
1992 _copyVersionStmt(VersionStmt *from)
1994 VersionStmt *newnode = makeNode(VersionStmt);
1996 newnode->relname = pstrdup(from->relname);
1997 newnode->direction = from->direction;
1998 newnode->fromRelname = pstrdup(from->fromRelname);
1999 newnode->date = pstrdup(from->date);
2005 _copyDefineStmt(DefineStmt *from)
2007 DefineStmt *newnode = makeNode(DefineStmt);
2009 newnode->defType = from->defType;
2010 newnode->defname = pstrdup(from->defname);
2011 Node_Copy(from, newnode, definition);
2017 _copyDropStmt(DropStmt *from)
2019 DropStmt *newnode = makeNode(DropStmt);
2021 Node_Copy(from, newnode, names);
2022 newnode->removeType = from->removeType;
2027 static TruncateStmt *
2028 _copyTruncateStmt(TruncateStmt *from)
2030 TruncateStmt *newnode = makeNode(TruncateStmt);
2032 newnode->relName = pstrdup(from->relName);
2037 static CommentStmt *
2038 _copyCommentStmt(CommentStmt *from)
2040 CommentStmt *newnode = makeNode(CommentStmt);
2042 newnode->objtype = from->objtype;
2043 newnode->objname = pstrdup(from->objname);
2044 if (from->objproperty)
2045 newnode->objproperty = pstrdup(from->objproperty);
2046 Node_Copy(from, newnode, objlist);
2047 newnode->comment = pstrdup(from->comment);
2053 _copyFetchStmt(FetchStmt *from)
2055 FetchStmt *newnode = makeNode(FetchStmt);
2057 newnode->direction = from->direction;
2058 newnode->howMany = from->howMany;
2059 newnode->portalname = pstrdup(from->portalname);
2060 newnode->ismove = from->ismove;
2066 _copyIndexStmt(IndexStmt *from)
2068 IndexStmt *newnode = makeNode(IndexStmt);
2070 newnode->idxname = pstrdup(from->idxname);
2071 newnode->relname = pstrdup(from->relname);
2072 newnode->accessMethod = pstrdup(from->accessMethod);
2073 Node_Copy(from, newnode, indexParams);
2074 Node_Copy(from, newnode, whereClause);
2075 Node_Copy(from, newnode, rangetable);
2076 newnode->unique = from->unique;
2077 newnode->primary = from->primary;
2082 static ProcedureStmt *
2083 _copyProcedureStmt(ProcedureStmt *from)
2085 ProcedureStmt *newnode = makeNode(ProcedureStmt);
2087 newnode->replace = from->replace;
2088 newnode->funcname = pstrdup(from->funcname);
2089 Node_Copy(from, newnode, argTypes);
2090 Node_Copy(from, newnode, returnType);
2091 Node_Copy(from, newnode, withClause);
2092 Node_Copy(from, newnode, as);
2093 newnode->language = pstrdup(from->language);
2098 static RemoveAggrStmt *
2099 _copyRemoveAggrStmt(RemoveAggrStmt *from)
2101 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
2103 newnode->aggname = pstrdup(from->aggname);
2104 Node_Copy(from, newnode, aggtype);
2109 static RemoveFuncStmt *
2110 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2112 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2114 newnode->funcname = pstrdup(from->funcname);
2115 Node_Copy(from, newnode, args);
2120 static RemoveOperStmt *
2121 _copyRemoveOperStmt(RemoveOperStmt *from)
2123 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2125 newnode->opname = pstrdup(from->opname);
2126 Node_Copy(from, newnode, args);
2132 _copyRenameStmt(RenameStmt *from)
2134 RenameStmt *newnode = makeNode(RenameStmt);
2136 newnode->relname = pstrdup(from->relname);
2137 newnode->inhOpt = from->inhOpt;
2139 newnode->column = pstrdup(from->column);
2141 newnode->newname = pstrdup(from->newname);
2147 _copyRuleStmt(RuleStmt *from)
2149 RuleStmt *newnode = makeNode(RuleStmt);
2151 newnode->rulename = pstrdup(from->rulename);
2152 Node_Copy(from, newnode, whereClause);
2153 newnode->event = from->event;
2154 Node_Copy(from, newnode, object);
2155 newnode->instead = from->instead;
2156 Node_Copy(from, newnode, actions);
2162 _copyNotifyStmt(NotifyStmt *from)
2164 NotifyStmt *newnode = makeNode(NotifyStmt);
2167 newnode->relname = pstrdup(from->relname);
2173 _copyListenStmt(ListenStmt *from)
2175 ListenStmt *newnode = makeNode(ListenStmt);
2178 newnode->relname = pstrdup(from->relname);
2183 static UnlistenStmt *
2184 _copyUnlistenStmt(UnlistenStmt *from)
2186 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2189 newnode->relname = pstrdup(from->relname);
2194 static TransactionStmt *
2195 _copyTransactionStmt(TransactionStmt *from)
2197 TransactionStmt *newnode = makeNode(TransactionStmt);
2199 newnode->command = from->command;
2205 _copyViewStmt(ViewStmt *from)
2207 ViewStmt *newnode = makeNode(ViewStmt);
2210 newnode->viewname = pstrdup(from->viewname);
2211 Node_Copy(from, newnode, aliases);
2212 Node_Copy(from, newnode, query);
2218 _copyLoadStmt(LoadStmt *from)
2220 LoadStmt *newnode = makeNode(LoadStmt);
2223 newnode->filename = pstrdup(from->filename);
2228 static CreatedbStmt *
2229 _copyCreatedbStmt(CreatedbStmt *from)
2231 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2234 newnode->dbname = pstrdup(from->dbname);
2236 newnode->dbowner = pstrdup(from->dbowner);
2238 newnode->dbpath = pstrdup(from->dbpath);
2239 if (from->dbtemplate)
2240 newnode->dbtemplate = pstrdup(from->dbtemplate);
2241 newnode->encoding = from->encoding;
2247 _copyDropdbStmt(DropdbStmt *from)
2249 DropdbStmt *newnode = makeNode(DropdbStmt);
2252 newnode->dbname = pstrdup(from->dbname);
2258 _copyVacuumStmt(VacuumStmt *from)
2260 VacuumStmt *newnode = makeNode(VacuumStmt);
2262 newnode->vacuum = from->vacuum;
2263 newnode->full = from->full;
2264 newnode->analyze = from->analyze;
2265 newnode->freeze = from->freeze;
2266 newnode->verbose = from->verbose;
2268 newnode->vacrel = pstrdup(from->vacrel);
2269 Node_Copy(from, newnode, va_cols);
2274 static ExplainStmt *
2275 _copyExplainStmt(ExplainStmt *from)
2277 ExplainStmt *newnode = makeNode(ExplainStmt);
2279 Node_Copy(from, newnode, query);
2280 newnode->verbose = from->verbose;
2281 newnode->analyze = from->analyze;
2286 static CreateSeqStmt *
2287 _copyCreateSeqStmt(CreateSeqStmt *from)
2289 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2292 newnode->seqname = pstrdup(from->seqname);
2293 Node_Copy(from, newnode, options);
2298 static VariableSetStmt *
2299 _copyVariableSetStmt(VariableSetStmt *from)
2301 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2304 newnode->name = pstrdup(from->name);
2305 Node_Copy(from, newnode, args);
2310 static VariableShowStmt *
2311 _copyVariableShowStmt(VariableShowStmt *from)
2313 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2316 newnode->name = pstrdup(from->name);
2321 static VariableResetStmt *
2322 _copyVariableResetStmt(VariableResetStmt *from)
2324 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2327 newnode->name = pstrdup(from->name);
2332 static CreateTrigStmt *
2333 _copyCreateTrigStmt(CreateTrigStmt *from)
2335 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2338 newnode->trigname = pstrdup(from->trigname);
2340 newnode->relname = pstrdup(from->relname);
2342 newnode->funcname = pstrdup(from->funcname);
2343 Node_Copy(from, newnode, args);
2344 newnode->before = from->before;
2345 newnode->row = from->row;
2346 memcpy(newnode->actions, from->actions, sizeof(from->actions));
2348 newnode->lang = pstrdup(from->lang);
2350 newnode->text = pstrdup(from->text);
2352 Node_Copy(from, newnode, attr);
2354 newnode->when = pstrdup(from->when);
2355 newnode->isconstraint = from->isconstraint;
2356 newnode->deferrable = from->deferrable;
2357 newnode->initdeferred = from->initdeferred;
2358 if (from->constrrelname)
2359 newnode->constrrelname = pstrdup(from->constrrelname);
2364 static DropTrigStmt *
2365 _copyDropTrigStmt(DropTrigStmt *from)
2367 DropTrigStmt *newnode = makeNode(DropTrigStmt);
2370 newnode->trigname = pstrdup(from->trigname);
2372 newnode->relname = pstrdup(from->relname);
2377 static CreatePLangStmt *
2378 _copyCreatePLangStmt(CreatePLangStmt *from)
2380 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2383 newnode->plname = pstrdup(from->plname);
2384 if (from->plhandler)
2385 newnode->plhandler = pstrdup(from->plhandler);
2386 if (from->plcompiler)
2387 newnode->plcompiler = pstrdup(from->plcompiler);
2388 newnode->pltrusted = from->pltrusted;
2393 static DropPLangStmt *
2394 _copyDropPLangStmt(DropPLangStmt *from)
2396 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2399 newnode->plname = pstrdup(from->plname);
2404 static CreateUserStmt *
2405 _copyCreateUserStmt(CreateUserStmt *from)
2407 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2410 newnode->user = pstrdup(from->user);
2411 Node_Copy(from, newnode, options);
2416 static AlterUserStmt *
2417 _copyAlterUserStmt(AlterUserStmt *from)
2419 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2422 newnode->user = pstrdup(from->user);
2423 Node_Copy(from, newnode, options);
2428 static DropUserStmt *
2429 _copyDropUserStmt(DropUserStmt *from)
2431 DropUserStmt *newnode = makeNode(DropUserStmt);
2433 Node_Copy(from, newnode, users);
2439 _copyLockStmt(LockStmt *from)
2441 LockStmt *newnode = makeNode(LockStmt);
2443 Node_Copy(from, newnode, rellist);
2445 newnode->mode = from->mode;
2450 static ConstraintsSetStmt *
2451 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2453 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2455 Node_Copy(from, newnode, constraints);
2456 newnode->deferred = from->deferred;
2461 static CreateGroupStmt *
2462 _copyCreateGroupStmt(CreateGroupStmt *from)
2464 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2467 newnode->name = pstrdup(from->name);
2468 Node_Copy(from, newnode, options);
2473 static AlterGroupStmt *
2474 _copyAlterGroupStmt(AlterGroupStmt *from)
2476 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2479 newnode->name = pstrdup(from->name);
2480 newnode->action = from->action;
2481 Node_Copy(from, newnode, listUsers);
2486 static DropGroupStmt *
2487 _copyDropGroupStmt(DropGroupStmt *from)
2489 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2492 newnode->name = pstrdup(from->name);
2497 static ReindexStmt *
2498 _copyReindexStmt(ReindexStmt *from)
2500 ReindexStmt *newnode = makeNode(ReindexStmt);
2502 newnode->reindexType = from->reindexType;
2504 newnode->name = pstrdup(from->name);
2505 newnode->force = from->force;
2506 newnode->all = from->all;
2512 /* ****************************************************************
2513 * pg_list.h copy functions
2514 * ****************************************************************
2518 _copyValue(Value *from)
2520 Value *newnode = makeNode(Value);
2522 newnode->type = from->type;
2526 newnode->val.ival = from->val.ival;
2531 newnode->val.str = pstrdup(from->val.str);
2540 * copyObject returns a copy of the node or list. If it is a list, it
2541 * recursively copies its items.
2545 copyObject(void *from)
2552 switch (nodeTag(from))
2558 retval = _copyPlan(from);
2561 retval = _copyResult(from);
2564 retval = _copyAppend(from);
2567 retval = _copyScan(from);
2570 retval = _copySeqScan(from);
2573 retval = _copyIndexScan(from);
2576 retval = _copyTidScan(from);
2578 case T_SubqueryScan:
2579 retval = _copySubqueryScan(from);
2582 retval = _copyJoin(from);
2585 retval = _copyNestLoop(from);
2588 retval = _copyMergeJoin(from);
2591 retval = _copyHashJoin(from);
2594 retval = _copyMaterial(from);
2597 retval = _copySort(from);
2600 retval = _copyGroup(from);
2603 retval = _copyAgg(from);
2606 retval = _copyUnique(from);
2609 retval = _copySetOp(from);
2612 retval = _copyLimit(from);
2615 retval = _copyHash(from);
2618 retval = _copySubPlan(from);
2625 retval = _copyResdom(from);
2628 retval = _copyFjoin(from);
2631 retval = _copyExpr(from);
2634 retval = _copyVar(from);
2637 retval = _copyOper(from);
2640 retval = _copyConst(from);
2643 retval = _copyParam(from);
2646 retval = _copyAggref(from);
2649 retval = _copySubLink(from);
2652 retval = _copyFunc(from);
2655 retval = _copyArrayRef(from);
2658 retval = _copyIter(from);
2661 retval = _copyFieldSelect(from);
2664 retval = _copyRelabelType(from);
2667 retval = _copyRangeTblRef(from);
2670 retval = _copyFromExpr(from);
2673 retval = _copyJoinExpr(from);
2680 retval = _copyRelOptInfo(from);
2683 retval = _copyPath(from);
2686 retval = _copyIndexPath(from);
2689 retval = _copyTidPath(from);
2692 retval = _copyAppendPath(from);
2695 retval = _copyNestPath(from);
2698 retval = _copyMergePath(from);
2701 retval = _copyHashPath(from);
2704 retval = _copyPathKeyItem(from);
2706 case T_RestrictInfo:
2707 retval = _copyRestrictInfo(from);
2710 retval = _copyJoinInfo(from);
2713 retval = _copyStream(from);
2715 case T_IndexOptInfo:
2716 retval = _copyIndexOptInfo(from);
2726 retval = _copyValue(from);
2734 /* rather ugly coding for speed... */
2735 /* Note the input list cannot be NIL if we got here. */
2736 nl = makeList1(copyObject(lfirst(list)));
2739 foreach(l, lnext(list))
2741 lnext(nl) = makeList1(copyObject(lfirst(l)));
2751 retval = _copyQuery(from);
2754 retval = _copyInsertStmt(from);
2757 retval = _copyDeleteStmt(from);
2760 retval = _copyUpdateStmt(from);
2763 retval = _copySelectStmt(from);
2765 case T_SetOperationStmt:
2766 retval = _copySetOperationStmt(from);
2768 case T_AlterTableStmt:
2769 retval = _copyAlterTableStmt(from);
2772 retval = _copyGrantStmt(from);
2774 case T_ClosePortalStmt:
2775 retval = _copyClosePortalStmt(from);
2778 retval = _copyClusterStmt(from);
2781 retval = _copyCopyStmt(from);
2784 retval = _copyCreateStmt(from);
2787 retval = _copyVersionStmt(from);
2790 retval = _copyDefineStmt(from);
2793 retval = _copyDropStmt(from);
2795 case T_TruncateStmt:
2796 retval = _copyTruncateStmt(from);
2799 retval = _copyCommentStmt(from);
2802 retval = _copyFetchStmt(from);
2805 retval = _copyIndexStmt(from);
2807 case T_ProcedureStmt:
2808 retval = _copyProcedureStmt(from);
2810 case T_RemoveAggrStmt:
2811 retval = _copyRemoveAggrStmt(from);
2813 case T_RemoveFuncStmt:
2814 retval = _copyRemoveFuncStmt(from);
2816 case T_RemoveOperStmt:
2817 retval = _copyRemoveOperStmt(from);
2820 retval = _copyRenameStmt(from);
2823 retval = _copyRuleStmt(from);
2826 retval = _copyNotifyStmt(from);
2829 retval = _copyListenStmt(from);
2831 case T_UnlistenStmt:
2832 retval = _copyUnlistenStmt(from);
2834 case T_TransactionStmt:
2835 retval = _copyTransactionStmt(from);
2838 retval = _copyViewStmt(from);
2841 retval = _copyLoadStmt(from);
2843 case T_CreatedbStmt:
2844 retval = _copyCreatedbStmt(from);
2847 retval = _copyDropdbStmt(from);
2850 retval = _copyVacuumStmt(from);
2853 retval = _copyExplainStmt(from);
2855 case T_CreateSeqStmt:
2856 retval = _copyCreateSeqStmt(from);
2858 case T_VariableSetStmt:
2859 retval = _copyVariableSetStmt(from);
2861 case T_VariableShowStmt:
2862 retval = _copyVariableShowStmt(from);
2864 case T_VariableResetStmt:
2865 retval = _copyVariableResetStmt(from);
2867 case T_CreateTrigStmt:
2868 retval = _copyCreateTrigStmt(from);
2870 case T_DropTrigStmt:
2871 retval = _copyDropTrigStmt(from);
2873 case T_CreatePLangStmt:
2874 retval = _copyCreatePLangStmt(from);
2876 case T_DropPLangStmt:
2877 retval = _copyDropPLangStmt(from);
2879 case T_CreateUserStmt:
2880 retval = _copyCreateUserStmt(from);
2882 case T_AlterUserStmt:
2883 retval = _copyAlterUserStmt(from);
2885 case T_DropUserStmt:
2886 retval = _copyDropUserStmt(from);
2889 retval = _copyLockStmt(from);
2891 case T_ConstraintsSetStmt:
2892 retval = _copyConstraintsSetStmt(from);
2894 case T_CreateGroupStmt:
2895 retval = _copyCreateGroupStmt(from);
2897 case T_AlterGroupStmt:
2898 retval = _copyAlterGroupStmt(from);
2900 case T_DropGroupStmt:
2901 retval = _copyDropGroupStmt(from);
2904 retval = _copyReindexStmt(from);
2906 case T_CheckPointStmt:
2907 retval = (void *) makeNode(CheckPointStmt);
2911 retval = _copyAExpr(from);
2914 retval = _copyAttr(from);
2917 retval = _copyAConst(from);
2920 retval = _copyParamNo(from);
2923 retval = _copyIdent(from);
2926 retval = _copyFuncCall(from);
2929 retval = _copyAIndices(from);
2932 retval = _copyResTarget(from);
2935 retval = _copyTypeCast(from);
2938 retval = _copySortGroupBy(from);
2941 retval = _copyRangeVar(from);
2943 case T_RangeSubselect:
2944 retval = _copyRangeSubselect(from);
2947 retval = _copyTypeName(from);
2950 retval = _copyIndexElem(from);
2953 retval = _copyColumnDef(from);
2956 retval = _copyConstraint(from);
2959 retval = _copyDefElem(from);
2962 retval = _copyTargetEntry(from);
2964 case T_RangeTblEntry:
2965 retval = _copyRangeTblEntry(from);
2968 retval = _copySortClause(from);
2971 retval = _copyGroupClause(from);
2974 retval = _copyCaseExpr(from);
2977 retval = _copyCaseWhen(from);
2980 retval = _copyNullTest(from);
2983 retval = _copyBooleanTest(from);
2985 case T_FkConstraint:
2986 retval = _copyFkConstraint(from);
2989 retval = _copyPrivGrantee(from);
2991 case T_FuncWithArgs:
2992 retval = _copyFuncWithArgs(from);
2996 elog(ERROR, "copyObject: don't know how to copy node type %d",
2998 retval = from; /* keep compiler quiet */