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-2003, PostgreSQL Global Development Group
15 * Portions Copyright (c) 1994, Regents of the University of California
18 * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.277 2004/01/14 23:01:54 tgl 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 /* this can become COPY_NODE_FIELD when intlists are normal objects: */
267 List *newstrat = NIL;
270 foreach(tmp, from->indxstrategy)
272 newstrat = lappend(newstrat, listCopy(lfirst(tmp)));
274 newnode->indxstrategy = newstrat;
276 /* this can become COPY_NODE_FIELD when OID lists are normal objects: */
278 List *newsubtype = NIL;
281 foreach(tmp, from->indxsubtype)
283 newsubtype = lappend(newsubtype, listCopy(lfirst(tmp)));
285 newnode->indxsubtype = newsubtype;
287 /* this can become COPY_NODE_FIELD when intlists are normal objects: */
289 List *newstrat = NIL;
292 foreach(tmp, from->indxlossy)
294 newstrat = lappend(newstrat, listCopy(lfirst(tmp)));
296 newnode->indxlossy = newstrat;
298 COPY_SCALAR_FIELD(indxorderdir);
307 _copyTidScan(TidScan *from)
309 TidScan *newnode = makeNode(TidScan);
312 * copy node superclass fields
314 CopyScanFields((Scan *) from, (Scan *) newnode);
317 * copy remainder of node
319 COPY_NODE_FIELD(tideval);
327 static SubqueryScan *
328 _copySubqueryScan(SubqueryScan *from)
330 SubqueryScan *newnode = makeNode(SubqueryScan);
333 * copy node superclass fields
335 CopyScanFields((Scan *) from, (Scan *) newnode);
338 * copy remainder of node
340 COPY_NODE_FIELD(subplan);
348 static FunctionScan *
349 _copyFunctionScan(FunctionScan *from)
351 FunctionScan *newnode = makeNode(FunctionScan);
354 * copy node superclass fields
356 CopyScanFields((Scan *) from, (Scan *) newnode);
364 * This function copies the fields of the Join node. It is used by
365 * all the copy functions for classes which inherit from Join.
368 CopyJoinFields(Join *from, Join *newnode)
370 CopyPlanFields((Plan *) from, (Plan *) newnode);
372 COPY_SCALAR_FIELD(jointype);
373 COPY_NODE_FIELD(joinqual);
381 _copyJoin(Join *from)
383 Join *newnode = makeNode(Join);
386 * copy node superclass fields
388 CopyJoinFields(from, newnode);
398 _copyNestLoop(NestLoop *from)
400 NestLoop *newnode = makeNode(NestLoop);
403 * copy node superclass fields
405 CopyJoinFields((Join *) from, (Join *) newnode);
415 _copyMergeJoin(MergeJoin *from)
417 MergeJoin *newnode = makeNode(MergeJoin);
420 * copy node superclass fields
422 CopyJoinFields((Join *) from, (Join *) newnode);
425 * copy remainder of node
427 COPY_NODE_FIELD(mergeclauses);
436 _copyHashJoin(HashJoin *from)
438 HashJoin *newnode = makeNode(HashJoin);
441 * copy node superclass fields
443 CopyJoinFields((Join *) from, (Join *) newnode);
446 * copy remainder of node
448 COPY_NODE_FIELD(hashclauses);
458 _copyMaterial(Material *from)
460 Material *newnode = makeNode(Material);
463 * copy node superclass fields
465 CopyPlanFields((Plan *) from, (Plan *) newnode);
475 _copySort(Sort *from)
477 Sort *newnode = makeNode(Sort);
480 * copy node superclass fields
482 CopyPlanFields((Plan *) from, (Plan *) newnode);
484 COPY_SCALAR_FIELD(numCols);
485 COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
486 COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
496 _copyGroup(Group *from)
498 Group *newnode = makeNode(Group);
500 CopyPlanFields((Plan *) from, (Plan *) newnode);
502 COPY_SCALAR_FIELD(numCols);
503 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
514 Agg *newnode = makeNode(Agg);
516 CopyPlanFields((Plan *) from, (Plan *) newnode);
518 COPY_SCALAR_FIELD(aggstrategy);
519 COPY_SCALAR_FIELD(numCols);
520 if (from->numCols > 0)
521 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
522 COPY_SCALAR_FIELD(numGroups);
531 _copyUnique(Unique *from)
533 Unique *newnode = makeNode(Unique);
536 * copy node superclass fields
538 CopyPlanFields((Plan *) from, (Plan *) newnode);
541 * copy remainder of node
543 COPY_SCALAR_FIELD(numCols);
544 COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
553 _copyHash(Hash *from)
555 Hash *newnode = makeNode(Hash);
558 * copy node superclass fields
560 CopyPlanFields((Plan *) from, (Plan *) newnode);
563 * copy remainder of node
573 _copySetOp(SetOp *from)
575 SetOp *newnode = makeNode(SetOp);
578 * copy node superclass fields
580 CopyPlanFields((Plan *) from, (Plan *) newnode);
583 * copy remainder of node
585 COPY_SCALAR_FIELD(cmd);
586 COPY_SCALAR_FIELD(numCols);
587 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
588 COPY_SCALAR_FIELD(flagColIdx);
597 _copyLimit(Limit *from)
599 Limit *newnode = makeNode(Limit);
602 * copy node superclass fields
604 CopyPlanFields((Plan *) from, (Plan *) newnode);
607 * copy remainder of node
609 COPY_NODE_FIELD(limitOffset);
610 COPY_NODE_FIELD(limitCount);
615 /* ****************************************************************
616 * primnodes.h copy functions
617 * ****************************************************************
624 _copyResdom(Resdom *from)
626 Resdom *newnode = makeNode(Resdom);
628 COPY_SCALAR_FIELD(resno);
629 COPY_SCALAR_FIELD(restype);
630 COPY_SCALAR_FIELD(restypmod);
631 COPY_STRING_FIELD(resname);
632 COPY_SCALAR_FIELD(ressortgroupref);
633 COPY_SCALAR_FIELD(resorigtbl);
634 COPY_SCALAR_FIELD(resorigcol);
635 COPY_SCALAR_FIELD(resjunk);
644 _copyAlias(Alias *from)
646 Alias *newnode = makeNode(Alias);
648 COPY_STRING_FIELD(aliasname);
649 COPY_NODE_FIELD(colnames);
658 _copyRangeVar(RangeVar *from)
660 RangeVar *newnode = makeNode(RangeVar);
662 COPY_STRING_FIELD(catalogname);
663 COPY_STRING_FIELD(schemaname);
664 COPY_STRING_FIELD(relname);
665 COPY_SCALAR_FIELD(inhOpt);
666 COPY_SCALAR_FIELD(istemp);
667 COPY_NODE_FIELD(alias);
673 * We don't need a _copyExpr because Expr is an abstract supertype which
674 * should never actually get instantiated. Also, since it has no common
675 * fields except NodeTag, there's no need for a helper routine to factor
676 * out copying the common fields...
685 Var *newnode = makeNode(Var);
687 COPY_SCALAR_FIELD(varno);
688 COPY_SCALAR_FIELD(varattno);
689 COPY_SCALAR_FIELD(vartype);
690 COPY_SCALAR_FIELD(vartypmod);
691 COPY_SCALAR_FIELD(varlevelsup);
692 COPY_SCALAR_FIELD(varnoold);
693 COPY_SCALAR_FIELD(varoattno);
702 _copyConst(Const *from)
704 Const *newnode = makeNode(Const);
706 COPY_SCALAR_FIELD(consttype);
707 COPY_SCALAR_FIELD(constlen);
709 if (from->constbyval || from->constisnull)
712 * passed by value so just copy the datum. Also, don't try to copy
713 * struct when value is null!
715 newnode->constvalue = from->constvalue;
720 * passed by reference. We need a palloc'd copy.
722 newnode->constvalue = datumCopy(from->constvalue,
727 COPY_SCALAR_FIELD(constisnull);
728 COPY_SCALAR_FIELD(constbyval);
737 _copyParam(Param *from)
739 Param *newnode = makeNode(Param);
741 COPY_SCALAR_FIELD(paramkind);
742 COPY_SCALAR_FIELD(paramid);
743 COPY_STRING_FIELD(paramname);
744 COPY_SCALAR_FIELD(paramtype);
753 _copyAggref(Aggref *from)
755 Aggref *newnode = makeNode(Aggref);
757 COPY_SCALAR_FIELD(aggfnoid);
758 COPY_SCALAR_FIELD(aggtype);
759 COPY_NODE_FIELD(target);
760 COPY_SCALAR_FIELD(agglevelsup);
761 COPY_SCALAR_FIELD(aggstar);
762 COPY_SCALAR_FIELD(aggdistinct);
771 _copyArrayRef(ArrayRef *from)
773 ArrayRef *newnode = makeNode(ArrayRef);
775 COPY_SCALAR_FIELD(refrestype);
776 COPY_SCALAR_FIELD(refarraytype);
777 COPY_SCALAR_FIELD(refelemtype);
778 COPY_NODE_FIELD(refupperindexpr);
779 COPY_NODE_FIELD(reflowerindexpr);
780 COPY_NODE_FIELD(refexpr);
781 COPY_NODE_FIELD(refassgnexpr);
790 _copyFuncExpr(FuncExpr *from)
792 FuncExpr *newnode = makeNode(FuncExpr);
794 COPY_SCALAR_FIELD(funcid);
795 COPY_SCALAR_FIELD(funcresulttype);
796 COPY_SCALAR_FIELD(funcretset);
797 COPY_SCALAR_FIELD(funcformat);
798 COPY_NODE_FIELD(args);
807 _copyOpExpr(OpExpr *from)
809 OpExpr *newnode = makeNode(OpExpr);
811 COPY_SCALAR_FIELD(opno);
812 COPY_SCALAR_FIELD(opfuncid);
813 COPY_SCALAR_FIELD(opresulttype);
814 COPY_SCALAR_FIELD(opretset);
815 COPY_NODE_FIELD(args);
821 * _copyDistinctExpr (same as OpExpr)
823 static DistinctExpr *
824 _copyDistinctExpr(DistinctExpr *from)
826 DistinctExpr *newnode = makeNode(DistinctExpr);
828 COPY_SCALAR_FIELD(opno);
829 COPY_SCALAR_FIELD(opfuncid);
830 COPY_SCALAR_FIELD(opresulttype);
831 COPY_SCALAR_FIELD(opretset);
832 COPY_NODE_FIELD(args);
838 * _copyScalarArrayOpExpr
840 static ScalarArrayOpExpr *
841 _copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
843 ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
845 COPY_SCALAR_FIELD(opno);
846 COPY_SCALAR_FIELD(opfuncid);
847 COPY_SCALAR_FIELD(useOr);
848 COPY_NODE_FIELD(args);
857 _copyBoolExpr(BoolExpr *from)
859 BoolExpr *newnode = makeNode(BoolExpr);
861 COPY_SCALAR_FIELD(boolop);
862 COPY_NODE_FIELD(args);
871 _copySubLink(SubLink *from)
873 SubLink *newnode = makeNode(SubLink);
875 COPY_SCALAR_FIELD(subLinkType);
876 COPY_SCALAR_FIELD(useOr);
877 COPY_NODE_FIELD(lefthand);
878 COPY_NODE_FIELD(operName);
879 COPY_OIDLIST_FIELD(operOids);
880 COPY_NODE_FIELD(subselect);
889 _copySubPlan(SubPlan *from)
891 SubPlan *newnode = makeNode(SubPlan);
893 COPY_SCALAR_FIELD(subLinkType);
894 COPY_SCALAR_FIELD(useOr);
895 COPY_NODE_FIELD(exprs);
896 COPY_INTLIST_FIELD(paramIds);
897 COPY_NODE_FIELD(plan);
898 COPY_SCALAR_FIELD(plan_id);
899 COPY_NODE_FIELD(rtable);
900 COPY_SCALAR_FIELD(useHashTable);
901 COPY_SCALAR_FIELD(unknownEqFalse);
902 COPY_INTLIST_FIELD(setParam);
903 COPY_INTLIST_FIELD(parParam);
904 COPY_NODE_FIELD(args);
913 _copyFieldSelect(FieldSelect *from)
915 FieldSelect *newnode = makeNode(FieldSelect);
917 COPY_NODE_FIELD(arg);
918 COPY_SCALAR_FIELD(fieldnum);
919 COPY_SCALAR_FIELD(resulttype);
920 COPY_SCALAR_FIELD(resulttypmod);
929 _copyRelabelType(RelabelType *from)
931 RelabelType *newnode = makeNode(RelabelType);
933 COPY_NODE_FIELD(arg);
934 COPY_SCALAR_FIELD(resulttype);
935 COPY_SCALAR_FIELD(resulttypmod);
936 COPY_SCALAR_FIELD(relabelformat);
945 _copyCaseExpr(CaseExpr *from)
947 CaseExpr *newnode = makeNode(CaseExpr);
949 COPY_SCALAR_FIELD(casetype);
950 COPY_NODE_FIELD(arg);
951 COPY_NODE_FIELD(args);
952 COPY_NODE_FIELD(defresult);
961 _copyCaseWhen(CaseWhen *from)
963 CaseWhen *newnode = makeNode(CaseWhen);
965 COPY_NODE_FIELD(expr);
966 COPY_NODE_FIELD(result);
975 _copyArrayExpr(ArrayExpr *from)
977 ArrayExpr *newnode = makeNode(ArrayExpr);
979 COPY_SCALAR_FIELD(array_typeid);
980 COPY_SCALAR_FIELD(element_typeid);
981 COPY_NODE_FIELD(elements);
982 COPY_SCALAR_FIELD(multidims);
990 static CoalesceExpr *
991 _copyCoalesceExpr(CoalesceExpr *from)
993 CoalesceExpr *newnode = makeNode(CoalesceExpr);
995 COPY_SCALAR_FIELD(coalescetype);
996 COPY_NODE_FIELD(args);
1002 * _copyNullIfExpr (same as OpExpr)
1005 _copyNullIfExpr(NullIfExpr *from)
1007 NullIfExpr *newnode = makeNode(NullIfExpr);
1009 COPY_SCALAR_FIELD(opno);
1010 COPY_SCALAR_FIELD(opfuncid);
1011 COPY_SCALAR_FIELD(opresulttype);
1012 COPY_SCALAR_FIELD(opretset);
1013 COPY_NODE_FIELD(args);
1022 _copyNullTest(NullTest *from)
1024 NullTest *newnode = makeNode(NullTest);
1026 COPY_NODE_FIELD(arg);
1027 COPY_SCALAR_FIELD(nulltesttype);
1035 static BooleanTest *
1036 _copyBooleanTest(BooleanTest *from)
1038 BooleanTest *newnode = makeNode(BooleanTest);
1040 COPY_NODE_FIELD(arg);
1041 COPY_SCALAR_FIELD(booltesttype);
1047 * _copyCoerceToDomain
1049 static CoerceToDomain *
1050 _copyCoerceToDomain(CoerceToDomain *from)
1052 CoerceToDomain *newnode = makeNode(CoerceToDomain);
1054 COPY_NODE_FIELD(arg);
1055 COPY_SCALAR_FIELD(resulttype);
1056 COPY_SCALAR_FIELD(resulttypmod);
1057 COPY_SCALAR_FIELD(coercionformat);
1063 * _copyCoerceToDomainValue
1065 static CoerceToDomainValue *
1066 _copyCoerceToDomainValue(CoerceToDomainValue *from)
1068 CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1070 COPY_SCALAR_FIELD(typeId);
1071 COPY_SCALAR_FIELD(typeMod);
1079 static SetToDefault *
1080 _copySetToDefault(SetToDefault *from)
1082 SetToDefault *newnode = makeNode(SetToDefault);
1084 COPY_SCALAR_FIELD(typeId);
1085 COPY_SCALAR_FIELD(typeMod);
1093 static TargetEntry *
1094 _copyTargetEntry(TargetEntry *from)
1096 TargetEntry *newnode = makeNode(TargetEntry);
1098 COPY_NODE_FIELD(resdom);
1099 COPY_NODE_FIELD(expr);
1107 static RangeTblRef *
1108 _copyRangeTblRef(RangeTblRef *from)
1110 RangeTblRef *newnode = makeNode(RangeTblRef);
1112 COPY_SCALAR_FIELD(rtindex);
1121 _copyJoinExpr(JoinExpr *from)
1123 JoinExpr *newnode = makeNode(JoinExpr);
1125 COPY_SCALAR_FIELD(jointype);
1126 COPY_SCALAR_FIELD(isNatural);
1127 COPY_NODE_FIELD(larg);
1128 COPY_NODE_FIELD(rarg);
1129 COPY_NODE_FIELD(using);
1130 COPY_NODE_FIELD(quals);
1131 COPY_NODE_FIELD(alias);
1132 COPY_SCALAR_FIELD(rtindex);
1141 _copyFromExpr(FromExpr *from)
1143 FromExpr *newnode = makeNode(FromExpr);
1145 COPY_NODE_FIELD(fromlist);
1146 COPY_NODE_FIELD(quals);
1151 /* ****************************************************************
1152 * relation.h copy functions
1154 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1155 * There are some subsidiary structs that are useful to copy, though.
1156 * ****************************************************************
1162 static PathKeyItem *
1163 _copyPathKeyItem(PathKeyItem *from)
1165 PathKeyItem *newnode = makeNode(PathKeyItem);
1167 COPY_NODE_FIELD(key);
1168 COPY_SCALAR_FIELD(sortop);
1176 static RestrictInfo *
1177 _copyRestrictInfo(RestrictInfo *from)
1179 RestrictInfo *newnode = makeNode(RestrictInfo);
1181 COPY_NODE_FIELD(clause);
1182 COPY_SCALAR_FIELD(is_pushed_down);
1183 COPY_SCALAR_FIELD(valid_everywhere);
1184 COPY_SCALAR_FIELD(can_join);
1185 COPY_BITMAPSET_FIELD(clause_relids);
1186 COPY_BITMAPSET_FIELD(left_relids);
1187 COPY_BITMAPSET_FIELD(right_relids);
1188 COPY_NODE_FIELD(orclause);
1189 COPY_SCALAR_FIELD(eval_cost);
1190 COPY_SCALAR_FIELD(this_selec);
1191 COPY_SCALAR_FIELD(mergejoinoperator);
1192 COPY_SCALAR_FIELD(left_sortop);
1193 COPY_SCALAR_FIELD(right_sortop);
1196 * Do not copy pathkeys, since they'd not be canonical in a copied
1199 newnode->left_pathkey = NIL;
1200 newnode->right_pathkey = NIL;
1202 COPY_SCALAR_FIELD(left_mergescansel);
1203 COPY_SCALAR_FIELD(right_mergescansel);
1204 COPY_SCALAR_FIELD(hashjoinoperator);
1205 COPY_SCALAR_FIELD(left_bucketsize);
1206 COPY_SCALAR_FIELD(right_bucketsize);
1215 _copyJoinInfo(JoinInfo *from)
1217 JoinInfo *newnode = makeNode(JoinInfo);
1219 COPY_BITMAPSET_FIELD(unjoined_relids);
1220 COPY_NODE_FIELD(jinfo_restrictinfo);
1228 static InClauseInfo *
1229 _copyInClauseInfo(InClauseInfo *from)
1231 InClauseInfo *newnode = makeNode(InClauseInfo);
1233 COPY_BITMAPSET_FIELD(lefthand);
1234 COPY_BITMAPSET_FIELD(righthand);
1235 COPY_NODE_FIELD(sub_targetlist);
1240 /* ****************************************************************
1241 * parsenodes.h copy functions
1242 * ****************************************************************
1245 static RangeTblEntry *
1246 _copyRangeTblEntry(RangeTblEntry *from)
1248 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1250 COPY_SCALAR_FIELD(rtekind);
1251 COPY_SCALAR_FIELD(relid);
1252 COPY_NODE_FIELD(subquery);
1253 COPY_NODE_FIELD(funcexpr);
1254 COPY_NODE_FIELD(coldeflist);
1255 COPY_SCALAR_FIELD(jointype);
1256 COPY_NODE_FIELD(joinaliasvars);
1257 COPY_NODE_FIELD(alias);
1258 COPY_NODE_FIELD(eref);
1259 COPY_SCALAR_FIELD(inh);
1260 COPY_SCALAR_FIELD(inFromCl);
1261 COPY_SCALAR_FIELD(requiredPerms);
1262 COPY_SCALAR_FIELD(checkAsUser);
1267 static FkConstraint *
1268 _copyFkConstraint(FkConstraint *from)
1270 FkConstraint *newnode = makeNode(FkConstraint);
1272 COPY_STRING_FIELD(constr_name);
1273 COPY_NODE_FIELD(pktable);
1274 COPY_NODE_FIELD(fk_attrs);
1275 COPY_NODE_FIELD(pk_attrs);
1276 COPY_SCALAR_FIELD(fk_matchtype);
1277 COPY_SCALAR_FIELD(fk_upd_action);
1278 COPY_SCALAR_FIELD(fk_del_action);
1279 COPY_SCALAR_FIELD(deferrable);
1280 COPY_SCALAR_FIELD(initdeferred);
1281 COPY_SCALAR_FIELD(skip_validation);
1287 _copySortClause(SortClause *from)
1289 SortClause *newnode = makeNode(SortClause);
1291 COPY_SCALAR_FIELD(tleSortGroupRef);
1292 COPY_SCALAR_FIELD(sortop);
1297 static GroupClause *
1298 _copyGroupClause(GroupClause *from)
1300 GroupClause *newnode = makeNode(GroupClause);
1302 COPY_SCALAR_FIELD(tleSortGroupRef);
1303 COPY_SCALAR_FIELD(sortop);
1309 _copyAExpr(A_Expr *from)
1311 A_Expr *newnode = makeNode(A_Expr);
1313 COPY_SCALAR_FIELD(kind);
1314 COPY_NODE_FIELD(name);
1315 COPY_NODE_FIELD(lexpr);
1316 COPY_NODE_FIELD(rexpr);
1322 _copyColumnRef(ColumnRef *from)
1324 ColumnRef *newnode = makeNode(ColumnRef);
1326 COPY_NODE_FIELD(fields);
1327 COPY_NODE_FIELD(indirection);
1333 _copyParamRef(ParamRef *from)
1335 ParamRef *newnode = makeNode(ParamRef);
1337 COPY_SCALAR_FIELD(number);
1338 COPY_NODE_FIELD(fields);
1339 COPY_NODE_FIELD(indirection);
1345 _copyAConst(A_Const *from)
1347 A_Const *newnode = makeNode(A_Const);
1349 /* This part must duplicate _copyValue */
1350 COPY_SCALAR_FIELD(val.type);
1351 switch (from->val.type)
1354 COPY_SCALAR_FIELD(val.val.ival);
1359 COPY_STRING_FIELD(val.val.str);
1365 elog(ERROR, "unrecognized node type: %d",
1366 (int) from->val.type);
1370 COPY_NODE_FIELD(typename);
1376 _copyFuncCall(FuncCall *from)
1378 FuncCall *newnode = makeNode(FuncCall);
1380 COPY_NODE_FIELD(funcname);
1381 COPY_NODE_FIELD(args);
1382 COPY_SCALAR_FIELD(agg_star);
1383 COPY_SCALAR_FIELD(agg_distinct);
1389 _copyAIndices(A_Indices *from)
1391 A_Indices *newnode = makeNode(A_Indices);
1393 COPY_NODE_FIELD(lidx);
1394 COPY_NODE_FIELD(uidx);
1399 static ExprFieldSelect *
1400 _copyExprFieldSelect(ExprFieldSelect *from)
1402 ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
1404 COPY_NODE_FIELD(arg);
1405 COPY_NODE_FIELD(fields);
1406 COPY_NODE_FIELD(indirection);
1412 _copyResTarget(ResTarget *from)
1414 ResTarget *newnode = makeNode(ResTarget);
1416 COPY_STRING_FIELD(name);
1417 COPY_NODE_FIELD(indirection);
1418 COPY_NODE_FIELD(val);
1424 _copyTypeName(TypeName *from)
1426 TypeName *newnode = makeNode(TypeName);
1428 COPY_NODE_FIELD(names);
1429 COPY_SCALAR_FIELD(typeid);
1430 COPY_SCALAR_FIELD(timezone);
1431 COPY_SCALAR_FIELD(setof);
1432 COPY_SCALAR_FIELD(pct_type);
1433 COPY_SCALAR_FIELD(typmod);
1434 COPY_NODE_FIELD(arrayBounds);
1440 _copySortBy(SortBy *from)
1442 SortBy *newnode = makeNode(SortBy);
1444 COPY_SCALAR_FIELD(sortby_kind);
1445 COPY_NODE_FIELD(useOp);
1446 COPY_NODE_FIELD(node);
1451 static RangeSubselect *
1452 _copyRangeSubselect(RangeSubselect *from)
1454 RangeSubselect *newnode = makeNode(RangeSubselect);
1456 COPY_NODE_FIELD(subquery);
1457 COPY_NODE_FIELD(alias);
1462 static RangeFunction *
1463 _copyRangeFunction(RangeFunction *from)
1465 RangeFunction *newnode = makeNode(RangeFunction);
1467 COPY_NODE_FIELD(funccallnode);
1468 COPY_NODE_FIELD(alias);
1469 COPY_NODE_FIELD(coldeflist);
1475 _copyTypeCast(TypeCast *from)
1477 TypeCast *newnode = makeNode(TypeCast);
1479 COPY_NODE_FIELD(arg);
1480 COPY_NODE_FIELD(typename);
1486 _copyIndexElem(IndexElem *from)
1488 IndexElem *newnode = makeNode(IndexElem);
1490 COPY_STRING_FIELD(name);
1491 COPY_NODE_FIELD(expr);
1492 COPY_NODE_FIELD(opclass);
1498 _copyColumnDef(ColumnDef *from)
1500 ColumnDef *newnode = makeNode(ColumnDef);
1502 COPY_STRING_FIELD(colname);
1503 COPY_NODE_FIELD(typename);
1504 COPY_SCALAR_FIELD(inhcount);
1505 COPY_SCALAR_FIELD(is_local);
1506 COPY_SCALAR_FIELD(is_not_null);
1507 COPY_NODE_FIELD(raw_default);
1508 COPY_STRING_FIELD(cooked_default);
1509 COPY_NODE_FIELD(constraints);
1510 COPY_NODE_FIELD(support);
1516 _copyConstraint(Constraint *from)
1518 Constraint *newnode = makeNode(Constraint);
1520 COPY_SCALAR_FIELD(contype);
1521 COPY_STRING_FIELD(name);
1522 COPY_NODE_FIELD(raw_expr);
1523 COPY_STRING_FIELD(cooked_expr);
1524 COPY_NODE_FIELD(keys);
1530 _copyDefElem(DefElem *from)
1532 DefElem *newnode = makeNode(DefElem);
1534 COPY_STRING_FIELD(defname);
1535 COPY_NODE_FIELD(arg);
1541 _copyQuery(Query *from)
1543 Query *newnode = makeNode(Query);
1545 COPY_SCALAR_FIELD(commandType);
1546 COPY_SCALAR_FIELD(querySource);
1547 COPY_SCALAR_FIELD(canSetTag);
1548 COPY_NODE_FIELD(utilityStmt);
1549 COPY_SCALAR_FIELD(resultRelation);
1550 COPY_NODE_FIELD(into);
1551 COPY_SCALAR_FIELD(intoHasOids);
1552 COPY_SCALAR_FIELD(hasAggs);
1553 COPY_SCALAR_FIELD(hasSubLinks);
1554 COPY_NODE_FIELD(rtable);
1555 COPY_NODE_FIELD(jointree);
1556 COPY_INTLIST_FIELD(rowMarks);
1557 COPY_NODE_FIELD(targetList);
1558 COPY_NODE_FIELD(groupClause);
1559 COPY_NODE_FIELD(havingQual);
1560 COPY_NODE_FIELD(distinctClause);
1561 COPY_NODE_FIELD(sortClause);
1562 COPY_NODE_FIELD(limitOffset);
1563 COPY_NODE_FIELD(limitCount);
1564 COPY_NODE_FIELD(setOperations);
1565 COPY_INTLIST_FIELD(resultRelations);
1566 COPY_NODE_FIELD(in_info_list);
1567 COPY_SCALAR_FIELD(hasJoinRTEs);
1570 * We do not copy the other planner internal fields: base_rel_list,
1571 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. That
1572 * would get us into copying RelOptInfo/Path trees, which we don't
1573 * want to do. It is necessary to copy in_info_list and hasJoinRTEs
1574 * for the benefit of inheritance_planner(), which may try to copy a
1575 * Query in which these are already set.
1582 _copyInsertStmt(InsertStmt *from)
1584 InsertStmt *newnode = makeNode(InsertStmt);
1586 COPY_NODE_FIELD(relation);
1587 COPY_NODE_FIELD(cols);
1588 COPY_NODE_FIELD(targetList);
1589 COPY_NODE_FIELD(selectStmt);
1595 _copyDeleteStmt(DeleteStmt *from)
1597 DeleteStmt *newnode = makeNode(DeleteStmt);
1599 COPY_NODE_FIELD(relation);
1600 COPY_NODE_FIELD(whereClause);
1606 _copyUpdateStmt(UpdateStmt *from)
1608 UpdateStmt *newnode = makeNode(UpdateStmt);
1610 COPY_NODE_FIELD(relation);
1611 COPY_NODE_FIELD(targetList);
1612 COPY_NODE_FIELD(whereClause);
1613 COPY_NODE_FIELD(fromClause);
1619 _copySelectStmt(SelectStmt *from)
1621 SelectStmt *newnode = makeNode(SelectStmt);
1623 COPY_NODE_FIELD(distinctClause);
1624 COPY_NODE_FIELD(into);
1625 COPY_NODE_FIELD(intoColNames);
1626 COPY_SCALAR_FIELD(intoHasOids);
1627 COPY_NODE_FIELD(targetList);
1628 COPY_NODE_FIELD(fromClause);
1629 COPY_NODE_FIELD(whereClause);
1630 COPY_NODE_FIELD(groupClause);
1631 COPY_NODE_FIELD(havingClause);
1632 COPY_NODE_FIELD(sortClause);
1633 COPY_NODE_FIELD(limitOffset);
1634 COPY_NODE_FIELD(limitCount);
1635 COPY_NODE_FIELD(forUpdate);
1636 COPY_SCALAR_FIELD(op);
1637 COPY_SCALAR_FIELD(all);
1638 COPY_NODE_FIELD(larg);
1639 COPY_NODE_FIELD(rarg);
1644 static SetOperationStmt *
1645 _copySetOperationStmt(SetOperationStmt *from)
1647 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1649 COPY_SCALAR_FIELD(op);
1650 COPY_SCALAR_FIELD(all);
1651 COPY_NODE_FIELD(larg);
1652 COPY_NODE_FIELD(rarg);
1653 COPY_OIDLIST_FIELD(colTypes);
1658 static AlterTableStmt *
1659 _copyAlterTableStmt(AlterTableStmt *from)
1661 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1663 COPY_SCALAR_FIELD(subtype);
1664 COPY_NODE_FIELD(relation);
1665 COPY_STRING_FIELD(name);
1666 COPY_NODE_FIELD(def);
1667 COPY_SCALAR_FIELD(behavior);
1672 static AlterDomainStmt *
1673 _copyAlterDomainStmt(AlterDomainStmt *from)
1675 AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1677 COPY_SCALAR_FIELD(subtype);
1678 COPY_NODE_FIELD(typename);
1679 COPY_STRING_FIELD(name);
1680 COPY_NODE_FIELD(def);
1681 COPY_SCALAR_FIELD(behavior);
1687 _copyGrantStmt(GrantStmt *from)
1689 GrantStmt *newnode = makeNode(GrantStmt);
1691 COPY_SCALAR_FIELD(is_grant);
1692 COPY_SCALAR_FIELD(objtype);
1693 COPY_NODE_FIELD(objects);
1694 COPY_INTLIST_FIELD(privileges);
1695 COPY_NODE_FIELD(grantees);
1696 COPY_SCALAR_FIELD(grant_option);
1697 COPY_SCALAR_FIELD(behavior);
1702 static PrivGrantee *
1703 _copyPrivGrantee(PrivGrantee *from)
1705 PrivGrantee *newnode = makeNode(PrivGrantee);
1707 COPY_STRING_FIELD(username);
1708 COPY_STRING_FIELD(groupname);
1713 static FuncWithArgs *
1714 _copyFuncWithArgs(FuncWithArgs *from)
1716 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1718 COPY_NODE_FIELD(funcname);
1719 COPY_NODE_FIELD(funcargs);
1724 static DeclareCursorStmt *
1725 _copyDeclareCursorStmt(DeclareCursorStmt *from)
1727 DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
1729 COPY_STRING_FIELD(portalname);
1730 COPY_SCALAR_FIELD(options);
1731 COPY_NODE_FIELD(query);
1736 static ClosePortalStmt *
1737 _copyClosePortalStmt(ClosePortalStmt *from)
1739 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1741 COPY_STRING_FIELD(portalname);
1746 static ClusterStmt *
1747 _copyClusterStmt(ClusterStmt *from)
1749 ClusterStmt *newnode = makeNode(ClusterStmt);
1751 COPY_NODE_FIELD(relation);
1752 COPY_STRING_FIELD(indexname);
1758 _copyCopyStmt(CopyStmt *from)
1760 CopyStmt *newnode = makeNode(CopyStmt);
1762 COPY_NODE_FIELD(relation);
1763 COPY_NODE_FIELD(attlist);
1764 COPY_SCALAR_FIELD(is_from);
1765 COPY_STRING_FIELD(filename);
1766 COPY_NODE_FIELD(options);
1772 _copyCreateStmt(CreateStmt *from)
1774 CreateStmt *newnode = makeNode(CreateStmt);
1776 COPY_NODE_FIELD(relation);
1777 COPY_NODE_FIELD(tableElts);
1778 COPY_NODE_FIELD(inhRelations);
1779 COPY_NODE_FIELD(constraints);
1780 COPY_SCALAR_FIELD(hasoids);
1781 COPY_SCALAR_FIELD(oncommit);
1786 static InhRelation *
1787 _copyInhRelation(InhRelation *from)
1789 InhRelation *newnode = makeNode(InhRelation);
1791 COPY_NODE_FIELD(relation);
1792 COPY_SCALAR_FIELD(including_defaults);
1798 _copyDefineStmt(DefineStmt *from)
1800 DefineStmt *newnode = makeNode(DefineStmt);
1802 COPY_SCALAR_FIELD(kind);
1803 COPY_NODE_FIELD(defnames);
1804 COPY_NODE_FIELD(definition);
1810 _copyDropStmt(DropStmt *from)
1812 DropStmt *newnode = makeNode(DropStmt);
1814 COPY_NODE_FIELD(objects);
1815 COPY_SCALAR_FIELD(removeType);
1816 COPY_SCALAR_FIELD(behavior);
1821 static TruncateStmt *
1822 _copyTruncateStmt(TruncateStmt *from)
1824 TruncateStmt *newnode = makeNode(TruncateStmt);
1826 COPY_NODE_FIELD(relation);
1831 static CommentStmt *
1832 _copyCommentStmt(CommentStmt *from)
1834 CommentStmt *newnode = makeNode(CommentStmt);
1836 COPY_SCALAR_FIELD(objtype);
1837 COPY_NODE_FIELD(objname);
1838 COPY_NODE_FIELD(objargs);
1839 COPY_STRING_FIELD(comment);
1845 _copyFetchStmt(FetchStmt *from)
1847 FetchStmt *newnode = makeNode(FetchStmt);
1849 COPY_SCALAR_FIELD(direction);
1850 COPY_SCALAR_FIELD(howMany);
1851 COPY_STRING_FIELD(portalname);
1852 COPY_SCALAR_FIELD(ismove);
1858 _copyIndexStmt(IndexStmt *from)
1860 IndexStmt *newnode = makeNode(IndexStmt);
1862 COPY_STRING_FIELD(idxname);
1863 COPY_NODE_FIELD(relation);
1864 COPY_STRING_FIELD(accessMethod);
1865 COPY_NODE_FIELD(indexParams);
1866 COPY_NODE_FIELD(whereClause);
1867 COPY_NODE_FIELD(rangetable);
1868 COPY_SCALAR_FIELD(unique);
1869 COPY_SCALAR_FIELD(primary);
1870 COPY_SCALAR_FIELD(isconstraint);
1875 static CreateFunctionStmt *
1876 _copyCreateFunctionStmt(CreateFunctionStmt *from)
1878 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
1880 COPY_SCALAR_FIELD(replace);
1881 COPY_NODE_FIELD(funcname);
1882 COPY_NODE_FIELD(parameters);
1883 COPY_NODE_FIELD(returnType);
1884 COPY_NODE_FIELD(options);
1885 COPY_NODE_FIELD(withClause);
1890 static FunctionParameter *
1891 _copyFunctionParameter(FunctionParameter *from)
1893 FunctionParameter *newnode = makeNode(FunctionParameter);
1895 COPY_STRING_FIELD(name);
1896 COPY_NODE_FIELD(argType);
1901 static RemoveAggrStmt *
1902 _copyRemoveAggrStmt(RemoveAggrStmt *from)
1904 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1906 COPY_NODE_FIELD(aggname);
1907 COPY_NODE_FIELD(aggtype);
1908 COPY_SCALAR_FIELD(behavior);
1913 static RemoveFuncStmt *
1914 _copyRemoveFuncStmt(RemoveFuncStmt *from)
1916 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
1918 COPY_NODE_FIELD(funcname);
1919 COPY_NODE_FIELD(args);
1920 COPY_SCALAR_FIELD(behavior);
1925 static RemoveOperStmt *
1926 _copyRemoveOperStmt(RemoveOperStmt *from)
1928 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
1930 COPY_NODE_FIELD(opname);
1931 COPY_NODE_FIELD(args);
1932 COPY_SCALAR_FIELD(behavior);
1937 static RemoveOpClassStmt *
1938 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
1940 RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
1942 COPY_NODE_FIELD(opclassname);
1943 COPY_STRING_FIELD(amname);
1944 COPY_SCALAR_FIELD(behavior);
1950 _copyRenameStmt(RenameStmt *from)
1952 RenameStmt *newnode = makeNode(RenameStmt);
1954 COPY_NODE_FIELD(relation);
1955 COPY_NODE_FIELD(object);
1956 COPY_NODE_FIELD(objarg);
1957 COPY_STRING_FIELD(subname);
1958 COPY_STRING_FIELD(newname);
1959 COPY_SCALAR_FIELD(renameType);
1965 _copyRuleStmt(RuleStmt *from)
1967 RuleStmt *newnode = makeNode(RuleStmt);
1969 COPY_NODE_FIELD(relation);
1970 COPY_STRING_FIELD(rulename);
1971 COPY_NODE_FIELD(whereClause);
1972 COPY_SCALAR_FIELD(event);
1973 COPY_SCALAR_FIELD(instead);
1974 COPY_NODE_FIELD(actions);
1975 COPY_SCALAR_FIELD(replace);
1981 _copyNotifyStmt(NotifyStmt *from)
1983 NotifyStmt *newnode = makeNode(NotifyStmt);
1985 COPY_NODE_FIELD(relation);
1991 _copyListenStmt(ListenStmt *from)
1993 ListenStmt *newnode = makeNode(ListenStmt);
1995 COPY_NODE_FIELD(relation);
2000 static UnlistenStmt *
2001 _copyUnlistenStmt(UnlistenStmt *from)
2003 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2005 COPY_NODE_FIELD(relation);
2010 static TransactionStmt *
2011 _copyTransactionStmt(TransactionStmt *from)
2013 TransactionStmt *newnode = makeNode(TransactionStmt);
2015 COPY_SCALAR_FIELD(kind);
2016 COPY_NODE_FIELD(options);
2021 static CompositeTypeStmt *
2022 _copyCompositeTypeStmt(CompositeTypeStmt *from)
2024 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
2026 COPY_NODE_FIELD(typevar);
2027 COPY_NODE_FIELD(coldeflist);
2033 _copyViewStmt(ViewStmt *from)
2035 ViewStmt *newnode = makeNode(ViewStmt);
2037 COPY_NODE_FIELD(view);
2038 COPY_NODE_FIELD(aliases);
2039 COPY_NODE_FIELD(query);
2040 COPY_SCALAR_FIELD(replace);
2046 _copyLoadStmt(LoadStmt *from)
2048 LoadStmt *newnode = makeNode(LoadStmt);
2050 COPY_STRING_FIELD(filename);
2055 static CreateDomainStmt *
2056 _copyCreateDomainStmt(CreateDomainStmt *from)
2058 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2060 COPY_NODE_FIELD(domainname);
2061 COPY_NODE_FIELD(typename);
2062 COPY_NODE_FIELD(constraints);
2067 static CreateOpClassStmt *
2068 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2070 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2072 COPY_NODE_FIELD(opclassname);
2073 COPY_STRING_FIELD(amname);
2074 COPY_NODE_FIELD(datatype);
2075 COPY_NODE_FIELD(items);
2076 COPY_SCALAR_FIELD(isDefault);
2081 static CreateOpClassItem *
2082 _copyCreateOpClassItem(CreateOpClassItem *from)
2084 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2086 COPY_SCALAR_FIELD(itemtype);
2087 COPY_NODE_FIELD(name);
2088 COPY_NODE_FIELD(args);
2089 COPY_SCALAR_FIELD(number);
2090 COPY_SCALAR_FIELD(recheck);
2091 COPY_NODE_FIELD(storedtype);
2096 static CreatedbStmt *
2097 _copyCreatedbStmt(CreatedbStmt *from)
2099 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2101 COPY_STRING_FIELD(dbname);
2102 COPY_NODE_FIELD(options);
2107 static AlterDatabaseSetStmt *
2108 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2110 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2112 COPY_STRING_FIELD(dbname);
2113 COPY_STRING_FIELD(variable);
2114 COPY_NODE_FIELD(value);
2120 _copyDropdbStmt(DropdbStmt *from)
2122 DropdbStmt *newnode = makeNode(DropdbStmt);
2124 COPY_STRING_FIELD(dbname);
2130 _copyVacuumStmt(VacuumStmt *from)
2132 VacuumStmt *newnode = makeNode(VacuumStmt);
2134 COPY_SCALAR_FIELD(vacuum);
2135 COPY_SCALAR_FIELD(full);
2136 COPY_SCALAR_FIELD(analyze);
2137 COPY_SCALAR_FIELD(freeze);
2138 COPY_SCALAR_FIELD(verbose);
2139 COPY_NODE_FIELD(relation);
2140 COPY_NODE_FIELD(va_cols);
2145 static ExplainStmt *
2146 _copyExplainStmt(ExplainStmt *from)
2148 ExplainStmt *newnode = makeNode(ExplainStmt);
2150 COPY_NODE_FIELD(query);
2151 COPY_SCALAR_FIELD(verbose);
2152 COPY_SCALAR_FIELD(analyze);
2157 static CreateSeqStmt *
2158 _copyCreateSeqStmt(CreateSeqStmt *from)
2160 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2162 COPY_NODE_FIELD(sequence);
2163 COPY_NODE_FIELD(options);
2168 static AlterSeqStmt *
2169 _copyAlterSeqStmt(AlterSeqStmt *from)
2171 AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
2173 COPY_NODE_FIELD(sequence);
2174 COPY_NODE_FIELD(options);
2179 static VariableSetStmt *
2180 _copyVariableSetStmt(VariableSetStmt *from)
2182 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2184 COPY_STRING_FIELD(name);
2185 COPY_NODE_FIELD(args);
2186 COPY_SCALAR_FIELD(is_local);
2191 static VariableShowStmt *
2192 _copyVariableShowStmt(VariableShowStmt *from)
2194 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2196 COPY_STRING_FIELD(name);
2201 static VariableResetStmt *
2202 _copyVariableResetStmt(VariableResetStmt *from)
2204 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2206 COPY_STRING_FIELD(name);
2211 static CreateTrigStmt *
2212 _copyCreateTrigStmt(CreateTrigStmt *from)
2214 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2216 COPY_STRING_FIELD(trigname);
2217 COPY_NODE_FIELD(relation);
2218 COPY_NODE_FIELD(funcname);
2219 COPY_NODE_FIELD(args);
2220 COPY_SCALAR_FIELD(before);
2221 COPY_SCALAR_FIELD(row);
2222 strcpy(newnode->actions, from->actions); /* in-line string field */
2223 COPY_SCALAR_FIELD(isconstraint);
2224 COPY_SCALAR_FIELD(deferrable);
2225 COPY_SCALAR_FIELD(initdeferred);
2226 COPY_NODE_FIELD(constrrel);
2231 static DropPropertyStmt *
2232 _copyDropPropertyStmt(DropPropertyStmt *from)
2234 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2236 COPY_NODE_FIELD(relation);
2237 COPY_STRING_FIELD(property);
2238 COPY_SCALAR_FIELD(removeType);
2239 COPY_SCALAR_FIELD(behavior);
2244 static CreatePLangStmt *
2245 _copyCreatePLangStmt(CreatePLangStmt *from)
2247 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2249 COPY_STRING_FIELD(plname);
2250 COPY_NODE_FIELD(plhandler);
2251 COPY_NODE_FIELD(plvalidator);
2252 COPY_SCALAR_FIELD(pltrusted);
2257 static DropPLangStmt *
2258 _copyDropPLangStmt(DropPLangStmt *from)
2260 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2262 COPY_STRING_FIELD(plname);
2263 COPY_SCALAR_FIELD(behavior);
2268 static CreateUserStmt *
2269 _copyCreateUserStmt(CreateUserStmt *from)
2271 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2273 COPY_STRING_FIELD(user);
2274 COPY_NODE_FIELD(options);
2279 static AlterUserStmt *
2280 _copyAlterUserStmt(AlterUserStmt *from)
2282 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2284 COPY_STRING_FIELD(user);
2285 COPY_NODE_FIELD(options);
2290 static AlterUserSetStmt *
2291 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2293 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2295 COPY_STRING_FIELD(user);
2296 COPY_STRING_FIELD(variable);
2297 COPY_NODE_FIELD(value);
2302 static DropUserStmt *
2303 _copyDropUserStmt(DropUserStmt *from)
2305 DropUserStmt *newnode = makeNode(DropUserStmt);
2307 COPY_NODE_FIELD(users);
2313 _copyLockStmt(LockStmt *from)
2315 LockStmt *newnode = makeNode(LockStmt);
2317 COPY_NODE_FIELD(relations);
2318 COPY_SCALAR_FIELD(mode);
2323 static ConstraintsSetStmt *
2324 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2326 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2328 COPY_NODE_FIELD(constraints);
2329 COPY_SCALAR_FIELD(deferred);
2334 static CreateGroupStmt *
2335 _copyCreateGroupStmt(CreateGroupStmt *from)
2337 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2339 COPY_STRING_FIELD(name);
2340 COPY_NODE_FIELD(options);
2345 static AlterGroupStmt *
2346 _copyAlterGroupStmt(AlterGroupStmt *from)
2348 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2350 COPY_STRING_FIELD(name);
2351 COPY_SCALAR_FIELD(action);
2352 COPY_NODE_FIELD(listUsers);
2357 static DropGroupStmt *
2358 _copyDropGroupStmt(DropGroupStmt *from)
2360 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2362 COPY_STRING_FIELD(name);
2367 static ReindexStmt *
2368 _copyReindexStmt(ReindexStmt *from)
2370 ReindexStmt *newnode = makeNode(ReindexStmt);
2372 COPY_SCALAR_FIELD(kind);
2373 COPY_NODE_FIELD(relation);
2374 COPY_STRING_FIELD(name);
2375 COPY_SCALAR_FIELD(force);
2376 COPY_SCALAR_FIELD(all);
2381 static CreateSchemaStmt *
2382 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2384 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2386 COPY_STRING_FIELD(schemaname);
2387 COPY_STRING_FIELD(authid);
2388 COPY_NODE_FIELD(schemaElts);
2393 static CreateConversionStmt *
2394 _copyCreateConversionStmt(CreateConversionStmt *from)
2396 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2398 COPY_NODE_FIELD(conversion_name);
2399 COPY_STRING_FIELD(for_encoding_name);
2400 COPY_STRING_FIELD(to_encoding_name);
2401 COPY_NODE_FIELD(func_name);
2402 COPY_SCALAR_FIELD(def);
2407 static CreateCastStmt *
2408 _copyCreateCastStmt(CreateCastStmt *from)
2410 CreateCastStmt *newnode = makeNode(CreateCastStmt);
2412 COPY_NODE_FIELD(sourcetype);
2413 COPY_NODE_FIELD(targettype);
2414 COPY_NODE_FIELD(func);
2415 COPY_SCALAR_FIELD(context);
2420 static DropCastStmt *
2421 _copyDropCastStmt(DropCastStmt *from)
2423 DropCastStmt *newnode = makeNode(DropCastStmt);
2425 COPY_NODE_FIELD(sourcetype);
2426 COPY_NODE_FIELD(targettype);
2427 COPY_SCALAR_FIELD(behavior);
2432 static PrepareStmt *
2433 _copyPrepareStmt(PrepareStmt *from)
2435 PrepareStmt *newnode = makeNode(PrepareStmt);
2437 COPY_STRING_FIELD(name);
2438 COPY_NODE_FIELD(argtypes);
2439 COPY_OIDLIST_FIELD(argtype_oids);
2440 COPY_NODE_FIELD(query);
2445 static ExecuteStmt *
2446 _copyExecuteStmt(ExecuteStmt *from)
2448 ExecuteStmt *newnode = makeNode(ExecuteStmt);
2450 COPY_STRING_FIELD(name);
2451 COPY_NODE_FIELD(into);
2452 COPY_NODE_FIELD(params);
2457 static DeallocateStmt *
2458 _copyDeallocateStmt(DeallocateStmt *from)
2460 DeallocateStmt *newnode = makeNode(DeallocateStmt);
2462 COPY_STRING_FIELD(name);
2468 /* ****************************************************************
2469 * pg_list.h copy functions
2470 * ****************************************************************
2474 _copyValue(Value *from)
2476 Value *newnode = makeNode(Value);
2478 /* See also _copyAConst when changing this code! */
2480 COPY_SCALAR_FIELD(type);
2484 COPY_SCALAR_FIELD(val.ival);
2489 COPY_STRING_FIELD(val.str);
2495 elog(ERROR, "unrecognized node type: %d",
2505 * Create a copy of a Node tree or list. This is a "deep" copy: all
2506 * substructure is copied too, recursively.
2509 copyObject(void *from)
2516 switch (nodeTag(from))
2522 retval = _copyPlan(from);
2525 retval = _copyResult(from);
2528 retval = _copyAppend(from);
2531 retval = _copyScan(from);
2534 retval = _copySeqScan(from);
2537 retval = _copyIndexScan(from);
2540 retval = _copyTidScan(from);
2542 case T_SubqueryScan:
2543 retval = _copySubqueryScan(from);
2545 case T_FunctionScan:
2546 retval = _copyFunctionScan(from);
2549 retval = _copyJoin(from);
2552 retval = _copyNestLoop(from);
2555 retval = _copyMergeJoin(from);
2558 retval = _copyHashJoin(from);
2561 retval = _copyMaterial(from);
2564 retval = _copySort(from);
2567 retval = _copyGroup(from);
2570 retval = _copyAgg(from);
2573 retval = _copyUnique(from);
2576 retval = _copyHash(from);
2579 retval = _copySetOp(from);
2582 retval = _copyLimit(from);
2589 retval = _copyResdom(from);
2592 retval = _copyAlias(from);
2595 retval = _copyRangeVar(from);
2598 retval = _copyVar(from);
2601 retval = _copyConst(from);
2604 retval = _copyParam(from);
2607 retval = _copyAggref(from);
2610 retval = _copyArrayRef(from);
2613 retval = _copyFuncExpr(from);
2616 retval = _copyOpExpr(from);
2618 case T_DistinctExpr:
2619 retval = _copyDistinctExpr(from);
2621 case T_ScalarArrayOpExpr:
2622 retval = _copyScalarArrayOpExpr(from);
2625 retval = _copyBoolExpr(from);
2628 retval = _copySubLink(from);
2631 retval = _copySubPlan(from);
2634 retval = _copyFieldSelect(from);
2637 retval = _copyRelabelType(from);
2640 retval = _copyCaseExpr(from);
2643 retval = _copyCaseWhen(from);
2646 retval = _copyArrayExpr(from);
2648 case T_CoalesceExpr:
2649 retval = _copyCoalesceExpr(from);
2652 retval = _copyNullIfExpr(from);
2655 retval = _copyNullTest(from);
2658 retval = _copyBooleanTest(from);
2660 case T_CoerceToDomain:
2661 retval = _copyCoerceToDomain(from);
2663 case T_CoerceToDomainValue:
2664 retval = _copyCoerceToDomainValue(from);
2666 case T_SetToDefault:
2667 retval = _copySetToDefault(from);
2670 retval = _copyTargetEntry(from);
2673 retval = _copyRangeTblRef(from);
2676 retval = _copyJoinExpr(from);
2679 retval = _copyFromExpr(from);
2686 retval = _copyPathKeyItem(from);
2688 case T_RestrictInfo:
2689 retval = _copyRestrictInfo(from);
2692 retval = _copyJoinInfo(from);
2694 case T_InClauseInfo:
2695 retval = _copyInClauseInfo(from);
2706 retval = _copyValue(from);
2715 /* rather ugly coding for speed... */
2716 /* Note the input list cannot be NIL if we got here. */
2717 newcell = makeNode(List);
2718 lfirst(newcell) = copyObject(lfirst(list));
2720 retval = (void *) newcell;
2723 foreach(oldl, lnext(list))
2725 newcell = makeNode(List);
2726 lfirst(newcell) = copyObject(lfirst(oldl));
2727 prev->next = newcell;
2738 retval = _copyQuery(from);
2741 retval = _copyInsertStmt(from);
2744 retval = _copyDeleteStmt(from);
2747 retval = _copyUpdateStmt(from);
2750 retval = _copySelectStmt(from);
2752 case T_SetOperationStmt:
2753 retval = _copySetOperationStmt(from);
2755 case T_AlterTableStmt:
2756 retval = _copyAlterTableStmt(from);
2758 case T_AlterDomainStmt:
2759 retval = _copyAlterDomainStmt(from);
2762 retval = _copyGrantStmt(from);
2764 case T_DeclareCursorStmt:
2765 retval = _copyDeclareCursorStmt(from);
2767 case T_ClosePortalStmt:
2768 retval = _copyClosePortalStmt(from);
2771 retval = _copyClusterStmt(from);
2774 retval = _copyCopyStmt(from);
2777 retval = _copyCreateStmt(from);
2780 retval = _copyInhRelation(from);
2783 retval = _copyDefineStmt(from);
2786 retval = _copyDropStmt(from);
2788 case T_TruncateStmt:
2789 retval = _copyTruncateStmt(from);
2792 retval = _copyCommentStmt(from);
2795 retval = _copyFetchStmt(from);
2798 retval = _copyIndexStmt(from);
2800 case T_CreateFunctionStmt:
2801 retval = _copyCreateFunctionStmt(from);
2803 case T_FunctionParameter:
2804 retval = _copyFunctionParameter(from);
2806 case T_RemoveAggrStmt:
2807 retval = _copyRemoveAggrStmt(from);
2809 case T_RemoveFuncStmt:
2810 retval = _copyRemoveFuncStmt(from);
2812 case T_RemoveOperStmt:
2813 retval = _copyRemoveOperStmt(from);
2815 case T_RemoveOpClassStmt:
2816 retval = _copyRemoveOpClassStmt(from);
2819 retval = _copyRenameStmt(from);
2822 retval = _copyRuleStmt(from);
2825 retval = _copyNotifyStmt(from);
2828 retval = _copyListenStmt(from);
2830 case T_UnlistenStmt:
2831 retval = _copyUnlistenStmt(from);
2833 case T_TransactionStmt:
2834 retval = _copyTransactionStmt(from);
2836 case T_CompositeTypeStmt:
2837 retval = _copyCompositeTypeStmt(from);
2840 retval = _copyViewStmt(from);
2843 retval = _copyLoadStmt(from);
2845 case T_CreateDomainStmt:
2846 retval = _copyCreateDomainStmt(from);
2848 case T_CreateOpClassStmt:
2849 retval = _copyCreateOpClassStmt(from);
2851 case T_CreateOpClassItem:
2852 retval = _copyCreateOpClassItem(from);
2854 case T_CreatedbStmt:
2855 retval = _copyCreatedbStmt(from);
2857 case T_AlterDatabaseSetStmt:
2858 retval = _copyAlterDatabaseSetStmt(from);
2861 retval = _copyDropdbStmt(from);
2864 retval = _copyVacuumStmt(from);
2867 retval = _copyExplainStmt(from);
2869 case T_CreateSeqStmt:
2870 retval = _copyCreateSeqStmt(from);
2872 case T_AlterSeqStmt:
2873 retval = _copyAlterSeqStmt(from);
2875 case T_VariableSetStmt:
2876 retval = _copyVariableSetStmt(from);
2878 case T_VariableShowStmt:
2879 retval = _copyVariableShowStmt(from);
2881 case T_VariableResetStmt:
2882 retval = _copyVariableResetStmt(from);
2884 case T_CreateTrigStmt:
2885 retval = _copyCreateTrigStmt(from);
2887 case T_DropPropertyStmt:
2888 retval = _copyDropPropertyStmt(from);
2890 case T_CreatePLangStmt:
2891 retval = _copyCreatePLangStmt(from);
2893 case T_DropPLangStmt:
2894 retval = _copyDropPLangStmt(from);
2896 case T_CreateUserStmt:
2897 retval = _copyCreateUserStmt(from);
2899 case T_AlterUserStmt:
2900 retval = _copyAlterUserStmt(from);
2902 case T_AlterUserSetStmt:
2903 retval = _copyAlterUserSetStmt(from);
2905 case T_DropUserStmt:
2906 retval = _copyDropUserStmt(from);
2909 retval = _copyLockStmt(from);
2911 case T_ConstraintsSetStmt:
2912 retval = _copyConstraintsSetStmt(from);
2914 case T_CreateGroupStmt:
2915 retval = _copyCreateGroupStmt(from);
2917 case T_AlterGroupStmt:
2918 retval = _copyAlterGroupStmt(from);
2920 case T_DropGroupStmt:
2921 retval = _copyDropGroupStmt(from);
2924 retval = _copyReindexStmt(from);
2926 case T_CheckPointStmt:
2927 retval = (void *) makeNode(CheckPointStmt);
2929 case T_CreateSchemaStmt:
2930 retval = _copyCreateSchemaStmt(from);
2932 case T_CreateConversionStmt:
2933 retval = _copyCreateConversionStmt(from);
2935 case T_CreateCastStmt:
2936 retval = _copyCreateCastStmt(from);
2938 case T_DropCastStmt:
2939 retval = _copyDropCastStmt(from);
2942 retval = _copyPrepareStmt(from);
2945 retval = _copyExecuteStmt(from);
2947 case T_DeallocateStmt:
2948 retval = _copyDeallocateStmt(from);
2952 retval = _copyAExpr(from);
2955 retval = _copyColumnRef(from);
2958 retval = _copyParamRef(from);
2961 retval = _copyAConst(from);
2964 retval = _copyFuncCall(from);
2967 retval = _copyAIndices(from);
2969 case T_ExprFieldSelect:
2970 retval = _copyExprFieldSelect(from);
2973 retval = _copyResTarget(from);
2976 retval = _copyTypeCast(from);
2979 retval = _copySortBy(from);
2981 case T_RangeSubselect:
2982 retval = _copyRangeSubselect(from);
2984 case T_RangeFunction:
2985 retval = _copyRangeFunction(from);
2988 retval = _copyTypeName(from);
2991 retval = _copyIndexElem(from);
2994 retval = _copyColumnDef(from);
2997 retval = _copyConstraint(from);
3000 retval = _copyDefElem(from);
3002 case T_RangeTblEntry:
3003 retval = _copyRangeTblEntry(from);
3006 retval = _copySortClause(from);
3009 retval = _copyGroupClause(from);
3011 case T_FkConstraint:
3012 retval = _copyFkConstraint(from);
3015 retval = _copyPrivGrantee(from);
3017 case T_FuncWithArgs:
3018 retval = _copyFuncWithArgs(from);
3022 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
3023 retval = from; /* keep compiler quiet */