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.167 2002/03/07 16:35:34 momjian 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->left_mergescansel = from->left_mergescansel;
1410 newnode->right_mergescansel = from->right_mergescansel;
1411 newnode->hashjoinoperator = from->hashjoinoperator;
1412 newnode->left_bucketsize = from->left_bucketsize;
1413 newnode->right_bucketsize = from->right_bucketsize;
1423 _copyJoinInfo(JoinInfo *from)
1425 JoinInfo *newnode = makeNode(JoinInfo);
1428 * copy remainder of node
1430 newnode->unjoined_relids = listCopy(from->unjoined_relids);
1431 Node_Copy(from, newnode, jinfo_restrictinfo);
1437 _copyIter(Iter *from)
1439 Iter *newnode = makeNode(Iter);
1441 Node_Copy(from, newnode, iterexpr);
1442 newnode->itertype = from->itertype;
1448 _copyStream(Stream *from)
1450 Stream *newnode = makeNode(Stream);
1452 newnode->pathptr = from->pathptr;
1453 newnode->cinfo = from->cinfo;
1454 newnode->clausetype = from->clausetype;
1456 newnode->upstream = (StreamPtr) NULL; /* only copy nodes
1458 Node_Copy(from, newnode, downstream);
1459 if (newnode->downstream)
1460 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1462 newnode->groupup = from->groupup;
1463 newnode->groupcost = from->groupcost;
1464 newnode->groupsel = from->groupsel;
1469 /* ****************************************************************
1470 * parsenodes.h copy functions
1471 * ****************************************************************
1474 static TargetEntry *
1475 _copyTargetEntry(TargetEntry *from)
1477 TargetEntry *newnode = makeNode(TargetEntry);
1479 Node_Copy(from, newnode, resdom);
1480 Node_Copy(from, newnode, fjoin);
1481 Node_Copy(from, newnode, expr);
1485 static RangeTblEntry *
1486 _copyRangeTblEntry(RangeTblEntry *from)
1488 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1491 newnode->relname = pstrdup(from->relname);
1492 newnode->relid = from->relid;
1493 Node_Copy(from, newnode, subquery);
1494 Node_Copy(from, newnode, alias);
1495 Node_Copy(from, newnode, eref);
1496 newnode->inh = from->inh;
1497 newnode->inFromCl = from->inFromCl;
1498 newnode->checkForRead = from->checkForRead;
1499 newnode->checkForWrite = from->checkForWrite;
1500 newnode->checkAsUser = from->checkAsUser;
1505 static FkConstraint *
1506 _copyFkConstraint(FkConstraint *from)
1508 FkConstraint *newnode = makeNode(FkConstraint);
1510 if (from->constr_name)
1511 newnode->constr_name = pstrdup(from->constr_name);
1512 if (from->pktable_name)
1513 newnode->pktable_name = pstrdup(from->pktable_name);
1514 Node_Copy(from, newnode, fk_attrs);
1515 Node_Copy(from, newnode, pk_attrs);
1516 if (from->match_type)
1517 newnode->match_type = pstrdup(from->match_type);
1518 newnode->actions = from->actions;
1519 newnode->deferrable = from->deferrable;
1520 newnode->initdeferred = from->initdeferred;
1526 _copySortClause(SortClause *from)
1528 SortClause *newnode = makeNode(SortClause);
1530 newnode->tleSortGroupRef = from->tleSortGroupRef;
1531 newnode->sortop = from->sortop;
1537 _copyAExpr(A_Expr *from)
1539 A_Expr *newnode = makeNode(A_Expr);
1541 newnode->oper = from->oper;
1543 newnode->opname = pstrdup(from->opname);
1544 Node_Copy(from, newnode, lexpr);
1545 Node_Copy(from, newnode, rexpr);
1551 _copyAConst(A_Const *from)
1553 A_Const *newnode = makeNode(A_Const);
1555 newnode->val = *((Value *) (copyObject(&(from->val))));
1556 Node_Copy(from, newnode, typename);
1562 _copyParamNo(ParamNo *from)
1564 ParamNo *newnode = makeNode(ParamNo);
1566 newnode->number = from->number;
1567 Node_Copy(from, newnode, typename);
1568 Node_Copy(from, newnode, indirection);
1574 _copyIdent(Ident *from)
1576 Ident *newnode = makeNode(Ident);
1579 newnode->name = pstrdup(from->name);
1580 Node_Copy(from, newnode, indirection);
1581 newnode->isRel = from->isRel;
1587 _copyFuncCall(FuncCall *from)
1589 FuncCall *newnode = makeNode(FuncCall);
1592 newnode->funcname = pstrdup(from->funcname);
1593 Node_Copy(from, newnode, args);
1594 newnode->agg_star = from->agg_star;
1595 newnode->agg_distinct = from->agg_distinct;
1601 _copyAIndices(A_Indices *from)
1603 A_Indices *newnode = makeNode(A_Indices);
1605 Node_Copy(from, newnode, lidx);
1606 Node_Copy(from, newnode, uidx);
1612 _copyResTarget(ResTarget *from)
1614 ResTarget *newnode = makeNode(ResTarget);
1617 newnode->name = pstrdup(from->name);
1618 Node_Copy(from, newnode, indirection);
1619 Node_Copy(from, newnode, val);
1625 _copyTypeName(TypeName *from)
1627 TypeName *newnode = makeNode(TypeName);
1630 newnode->name = pstrdup(from->name);
1631 newnode->timezone = from->timezone;
1632 newnode->setof = from->setof;
1633 newnode->typmod = from->typmod;
1634 Node_Copy(from, newnode, arrayBounds);
1639 static SortGroupBy *
1640 _copySortGroupBy(SortGroupBy *from)
1642 SortGroupBy *newnode = makeNode(SortGroupBy);
1645 newnode->useOp = pstrdup(from->useOp);
1646 Node_Copy(from, newnode, node);
1652 _copyRangeVar(RangeVar *from)
1654 RangeVar *newnode = makeNode(RangeVar);
1657 newnode->relname = pstrdup(from->relname);
1658 newnode->inhOpt = from->inhOpt;
1659 Node_Copy(from, newnode, name);
1664 static RangeSubselect *
1665 _copyRangeSubselect(RangeSubselect *from)
1667 RangeSubselect *newnode = makeNode(RangeSubselect);
1669 Node_Copy(from, newnode, subquery);
1670 Node_Copy(from, newnode, name);
1676 _copyTypeCast(TypeCast *from)
1678 TypeCast *newnode = makeNode(TypeCast);
1680 Node_Copy(from, newnode, arg);
1681 Node_Copy(from, newnode, typename);
1687 _copyIndexElem(IndexElem *from)
1689 IndexElem *newnode = makeNode(IndexElem);
1692 newnode->name = pstrdup(from->name);
1693 Node_Copy(from, newnode, args);
1695 newnode->class = pstrdup(from->class);
1701 _copyColumnDef(ColumnDef *from)
1703 ColumnDef *newnode = makeNode(ColumnDef);
1706 newnode->colname = pstrdup(from->colname);
1707 Node_Copy(from, newnode, typename);
1708 newnode->is_not_null = from->is_not_null;
1709 Node_Copy(from, newnode, raw_default);
1710 if (from->cooked_default)
1711 newnode->cooked_default = pstrdup(from->cooked_default);
1712 Node_Copy(from, newnode, constraints);
1718 _copyConstraint(Constraint *from)
1720 Constraint *newnode = makeNode(Constraint);
1722 newnode->contype = from->contype;
1724 newnode->name = pstrdup(from->name);
1725 Node_Copy(from, newnode, raw_expr);
1726 if (from->cooked_expr)
1727 newnode->cooked_expr = pstrdup(from->cooked_expr);
1728 Node_Copy(from, newnode, keys);
1734 _copyDefElem(DefElem *from)
1736 DefElem *newnode = makeNode(DefElem);
1739 newnode->defname = pstrdup(from->defname);
1740 Node_Copy(from, newnode, arg);
1746 _copyQuery(Query *from)
1748 Query *newnode = makeNode(Query);
1750 newnode->commandType = from->commandType;
1751 Node_Copy(from, newnode, utilityStmt);
1752 newnode->resultRelation = from->resultRelation;
1754 newnode->into = pstrdup(from->into);
1755 newnode->isPortal = from->isPortal;
1756 newnode->isBinary = from->isBinary;
1757 newnode->isTemp = from->isTemp;
1758 newnode->hasAggs = from->hasAggs;
1759 newnode->hasSubLinks = from->hasSubLinks;
1760 newnode->originalQuery = from->originalQuery;
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. Not
1784 * 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, intoColNames);
1842 Node_Copy(from, newnode, targetList);
1843 Node_Copy(from, newnode, fromClause);
1844 Node_Copy(from, newnode, whereClause);
1845 Node_Copy(from, newnode, groupClause);
1846 Node_Copy(from, newnode, havingClause);
1847 Node_Copy(from, newnode, sortClause);
1848 if (from->portalname)
1849 newnode->portalname = pstrdup(from->portalname);
1850 newnode->binary = from->binary;
1851 Node_Copy(from, newnode, limitOffset);
1852 Node_Copy(from, newnode, limitCount);
1853 Node_Copy(from, newnode, forUpdate);
1854 newnode->op = from->op;
1855 newnode->all = from->all;
1856 Node_Copy(from, newnode, larg);
1857 Node_Copy(from, newnode, rarg);
1862 static SetOperationStmt *
1863 _copySetOperationStmt(SetOperationStmt *from)
1865 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1867 newnode->op = from->op;
1868 newnode->all = from->all;
1869 Node_Copy(from, newnode, larg);
1870 Node_Copy(from, newnode, rarg);
1871 newnode->colTypes = listCopy(from->colTypes);
1876 static AlterTableStmt *
1877 _copyAlterTableStmt(AlterTableStmt *from)
1879 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1881 newnode->subtype = from->subtype;
1883 newnode->relname = pstrdup(from->relname);
1884 newnode->inhOpt = from->inhOpt;
1886 newnode->name = pstrdup(from->name);
1887 Node_Copy(from, newnode, def);
1888 newnode->behavior = from->behavior;
1894 _copyGrantStmt(GrantStmt *from)
1896 GrantStmt *newnode = makeNode(GrantStmt);
1898 newnode->is_grant = from->is_grant;
1899 newnode->objtype = from->objtype;
1900 Node_Copy(from, newnode, objects);
1901 Node_Copy(from, newnode, privileges);
1902 Node_Copy(from, newnode, grantees);
1907 static PrivGrantee *
1908 _copyPrivGrantee(PrivGrantee *from)
1910 PrivGrantee *newnode = makeNode(PrivGrantee);
1913 newnode->username = pstrdup(from->username);
1914 if (from->groupname)
1915 newnode->groupname = pstrdup(from->groupname);
1920 static FuncWithArgs *
1921 _copyFuncWithArgs(FuncWithArgs *from)
1923 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1926 newnode->funcname = pstrdup(from->funcname);
1928 newnode->funcname = NULL;
1929 Node_Copy(from, newnode, funcargs);
1934 static ClosePortalStmt *
1935 _copyClosePortalStmt(ClosePortalStmt *from)
1937 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1939 if (from->portalname)
1940 newnode->portalname = pstrdup(from->portalname);
1945 static ClusterStmt *
1946 _copyClusterStmt(ClusterStmt *from)
1948 ClusterStmt *newnode = makeNode(ClusterStmt);
1951 newnode->relname = pstrdup(from->relname);
1952 if (from->indexname)
1953 newnode->indexname = pstrdup(from->indexname);
1959 _copyCopyStmt(CopyStmt *from)
1961 CopyStmt *newnode = makeNode(CopyStmt);
1963 newnode->binary = from->binary;
1965 newnode->relname = pstrdup(from->relname);
1966 newnode->oids = from->oids;
1967 newnode->direction = from->direction;
1969 newnode->filename = pstrdup(from->filename);
1970 if (from->delimiter)
1971 newnode->delimiter = pstrdup(from->delimiter);
1972 if (from->null_print)
1973 newnode->null_print = pstrdup(from->null_print);
1979 _copyCreateStmt(CreateStmt *from)
1981 CreateStmt *newnode = makeNode(CreateStmt);
1983 newnode->relname = pstrdup(from->relname);
1984 Node_Copy(from, newnode, tableElts);
1985 Node_Copy(from, newnode, inhRelnames);
1986 Node_Copy(from, newnode, constraints);
1987 newnode->istemp = from->istemp;
1988 newnode->hasoids = from->hasoids;
1993 static VersionStmt *
1994 _copyVersionStmt(VersionStmt *from)
1996 VersionStmt *newnode = makeNode(VersionStmt);
1998 newnode->relname = pstrdup(from->relname);
1999 newnode->direction = from->direction;
2000 newnode->fromRelname = pstrdup(from->fromRelname);
2001 newnode->date = pstrdup(from->date);
2007 _copyDefineStmt(DefineStmt *from)
2009 DefineStmt *newnode = makeNode(DefineStmt);
2011 newnode->defType = from->defType;
2012 newnode->defname = pstrdup(from->defname);
2013 Node_Copy(from, newnode, definition);
2019 _copyDropStmt(DropStmt *from)
2021 DropStmt *newnode = makeNode(DropStmt);
2023 Node_Copy(from, newnode, names);
2024 newnode->removeType = from->removeType;
2029 static TruncateStmt *
2030 _copyTruncateStmt(TruncateStmt *from)
2032 TruncateStmt *newnode = makeNode(TruncateStmt);
2034 newnode->relName = pstrdup(from->relName);
2039 static CommentStmt *
2040 _copyCommentStmt(CommentStmt *from)
2042 CommentStmt *newnode = makeNode(CommentStmt);
2044 newnode->objtype = from->objtype;
2045 newnode->objname = pstrdup(from->objname);
2046 if (from->objproperty)
2047 newnode->objproperty = pstrdup(from->objproperty);
2048 Node_Copy(from, newnode, objlist);
2049 newnode->comment = pstrdup(from->comment);
2055 _copyFetchStmt(FetchStmt *from)
2057 FetchStmt *newnode = makeNode(FetchStmt);
2059 newnode->direction = from->direction;
2060 newnode->howMany = from->howMany;
2061 newnode->portalname = pstrdup(from->portalname);
2062 newnode->ismove = from->ismove;
2068 _copyIndexStmt(IndexStmt *from)
2070 IndexStmt *newnode = makeNode(IndexStmt);
2072 newnode->idxname = pstrdup(from->idxname);
2073 newnode->relname = pstrdup(from->relname);
2074 newnode->accessMethod = pstrdup(from->accessMethod);
2075 Node_Copy(from, newnode, indexParams);
2076 Node_Copy(from, newnode, whereClause);
2077 Node_Copy(from, newnode, rangetable);
2078 newnode->unique = from->unique;
2079 newnode->primary = from->primary;
2084 static ProcedureStmt *
2085 _copyProcedureStmt(ProcedureStmt *from)
2087 ProcedureStmt *newnode = makeNode(ProcedureStmt);
2089 newnode->replace = from->replace;
2090 newnode->funcname = pstrdup(from->funcname);
2091 Node_Copy(from, newnode, argTypes);
2092 Node_Copy(from, newnode, returnType);
2093 Node_Copy(from, newnode, withClause);
2094 Node_Copy(from, newnode, as);
2095 newnode->language = pstrdup(from->language);
2100 static RemoveAggrStmt *
2101 _copyRemoveAggrStmt(RemoveAggrStmt *from)
2103 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
2105 newnode->aggname = pstrdup(from->aggname);
2106 Node_Copy(from, newnode, aggtype);
2111 static RemoveFuncStmt *
2112 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2114 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2116 newnode->funcname = pstrdup(from->funcname);
2117 Node_Copy(from, newnode, args);
2122 static RemoveOperStmt *
2123 _copyRemoveOperStmt(RemoveOperStmt *from)
2125 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2127 newnode->opname = pstrdup(from->opname);
2128 Node_Copy(from, newnode, args);
2134 _copyRenameStmt(RenameStmt *from)
2136 RenameStmt *newnode = makeNode(RenameStmt);
2138 newnode->relname = pstrdup(from->relname);
2139 newnode->inhOpt = from->inhOpt;
2141 newnode->column = pstrdup(from->column);
2143 newnode->newname = pstrdup(from->newname);
2149 _copyRuleStmt(RuleStmt *from)
2151 RuleStmt *newnode = makeNode(RuleStmt);
2153 newnode->rulename = pstrdup(from->rulename);
2154 Node_Copy(from, newnode, whereClause);
2155 newnode->event = from->event;
2156 Node_Copy(from, newnode, object);
2157 newnode->instead = from->instead;
2158 Node_Copy(from, newnode, actions);
2164 _copyNotifyStmt(NotifyStmt *from)
2166 NotifyStmt *newnode = makeNode(NotifyStmt);
2169 newnode->relname = pstrdup(from->relname);
2175 _copyListenStmt(ListenStmt *from)
2177 ListenStmt *newnode = makeNode(ListenStmt);
2180 newnode->relname = pstrdup(from->relname);
2185 static UnlistenStmt *
2186 _copyUnlistenStmt(UnlistenStmt *from)
2188 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2191 newnode->relname = pstrdup(from->relname);
2196 static TransactionStmt *
2197 _copyTransactionStmt(TransactionStmt *from)
2199 TransactionStmt *newnode = makeNode(TransactionStmt);
2201 newnode->command = from->command;
2207 _copyViewStmt(ViewStmt *from)
2209 ViewStmt *newnode = makeNode(ViewStmt);
2212 newnode->viewname = pstrdup(from->viewname);
2213 Node_Copy(from, newnode, aliases);
2214 Node_Copy(from, newnode, query);
2220 _copyLoadStmt(LoadStmt *from)
2222 LoadStmt *newnode = makeNode(LoadStmt);
2225 newnode->filename = pstrdup(from->filename);
2230 static CreatedbStmt *
2231 _copyCreatedbStmt(CreatedbStmt *from)
2233 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2236 newnode->dbname = pstrdup(from->dbname);
2238 newnode->dbowner = pstrdup(from->dbowner);
2240 newnode->dbpath = pstrdup(from->dbpath);
2241 if (from->dbtemplate)
2242 newnode->dbtemplate = pstrdup(from->dbtemplate);
2243 newnode->encoding = from->encoding;
2248 static AlterDatabaseSetStmt *
2249 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2251 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2254 newnode->dbname = pstrdup(from->dbname);
2256 newnode->variable = pstrdup(from->variable);
2257 Node_Copy(from, newnode, value);
2263 _copyDropdbStmt(DropdbStmt *from)
2265 DropdbStmt *newnode = makeNode(DropdbStmt);
2268 newnode->dbname = pstrdup(from->dbname);
2274 _copyVacuumStmt(VacuumStmt *from)
2276 VacuumStmt *newnode = makeNode(VacuumStmt);
2278 newnode->vacuum = from->vacuum;
2279 newnode->full = from->full;
2280 newnode->analyze = from->analyze;
2281 newnode->freeze = from->freeze;
2282 newnode->verbose = from->verbose;
2284 newnode->vacrel = pstrdup(from->vacrel);
2285 Node_Copy(from, newnode, va_cols);
2290 static ExplainStmt *
2291 _copyExplainStmt(ExplainStmt *from)
2293 ExplainStmt *newnode = makeNode(ExplainStmt);
2295 Node_Copy(from, newnode, query);
2296 newnode->verbose = from->verbose;
2297 newnode->analyze = from->analyze;
2302 static CreateSeqStmt *
2303 _copyCreateSeqStmt(CreateSeqStmt *from)
2305 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2308 newnode->seqname = pstrdup(from->seqname);
2309 Node_Copy(from, newnode, options);
2314 static VariableSetStmt *
2315 _copyVariableSetStmt(VariableSetStmt *from)
2317 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2320 newnode->name = pstrdup(from->name);
2321 Node_Copy(from, newnode, args);
2326 static VariableShowStmt *
2327 _copyVariableShowStmt(VariableShowStmt *from)
2329 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2332 newnode->name = pstrdup(from->name);
2337 static VariableResetStmt *
2338 _copyVariableResetStmt(VariableResetStmt *from)
2340 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2343 newnode->name = pstrdup(from->name);
2348 static CreateTrigStmt *
2349 _copyCreateTrigStmt(CreateTrigStmt *from)
2351 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2354 newnode->trigname = pstrdup(from->trigname);
2356 newnode->relname = pstrdup(from->relname);
2358 newnode->funcname = pstrdup(from->funcname);
2359 Node_Copy(from, newnode, args);
2360 newnode->before = from->before;
2361 newnode->row = from->row;
2362 memcpy(newnode->actions, from->actions, sizeof(from->actions));
2364 newnode->lang = pstrdup(from->lang);
2366 newnode->text = pstrdup(from->text);
2368 Node_Copy(from, newnode, attr);
2370 newnode->when = pstrdup(from->when);
2371 newnode->isconstraint = from->isconstraint;
2372 newnode->deferrable = from->deferrable;
2373 newnode->initdeferred = from->initdeferred;
2374 if (from->constrrelname)
2375 newnode->constrrelname = pstrdup(from->constrrelname);
2380 static DropTrigStmt *
2381 _copyDropTrigStmt(DropTrigStmt *from)
2383 DropTrigStmt *newnode = makeNode(DropTrigStmt);
2386 newnode->trigname = pstrdup(from->trigname);
2388 newnode->relname = pstrdup(from->relname);
2393 static CreatePLangStmt *
2394 _copyCreatePLangStmt(CreatePLangStmt *from)
2396 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2399 newnode->plname = pstrdup(from->plname);
2400 if (from->plhandler)
2401 newnode->plhandler = pstrdup(from->plhandler);
2402 if (from->plcompiler)
2403 newnode->plcompiler = pstrdup(from->plcompiler);
2404 newnode->pltrusted = from->pltrusted;
2409 static DropPLangStmt *
2410 _copyDropPLangStmt(DropPLangStmt *from)
2412 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2415 newnode->plname = pstrdup(from->plname);
2420 static CreateUserStmt *
2421 _copyCreateUserStmt(CreateUserStmt *from)
2423 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2426 newnode->user = pstrdup(from->user);
2427 Node_Copy(from, newnode, options);
2432 static AlterUserStmt *
2433 _copyAlterUserStmt(AlterUserStmt *from)
2435 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2438 newnode->user = pstrdup(from->user);
2439 Node_Copy(from, newnode, options);
2444 static AlterUserSetStmt *
2445 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2447 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2450 newnode->user = pstrdup(from->user);
2452 newnode->user = pstrdup(from->variable);
2453 Node_Copy(from, newnode, value);
2458 static DropUserStmt *
2459 _copyDropUserStmt(DropUserStmt *from)
2461 DropUserStmt *newnode = makeNode(DropUserStmt);
2463 Node_Copy(from, newnode, users);
2469 _copyLockStmt(LockStmt *from)
2471 LockStmt *newnode = makeNode(LockStmt);
2473 Node_Copy(from, newnode, rellist);
2475 newnode->mode = from->mode;
2480 static ConstraintsSetStmt *
2481 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2483 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2485 Node_Copy(from, newnode, constraints);
2486 newnode->deferred = from->deferred;
2491 static CreateGroupStmt *
2492 _copyCreateGroupStmt(CreateGroupStmt *from)
2494 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2497 newnode->name = pstrdup(from->name);
2498 Node_Copy(from, newnode, options);
2503 static AlterGroupStmt *
2504 _copyAlterGroupStmt(AlterGroupStmt *from)
2506 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2509 newnode->name = pstrdup(from->name);
2510 newnode->action = from->action;
2511 Node_Copy(from, newnode, listUsers);
2516 static DropGroupStmt *
2517 _copyDropGroupStmt(DropGroupStmt *from)
2519 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2522 newnode->name = pstrdup(from->name);
2527 static ReindexStmt *
2528 _copyReindexStmt(ReindexStmt *from)
2530 ReindexStmt *newnode = makeNode(ReindexStmt);
2532 newnode->reindexType = from->reindexType;
2534 newnode->name = pstrdup(from->name);
2535 newnode->force = from->force;
2536 newnode->all = from->all;
2542 /* ****************************************************************
2543 * pg_list.h copy functions
2544 * ****************************************************************
2548 _copyValue(Value *from)
2550 Value *newnode = makeNode(Value);
2552 newnode->type = from->type;
2556 newnode->val.ival = from->val.ival;
2561 newnode->val.str = pstrdup(from->val.str);
2570 * copyObject returns a copy of the node or list. If it is a list, it
2571 * recursively copies its items.
2575 copyObject(void *from)
2582 switch (nodeTag(from))
2588 retval = _copyPlan(from);
2591 retval = _copyResult(from);
2594 retval = _copyAppend(from);
2597 retval = _copyScan(from);
2600 retval = _copySeqScan(from);
2603 retval = _copyIndexScan(from);
2606 retval = _copyTidScan(from);
2608 case T_SubqueryScan:
2609 retval = _copySubqueryScan(from);
2612 retval = _copyJoin(from);
2615 retval = _copyNestLoop(from);
2618 retval = _copyMergeJoin(from);
2621 retval = _copyHashJoin(from);
2624 retval = _copyMaterial(from);
2627 retval = _copySort(from);
2630 retval = _copyGroup(from);
2633 retval = _copyAgg(from);
2636 retval = _copyUnique(from);
2639 retval = _copySetOp(from);
2642 retval = _copyLimit(from);
2645 retval = _copyHash(from);
2648 retval = _copySubPlan(from);
2655 retval = _copyResdom(from);
2658 retval = _copyFjoin(from);
2661 retval = _copyExpr(from);
2664 retval = _copyVar(from);
2667 retval = _copyOper(from);
2670 retval = _copyConst(from);
2673 retval = _copyParam(from);
2676 retval = _copyAggref(from);
2679 retval = _copySubLink(from);
2682 retval = _copyFunc(from);
2685 retval = _copyArrayRef(from);
2688 retval = _copyIter(from);
2691 retval = _copyFieldSelect(from);
2694 retval = _copyRelabelType(from);
2697 retval = _copyRangeTblRef(from);
2700 retval = _copyFromExpr(from);
2703 retval = _copyJoinExpr(from);
2710 retval = _copyRelOptInfo(from);
2713 retval = _copyPath(from);
2716 retval = _copyIndexPath(from);
2719 retval = _copyTidPath(from);
2722 retval = _copyAppendPath(from);
2725 retval = _copyNestPath(from);
2728 retval = _copyMergePath(from);
2731 retval = _copyHashPath(from);
2734 retval = _copyPathKeyItem(from);
2736 case T_RestrictInfo:
2737 retval = _copyRestrictInfo(from);
2740 retval = _copyJoinInfo(from);
2743 retval = _copyStream(from);
2745 case T_IndexOptInfo:
2746 retval = _copyIndexOptInfo(from);
2756 retval = _copyValue(from);
2764 /* rather ugly coding for speed... */
2765 /* Note the input list cannot be NIL if we got here. */
2766 nl = makeList1(copyObject(lfirst(list)));
2769 foreach(l, lnext(list))
2771 lnext(nl) = makeList1(copyObject(lfirst(l)));
2781 retval = _copyQuery(from);
2784 retval = _copyInsertStmt(from);
2787 retval = _copyDeleteStmt(from);
2790 retval = _copyUpdateStmt(from);
2793 retval = _copySelectStmt(from);
2795 case T_SetOperationStmt:
2796 retval = _copySetOperationStmt(from);
2798 case T_AlterTableStmt:
2799 retval = _copyAlterTableStmt(from);
2802 retval = _copyGrantStmt(from);
2804 case T_ClosePortalStmt:
2805 retval = _copyClosePortalStmt(from);
2808 retval = _copyClusterStmt(from);
2811 retval = _copyCopyStmt(from);
2814 retval = _copyCreateStmt(from);
2817 retval = _copyVersionStmt(from);
2820 retval = _copyDefineStmt(from);
2823 retval = _copyDropStmt(from);
2825 case T_TruncateStmt:
2826 retval = _copyTruncateStmt(from);
2829 retval = _copyCommentStmt(from);
2832 retval = _copyFetchStmt(from);
2835 retval = _copyIndexStmt(from);
2837 case T_ProcedureStmt:
2838 retval = _copyProcedureStmt(from);
2840 case T_RemoveAggrStmt:
2841 retval = _copyRemoveAggrStmt(from);
2843 case T_RemoveFuncStmt:
2844 retval = _copyRemoveFuncStmt(from);
2846 case T_RemoveOperStmt:
2847 retval = _copyRemoveOperStmt(from);
2850 retval = _copyRenameStmt(from);
2853 retval = _copyRuleStmt(from);
2856 retval = _copyNotifyStmt(from);
2859 retval = _copyListenStmt(from);
2861 case T_UnlistenStmt:
2862 retval = _copyUnlistenStmt(from);
2864 case T_TransactionStmt:
2865 retval = _copyTransactionStmt(from);
2868 retval = _copyViewStmt(from);
2871 retval = _copyLoadStmt(from);
2873 case T_CreatedbStmt:
2874 retval = _copyCreatedbStmt(from);
2876 case T_AlterDatabaseSetStmt:
2877 retval = _copyAlterDatabaseSetStmt(from);
2880 retval = _copyDropdbStmt(from);
2883 retval = _copyVacuumStmt(from);
2886 retval = _copyExplainStmt(from);
2888 case T_CreateSeqStmt:
2889 retval = _copyCreateSeqStmt(from);
2891 case T_VariableSetStmt:
2892 retval = _copyVariableSetStmt(from);
2894 case T_VariableShowStmt:
2895 retval = _copyVariableShowStmt(from);
2897 case T_VariableResetStmt:
2898 retval = _copyVariableResetStmt(from);
2900 case T_CreateTrigStmt:
2901 retval = _copyCreateTrigStmt(from);
2903 case T_DropTrigStmt:
2904 retval = _copyDropTrigStmt(from);
2906 case T_CreatePLangStmt:
2907 retval = _copyCreatePLangStmt(from);
2909 case T_DropPLangStmt:
2910 retval = _copyDropPLangStmt(from);
2912 case T_CreateUserStmt:
2913 retval = _copyCreateUserStmt(from);
2915 case T_AlterUserStmt:
2916 retval = _copyAlterUserStmt(from);
2918 case T_AlterUserSetStmt:
2919 retval = _copyAlterUserSetStmt(from);
2921 case T_DropUserStmt:
2922 retval = _copyDropUserStmt(from);
2925 retval = _copyLockStmt(from);
2927 case T_ConstraintsSetStmt:
2928 retval = _copyConstraintsSetStmt(from);
2930 case T_CreateGroupStmt:
2931 retval = _copyCreateGroupStmt(from);
2933 case T_AlterGroupStmt:
2934 retval = _copyAlterGroupStmt(from);
2936 case T_DropGroupStmt:
2937 retval = _copyDropGroupStmt(from);
2940 retval = _copyReindexStmt(from);
2942 case T_CheckPointStmt:
2943 retval = (void *) makeNode(CheckPointStmt);
2947 retval = _copyAExpr(from);
2950 retval = _copyAttr(from);
2953 retval = _copyAConst(from);
2956 retval = _copyParamNo(from);
2959 retval = _copyIdent(from);
2962 retval = _copyFuncCall(from);
2965 retval = _copyAIndices(from);
2968 retval = _copyResTarget(from);
2971 retval = _copyTypeCast(from);
2974 retval = _copySortGroupBy(from);
2977 retval = _copyRangeVar(from);
2979 case T_RangeSubselect:
2980 retval = _copyRangeSubselect(from);
2983 retval = _copyTypeName(from);
2986 retval = _copyIndexElem(from);
2989 retval = _copyColumnDef(from);
2992 retval = _copyConstraint(from);
2995 retval = _copyDefElem(from);
2998 retval = _copyTargetEntry(from);
3000 case T_RangeTblEntry:
3001 retval = _copyRangeTblEntry(from);
3004 retval = _copySortClause(from);
3007 retval = _copyGroupClause(from);
3010 retval = _copyCaseExpr(from);
3013 retval = _copyCaseWhen(from);
3016 retval = _copyNullTest(from);
3019 retval = _copyBooleanTest(from);
3021 case T_FkConstraint:
3022 retval = _copyFkConstraint(from);
3025 retval = _copyPrivGrantee(from);
3027 case T_FuncWithArgs:
3028 retval = _copyFuncWithArgs(from);
3032 elog(ERROR, "copyObject: don't know how to copy node type %d",
3034 retval = from; /* keep compiler quiet */