1 /*-------------------------------------------------------------------------
4 * Copy functions for Postgres tree nodes.
6 * NOTE: we currently support copying all node types found in parse and
7 * plan trees. We do not support copying executor state trees; there
8 * is no need for that, and no point in maintaining all the code that
9 * would be needed. We also do not support copying Path trees, mainly
10 * because the circular linkages between RelOptInfo and Path nodes can't
11 * be handled easily in a simple depth-first traversal.
14 * Portions Copyright (c) 1996-2002, 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.254 2003/06/25 03:40:17 momjian Exp $
20 *-------------------------------------------------------------------------
25 #include "nodes/parsenodes.h"
26 #include "nodes/plannodes.h"
27 #include "nodes/relation.h"
28 #include "utils/datum.h"
32 * Macros to simplify copying of different kinds of fields. Use these
33 * wherever possible to reduce the chance for silly typos. Note that these
34 * hard-wire the convention that the local variables in a Copy routine are
35 * named 'newnode' and 'from'.
38 /* Copy a simple scalar field (int, float, bool, enum, etc) */
39 #define COPY_SCALAR_FIELD(fldname) \
40 (newnode->fldname = from->fldname)
42 /* Copy a field that is a pointer to some kind of Node or Node tree */
43 #define COPY_NODE_FIELD(fldname) \
44 (newnode->fldname = copyObject(from->fldname))
46 /* Copy a field that is a pointer to a list of integers */
47 #define COPY_INTLIST_FIELD(fldname) \
48 (newnode->fldname = listCopy(from->fldname))
50 /* Copy a field that is a pointer to a list of Oids */
51 #define COPY_OIDLIST_FIELD(fldname) \
52 (newnode->fldname = listCopy(from->fldname))
54 /* Copy a field that is a pointer to a Bitmapset */
55 #define COPY_BITMAPSET_FIELD(fldname) \
56 (newnode->fldname = bms_copy(from->fldname))
58 /* Copy a field that is a pointer to a C string, or perhaps NULL */
59 #define COPY_STRING_FIELD(fldname) \
60 (newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)
62 /* Copy a field that is a pointer to a simple palloc'd object of size sz */
63 #define COPY_POINTER_FIELD(fldname, sz) \
66 newnode->fldname = palloc(_size); \
67 memcpy(newnode->fldname, from->fldname, _size); \
73 * This copy function only copies the "cons-cells" of the list, not the
74 * pointed-to objects. (Use copyObject if you want a "deep" copy.)
76 * We also use this function for copying lists of integers and Oids,
77 * which is notationally a bit ugly, but perfectly safe.
79 * Note that copyObject will surely coredump if applied to a list
80 * of integers or Oids!
90 /* rather ugly coding for speed... */
94 newcell = makeNode(List);
95 newcell->elem = list->elem;
97 newlist = prev = newcell;
99 foreach(oldl, lnext(list))
101 newcell = makeNode(List);
102 newcell->elem = oldl->elem;
103 prev->next = newcell;
111 /* ****************************************************************
112 * plannodes.h copy functions
113 * ****************************************************************
119 * This function copies the fields of the Plan node. It is used by
120 * all the copy functions for classes which inherit from Plan.
123 CopyPlanFields(Plan *from, Plan *newnode)
125 COPY_SCALAR_FIELD(startup_cost);
126 COPY_SCALAR_FIELD(total_cost);
127 COPY_SCALAR_FIELD(plan_rows);
128 COPY_SCALAR_FIELD(plan_width);
129 COPY_NODE_FIELD(targetlist);
130 COPY_NODE_FIELD(qual);
131 COPY_NODE_FIELD(lefttree);
132 COPY_NODE_FIELD(righttree);
133 COPY_NODE_FIELD(initPlan);
134 COPY_BITMAPSET_FIELD(extParam);
135 COPY_BITMAPSET_FIELD(allParam);
136 COPY_SCALAR_FIELD(nParamExec);
143 _copyPlan(Plan *from)
145 Plan *newnode = makeNode(Plan);
148 * copy node superclass fields
150 CopyPlanFields(from, newnode);
160 _copyResult(Result *from)
162 Result *newnode = makeNode(Result);
165 * copy node superclass fields
167 CopyPlanFields((Plan *) from, (Plan *) newnode);
170 * copy remainder of node
172 COPY_NODE_FIELD(resconstantqual);
181 _copyAppend(Append *from)
183 Append *newnode = makeNode(Append);
186 * copy node superclass fields
188 CopyPlanFields((Plan *) from, (Plan *) newnode);
191 * copy remainder of node
193 COPY_NODE_FIELD(appendplans);
194 COPY_SCALAR_FIELD(isTarget);
203 * This function copies the fields of the Scan node. It is used by
204 * all the copy functions for classes which inherit from Scan.
207 CopyScanFields(Scan *from, Scan *newnode)
209 CopyPlanFields((Plan *) from, (Plan *) newnode);
211 COPY_SCALAR_FIELD(scanrelid);
218 _copyScan(Scan *from)
220 Scan *newnode = makeNode(Scan);
223 * copy node superclass fields
225 CopyScanFields((Scan *) from, (Scan *) newnode);
234 _copySeqScan(SeqScan *from)
236 SeqScan *newnode = makeNode(SeqScan);
239 * copy node superclass fields
241 CopyScanFields((Scan *) from, (Scan *) newnode);
250 _copyIndexScan(IndexScan *from)
252 IndexScan *newnode = makeNode(IndexScan);
255 * copy node superclass fields
257 CopyScanFields((Scan *) from, (Scan *) newnode);
260 * copy remainder of node
262 COPY_OIDLIST_FIELD(indxid);
263 COPY_NODE_FIELD(indxqual);
264 COPY_NODE_FIELD(indxqualorig);
265 COPY_SCALAR_FIELD(indxorderdir);
274 _copyTidScan(TidScan *from)
276 TidScan *newnode = makeNode(TidScan);
279 * copy node superclass fields
281 CopyScanFields((Scan *) from, (Scan *) newnode);
284 * copy remainder of node
286 COPY_NODE_FIELD(tideval);
294 static SubqueryScan *
295 _copySubqueryScan(SubqueryScan *from)
297 SubqueryScan *newnode = makeNode(SubqueryScan);
300 * copy node superclass fields
302 CopyScanFields((Scan *) from, (Scan *) newnode);
305 * copy remainder of node
307 COPY_NODE_FIELD(subplan);
315 static FunctionScan *
316 _copyFunctionScan(FunctionScan *from)
318 FunctionScan *newnode = makeNode(FunctionScan);
321 * copy node superclass fields
323 CopyScanFields((Scan *) from, (Scan *) newnode);
331 * This function copies the fields of the Join node. It is used by
332 * all the copy functions for classes which inherit from Join.
335 CopyJoinFields(Join *from, Join *newnode)
337 CopyPlanFields((Plan *) from, (Plan *) newnode);
339 COPY_SCALAR_FIELD(jointype);
340 COPY_NODE_FIELD(joinqual);
348 _copyJoin(Join *from)
350 Join *newnode = makeNode(Join);
353 * copy node superclass fields
355 CopyJoinFields(from, newnode);
365 _copyNestLoop(NestLoop *from)
367 NestLoop *newnode = makeNode(NestLoop);
370 * copy node superclass fields
372 CopyJoinFields((Join *) from, (Join *) newnode);
382 _copyMergeJoin(MergeJoin *from)
384 MergeJoin *newnode = makeNode(MergeJoin);
387 * copy node superclass fields
389 CopyJoinFields((Join *) from, (Join *) newnode);
392 * copy remainder of node
394 COPY_NODE_FIELD(mergeclauses);
403 _copyHashJoin(HashJoin *from)
405 HashJoin *newnode = makeNode(HashJoin);
408 * copy node superclass fields
410 CopyJoinFields((Join *) from, (Join *) newnode);
413 * copy remainder of node
415 COPY_NODE_FIELD(hashclauses);
425 _copyMaterial(Material *from)
427 Material *newnode = makeNode(Material);
430 * copy node superclass fields
432 CopyPlanFields((Plan *) from, (Plan *) newnode);
442 _copySort(Sort *from)
444 Sort *newnode = makeNode(Sort);
447 * copy node superclass fields
449 CopyPlanFields((Plan *) from, (Plan *) newnode);
451 COPY_SCALAR_FIELD(numCols);
452 COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
453 COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
463 _copyGroup(Group *from)
465 Group *newnode = makeNode(Group);
467 CopyPlanFields((Plan *) from, (Plan *) newnode);
469 COPY_SCALAR_FIELD(numCols);
470 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
481 Agg *newnode = makeNode(Agg);
483 CopyPlanFields((Plan *) from, (Plan *) newnode);
485 COPY_SCALAR_FIELD(aggstrategy);
486 COPY_SCALAR_FIELD(numCols);
487 if (from->numCols > 0)
488 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
489 COPY_SCALAR_FIELD(numGroups);
498 _copyUnique(Unique *from)
500 Unique *newnode = makeNode(Unique);
503 * copy node superclass fields
505 CopyPlanFields((Plan *) from, (Plan *) newnode);
508 * copy remainder of node
510 COPY_SCALAR_FIELD(numCols);
511 COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
520 _copyHash(Hash *from)
522 Hash *newnode = makeNode(Hash);
525 * copy node superclass fields
527 CopyPlanFields((Plan *) from, (Plan *) newnode);
530 * copy remainder of node
532 COPY_NODE_FIELD(hashkeys);
541 _copySetOp(SetOp *from)
543 SetOp *newnode = makeNode(SetOp);
546 * copy node superclass fields
548 CopyPlanFields((Plan *) from, (Plan *) newnode);
551 * copy remainder of node
553 COPY_SCALAR_FIELD(cmd);
554 COPY_SCALAR_FIELD(numCols);
555 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
556 COPY_SCALAR_FIELD(flagColIdx);
565 _copyLimit(Limit *from)
567 Limit *newnode = makeNode(Limit);
570 * copy node superclass fields
572 CopyPlanFields((Plan *) from, (Plan *) newnode);
575 * copy remainder of node
577 COPY_NODE_FIELD(limitOffset);
578 COPY_NODE_FIELD(limitCount);
583 /* ****************************************************************
584 * primnodes.h copy functions
585 * ****************************************************************
592 _copyResdom(Resdom *from)
594 Resdom *newnode = makeNode(Resdom);
596 COPY_SCALAR_FIELD(resno);
597 COPY_SCALAR_FIELD(restype);
598 COPY_SCALAR_FIELD(restypmod);
599 COPY_STRING_FIELD(resname);
600 COPY_SCALAR_FIELD(ressortgroupref);
601 COPY_SCALAR_FIELD(resorigtbl);
602 COPY_SCALAR_FIELD(resorigcol);
603 COPY_SCALAR_FIELD(resjunk);
612 _copyAlias(Alias *from)
614 Alias *newnode = makeNode(Alias);
616 COPY_STRING_FIELD(aliasname);
617 COPY_NODE_FIELD(colnames);
626 _copyRangeVar(RangeVar *from)
628 RangeVar *newnode = makeNode(RangeVar);
630 COPY_STRING_FIELD(catalogname);
631 COPY_STRING_FIELD(schemaname);
632 COPY_STRING_FIELD(relname);
633 COPY_SCALAR_FIELD(inhOpt);
634 COPY_SCALAR_FIELD(istemp);
635 COPY_NODE_FIELD(alias);
641 * We don't need a _copyExpr because Expr is an abstract supertype which
642 * should never actually get instantiated. Also, since it has no common
643 * fields except NodeTag, there's no need for a helper routine to factor
644 * out copying the common fields...
653 Var *newnode = makeNode(Var);
655 COPY_SCALAR_FIELD(varno);
656 COPY_SCALAR_FIELD(varattno);
657 COPY_SCALAR_FIELD(vartype);
658 COPY_SCALAR_FIELD(vartypmod);
659 COPY_SCALAR_FIELD(varlevelsup);
660 COPY_SCALAR_FIELD(varnoold);
661 COPY_SCALAR_FIELD(varoattno);
670 _copyConst(Const *from)
672 Const *newnode = makeNode(Const);
674 COPY_SCALAR_FIELD(consttype);
675 COPY_SCALAR_FIELD(constlen);
677 if (from->constbyval || from->constisnull)
680 * passed by value so just copy the datum. Also, don't try to copy
681 * struct when value is null!
683 newnode->constvalue = from->constvalue;
688 * passed by reference. We need a palloc'd copy.
690 newnode->constvalue = datumCopy(from->constvalue,
695 COPY_SCALAR_FIELD(constisnull);
696 COPY_SCALAR_FIELD(constbyval);
705 _copyParam(Param *from)
707 Param *newnode = makeNode(Param);
709 COPY_SCALAR_FIELD(paramkind);
710 COPY_SCALAR_FIELD(paramid);
711 COPY_STRING_FIELD(paramname);
712 COPY_SCALAR_FIELD(paramtype);
721 _copyAggref(Aggref *from)
723 Aggref *newnode = makeNode(Aggref);
725 COPY_SCALAR_FIELD(aggfnoid);
726 COPY_SCALAR_FIELD(aggtype);
727 COPY_NODE_FIELD(target);
728 COPY_SCALAR_FIELD(agglevelsup);
729 COPY_SCALAR_FIELD(aggstar);
730 COPY_SCALAR_FIELD(aggdistinct);
731 COPY_NODE_FIELD(args);
740 _copyArrayRef(ArrayRef *from)
742 ArrayRef *newnode = makeNode(ArrayRef);
744 COPY_SCALAR_FIELD(refrestype);
745 COPY_SCALAR_FIELD(refarraytype);
746 COPY_SCALAR_FIELD(refelemtype);
747 COPY_NODE_FIELD(refupperindexpr);
748 COPY_NODE_FIELD(reflowerindexpr);
749 COPY_NODE_FIELD(refexpr);
750 COPY_NODE_FIELD(refassgnexpr);
759 _copyFuncExpr(FuncExpr *from)
761 FuncExpr *newnode = makeNode(FuncExpr);
763 COPY_SCALAR_FIELD(funcid);
764 COPY_SCALAR_FIELD(funcresulttype);
765 COPY_SCALAR_FIELD(funcretset);
766 COPY_SCALAR_FIELD(funcformat);
767 COPY_NODE_FIELD(args);
776 _copyOpExpr(OpExpr *from)
778 OpExpr *newnode = makeNode(OpExpr);
780 COPY_SCALAR_FIELD(opno);
781 COPY_SCALAR_FIELD(opfuncid);
782 COPY_SCALAR_FIELD(opresulttype);
783 COPY_SCALAR_FIELD(opretset);
784 COPY_NODE_FIELD(args);
790 * _copyDistinctExpr (same as OpExpr)
792 static DistinctExpr *
793 _copyDistinctExpr(DistinctExpr *from)
795 DistinctExpr *newnode = makeNode(DistinctExpr);
797 COPY_SCALAR_FIELD(opno);
798 COPY_SCALAR_FIELD(opfuncid);
799 COPY_SCALAR_FIELD(opresulttype);
800 COPY_SCALAR_FIELD(opretset);
801 COPY_NODE_FIELD(args);
810 _copyBoolExpr(BoolExpr *from)
812 BoolExpr *newnode = makeNode(BoolExpr);
814 COPY_SCALAR_FIELD(boolop);
815 COPY_NODE_FIELD(args);
824 _copySubLink(SubLink *from)
826 SubLink *newnode = makeNode(SubLink);
828 COPY_SCALAR_FIELD(subLinkType);
829 COPY_SCALAR_FIELD(useOr);
830 COPY_SCALAR_FIELD(isExpr);
831 COPY_NODE_FIELD(lefthand);
832 COPY_NODE_FIELD(operName);
833 COPY_OIDLIST_FIELD(operOids);
834 COPY_NODE_FIELD(subselect);
843 _copySubPlan(SubPlan *from)
845 SubPlan *newnode = makeNode(SubPlan);
847 COPY_SCALAR_FIELD(subLinkType);
848 COPY_SCALAR_FIELD(useOr);
849 COPY_SCALAR_FIELD(isExpr);
850 COPY_SCALAR_FIELD(exprtype);
851 COPY_SCALAR_FIELD(elemtype);
852 COPY_SCALAR_FIELD(elmlen);
853 COPY_SCALAR_FIELD(elmbyval);
854 COPY_SCALAR_FIELD(elmalign);
855 COPY_NODE_FIELD(exprs);
856 COPY_INTLIST_FIELD(paramIds);
857 COPY_NODE_FIELD(plan);
858 COPY_SCALAR_FIELD(plan_id);
859 COPY_NODE_FIELD(rtable);
860 COPY_SCALAR_FIELD(useHashTable);
861 COPY_SCALAR_FIELD(unknownEqFalse);
862 COPY_INTLIST_FIELD(setParam);
863 COPY_INTLIST_FIELD(parParam);
864 COPY_NODE_FIELD(args);
873 _copyFieldSelect(FieldSelect *from)
875 FieldSelect *newnode = makeNode(FieldSelect);
877 COPY_NODE_FIELD(arg);
878 COPY_SCALAR_FIELD(fieldnum);
879 COPY_SCALAR_FIELD(resulttype);
880 COPY_SCALAR_FIELD(resulttypmod);
889 _copyRelabelType(RelabelType *from)
891 RelabelType *newnode = makeNode(RelabelType);
893 COPY_NODE_FIELD(arg);
894 COPY_SCALAR_FIELD(resulttype);
895 COPY_SCALAR_FIELD(resulttypmod);
896 COPY_SCALAR_FIELD(relabelformat);
905 _copyCaseExpr(CaseExpr *from)
907 CaseExpr *newnode = makeNode(CaseExpr);
909 COPY_SCALAR_FIELD(casetype);
910 COPY_NODE_FIELD(arg);
911 COPY_NODE_FIELD(args);
912 COPY_NODE_FIELD(defresult);
921 _copyCaseWhen(CaseWhen *from)
923 CaseWhen *newnode = makeNode(CaseWhen);
925 COPY_NODE_FIELD(expr);
926 COPY_NODE_FIELD(result);
935 _copyArrayExpr(ArrayExpr *from)
937 ArrayExpr *newnode = makeNode(ArrayExpr);
939 COPY_SCALAR_FIELD(array_typeid);
940 COPY_SCALAR_FIELD(element_typeid);
941 COPY_NODE_FIELD(elements);
942 COPY_SCALAR_FIELD(ndims);
950 static CoalesceExpr *
951 _copyCoalesceExpr(CoalesceExpr *from)
953 CoalesceExpr *newnode = makeNode(CoalesceExpr);
955 COPY_SCALAR_FIELD(coalescetype);
956 COPY_NODE_FIELD(args);
962 * _copyNullIfExpr (same as OpExpr)
965 _copyNullIfExpr(NullIfExpr *from)
967 NullIfExpr *newnode = makeNode(NullIfExpr);
969 COPY_SCALAR_FIELD(opno);
970 COPY_SCALAR_FIELD(opfuncid);
971 COPY_SCALAR_FIELD(opresulttype);
972 COPY_SCALAR_FIELD(opretset);
973 COPY_NODE_FIELD(args);
982 _copyNullTest(NullTest *from)
984 NullTest *newnode = makeNode(NullTest);
986 COPY_NODE_FIELD(arg);
987 COPY_SCALAR_FIELD(nulltesttype);
996 _copyBooleanTest(BooleanTest *from)
998 BooleanTest *newnode = makeNode(BooleanTest);
1000 COPY_NODE_FIELD(arg);
1001 COPY_SCALAR_FIELD(booltesttype);
1007 * _copyCoerceToDomain
1009 static CoerceToDomain *
1010 _copyCoerceToDomain(CoerceToDomain *from)
1012 CoerceToDomain *newnode = makeNode(CoerceToDomain);
1014 COPY_NODE_FIELD(arg);
1015 COPY_SCALAR_FIELD(resulttype);
1016 COPY_SCALAR_FIELD(resulttypmod);
1017 COPY_SCALAR_FIELD(coercionformat);
1023 * _copyCoerceToDomainValue
1025 static CoerceToDomainValue *
1026 _copyCoerceToDomainValue(CoerceToDomainValue *from)
1028 CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1030 COPY_SCALAR_FIELD(typeId);
1031 COPY_SCALAR_FIELD(typeMod);
1039 static TargetEntry *
1040 _copyTargetEntry(TargetEntry *from)
1042 TargetEntry *newnode = makeNode(TargetEntry);
1044 COPY_NODE_FIELD(resdom);
1045 COPY_NODE_FIELD(expr);
1053 static RangeTblRef *
1054 _copyRangeTblRef(RangeTblRef *from)
1056 RangeTblRef *newnode = makeNode(RangeTblRef);
1058 COPY_SCALAR_FIELD(rtindex);
1067 _copyJoinExpr(JoinExpr *from)
1069 JoinExpr *newnode = makeNode(JoinExpr);
1071 COPY_SCALAR_FIELD(jointype);
1072 COPY_SCALAR_FIELD(isNatural);
1073 COPY_NODE_FIELD(larg);
1074 COPY_NODE_FIELD(rarg);
1075 COPY_NODE_FIELD(using);
1076 COPY_NODE_FIELD(quals);
1077 COPY_NODE_FIELD(alias);
1078 COPY_SCALAR_FIELD(rtindex);
1087 _copyFromExpr(FromExpr *from)
1089 FromExpr *newnode = makeNode(FromExpr);
1091 COPY_NODE_FIELD(fromlist);
1092 COPY_NODE_FIELD(quals);
1097 /* ****************************************************************
1098 * relation.h copy functions
1100 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1101 * There are some subsidiary structs that are useful to copy, though.
1102 * ****************************************************************
1108 static PathKeyItem *
1109 _copyPathKeyItem(PathKeyItem *from)
1111 PathKeyItem *newnode = makeNode(PathKeyItem);
1113 COPY_NODE_FIELD(key);
1114 COPY_SCALAR_FIELD(sortop);
1122 static RestrictInfo *
1123 _copyRestrictInfo(RestrictInfo *from)
1125 RestrictInfo *newnode = makeNode(RestrictInfo);
1127 COPY_NODE_FIELD(clause);
1128 COPY_SCALAR_FIELD(ispusheddown);
1129 COPY_NODE_FIELD(subclauseindices); /* XXX probably bad */
1130 COPY_SCALAR_FIELD(eval_cost);
1131 COPY_SCALAR_FIELD(this_selec);
1132 COPY_BITMAPSET_FIELD(left_relids);
1133 COPY_BITMAPSET_FIELD(right_relids);
1134 COPY_SCALAR_FIELD(mergejoinoperator);
1135 COPY_SCALAR_FIELD(left_sortop);
1136 COPY_SCALAR_FIELD(right_sortop);
1139 * Do not copy pathkeys, since they'd not be canonical in a copied
1142 newnode->left_pathkey = NIL;
1143 newnode->right_pathkey = NIL;
1145 COPY_SCALAR_FIELD(left_mergescansel);
1146 COPY_SCALAR_FIELD(right_mergescansel);
1147 COPY_SCALAR_FIELD(hashjoinoperator);
1148 COPY_SCALAR_FIELD(left_bucketsize);
1149 COPY_SCALAR_FIELD(right_bucketsize);
1158 _copyJoinInfo(JoinInfo *from)
1160 JoinInfo *newnode = makeNode(JoinInfo);
1162 COPY_BITMAPSET_FIELD(unjoined_relids);
1163 COPY_NODE_FIELD(jinfo_restrictinfo);
1171 static InClauseInfo *
1172 _copyInClauseInfo(InClauseInfo *from)
1174 InClauseInfo *newnode = makeNode(InClauseInfo);
1176 COPY_BITMAPSET_FIELD(lefthand);
1177 COPY_BITMAPSET_FIELD(righthand);
1178 COPY_NODE_FIELD(sub_targetlist);
1183 /* ****************************************************************
1184 * parsenodes.h copy functions
1185 * ****************************************************************
1188 static RangeTblEntry *
1189 _copyRangeTblEntry(RangeTblEntry *from)
1191 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1193 COPY_SCALAR_FIELD(rtekind);
1194 COPY_SCALAR_FIELD(relid);
1195 COPY_NODE_FIELD(subquery);
1196 COPY_NODE_FIELD(funcexpr);
1197 COPY_NODE_FIELD(coldeflist);
1198 COPY_SCALAR_FIELD(jointype);
1199 COPY_NODE_FIELD(joinaliasvars);
1200 COPY_NODE_FIELD(alias);
1201 COPY_NODE_FIELD(eref);
1202 COPY_SCALAR_FIELD(inh);
1203 COPY_SCALAR_FIELD(inFromCl);
1204 COPY_SCALAR_FIELD(checkForRead);
1205 COPY_SCALAR_FIELD(checkForWrite);
1206 COPY_SCALAR_FIELD(checkAsUser);
1211 static FkConstraint *
1212 _copyFkConstraint(FkConstraint *from)
1214 FkConstraint *newnode = makeNode(FkConstraint);
1216 COPY_STRING_FIELD(constr_name);
1217 COPY_NODE_FIELD(pktable);
1218 COPY_NODE_FIELD(fk_attrs);
1219 COPY_NODE_FIELD(pk_attrs);
1220 COPY_SCALAR_FIELD(fk_matchtype);
1221 COPY_SCALAR_FIELD(fk_upd_action);
1222 COPY_SCALAR_FIELD(fk_del_action);
1223 COPY_SCALAR_FIELD(deferrable);
1224 COPY_SCALAR_FIELD(initdeferred);
1225 COPY_SCALAR_FIELD(skip_validation);
1231 _copySortClause(SortClause *from)
1233 SortClause *newnode = makeNode(SortClause);
1235 COPY_SCALAR_FIELD(tleSortGroupRef);
1236 COPY_SCALAR_FIELD(sortop);
1241 static GroupClause *
1242 _copyGroupClause(GroupClause *from)
1244 GroupClause *newnode = makeNode(GroupClause);
1246 COPY_SCALAR_FIELD(tleSortGroupRef);
1247 COPY_SCALAR_FIELD(sortop);
1253 _copyAExpr(A_Expr *from)
1255 A_Expr *newnode = makeNode(A_Expr);
1257 COPY_SCALAR_FIELD(kind);
1258 COPY_NODE_FIELD(name);
1259 COPY_NODE_FIELD(lexpr);
1260 COPY_NODE_FIELD(rexpr);
1266 _copyColumnRef(ColumnRef *from)
1268 ColumnRef *newnode = makeNode(ColumnRef);
1270 COPY_NODE_FIELD(fields);
1271 COPY_NODE_FIELD(indirection);
1277 _copyParamRef(ParamRef *from)
1279 ParamRef *newnode = makeNode(ParamRef);
1281 COPY_SCALAR_FIELD(number);
1282 COPY_NODE_FIELD(fields);
1283 COPY_NODE_FIELD(indirection);
1289 _copyAConst(A_Const *from)
1291 A_Const *newnode = makeNode(A_Const);
1293 /* This part must duplicate _copyValue */
1294 COPY_SCALAR_FIELD(val.type);
1295 switch (from->val.type)
1298 COPY_SCALAR_FIELD(val.val.ival);
1303 COPY_STRING_FIELD(val.val.str);
1309 elog(ERROR, "_copyAConst: unknown node type %d", from->val.type);
1313 COPY_NODE_FIELD(typename);
1319 _copyFuncCall(FuncCall *from)
1321 FuncCall *newnode = makeNode(FuncCall);
1323 COPY_NODE_FIELD(funcname);
1324 COPY_NODE_FIELD(args);
1325 COPY_SCALAR_FIELD(agg_star);
1326 COPY_SCALAR_FIELD(agg_distinct);
1332 _copyAIndices(A_Indices *from)
1334 A_Indices *newnode = makeNode(A_Indices);
1336 COPY_NODE_FIELD(lidx);
1337 COPY_NODE_FIELD(uidx);
1342 static ExprFieldSelect *
1343 _copyExprFieldSelect(ExprFieldSelect *from)
1345 ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
1347 COPY_NODE_FIELD(arg);
1348 COPY_NODE_FIELD(fields);
1349 COPY_NODE_FIELD(indirection);
1355 _copyResTarget(ResTarget *from)
1357 ResTarget *newnode = makeNode(ResTarget);
1359 COPY_STRING_FIELD(name);
1360 COPY_NODE_FIELD(indirection);
1361 COPY_NODE_FIELD(val);
1367 _copyTypeName(TypeName *from)
1369 TypeName *newnode = makeNode(TypeName);
1371 COPY_NODE_FIELD(names);
1372 COPY_SCALAR_FIELD(typeid);
1373 COPY_SCALAR_FIELD(timezone);
1374 COPY_SCALAR_FIELD(setof);
1375 COPY_SCALAR_FIELD(pct_type);
1376 COPY_SCALAR_FIELD(typmod);
1377 COPY_NODE_FIELD(arrayBounds);
1382 static SortGroupBy *
1383 _copySortGroupBy(SortGroupBy *from)
1385 SortGroupBy *newnode = makeNode(SortGroupBy);
1387 COPY_NODE_FIELD(useOp);
1388 COPY_NODE_FIELD(node);
1393 static RangeSubselect *
1394 _copyRangeSubselect(RangeSubselect *from)
1396 RangeSubselect *newnode = makeNode(RangeSubselect);
1398 COPY_NODE_FIELD(subquery);
1399 COPY_NODE_FIELD(alias);
1404 static RangeFunction *
1405 _copyRangeFunction(RangeFunction *from)
1407 RangeFunction *newnode = makeNode(RangeFunction);
1409 COPY_NODE_FIELD(funccallnode);
1410 COPY_NODE_FIELD(alias);
1411 COPY_NODE_FIELD(coldeflist);
1417 _copyTypeCast(TypeCast *from)
1419 TypeCast *newnode = makeNode(TypeCast);
1421 COPY_NODE_FIELD(arg);
1422 COPY_NODE_FIELD(typename);
1428 _copyIndexElem(IndexElem *from)
1430 IndexElem *newnode = makeNode(IndexElem);
1432 COPY_STRING_FIELD(name);
1433 COPY_NODE_FIELD(expr);
1434 COPY_NODE_FIELD(opclass);
1440 _copyColumnDef(ColumnDef *from)
1442 ColumnDef *newnode = makeNode(ColumnDef);
1444 COPY_STRING_FIELD(colname);
1445 COPY_NODE_FIELD(typename);
1446 COPY_SCALAR_FIELD(inhcount);
1447 COPY_SCALAR_FIELD(is_local);
1448 COPY_SCALAR_FIELD(is_not_null);
1449 COPY_NODE_FIELD(raw_default);
1450 COPY_STRING_FIELD(cooked_default);
1451 COPY_NODE_FIELD(constraints);
1452 COPY_NODE_FIELD(support);
1458 _copyConstraint(Constraint *from)
1460 Constraint *newnode = makeNode(Constraint);
1462 COPY_SCALAR_FIELD(contype);
1463 COPY_STRING_FIELD(name);
1464 COPY_NODE_FIELD(raw_expr);
1465 COPY_STRING_FIELD(cooked_expr);
1466 COPY_NODE_FIELD(keys);
1472 _copyDefElem(DefElem *from)
1474 DefElem *newnode = makeNode(DefElem);
1476 COPY_STRING_FIELD(defname);
1477 COPY_NODE_FIELD(arg);
1483 _copyQuery(Query *from)
1485 Query *newnode = makeNode(Query);
1487 COPY_SCALAR_FIELD(commandType);
1488 COPY_SCALAR_FIELD(querySource);
1489 COPY_SCALAR_FIELD(canSetTag);
1490 COPY_NODE_FIELD(utilityStmt);
1491 COPY_SCALAR_FIELD(resultRelation);
1492 COPY_NODE_FIELD(into);
1493 COPY_SCALAR_FIELD(hasAggs);
1494 COPY_SCALAR_FIELD(hasSubLinks);
1495 COPY_NODE_FIELD(rtable);
1496 COPY_NODE_FIELD(jointree);
1497 COPY_INTLIST_FIELD(rowMarks);
1498 COPY_NODE_FIELD(targetList);
1499 COPY_NODE_FIELD(groupClause);
1500 COPY_NODE_FIELD(havingQual);
1501 COPY_NODE_FIELD(distinctClause);
1502 COPY_NODE_FIELD(sortClause);
1503 COPY_NODE_FIELD(limitOffset);
1504 COPY_NODE_FIELD(limitCount);
1505 COPY_NODE_FIELD(setOperations);
1506 COPY_INTLIST_FIELD(resultRelations);
1507 COPY_NODE_FIELD(in_info_list);
1508 COPY_SCALAR_FIELD(hasJoinRTEs);
1511 * We do not copy the other planner internal fields: base_rel_list,
1512 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys.
1513 * That would get us into copying RelOptInfo/Path trees, which we don't
1514 * want to do. It is necessary to copy in_info_list and hasJoinRTEs
1515 * for the benefit of inheritance_planner(), which may try to copy a
1516 * Query in which these are already set.
1523 _copyInsertStmt(InsertStmt *from)
1525 InsertStmt *newnode = makeNode(InsertStmt);
1527 COPY_NODE_FIELD(relation);
1528 COPY_NODE_FIELD(cols);
1529 COPY_NODE_FIELD(targetList);
1530 COPY_NODE_FIELD(selectStmt);
1536 _copyDeleteStmt(DeleteStmt *from)
1538 DeleteStmt *newnode = makeNode(DeleteStmt);
1540 COPY_NODE_FIELD(relation);
1541 COPY_NODE_FIELD(whereClause);
1547 _copyUpdateStmt(UpdateStmt *from)
1549 UpdateStmt *newnode = makeNode(UpdateStmt);
1551 COPY_NODE_FIELD(relation);
1552 COPY_NODE_FIELD(targetList);
1553 COPY_NODE_FIELD(whereClause);
1554 COPY_NODE_FIELD(fromClause);
1560 _copySelectStmt(SelectStmt *from)
1562 SelectStmt *newnode = makeNode(SelectStmt);
1564 COPY_NODE_FIELD(distinctClause);
1565 COPY_NODE_FIELD(into);
1566 COPY_NODE_FIELD(intoColNames);
1567 COPY_NODE_FIELD(targetList);
1568 COPY_NODE_FIELD(fromClause);
1569 COPY_NODE_FIELD(whereClause);
1570 COPY_NODE_FIELD(groupClause);
1571 COPY_NODE_FIELD(havingClause);
1572 COPY_NODE_FIELD(sortClause);
1573 COPY_NODE_FIELD(limitOffset);
1574 COPY_NODE_FIELD(limitCount);
1575 COPY_NODE_FIELD(forUpdate);
1576 COPY_SCALAR_FIELD(op);
1577 COPY_SCALAR_FIELD(all);
1578 COPY_NODE_FIELD(larg);
1579 COPY_NODE_FIELD(rarg);
1584 static SetOperationStmt *
1585 _copySetOperationStmt(SetOperationStmt *from)
1587 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1589 COPY_SCALAR_FIELD(op);
1590 COPY_SCALAR_FIELD(all);
1591 COPY_NODE_FIELD(larg);
1592 COPY_NODE_FIELD(rarg);
1593 COPY_OIDLIST_FIELD(colTypes);
1598 static AlterTableStmt *
1599 _copyAlterTableStmt(AlterTableStmt *from)
1601 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1603 COPY_SCALAR_FIELD(subtype);
1604 COPY_NODE_FIELD(relation);
1605 COPY_STRING_FIELD(name);
1606 COPY_NODE_FIELD(def);
1607 COPY_SCALAR_FIELD(behavior);
1612 static AlterDomainStmt *
1613 _copyAlterDomainStmt(AlterDomainStmt *from)
1615 AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1617 COPY_SCALAR_FIELD(subtype);
1618 COPY_NODE_FIELD(typename);
1619 COPY_STRING_FIELD(name);
1620 COPY_NODE_FIELD(def);
1621 COPY_SCALAR_FIELD(behavior);
1627 _copyGrantStmt(GrantStmt *from)
1629 GrantStmt *newnode = makeNode(GrantStmt);
1631 COPY_SCALAR_FIELD(is_grant);
1632 COPY_SCALAR_FIELD(objtype);
1633 COPY_NODE_FIELD(objects);
1634 COPY_INTLIST_FIELD(privileges);
1635 COPY_NODE_FIELD(grantees);
1636 COPY_SCALAR_FIELD(grant_option);
1637 COPY_SCALAR_FIELD(behavior);
1642 static PrivGrantee *
1643 _copyPrivGrantee(PrivGrantee *from)
1645 PrivGrantee *newnode = makeNode(PrivGrantee);
1647 COPY_STRING_FIELD(username);
1648 COPY_STRING_FIELD(groupname);
1653 static FuncWithArgs *
1654 _copyFuncWithArgs(FuncWithArgs *from)
1656 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1658 COPY_NODE_FIELD(funcname);
1659 COPY_NODE_FIELD(funcargs);
1664 static InsertDefault *
1665 _copyInsertDefault(InsertDefault *from)
1667 InsertDefault *newnode = makeNode(InsertDefault);
1672 static DeclareCursorStmt *
1673 _copyDeclareCursorStmt(DeclareCursorStmt *from)
1675 DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
1677 COPY_STRING_FIELD(portalname);
1678 COPY_SCALAR_FIELD(options);
1679 COPY_NODE_FIELD(query);
1684 static ClosePortalStmt *
1685 _copyClosePortalStmt(ClosePortalStmt *from)
1687 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1689 COPY_STRING_FIELD(portalname);
1694 static ClusterStmt *
1695 _copyClusterStmt(ClusterStmt *from)
1697 ClusterStmt *newnode = makeNode(ClusterStmt);
1699 COPY_NODE_FIELD(relation);
1700 COPY_STRING_FIELD(indexname);
1706 _copyCopyStmt(CopyStmt *from)
1708 CopyStmt *newnode = makeNode(CopyStmt);
1710 COPY_NODE_FIELD(relation);
1711 COPY_NODE_FIELD(attlist);
1712 COPY_SCALAR_FIELD(is_from);
1713 COPY_STRING_FIELD(filename);
1714 COPY_NODE_FIELD(options);
1720 _copyCreateStmt(CreateStmt *from)
1722 CreateStmt *newnode = makeNode(CreateStmt);
1724 COPY_NODE_FIELD(relation);
1725 COPY_NODE_FIELD(tableElts);
1726 COPY_NODE_FIELD(inhRelations);
1727 COPY_NODE_FIELD(constraints);
1728 COPY_SCALAR_FIELD(hasoids);
1729 COPY_SCALAR_FIELD(oncommit);
1734 static InhRelation *
1735 _copyInhRelation(InhRelation *from)
1737 InhRelation *newnode = makeNode(InhRelation);
1739 COPY_NODE_FIELD(relation);
1740 COPY_SCALAR_FIELD(including_defaults);
1746 _copyDefineStmt(DefineStmt *from)
1748 DefineStmt *newnode = makeNode(DefineStmt);
1750 COPY_SCALAR_FIELD(kind);
1751 COPY_NODE_FIELD(defnames);
1752 COPY_NODE_FIELD(definition);
1758 _copyDropStmt(DropStmt *from)
1760 DropStmt *newnode = makeNode(DropStmt);
1762 COPY_NODE_FIELD(objects);
1763 COPY_SCALAR_FIELD(removeType);
1764 COPY_SCALAR_FIELD(behavior);
1769 static TruncateStmt *
1770 _copyTruncateStmt(TruncateStmt *from)
1772 TruncateStmt *newnode = makeNode(TruncateStmt);
1774 COPY_NODE_FIELD(relation);
1779 static CommentStmt *
1780 _copyCommentStmt(CommentStmt *from)
1782 CommentStmt *newnode = makeNode(CommentStmt);
1784 COPY_SCALAR_FIELD(objtype);
1785 COPY_NODE_FIELD(objname);
1786 COPY_NODE_FIELD(objargs);
1787 COPY_STRING_FIELD(comment);
1793 _copyFetchStmt(FetchStmt *from)
1795 FetchStmt *newnode = makeNode(FetchStmt);
1797 COPY_SCALAR_FIELD(direction);
1798 COPY_SCALAR_FIELD(howMany);
1799 COPY_STRING_FIELD(portalname);
1800 COPY_SCALAR_FIELD(ismove);
1806 _copyIndexStmt(IndexStmt *from)
1808 IndexStmt *newnode = makeNode(IndexStmt);
1810 COPY_STRING_FIELD(idxname);
1811 COPY_NODE_FIELD(relation);
1812 COPY_STRING_FIELD(accessMethod);
1813 COPY_NODE_FIELD(indexParams);
1814 COPY_NODE_FIELD(whereClause);
1815 COPY_NODE_FIELD(rangetable);
1816 COPY_SCALAR_FIELD(unique);
1817 COPY_SCALAR_FIELD(primary);
1818 COPY_SCALAR_FIELD(isconstraint);
1823 static CreateFunctionStmt *
1824 _copyCreateFunctionStmt(CreateFunctionStmt *from)
1826 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
1828 COPY_SCALAR_FIELD(replace);
1829 COPY_NODE_FIELD(funcname);
1830 COPY_NODE_FIELD(argTypes);
1831 COPY_NODE_FIELD(returnType);
1832 COPY_NODE_FIELD(options);
1833 COPY_NODE_FIELD(withClause);
1838 static RemoveAggrStmt *
1839 _copyRemoveAggrStmt(RemoveAggrStmt *from)
1841 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1843 COPY_NODE_FIELD(aggname);
1844 COPY_NODE_FIELD(aggtype);
1845 COPY_SCALAR_FIELD(behavior);
1850 static RemoveFuncStmt *
1851 _copyRemoveFuncStmt(RemoveFuncStmt *from)
1853 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
1855 COPY_NODE_FIELD(funcname);
1856 COPY_NODE_FIELD(args);
1857 COPY_SCALAR_FIELD(behavior);
1862 static RemoveOperStmt *
1863 _copyRemoveOperStmt(RemoveOperStmt *from)
1865 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
1867 COPY_NODE_FIELD(opname);
1868 COPY_NODE_FIELD(args);
1869 COPY_SCALAR_FIELD(behavior);
1874 static RemoveOpClassStmt *
1875 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
1877 RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
1879 COPY_NODE_FIELD(opclassname);
1880 COPY_STRING_FIELD(amname);
1881 COPY_SCALAR_FIELD(behavior);
1887 _copyRenameStmt(RenameStmt *from)
1889 RenameStmt *newnode = makeNode(RenameStmt);
1891 COPY_NODE_FIELD(relation);
1892 COPY_STRING_FIELD(oldname);
1893 COPY_STRING_FIELD(newname);
1894 COPY_SCALAR_FIELD(renameType);
1900 _copyRuleStmt(RuleStmt *from)
1902 RuleStmt *newnode = makeNode(RuleStmt);
1904 COPY_NODE_FIELD(relation);
1905 COPY_STRING_FIELD(rulename);
1906 COPY_NODE_FIELD(whereClause);
1907 COPY_SCALAR_FIELD(event);
1908 COPY_SCALAR_FIELD(instead);
1909 COPY_NODE_FIELD(actions);
1910 COPY_SCALAR_FIELD(replace);
1916 _copyNotifyStmt(NotifyStmt *from)
1918 NotifyStmt *newnode = makeNode(NotifyStmt);
1920 COPY_NODE_FIELD(relation);
1926 _copyListenStmt(ListenStmt *from)
1928 ListenStmt *newnode = makeNode(ListenStmt);
1930 COPY_NODE_FIELD(relation);
1935 static UnlistenStmt *
1936 _copyUnlistenStmt(UnlistenStmt *from)
1938 UnlistenStmt *newnode = makeNode(UnlistenStmt);
1940 COPY_NODE_FIELD(relation);
1945 static TransactionStmt *
1946 _copyTransactionStmt(TransactionStmt *from)
1948 TransactionStmt *newnode = makeNode(TransactionStmt);
1950 COPY_SCALAR_FIELD(kind);
1951 COPY_NODE_FIELD(options);
1956 static CompositeTypeStmt *
1957 _copyCompositeTypeStmt(CompositeTypeStmt *from)
1959 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
1961 COPY_NODE_FIELD(typevar);
1962 COPY_NODE_FIELD(coldeflist);
1968 _copyViewStmt(ViewStmt *from)
1970 ViewStmt *newnode = makeNode(ViewStmt);
1972 COPY_NODE_FIELD(view);
1973 COPY_NODE_FIELD(aliases);
1974 COPY_NODE_FIELD(query);
1975 COPY_SCALAR_FIELD(replace);
1981 _copyLoadStmt(LoadStmt *from)
1983 LoadStmt *newnode = makeNode(LoadStmt);
1985 COPY_STRING_FIELD(filename);
1990 static CreateDomainStmt *
1991 _copyCreateDomainStmt(CreateDomainStmt *from)
1993 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
1995 COPY_NODE_FIELD(domainname);
1996 COPY_NODE_FIELD(typename);
1997 COPY_NODE_FIELD(constraints);
2002 static CreateOpClassStmt *
2003 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2005 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2007 COPY_NODE_FIELD(opclassname);
2008 COPY_STRING_FIELD(amname);
2009 COPY_NODE_FIELD(datatype);
2010 COPY_NODE_FIELD(items);
2011 COPY_SCALAR_FIELD(isDefault);
2016 static CreateOpClassItem *
2017 _copyCreateOpClassItem(CreateOpClassItem *from)
2019 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2021 COPY_SCALAR_FIELD(itemtype);
2022 COPY_NODE_FIELD(name);
2023 COPY_NODE_FIELD(args);
2024 COPY_SCALAR_FIELD(number);
2025 COPY_SCALAR_FIELD(recheck);
2026 COPY_NODE_FIELD(storedtype);
2031 static CreatedbStmt *
2032 _copyCreatedbStmt(CreatedbStmt *from)
2034 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2036 COPY_STRING_FIELD(dbname);
2037 COPY_NODE_FIELD(options);
2042 static AlterDatabaseSetStmt *
2043 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2045 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2047 COPY_STRING_FIELD(dbname);
2048 COPY_STRING_FIELD(variable);
2049 COPY_NODE_FIELD(value);
2055 _copyDropdbStmt(DropdbStmt *from)
2057 DropdbStmt *newnode = makeNode(DropdbStmt);
2059 COPY_STRING_FIELD(dbname);
2065 _copyVacuumStmt(VacuumStmt *from)
2067 VacuumStmt *newnode = makeNode(VacuumStmt);
2069 COPY_SCALAR_FIELD(vacuum);
2070 COPY_SCALAR_FIELD(full);
2071 COPY_SCALAR_FIELD(analyze);
2072 COPY_SCALAR_FIELD(freeze);
2073 COPY_SCALAR_FIELD(verbose);
2074 COPY_NODE_FIELD(relation);
2075 COPY_NODE_FIELD(va_cols);
2080 static ExplainStmt *
2081 _copyExplainStmt(ExplainStmt *from)
2083 ExplainStmt *newnode = makeNode(ExplainStmt);
2085 COPY_NODE_FIELD(query);
2086 COPY_SCALAR_FIELD(verbose);
2087 COPY_SCALAR_FIELD(analyze);
2092 static CreateSeqStmt *
2093 _copyCreateSeqStmt(CreateSeqStmt *from)
2095 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2097 COPY_NODE_FIELD(sequence);
2098 COPY_NODE_FIELD(options);
2103 static AlterSeqStmt *
2104 _copyAlterSeqStmt(AlterSeqStmt *from)
2106 AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
2108 COPY_NODE_FIELD(sequence);
2109 COPY_NODE_FIELD(options);
2114 static VariableSetStmt *
2115 _copyVariableSetStmt(VariableSetStmt *from)
2117 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2119 COPY_STRING_FIELD(name);
2120 COPY_NODE_FIELD(args);
2121 COPY_SCALAR_FIELD(is_local);
2126 static VariableShowStmt *
2127 _copyVariableShowStmt(VariableShowStmt *from)
2129 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2131 COPY_STRING_FIELD(name);
2136 static VariableResetStmt *
2137 _copyVariableResetStmt(VariableResetStmt *from)
2139 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2141 COPY_STRING_FIELD(name);
2146 static CreateTrigStmt *
2147 _copyCreateTrigStmt(CreateTrigStmt *from)
2149 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2151 COPY_STRING_FIELD(trigname);
2152 COPY_NODE_FIELD(relation);
2153 COPY_NODE_FIELD(funcname);
2154 COPY_NODE_FIELD(args);
2155 COPY_SCALAR_FIELD(before);
2156 COPY_SCALAR_FIELD(row);
2157 strcpy(newnode->actions, from->actions); /* in-line string field */
2158 COPY_SCALAR_FIELD(isconstraint);
2159 COPY_SCALAR_FIELD(deferrable);
2160 COPY_SCALAR_FIELD(initdeferred);
2161 COPY_NODE_FIELD(constrrel);
2166 static DropPropertyStmt *
2167 _copyDropPropertyStmt(DropPropertyStmt *from)
2169 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2171 COPY_NODE_FIELD(relation);
2172 COPY_STRING_FIELD(property);
2173 COPY_SCALAR_FIELD(removeType);
2174 COPY_SCALAR_FIELD(behavior);
2179 static CreatePLangStmt *
2180 _copyCreatePLangStmt(CreatePLangStmt *from)
2182 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2184 COPY_STRING_FIELD(plname);
2185 COPY_NODE_FIELD(plhandler);
2186 COPY_NODE_FIELD(plvalidator);
2187 COPY_SCALAR_FIELD(pltrusted);
2192 static DropPLangStmt *
2193 _copyDropPLangStmt(DropPLangStmt *from)
2195 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2197 COPY_STRING_FIELD(plname);
2198 COPY_SCALAR_FIELD(behavior);
2203 static CreateUserStmt *
2204 _copyCreateUserStmt(CreateUserStmt *from)
2206 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2208 COPY_STRING_FIELD(user);
2209 COPY_NODE_FIELD(options);
2214 static AlterUserStmt *
2215 _copyAlterUserStmt(AlterUserStmt *from)
2217 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2219 COPY_STRING_FIELD(user);
2220 COPY_NODE_FIELD(options);
2225 static AlterUserSetStmt *
2226 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2228 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2230 COPY_STRING_FIELD(user);
2231 COPY_STRING_FIELD(variable);
2232 COPY_NODE_FIELD(value);
2237 static DropUserStmt *
2238 _copyDropUserStmt(DropUserStmt *from)
2240 DropUserStmt *newnode = makeNode(DropUserStmt);
2242 COPY_NODE_FIELD(users);
2248 _copyLockStmt(LockStmt *from)
2250 LockStmt *newnode = makeNode(LockStmt);
2252 COPY_NODE_FIELD(relations);
2253 COPY_SCALAR_FIELD(mode);
2258 static ConstraintsSetStmt *
2259 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2261 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2263 COPY_NODE_FIELD(constraints);
2264 COPY_SCALAR_FIELD(deferred);
2269 static CreateGroupStmt *
2270 _copyCreateGroupStmt(CreateGroupStmt *from)
2272 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2274 COPY_STRING_FIELD(name);
2275 COPY_NODE_FIELD(options);
2280 static AlterGroupStmt *
2281 _copyAlterGroupStmt(AlterGroupStmt *from)
2283 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2285 COPY_STRING_FIELD(name);
2286 COPY_SCALAR_FIELD(action);
2287 COPY_NODE_FIELD(listUsers);
2292 static DropGroupStmt *
2293 _copyDropGroupStmt(DropGroupStmt *from)
2295 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2297 COPY_STRING_FIELD(name);
2302 static ReindexStmt *
2303 _copyReindexStmt(ReindexStmt *from)
2305 ReindexStmt *newnode = makeNode(ReindexStmt);
2307 COPY_SCALAR_FIELD(kind);
2308 COPY_NODE_FIELD(relation);
2309 COPY_STRING_FIELD(name);
2310 COPY_SCALAR_FIELD(force);
2311 COPY_SCALAR_FIELD(all);
2316 static CreateSchemaStmt *
2317 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2319 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2321 COPY_STRING_FIELD(schemaname);
2322 COPY_STRING_FIELD(authid);
2323 COPY_NODE_FIELD(schemaElts);
2328 static CreateConversionStmt *
2329 _copyCreateConversionStmt(CreateConversionStmt *from)
2331 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2333 COPY_NODE_FIELD(conversion_name);
2334 COPY_STRING_FIELD(for_encoding_name);
2335 COPY_STRING_FIELD(to_encoding_name);
2336 COPY_NODE_FIELD(func_name);
2337 COPY_SCALAR_FIELD(def);
2342 static CreateCastStmt *
2343 _copyCreateCastStmt(CreateCastStmt *from)
2345 CreateCastStmt *newnode = makeNode(CreateCastStmt);
2347 COPY_NODE_FIELD(sourcetype);
2348 COPY_NODE_FIELD(targettype);
2349 COPY_NODE_FIELD(func);
2350 COPY_SCALAR_FIELD(context);
2355 static DropCastStmt *
2356 _copyDropCastStmt(DropCastStmt *from)
2358 DropCastStmt *newnode = makeNode(DropCastStmt);
2360 COPY_NODE_FIELD(sourcetype);
2361 COPY_NODE_FIELD(targettype);
2362 COPY_SCALAR_FIELD(behavior);
2367 static PrepareStmt *
2368 _copyPrepareStmt(PrepareStmt *from)
2370 PrepareStmt *newnode = makeNode(PrepareStmt);
2372 COPY_STRING_FIELD(name);
2373 COPY_NODE_FIELD(argtypes);
2374 COPY_OIDLIST_FIELD(argtype_oids);
2375 COPY_NODE_FIELD(query);
2380 static ExecuteStmt *
2381 _copyExecuteStmt(ExecuteStmt *from)
2383 ExecuteStmt *newnode = makeNode(ExecuteStmt);
2385 COPY_STRING_FIELD(name);
2386 COPY_NODE_FIELD(into);
2387 COPY_NODE_FIELD(params);
2392 static DeallocateStmt *
2393 _copyDeallocateStmt(DeallocateStmt *from)
2395 DeallocateStmt *newnode = makeNode(DeallocateStmt);
2397 COPY_STRING_FIELD(name);
2403 /* ****************************************************************
2404 * pg_list.h copy functions
2405 * ****************************************************************
2409 _copyValue(Value *from)
2411 Value *newnode = makeNode(Value);
2413 /* See also _copyAConst when changing this code! */
2415 COPY_SCALAR_FIELD(type);
2419 COPY_SCALAR_FIELD(val.ival);
2424 COPY_STRING_FIELD(val.str);
2430 elog(ERROR, "_copyValue: unknown node type %d", from->type);
2439 * Create a copy of a Node tree or list. This is a "deep" copy: all
2440 * substructure is copied too, recursively.
2443 copyObject(void *from)
2450 switch (nodeTag(from))
2456 retval = _copyPlan(from);
2459 retval = _copyResult(from);
2462 retval = _copyAppend(from);
2465 retval = _copyScan(from);
2468 retval = _copySeqScan(from);
2471 retval = _copyIndexScan(from);
2474 retval = _copyTidScan(from);
2476 case T_SubqueryScan:
2477 retval = _copySubqueryScan(from);
2479 case T_FunctionScan:
2480 retval = _copyFunctionScan(from);
2483 retval = _copyJoin(from);
2486 retval = _copyNestLoop(from);
2489 retval = _copyMergeJoin(from);
2492 retval = _copyHashJoin(from);
2495 retval = _copyMaterial(from);
2498 retval = _copySort(from);
2501 retval = _copyGroup(from);
2504 retval = _copyAgg(from);
2507 retval = _copyUnique(from);
2510 retval = _copyHash(from);
2513 retval = _copySetOp(from);
2516 retval = _copyLimit(from);
2523 retval = _copyResdom(from);
2526 retval = _copyAlias(from);
2529 retval = _copyRangeVar(from);
2532 retval = _copyVar(from);
2535 retval = _copyConst(from);
2538 retval = _copyParam(from);
2541 retval = _copyAggref(from);
2544 retval = _copyArrayRef(from);
2547 retval = _copyFuncExpr(from);
2550 retval = _copyOpExpr(from);
2552 case T_DistinctExpr:
2553 retval = _copyDistinctExpr(from);
2556 retval = _copyBoolExpr(from);
2559 retval = _copySubLink(from);
2562 retval = _copySubPlan(from);
2565 retval = _copyFieldSelect(from);
2568 retval = _copyRelabelType(from);
2571 retval = _copyCaseExpr(from);
2574 retval = _copyCaseWhen(from);
2577 retval = _copyArrayExpr(from);
2579 case T_CoalesceExpr:
2580 retval = _copyCoalesceExpr(from);
2583 retval = _copyNullIfExpr(from);
2586 retval = _copyNullTest(from);
2589 retval = _copyBooleanTest(from);
2591 case T_CoerceToDomain:
2592 retval = _copyCoerceToDomain(from);
2594 case T_CoerceToDomainValue:
2595 retval = _copyCoerceToDomainValue(from);
2598 retval = _copyTargetEntry(from);
2601 retval = _copyRangeTblRef(from);
2604 retval = _copyJoinExpr(from);
2607 retval = _copyFromExpr(from);
2614 retval = _copyPathKeyItem(from);
2616 case T_RestrictInfo:
2617 retval = _copyRestrictInfo(from);
2620 retval = _copyJoinInfo(from);
2622 case T_InClauseInfo:
2623 retval = _copyInClauseInfo(from);
2634 retval = _copyValue(from);
2643 /* rather ugly coding for speed... */
2644 /* Note the input list cannot be NIL if we got here. */
2645 newcell = makeNode(List);
2646 lfirst(newcell) = copyObject(lfirst(list));
2648 retval = (void *) newcell;
2651 foreach(oldl, lnext(list))
2653 newcell = makeNode(List);
2654 lfirst(newcell) = copyObject(lfirst(oldl));
2655 prev->next = newcell;
2666 retval = _copyQuery(from);
2669 retval = _copyInsertStmt(from);
2672 retval = _copyDeleteStmt(from);
2675 retval = _copyUpdateStmt(from);
2678 retval = _copySelectStmt(from);
2680 case T_SetOperationStmt:
2681 retval = _copySetOperationStmt(from);
2683 case T_AlterTableStmt:
2684 retval = _copyAlterTableStmt(from);
2686 case T_AlterDomainStmt:
2687 retval = _copyAlterDomainStmt(from);
2690 retval = _copyGrantStmt(from);
2692 case T_DeclareCursorStmt:
2693 retval = _copyDeclareCursorStmt(from);
2695 case T_ClosePortalStmt:
2696 retval = _copyClosePortalStmt(from);
2699 retval = _copyClusterStmt(from);
2702 retval = _copyCopyStmt(from);
2705 retval = _copyCreateStmt(from);
2708 retval = _copyInhRelation(from);
2711 retval = _copyDefineStmt(from);
2714 retval = _copyDropStmt(from);
2716 case T_TruncateStmt:
2717 retval = _copyTruncateStmt(from);
2720 retval = _copyCommentStmt(from);
2723 retval = _copyFetchStmt(from);
2726 retval = _copyIndexStmt(from);
2728 case T_CreateFunctionStmt:
2729 retval = _copyCreateFunctionStmt(from);
2731 case T_RemoveAggrStmt:
2732 retval = _copyRemoveAggrStmt(from);
2734 case T_RemoveFuncStmt:
2735 retval = _copyRemoveFuncStmt(from);
2737 case T_RemoveOperStmt:
2738 retval = _copyRemoveOperStmt(from);
2740 case T_RemoveOpClassStmt:
2741 retval = _copyRemoveOpClassStmt(from);
2744 retval = _copyRenameStmt(from);
2747 retval = _copyRuleStmt(from);
2750 retval = _copyNotifyStmt(from);
2753 retval = _copyListenStmt(from);
2755 case T_UnlistenStmt:
2756 retval = _copyUnlistenStmt(from);
2758 case T_TransactionStmt:
2759 retval = _copyTransactionStmt(from);
2761 case T_CompositeTypeStmt:
2762 retval = _copyCompositeTypeStmt(from);
2765 retval = _copyViewStmt(from);
2768 retval = _copyLoadStmt(from);
2770 case T_CreateDomainStmt:
2771 retval = _copyCreateDomainStmt(from);
2773 case T_CreateOpClassStmt:
2774 retval = _copyCreateOpClassStmt(from);
2776 case T_CreateOpClassItem:
2777 retval = _copyCreateOpClassItem(from);
2779 case T_CreatedbStmt:
2780 retval = _copyCreatedbStmt(from);
2782 case T_AlterDatabaseSetStmt:
2783 retval = _copyAlterDatabaseSetStmt(from);
2786 retval = _copyDropdbStmt(from);
2789 retval = _copyVacuumStmt(from);
2792 retval = _copyExplainStmt(from);
2794 case T_CreateSeqStmt:
2795 retval = _copyCreateSeqStmt(from);
2797 case T_AlterSeqStmt:
2798 retval = _copyAlterSeqStmt(from);
2800 case T_VariableSetStmt:
2801 retval = _copyVariableSetStmt(from);
2803 case T_VariableShowStmt:
2804 retval = _copyVariableShowStmt(from);
2806 case T_VariableResetStmt:
2807 retval = _copyVariableResetStmt(from);
2809 case T_CreateTrigStmt:
2810 retval = _copyCreateTrigStmt(from);
2812 case T_DropPropertyStmt:
2813 retval = _copyDropPropertyStmt(from);
2815 case T_CreatePLangStmt:
2816 retval = _copyCreatePLangStmt(from);
2818 case T_DropPLangStmt:
2819 retval = _copyDropPLangStmt(from);
2821 case T_CreateUserStmt:
2822 retval = _copyCreateUserStmt(from);
2824 case T_AlterUserStmt:
2825 retval = _copyAlterUserStmt(from);
2827 case T_AlterUserSetStmt:
2828 retval = _copyAlterUserSetStmt(from);
2830 case T_DropUserStmt:
2831 retval = _copyDropUserStmt(from);
2834 retval = _copyLockStmt(from);
2836 case T_ConstraintsSetStmt:
2837 retval = _copyConstraintsSetStmt(from);
2839 case T_CreateGroupStmt:
2840 retval = _copyCreateGroupStmt(from);
2842 case T_AlterGroupStmt:
2843 retval = _copyAlterGroupStmt(from);
2845 case T_DropGroupStmt:
2846 retval = _copyDropGroupStmt(from);
2849 retval = _copyReindexStmt(from);
2851 case T_CheckPointStmt:
2852 retval = (void *) makeNode(CheckPointStmt);
2854 case T_CreateSchemaStmt:
2855 retval = _copyCreateSchemaStmt(from);
2857 case T_CreateConversionStmt:
2858 retval = _copyCreateConversionStmt(from);
2860 case T_CreateCastStmt:
2861 retval = _copyCreateCastStmt(from);
2863 case T_DropCastStmt:
2864 retval = _copyDropCastStmt(from);
2867 retval = _copyPrepareStmt(from);
2870 retval = _copyExecuteStmt(from);
2872 case T_DeallocateStmt:
2873 retval = _copyDeallocateStmt(from);
2877 retval = _copyAExpr(from);
2880 retval = _copyColumnRef(from);
2883 retval = _copyParamRef(from);
2886 retval = _copyAConst(from);
2889 retval = _copyFuncCall(from);
2892 retval = _copyAIndices(from);
2894 case T_ExprFieldSelect:
2895 retval = _copyExprFieldSelect(from);
2898 retval = _copyResTarget(from);
2901 retval = _copyTypeCast(from);
2904 retval = _copySortGroupBy(from);
2906 case T_RangeSubselect:
2907 retval = _copyRangeSubselect(from);
2909 case T_RangeFunction:
2910 retval = _copyRangeFunction(from);
2913 retval = _copyTypeName(from);
2916 retval = _copyIndexElem(from);
2919 retval = _copyColumnDef(from);
2922 retval = _copyConstraint(from);
2925 retval = _copyDefElem(from);
2927 case T_RangeTblEntry:
2928 retval = _copyRangeTblEntry(from);
2931 retval = _copySortClause(from);
2934 retval = _copyGroupClause(from);
2936 case T_FkConstraint:
2937 retval = _copyFkConstraint(from);
2940 retval = _copyPrivGrantee(from);
2942 case T_FuncWithArgs:
2943 retval = _copyFuncWithArgs(from);
2945 case T_InsertDefault:
2946 retval = _copyInsertDefault(from);
2950 elog(ERROR, "copyObject: don't know how to copy node type %d",
2952 retval = from; /* keep compiler quiet */