Add vacuum_freeze_table_age GUC option, to control when VACUUM should
[PostgreSQL.git] / src / backend / nodes / copyfuncs.c
blob0c7140cca113a676667008c0da15ef7e5c87020f
1 /*-------------------------------------------------------------------------
3 * copyfuncs.c
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-2009, PostgreSQL Global Development Group
15 * Portions Copyright (c) 1994, Regents of the University of California
17 * IDENTIFICATION
18 * $PostgreSQL$
20 *-------------------------------------------------------------------------
23 #include "postgres.h"
25 #include "nodes/plannodes.h"
26 #include "nodes/relation.h"
27 #include "utils/datum.h"
31 * Macros to simplify copying of different kinds of fields. Use these
32 * wherever possible to reduce the chance for silly typos. Note that these
33 * hard-wire the convention that the local variables in a Copy routine are
34 * named 'newnode' and 'from'.
37 /* Copy a simple scalar field (int, float, bool, enum, etc) */
38 #define COPY_SCALAR_FIELD(fldname) \
39 (newnode->fldname = from->fldname)
41 /* Copy a field that is a pointer to some kind of Node or Node tree */
42 #define COPY_NODE_FIELD(fldname) \
43 (newnode->fldname = copyObject(from->fldname))
45 /* Copy a field that is a pointer to a Bitmapset */
46 #define COPY_BITMAPSET_FIELD(fldname) \
47 (newnode->fldname = bms_copy(from->fldname))
49 /* Copy a field that is a pointer to a C string, or perhaps NULL */
50 #define COPY_STRING_FIELD(fldname) \
51 (newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)
53 /* Copy a field that is a pointer to a simple palloc'd object of size sz */
54 #define COPY_POINTER_FIELD(fldname, sz) \
55 do { \
56 Size _size = (sz); \
57 newnode->fldname = palloc(_size); \
58 memcpy(newnode->fldname, from->fldname, _size); \
59 } while (0)
61 /* Copy a parse location field (for Copy, this is same as scalar case) */
62 #define COPY_LOCATION_FIELD(fldname) \
63 (newnode->fldname = from->fldname)
66 /* ****************************************************************
67 * plannodes.h copy functions
68 * ****************************************************************
72 * _copyPlannedStmt
74 static PlannedStmt *
75 _copyPlannedStmt(PlannedStmt *from)
77 PlannedStmt *newnode = makeNode(PlannedStmt);
79 COPY_SCALAR_FIELD(commandType);
80 COPY_SCALAR_FIELD(canSetTag);
81 COPY_NODE_FIELD(planTree);
82 COPY_NODE_FIELD(rtable);
83 COPY_NODE_FIELD(resultRelations);
84 COPY_NODE_FIELD(utilityStmt);
85 COPY_NODE_FIELD(intoClause);
86 COPY_NODE_FIELD(subplans);
87 COPY_BITMAPSET_FIELD(rewindPlanIDs);
88 COPY_NODE_FIELD(returningLists);
89 COPY_NODE_FIELD(rowMarks);
90 COPY_NODE_FIELD(relationOids);
91 COPY_NODE_FIELD(invalItems);
92 COPY_SCALAR_FIELD(nParamExec);
94 return newnode;
98 * CopyPlanFields
100 * This function copies the fields of the Plan node. It is used by
101 * all the copy functions for classes which inherit from Plan.
103 static void
104 CopyPlanFields(Plan *from, Plan *newnode)
106 COPY_SCALAR_FIELD(startup_cost);
107 COPY_SCALAR_FIELD(total_cost);
108 COPY_SCALAR_FIELD(plan_rows);
109 COPY_SCALAR_FIELD(plan_width);
110 COPY_NODE_FIELD(targetlist);
111 COPY_NODE_FIELD(qual);
112 COPY_NODE_FIELD(lefttree);
113 COPY_NODE_FIELD(righttree);
114 COPY_NODE_FIELD(initPlan);
115 COPY_BITMAPSET_FIELD(extParam);
116 COPY_BITMAPSET_FIELD(allParam);
120 * _copyPlan
122 static Plan *
123 _copyPlan(Plan *from)
125 Plan *newnode = makeNode(Plan);
128 * copy node superclass fields
130 CopyPlanFields(from, newnode);
132 return newnode;
137 * _copyResult
139 static Result *
140 _copyResult(Result *from)
142 Result *newnode = makeNode(Result);
145 * copy node superclass fields
147 CopyPlanFields((Plan *) from, (Plan *) newnode);
150 * copy remainder of node
152 COPY_NODE_FIELD(resconstantqual);
154 return newnode;
158 * _copyAppend
160 static Append *
161 _copyAppend(Append *from)
163 Append *newnode = makeNode(Append);
166 * copy node superclass fields
168 CopyPlanFields((Plan *) from, (Plan *) newnode);
171 * copy remainder of node
173 COPY_NODE_FIELD(appendplans);
174 COPY_SCALAR_FIELD(isTarget);
176 return newnode;
180 * _copyRecursiveUnion
182 static RecursiveUnion *
183 _copyRecursiveUnion(RecursiveUnion *from)
185 RecursiveUnion *newnode = makeNode(RecursiveUnion);
188 * copy node superclass fields
190 CopyPlanFields((Plan *) from, (Plan *) newnode);
193 * copy remainder of node
195 COPY_SCALAR_FIELD(wtParam);
196 COPY_SCALAR_FIELD(numCols);
197 if (from->numCols > 0)
199 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
200 COPY_POINTER_FIELD(dupOperators, from->numCols * sizeof(Oid));
202 COPY_SCALAR_FIELD(numGroups);
204 return newnode;
208 * _copyBitmapAnd
210 static BitmapAnd *
211 _copyBitmapAnd(BitmapAnd *from)
213 BitmapAnd *newnode = makeNode(BitmapAnd);
216 * copy node superclass fields
218 CopyPlanFields((Plan *) from, (Plan *) newnode);
221 * copy remainder of node
223 COPY_NODE_FIELD(bitmapplans);
225 return newnode;
229 * _copyBitmapOr
231 static BitmapOr *
232 _copyBitmapOr(BitmapOr *from)
234 BitmapOr *newnode = makeNode(BitmapOr);
237 * copy node superclass fields
239 CopyPlanFields((Plan *) from, (Plan *) newnode);
242 * copy remainder of node
244 COPY_NODE_FIELD(bitmapplans);
246 return newnode;
251 * CopyScanFields
253 * This function copies the fields of the Scan node. It is used by
254 * all the copy functions for classes which inherit from Scan.
256 static void
257 CopyScanFields(Scan *from, Scan *newnode)
259 CopyPlanFields((Plan *) from, (Plan *) newnode);
261 COPY_SCALAR_FIELD(scanrelid);
265 * _copyScan
267 static Scan *
268 _copyScan(Scan *from)
270 Scan *newnode = makeNode(Scan);
273 * copy node superclass fields
275 CopyScanFields((Scan *) from, (Scan *) newnode);
277 return newnode;
281 * _copySeqScan
283 static SeqScan *
284 _copySeqScan(SeqScan *from)
286 SeqScan *newnode = makeNode(SeqScan);
289 * copy node superclass fields
291 CopyScanFields((Scan *) from, (Scan *) newnode);
293 return newnode;
297 * _copyIndexScan
299 static IndexScan *
300 _copyIndexScan(IndexScan *from)
302 IndexScan *newnode = makeNode(IndexScan);
305 * copy node superclass fields
307 CopyScanFields((Scan *) from, (Scan *) newnode);
310 * copy remainder of node
312 COPY_SCALAR_FIELD(indexid);
313 COPY_NODE_FIELD(indexqual);
314 COPY_NODE_FIELD(indexqualorig);
315 COPY_SCALAR_FIELD(indexorderdir);
317 return newnode;
321 * _copyBitmapIndexScan
323 static BitmapIndexScan *
324 _copyBitmapIndexScan(BitmapIndexScan *from)
326 BitmapIndexScan *newnode = makeNode(BitmapIndexScan);
329 * copy node superclass fields
331 CopyScanFields((Scan *) from, (Scan *) newnode);
334 * copy remainder of node
336 COPY_SCALAR_FIELD(indexid);
337 COPY_NODE_FIELD(indexqual);
338 COPY_NODE_FIELD(indexqualorig);
340 return newnode;
344 * _copyBitmapHeapScan
346 static BitmapHeapScan *
347 _copyBitmapHeapScan(BitmapHeapScan *from)
349 BitmapHeapScan *newnode = makeNode(BitmapHeapScan);
352 * copy node superclass fields
354 CopyScanFields((Scan *) from, (Scan *) newnode);
357 * copy remainder of node
359 COPY_NODE_FIELD(bitmapqualorig);
361 return newnode;
365 * _copyTidScan
367 static TidScan *
368 _copyTidScan(TidScan *from)
370 TidScan *newnode = makeNode(TidScan);
373 * copy node superclass fields
375 CopyScanFields((Scan *) from, (Scan *) newnode);
378 * copy remainder of node
380 COPY_NODE_FIELD(tidquals);
382 return newnode;
386 * _copySubqueryScan
388 static SubqueryScan *
389 _copySubqueryScan(SubqueryScan *from)
391 SubqueryScan *newnode = makeNode(SubqueryScan);
394 * copy node superclass fields
396 CopyScanFields((Scan *) from, (Scan *) newnode);
399 * copy remainder of node
401 COPY_NODE_FIELD(subplan);
402 COPY_NODE_FIELD(subrtable);
404 return newnode;
408 * _copyFunctionScan
410 static FunctionScan *
411 _copyFunctionScan(FunctionScan *from)
413 FunctionScan *newnode = makeNode(FunctionScan);
416 * copy node superclass fields
418 CopyScanFields((Scan *) from, (Scan *) newnode);
421 * copy remainder of node
423 COPY_NODE_FIELD(funcexpr);
424 COPY_NODE_FIELD(funccolnames);
425 COPY_NODE_FIELD(funccoltypes);
426 COPY_NODE_FIELD(funccoltypmods);
428 return newnode;
432 * _copyValuesScan
434 static ValuesScan *
435 _copyValuesScan(ValuesScan *from)
437 ValuesScan *newnode = makeNode(ValuesScan);
440 * copy node superclass fields
442 CopyScanFields((Scan *) from, (Scan *) newnode);
445 * copy remainder of node
447 COPY_NODE_FIELD(values_lists);
449 return newnode;
453 * _copyCteScan
455 static CteScan *
456 _copyCteScan(CteScan *from)
458 CteScan *newnode = makeNode(CteScan);
461 * copy node superclass fields
463 CopyScanFields((Scan *) from, (Scan *) newnode);
466 * copy remainder of node
468 COPY_SCALAR_FIELD(ctePlanId);
469 COPY_SCALAR_FIELD(cteParam);
471 return newnode;
475 * _copyWorkTableScan
477 static WorkTableScan *
478 _copyWorkTableScan(WorkTableScan *from)
480 WorkTableScan *newnode = makeNode(WorkTableScan);
483 * copy node superclass fields
485 CopyScanFields((Scan *) from, (Scan *) newnode);
488 * copy remainder of node
490 COPY_SCALAR_FIELD(wtParam);
492 return newnode;
496 * CopyJoinFields
498 * This function copies the fields of the Join node. It is used by
499 * all the copy functions for classes which inherit from Join.
501 static void
502 CopyJoinFields(Join *from, Join *newnode)
504 CopyPlanFields((Plan *) from, (Plan *) newnode);
506 COPY_SCALAR_FIELD(jointype);
507 COPY_NODE_FIELD(joinqual);
512 * _copyJoin
514 static Join *
515 _copyJoin(Join *from)
517 Join *newnode = makeNode(Join);
520 * copy node superclass fields
522 CopyJoinFields(from, newnode);
524 return newnode;
529 * _copyNestLoop
531 static NestLoop *
532 _copyNestLoop(NestLoop *from)
534 NestLoop *newnode = makeNode(NestLoop);
537 * copy node superclass fields
539 CopyJoinFields((Join *) from, (Join *) newnode);
541 return newnode;
546 * _copyMergeJoin
548 static MergeJoin *
549 _copyMergeJoin(MergeJoin *from)
551 MergeJoin *newnode = makeNode(MergeJoin);
552 int numCols;
555 * copy node superclass fields
557 CopyJoinFields((Join *) from, (Join *) newnode);
560 * copy remainder of node
562 COPY_NODE_FIELD(mergeclauses);
563 numCols = list_length(from->mergeclauses);
564 COPY_POINTER_FIELD(mergeFamilies, numCols * sizeof(Oid));
565 COPY_POINTER_FIELD(mergeStrategies, numCols * sizeof(int));
566 COPY_POINTER_FIELD(mergeNullsFirst, numCols * sizeof(bool));
568 return newnode;
572 * _copyHashJoin
574 static HashJoin *
575 _copyHashJoin(HashJoin *from)
577 HashJoin *newnode = makeNode(HashJoin);
580 * copy node superclass fields
582 CopyJoinFields((Join *) from, (Join *) newnode);
585 * copy remainder of node
587 COPY_NODE_FIELD(hashclauses);
589 return newnode;
594 * _copyMaterial
596 static Material *
597 _copyMaterial(Material *from)
599 Material *newnode = makeNode(Material);
602 * copy node superclass fields
604 CopyPlanFields((Plan *) from, (Plan *) newnode);
606 return newnode;
611 * _copySort
613 static Sort *
614 _copySort(Sort *from)
616 Sort *newnode = makeNode(Sort);
619 * copy node superclass fields
621 CopyPlanFields((Plan *) from, (Plan *) newnode);
623 COPY_SCALAR_FIELD(numCols);
624 COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
625 COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
626 COPY_POINTER_FIELD(nullsFirst, from->numCols * sizeof(bool));
628 return newnode;
633 * _copyGroup
635 static Group *
636 _copyGroup(Group *from)
638 Group *newnode = makeNode(Group);
640 CopyPlanFields((Plan *) from, (Plan *) newnode);
642 COPY_SCALAR_FIELD(numCols);
643 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
644 COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
646 return newnode;
650 * _copyAgg
652 static Agg *
653 _copyAgg(Agg *from)
655 Agg *newnode = makeNode(Agg);
657 CopyPlanFields((Plan *) from, (Plan *) newnode);
659 COPY_SCALAR_FIELD(aggstrategy);
660 COPY_SCALAR_FIELD(numCols);
661 if (from->numCols > 0)
663 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
664 COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
666 COPY_SCALAR_FIELD(numGroups);
668 return newnode;
672 * _copyWindowAgg
674 static WindowAgg *
675 _copyWindowAgg(WindowAgg *from)
677 WindowAgg *newnode = makeNode(WindowAgg);
679 CopyPlanFields((Plan *) from, (Plan *) newnode);
681 COPY_SCALAR_FIELD(winref);
682 COPY_SCALAR_FIELD(partNumCols);
683 if (from->partNumCols > 0)
685 COPY_POINTER_FIELD(partColIdx, from->partNumCols * sizeof(AttrNumber));
686 COPY_POINTER_FIELD(partOperators, from->partNumCols * sizeof(Oid));
688 COPY_SCALAR_FIELD(ordNumCols);
689 if (from->ordNumCols > 0)
691 COPY_POINTER_FIELD(ordColIdx, from->ordNumCols * sizeof(AttrNumber));
692 COPY_POINTER_FIELD(ordOperators, from->ordNumCols * sizeof(Oid));
694 COPY_SCALAR_FIELD(frameOptions);
696 return newnode;
700 * _copyUnique
702 static Unique *
703 _copyUnique(Unique *from)
705 Unique *newnode = makeNode(Unique);
708 * copy node superclass fields
710 CopyPlanFields((Plan *) from, (Plan *) newnode);
713 * copy remainder of node
715 COPY_SCALAR_FIELD(numCols);
716 COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
717 COPY_POINTER_FIELD(uniqOperators, from->numCols * sizeof(Oid));
719 return newnode;
723 * _copyHash
725 static Hash *
726 _copyHash(Hash *from)
728 Hash *newnode = makeNode(Hash);
731 * copy node superclass fields
733 CopyPlanFields((Plan *) from, (Plan *) newnode);
736 * copy remainder of node
739 return newnode;
743 * _copySetOp
745 static SetOp *
746 _copySetOp(SetOp *from)
748 SetOp *newnode = makeNode(SetOp);
751 * copy node superclass fields
753 CopyPlanFields((Plan *) from, (Plan *) newnode);
756 * copy remainder of node
758 COPY_SCALAR_FIELD(cmd);
759 COPY_SCALAR_FIELD(strategy);
760 COPY_SCALAR_FIELD(numCols);
761 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
762 COPY_POINTER_FIELD(dupOperators, from->numCols * sizeof(Oid));
763 COPY_SCALAR_FIELD(flagColIdx);
764 COPY_SCALAR_FIELD(firstFlag);
765 COPY_SCALAR_FIELD(numGroups);
767 return newnode;
771 * _copyLimit
773 static Limit *
774 _copyLimit(Limit *from)
776 Limit *newnode = makeNode(Limit);
779 * copy node superclass fields
781 CopyPlanFields((Plan *) from, (Plan *) newnode);
784 * copy remainder of node
786 COPY_NODE_FIELD(limitOffset);
787 COPY_NODE_FIELD(limitCount);
789 return newnode;
793 * _copyPlanInvalItem
795 static PlanInvalItem *
796 _copyPlanInvalItem(PlanInvalItem *from)
798 PlanInvalItem *newnode = makeNode(PlanInvalItem);
800 COPY_SCALAR_FIELD(cacheId);
801 /* tupleId isn't really a "scalar", but this works anyway */
802 COPY_SCALAR_FIELD(tupleId);
804 return newnode;
807 /* ****************************************************************
808 * primnodes.h copy functions
809 * ****************************************************************
813 * _copyAlias
815 static Alias *
816 _copyAlias(Alias *from)
818 Alias *newnode = makeNode(Alias);
820 COPY_STRING_FIELD(aliasname);
821 COPY_NODE_FIELD(colnames);
823 return newnode;
827 * _copyRangeVar
829 static RangeVar *
830 _copyRangeVar(RangeVar *from)
832 RangeVar *newnode = makeNode(RangeVar);
834 COPY_STRING_FIELD(catalogname);
835 COPY_STRING_FIELD(schemaname);
836 COPY_STRING_FIELD(relname);
837 COPY_SCALAR_FIELD(inhOpt);
838 COPY_SCALAR_FIELD(istemp);
839 COPY_NODE_FIELD(alias);
840 COPY_LOCATION_FIELD(location);
842 return newnode;
846 * _copyIntoClause
848 static IntoClause *
849 _copyIntoClause(IntoClause *from)
851 IntoClause *newnode = makeNode(IntoClause);
853 COPY_NODE_FIELD(rel);
854 COPY_NODE_FIELD(colNames);
855 COPY_NODE_FIELD(options);
856 COPY_SCALAR_FIELD(onCommit);
857 COPY_STRING_FIELD(tableSpaceName);
859 return newnode;
863 * We don't need a _copyExpr because Expr is an abstract supertype which
864 * should never actually get instantiated. Also, since it has no common
865 * fields except NodeTag, there's no need for a helper routine to factor
866 * out copying the common fields...
870 * _copyVar
872 static Var *
873 _copyVar(Var *from)
875 Var *newnode = makeNode(Var);
877 COPY_SCALAR_FIELD(varno);
878 COPY_SCALAR_FIELD(varattno);
879 COPY_SCALAR_FIELD(vartype);
880 COPY_SCALAR_FIELD(vartypmod);
881 COPY_SCALAR_FIELD(varlevelsup);
882 COPY_SCALAR_FIELD(varnoold);
883 COPY_SCALAR_FIELD(varoattno);
884 COPY_LOCATION_FIELD(location);
886 return newnode;
890 * _copyConst
892 static Const *
893 _copyConst(Const *from)
895 Const *newnode = makeNode(Const);
897 COPY_SCALAR_FIELD(consttype);
898 COPY_SCALAR_FIELD(consttypmod);
899 COPY_SCALAR_FIELD(constlen);
901 if (from->constbyval || from->constisnull)
904 * passed by value so just copy the datum. Also, don't try to copy
905 * struct when value is null!
907 newnode->constvalue = from->constvalue;
909 else
912 * passed by reference. We need a palloc'd copy.
914 newnode->constvalue = datumCopy(from->constvalue,
915 from->constbyval,
916 from->constlen);
919 COPY_SCALAR_FIELD(constisnull);
920 COPY_SCALAR_FIELD(constbyval);
921 COPY_LOCATION_FIELD(location);
923 return newnode;
927 * _copyParam
929 static Param *
930 _copyParam(Param *from)
932 Param *newnode = makeNode(Param);
934 COPY_SCALAR_FIELD(paramkind);
935 COPY_SCALAR_FIELD(paramid);
936 COPY_SCALAR_FIELD(paramtype);
937 COPY_SCALAR_FIELD(paramtypmod);
938 COPY_LOCATION_FIELD(location);
940 return newnode;
944 * _copyAggref
946 static Aggref *
947 _copyAggref(Aggref *from)
949 Aggref *newnode = makeNode(Aggref);
951 COPY_SCALAR_FIELD(aggfnoid);
952 COPY_SCALAR_FIELD(aggtype);
953 COPY_NODE_FIELD(args);
954 COPY_SCALAR_FIELD(agglevelsup);
955 COPY_SCALAR_FIELD(aggstar);
956 COPY_SCALAR_FIELD(aggdistinct);
957 COPY_LOCATION_FIELD(location);
959 return newnode;
963 * _copyWindowFunc
965 static WindowFunc *
966 _copyWindowFunc(WindowFunc *from)
968 WindowFunc *newnode = makeNode(WindowFunc);
970 COPY_SCALAR_FIELD(winfnoid);
971 COPY_SCALAR_FIELD(wintype);
972 COPY_NODE_FIELD(args);
973 COPY_SCALAR_FIELD(winref);
974 COPY_SCALAR_FIELD(winstar);
975 COPY_SCALAR_FIELD(winagg);
976 COPY_LOCATION_FIELD(location);
978 return newnode;
982 * _copyArrayRef
984 static ArrayRef *
985 _copyArrayRef(ArrayRef *from)
987 ArrayRef *newnode = makeNode(ArrayRef);
989 COPY_SCALAR_FIELD(refarraytype);
990 COPY_SCALAR_FIELD(refelemtype);
991 COPY_SCALAR_FIELD(reftypmod);
992 COPY_NODE_FIELD(refupperindexpr);
993 COPY_NODE_FIELD(reflowerindexpr);
994 COPY_NODE_FIELD(refexpr);
995 COPY_NODE_FIELD(refassgnexpr);
997 return newnode;
1001 * _copyFuncExpr
1003 static FuncExpr *
1004 _copyFuncExpr(FuncExpr *from)
1006 FuncExpr *newnode = makeNode(FuncExpr);
1008 COPY_SCALAR_FIELD(funcid);
1009 COPY_SCALAR_FIELD(funcresulttype);
1010 COPY_SCALAR_FIELD(funcretset);
1011 COPY_SCALAR_FIELD(funcformat);
1012 COPY_NODE_FIELD(args);
1013 COPY_LOCATION_FIELD(location);
1015 return newnode;
1019 * _copyOpExpr
1021 static OpExpr *
1022 _copyOpExpr(OpExpr *from)
1024 OpExpr *newnode = makeNode(OpExpr);
1026 COPY_SCALAR_FIELD(opno);
1027 COPY_SCALAR_FIELD(opfuncid);
1028 COPY_SCALAR_FIELD(opresulttype);
1029 COPY_SCALAR_FIELD(opretset);
1030 COPY_NODE_FIELD(args);
1031 COPY_LOCATION_FIELD(location);
1033 return newnode;
1037 * _copyDistinctExpr (same as OpExpr)
1039 static DistinctExpr *
1040 _copyDistinctExpr(DistinctExpr *from)
1042 DistinctExpr *newnode = makeNode(DistinctExpr);
1044 COPY_SCALAR_FIELD(opno);
1045 COPY_SCALAR_FIELD(opfuncid);
1046 COPY_SCALAR_FIELD(opresulttype);
1047 COPY_SCALAR_FIELD(opretset);
1048 COPY_NODE_FIELD(args);
1049 COPY_LOCATION_FIELD(location);
1051 return newnode;
1055 * _copyScalarArrayOpExpr
1057 static ScalarArrayOpExpr *
1058 _copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
1060 ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
1062 COPY_SCALAR_FIELD(opno);
1063 COPY_SCALAR_FIELD(opfuncid);
1064 COPY_SCALAR_FIELD(useOr);
1065 COPY_NODE_FIELD(args);
1066 COPY_LOCATION_FIELD(location);
1068 return newnode;
1072 * _copyBoolExpr
1074 static BoolExpr *
1075 _copyBoolExpr(BoolExpr *from)
1077 BoolExpr *newnode = makeNode(BoolExpr);
1079 COPY_SCALAR_FIELD(boolop);
1080 COPY_NODE_FIELD(args);
1081 COPY_LOCATION_FIELD(location);
1083 return newnode;
1087 * _copySubLink
1089 static SubLink *
1090 _copySubLink(SubLink *from)
1092 SubLink *newnode = makeNode(SubLink);
1094 COPY_SCALAR_FIELD(subLinkType);
1095 COPY_NODE_FIELD(testexpr);
1096 COPY_NODE_FIELD(operName);
1097 COPY_NODE_FIELD(subselect);
1098 COPY_LOCATION_FIELD(location);
1100 return newnode;
1104 * _copySubPlan
1106 static SubPlan *
1107 _copySubPlan(SubPlan *from)
1109 SubPlan *newnode = makeNode(SubPlan);
1111 COPY_SCALAR_FIELD(subLinkType);
1112 COPY_NODE_FIELD(testexpr);
1113 COPY_NODE_FIELD(paramIds);
1114 COPY_SCALAR_FIELD(plan_id);
1115 COPY_SCALAR_FIELD(firstColType);
1116 COPY_SCALAR_FIELD(useHashTable);
1117 COPY_SCALAR_FIELD(unknownEqFalse);
1118 COPY_NODE_FIELD(setParam);
1119 COPY_NODE_FIELD(parParam);
1120 COPY_NODE_FIELD(args);
1121 COPY_SCALAR_FIELD(startup_cost);
1122 COPY_SCALAR_FIELD(per_call_cost);
1124 return newnode;
1128 * _copyAlternativeSubPlan
1130 static AlternativeSubPlan *
1131 _copyAlternativeSubPlan(AlternativeSubPlan *from)
1133 AlternativeSubPlan *newnode = makeNode(AlternativeSubPlan);
1135 COPY_NODE_FIELD(subplans);
1137 return newnode;
1141 * _copyFieldSelect
1143 static FieldSelect *
1144 _copyFieldSelect(FieldSelect *from)
1146 FieldSelect *newnode = makeNode(FieldSelect);
1148 COPY_NODE_FIELD(arg);
1149 COPY_SCALAR_FIELD(fieldnum);
1150 COPY_SCALAR_FIELD(resulttype);
1151 COPY_SCALAR_FIELD(resulttypmod);
1153 return newnode;
1157 * _copyFieldStore
1159 static FieldStore *
1160 _copyFieldStore(FieldStore *from)
1162 FieldStore *newnode = makeNode(FieldStore);
1164 COPY_NODE_FIELD(arg);
1165 COPY_NODE_FIELD(newvals);
1166 COPY_NODE_FIELD(fieldnums);
1167 COPY_SCALAR_FIELD(resulttype);
1169 return newnode;
1173 * _copyRelabelType
1175 static RelabelType *
1176 _copyRelabelType(RelabelType *from)
1178 RelabelType *newnode = makeNode(RelabelType);
1180 COPY_NODE_FIELD(arg);
1181 COPY_SCALAR_FIELD(resulttype);
1182 COPY_SCALAR_FIELD(resulttypmod);
1183 COPY_SCALAR_FIELD(relabelformat);
1184 COPY_LOCATION_FIELD(location);
1186 return newnode;
1190 * _copyCoerceViaIO
1192 static CoerceViaIO *
1193 _copyCoerceViaIO(CoerceViaIO *from)
1195 CoerceViaIO *newnode = makeNode(CoerceViaIO);
1197 COPY_NODE_FIELD(arg);
1198 COPY_SCALAR_FIELD(resulttype);
1199 COPY_SCALAR_FIELD(coerceformat);
1200 COPY_LOCATION_FIELD(location);
1202 return newnode;
1206 * _copyArrayCoerceExpr
1208 static ArrayCoerceExpr *
1209 _copyArrayCoerceExpr(ArrayCoerceExpr *from)
1211 ArrayCoerceExpr *newnode = makeNode(ArrayCoerceExpr);
1213 COPY_NODE_FIELD(arg);
1214 COPY_SCALAR_FIELD(elemfuncid);
1215 COPY_SCALAR_FIELD(resulttype);
1216 COPY_SCALAR_FIELD(resulttypmod);
1217 COPY_SCALAR_FIELD(isExplicit);
1218 COPY_SCALAR_FIELD(coerceformat);
1219 COPY_LOCATION_FIELD(location);
1221 return newnode;
1225 * _copyConvertRowtypeExpr
1227 static ConvertRowtypeExpr *
1228 _copyConvertRowtypeExpr(ConvertRowtypeExpr *from)
1230 ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);
1232 COPY_NODE_FIELD(arg);
1233 COPY_SCALAR_FIELD(resulttype);
1234 COPY_SCALAR_FIELD(convertformat);
1235 COPY_LOCATION_FIELD(location);
1237 return newnode;
1241 * _copyCaseExpr
1243 static CaseExpr *
1244 _copyCaseExpr(CaseExpr *from)
1246 CaseExpr *newnode = makeNode(CaseExpr);
1248 COPY_SCALAR_FIELD(casetype);
1249 COPY_NODE_FIELD(arg);
1250 COPY_NODE_FIELD(args);
1251 COPY_NODE_FIELD(defresult);
1252 COPY_LOCATION_FIELD(location);
1254 return newnode;
1258 * _copyCaseWhen
1260 static CaseWhen *
1261 _copyCaseWhen(CaseWhen *from)
1263 CaseWhen *newnode = makeNode(CaseWhen);
1265 COPY_NODE_FIELD(expr);
1266 COPY_NODE_FIELD(result);
1267 COPY_LOCATION_FIELD(location);
1269 return newnode;
1273 * _copyCaseTestExpr
1275 static CaseTestExpr *
1276 _copyCaseTestExpr(CaseTestExpr *from)
1278 CaseTestExpr *newnode = makeNode(CaseTestExpr);
1280 COPY_SCALAR_FIELD(typeId);
1281 COPY_SCALAR_FIELD(typeMod);
1283 return newnode;
1287 * _copyArrayExpr
1289 static ArrayExpr *
1290 _copyArrayExpr(ArrayExpr *from)
1292 ArrayExpr *newnode = makeNode(ArrayExpr);
1294 COPY_SCALAR_FIELD(array_typeid);
1295 COPY_SCALAR_FIELD(element_typeid);
1296 COPY_NODE_FIELD(elements);
1297 COPY_SCALAR_FIELD(multidims);
1298 COPY_LOCATION_FIELD(location);
1300 return newnode;
1304 * _copyRowExpr
1306 static RowExpr *
1307 _copyRowExpr(RowExpr *from)
1309 RowExpr *newnode = makeNode(RowExpr);
1311 COPY_NODE_FIELD(args);
1312 COPY_SCALAR_FIELD(row_typeid);
1313 COPY_SCALAR_FIELD(row_format);
1314 COPY_NODE_FIELD(colnames);
1315 COPY_LOCATION_FIELD(location);
1317 return newnode;
1321 * _copyRowCompareExpr
1323 static RowCompareExpr *
1324 _copyRowCompareExpr(RowCompareExpr *from)
1326 RowCompareExpr *newnode = makeNode(RowCompareExpr);
1328 COPY_SCALAR_FIELD(rctype);
1329 COPY_NODE_FIELD(opnos);
1330 COPY_NODE_FIELD(opfamilies);
1331 COPY_NODE_FIELD(largs);
1332 COPY_NODE_FIELD(rargs);
1334 return newnode;
1338 * _copyCoalesceExpr
1340 static CoalesceExpr *
1341 _copyCoalesceExpr(CoalesceExpr *from)
1343 CoalesceExpr *newnode = makeNode(CoalesceExpr);
1345 COPY_SCALAR_FIELD(coalescetype);
1346 COPY_NODE_FIELD(args);
1347 COPY_LOCATION_FIELD(location);
1349 return newnode;
1353 * _copyMinMaxExpr
1355 static MinMaxExpr *
1356 _copyMinMaxExpr(MinMaxExpr *from)
1358 MinMaxExpr *newnode = makeNode(MinMaxExpr);
1360 COPY_SCALAR_FIELD(minmaxtype);
1361 COPY_SCALAR_FIELD(op);
1362 COPY_NODE_FIELD(args);
1363 COPY_LOCATION_FIELD(location);
1365 return newnode;
1369 * _copyXmlExpr
1371 static XmlExpr *
1372 _copyXmlExpr(XmlExpr *from)
1374 XmlExpr *newnode = makeNode(XmlExpr);
1376 COPY_SCALAR_FIELD(op);
1377 COPY_STRING_FIELD(name);
1378 COPY_NODE_FIELD(named_args);
1379 COPY_NODE_FIELD(arg_names);
1380 COPY_NODE_FIELD(args);
1381 COPY_SCALAR_FIELD(xmloption);
1382 COPY_SCALAR_FIELD(type);
1383 COPY_SCALAR_FIELD(typmod);
1384 COPY_LOCATION_FIELD(location);
1386 return newnode;
1390 * _copyNullIfExpr (same as OpExpr)
1392 static NullIfExpr *
1393 _copyNullIfExpr(NullIfExpr *from)
1395 NullIfExpr *newnode = makeNode(NullIfExpr);
1397 COPY_SCALAR_FIELD(opno);
1398 COPY_SCALAR_FIELD(opfuncid);
1399 COPY_SCALAR_FIELD(opresulttype);
1400 COPY_SCALAR_FIELD(opretset);
1401 COPY_NODE_FIELD(args);
1402 COPY_LOCATION_FIELD(location);
1404 return newnode;
1408 * _copyNullTest
1410 static NullTest *
1411 _copyNullTest(NullTest *from)
1413 NullTest *newnode = makeNode(NullTest);
1415 COPY_NODE_FIELD(arg);
1416 COPY_SCALAR_FIELD(nulltesttype);
1418 return newnode;
1422 * _copyBooleanTest
1424 static BooleanTest *
1425 _copyBooleanTest(BooleanTest *from)
1427 BooleanTest *newnode = makeNode(BooleanTest);
1429 COPY_NODE_FIELD(arg);
1430 COPY_SCALAR_FIELD(booltesttype);
1432 return newnode;
1436 * _copyCoerceToDomain
1438 static CoerceToDomain *
1439 _copyCoerceToDomain(CoerceToDomain *from)
1441 CoerceToDomain *newnode = makeNode(CoerceToDomain);
1443 COPY_NODE_FIELD(arg);
1444 COPY_SCALAR_FIELD(resulttype);
1445 COPY_SCALAR_FIELD(resulttypmod);
1446 COPY_SCALAR_FIELD(coercionformat);
1447 COPY_LOCATION_FIELD(location);
1449 return newnode;
1453 * _copyCoerceToDomainValue
1455 static CoerceToDomainValue *
1456 _copyCoerceToDomainValue(CoerceToDomainValue *from)
1458 CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1460 COPY_SCALAR_FIELD(typeId);
1461 COPY_SCALAR_FIELD(typeMod);
1462 COPY_LOCATION_FIELD(location);
1464 return newnode;
1468 * _copySetToDefault
1470 static SetToDefault *
1471 _copySetToDefault(SetToDefault *from)
1473 SetToDefault *newnode = makeNode(SetToDefault);
1475 COPY_SCALAR_FIELD(typeId);
1476 COPY_SCALAR_FIELD(typeMod);
1477 COPY_LOCATION_FIELD(location);
1479 return newnode;
1483 * _copyCurrentOfExpr
1485 static CurrentOfExpr *
1486 _copyCurrentOfExpr(CurrentOfExpr *from)
1488 CurrentOfExpr *newnode = makeNode(CurrentOfExpr);
1490 COPY_SCALAR_FIELD(cvarno);
1491 COPY_STRING_FIELD(cursor_name);
1492 COPY_SCALAR_FIELD(cursor_param);
1494 return newnode;
1498 * _copyTargetEntry
1500 static TargetEntry *
1501 _copyTargetEntry(TargetEntry *from)
1503 TargetEntry *newnode = makeNode(TargetEntry);
1505 COPY_NODE_FIELD(expr);
1506 COPY_SCALAR_FIELD(resno);
1507 COPY_STRING_FIELD(resname);
1508 COPY_SCALAR_FIELD(ressortgroupref);
1509 COPY_SCALAR_FIELD(resorigtbl);
1510 COPY_SCALAR_FIELD(resorigcol);
1511 COPY_SCALAR_FIELD(resjunk);
1513 return newnode;
1517 * _copyRangeTblRef
1519 static RangeTblRef *
1520 _copyRangeTblRef(RangeTblRef *from)
1522 RangeTblRef *newnode = makeNode(RangeTblRef);
1524 COPY_SCALAR_FIELD(rtindex);
1526 return newnode;
1530 * _copyJoinExpr
1532 static JoinExpr *
1533 _copyJoinExpr(JoinExpr *from)
1535 JoinExpr *newnode = makeNode(JoinExpr);
1537 COPY_SCALAR_FIELD(jointype);
1538 COPY_SCALAR_FIELD(isNatural);
1539 COPY_NODE_FIELD(larg);
1540 COPY_NODE_FIELD(rarg);
1541 COPY_NODE_FIELD(using);
1542 COPY_NODE_FIELD(quals);
1543 COPY_NODE_FIELD(alias);
1544 COPY_SCALAR_FIELD(rtindex);
1546 return newnode;
1550 * _copyFromExpr
1552 static FromExpr *
1553 _copyFromExpr(FromExpr *from)
1555 FromExpr *newnode = makeNode(FromExpr);
1557 COPY_NODE_FIELD(fromlist);
1558 COPY_NODE_FIELD(quals);
1560 return newnode;
1563 /* ****************************************************************
1564 * relation.h copy functions
1566 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1567 * There are some subsidiary structs that are useful to copy, though.
1568 * ****************************************************************
1572 * _copyPathKey
1574 static PathKey *
1575 _copyPathKey(PathKey *from)
1577 PathKey *newnode = makeNode(PathKey);
1579 /* EquivalenceClasses are never moved, so just shallow-copy the pointer */
1580 COPY_SCALAR_FIELD(pk_eclass);
1581 COPY_SCALAR_FIELD(pk_opfamily);
1582 COPY_SCALAR_FIELD(pk_strategy);
1583 COPY_SCALAR_FIELD(pk_nulls_first);
1585 return newnode;
1589 * _copyRestrictInfo
1591 static RestrictInfo *
1592 _copyRestrictInfo(RestrictInfo *from)
1594 RestrictInfo *newnode = makeNode(RestrictInfo);
1596 COPY_NODE_FIELD(clause);
1597 COPY_SCALAR_FIELD(is_pushed_down);
1598 COPY_SCALAR_FIELD(outerjoin_delayed);
1599 COPY_SCALAR_FIELD(can_join);
1600 COPY_SCALAR_FIELD(pseudoconstant);
1601 COPY_BITMAPSET_FIELD(clause_relids);
1602 COPY_BITMAPSET_FIELD(required_relids);
1603 COPY_BITMAPSET_FIELD(left_relids);
1604 COPY_BITMAPSET_FIELD(right_relids);
1605 COPY_NODE_FIELD(orclause);
1606 /* EquivalenceClasses are never copied, so shallow-copy the pointers */
1607 COPY_SCALAR_FIELD(parent_ec);
1608 COPY_SCALAR_FIELD(eval_cost);
1609 COPY_SCALAR_FIELD(this_selec);
1610 COPY_NODE_FIELD(mergeopfamilies);
1611 /* EquivalenceClasses are never copied, so shallow-copy the pointers */
1612 COPY_SCALAR_FIELD(left_ec);
1613 COPY_SCALAR_FIELD(right_ec);
1614 COPY_SCALAR_FIELD(left_em);
1615 COPY_SCALAR_FIELD(right_em);
1616 /* MergeScanSelCache isn't a Node, so hard to copy; just reset cache */
1617 newnode->scansel_cache = NIL;
1618 COPY_SCALAR_FIELD(outer_is_left);
1619 COPY_SCALAR_FIELD(hashjoinoperator);
1620 COPY_SCALAR_FIELD(left_bucketsize);
1621 COPY_SCALAR_FIELD(right_bucketsize);
1623 return newnode;
1627 * _copyFlattenedSubLink
1629 static FlattenedSubLink *
1630 _copyFlattenedSubLink(FlattenedSubLink *from)
1632 FlattenedSubLink *newnode = makeNode(FlattenedSubLink);
1634 COPY_SCALAR_FIELD(jointype);
1635 COPY_BITMAPSET_FIELD(lefthand);
1636 COPY_BITMAPSET_FIELD(righthand);
1637 COPY_NODE_FIELD(quals);
1639 return newnode;
1643 * _copyPlaceHolderVar
1645 static PlaceHolderVar *
1646 _copyPlaceHolderVar(PlaceHolderVar *from)
1648 PlaceHolderVar *newnode = makeNode(PlaceHolderVar);
1650 COPY_NODE_FIELD(phexpr);
1651 COPY_BITMAPSET_FIELD(phrels);
1652 COPY_SCALAR_FIELD(phid);
1653 COPY_SCALAR_FIELD(phlevelsup);
1655 return newnode;
1659 * _copySpecialJoinInfo
1661 static SpecialJoinInfo *
1662 _copySpecialJoinInfo(SpecialJoinInfo *from)
1664 SpecialJoinInfo *newnode = makeNode(SpecialJoinInfo);
1666 COPY_BITMAPSET_FIELD(min_lefthand);
1667 COPY_BITMAPSET_FIELD(min_righthand);
1668 COPY_BITMAPSET_FIELD(syn_lefthand);
1669 COPY_BITMAPSET_FIELD(syn_righthand);
1670 COPY_SCALAR_FIELD(jointype);
1671 COPY_SCALAR_FIELD(lhs_strict);
1672 COPY_SCALAR_FIELD(delay_upper_joins);
1673 COPY_NODE_FIELD(join_quals);
1675 return newnode;
1679 * _copyAppendRelInfo
1681 static AppendRelInfo *
1682 _copyAppendRelInfo(AppendRelInfo *from)
1684 AppendRelInfo *newnode = makeNode(AppendRelInfo);
1686 COPY_SCALAR_FIELD(parent_relid);
1687 COPY_SCALAR_FIELD(child_relid);
1688 COPY_SCALAR_FIELD(parent_reltype);
1689 COPY_SCALAR_FIELD(child_reltype);
1690 COPY_NODE_FIELD(translated_vars);
1691 COPY_SCALAR_FIELD(parent_reloid);
1693 return newnode;
1697 * _copyPlaceHolderInfo
1699 static PlaceHolderInfo *
1700 _copyPlaceHolderInfo(PlaceHolderInfo *from)
1702 PlaceHolderInfo *newnode = makeNode(PlaceHolderInfo);
1704 COPY_SCALAR_FIELD(phid);
1705 COPY_NODE_FIELD(ph_var);
1706 COPY_BITMAPSET_FIELD(ph_eval_at);
1707 COPY_BITMAPSET_FIELD(ph_needed);
1708 COPY_SCALAR_FIELD(ph_width);
1710 return newnode;
1713 /* ****************************************************************
1714 * parsenodes.h copy functions
1715 * ****************************************************************
1718 static RangeTblEntry *
1719 _copyRangeTblEntry(RangeTblEntry *from)
1721 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1723 COPY_SCALAR_FIELD(rtekind);
1724 COPY_SCALAR_FIELD(relid);
1725 COPY_NODE_FIELD(subquery);
1726 COPY_SCALAR_FIELD(jointype);
1727 COPY_NODE_FIELD(joinaliasvars);
1728 COPY_NODE_FIELD(funcexpr);
1729 COPY_NODE_FIELD(funccoltypes);
1730 COPY_NODE_FIELD(funccoltypmods);
1731 COPY_NODE_FIELD(values_lists);
1732 COPY_STRING_FIELD(ctename);
1733 COPY_SCALAR_FIELD(ctelevelsup);
1734 COPY_SCALAR_FIELD(self_reference);
1735 COPY_NODE_FIELD(ctecoltypes);
1736 COPY_NODE_FIELD(ctecoltypmods);
1737 COPY_NODE_FIELD(alias);
1738 COPY_NODE_FIELD(eref);
1739 COPY_SCALAR_FIELD(inh);
1740 COPY_SCALAR_FIELD(inFromCl);
1741 COPY_SCALAR_FIELD(requiredPerms);
1742 COPY_SCALAR_FIELD(checkAsUser);
1744 return newnode;
1747 static FkConstraint *
1748 _copyFkConstraint(FkConstraint *from)
1750 FkConstraint *newnode = makeNode(FkConstraint);
1752 COPY_STRING_FIELD(constr_name);
1753 COPY_NODE_FIELD(pktable);
1754 COPY_NODE_FIELD(fk_attrs);
1755 COPY_NODE_FIELD(pk_attrs);
1756 COPY_SCALAR_FIELD(fk_matchtype);
1757 COPY_SCALAR_FIELD(fk_upd_action);
1758 COPY_SCALAR_FIELD(fk_del_action);
1759 COPY_SCALAR_FIELD(deferrable);
1760 COPY_SCALAR_FIELD(initdeferred);
1761 COPY_SCALAR_FIELD(skip_validation);
1763 return newnode;
1766 static SortGroupClause *
1767 _copySortGroupClause(SortGroupClause *from)
1769 SortGroupClause *newnode = makeNode(SortGroupClause);
1771 COPY_SCALAR_FIELD(tleSortGroupRef);
1772 COPY_SCALAR_FIELD(eqop);
1773 COPY_SCALAR_FIELD(sortop);
1774 COPY_SCALAR_FIELD(nulls_first);
1776 return newnode;
1779 static WindowClause *
1780 _copyWindowClause(WindowClause *from)
1782 WindowClause *newnode = makeNode(WindowClause);
1784 COPY_STRING_FIELD(name);
1785 COPY_STRING_FIELD(refname);
1786 COPY_NODE_FIELD(partitionClause);
1787 COPY_NODE_FIELD(orderClause);
1788 COPY_SCALAR_FIELD(frameOptions);
1789 COPY_SCALAR_FIELD(winref);
1790 COPY_SCALAR_FIELD(copiedOrder);
1792 return newnode;
1795 static RowMarkClause *
1796 _copyRowMarkClause(RowMarkClause *from)
1798 RowMarkClause *newnode = makeNode(RowMarkClause);
1800 COPY_SCALAR_FIELD(rti);
1801 COPY_SCALAR_FIELD(prti);
1802 COPY_SCALAR_FIELD(forUpdate);
1803 COPY_SCALAR_FIELD(noWait);
1804 COPY_SCALAR_FIELD(isParent);
1806 return newnode;
1809 static WithClause *
1810 _copyWithClause(WithClause *from)
1812 WithClause *newnode = makeNode(WithClause);
1814 COPY_NODE_FIELD(ctes);
1815 COPY_SCALAR_FIELD(recursive);
1816 COPY_LOCATION_FIELD(location);
1818 return newnode;
1821 static CommonTableExpr *
1822 _copyCommonTableExpr(CommonTableExpr *from)
1824 CommonTableExpr *newnode = makeNode(CommonTableExpr);
1826 COPY_STRING_FIELD(ctename);
1827 COPY_NODE_FIELD(aliascolnames);
1828 COPY_NODE_FIELD(ctequery);
1829 COPY_LOCATION_FIELD(location);
1830 COPY_SCALAR_FIELD(cterecursive);
1831 COPY_SCALAR_FIELD(cterefcount);
1832 COPY_NODE_FIELD(ctecolnames);
1833 COPY_NODE_FIELD(ctecoltypes);
1834 COPY_NODE_FIELD(ctecoltypmods);
1836 return newnode;
1839 static A_Expr *
1840 _copyAExpr(A_Expr *from)
1842 A_Expr *newnode = makeNode(A_Expr);
1844 COPY_SCALAR_FIELD(kind);
1845 COPY_NODE_FIELD(name);
1846 COPY_NODE_FIELD(lexpr);
1847 COPY_NODE_FIELD(rexpr);
1848 COPY_LOCATION_FIELD(location);
1850 return newnode;
1853 static ColumnRef *
1854 _copyColumnRef(ColumnRef *from)
1856 ColumnRef *newnode = makeNode(ColumnRef);
1858 COPY_NODE_FIELD(fields);
1859 COPY_LOCATION_FIELD(location);
1861 return newnode;
1864 static ParamRef *
1865 _copyParamRef(ParamRef *from)
1867 ParamRef *newnode = makeNode(ParamRef);
1869 COPY_SCALAR_FIELD(number);
1870 COPY_LOCATION_FIELD(location);
1872 return newnode;
1875 static A_Const *
1876 _copyAConst(A_Const *from)
1878 A_Const *newnode = makeNode(A_Const);
1880 /* This part must duplicate _copyValue */
1881 COPY_SCALAR_FIELD(val.type);
1882 switch (from->val.type)
1884 case T_Integer:
1885 COPY_SCALAR_FIELD(val.val.ival);
1886 break;
1887 case T_Float:
1888 case T_String:
1889 case T_BitString:
1890 COPY_STRING_FIELD(val.val.str);
1891 break;
1892 case T_Null:
1893 /* nothing to do */
1894 break;
1895 default:
1896 elog(ERROR, "unrecognized node type: %d",
1897 (int) from->val.type);
1898 break;
1901 COPY_LOCATION_FIELD(location);
1903 return newnode;
1906 static FuncCall *
1907 _copyFuncCall(FuncCall *from)
1909 FuncCall *newnode = makeNode(FuncCall);
1911 COPY_NODE_FIELD(funcname);
1912 COPY_NODE_FIELD(args);
1913 COPY_SCALAR_FIELD(agg_star);
1914 COPY_SCALAR_FIELD(agg_distinct);
1915 COPY_SCALAR_FIELD(func_variadic);
1916 COPY_NODE_FIELD(over);
1917 COPY_LOCATION_FIELD(location);
1919 return newnode;
1922 static A_Star *
1923 _copyAStar(A_Star *from)
1925 A_Star *newnode = makeNode(A_Star);
1927 return newnode;
1930 static A_Indices *
1931 _copyAIndices(A_Indices *from)
1933 A_Indices *newnode = makeNode(A_Indices);
1935 COPY_NODE_FIELD(lidx);
1936 COPY_NODE_FIELD(uidx);
1938 return newnode;
1941 static A_Indirection *
1942 _copyA_Indirection(A_Indirection *from)
1944 A_Indirection *newnode = makeNode(A_Indirection);
1946 COPY_NODE_FIELD(arg);
1947 COPY_NODE_FIELD(indirection);
1949 return newnode;
1952 static A_ArrayExpr *
1953 _copyA_ArrayExpr(A_ArrayExpr *from)
1955 A_ArrayExpr *newnode = makeNode(A_ArrayExpr);
1957 COPY_NODE_FIELD(elements);
1958 COPY_LOCATION_FIELD(location);
1960 return newnode;
1963 static ResTarget *
1964 _copyResTarget(ResTarget *from)
1966 ResTarget *newnode = makeNode(ResTarget);
1968 COPY_STRING_FIELD(name);
1969 COPY_NODE_FIELD(indirection);
1970 COPY_NODE_FIELD(val);
1971 COPY_LOCATION_FIELD(location);
1973 return newnode;
1976 static TypeName *
1977 _copyTypeName(TypeName *from)
1979 TypeName *newnode = makeNode(TypeName);
1981 COPY_NODE_FIELD(names);
1982 COPY_SCALAR_FIELD(typeid);
1983 COPY_SCALAR_FIELD(setof);
1984 COPY_SCALAR_FIELD(pct_type);
1985 COPY_NODE_FIELD(typmods);
1986 COPY_SCALAR_FIELD(typemod);
1987 COPY_NODE_FIELD(arrayBounds);
1988 COPY_LOCATION_FIELD(location);
1990 return newnode;
1993 static SortBy *
1994 _copySortBy(SortBy *from)
1996 SortBy *newnode = makeNode(SortBy);
1998 COPY_NODE_FIELD(node);
1999 COPY_SCALAR_FIELD(sortby_dir);
2000 COPY_SCALAR_FIELD(sortby_nulls);
2001 COPY_NODE_FIELD(useOp);
2002 COPY_LOCATION_FIELD(location);
2004 return newnode;
2007 static WindowDef *
2008 _copyWindowDef(WindowDef *from)
2010 WindowDef *newnode = makeNode(WindowDef);
2012 COPY_STRING_FIELD(name);
2013 COPY_STRING_FIELD(refname);
2014 COPY_NODE_FIELD(partitionClause);
2015 COPY_NODE_FIELD(orderClause);
2016 COPY_SCALAR_FIELD(frameOptions);
2017 COPY_LOCATION_FIELD(location);
2019 return newnode;
2022 static RangeSubselect *
2023 _copyRangeSubselect(RangeSubselect *from)
2025 RangeSubselect *newnode = makeNode(RangeSubselect);
2027 COPY_NODE_FIELD(subquery);
2028 COPY_NODE_FIELD(alias);
2030 return newnode;
2033 static RangeFunction *
2034 _copyRangeFunction(RangeFunction *from)
2036 RangeFunction *newnode = makeNode(RangeFunction);
2038 COPY_NODE_FIELD(funccallnode);
2039 COPY_NODE_FIELD(alias);
2040 COPY_NODE_FIELD(coldeflist);
2042 return newnode;
2045 static TypeCast *
2046 _copyTypeCast(TypeCast *from)
2048 TypeCast *newnode = makeNode(TypeCast);
2050 COPY_NODE_FIELD(arg);
2051 COPY_NODE_FIELD(typename);
2052 COPY_LOCATION_FIELD(location);
2054 return newnode;
2057 static IndexElem *
2058 _copyIndexElem(IndexElem *from)
2060 IndexElem *newnode = makeNode(IndexElem);
2062 COPY_STRING_FIELD(name);
2063 COPY_NODE_FIELD(expr);
2064 COPY_NODE_FIELD(opclass);
2065 COPY_SCALAR_FIELD(ordering);
2066 COPY_SCALAR_FIELD(nulls_ordering);
2068 return newnode;
2071 static ColumnDef *
2072 _copyColumnDef(ColumnDef *from)
2074 ColumnDef *newnode = makeNode(ColumnDef);
2076 COPY_STRING_FIELD(colname);
2077 COPY_NODE_FIELD(typename);
2078 COPY_SCALAR_FIELD(inhcount);
2079 COPY_SCALAR_FIELD(is_local);
2080 COPY_SCALAR_FIELD(is_not_null);
2081 COPY_NODE_FIELD(raw_default);
2082 COPY_STRING_FIELD(cooked_default);
2083 COPY_NODE_FIELD(constraints);
2085 return newnode;
2088 static Constraint *
2089 _copyConstraint(Constraint *from)
2091 Constraint *newnode = makeNode(Constraint);
2093 COPY_SCALAR_FIELD(contype);
2094 COPY_STRING_FIELD(name);
2095 COPY_NODE_FIELD(raw_expr);
2096 COPY_STRING_FIELD(cooked_expr);
2097 COPY_NODE_FIELD(keys);
2098 COPY_NODE_FIELD(options);
2099 COPY_STRING_FIELD(indexspace);
2101 return newnode;
2104 static DefElem *
2105 _copyDefElem(DefElem *from)
2107 DefElem *newnode = makeNode(DefElem);
2109 COPY_STRING_FIELD(defname);
2110 COPY_NODE_FIELD(arg);
2112 return newnode;
2115 static OptionDefElem *
2116 _copyOptionDefElem(OptionDefElem *from)
2118 OptionDefElem *newnode = makeNode(OptionDefElem);
2120 COPY_SCALAR_FIELD(alter_op);
2121 COPY_NODE_FIELD(def);
2123 return newnode;
2126 static LockingClause *
2127 _copyLockingClause(LockingClause *from)
2129 LockingClause *newnode = makeNode(LockingClause);
2131 COPY_NODE_FIELD(lockedRels);
2132 COPY_SCALAR_FIELD(forUpdate);
2133 COPY_SCALAR_FIELD(noWait);
2135 return newnode;
2138 static XmlSerialize *
2139 _copyXmlSerialize(XmlSerialize *from)
2141 XmlSerialize *newnode = makeNode(XmlSerialize);
2143 COPY_SCALAR_FIELD(xmloption);
2144 COPY_NODE_FIELD(expr);
2145 COPY_NODE_FIELD(typename);
2146 COPY_LOCATION_FIELD(location);
2148 return newnode;
2151 static Query *
2152 _copyQuery(Query *from)
2154 Query *newnode = makeNode(Query);
2156 COPY_SCALAR_FIELD(commandType);
2157 COPY_SCALAR_FIELD(querySource);
2158 COPY_SCALAR_FIELD(canSetTag);
2159 COPY_NODE_FIELD(utilityStmt);
2160 COPY_SCALAR_FIELD(resultRelation);
2161 COPY_NODE_FIELD(intoClause);
2162 COPY_SCALAR_FIELD(hasAggs);
2163 COPY_SCALAR_FIELD(hasWindowFuncs);
2164 COPY_SCALAR_FIELD(hasSubLinks);
2165 COPY_SCALAR_FIELD(hasDistinctOn);
2166 COPY_SCALAR_FIELD(hasRecursive);
2167 COPY_NODE_FIELD(cteList);
2168 COPY_NODE_FIELD(rtable);
2169 COPY_NODE_FIELD(jointree);
2170 COPY_NODE_FIELD(targetList);
2171 COPY_NODE_FIELD(returningList);
2172 COPY_NODE_FIELD(groupClause);
2173 COPY_NODE_FIELD(havingQual);
2174 COPY_NODE_FIELD(windowClause);
2175 COPY_NODE_FIELD(distinctClause);
2176 COPY_NODE_FIELD(sortClause);
2177 COPY_NODE_FIELD(limitOffset);
2178 COPY_NODE_FIELD(limitCount);
2179 COPY_NODE_FIELD(rowMarks);
2180 COPY_NODE_FIELD(setOperations);
2182 return newnode;
2185 static InsertStmt *
2186 _copyInsertStmt(InsertStmt *from)
2188 InsertStmt *newnode = makeNode(InsertStmt);
2190 COPY_NODE_FIELD(relation);
2191 COPY_NODE_FIELD(cols);
2192 COPY_NODE_FIELD(selectStmt);
2193 COPY_NODE_FIELD(returningList);
2195 return newnode;
2198 static DeleteStmt *
2199 _copyDeleteStmt(DeleteStmt *from)
2201 DeleteStmt *newnode = makeNode(DeleteStmt);
2203 COPY_NODE_FIELD(relation);
2204 COPY_NODE_FIELD(usingClause);
2205 COPY_NODE_FIELD(whereClause);
2206 COPY_NODE_FIELD(returningList);
2208 return newnode;
2211 static UpdateStmt *
2212 _copyUpdateStmt(UpdateStmt *from)
2214 UpdateStmt *newnode = makeNode(UpdateStmt);
2216 COPY_NODE_FIELD(relation);
2217 COPY_NODE_FIELD(targetList);
2218 COPY_NODE_FIELD(whereClause);
2219 COPY_NODE_FIELD(fromClause);
2220 COPY_NODE_FIELD(returningList);
2222 return newnode;
2225 static SelectStmt *
2226 _copySelectStmt(SelectStmt *from)
2228 SelectStmt *newnode = makeNode(SelectStmt);
2230 COPY_NODE_FIELD(distinctClause);
2231 COPY_NODE_FIELD(intoClause);
2232 COPY_NODE_FIELD(targetList);
2233 COPY_NODE_FIELD(fromClause);
2234 COPY_NODE_FIELD(whereClause);
2235 COPY_NODE_FIELD(groupClause);
2236 COPY_NODE_FIELD(havingClause);
2237 COPY_NODE_FIELD(windowClause);
2238 COPY_NODE_FIELD(withClause);
2239 COPY_NODE_FIELD(valuesLists);
2240 COPY_NODE_FIELD(sortClause);
2241 COPY_NODE_FIELD(limitOffset);
2242 COPY_NODE_FIELD(limitCount);
2243 COPY_NODE_FIELD(lockingClause);
2244 COPY_SCALAR_FIELD(op);
2245 COPY_SCALAR_FIELD(all);
2246 COPY_NODE_FIELD(larg);
2247 COPY_NODE_FIELD(rarg);
2249 return newnode;
2252 static SetOperationStmt *
2253 _copySetOperationStmt(SetOperationStmt *from)
2255 SetOperationStmt *newnode = makeNode(SetOperationStmt);
2257 COPY_SCALAR_FIELD(op);
2258 COPY_SCALAR_FIELD(all);
2259 COPY_NODE_FIELD(larg);
2260 COPY_NODE_FIELD(rarg);
2261 COPY_NODE_FIELD(colTypes);
2262 COPY_NODE_FIELD(colTypmods);
2263 COPY_NODE_FIELD(groupClauses);
2265 return newnode;
2268 static AlterTableStmt *
2269 _copyAlterTableStmt(AlterTableStmt *from)
2271 AlterTableStmt *newnode = makeNode(AlterTableStmt);
2273 COPY_NODE_FIELD(relation);
2274 COPY_NODE_FIELD(cmds);
2275 COPY_SCALAR_FIELD(relkind);
2277 return newnode;
2280 static AlterTableCmd *
2281 _copyAlterTableCmd(AlterTableCmd *from)
2283 AlterTableCmd *newnode = makeNode(AlterTableCmd);
2285 COPY_SCALAR_FIELD(subtype);
2286 COPY_STRING_FIELD(name);
2287 COPY_NODE_FIELD(def);
2288 COPY_NODE_FIELD(transform);
2289 COPY_SCALAR_FIELD(behavior);
2291 return newnode;
2294 static AlterDomainStmt *
2295 _copyAlterDomainStmt(AlterDomainStmt *from)
2297 AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
2299 COPY_SCALAR_FIELD(subtype);
2300 COPY_NODE_FIELD(typename);
2301 COPY_STRING_FIELD(name);
2302 COPY_NODE_FIELD(def);
2303 COPY_SCALAR_FIELD(behavior);
2305 return newnode;
2308 static GrantStmt *
2309 _copyGrantStmt(GrantStmt *from)
2311 GrantStmt *newnode = makeNode(GrantStmt);
2313 COPY_SCALAR_FIELD(is_grant);
2314 COPY_SCALAR_FIELD(objtype);
2315 COPY_NODE_FIELD(objects);
2316 COPY_NODE_FIELD(privileges);
2317 COPY_NODE_FIELD(grantees);
2318 COPY_SCALAR_FIELD(grant_option);
2319 COPY_SCALAR_FIELD(behavior);
2321 return newnode;
2324 static PrivGrantee *
2325 _copyPrivGrantee(PrivGrantee *from)
2327 PrivGrantee *newnode = makeNode(PrivGrantee);
2329 COPY_STRING_FIELD(rolname);
2331 return newnode;
2334 static FuncWithArgs *
2335 _copyFuncWithArgs(FuncWithArgs *from)
2337 FuncWithArgs *newnode = makeNode(FuncWithArgs);
2339 COPY_NODE_FIELD(funcname);
2340 COPY_NODE_FIELD(funcargs);
2342 return newnode;
2345 static GrantRoleStmt *
2346 _copyGrantRoleStmt(GrantRoleStmt *from)
2348 GrantRoleStmt *newnode = makeNode(GrantRoleStmt);
2350 COPY_NODE_FIELD(granted_roles);
2351 COPY_NODE_FIELD(grantee_roles);
2352 COPY_SCALAR_FIELD(is_grant);
2353 COPY_SCALAR_FIELD(admin_opt);
2354 COPY_STRING_FIELD(grantor);
2355 COPY_SCALAR_FIELD(behavior);
2357 return newnode;
2360 static DeclareCursorStmt *
2361 _copyDeclareCursorStmt(DeclareCursorStmt *from)
2363 DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
2365 COPY_STRING_FIELD(portalname);
2366 COPY_SCALAR_FIELD(options);
2367 COPY_NODE_FIELD(query);
2369 return newnode;
2372 static ClosePortalStmt *
2373 _copyClosePortalStmt(ClosePortalStmt *from)
2375 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
2377 COPY_STRING_FIELD(portalname);
2379 return newnode;
2382 static ClusterStmt *
2383 _copyClusterStmt(ClusterStmt *from)
2385 ClusterStmt *newnode = makeNode(ClusterStmt);
2387 COPY_NODE_FIELD(relation);
2388 COPY_STRING_FIELD(indexname);
2389 COPY_SCALAR_FIELD(verbose) ;
2391 return newnode;
2394 static CopyStmt *
2395 _copyCopyStmt(CopyStmt *from)
2397 CopyStmt *newnode = makeNode(CopyStmt);
2399 COPY_NODE_FIELD(relation);
2400 COPY_NODE_FIELD(query);
2401 COPY_NODE_FIELD(attlist);
2402 COPY_SCALAR_FIELD(is_from);
2403 COPY_STRING_FIELD(filename);
2404 COPY_NODE_FIELD(options);
2406 return newnode;
2409 static CreateStmt *
2410 _copyCreateStmt(CreateStmt *from)
2412 CreateStmt *newnode = makeNode(CreateStmt);
2414 COPY_NODE_FIELD(relation);
2415 COPY_NODE_FIELD(tableElts);
2416 COPY_NODE_FIELD(inhRelations);
2417 COPY_NODE_FIELD(constraints);
2418 COPY_NODE_FIELD(options);
2419 COPY_SCALAR_FIELD(oncommit);
2420 COPY_STRING_FIELD(tablespacename);
2422 return newnode;
2425 static InhRelation *
2426 _copyInhRelation(InhRelation *from)
2428 InhRelation *newnode = makeNode(InhRelation);
2430 COPY_NODE_FIELD(relation);
2431 COPY_NODE_FIELD(options);
2433 return newnode;
2436 static DefineStmt *
2437 _copyDefineStmt(DefineStmt *from)
2439 DefineStmt *newnode = makeNode(DefineStmt);
2441 COPY_SCALAR_FIELD(kind);
2442 COPY_SCALAR_FIELD(oldstyle);
2443 COPY_NODE_FIELD(defnames);
2444 COPY_NODE_FIELD(args);
2445 COPY_NODE_FIELD(definition);
2447 return newnode;
2450 static DropStmt *
2451 _copyDropStmt(DropStmt *from)
2453 DropStmt *newnode = makeNode(DropStmt);
2455 COPY_NODE_FIELD(objects);
2456 COPY_SCALAR_FIELD(removeType);
2457 COPY_SCALAR_FIELD(behavior);
2458 COPY_SCALAR_FIELD(missing_ok);
2460 return newnode;
2463 static TruncateStmt *
2464 _copyTruncateStmt(TruncateStmt *from)
2466 TruncateStmt *newnode = makeNode(TruncateStmt);
2468 COPY_NODE_FIELD(relations);
2469 COPY_SCALAR_FIELD(restart_seqs);
2470 COPY_SCALAR_FIELD(behavior);
2472 return newnode;
2475 static CommentStmt *
2476 _copyCommentStmt(CommentStmt *from)
2478 CommentStmt *newnode = makeNode(CommentStmt);
2480 COPY_SCALAR_FIELD(objtype);
2481 COPY_NODE_FIELD(objname);
2482 COPY_NODE_FIELD(objargs);
2483 COPY_STRING_FIELD(comment);
2485 return newnode;
2488 static FetchStmt *
2489 _copyFetchStmt(FetchStmt *from)
2491 FetchStmt *newnode = makeNode(FetchStmt);
2493 COPY_SCALAR_FIELD(direction);
2494 COPY_SCALAR_FIELD(howMany);
2495 COPY_STRING_FIELD(portalname);
2496 COPY_SCALAR_FIELD(ismove);
2498 return newnode;
2501 static IndexStmt *
2502 _copyIndexStmt(IndexStmt *from)
2504 IndexStmt *newnode = makeNode(IndexStmt);
2506 COPY_STRING_FIELD(idxname);
2507 COPY_NODE_FIELD(relation);
2508 COPY_STRING_FIELD(accessMethod);
2509 COPY_STRING_FIELD(tableSpace);
2510 COPY_NODE_FIELD(indexParams);
2511 COPY_NODE_FIELD(options);
2512 COPY_NODE_FIELD(whereClause);
2513 COPY_SCALAR_FIELD(unique);
2514 COPY_SCALAR_FIELD(primary);
2515 COPY_SCALAR_FIELD(isconstraint);
2516 COPY_SCALAR_FIELD(concurrent);
2518 return newnode;
2521 static CreateFunctionStmt *
2522 _copyCreateFunctionStmt(CreateFunctionStmt *from)
2524 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
2526 COPY_SCALAR_FIELD(replace);
2527 COPY_NODE_FIELD(funcname);
2528 COPY_NODE_FIELD(parameters);
2529 COPY_NODE_FIELD(returnType);
2530 COPY_NODE_FIELD(options);
2531 COPY_NODE_FIELD(withClause);
2533 return newnode;
2536 static FunctionParameter *
2537 _copyFunctionParameter(FunctionParameter *from)
2539 FunctionParameter *newnode = makeNode(FunctionParameter);
2541 COPY_STRING_FIELD(name);
2542 COPY_NODE_FIELD(argType);
2543 COPY_SCALAR_FIELD(mode);
2544 COPY_NODE_FIELD(defexpr);
2546 return newnode;
2549 static AlterFunctionStmt *
2550 _copyAlterFunctionStmt(AlterFunctionStmt *from)
2552 AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);
2554 COPY_NODE_FIELD(func);
2555 COPY_NODE_FIELD(actions);
2557 return newnode;
2560 static RemoveFuncStmt *
2561 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2563 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2565 COPY_SCALAR_FIELD(kind);
2566 COPY_NODE_FIELD(name);
2567 COPY_NODE_FIELD(args);
2568 COPY_SCALAR_FIELD(behavior);
2569 COPY_SCALAR_FIELD(missing_ok);
2571 return newnode;
2574 static RemoveOpClassStmt *
2575 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
2577 RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
2579 COPY_NODE_FIELD(opclassname);
2580 COPY_STRING_FIELD(amname);
2581 COPY_SCALAR_FIELD(behavior);
2582 COPY_SCALAR_FIELD(missing_ok);
2584 return newnode;
2587 static RemoveOpFamilyStmt *
2588 _copyRemoveOpFamilyStmt(RemoveOpFamilyStmt *from)
2590 RemoveOpFamilyStmt *newnode = makeNode(RemoveOpFamilyStmt);
2592 COPY_NODE_FIELD(opfamilyname);
2593 COPY_STRING_FIELD(amname);
2594 COPY_SCALAR_FIELD(behavior);
2595 COPY_SCALAR_FIELD(missing_ok);
2597 return newnode;
2600 static RenameStmt *
2601 _copyRenameStmt(RenameStmt *from)
2603 RenameStmt *newnode = makeNode(RenameStmt);
2605 COPY_SCALAR_FIELD(renameType);
2606 COPY_NODE_FIELD(relation);
2607 COPY_NODE_FIELD(object);
2608 COPY_NODE_FIELD(objarg);
2609 COPY_STRING_FIELD(subname);
2610 COPY_STRING_FIELD(newname);
2612 return newnode;
2615 static AlterObjectSchemaStmt *
2616 _copyAlterObjectSchemaStmt(AlterObjectSchemaStmt *from)
2618 AlterObjectSchemaStmt *newnode = makeNode(AlterObjectSchemaStmt);
2620 COPY_SCALAR_FIELD(objectType);
2621 COPY_NODE_FIELD(relation);
2622 COPY_NODE_FIELD(object);
2623 COPY_NODE_FIELD(objarg);
2624 COPY_STRING_FIELD(addname);
2625 COPY_STRING_FIELD(newschema);
2627 return newnode;
2630 static AlterOwnerStmt *
2631 _copyAlterOwnerStmt(AlterOwnerStmt *from)
2633 AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);
2635 COPY_SCALAR_FIELD(objectType);
2636 COPY_NODE_FIELD(relation);
2637 COPY_NODE_FIELD(object);
2638 COPY_NODE_FIELD(objarg);
2639 COPY_STRING_FIELD(addname);
2640 COPY_STRING_FIELD(newowner);
2642 return newnode;
2645 static RuleStmt *
2646 _copyRuleStmt(RuleStmt *from)
2648 RuleStmt *newnode = makeNode(RuleStmt);
2650 COPY_NODE_FIELD(relation);
2651 COPY_STRING_FIELD(rulename);
2652 COPY_NODE_FIELD(whereClause);
2653 COPY_SCALAR_FIELD(event);
2654 COPY_SCALAR_FIELD(instead);
2655 COPY_NODE_FIELD(actions);
2656 COPY_SCALAR_FIELD(replace);
2658 return newnode;
2661 static NotifyStmt *
2662 _copyNotifyStmt(NotifyStmt *from)
2664 NotifyStmt *newnode = makeNode(NotifyStmt);
2666 COPY_STRING_FIELD(conditionname);
2668 return newnode;
2671 static ListenStmt *
2672 _copyListenStmt(ListenStmt *from)
2674 ListenStmt *newnode = makeNode(ListenStmt);
2676 COPY_STRING_FIELD(conditionname);
2678 return newnode;
2681 static UnlistenStmt *
2682 _copyUnlistenStmt(UnlistenStmt *from)
2684 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2686 COPY_STRING_FIELD(conditionname);
2688 return newnode;
2691 static TransactionStmt *
2692 _copyTransactionStmt(TransactionStmt *from)
2694 TransactionStmt *newnode = makeNode(TransactionStmt);
2696 COPY_SCALAR_FIELD(kind);
2697 COPY_NODE_FIELD(options);
2698 COPY_STRING_FIELD(gid);
2700 return newnode;
2703 static CompositeTypeStmt *
2704 _copyCompositeTypeStmt(CompositeTypeStmt *from)
2706 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
2708 COPY_NODE_FIELD(typevar);
2709 COPY_NODE_FIELD(coldeflist);
2711 return newnode;
2714 static CreateEnumStmt *
2715 _copyCreateEnumStmt(CreateEnumStmt *from)
2717 CreateEnumStmt *newnode = makeNode(CreateEnumStmt);
2719 COPY_NODE_FIELD(typename);
2720 COPY_NODE_FIELD(vals);
2722 return newnode;
2725 static ViewStmt *
2726 _copyViewStmt(ViewStmt *from)
2728 ViewStmt *newnode = makeNode(ViewStmt);
2730 COPY_NODE_FIELD(view);
2731 COPY_NODE_FIELD(aliases);
2732 COPY_NODE_FIELD(query);
2733 COPY_SCALAR_FIELD(replace);
2735 return newnode;
2738 static LoadStmt *
2739 _copyLoadStmt(LoadStmt *from)
2741 LoadStmt *newnode = makeNode(LoadStmt);
2743 COPY_STRING_FIELD(filename);
2745 return newnode;
2748 static CreateDomainStmt *
2749 _copyCreateDomainStmt(CreateDomainStmt *from)
2751 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2753 COPY_NODE_FIELD(domainname);
2754 COPY_NODE_FIELD(typename);
2755 COPY_NODE_FIELD(constraints);
2757 return newnode;
2760 static CreateOpClassStmt *
2761 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2763 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2765 COPY_NODE_FIELD(opclassname);
2766 COPY_NODE_FIELD(opfamilyname);
2767 COPY_STRING_FIELD(amname);
2768 COPY_NODE_FIELD(datatype);
2769 COPY_NODE_FIELD(items);
2770 COPY_SCALAR_FIELD(isDefault);
2772 return newnode;
2775 static CreateOpClassItem *
2776 _copyCreateOpClassItem(CreateOpClassItem *from)
2778 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2780 COPY_SCALAR_FIELD(itemtype);
2781 COPY_NODE_FIELD(name);
2782 COPY_NODE_FIELD(args);
2783 COPY_SCALAR_FIELD(number);
2784 COPY_NODE_FIELD(class_args);
2785 COPY_NODE_FIELD(storedtype);
2787 return newnode;
2790 static CreateOpFamilyStmt *
2791 _copyCreateOpFamilyStmt(CreateOpFamilyStmt *from)
2793 CreateOpFamilyStmt *newnode = makeNode(CreateOpFamilyStmt);
2795 COPY_NODE_FIELD(opfamilyname);
2796 COPY_STRING_FIELD(amname);
2798 return newnode;
2801 static AlterOpFamilyStmt *
2802 _copyAlterOpFamilyStmt(AlterOpFamilyStmt *from)
2804 AlterOpFamilyStmt *newnode = makeNode(AlterOpFamilyStmt);
2806 COPY_NODE_FIELD(opfamilyname);
2807 COPY_STRING_FIELD(amname);
2808 COPY_SCALAR_FIELD(isDrop);
2809 COPY_NODE_FIELD(items);
2811 return newnode;
2814 static CreatedbStmt *
2815 _copyCreatedbStmt(CreatedbStmt *from)
2817 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2819 COPY_STRING_FIELD(dbname);
2820 COPY_NODE_FIELD(options);
2822 return newnode;
2825 static AlterDatabaseStmt *
2826 _copyAlterDatabaseStmt(AlterDatabaseStmt *from)
2828 AlterDatabaseStmt *newnode = makeNode(AlterDatabaseStmt);
2830 COPY_STRING_FIELD(dbname);
2831 COPY_NODE_FIELD(options);
2833 return newnode;
2836 static AlterDatabaseSetStmt *
2837 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2839 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2841 COPY_STRING_FIELD(dbname);
2842 COPY_NODE_FIELD(setstmt);
2844 return newnode;
2847 static DropdbStmt *
2848 _copyDropdbStmt(DropdbStmt *from)
2850 DropdbStmt *newnode = makeNode(DropdbStmt);
2852 COPY_STRING_FIELD(dbname);
2853 COPY_SCALAR_FIELD(missing_ok);
2855 return newnode;
2858 static VacuumStmt *
2859 _copyVacuumStmt(VacuumStmt *from)
2861 VacuumStmt *newnode = makeNode(VacuumStmt);
2863 COPY_SCALAR_FIELD(vacuum);
2864 COPY_SCALAR_FIELD(full);
2865 COPY_SCALAR_FIELD(analyze);
2866 COPY_SCALAR_FIELD(verbose);
2867 COPY_SCALAR_FIELD(freeze_min_age);
2868 COPY_SCALAR_FIELD(freeze_table_age);
2869 COPY_NODE_FIELD(relation);
2870 COPY_NODE_FIELD(va_cols);
2872 return newnode;
2875 static ExplainStmt *
2876 _copyExplainStmt(ExplainStmt *from)
2878 ExplainStmt *newnode = makeNode(ExplainStmt);
2880 COPY_NODE_FIELD(query);
2881 COPY_SCALAR_FIELD(verbose);
2882 COPY_SCALAR_FIELD(analyze);
2884 return newnode;
2887 static CreateSeqStmt *
2888 _copyCreateSeqStmt(CreateSeqStmt *from)
2890 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2892 COPY_NODE_FIELD(sequence);
2893 COPY_NODE_FIELD(options);
2895 return newnode;
2898 static AlterSeqStmt *
2899 _copyAlterSeqStmt(AlterSeqStmt *from)
2901 AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
2903 COPY_NODE_FIELD(sequence);
2904 COPY_NODE_FIELD(options);
2906 return newnode;
2909 static VariableSetStmt *
2910 _copyVariableSetStmt(VariableSetStmt *from)
2912 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2914 COPY_SCALAR_FIELD(kind);
2915 COPY_STRING_FIELD(name);
2916 COPY_NODE_FIELD(args);
2917 COPY_SCALAR_FIELD(is_local);
2919 return newnode;
2922 static VariableShowStmt *
2923 _copyVariableShowStmt(VariableShowStmt *from)
2925 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2927 COPY_STRING_FIELD(name);
2929 return newnode;
2932 static DiscardStmt *
2933 _copyDiscardStmt(DiscardStmt *from)
2935 DiscardStmt *newnode = makeNode(DiscardStmt);
2937 COPY_SCALAR_FIELD(target);
2939 return newnode;
2942 static CreateTableSpaceStmt *
2943 _copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
2945 CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
2947 COPY_STRING_FIELD(tablespacename);
2948 COPY_STRING_FIELD(owner);
2949 COPY_STRING_FIELD(location);
2951 return newnode;
2954 static DropTableSpaceStmt *
2955 _copyDropTableSpaceStmt(DropTableSpaceStmt *from)
2957 DropTableSpaceStmt *newnode = makeNode(DropTableSpaceStmt);
2959 COPY_STRING_FIELD(tablespacename);
2960 COPY_SCALAR_FIELD(missing_ok);
2962 return newnode;
2965 static CreateFdwStmt *
2966 _copyCreateFdwStmt(CreateFdwStmt *from)
2968 CreateFdwStmt *newnode = makeNode(CreateFdwStmt);
2970 COPY_STRING_FIELD(fdwname);
2971 COPY_STRING_FIELD(library);
2972 COPY_NODE_FIELD(options);
2974 return newnode;
2977 static AlterFdwStmt *
2978 _copyAlterFdwStmt(AlterFdwStmt *from)
2980 AlterFdwStmt *newnode = makeNode(AlterFdwStmt);
2982 COPY_STRING_FIELD(fdwname);
2983 COPY_STRING_FIELD(library);
2984 COPY_NODE_FIELD(options);
2986 return newnode;
2989 static DropFdwStmt *
2990 _copyDropFdwStmt(DropFdwStmt *from)
2992 DropFdwStmt *newnode = makeNode(DropFdwStmt);
2994 COPY_STRING_FIELD(fdwname);
2995 COPY_SCALAR_FIELD(missing_ok);
2996 COPY_SCALAR_FIELD(behavior);
2998 return newnode;
3001 static CreateForeignServerStmt *
3002 _copyCreateForeignServerStmt(CreateForeignServerStmt *from)
3004 CreateForeignServerStmt *newnode = makeNode(CreateForeignServerStmt);
3006 COPY_STRING_FIELD(servername);
3007 COPY_STRING_FIELD(servertype);
3008 COPY_STRING_FIELD(version);
3009 COPY_STRING_FIELD(fdwname);
3010 COPY_NODE_FIELD(options);
3012 return newnode;
3015 static AlterForeignServerStmt *
3016 _copyAlterForeignServerStmt(AlterForeignServerStmt *from)
3018 AlterForeignServerStmt *newnode = makeNode(AlterForeignServerStmt);
3020 COPY_STRING_FIELD(servername);
3021 COPY_STRING_FIELD(version);
3022 COPY_NODE_FIELD(options);
3023 COPY_SCALAR_FIELD(has_version);
3025 return newnode;
3028 static DropForeignServerStmt *
3029 _copyDropForeignServerStmt(DropForeignServerStmt *from)
3031 DropForeignServerStmt *newnode = makeNode(DropForeignServerStmt);
3033 COPY_STRING_FIELD(servername);
3034 COPY_SCALAR_FIELD(missing_ok);
3035 COPY_SCALAR_FIELD(behavior);
3037 return newnode;
3040 static CreateUserMappingStmt *
3041 _copyCreateUserMappingStmt(CreateUserMappingStmt *from)
3043 CreateUserMappingStmt *newnode = makeNode(CreateUserMappingStmt);
3045 COPY_STRING_FIELD(username);
3046 COPY_STRING_FIELD(servername);
3047 COPY_NODE_FIELD(options);
3049 return newnode;
3052 static AlterUserMappingStmt *
3053 _copyAlterUserMappingStmt(AlterUserMappingStmt *from)
3055 AlterUserMappingStmt *newnode = makeNode(AlterUserMappingStmt);
3057 COPY_STRING_FIELD(username);
3058 COPY_STRING_FIELD(servername);
3059 COPY_NODE_FIELD(options);
3061 return newnode;
3064 static DropUserMappingStmt *
3065 _copyDropUserMappingStmt(DropUserMappingStmt *from)
3067 DropUserMappingStmt *newnode = makeNode(DropUserMappingStmt);
3069 COPY_STRING_FIELD(username);
3070 COPY_STRING_FIELD(servername);
3071 COPY_SCALAR_FIELD(missing_ok);
3073 return newnode;
3076 static CreateTrigStmt *
3077 _copyCreateTrigStmt(CreateTrigStmt *from)
3079 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
3081 COPY_STRING_FIELD(trigname);
3082 COPY_NODE_FIELD(relation);
3083 COPY_NODE_FIELD(funcname);
3084 COPY_NODE_FIELD(args);
3085 COPY_SCALAR_FIELD(before);
3086 COPY_SCALAR_FIELD(row);
3087 strcpy(newnode->actions, from->actions); /* in-line string field */
3088 COPY_SCALAR_FIELD(isconstraint);
3089 COPY_SCALAR_FIELD(deferrable);
3090 COPY_SCALAR_FIELD(initdeferred);
3091 COPY_NODE_FIELD(constrrel);
3093 return newnode;
3096 static DropPropertyStmt *
3097 _copyDropPropertyStmt(DropPropertyStmt *from)
3099 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
3101 COPY_NODE_FIELD(relation);
3102 COPY_STRING_FIELD(property);
3103 COPY_SCALAR_FIELD(removeType);
3104 COPY_SCALAR_FIELD(behavior);
3105 COPY_SCALAR_FIELD(missing_ok);
3107 return newnode;
3110 static CreatePLangStmt *
3111 _copyCreatePLangStmt(CreatePLangStmt *from)
3113 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
3115 COPY_STRING_FIELD(plname);
3116 COPY_NODE_FIELD(plhandler);
3117 COPY_NODE_FIELD(plvalidator);
3118 COPY_SCALAR_FIELD(pltrusted);
3120 return newnode;
3123 static DropPLangStmt *
3124 _copyDropPLangStmt(DropPLangStmt *from)
3126 DropPLangStmt *newnode = makeNode(DropPLangStmt);
3128 COPY_STRING_FIELD(plname);
3129 COPY_SCALAR_FIELD(behavior);
3130 COPY_SCALAR_FIELD(missing_ok);
3132 return newnode;
3135 static CreateRoleStmt *
3136 _copyCreateRoleStmt(CreateRoleStmt *from)
3138 CreateRoleStmt *newnode = makeNode(CreateRoleStmt);
3140 COPY_SCALAR_FIELD(stmt_type);
3141 COPY_STRING_FIELD(role);
3142 COPY_NODE_FIELD(options);
3144 return newnode;
3147 static AlterRoleStmt *
3148 _copyAlterRoleStmt(AlterRoleStmt *from)
3150 AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
3152 COPY_STRING_FIELD(role);
3153 COPY_NODE_FIELD(options);
3154 COPY_SCALAR_FIELD(action);
3156 return newnode;
3159 static AlterRoleSetStmt *
3160 _copyAlterRoleSetStmt(AlterRoleSetStmt *from)
3162 AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
3164 COPY_STRING_FIELD(role);
3165 COPY_NODE_FIELD(setstmt);
3167 return newnode;
3170 static DropRoleStmt *
3171 _copyDropRoleStmt(DropRoleStmt *from)
3173 DropRoleStmt *newnode = makeNode(DropRoleStmt);
3175 COPY_NODE_FIELD(roles);
3176 COPY_SCALAR_FIELD(missing_ok);
3178 return newnode;
3181 static LockStmt *
3182 _copyLockStmt(LockStmt *from)
3184 LockStmt *newnode = makeNode(LockStmt);
3186 COPY_NODE_FIELD(relations);
3187 COPY_SCALAR_FIELD(mode);
3188 COPY_SCALAR_FIELD(nowait);
3190 return newnode;
3193 static ConstraintsSetStmt *
3194 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
3196 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
3198 COPY_NODE_FIELD(constraints);
3199 COPY_SCALAR_FIELD(deferred);
3201 return newnode;
3204 static ReindexStmt *
3205 _copyReindexStmt(ReindexStmt *from)
3207 ReindexStmt *newnode = makeNode(ReindexStmt);
3209 COPY_SCALAR_FIELD(kind);
3210 COPY_NODE_FIELD(relation);
3211 COPY_STRING_FIELD(name);
3212 COPY_SCALAR_FIELD(do_system);
3213 COPY_SCALAR_FIELD(do_user);
3215 return newnode;
3218 static CreateSchemaStmt *
3219 _copyCreateSchemaStmt(CreateSchemaStmt *from)
3221 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
3223 COPY_STRING_FIELD(schemaname);
3224 COPY_STRING_FIELD(authid);
3225 COPY_NODE_FIELD(schemaElts);
3227 return newnode;
3230 static CreateConversionStmt *
3231 _copyCreateConversionStmt(CreateConversionStmt *from)
3233 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
3235 COPY_NODE_FIELD(conversion_name);
3236 COPY_STRING_FIELD(for_encoding_name);
3237 COPY_STRING_FIELD(to_encoding_name);
3238 COPY_NODE_FIELD(func_name);
3239 COPY_SCALAR_FIELD(def);
3241 return newnode;
3244 static CreateCastStmt *
3245 _copyCreateCastStmt(CreateCastStmt *from)
3247 CreateCastStmt *newnode = makeNode(CreateCastStmt);
3249 COPY_NODE_FIELD(sourcetype);
3250 COPY_NODE_FIELD(targettype);
3251 COPY_NODE_FIELD(func);
3252 COPY_SCALAR_FIELD(context);
3253 COPY_SCALAR_FIELD(inout);
3255 return newnode;
3258 static DropCastStmt *
3259 _copyDropCastStmt(DropCastStmt *from)
3261 DropCastStmt *newnode = makeNode(DropCastStmt);
3263 COPY_NODE_FIELD(sourcetype);
3264 COPY_NODE_FIELD(targettype);
3265 COPY_SCALAR_FIELD(behavior);
3266 COPY_SCALAR_FIELD(missing_ok);
3268 return newnode;
3271 static PrepareStmt *
3272 _copyPrepareStmt(PrepareStmt *from)
3274 PrepareStmt *newnode = makeNode(PrepareStmt);
3276 COPY_STRING_FIELD(name);
3277 COPY_NODE_FIELD(argtypes);
3278 COPY_NODE_FIELD(query);
3280 return newnode;
3283 static ExecuteStmt *
3284 _copyExecuteStmt(ExecuteStmt *from)
3286 ExecuteStmt *newnode = makeNode(ExecuteStmt);
3288 COPY_STRING_FIELD(name);
3289 COPY_NODE_FIELD(into);
3290 COPY_NODE_FIELD(params);
3292 return newnode;
3295 static DeallocateStmt *
3296 _copyDeallocateStmt(DeallocateStmt *from)
3298 DeallocateStmt *newnode = makeNode(DeallocateStmt);
3300 COPY_STRING_FIELD(name);
3302 return newnode;
3305 static DropOwnedStmt *
3306 _copyDropOwnedStmt(DropOwnedStmt *from)
3308 DropOwnedStmt *newnode = makeNode(DropOwnedStmt);
3310 COPY_NODE_FIELD(roles);
3311 COPY_SCALAR_FIELD(behavior);
3313 return newnode;
3316 static ReassignOwnedStmt *
3317 _copyReassignOwnedStmt(ReassignOwnedStmt *from)
3319 ReassignOwnedStmt *newnode = makeNode(ReassignOwnedStmt);
3321 COPY_NODE_FIELD(roles);
3322 COPY_SCALAR_FIELD(newrole);
3324 return newnode;
3327 static AlterTSDictionaryStmt *
3328 _copyAlterTSDictionaryStmt(AlterTSDictionaryStmt *from)
3330 AlterTSDictionaryStmt *newnode = makeNode(AlterTSDictionaryStmt);
3332 COPY_NODE_FIELD(dictname);
3333 COPY_NODE_FIELD(options);
3335 return newnode;
3338 static AlterTSConfigurationStmt *
3339 _copyAlterTSConfigurationStmt(AlterTSConfigurationStmt *from)
3341 AlterTSConfigurationStmt *newnode = makeNode(AlterTSConfigurationStmt);
3343 COPY_NODE_FIELD(cfgname);
3344 COPY_NODE_FIELD(tokentype);
3345 COPY_NODE_FIELD(dicts);
3346 COPY_SCALAR_FIELD(override);
3347 COPY_SCALAR_FIELD(replace);
3348 COPY_SCALAR_FIELD(missing_ok);
3350 return newnode;
3353 /* ****************************************************************
3354 * pg_list.h copy functions
3355 * ****************************************************************
3359 * Perform a deep copy of the specified list, using copyObject(). The
3360 * list MUST be of type T_List; T_IntList and T_OidList nodes don't
3361 * need deep copies, so they should be copied via list_copy()
3363 #define COPY_NODE_CELL(new, old) \
3364 (new) = (ListCell *) palloc(sizeof(ListCell)); \
3365 lfirst(new) = copyObject(lfirst(old));
3367 static List *
3368 _copyList(List *from)
3370 List *new;
3371 ListCell *curr_old;
3372 ListCell *prev_new;
3374 Assert(list_length(from) >= 1);
3376 new = makeNode(List);
3377 new->length = from->length;
3379 COPY_NODE_CELL(new->head, from->head);
3380 prev_new = new->head;
3381 curr_old = lnext(from->head);
3383 while (curr_old)
3385 COPY_NODE_CELL(prev_new->next, curr_old);
3386 prev_new = prev_new->next;
3387 curr_old = curr_old->next;
3389 prev_new->next = NULL;
3390 new->tail = prev_new;
3392 return new;
3395 /* ****************************************************************
3396 * value.h copy functions
3397 * ****************************************************************
3399 static Value *
3400 _copyValue(Value *from)
3402 Value *newnode = makeNode(Value);
3404 /* See also _copyAConst when changing this code! */
3406 COPY_SCALAR_FIELD(type);
3407 switch (from->type)
3409 case T_Integer:
3410 COPY_SCALAR_FIELD(val.ival);
3411 break;
3412 case T_Float:
3413 case T_String:
3414 case T_BitString:
3415 COPY_STRING_FIELD(val.str);
3416 break;
3417 case T_Null:
3418 /* nothing to do */
3419 break;
3420 default:
3421 elog(ERROR, "unrecognized node type: %d",
3422 (int) from->type);
3423 break;
3425 return newnode;
3429 * copyObject
3431 * Create a copy of a Node tree or list. This is a "deep" copy: all
3432 * substructure is copied too, recursively.
3434 void *
3435 copyObject(void *from)
3437 void *retval;
3439 if (from == NULL)
3440 return NULL;
3442 switch (nodeTag(from))
3445 * PLAN NODES
3447 case T_PlannedStmt:
3448 retval = _copyPlannedStmt(from);
3449 break;
3450 case T_Plan:
3451 retval = _copyPlan(from);
3452 break;
3453 case T_Result:
3454 retval = _copyResult(from);
3455 break;
3456 case T_Append:
3457 retval = _copyAppend(from);
3458 break;
3459 case T_RecursiveUnion:
3460 retval = _copyRecursiveUnion(from);
3461 break;
3462 case T_BitmapAnd:
3463 retval = _copyBitmapAnd(from);
3464 break;
3465 case T_BitmapOr:
3466 retval = _copyBitmapOr(from);
3467 break;
3468 case T_Scan:
3469 retval = _copyScan(from);
3470 break;
3471 case T_SeqScan:
3472 retval = _copySeqScan(from);
3473 break;
3474 case T_IndexScan:
3475 retval = _copyIndexScan(from);
3476 break;
3477 case T_BitmapIndexScan:
3478 retval = _copyBitmapIndexScan(from);
3479 break;
3480 case T_BitmapHeapScan:
3481 retval = _copyBitmapHeapScan(from);
3482 break;
3483 case T_TidScan:
3484 retval = _copyTidScan(from);
3485 break;
3486 case T_SubqueryScan:
3487 retval = _copySubqueryScan(from);
3488 break;
3489 case T_FunctionScan:
3490 retval = _copyFunctionScan(from);
3491 break;
3492 case T_ValuesScan:
3493 retval = _copyValuesScan(from);
3494 break;
3495 case T_CteScan:
3496 retval = _copyCteScan(from);
3497 break;
3498 case T_WorkTableScan:
3499 retval = _copyWorkTableScan(from);
3500 break;
3501 case T_Join:
3502 retval = _copyJoin(from);
3503 break;
3504 case T_NestLoop:
3505 retval = _copyNestLoop(from);
3506 break;
3507 case T_MergeJoin:
3508 retval = _copyMergeJoin(from);
3509 break;
3510 case T_HashJoin:
3511 retval = _copyHashJoin(from);
3512 break;
3513 case T_Material:
3514 retval = _copyMaterial(from);
3515 break;
3516 case T_Sort:
3517 retval = _copySort(from);
3518 break;
3519 case T_Group:
3520 retval = _copyGroup(from);
3521 break;
3522 case T_Agg:
3523 retval = _copyAgg(from);
3524 break;
3525 case T_WindowAgg:
3526 retval = _copyWindowAgg(from);
3527 break;
3528 case T_Unique:
3529 retval = _copyUnique(from);
3530 break;
3531 case T_Hash:
3532 retval = _copyHash(from);
3533 break;
3534 case T_SetOp:
3535 retval = _copySetOp(from);
3536 break;
3537 case T_Limit:
3538 retval = _copyLimit(from);
3539 break;
3540 case T_PlanInvalItem:
3541 retval = _copyPlanInvalItem(from);
3542 break;
3545 * PRIMITIVE NODES
3547 case T_Alias:
3548 retval = _copyAlias(from);
3549 break;
3550 case T_RangeVar:
3551 retval = _copyRangeVar(from);
3552 break;
3553 case T_IntoClause:
3554 retval = _copyIntoClause(from);
3555 break;
3556 case T_Var:
3557 retval = _copyVar(from);
3558 break;
3559 case T_Const:
3560 retval = _copyConst(from);
3561 break;
3562 case T_Param:
3563 retval = _copyParam(from);
3564 break;
3565 case T_Aggref:
3566 retval = _copyAggref(from);
3567 break;
3568 case T_WindowFunc:
3569 retval = _copyWindowFunc(from);
3570 break;
3571 case T_ArrayRef:
3572 retval = _copyArrayRef(from);
3573 break;
3574 case T_FuncExpr:
3575 retval = _copyFuncExpr(from);
3576 break;
3577 case T_OpExpr:
3578 retval = _copyOpExpr(from);
3579 break;
3580 case T_DistinctExpr:
3581 retval = _copyDistinctExpr(from);
3582 break;
3583 case T_ScalarArrayOpExpr:
3584 retval = _copyScalarArrayOpExpr(from);
3585 break;
3586 case T_BoolExpr:
3587 retval = _copyBoolExpr(from);
3588 break;
3589 case T_SubLink:
3590 retval = _copySubLink(from);
3591 break;
3592 case T_SubPlan:
3593 retval = _copySubPlan(from);
3594 break;
3595 case T_AlternativeSubPlan:
3596 retval = _copyAlternativeSubPlan(from);
3597 break;
3598 case T_FieldSelect:
3599 retval = _copyFieldSelect(from);
3600 break;
3601 case T_FieldStore:
3602 retval = _copyFieldStore(from);
3603 break;
3604 case T_RelabelType:
3605 retval = _copyRelabelType(from);
3606 break;
3607 case T_CoerceViaIO:
3608 retval = _copyCoerceViaIO(from);
3609 break;
3610 case T_ArrayCoerceExpr:
3611 retval = _copyArrayCoerceExpr(from);
3612 break;
3613 case T_ConvertRowtypeExpr:
3614 retval = _copyConvertRowtypeExpr(from);
3615 break;
3616 case T_CaseExpr:
3617 retval = _copyCaseExpr(from);
3618 break;
3619 case T_CaseWhen:
3620 retval = _copyCaseWhen(from);
3621 break;
3622 case T_CaseTestExpr:
3623 retval = _copyCaseTestExpr(from);
3624 break;
3625 case T_ArrayExpr:
3626 retval = _copyArrayExpr(from);
3627 break;
3628 case T_RowExpr:
3629 retval = _copyRowExpr(from);
3630 break;
3631 case T_RowCompareExpr:
3632 retval = _copyRowCompareExpr(from);
3633 break;
3634 case T_CoalesceExpr:
3635 retval = _copyCoalesceExpr(from);
3636 break;
3637 case T_MinMaxExpr:
3638 retval = _copyMinMaxExpr(from);
3639 break;
3640 case T_XmlExpr:
3641 retval = _copyXmlExpr(from);
3642 break;
3643 case T_NullIfExpr:
3644 retval = _copyNullIfExpr(from);
3645 break;
3646 case T_NullTest:
3647 retval = _copyNullTest(from);
3648 break;
3649 case T_BooleanTest:
3650 retval = _copyBooleanTest(from);
3651 break;
3652 case T_CoerceToDomain:
3653 retval = _copyCoerceToDomain(from);
3654 break;
3655 case T_CoerceToDomainValue:
3656 retval = _copyCoerceToDomainValue(from);
3657 break;
3658 case T_SetToDefault:
3659 retval = _copySetToDefault(from);
3660 break;
3661 case T_CurrentOfExpr:
3662 retval = _copyCurrentOfExpr(from);
3663 break;
3664 case T_TargetEntry:
3665 retval = _copyTargetEntry(from);
3666 break;
3667 case T_RangeTblRef:
3668 retval = _copyRangeTblRef(from);
3669 break;
3670 case T_JoinExpr:
3671 retval = _copyJoinExpr(from);
3672 break;
3673 case T_FromExpr:
3674 retval = _copyFromExpr(from);
3675 break;
3678 * RELATION NODES
3680 case T_PathKey:
3681 retval = _copyPathKey(from);
3682 break;
3683 case T_RestrictInfo:
3684 retval = _copyRestrictInfo(from);
3685 break;
3686 case T_FlattenedSubLink:
3687 retval = _copyFlattenedSubLink(from);
3688 break;
3689 case T_PlaceHolderVar:
3690 retval = _copyPlaceHolderVar(from);
3691 break;
3692 case T_SpecialJoinInfo:
3693 retval = _copySpecialJoinInfo(from);
3694 break;
3695 case T_AppendRelInfo:
3696 retval = _copyAppendRelInfo(from);
3697 break;
3698 case T_PlaceHolderInfo:
3699 retval = _copyPlaceHolderInfo(from);
3700 break;
3703 * VALUE NODES
3705 case T_Integer:
3706 case T_Float:
3707 case T_String:
3708 case T_BitString:
3709 case T_Null:
3710 retval = _copyValue(from);
3711 break;
3714 * LIST NODES
3716 case T_List:
3717 retval = _copyList(from);
3718 break;
3721 * Lists of integers and OIDs don't need to be deep-copied, so we
3722 * perform a shallow copy via list_copy()
3724 case T_IntList:
3725 case T_OidList:
3726 retval = list_copy(from);
3727 break;
3730 * PARSE NODES
3732 case T_Query:
3733 retval = _copyQuery(from);
3734 break;
3735 case T_InsertStmt:
3736 retval = _copyInsertStmt(from);
3737 break;
3738 case T_DeleteStmt:
3739 retval = _copyDeleteStmt(from);
3740 break;
3741 case T_UpdateStmt:
3742 retval = _copyUpdateStmt(from);
3743 break;
3744 case T_SelectStmt:
3745 retval = _copySelectStmt(from);
3746 break;
3747 case T_SetOperationStmt:
3748 retval = _copySetOperationStmt(from);
3749 break;
3750 case T_AlterTableStmt:
3751 retval = _copyAlterTableStmt(from);
3752 break;
3753 case T_AlterTableCmd:
3754 retval = _copyAlterTableCmd(from);
3755 break;
3756 case T_AlterDomainStmt:
3757 retval = _copyAlterDomainStmt(from);
3758 break;
3759 case T_GrantStmt:
3760 retval = _copyGrantStmt(from);
3761 break;
3762 case T_GrantRoleStmt:
3763 retval = _copyGrantRoleStmt(from);
3764 break;
3765 case T_DeclareCursorStmt:
3766 retval = _copyDeclareCursorStmt(from);
3767 break;
3768 case T_ClosePortalStmt:
3769 retval = _copyClosePortalStmt(from);
3770 break;
3771 case T_ClusterStmt:
3772 retval = _copyClusterStmt(from);
3773 break;
3774 case T_CopyStmt:
3775 retval = _copyCopyStmt(from);
3776 break;
3777 case T_CreateStmt:
3778 retval = _copyCreateStmt(from);
3779 break;
3780 case T_InhRelation:
3781 retval = _copyInhRelation(from);
3782 break;
3783 case T_DefineStmt:
3784 retval = _copyDefineStmt(from);
3785 break;
3786 case T_DropStmt:
3787 retval = _copyDropStmt(from);
3788 break;
3789 case T_TruncateStmt:
3790 retval = _copyTruncateStmt(from);
3791 break;
3792 case T_CommentStmt:
3793 retval = _copyCommentStmt(from);
3794 break;
3795 case T_FetchStmt:
3796 retval = _copyFetchStmt(from);
3797 break;
3798 case T_IndexStmt:
3799 retval = _copyIndexStmt(from);
3800 break;
3801 case T_CreateFunctionStmt:
3802 retval = _copyCreateFunctionStmt(from);
3803 break;
3804 case T_FunctionParameter:
3805 retval = _copyFunctionParameter(from);
3806 break;
3807 case T_AlterFunctionStmt:
3808 retval = _copyAlterFunctionStmt(from);
3809 break;
3810 case T_RemoveFuncStmt:
3811 retval = _copyRemoveFuncStmt(from);
3812 break;
3813 case T_RemoveOpClassStmt:
3814 retval = _copyRemoveOpClassStmt(from);
3815 break;
3816 case T_RemoveOpFamilyStmt:
3817 retval = _copyRemoveOpFamilyStmt(from);
3818 break;
3819 case T_RenameStmt:
3820 retval = _copyRenameStmt(from);
3821 break;
3822 case T_AlterObjectSchemaStmt:
3823 retval = _copyAlterObjectSchemaStmt(from);
3824 break;
3825 case T_AlterOwnerStmt:
3826 retval = _copyAlterOwnerStmt(from);
3827 break;
3828 case T_RuleStmt:
3829 retval = _copyRuleStmt(from);
3830 break;
3831 case T_NotifyStmt:
3832 retval = _copyNotifyStmt(from);
3833 break;
3834 case T_ListenStmt:
3835 retval = _copyListenStmt(from);
3836 break;
3837 case T_UnlistenStmt:
3838 retval = _copyUnlistenStmt(from);
3839 break;
3840 case T_TransactionStmt:
3841 retval = _copyTransactionStmt(from);
3842 break;
3843 case T_CompositeTypeStmt:
3844 retval = _copyCompositeTypeStmt(from);
3845 break;
3846 case T_CreateEnumStmt:
3847 retval = _copyCreateEnumStmt(from);
3848 break;
3849 case T_ViewStmt:
3850 retval = _copyViewStmt(from);
3851 break;
3852 case T_LoadStmt:
3853 retval = _copyLoadStmt(from);
3854 break;
3855 case T_CreateDomainStmt:
3856 retval = _copyCreateDomainStmt(from);
3857 break;
3858 case T_CreateOpClassStmt:
3859 retval = _copyCreateOpClassStmt(from);
3860 break;
3861 case T_CreateOpClassItem:
3862 retval = _copyCreateOpClassItem(from);
3863 break;
3864 case T_CreateOpFamilyStmt:
3865 retval = _copyCreateOpFamilyStmt(from);
3866 break;
3867 case T_AlterOpFamilyStmt:
3868 retval = _copyAlterOpFamilyStmt(from);
3869 break;
3870 case T_CreatedbStmt:
3871 retval = _copyCreatedbStmt(from);
3872 break;
3873 case T_AlterDatabaseStmt:
3874 retval = _copyAlterDatabaseStmt(from);
3875 break;
3876 case T_AlterDatabaseSetStmt:
3877 retval = _copyAlterDatabaseSetStmt(from);
3878 break;
3879 case T_DropdbStmt:
3880 retval = _copyDropdbStmt(from);
3881 break;
3882 case T_VacuumStmt:
3883 retval = _copyVacuumStmt(from);
3884 break;
3885 case T_ExplainStmt:
3886 retval = _copyExplainStmt(from);
3887 break;
3888 case T_CreateSeqStmt:
3889 retval = _copyCreateSeqStmt(from);
3890 break;
3891 case T_AlterSeqStmt:
3892 retval = _copyAlterSeqStmt(from);
3893 break;
3894 case T_VariableSetStmt:
3895 retval = _copyVariableSetStmt(from);
3896 break;
3897 case T_VariableShowStmt:
3898 retval = _copyVariableShowStmt(from);
3899 break;
3900 case T_DiscardStmt:
3901 retval = _copyDiscardStmt(from);
3902 break;
3903 case T_CreateTableSpaceStmt:
3904 retval = _copyCreateTableSpaceStmt(from);
3905 break;
3906 case T_DropTableSpaceStmt:
3907 retval = _copyDropTableSpaceStmt(from);
3908 break;
3909 case T_CreateFdwStmt:
3910 retval = _copyCreateFdwStmt(from);
3911 break;
3912 case T_AlterFdwStmt:
3913 retval = _copyAlterFdwStmt(from);
3914 break;
3915 case T_DropFdwStmt:
3916 retval = _copyDropFdwStmt(from);
3917 break;
3918 case T_CreateForeignServerStmt:
3919 retval = _copyCreateForeignServerStmt(from);
3920 break;
3921 case T_AlterForeignServerStmt:
3922 retval = _copyAlterForeignServerStmt(from);
3923 break;
3924 case T_DropForeignServerStmt:
3925 retval = _copyDropForeignServerStmt(from);
3926 break;
3927 case T_CreateUserMappingStmt:
3928 retval = _copyCreateUserMappingStmt(from);
3929 break;
3930 case T_AlterUserMappingStmt:
3931 retval = _copyAlterUserMappingStmt(from);
3932 break;
3933 case T_DropUserMappingStmt:
3934 retval = _copyDropUserMappingStmt(from);
3935 break;
3936 case T_CreateTrigStmt:
3937 retval = _copyCreateTrigStmt(from);
3938 break;
3939 case T_DropPropertyStmt:
3940 retval = _copyDropPropertyStmt(from);
3941 break;
3942 case T_CreatePLangStmt:
3943 retval = _copyCreatePLangStmt(from);
3944 break;
3945 case T_DropPLangStmt:
3946 retval = _copyDropPLangStmt(from);
3947 break;
3948 case T_CreateRoleStmt:
3949 retval = _copyCreateRoleStmt(from);
3950 break;
3951 case T_AlterRoleStmt:
3952 retval = _copyAlterRoleStmt(from);
3953 break;
3954 case T_AlterRoleSetStmt:
3955 retval = _copyAlterRoleSetStmt(from);
3956 break;
3957 case T_DropRoleStmt:
3958 retval = _copyDropRoleStmt(from);
3959 break;
3960 case T_LockStmt:
3961 retval = _copyLockStmt(from);
3962 break;
3963 case T_ConstraintsSetStmt:
3964 retval = _copyConstraintsSetStmt(from);
3965 break;
3966 case T_ReindexStmt:
3967 retval = _copyReindexStmt(from);
3968 break;
3969 case T_CheckPointStmt:
3970 retval = (void *) makeNode(CheckPointStmt);
3971 break;
3972 case T_CreateSchemaStmt:
3973 retval = _copyCreateSchemaStmt(from);
3974 break;
3975 case T_CreateConversionStmt:
3976 retval = _copyCreateConversionStmt(from);
3977 break;
3978 case T_CreateCastStmt:
3979 retval = _copyCreateCastStmt(from);
3980 break;
3981 case T_DropCastStmt:
3982 retval = _copyDropCastStmt(from);
3983 break;
3984 case T_PrepareStmt:
3985 retval = _copyPrepareStmt(from);
3986 break;
3987 case T_ExecuteStmt:
3988 retval = _copyExecuteStmt(from);
3989 break;
3990 case T_DeallocateStmt:
3991 retval = _copyDeallocateStmt(from);
3992 break;
3993 case T_DropOwnedStmt:
3994 retval = _copyDropOwnedStmt(from);
3995 break;
3996 case T_ReassignOwnedStmt:
3997 retval = _copyReassignOwnedStmt(from);
3998 break;
3999 case T_AlterTSDictionaryStmt:
4000 retval = _copyAlterTSDictionaryStmt(from);
4001 break;
4002 case T_AlterTSConfigurationStmt:
4003 retval = _copyAlterTSConfigurationStmt(from);
4004 break;
4006 case T_A_Expr:
4007 retval = _copyAExpr(from);
4008 break;
4009 case T_ColumnRef:
4010 retval = _copyColumnRef(from);
4011 break;
4012 case T_ParamRef:
4013 retval = _copyParamRef(from);
4014 break;
4015 case T_A_Const:
4016 retval = _copyAConst(from);
4017 break;
4018 case T_FuncCall:
4019 retval = _copyFuncCall(from);
4020 break;
4021 case T_A_Star:
4022 retval = _copyAStar(from);
4023 break;
4024 case T_A_Indices:
4025 retval = _copyAIndices(from);
4026 break;
4027 case T_A_Indirection:
4028 retval = _copyA_Indirection(from);
4029 break;
4030 case T_A_ArrayExpr:
4031 retval = _copyA_ArrayExpr(from);
4032 break;
4033 case T_ResTarget:
4034 retval = _copyResTarget(from);
4035 break;
4036 case T_TypeCast:
4037 retval = _copyTypeCast(from);
4038 break;
4039 case T_SortBy:
4040 retval = _copySortBy(from);
4041 break;
4042 case T_WindowDef:
4043 retval = _copyWindowDef(from);
4044 break;
4045 case T_RangeSubselect:
4046 retval = _copyRangeSubselect(from);
4047 break;
4048 case T_RangeFunction:
4049 retval = _copyRangeFunction(from);
4050 break;
4051 case T_TypeName:
4052 retval = _copyTypeName(from);
4053 break;
4054 case T_IndexElem:
4055 retval = _copyIndexElem(from);
4056 break;
4057 case T_ColumnDef:
4058 retval = _copyColumnDef(from);
4059 break;
4060 case T_Constraint:
4061 retval = _copyConstraint(from);
4062 break;
4063 case T_DefElem:
4064 retval = _copyDefElem(from);
4065 break;
4066 case T_OptionDefElem:
4067 retval = _copyOptionDefElem(from);
4068 break;
4069 case T_LockingClause:
4070 retval = _copyLockingClause(from);
4071 break;
4072 case T_RangeTblEntry:
4073 retval = _copyRangeTblEntry(from);
4074 break;
4075 case T_SortGroupClause:
4076 retval = _copySortGroupClause(from);
4077 break;
4078 case T_WindowClause:
4079 retval = _copyWindowClause(from);
4080 break;
4081 case T_RowMarkClause:
4082 retval = _copyRowMarkClause(from);
4083 break;
4084 case T_WithClause:
4085 retval = _copyWithClause(from);
4086 break;
4087 case T_CommonTableExpr:
4088 retval = _copyCommonTableExpr(from);
4089 break;
4090 case T_FkConstraint:
4091 retval = _copyFkConstraint(from);
4092 break;
4093 case T_PrivGrantee:
4094 retval = _copyPrivGrantee(from);
4095 break;
4096 case T_FuncWithArgs:
4097 retval = _copyFuncWithArgs(from);
4098 break;
4099 case T_XmlSerialize:
4100 retval = _copyXmlSerialize(from);
4101 break;
4103 default:
4104 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
4105 retval = from; /* keep compiler quiet */
4106 break;
4109 return retval;