]> granicus.if.org Git - postgresql/blob - src/backend/nodes/copyfuncs.c
7b003dc095c8446fb4ef0deea1a527c2d36020cc
[postgresql] / src / backend / nodes / copyfuncs.c
1 /*-------------------------------------------------------------------------
2  *
3  * copyfuncs.c
4  *        Copy functions for Postgres tree nodes.
5  *
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.
12  *
13  *
14  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
15  * Portions Copyright (c) 1994, Regents of the University of California
16  *
17  * IDENTIFICATION
18  *        $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.362 2007/01/20 20:45:38 tgl Exp $
19  *
20  *-------------------------------------------------------------------------
21  */
22
23 #include "postgres.h"
24
25 #include "nodes/plannodes.h"
26 #include "nodes/relation.h"
27 #include "utils/datum.h"
28
29
30 /*
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'.
35  */
36
37 /* Copy a simple scalar field (int, float, bool, enum, etc) */
38 #define COPY_SCALAR_FIELD(fldname) \
39         (newnode->fldname = from->fldname)
40
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))
44
45 /* Copy a field that is a pointer to a Bitmapset */
46 #define COPY_BITMAPSET_FIELD(fldname) \
47         (newnode->fldname = bms_copy(from->fldname))
48
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)
52
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)
60
61
62 /* ****************************************************************
63  *                                       plannodes.h copy functions
64  * ****************************************************************
65  */
66
67 /*
68  * CopyPlanFields
69  *
70  *              This function copies the fields of the Plan node.  It is used by
71  *              all the copy functions for classes which inherit from Plan.
72  */
73 static void
74 CopyPlanFields(Plan *from, Plan *newnode)
75 {
76         COPY_SCALAR_FIELD(startup_cost);
77         COPY_SCALAR_FIELD(total_cost);
78         COPY_SCALAR_FIELD(plan_rows);
79         COPY_SCALAR_FIELD(plan_width);
80         COPY_NODE_FIELD(targetlist);
81         COPY_NODE_FIELD(qual);
82         COPY_NODE_FIELD(lefttree);
83         COPY_NODE_FIELD(righttree);
84         COPY_NODE_FIELD(initPlan);
85         COPY_BITMAPSET_FIELD(extParam);
86         COPY_BITMAPSET_FIELD(allParam);
87         COPY_SCALAR_FIELD(nParamExec);
88 }
89
90 /*
91  * _copyPlan
92  */
93 static Plan *
94 _copyPlan(Plan *from)
95 {
96         Plan       *newnode = makeNode(Plan);
97
98         /*
99          * copy node superclass fields
100          */
101         CopyPlanFields(from, newnode);
102
103         return newnode;
104 }
105
106
107 /*
108  * _copyResult
109  */
110 static Result *
111 _copyResult(Result *from)
112 {
113         Result     *newnode = makeNode(Result);
114
115         /*
116          * copy node superclass fields
117          */
118         CopyPlanFields((Plan *) from, (Plan *) newnode);
119
120         /*
121          * copy remainder of node
122          */
123         COPY_NODE_FIELD(resconstantqual);
124
125         return newnode;
126 }
127
128 /*
129  * _copyAppend
130  */
131 static Append *
132 _copyAppend(Append *from)
133 {
134         Append     *newnode = makeNode(Append);
135
136         /*
137          * copy node superclass fields
138          */
139         CopyPlanFields((Plan *) from, (Plan *) newnode);
140
141         /*
142          * copy remainder of node
143          */
144         COPY_NODE_FIELD(appendplans);
145         COPY_SCALAR_FIELD(isTarget);
146
147         return newnode;
148 }
149
150 /*
151  * _copyBitmapAnd
152  */
153 static BitmapAnd *
154 _copyBitmapAnd(BitmapAnd *from)
155 {
156         BitmapAnd  *newnode = makeNode(BitmapAnd);
157
158         /*
159          * copy node superclass fields
160          */
161         CopyPlanFields((Plan *) from, (Plan *) newnode);
162
163         /*
164          * copy remainder of node
165          */
166         COPY_NODE_FIELD(bitmapplans);
167
168         return newnode;
169 }
170
171 /*
172  * _copyBitmapOr
173  */
174 static BitmapOr *
175 _copyBitmapOr(BitmapOr *from)
176 {
177         BitmapOr   *newnode = makeNode(BitmapOr);
178
179         /*
180          * copy node superclass fields
181          */
182         CopyPlanFields((Plan *) from, (Plan *) newnode);
183
184         /*
185          * copy remainder of node
186          */
187         COPY_NODE_FIELD(bitmapplans);
188
189         return newnode;
190 }
191
192
193 /*
194  * CopyScanFields
195  *
196  *              This function copies the fields of the Scan node.  It is used by
197  *              all the copy functions for classes which inherit from Scan.
198  */
199 static void
200 CopyScanFields(Scan *from, Scan *newnode)
201 {
202         CopyPlanFields((Plan *) from, (Plan *) newnode);
203
204         COPY_SCALAR_FIELD(scanrelid);
205 }
206
207 /*
208  * _copyScan
209  */
210 static Scan *
211 _copyScan(Scan *from)
212 {
213         Scan       *newnode = makeNode(Scan);
214
215         /*
216          * copy node superclass fields
217          */
218         CopyScanFields((Scan *) from, (Scan *) newnode);
219
220         return newnode;
221 }
222
223 /*
224  * _copySeqScan
225  */
226 static SeqScan *
227 _copySeqScan(SeqScan *from)
228 {
229         SeqScan    *newnode = makeNode(SeqScan);
230
231         /*
232          * copy node superclass fields
233          */
234         CopyScanFields((Scan *) from, (Scan *) newnode);
235
236         return newnode;
237 }
238
239 /*
240  * _copyIndexScan
241  */
242 static IndexScan *
243 _copyIndexScan(IndexScan *from)
244 {
245         IndexScan  *newnode = makeNode(IndexScan);
246
247         /*
248          * copy node superclass fields
249          */
250         CopyScanFields((Scan *) from, (Scan *) newnode);
251
252         /*
253          * copy remainder of node
254          */
255         COPY_SCALAR_FIELD(indexid);
256         COPY_NODE_FIELD(indexqual);
257         COPY_NODE_FIELD(indexqualorig);
258         COPY_NODE_FIELD(indexstrategy);
259         COPY_NODE_FIELD(indexsubtype);
260         COPY_SCALAR_FIELD(indexorderdir);
261
262         return newnode;
263 }
264
265 /*
266  * _copyBitmapIndexScan
267  */
268 static BitmapIndexScan *
269 _copyBitmapIndexScan(BitmapIndexScan *from)
270 {
271         BitmapIndexScan *newnode = makeNode(BitmapIndexScan);
272
273         /*
274          * copy node superclass fields
275          */
276         CopyScanFields((Scan *) from, (Scan *) newnode);
277
278         /*
279          * copy remainder of node
280          */
281         COPY_SCALAR_FIELD(indexid);
282         COPY_NODE_FIELD(indexqual);
283         COPY_NODE_FIELD(indexqualorig);
284         COPY_NODE_FIELD(indexstrategy);
285         COPY_NODE_FIELD(indexsubtype);
286
287         return newnode;
288 }
289
290 /*
291  * _copyBitmapHeapScan
292  */
293 static BitmapHeapScan *
294 _copyBitmapHeapScan(BitmapHeapScan *from)
295 {
296         BitmapHeapScan *newnode = makeNode(BitmapHeapScan);
297
298         /*
299          * copy node superclass fields
300          */
301         CopyScanFields((Scan *) from, (Scan *) newnode);
302
303         /*
304          * copy remainder of node
305          */
306         COPY_NODE_FIELD(bitmapqualorig);
307
308         return newnode;
309 }
310
311 /*
312  * _copyTidScan
313  */
314 static TidScan *
315 _copyTidScan(TidScan *from)
316 {
317         TidScan    *newnode = makeNode(TidScan);
318
319         /*
320          * copy node superclass fields
321          */
322         CopyScanFields((Scan *) from, (Scan *) newnode);
323
324         /*
325          * copy remainder of node
326          */
327         COPY_NODE_FIELD(tidquals);
328
329         return newnode;
330 }
331
332 /*
333  * _copySubqueryScan
334  */
335 static SubqueryScan *
336 _copySubqueryScan(SubqueryScan *from)
337 {
338         SubqueryScan *newnode = makeNode(SubqueryScan);
339
340         /*
341          * copy node superclass fields
342          */
343         CopyScanFields((Scan *) from, (Scan *) newnode);
344
345         /*
346          * copy remainder of node
347          */
348         COPY_NODE_FIELD(subplan);
349
350         return newnode;
351 }
352
353 /*
354  * _copyFunctionScan
355  */
356 static FunctionScan *
357 _copyFunctionScan(FunctionScan *from)
358 {
359         FunctionScan *newnode = makeNode(FunctionScan);
360
361         /*
362          * copy node superclass fields
363          */
364         CopyScanFields((Scan *) from, (Scan *) newnode);
365
366         return newnode;
367 }
368
369 /*
370  * _copyValuesScan
371  */
372 static ValuesScan *
373 _copyValuesScan(ValuesScan *from)
374 {
375         ValuesScan *newnode = makeNode(ValuesScan);
376
377         /*
378          * copy node superclass fields
379          */
380         CopyScanFields((Scan *) from, (Scan *) newnode);
381
382         return newnode;
383 }
384
385 /*
386  * CopyJoinFields
387  *
388  *              This function copies the fields of the Join node.  It is used by
389  *              all the copy functions for classes which inherit from Join.
390  */
391 static void
392 CopyJoinFields(Join *from, Join *newnode)
393 {
394         CopyPlanFields((Plan *) from, (Plan *) newnode);
395
396         COPY_SCALAR_FIELD(jointype);
397         COPY_NODE_FIELD(joinqual);
398 }
399
400
401 /*
402  * _copyJoin
403  */
404 static Join *
405 _copyJoin(Join *from)
406 {
407         Join       *newnode = makeNode(Join);
408
409         /*
410          * copy node superclass fields
411          */
412         CopyJoinFields(from, newnode);
413
414         return newnode;
415 }
416
417
418 /*
419  * _copyNestLoop
420  */
421 static NestLoop *
422 _copyNestLoop(NestLoop *from)
423 {
424         NestLoop   *newnode = makeNode(NestLoop);
425
426         /*
427          * copy node superclass fields
428          */
429         CopyJoinFields((Join *) from, (Join *) newnode);
430
431         return newnode;
432 }
433
434
435 /*
436  * _copyMergeJoin
437  */
438 static MergeJoin *
439 _copyMergeJoin(MergeJoin *from)
440 {
441         MergeJoin  *newnode = makeNode(MergeJoin);
442         int                     numCols;
443
444         /*
445          * copy node superclass fields
446          */
447         CopyJoinFields((Join *) from, (Join *) newnode);
448
449         /*
450          * copy remainder of node
451          */
452         COPY_NODE_FIELD(mergeclauses);
453         numCols = list_length(from->mergeclauses);
454         COPY_POINTER_FIELD(mergeFamilies, numCols * sizeof(Oid));
455         COPY_POINTER_FIELD(mergeStrategies, numCols * sizeof(int));
456         COPY_POINTER_FIELD(mergeNullsFirst, numCols * sizeof(bool));
457
458         return newnode;
459 }
460
461 /*
462  * _copyHashJoin
463  */
464 static HashJoin *
465 _copyHashJoin(HashJoin *from)
466 {
467         HashJoin   *newnode = makeNode(HashJoin);
468
469         /*
470          * copy node superclass fields
471          */
472         CopyJoinFields((Join *) from, (Join *) newnode);
473
474         /*
475          * copy remainder of node
476          */
477         COPY_NODE_FIELD(hashclauses);
478
479         return newnode;
480 }
481
482
483 /*
484  * _copyMaterial
485  */
486 static Material *
487 _copyMaterial(Material *from)
488 {
489         Material   *newnode = makeNode(Material);
490
491         /*
492          * copy node superclass fields
493          */
494         CopyPlanFields((Plan *) from, (Plan *) newnode);
495
496         return newnode;
497 }
498
499
500 /*
501  * _copySort
502  */
503 static Sort *
504 _copySort(Sort *from)
505 {
506         Sort       *newnode = makeNode(Sort);
507
508         /*
509          * copy node superclass fields
510          */
511         CopyPlanFields((Plan *) from, (Plan *) newnode);
512
513         COPY_SCALAR_FIELD(numCols);
514         COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
515         COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
516         COPY_POINTER_FIELD(nullsFirst, from->numCols * sizeof(bool));
517
518         return newnode;
519 }
520
521
522 /*
523  * _copyGroup
524  */
525 static Group *
526 _copyGroup(Group *from)
527 {
528         Group      *newnode = makeNode(Group);
529
530         CopyPlanFields((Plan *) from, (Plan *) newnode);
531
532         COPY_SCALAR_FIELD(numCols);
533         COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
534         COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
535
536         return newnode;
537 }
538
539 /*
540  * _copyAgg
541  */
542 static Agg *
543 _copyAgg(Agg *from)
544 {
545         Agg                *newnode = makeNode(Agg);
546
547         CopyPlanFields((Plan *) from, (Plan *) newnode);
548
549         COPY_SCALAR_FIELD(aggstrategy);
550         COPY_SCALAR_FIELD(numCols);
551         if (from->numCols > 0)
552         {
553                 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
554                 COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
555         }
556         COPY_SCALAR_FIELD(numGroups);
557
558         return newnode;
559 }
560
561 /*
562  * _copyUnique
563  */
564 static Unique *
565 _copyUnique(Unique *from)
566 {
567         Unique     *newnode = makeNode(Unique);
568
569         /*
570          * copy node superclass fields
571          */
572         CopyPlanFields((Plan *) from, (Plan *) newnode);
573
574         /*
575          * copy remainder of node
576          */
577         COPY_SCALAR_FIELD(numCols);
578         COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
579         COPY_POINTER_FIELD(uniqOperators, from->numCols * sizeof(Oid));
580
581         return newnode;
582 }
583
584 /*
585  * _copyHash
586  */
587 static Hash *
588 _copyHash(Hash *from)
589 {
590         Hash       *newnode = makeNode(Hash);
591
592         /*
593          * copy node superclass fields
594          */
595         CopyPlanFields((Plan *) from, (Plan *) newnode);
596
597         /*
598          * copy remainder of node
599          */
600
601         return newnode;
602 }
603
604 /*
605  * _copySetOp
606  */
607 static SetOp *
608 _copySetOp(SetOp *from)
609 {
610         SetOp      *newnode = makeNode(SetOp);
611
612         /*
613          * copy node superclass fields
614          */
615         CopyPlanFields((Plan *) from, (Plan *) newnode);
616
617         /*
618          * copy remainder of node
619          */
620         COPY_SCALAR_FIELD(cmd);
621         COPY_SCALAR_FIELD(numCols);
622         COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
623         COPY_POINTER_FIELD(dupOperators, from->numCols * sizeof(Oid));
624         COPY_SCALAR_FIELD(flagColIdx);
625
626         return newnode;
627 }
628
629 /*
630  * _copyLimit
631  */
632 static Limit *
633 _copyLimit(Limit *from)
634 {
635         Limit      *newnode = makeNode(Limit);
636
637         /*
638          * copy node superclass fields
639          */
640         CopyPlanFields((Plan *) from, (Plan *) newnode);
641
642         /*
643          * copy remainder of node
644          */
645         COPY_NODE_FIELD(limitOffset);
646         COPY_NODE_FIELD(limitCount);
647
648         return newnode;
649 }
650
651 /* ****************************************************************
652  *                                         primnodes.h copy functions
653  * ****************************************************************
654  */
655
656 /*
657  * _copyAlias
658  */
659 static Alias *
660 _copyAlias(Alias *from)
661 {
662         Alias      *newnode = makeNode(Alias);
663
664         COPY_STRING_FIELD(aliasname);
665         COPY_NODE_FIELD(colnames);
666
667         return newnode;
668 }
669
670 /*
671  * _copyRangeVar
672  */
673 static RangeVar *
674 _copyRangeVar(RangeVar *from)
675 {
676         RangeVar   *newnode = makeNode(RangeVar);
677
678         COPY_STRING_FIELD(catalogname);
679         COPY_STRING_FIELD(schemaname);
680         COPY_STRING_FIELD(relname);
681         COPY_SCALAR_FIELD(inhOpt);
682         COPY_SCALAR_FIELD(istemp);
683         COPY_NODE_FIELD(alias);
684
685         return newnode;
686 }
687
688 /*
689  * We don't need a _copyExpr because Expr is an abstract supertype which
690  * should never actually get instantiated.      Also, since it has no common
691  * fields except NodeTag, there's no need for a helper routine to factor
692  * out copying the common fields...
693  */
694
695 /*
696  * _copyVar
697  */
698 static Var *
699 _copyVar(Var *from)
700 {
701         Var                *newnode = makeNode(Var);
702
703         COPY_SCALAR_FIELD(varno);
704         COPY_SCALAR_FIELD(varattno);
705         COPY_SCALAR_FIELD(vartype);
706         COPY_SCALAR_FIELD(vartypmod);
707         COPY_SCALAR_FIELD(varlevelsup);
708         COPY_SCALAR_FIELD(varnoold);
709         COPY_SCALAR_FIELD(varoattno);
710
711         return newnode;
712 }
713
714 /*
715  * _copyConst
716  */
717 static Const *
718 _copyConst(Const *from)
719 {
720         Const      *newnode = makeNode(Const);
721
722         COPY_SCALAR_FIELD(consttype);
723         COPY_SCALAR_FIELD(constlen);
724
725         if (from->constbyval || from->constisnull)
726         {
727                 /*
728                  * passed by value so just copy the datum. Also, don't try to copy
729                  * struct when value is null!
730                  */
731                 newnode->constvalue = from->constvalue;
732         }
733         else
734         {
735                 /*
736                  * passed by reference.  We need a palloc'd copy.
737                  */
738                 newnode->constvalue = datumCopy(from->constvalue,
739                                                                                 from->constbyval,
740                                                                                 from->constlen);
741         }
742
743         COPY_SCALAR_FIELD(constisnull);
744         COPY_SCALAR_FIELD(constbyval);
745
746         return newnode;
747 }
748
749 /*
750  * _copyParam
751  */
752 static Param *
753 _copyParam(Param *from)
754 {
755         Param      *newnode = makeNode(Param);
756
757         COPY_SCALAR_FIELD(paramkind);
758         COPY_SCALAR_FIELD(paramid);
759         COPY_SCALAR_FIELD(paramtype);
760         COPY_SCALAR_FIELD(paramtypmod);
761
762         return newnode;
763 }
764
765 /*
766  * _copyAggref
767  */
768 static Aggref *
769 _copyAggref(Aggref *from)
770 {
771         Aggref     *newnode = makeNode(Aggref);
772
773         COPY_SCALAR_FIELD(aggfnoid);
774         COPY_SCALAR_FIELD(aggtype);
775         COPY_NODE_FIELD(args);
776         COPY_SCALAR_FIELD(agglevelsup);
777         COPY_SCALAR_FIELD(aggstar);
778         COPY_SCALAR_FIELD(aggdistinct);
779
780         return newnode;
781 }
782
783 /*
784  * _copyArrayRef
785  */
786 static ArrayRef *
787 _copyArrayRef(ArrayRef *from)
788 {
789         ArrayRef   *newnode = makeNode(ArrayRef);
790
791         COPY_SCALAR_FIELD(refrestype);
792         COPY_SCALAR_FIELD(refarraytype);
793         COPY_SCALAR_FIELD(refelemtype);
794         COPY_NODE_FIELD(refupperindexpr);
795         COPY_NODE_FIELD(reflowerindexpr);
796         COPY_NODE_FIELD(refexpr);
797         COPY_NODE_FIELD(refassgnexpr);
798
799         return newnode;
800 }
801
802 /*
803  * _copyFuncExpr
804  */
805 static FuncExpr *
806 _copyFuncExpr(FuncExpr *from)
807 {
808         FuncExpr   *newnode = makeNode(FuncExpr);
809
810         COPY_SCALAR_FIELD(funcid);
811         COPY_SCALAR_FIELD(funcresulttype);
812         COPY_SCALAR_FIELD(funcretset);
813         COPY_SCALAR_FIELD(funcformat);
814         COPY_NODE_FIELD(args);
815
816         return newnode;
817 }
818
819 /*
820  * _copyOpExpr
821  */
822 static OpExpr *
823 _copyOpExpr(OpExpr *from)
824 {
825         OpExpr     *newnode = makeNode(OpExpr);
826
827         COPY_SCALAR_FIELD(opno);
828         COPY_SCALAR_FIELD(opfuncid);
829         COPY_SCALAR_FIELD(opresulttype);
830         COPY_SCALAR_FIELD(opretset);
831         COPY_NODE_FIELD(args);
832
833         return newnode;
834 }
835
836 /*
837  * _copyDistinctExpr (same as OpExpr)
838  */
839 static DistinctExpr *
840 _copyDistinctExpr(DistinctExpr *from)
841 {
842         DistinctExpr *newnode = makeNode(DistinctExpr);
843
844         COPY_SCALAR_FIELD(opno);
845         COPY_SCALAR_FIELD(opfuncid);
846         COPY_SCALAR_FIELD(opresulttype);
847         COPY_SCALAR_FIELD(opretset);
848         COPY_NODE_FIELD(args);
849
850         return newnode;
851 }
852
853 /*
854  * _copyScalarArrayOpExpr
855  */
856 static ScalarArrayOpExpr *
857 _copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
858 {
859         ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
860
861         COPY_SCALAR_FIELD(opno);
862         COPY_SCALAR_FIELD(opfuncid);
863         COPY_SCALAR_FIELD(useOr);
864         COPY_NODE_FIELD(args);
865
866         return newnode;
867 }
868
869 /*
870  * _copyBoolExpr
871  */
872 static BoolExpr *
873 _copyBoolExpr(BoolExpr *from)
874 {
875         BoolExpr   *newnode = makeNode(BoolExpr);
876
877         COPY_SCALAR_FIELD(boolop);
878         COPY_NODE_FIELD(args);
879
880         return newnode;
881 }
882
883 /*
884  * _copySubLink
885  */
886 static SubLink *
887 _copySubLink(SubLink *from)
888 {
889         SubLink    *newnode = makeNode(SubLink);
890
891         COPY_SCALAR_FIELD(subLinkType);
892         COPY_NODE_FIELD(testexpr);
893         COPY_NODE_FIELD(operName);
894         COPY_NODE_FIELD(subselect);
895
896         return newnode;
897 }
898
899 /*
900  * _copySubPlan
901  */
902 static SubPlan *
903 _copySubPlan(SubPlan *from)
904 {
905         SubPlan    *newnode = makeNode(SubPlan);
906
907         COPY_SCALAR_FIELD(subLinkType);
908         COPY_NODE_FIELD(testexpr);
909         COPY_NODE_FIELD(paramIds);
910         COPY_NODE_FIELD(plan);
911         COPY_SCALAR_FIELD(plan_id);
912         COPY_NODE_FIELD(rtable);
913         COPY_SCALAR_FIELD(useHashTable);
914         COPY_SCALAR_FIELD(unknownEqFalse);
915         COPY_NODE_FIELD(setParam);
916         COPY_NODE_FIELD(parParam);
917         COPY_NODE_FIELD(args);
918
919         return newnode;
920 }
921
922 /*
923  * _copyFieldSelect
924  */
925 static FieldSelect *
926 _copyFieldSelect(FieldSelect *from)
927 {
928         FieldSelect *newnode = makeNode(FieldSelect);
929
930         COPY_NODE_FIELD(arg);
931         COPY_SCALAR_FIELD(fieldnum);
932         COPY_SCALAR_FIELD(resulttype);
933         COPY_SCALAR_FIELD(resulttypmod);
934
935         return newnode;
936 }
937
938 /*
939  * _copyFieldStore
940  */
941 static FieldStore *
942 _copyFieldStore(FieldStore *from)
943 {
944         FieldStore *newnode = makeNode(FieldStore);
945
946         COPY_NODE_FIELD(arg);
947         COPY_NODE_FIELD(newvals);
948         COPY_NODE_FIELD(fieldnums);
949         COPY_SCALAR_FIELD(resulttype);
950
951         return newnode;
952 }
953
954 /*
955  * _copyRelabelType
956  */
957 static RelabelType *
958 _copyRelabelType(RelabelType *from)
959 {
960         RelabelType *newnode = makeNode(RelabelType);
961
962         COPY_NODE_FIELD(arg);
963         COPY_SCALAR_FIELD(resulttype);
964         COPY_SCALAR_FIELD(resulttypmod);
965         COPY_SCALAR_FIELD(relabelformat);
966
967         return newnode;
968 }
969
970 /*
971  * _copyConvertRowtypeExpr
972  */
973 static ConvertRowtypeExpr *
974 _copyConvertRowtypeExpr(ConvertRowtypeExpr *from)
975 {
976         ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);
977
978         COPY_NODE_FIELD(arg);
979         COPY_SCALAR_FIELD(resulttype);
980         COPY_SCALAR_FIELD(convertformat);
981
982         return newnode;
983 }
984
985 /*
986  * _copyCaseExpr
987  */
988 static CaseExpr *
989 _copyCaseExpr(CaseExpr *from)
990 {
991         CaseExpr   *newnode = makeNode(CaseExpr);
992
993         COPY_SCALAR_FIELD(casetype);
994         COPY_NODE_FIELD(arg);
995         COPY_NODE_FIELD(args);
996         COPY_NODE_FIELD(defresult);
997
998         return newnode;
999 }
1000
1001 /*
1002  * _copyCaseWhen
1003  */
1004 static CaseWhen *
1005 _copyCaseWhen(CaseWhen *from)
1006 {
1007         CaseWhen   *newnode = makeNode(CaseWhen);
1008
1009         COPY_NODE_FIELD(expr);
1010         COPY_NODE_FIELD(result);
1011
1012         return newnode;
1013 }
1014
1015 /*
1016  * _copyCaseTestExpr
1017  */
1018 static CaseTestExpr *
1019 _copyCaseTestExpr(CaseTestExpr *from)
1020 {
1021         CaseTestExpr *newnode = makeNode(CaseTestExpr);
1022
1023         COPY_SCALAR_FIELD(typeId);
1024         COPY_SCALAR_FIELD(typeMod);
1025
1026         return newnode;
1027 }
1028
1029 /*
1030  * _copyArrayExpr
1031  */
1032 static ArrayExpr *
1033 _copyArrayExpr(ArrayExpr *from)
1034 {
1035         ArrayExpr  *newnode = makeNode(ArrayExpr);
1036
1037         COPY_SCALAR_FIELD(array_typeid);
1038         COPY_SCALAR_FIELD(element_typeid);
1039         COPY_NODE_FIELD(elements);
1040         COPY_SCALAR_FIELD(multidims);
1041
1042         return newnode;
1043 }
1044
1045 /*
1046  * _copyRowExpr
1047  */
1048 static RowExpr *
1049 _copyRowExpr(RowExpr *from)
1050 {
1051         RowExpr    *newnode = makeNode(RowExpr);
1052
1053         COPY_NODE_FIELD(args);
1054         COPY_SCALAR_FIELD(row_typeid);
1055         COPY_SCALAR_FIELD(row_format);
1056
1057         return newnode;
1058 }
1059
1060 /*
1061  * _copyRowCompareExpr
1062  */
1063 static RowCompareExpr *
1064 _copyRowCompareExpr(RowCompareExpr *from)
1065 {
1066         RowCompareExpr *newnode = makeNode(RowCompareExpr);
1067
1068         COPY_SCALAR_FIELD(rctype);
1069         COPY_NODE_FIELD(opnos);
1070         COPY_NODE_FIELD(opfamilies);
1071         COPY_NODE_FIELD(largs);
1072         COPY_NODE_FIELD(rargs);
1073
1074         return newnode;
1075 }
1076
1077 /*
1078  * _copyCoalesceExpr
1079  */
1080 static CoalesceExpr *
1081 _copyCoalesceExpr(CoalesceExpr *from)
1082 {
1083         CoalesceExpr *newnode = makeNode(CoalesceExpr);
1084
1085         COPY_SCALAR_FIELD(coalescetype);
1086         COPY_NODE_FIELD(args);
1087
1088         return newnode;
1089 }
1090
1091 /*
1092  * _copyMinMaxExpr
1093  */
1094 static MinMaxExpr *
1095 _copyMinMaxExpr(MinMaxExpr *from)
1096 {
1097         MinMaxExpr *newnode = makeNode(MinMaxExpr);
1098
1099         COPY_SCALAR_FIELD(minmaxtype);
1100         COPY_SCALAR_FIELD(op);
1101         COPY_NODE_FIELD(args);
1102
1103         return newnode;
1104 }
1105
1106 /*
1107  * _copyXmlExpr
1108  */
1109 static XmlExpr *
1110 _copyXmlExpr(XmlExpr *from)
1111 {
1112         XmlExpr *newnode = makeNode(XmlExpr);
1113
1114         COPY_SCALAR_FIELD(op);
1115         COPY_STRING_FIELD(name);
1116         COPY_NODE_FIELD(named_args);
1117         COPY_NODE_FIELD(arg_names);
1118         COPY_NODE_FIELD(args);
1119
1120         return newnode;
1121 }
1122
1123 /*
1124  * _copyNullIfExpr (same as OpExpr)
1125  */
1126 static NullIfExpr *
1127 _copyNullIfExpr(NullIfExpr *from)
1128 {
1129         NullIfExpr *newnode = makeNode(NullIfExpr);
1130
1131         COPY_SCALAR_FIELD(opno);
1132         COPY_SCALAR_FIELD(opfuncid);
1133         COPY_SCALAR_FIELD(opresulttype);
1134         COPY_SCALAR_FIELD(opretset);
1135         COPY_NODE_FIELD(args);
1136
1137         return newnode;
1138 }
1139
1140 /*
1141  * _copyNullTest
1142  */
1143 static NullTest *
1144 _copyNullTest(NullTest *from)
1145 {
1146         NullTest   *newnode = makeNode(NullTest);
1147
1148         COPY_NODE_FIELD(arg);
1149         COPY_SCALAR_FIELD(nulltesttype);
1150
1151         return newnode;
1152 }
1153
1154 /*
1155  * _copyBooleanTest
1156  */
1157 static BooleanTest *
1158 _copyBooleanTest(BooleanTest *from)
1159 {
1160         BooleanTest *newnode = makeNode(BooleanTest);
1161
1162         COPY_NODE_FIELD(arg);
1163         COPY_SCALAR_FIELD(booltesttype);
1164
1165         return newnode;
1166 }
1167
1168 /*
1169  * _copyCoerceToDomain
1170  */
1171 static CoerceToDomain *
1172 _copyCoerceToDomain(CoerceToDomain *from)
1173 {
1174         CoerceToDomain *newnode = makeNode(CoerceToDomain);
1175
1176         COPY_NODE_FIELD(arg);
1177         COPY_SCALAR_FIELD(resulttype);
1178         COPY_SCALAR_FIELD(resulttypmod);
1179         COPY_SCALAR_FIELD(coercionformat);
1180
1181         return newnode;
1182 }
1183
1184 /*
1185  * _copyCoerceToDomainValue
1186  */
1187 static CoerceToDomainValue *
1188 _copyCoerceToDomainValue(CoerceToDomainValue *from)
1189 {
1190         CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1191
1192         COPY_SCALAR_FIELD(typeId);
1193         COPY_SCALAR_FIELD(typeMod);
1194
1195         return newnode;
1196 }
1197
1198 /*
1199  * _copySetToDefault
1200  */
1201 static SetToDefault *
1202 _copySetToDefault(SetToDefault *from)
1203 {
1204         SetToDefault *newnode = makeNode(SetToDefault);
1205
1206         COPY_SCALAR_FIELD(typeId);
1207         COPY_SCALAR_FIELD(typeMod);
1208
1209         return newnode;
1210 }
1211
1212 /*
1213  * _copyTargetEntry
1214  */
1215 static TargetEntry *
1216 _copyTargetEntry(TargetEntry *from)
1217 {
1218         TargetEntry *newnode = makeNode(TargetEntry);
1219
1220         COPY_NODE_FIELD(expr);
1221         COPY_SCALAR_FIELD(resno);
1222         COPY_STRING_FIELD(resname);
1223         COPY_SCALAR_FIELD(ressortgroupref);
1224         COPY_SCALAR_FIELD(resorigtbl);
1225         COPY_SCALAR_FIELD(resorigcol);
1226         COPY_SCALAR_FIELD(resjunk);
1227
1228         return newnode;
1229 }
1230
1231 /*
1232  * _copyRangeTblRef
1233  */
1234 static RangeTblRef *
1235 _copyRangeTblRef(RangeTblRef *from)
1236 {
1237         RangeTblRef *newnode = makeNode(RangeTblRef);
1238
1239         COPY_SCALAR_FIELD(rtindex);
1240
1241         return newnode;
1242 }
1243
1244 /*
1245  * _copyJoinExpr
1246  */
1247 static JoinExpr *
1248 _copyJoinExpr(JoinExpr *from)
1249 {
1250         JoinExpr   *newnode = makeNode(JoinExpr);
1251
1252         COPY_SCALAR_FIELD(jointype);
1253         COPY_SCALAR_FIELD(isNatural);
1254         COPY_NODE_FIELD(larg);
1255         COPY_NODE_FIELD(rarg);
1256         COPY_NODE_FIELD(using);
1257         COPY_NODE_FIELD(quals);
1258         COPY_NODE_FIELD(alias);
1259         COPY_SCALAR_FIELD(rtindex);
1260
1261         return newnode;
1262 }
1263
1264 /*
1265  * _copyFromExpr
1266  */
1267 static FromExpr *
1268 _copyFromExpr(FromExpr *from)
1269 {
1270         FromExpr   *newnode = makeNode(FromExpr);
1271
1272         COPY_NODE_FIELD(fromlist);
1273         COPY_NODE_FIELD(quals);
1274
1275         return newnode;
1276 }
1277
1278 /* ****************************************************************
1279  *                                              relation.h copy functions
1280  *
1281  * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1282  * There are some subsidiary structs that are useful to copy, though.
1283  * ****************************************************************
1284  */
1285
1286 /*
1287  * _copyPathKey
1288  */
1289 static PathKey *
1290 _copyPathKey(PathKey *from)
1291 {
1292         PathKey *newnode = makeNode(PathKey);
1293
1294         /* EquivalenceClasses are never moved, so just shallow-copy the pointer */
1295         COPY_SCALAR_FIELD(pk_eclass);
1296         COPY_SCALAR_FIELD(pk_opfamily);
1297         COPY_SCALAR_FIELD(pk_strategy);
1298         COPY_SCALAR_FIELD(pk_nulls_first);
1299
1300         return newnode;
1301 }
1302
1303 /*
1304  * _copyRestrictInfo
1305  */
1306 static RestrictInfo *
1307 _copyRestrictInfo(RestrictInfo *from)
1308 {
1309         RestrictInfo *newnode = makeNode(RestrictInfo);
1310
1311         COPY_NODE_FIELD(clause);
1312         COPY_SCALAR_FIELD(is_pushed_down);
1313         COPY_SCALAR_FIELD(outerjoin_delayed);
1314         COPY_SCALAR_FIELD(can_join);
1315         COPY_SCALAR_FIELD(pseudoconstant);
1316         COPY_BITMAPSET_FIELD(clause_relids);
1317         COPY_BITMAPSET_FIELD(required_relids);
1318         COPY_BITMAPSET_FIELD(left_relids);
1319         COPY_BITMAPSET_FIELD(right_relids);
1320         COPY_NODE_FIELD(orclause);
1321         /* EquivalenceClasses are never copied, so shallow-copy the pointers */
1322         COPY_SCALAR_FIELD(parent_ec);
1323         COPY_SCALAR_FIELD(eval_cost);
1324         COPY_SCALAR_FIELD(this_selec);
1325         COPY_NODE_FIELD(mergeopfamilies);
1326         /* EquivalenceClasses are never copied, so shallow-copy the pointers */
1327         COPY_SCALAR_FIELD(left_ec);
1328         COPY_SCALAR_FIELD(right_ec);
1329         COPY_SCALAR_FIELD(outer_is_left);
1330         COPY_SCALAR_FIELD(hashjoinoperator);
1331         COPY_SCALAR_FIELD(left_bucketsize);
1332         COPY_SCALAR_FIELD(right_bucketsize);
1333
1334         return newnode;
1335 }
1336
1337 /*
1338  * _copyOuterJoinInfo
1339  */
1340 static OuterJoinInfo *
1341 _copyOuterJoinInfo(OuterJoinInfo *from)
1342 {
1343         OuterJoinInfo *newnode = makeNode(OuterJoinInfo);
1344
1345         COPY_BITMAPSET_FIELD(min_lefthand);
1346         COPY_BITMAPSET_FIELD(min_righthand);
1347         COPY_SCALAR_FIELD(is_full_join);
1348         COPY_SCALAR_FIELD(lhs_strict);
1349
1350         return newnode;
1351 }
1352
1353 /*
1354  * _copyInClauseInfo
1355  */
1356 static InClauseInfo *
1357 _copyInClauseInfo(InClauseInfo *from)
1358 {
1359         InClauseInfo *newnode = makeNode(InClauseInfo);
1360
1361         COPY_BITMAPSET_FIELD(lefthand);
1362         COPY_BITMAPSET_FIELD(righthand);
1363         COPY_NODE_FIELD(sub_targetlist);
1364         COPY_NODE_FIELD(in_operators);
1365
1366         return newnode;
1367 }
1368
1369 /*
1370  * _copyAppendRelInfo
1371  */
1372 static AppendRelInfo *
1373 _copyAppendRelInfo(AppendRelInfo *from)
1374 {
1375         AppendRelInfo *newnode = makeNode(AppendRelInfo);
1376
1377         COPY_SCALAR_FIELD(parent_relid);
1378         COPY_SCALAR_FIELD(child_relid);
1379         COPY_SCALAR_FIELD(parent_reltype);
1380         COPY_SCALAR_FIELD(child_reltype);
1381         COPY_NODE_FIELD(col_mappings);
1382         COPY_NODE_FIELD(translated_vars);
1383         COPY_SCALAR_FIELD(parent_reloid);
1384
1385         return newnode;
1386 }
1387
1388 /* ****************************************************************
1389  *                                      parsenodes.h copy functions
1390  * ****************************************************************
1391  */
1392
1393 static RangeTblEntry *
1394 _copyRangeTblEntry(RangeTblEntry *from)
1395 {
1396         RangeTblEntry *newnode = makeNode(RangeTblEntry);
1397
1398         COPY_SCALAR_FIELD(rtekind);
1399         COPY_SCALAR_FIELD(relid);
1400         COPY_NODE_FIELD(subquery);
1401         COPY_NODE_FIELD(funcexpr);
1402         COPY_NODE_FIELD(funccoltypes);
1403         COPY_NODE_FIELD(funccoltypmods);
1404         COPY_NODE_FIELD(values_lists);
1405         COPY_SCALAR_FIELD(jointype);
1406         COPY_NODE_FIELD(joinaliasvars);
1407         COPY_NODE_FIELD(alias);
1408         COPY_NODE_FIELD(eref);
1409         COPY_SCALAR_FIELD(inh);
1410         COPY_SCALAR_FIELD(inFromCl);
1411         COPY_SCALAR_FIELD(requiredPerms);
1412         COPY_SCALAR_FIELD(checkAsUser);
1413
1414         return newnode;
1415 }
1416
1417 static FkConstraint *
1418 _copyFkConstraint(FkConstraint *from)
1419 {
1420         FkConstraint *newnode = makeNode(FkConstraint);
1421
1422         COPY_STRING_FIELD(constr_name);
1423         COPY_NODE_FIELD(pktable);
1424         COPY_NODE_FIELD(fk_attrs);
1425         COPY_NODE_FIELD(pk_attrs);
1426         COPY_SCALAR_FIELD(fk_matchtype);
1427         COPY_SCALAR_FIELD(fk_upd_action);
1428         COPY_SCALAR_FIELD(fk_del_action);
1429         COPY_SCALAR_FIELD(deferrable);
1430         COPY_SCALAR_FIELD(initdeferred);
1431         COPY_SCALAR_FIELD(skip_validation);
1432
1433         return newnode;
1434 }
1435
1436 static SortClause *
1437 _copySortClause(SortClause *from)
1438 {
1439         SortClause *newnode = makeNode(SortClause);
1440
1441         COPY_SCALAR_FIELD(tleSortGroupRef);
1442         COPY_SCALAR_FIELD(sortop);
1443         COPY_SCALAR_FIELD(nulls_first);
1444
1445         return newnode;
1446 }
1447
1448 static GroupClause *
1449 _copyGroupClause(GroupClause *from)
1450 {
1451         GroupClause *newnode = makeNode(GroupClause);
1452
1453         COPY_SCALAR_FIELD(tleSortGroupRef);
1454         COPY_SCALAR_FIELD(sortop);
1455         COPY_SCALAR_FIELD(nulls_first);
1456
1457         return newnode;
1458 }
1459
1460 static RowMarkClause *
1461 _copyRowMarkClause(RowMarkClause *from)
1462 {
1463         RowMarkClause *newnode = makeNode(RowMarkClause);
1464
1465         COPY_SCALAR_FIELD(rti);
1466         COPY_SCALAR_FIELD(forUpdate);
1467         COPY_SCALAR_FIELD(noWait);
1468
1469         return newnode;
1470 }
1471
1472 static A_Expr *
1473 _copyAExpr(A_Expr *from)
1474 {
1475         A_Expr     *newnode = makeNode(A_Expr);
1476
1477         COPY_SCALAR_FIELD(kind);
1478         COPY_NODE_FIELD(name);
1479         COPY_NODE_FIELD(lexpr);
1480         COPY_NODE_FIELD(rexpr);
1481         COPY_SCALAR_FIELD(location);
1482
1483         return newnode;
1484 }
1485
1486 static ColumnRef *
1487 _copyColumnRef(ColumnRef *from)
1488 {
1489         ColumnRef  *newnode = makeNode(ColumnRef);
1490
1491         COPY_NODE_FIELD(fields);
1492         COPY_SCALAR_FIELD(location);
1493
1494         return newnode;
1495 }
1496
1497 static ParamRef *
1498 _copyParamRef(ParamRef *from)
1499 {
1500         ParamRef   *newnode = makeNode(ParamRef);
1501
1502         COPY_SCALAR_FIELD(number);
1503
1504         return newnode;
1505 }
1506
1507 static A_Const *
1508 _copyAConst(A_Const *from)
1509 {
1510         A_Const    *newnode = makeNode(A_Const);
1511
1512         /* This part must duplicate _copyValue */
1513         COPY_SCALAR_FIELD(val.type);
1514         switch (from->val.type)
1515         {
1516                 case T_Integer:
1517                         COPY_SCALAR_FIELD(val.val.ival);
1518                         break;
1519                 case T_Float:
1520                 case T_String:
1521                 case T_BitString:
1522                         COPY_STRING_FIELD(val.val.str);
1523                         break;
1524                 case T_Null:
1525                         /* nothing to do */
1526                         break;
1527                 default:
1528                         elog(ERROR, "unrecognized node type: %d",
1529                                  (int) from->val.type);
1530                         break;
1531         }
1532
1533         COPY_NODE_FIELD(typename);
1534
1535         return newnode;
1536 }
1537
1538 static FuncCall *
1539 _copyFuncCall(FuncCall *from)
1540 {
1541         FuncCall   *newnode = makeNode(FuncCall);
1542
1543         COPY_NODE_FIELD(funcname);
1544         COPY_NODE_FIELD(args);
1545         COPY_SCALAR_FIELD(agg_star);
1546         COPY_SCALAR_FIELD(agg_distinct);
1547         COPY_SCALAR_FIELD(location);
1548
1549         return newnode;
1550 }
1551
1552 static A_Indices *
1553 _copyAIndices(A_Indices *from)
1554 {
1555         A_Indices  *newnode = makeNode(A_Indices);
1556
1557         COPY_NODE_FIELD(lidx);
1558         COPY_NODE_FIELD(uidx);
1559
1560         return newnode;
1561 }
1562
1563 static A_Indirection *
1564 _copyA_Indirection(A_Indirection *from)
1565 {
1566         A_Indirection *newnode = makeNode(A_Indirection);
1567
1568         COPY_NODE_FIELD(arg);
1569         COPY_NODE_FIELD(indirection);
1570
1571         return newnode;
1572 }
1573
1574 static ResTarget *
1575 _copyResTarget(ResTarget *from)
1576 {
1577         ResTarget  *newnode = makeNode(ResTarget);
1578
1579         COPY_STRING_FIELD(name);
1580         COPY_NODE_FIELD(indirection);
1581         COPY_NODE_FIELD(val);
1582         COPY_SCALAR_FIELD(location);
1583
1584         return newnode;
1585 }
1586
1587 static TypeName *
1588 _copyTypeName(TypeName *from)
1589 {
1590         TypeName   *newnode = makeNode(TypeName);
1591
1592         COPY_NODE_FIELD(names);
1593         COPY_SCALAR_FIELD(typeid);
1594         COPY_SCALAR_FIELD(timezone);
1595         COPY_SCALAR_FIELD(setof);
1596         COPY_SCALAR_FIELD(pct_type);
1597         COPY_NODE_FIELD(typmods);
1598         COPY_SCALAR_FIELD(typemod);
1599         COPY_NODE_FIELD(arrayBounds);
1600         COPY_SCALAR_FIELD(location);
1601
1602         return newnode;
1603 }
1604
1605 static SortBy *
1606 _copySortBy(SortBy *from)
1607 {
1608         SortBy     *newnode = makeNode(SortBy);
1609
1610         COPY_SCALAR_FIELD(sortby_dir);
1611         COPY_SCALAR_FIELD(sortby_nulls);
1612         COPY_NODE_FIELD(useOp);
1613         COPY_NODE_FIELD(node);
1614
1615         return newnode;
1616 }
1617
1618 static RangeSubselect *
1619 _copyRangeSubselect(RangeSubselect *from)
1620 {
1621         RangeSubselect *newnode = makeNode(RangeSubselect);
1622
1623         COPY_NODE_FIELD(subquery);
1624         COPY_NODE_FIELD(alias);
1625
1626         return newnode;
1627 }
1628
1629 static RangeFunction *
1630 _copyRangeFunction(RangeFunction *from)
1631 {
1632         RangeFunction *newnode = makeNode(RangeFunction);
1633
1634         COPY_NODE_FIELD(funccallnode);
1635         COPY_NODE_FIELD(alias);
1636         COPY_NODE_FIELD(coldeflist);
1637
1638         return newnode;
1639 }
1640
1641 static TypeCast *
1642 _copyTypeCast(TypeCast *from)
1643 {
1644         TypeCast   *newnode = makeNode(TypeCast);
1645
1646         COPY_NODE_FIELD(arg);
1647         COPY_NODE_FIELD(typename);
1648
1649         return newnode;
1650 }
1651
1652 static IndexElem *
1653 _copyIndexElem(IndexElem *from)
1654 {
1655         IndexElem  *newnode = makeNode(IndexElem);
1656
1657         COPY_STRING_FIELD(name);
1658         COPY_NODE_FIELD(expr);
1659         COPY_NODE_FIELD(opclass);
1660         COPY_SCALAR_FIELD(ordering);
1661         COPY_SCALAR_FIELD(nulls_ordering);
1662
1663         return newnode;
1664 }
1665
1666 static ColumnDef *
1667 _copyColumnDef(ColumnDef *from)
1668 {
1669         ColumnDef  *newnode = makeNode(ColumnDef);
1670
1671         COPY_STRING_FIELD(colname);
1672         COPY_NODE_FIELD(typename);
1673         COPY_SCALAR_FIELD(inhcount);
1674         COPY_SCALAR_FIELD(is_local);
1675         COPY_SCALAR_FIELD(is_not_null);
1676         COPY_NODE_FIELD(raw_default);
1677         COPY_STRING_FIELD(cooked_default);
1678         COPY_NODE_FIELD(constraints);
1679
1680         return newnode;
1681 }
1682
1683 static Constraint *
1684 _copyConstraint(Constraint *from)
1685 {
1686         Constraint *newnode = makeNode(Constraint);
1687
1688         COPY_SCALAR_FIELD(contype);
1689         COPY_STRING_FIELD(name);
1690         COPY_NODE_FIELD(raw_expr);
1691         COPY_STRING_FIELD(cooked_expr);
1692         COPY_NODE_FIELD(keys);
1693         COPY_NODE_FIELD(options);
1694         COPY_STRING_FIELD(indexspace);
1695
1696         return newnode;
1697 }
1698
1699 static DefElem *
1700 _copyDefElem(DefElem *from)
1701 {
1702         DefElem    *newnode = makeNode(DefElem);
1703
1704         COPY_STRING_FIELD(defname);
1705         COPY_NODE_FIELD(arg);
1706
1707         return newnode;
1708 }
1709
1710 static LockingClause *
1711 _copyLockingClause(LockingClause *from)
1712 {
1713         LockingClause *newnode = makeNode(LockingClause);
1714
1715         COPY_NODE_FIELD(lockedRels);
1716         COPY_SCALAR_FIELD(forUpdate);
1717         COPY_SCALAR_FIELD(noWait);
1718
1719         return newnode;
1720 }
1721
1722 static Query *
1723 _copyQuery(Query *from)
1724 {
1725         Query      *newnode = makeNode(Query);
1726
1727         COPY_SCALAR_FIELD(commandType);
1728         COPY_SCALAR_FIELD(querySource);
1729         COPY_SCALAR_FIELD(canSetTag);
1730         COPY_NODE_FIELD(utilityStmt);
1731         COPY_SCALAR_FIELD(resultRelation);
1732         COPY_NODE_FIELD(into);
1733         COPY_NODE_FIELD(intoOptions);
1734         COPY_SCALAR_FIELD(intoOnCommit);
1735         COPY_STRING_FIELD(intoTableSpaceName);
1736         COPY_SCALAR_FIELD(hasAggs);
1737         COPY_SCALAR_FIELD(hasSubLinks);
1738         COPY_NODE_FIELD(rtable);
1739         COPY_NODE_FIELD(jointree);
1740         COPY_NODE_FIELD(targetList);
1741         COPY_NODE_FIELD(returningList);
1742         COPY_NODE_FIELD(groupClause);
1743         COPY_NODE_FIELD(havingQual);
1744         COPY_NODE_FIELD(distinctClause);
1745         COPY_NODE_FIELD(sortClause);
1746         COPY_NODE_FIELD(limitOffset);
1747         COPY_NODE_FIELD(limitCount);
1748         COPY_NODE_FIELD(rowMarks);
1749         COPY_NODE_FIELD(setOperations);
1750         COPY_NODE_FIELD(resultRelations);
1751         COPY_NODE_FIELD(returningLists);
1752
1753         return newnode;
1754 }
1755
1756 static InsertStmt *
1757 _copyInsertStmt(InsertStmt *from)
1758 {
1759         InsertStmt *newnode = makeNode(InsertStmt);
1760
1761         COPY_NODE_FIELD(relation);
1762         COPY_NODE_FIELD(cols);
1763         COPY_NODE_FIELD(selectStmt);
1764         COPY_NODE_FIELD(returningList);
1765
1766         return newnode;
1767 }
1768
1769 static DeleteStmt *
1770 _copyDeleteStmt(DeleteStmt *from)
1771 {
1772         DeleteStmt *newnode = makeNode(DeleteStmt);
1773
1774         COPY_NODE_FIELD(relation);
1775         COPY_NODE_FIELD(usingClause);
1776         COPY_NODE_FIELD(whereClause);
1777         COPY_NODE_FIELD(returningList);
1778
1779         return newnode;
1780 }
1781
1782 static UpdateStmt *
1783 _copyUpdateStmt(UpdateStmt *from)
1784 {
1785         UpdateStmt *newnode = makeNode(UpdateStmt);
1786
1787         COPY_NODE_FIELD(relation);
1788         COPY_NODE_FIELD(targetList);
1789         COPY_NODE_FIELD(whereClause);
1790         COPY_NODE_FIELD(fromClause);
1791         COPY_NODE_FIELD(returningList);
1792
1793         return newnode;
1794 }
1795
1796 static SelectStmt *
1797 _copySelectStmt(SelectStmt *from)
1798 {
1799         SelectStmt *newnode = makeNode(SelectStmt);
1800
1801         COPY_NODE_FIELD(distinctClause);
1802         COPY_NODE_FIELD(into);
1803         COPY_NODE_FIELD(intoColNames);
1804         COPY_NODE_FIELD(intoOptions);
1805         COPY_SCALAR_FIELD(intoOnCommit);
1806         COPY_STRING_FIELD(intoTableSpaceName);
1807         COPY_NODE_FIELD(targetList);
1808         COPY_NODE_FIELD(fromClause);
1809         COPY_NODE_FIELD(whereClause);
1810         COPY_NODE_FIELD(groupClause);
1811         COPY_NODE_FIELD(havingClause);
1812         COPY_NODE_FIELD(valuesLists);
1813         COPY_NODE_FIELD(sortClause);
1814         COPY_NODE_FIELD(limitOffset);
1815         COPY_NODE_FIELD(limitCount);
1816         COPY_NODE_FIELD(lockingClause);
1817         COPY_SCALAR_FIELD(op);
1818         COPY_SCALAR_FIELD(all);
1819         COPY_NODE_FIELD(larg);
1820         COPY_NODE_FIELD(rarg);
1821
1822         return newnode;
1823 }
1824
1825 static SetOperationStmt *
1826 _copySetOperationStmt(SetOperationStmt *from)
1827 {
1828         SetOperationStmt *newnode = makeNode(SetOperationStmt);
1829
1830         COPY_SCALAR_FIELD(op);
1831         COPY_SCALAR_FIELD(all);
1832         COPY_NODE_FIELD(larg);
1833         COPY_NODE_FIELD(rarg);
1834         COPY_NODE_FIELD(colTypes);
1835         COPY_NODE_FIELD(colTypmods);
1836
1837         return newnode;
1838 }
1839
1840 static AlterTableStmt *
1841 _copyAlterTableStmt(AlterTableStmt *from)
1842 {
1843         AlterTableStmt *newnode = makeNode(AlterTableStmt);
1844
1845         COPY_NODE_FIELD(relation);
1846         COPY_NODE_FIELD(cmds);
1847         COPY_SCALAR_FIELD(relkind);
1848
1849         return newnode;
1850 }
1851
1852 static AlterTableCmd *
1853 _copyAlterTableCmd(AlterTableCmd *from)
1854 {
1855         AlterTableCmd *newnode = makeNode(AlterTableCmd);
1856
1857         COPY_SCALAR_FIELD(subtype);
1858         COPY_STRING_FIELD(name);
1859         COPY_NODE_FIELD(def);
1860         COPY_NODE_FIELD(transform);
1861         COPY_SCALAR_FIELD(behavior);
1862
1863         return newnode;
1864 }
1865
1866 static AlterDomainStmt *
1867 _copyAlterDomainStmt(AlterDomainStmt *from)
1868 {
1869         AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1870
1871         COPY_SCALAR_FIELD(subtype);
1872         COPY_NODE_FIELD(typename);
1873         COPY_STRING_FIELD(name);
1874         COPY_NODE_FIELD(def);
1875         COPY_SCALAR_FIELD(behavior);
1876
1877         return newnode;
1878 }
1879
1880 static GrantStmt *
1881 _copyGrantStmt(GrantStmt *from)
1882 {
1883         GrantStmt  *newnode = makeNode(GrantStmt);
1884
1885         COPY_SCALAR_FIELD(is_grant);
1886         COPY_SCALAR_FIELD(objtype);
1887         COPY_NODE_FIELD(objects);
1888         COPY_NODE_FIELD(privileges);
1889         COPY_NODE_FIELD(grantees);
1890         COPY_SCALAR_FIELD(grant_option);
1891         COPY_SCALAR_FIELD(behavior);
1892
1893         return newnode;
1894 }
1895
1896 static PrivGrantee *
1897 _copyPrivGrantee(PrivGrantee *from)
1898 {
1899         PrivGrantee *newnode = makeNode(PrivGrantee);
1900
1901         COPY_STRING_FIELD(rolname);
1902
1903         return newnode;
1904 }
1905
1906 static FuncWithArgs *
1907 _copyFuncWithArgs(FuncWithArgs *from)
1908 {
1909         FuncWithArgs *newnode = makeNode(FuncWithArgs);
1910
1911         COPY_NODE_FIELD(funcname);
1912         COPY_NODE_FIELD(funcargs);
1913
1914         return newnode;
1915 }
1916
1917 static GrantRoleStmt *
1918 _copyGrantRoleStmt(GrantRoleStmt *from)
1919 {
1920         GrantRoleStmt *newnode = makeNode(GrantRoleStmt);
1921
1922         COPY_NODE_FIELD(granted_roles);
1923         COPY_NODE_FIELD(grantee_roles);
1924         COPY_SCALAR_FIELD(is_grant);
1925         COPY_SCALAR_FIELD(admin_opt);
1926         COPY_STRING_FIELD(grantor);
1927         COPY_SCALAR_FIELD(behavior);
1928
1929         return newnode;
1930 }
1931
1932 static DeclareCursorStmt *
1933 _copyDeclareCursorStmt(DeclareCursorStmt *from)
1934 {
1935         DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
1936
1937         COPY_STRING_FIELD(portalname);
1938         COPY_SCALAR_FIELD(options);
1939         COPY_NODE_FIELD(query);
1940
1941         return newnode;
1942 }
1943
1944 static ClosePortalStmt *
1945 _copyClosePortalStmt(ClosePortalStmt *from)
1946 {
1947         ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1948
1949         COPY_STRING_FIELD(portalname);
1950
1951         return newnode;
1952 }
1953
1954 static ClusterStmt *
1955 _copyClusterStmt(ClusterStmt *from)
1956 {
1957         ClusterStmt *newnode = makeNode(ClusterStmt);
1958
1959         COPY_NODE_FIELD(relation);
1960         COPY_STRING_FIELD(indexname);
1961
1962         return newnode;
1963 }
1964
1965 static CopyStmt *
1966 _copyCopyStmt(CopyStmt *from)
1967 {
1968         CopyStmt   *newnode = makeNode(CopyStmt);
1969
1970         COPY_NODE_FIELD(relation);
1971         COPY_NODE_FIELD(query);
1972         COPY_NODE_FIELD(attlist);
1973         COPY_SCALAR_FIELD(is_from);
1974         COPY_STRING_FIELD(filename);
1975         COPY_NODE_FIELD(options);
1976
1977         return newnode;
1978 }
1979
1980 static CreateStmt *
1981 _copyCreateStmt(CreateStmt *from)
1982 {
1983         CreateStmt *newnode = makeNode(CreateStmt);
1984
1985         COPY_NODE_FIELD(relation);
1986         COPY_NODE_FIELD(tableElts);
1987         COPY_NODE_FIELD(inhRelations);
1988         COPY_NODE_FIELD(constraints);
1989         COPY_NODE_FIELD(options);
1990         COPY_SCALAR_FIELD(oncommit);
1991         COPY_STRING_FIELD(tablespacename);
1992
1993         return newnode;
1994 }
1995
1996 static InhRelation *
1997 _copyInhRelation(InhRelation *from)
1998 {
1999         InhRelation *newnode = makeNode(InhRelation);
2000
2001         COPY_NODE_FIELD(relation);
2002         COPY_NODE_FIELD(options);
2003
2004         return newnode;
2005 }
2006
2007 static DefineStmt *
2008 _copyDefineStmt(DefineStmt *from)
2009 {
2010         DefineStmt *newnode = makeNode(DefineStmt);
2011
2012         COPY_SCALAR_FIELD(kind);
2013         COPY_SCALAR_FIELD(oldstyle);
2014         COPY_NODE_FIELD(defnames);
2015         COPY_NODE_FIELD(args);
2016         COPY_NODE_FIELD(definition);
2017
2018         return newnode;
2019 }
2020
2021 static DropStmt *
2022 _copyDropStmt(DropStmt *from)
2023 {
2024         DropStmt   *newnode = makeNode(DropStmt);
2025
2026         COPY_NODE_FIELD(objects);
2027         COPY_SCALAR_FIELD(removeType);
2028         COPY_SCALAR_FIELD(behavior);
2029         COPY_SCALAR_FIELD(missing_ok);
2030
2031         return newnode;
2032 }
2033
2034 static TruncateStmt *
2035 _copyTruncateStmt(TruncateStmt *from)
2036 {
2037         TruncateStmt *newnode = makeNode(TruncateStmt);
2038
2039         COPY_NODE_FIELD(relations);
2040         COPY_SCALAR_FIELD(behavior);
2041
2042         return newnode;
2043 }
2044
2045 static CommentStmt *
2046 _copyCommentStmt(CommentStmt *from)
2047 {
2048         CommentStmt *newnode = makeNode(CommentStmt);
2049
2050         COPY_SCALAR_FIELD(objtype);
2051         COPY_NODE_FIELD(objname);
2052         COPY_NODE_FIELD(objargs);
2053         COPY_STRING_FIELD(comment);
2054
2055         return newnode;
2056 }
2057
2058 static FetchStmt *
2059 _copyFetchStmt(FetchStmt *from)
2060 {
2061         FetchStmt  *newnode = makeNode(FetchStmt);
2062
2063         COPY_SCALAR_FIELD(direction);
2064         COPY_SCALAR_FIELD(howMany);
2065         COPY_STRING_FIELD(portalname);
2066         COPY_SCALAR_FIELD(ismove);
2067
2068         return newnode;
2069 }
2070
2071 static IndexStmt *
2072 _copyIndexStmt(IndexStmt *from)
2073 {
2074         IndexStmt  *newnode = makeNode(IndexStmt);
2075
2076         COPY_STRING_FIELD(idxname);
2077         COPY_NODE_FIELD(relation);
2078         COPY_STRING_FIELD(accessMethod);
2079         COPY_STRING_FIELD(tableSpace);
2080         COPY_NODE_FIELD(indexParams);
2081         COPY_NODE_FIELD(options);
2082         COPY_NODE_FIELD(whereClause);
2083         COPY_NODE_FIELD(rangetable);
2084         COPY_SCALAR_FIELD(unique);
2085         COPY_SCALAR_FIELD(primary);
2086         COPY_SCALAR_FIELD(isconstraint);
2087         COPY_SCALAR_FIELD(concurrent);
2088
2089         return newnode;
2090 }
2091
2092 static CreateFunctionStmt *
2093 _copyCreateFunctionStmt(CreateFunctionStmt *from)
2094 {
2095         CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
2096
2097         COPY_SCALAR_FIELD(replace);
2098         COPY_NODE_FIELD(funcname);
2099         COPY_NODE_FIELD(parameters);
2100         COPY_NODE_FIELD(returnType);
2101         COPY_NODE_FIELD(options);
2102         COPY_NODE_FIELD(withClause);
2103
2104         return newnode;
2105 }
2106
2107 static FunctionParameter *
2108 _copyFunctionParameter(FunctionParameter *from)
2109 {
2110         FunctionParameter *newnode = makeNode(FunctionParameter);
2111
2112         COPY_STRING_FIELD(name);
2113         COPY_NODE_FIELD(argType);
2114         COPY_SCALAR_FIELD(mode);
2115
2116         return newnode;
2117 }
2118
2119 static AlterFunctionStmt *
2120 _copyAlterFunctionStmt(AlterFunctionStmt *from)
2121 {
2122         AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);
2123
2124         COPY_NODE_FIELD(func);
2125         COPY_NODE_FIELD(actions);
2126
2127         return newnode;
2128 }
2129
2130 static RemoveFuncStmt *
2131 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2132 {
2133         RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2134
2135         COPY_SCALAR_FIELD(kind);
2136         COPY_NODE_FIELD(name);
2137         COPY_NODE_FIELD(args);
2138         COPY_SCALAR_FIELD(behavior);
2139         COPY_SCALAR_FIELD(missing_ok);
2140
2141         return newnode;
2142 }
2143
2144 static RemoveOpClassStmt *
2145 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
2146 {
2147         RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
2148
2149         COPY_NODE_FIELD(opclassname);
2150         COPY_STRING_FIELD(amname);
2151         COPY_SCALAR_FIELD(behavior);
2152         COPY_SCALAR_FIELD(missing_ok);
2153
2154         return newnode;
2155 }
2156
2157 static RenameStmt *
2158 _copyRenameStmt(RenameStmt *from)
2159 {
2160         RenameStmt *newnode = makeNode(RenameStmt);
2161
2162         COPY_SCALAR_FIELD(renameType);
2163         COPY_NODE_FIELD(relation);
2164         COPY_NODE_FIELD(object);
2165         COPY_NODE_FIELD(objarg);
2166         COPY_STRING_FIELD(subname);
2167         COPY_STRING_FIELD(newname);
2168
2169         return newnode;
2170 }
2171
2172 static AlterObjectSchemaStmt *
2173 _copyAlterObjectSchemaStmt(AlterObjectSchemaStmt *from)
2174 {
2175         AlterObjectSchemaStmt *newnode = makeNode(AlterObjectSchemaStmt);
2176
2177         COPY_SCALAR_FIELD(objectType);
2178         COPY_NODE_FIELD(relation);
2179         COPY_NODE_FIELD(object);
2180         COPY_NODE_FIELD(objarg);
2181         COPY_STRING_FIELD(addname);
2182         COPY_STRING_FIELD(newschema);
2183
2184         return newnode;
2185 }
2186
2187 static AlterOwnerStmt *
2188 _copyAlterOwnerStmt(AlterOwnerStmt *from)
2189 {
2190         AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);
2191
2192         COPY_SCALAR_FIELD(objectType);
2193         COPY_NODE_FIELD(relation);
2194         COPY_NODE_FIELD(object);
2195         COPY_NODE_FIELD(objarg);
2196         COPY_STRING_FIELD(addname);
2197         COPY_STRING_FIELD(newowner);
2198
2199         return newnode;
2200 }
2201
2202 static RuleStmt *
2203 _copyRuleStmt(RuleStmt *from)
2204 {
2205         RuleStmt   *newnode = makeNode(RuleStmt);
2206
2207         COPY_NODE_FIELD(relation);
2208         COPY_STRING_FIELD(rulename);
2209         COPY_NODE_FIELD(whereClause);
2210         COPY_SCALAR_FIELD(event);
2211         COPY_SCALAR_FIELD(instead);
2212         COPY_NODE_FIELD(actions);
2213         COPY_SCALAR_FIELD(replace);
2214
2215         return newnode;
2216 }
2217
2218 static NotifyStmt *
2219 _copyNotifyStmt(NotifyStmt *from)
2220 {
2221         NotifyStmt *newnode = makeNode(NotifyStmt);
2222
2223         COPY_NODE_FIELD(relation);
2224
2225         return newnode;
2226 }
2227
2228 static ListenStmt *
2229 _copyListenStmt(ListenStmt *from)
2230 {
2231         ListenStmt *newnode = makeNode(ListenStmt);
2232
2233         COPY_NODE_FIELD(relation);
2234
2235         return newnode;
2236 }
2237
2238 static UnlistenStmt *
2239 _copyUnlistenStmt(UnlistenStmt *from)
2240 {
2241         UnlistenStmt *newnode = makeNode(UnlistenStmt);
2242
2243         COPY_NODE_FIELD(relation);
2244
2245         return newnode;
2246 }
2247
2248 static TransactionStmt *
2249 _copyTransactionStmt(TransactionStmt *from)
2250 {
2251         TransactionStmt *newnode = makeNode(TransactionStmt);
2252
2253         COPY_SCALAR_FIELD(kind);
2254         COPY_NODE_FIELD(options);
2255         COPY_STRING_FIELD(gid);
2256
2257         return newnode;
2258 }
2259
2260 static CompositeTypeStmt *
2261 _copyCompositeTypeStmt(CompositeTypeStmt *from)
2262 {
2263         CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
2264
2265         COPY_NODE_FIELD(typevar);
2266         COPY_NODE_FIELD(coldeflist);
2267
2268         return newnode;
2269 }
2270
2271 static ViewStmt *
2272 _copyViewStmt(ViewStmt *from)
2273 {
2274         ViewStmt   *newnode = makeNode(ViewStmt);
2275
2276         COPY_NODE_FIELD(view);
2277         COPY_NODE_FIELD(aliases);
2278         COPY_NODE_FIELD(query);
2279         COPY_SCALAR_FIELD(replace);
2280
2281         return newnode;
2282 }
2283
2284 static LoadStmt *
2285 _copyLoadStmt(LoadStmt *from)
2286 {
2287         LoadStmt   *newnode = makeNode(LoadStmt);
2288
2289         COPY_STRING_FIELD(filename);
2290
2291         return newnode;
2292 }
2293
2294 static CreateDomainStmt *
2295 _copyCreateDomainStmt(CreateDomainStmt *from)
2296 {
2297         CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2298
2299         COPY_NODE_FIELD(domainname);
2300         COPY_NODE_FIELD(typename);
2301         COPY_NODE_FIELD(constraints);
2302
2303         return newnode;
2304 }
2305
2306 static CreateOpClassStmt *
2307 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2308 {
2309         CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2310
2311         COPY_NODE_FIELD(opclassname);
2312         COPY_NODE_FIELD(opfamilyname);
2313         COPY_STRING_FIELD(amname);
2314         COPY_NODE_FIELD(datatype);
2315         COPY_NODE_FIELD(items);
2316         COPY_SCALAR_FIELD(isDefault);
2317
2318         return newnode;
2319 }
2320
2321 static CreateOpClassItem *
2322 _copyCreateOpClassItem(CreateOpClassItem *from)
2323 {
2324         CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2325
2326         COPY_SCALAR_FIELD(itemtype);
2327         COPY_NODE_FIELD(name);
2328         COPY_NODE_FIELD(args);
2329         COPY_SCALAR_FIELD(number);
2330         COPY_SCALAR_FIELD(recheck);
2331         COPY_NODE_FIELD(storedtype);
2332
2333         return newnode;
2334 }
2335
2336 static CreatedbStmt *
2337 _copyCreatedbStmt(CreatedbStmt *from)
2338 {
2339         CreatedbStmt *newnode = makeNode(CreatedbStmt);
2340
2341         COPY_STRING_FIELD(dbname);
2342         COPY_NODE_FIELD(options);
2343
2344         return newnode;
2345 }
2346
2347 static AlterDatabaseStmt *
2348 _copyAlterDatabaseStmt(AlterDatabaseStmt *from)
2349 {
2350         AlterDatabaseStmt *newnode = makeNode(AlterDatabaseStmt);
2351
2352         COPY_STRING_FIELD(dbname);
2353         COPY_NODE_FIELD(options);
2354
2355         return newnode;
2356 }
2357
2358 static AlterDatabaseSetStmt *
2359 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2360 {
2361         AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2362
2363         COPY_STRING_FIELD(dbname);
2364         COPY_STRING_FIELD(variable);
2365         COPY_NODE_FIELD(value);
2366
2367         return newnode;
2368 }
2369
2370 static DropdbStmt *
2371 _copyDropdbStmt(DropdbStmt *from)
2372 {
2373         DropdbStmt *newnode = makeNode(DropdbStmt);
2374
2375         COPY_STRING_FIELD(dbname);
2376         COPY_SCALAR_FIELD(missing_ok);
2377
2378         return newnode;
2379 }
2380
2381 static VacuumStmt *
2382 _copyVacuumStmt(VacuumStmt *from)
2383 {
2384         VacuumStmt *newnode = makeNode(VacuumStmt);
2385
2386         COPY_SCALAR_FIELD(vacuum);
2387         COPY_SCALAR_FIELD(full);
2388         COPY_SCALAR_FIELD(analyze);
2389         COPY_SCALAR_FIELD(verbose);
2390         COPY_SCALAR_FIELD(freeze_min_age);
2391         COPY_NODE_FIELD(relation);
2392         COPY_NODE_FIELD(va_cols);
2393
2394         return newnode;
2395 }
2396
2397 static ExplainStmt *
2398 _copyExplainStmt(ExplainStmt *from)
2399 {
2400         ExplainStmt *newnode = makeNode(ExplainStmt);
2401
2402         COPY_NODE_FIELD(query);
2403         COPY_SCALAR_FIELD(verbose);
2404         COPY_SCALAR_FIELD(analyze);
2405
2406         return newnode;
2407 }
2408
2409 static CreateSeqStmt *
2410 _copyCreateSeqStmt(CreateSeqStmt *from)
2411 {
2412         CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2413
2414         COPY_NODE_FIELD(sequence);
2415         COPY_NODE_FIELD(options);
2416
2417         return newnode;
2418 }
2419
2420 static AlterSeqStmt *
2421 _copyAlterSeqStmt(AlterSeqStmt *from)
2422 {
2423         AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
2424
2425         COPY_NODE_FIELD(sequence);
2426         COPY_NODE_FIELD(options);
2427
2428         return newnode;
2429 }
2430
2431 static VariableSetStmt *
2432 _copyVariableSetStmt(VariableSetStmt *from)
2433 {
2434         VariableSetStmt *newnode = makeNode(VariableSetStmt);
2435
2436         COPY_STRING_FIELD(name);
2437         COPY_NODE_FIELD(args);
2438         COPY_SCALAR_FIELD(is_local);
2439
2440         return newnode;
2441 }
2442
2443 static VariableShowStmt *
2444 _copyVariableShowStmt(VariableShowStmt *from)
2445 {
2446         VariableShowStmt *newnode = makeNode(VariableShowStmt);
2447
2448         COPY_STRING_FIELD(name);
2449
2450         return newnode;
2451 }
2452
2453 static VariableResetStmt *
2454 _copyVariableResetStmt(VariableResetStmt *from)
2455 {
2456         VariableResetStmt *newnode = makeNode(VariableResetStmt);
2457
2458         COPY_STRING_FIELD(name);
2459
2460         return newnode;
2461 }
2462
2463 static CreateTableSpaceStmt *
2464 _copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
2465 {
2466         CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
2467
2468         COPY_STRING_FIELD(tablespacename);
2469         COPY_STRING_FIELD(owner);
2470         COPY_STRING_FIELD(location);
2471
2472         return newnode;
2473 }
2474
2475 static DropTableSpaceStmt *
2476 _copyDropTableSpaceStmt(DropTableSpaceStmt *from)
2477 {
2478         DropTableSpaceStmt *newnode = makeNode(DropTableSpaceStmt);
2479
2480         COPY_STRING_FIELD(tablespacename);
2481         COPY_SCALAR_FIELD(missing_ok);
2482
2483         return newnode;
2484 }
2485
2486 static CreateTrigStmt *
2487 _copyCreateTrigStmt(CreateTrigStmt *from)
2488 {
2489         CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2490
2491         COPY_STRING_FIELD(trigname);
2492         COPY_NODE_FIELD(relation);
2493         COPY_NODE_FIELD(funcname);
2494         COPY_NODE_FIELD(args);
2495         COPY_SCALAR_FIELD(before);
2496         COPY_SCALAR_FIELD(row);
2497         strcpy(newnode->actions, from->actions);        /* in-line string field */
2498         COPY_SCALAR_FIELD(isconstraint);
2499         COPY_SCALAR_FIELD(deferrable);
2500         COPY_SCALAR_FIELD(initdeferred);
2501         COPY_NODE_FIELD(constrrel);
2502
2503         return newnode;
2504 }
2505
2506 static DropPropertyStmt *
2507 _copyDropPropertyStmt(DropPropertyStmt *from)
2508 {
2509         DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2510
2511         COPY_NODE_FIELD(relation);
2512         COPY_STRING_FIELD(property);
2513         COPY_SCALAR_FIELD(removeType);
2514         COPY_SCALAR_FIELD(behavior);
2515         COPY_SCALAR_FIELD(missing_ok);
2516
2517         return newnode;
2518 }
2519
2520 static CreatePLangStmt *
2521 _copyCreatePLangStmt(CreatePLangStmt *from)
2522 {
2523         CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2524
2525         COPY_STRING_FIELD(plname);
2526         COPY_NODE_FIELD(plhandler);
2527         COPY_NODE_FIELD(plvalidator);
2528         COPY_SCALAR_FIELD(pltrusted);
2529
2530         return newnode;
2531 }
2532
2533 static DropPLangStmt *
2534 _copyDropPLangStmt(DropPLangStmt *from)
2535 {
2536         DropPLangStmt *newnode = makeNode(DropPLangStmt);
2537
2538         COPY_STRING_FIELD(plname);
2539         COPY_SCALAR_FIELD(behavior);
2540         COPY_SCALAR_FIELD(missing_ok);
2541
2542         return newnode;
2543 }
2544
2545 static CreateRoleStmt *
2546 _copyCreateRoleStmt(CreateRoleStmt *from)
2547 {
2548         CreateRoleStmt *newnode = makeNode(CreateRoleStmt);
2549
2550         COPY_SCALAR_FIELD(stmt_type);
2551         COPY_STRING_FIELD(role);
2552         COPY_NODE_FIELD(options);
2553
2554         return newnode;
2555 }
2556
2557 static AlterRoleStmt *
2558 _copyAlterRoleStmt(AlterRoleStmt *from)
2559 {
2560         AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
2561
2562         COPY_STRING_FIELD(role);
2563         COPY_NODE_FIELD(options);
2564         COPY_SCALAR_FIELD(action);
2565
2566         return newnode;
2567 }
2568
2569 static AlterRoleSetStmt *
2570 _copyAlterRoleSetStmt(AlterRoleSetStmt *from)
2571 {
2572         AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
2573
2574         COPY_STRING_FIELD(role);
2575         COPY_STRING_FIELD(variable);
2576         COPY_NODE_FIELD(value);
2577
2578         return newnode;
2579 }
2580
2581 static DropRoleStmt *
2582 _copyDropRoleStmt(DropRoleStmt *from)
2583 {
2584         DropRoleStmt *newnode = makeNode(DropRoleStmt);
2585
2586         COPY_NODE_FIELD(roles);
2587         COPY_SCALAR_FIELD(missing_ok);
2588
2589         return newnode;
2590 }
2591
2592 static LockStmt *
2593 _copyLockStmt(LockStmt *from)
2594 {
2595         LockStmt   *newnode = makeNode(LockStmt);
2596
2597         COPY_NODE_FIELD(relations);
2598         COPY_SCALAR_FIELD(mode);
2599         COPY_SCALAR_FIELD(nowait);
2600
2601         return newnode;
2602 }
2603
2604 static ConstraintsSetStmt *
2605 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2606 {
2607         ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2608
2609         COPY_NODE_FIELD(constraints);
2610         COPY_SCALAR_FIELD(deferred);
2611
2612         return newnode;
2613 }
2614
2615 static ReindexStmt *
2616 _copyReindexStmt(ReindexStmt *from)
2617 {
2618         ReindexStmt *newnode = makeNode(ReindexStmt);
2619
2620         COPY_SCALAR_FIELD(kind);
2621         COPY_NODE_FIELD(relation);
2622         COPY_STRING_FIELD(name);
2623         COPY_SCALAR_FIELD(do_system);
2624         COPY_SCALAR_FIELD(do_user);
2625
2626         return newnode;
2627 }
2628
2629 static CreateSchemaStmt *
2630 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2631 {
2632         CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2633
2634         COPY_STRING_FIELD(schemaname);
2635         COPY_STRING_FIELD(authid);
2636         COPY_NODE_FIELD(schemaElts);
2637
2638         return newnode;
2639 }
2640
2641 static CreateConversionStmt *
2642 _copyCreateConversionStmt(CreateConversionStmt *from)
2643 {
2644         CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2645
2646         COPY_NODE_FIELD(conversion_name);
2647         COPY_STRING_FIELD(for_encoding_name);
2648         COPY_STRING_FIELD(to_encoding_name);
2649         COPY_NODE_FIELD(func_name);
2650         COPY_SCALAR_FIELD(def);
2651
2652         return newnode;
2653 }
2654
2655 static CreateCastStmt *
2656 _copyCreateCastStmt(CreateCastStmt *from)
2657 {
2658         CreateCastStmt *newnode = makeNode(CreateCastStmt);
2659
2660         COPY_NODE_FIELD(sourcetype);
2661         COPY_NODE_FIELD(targettype);
2662         COPY_NODE_FIELD(func);
2663         COPY_SCALAR_FIELD(context);
2664
2665         return newnode;
2666 }
2667
2668 static DropCastStmt *
2669 _copyDropCastStmt(DropCastStmt *from)
2670 {
2671         DropCastStmt *newnode = makeNode(DropCastStmt);
2672
2673         COPY_NODE_FIELD(sourcetype);
2674         COPY_NODE_FIELD(targettype);
2675         COPY_SCALAR_FIELD(behavior);
2676         COPY_SCALAR_FIELD(missing_ok);
2677
2678         return newnode;
2679 }
2680
2681 static PrepareStmt *
2682 _copyPrepareStmt(PrepareStmt *from)
2683 {
2684         PrepareStmt *newnode = makeNode(PrepareStmt);
2685
2686         COPY_STRING_FIELD(name);
2687         COPY_NODE_FIELD(argtypes);
2688         COPY_NODE_FIELD(argtype_oids);
2689         COPY_NODE_FIELD(query);
2690
2691         return newnode;
2692 }
2693
2694 static ExecuteStmt *
2695 _copyExecuteStmt(ExecuteStmt *from)
2696 {
2697         ExecuteStmt *newnode = makeNode(ExecuteStmt);
2698
2699         COPY_STRING_FIELD(name);
2700         COPY_NODE_FIELD(into);
2701         COPY_NODE_FIELD(intoOptions);
2702         COPY_SCALAR_FIELD(into_on_commit);
2703         COPY_STRING_FIELD(into_tbl_space);
2704         COPY_NODE_FIELD(params);
2705
2706         return newnode;
2707 }
2708
2709 static DeallocateStmt *
2710 _copyDeallocateStmt(DeallocateStmt *from)
2711 {
2712         DeallocateStmt *newnode = makeNode(DeallocateStmt);
2713
2714         COPY_STRING_FIELD(name);
2715
2716         return newnode;
2717 }
2718
2719 static DropOwnedStmt *
2720 _copyDropOwnedStmt(DropOwnedStmt *from)
2721 {
2722         DropOwnedStmt *newnode = makeNode(DropOwnedStmt);
2723
2724         COPY_NODE_FIELD(roles);
2725         COPY_SCALAR_FIELD(behavior);
2726
2727         return newnode;
2728 }
2729
2730 static ReassignOwnedStmt *
2731 _copyReassignOwnedStmt(ReassignOwnedStmt *from)
2732 {
2733         ReassignOwnedStmt *newnode = makeNode(ReassignOwnedStmt);
2734
2735         COPY_NODE_FIELD(roles);
2736         COPY_SCALAR_FIELD(newrole);
2737
2738         return newnode;
2739 }
2740
2741 /* ****************************************************************
2742  *                                      pg_list.h copy functions
2743  * ****************************************************************
2744  */
2745
2746 /*
2747  * Perform a deep copy of the specified list, using copyObject(). The
2748  * list MUST be of type T_List; T_IntList and T_OidList nodes don't
2749  * need deep copies, so they should be copied via list_copy()
2750  */
2751 #define COPY_NODE_CELL(new, old)                                        \
2752         (new) = (ListCell *) palloc(sizeof(ListCell));  \
2753         lfirst(new) = copyObject(lfirst(old));
2754
2755 static List *
2756 _copyList(List *from)
2757 {
2758         List       *new;
2759         ListCell   *curr_old;
2760         ListCell   *prev_new;
2761
2762         Assert(list_length(from) >= 1);
2763
2764         new = makeNode(List);
2765         new->length = from->length;
2766
2767         COPY_NODE_CELL(new->head, from->head);
2768         prev_new = new->head;
2769         curr_old = lnext(from->head);
2770
2771         while (curr_old)
2772         {
2773                 COPY_NODE_CELL(prev_new->next, curr_old);
2774                 prev_new = prev_new->next;
2775                 curr_old = curr_old->next;
2776         }
2777         prev_new->next = NULL;
2778         new->tail = prev_new;
2779
2780         return new;
2781 }
2782
2783 /* ****************************************************************
2784  *                                      value.h copy functions
2785  * ****************************************************************
2786  */
2787 static Value *
2788 _copyValue(Value *from)
2789 {
2790         Value      *newnode = makeNode(Value);
2791
2792         /* See also _copyAConst when changing this code! */
2793
2794         COPY_SCALAR_FIELD(type);
2795         switch (from->type)
2796         {
2797                 case T_Integer:
2798                         COPY_SCALAR_FIELD(val.ival);
2799                         break;
2800                 case T_Float:
2801                 case T_String:
2802                 case T_BitString:
2803                         COPY_STRING_FIELD(val.str);
2804                         break;
2805                 case T_Null:
2806                         /* nothing to do */
2807                         break;
2808                 default:
2809                         elog(ERROR, "unrecognized node type: %d",
2810                                  (int) from->type);
2811                         break;
2812         }
2813         return newnode;
2814 }
2815
2816 /*
2817  * copyObject
2818  *
2819  * Create a copy of a Node tree or list.  This is a "deep" copy: all
2820  * substructure is copied too, recursively.
2821  */
2822 void *
2823 copyObject(void *from)
2824 {
2825         void       *retval;
2826
2827         if (from == NULL)
2828                 return NULL;
2829
2830         switch (nodeTag(from))
2831         {
2832                         /*
2833                          * PLAN NODES
2834                          */
2835                 case T_Plan:
2836                         retval = _copyPlan(from);
2837                         break;
2838                 case T_Result:
2839                         retval = _copyResult(from);
2840                         break;
2841                 case T_Append:
2842                         retval = _copyAppend(from);
2843                         break;
2844                 case T_BitmapAnd:
2845                         retval = _copyBitmapAnd(from);
2846                         break;
2847                 case T_BitmapOr:
2848                         retval = _copyBitmapOr(from);
2849                         break;
2850                 case T_Scan:
2851                         retval = _copyScan(from);
2852                         break;
2853                 case T_SeqScan:
2854                         retval = _copySeqScan(from);
2855                         break;
2856                 case T_IndexScan:
2857                         retval = _copyIndexScan(from);
2858                         break;
2859                 case T_BitmapIndexScan:
2860                         retval = _copyBitmapIndexScan(from);
2861                         break;
2862                 case T_BitmapHeapScan:
2863                         retval = _copyBitmapHeapScan(from);
2864                         break;
2865                 case T_TidScan:
2866                         retval = _copyTidScan(from);
2867                         break;
2868                 case T_SubqueryScan:
2869                         retval = _copySubqueryScan(from);
2870                         break;
2871                 case T_FunctionScan:
2872                         retval = _copyFunctionScan(from);
2873                         break;
2874                 case T_ValuesScan:
2875                         retval = _copyValuesScan(from);
2876                         break;
2877                 case T_Join:
2878                         retval = _copyJoin(from);
2879                         break;
2880                 case T_NestLoop:
2881                         retval = _copyNestLoop(from);
2882                         break;
2883                 case T_MergeJoin:
2884                         retval = _copyMergeJoin(from);
2885                         break;
2886                 case T_HashJoin:
2887                         retval = _copyHashJoin(from);
2888                         break;
2889                 case T_Material:
2890                         retval = _copyMaterial(from);
2891                         break;
2892                 case T_Sort:
2893                         retval = _copySort(from);
2894                         break;
2895                 case T_Group:
2896                         retval = _copyGroup(from);
2897                         break;
2898                 case T_Agg:
2899                         retval = _copyAgg(from);
2900                         break;
2901                 case T_Unique:
2902                         retval = _copyUnique(from);
2903                         break;
2904                 case T_Hash:
2905                         retval = _copyHash(from);
2906                         break;
2907                 case T_SetOp:
2908                         retval = _copySetOp(from);
2909                         break;
2910                 case T_Limit:
2911                         retval = _copyLimit(from);
2912                         break;
2913
2914                         /*
2915                          * PRIMITIVE NODES
2916                          */
2917                 case T_Alias:
2918                         retval = _copyAlias(from);
2919                         break;
2920                 case T_RangeVar:
2921                         retval = _copyRangeVar(from);
2922                         break;
2923                 case T_Var:
2924                         retval = _copyVar(from);
2925                         break;
2926                 case T_Const:
2927                         retval = _copyConst(from);
2928                         break;
2929                 case T_Param:
2930                         retval = _copyParam(from);
2931                         break;
2932                 case T_Aggref:
2933                         retval = _copyAggref(from);
2934                         break;
2935                 case T_ArrayRef:
2936                         retval = _copyArrayRef(from);
2937                         break;
2938                 case T_FuncExpr:
2939                         retval = _copyFuncExpr(from);
2940                         break;
2941                 case T_OpExpr:
2942                         retval = _copyOpExpr(from);
2943                         break;
2944                 case T_DistinctExpr:
2945                         retval = _copyDistinctExpr(from);
2946                         break;
2947                 case T_ScalarArrayOpExpr:
2948                         retval = _copyScalarArrayOpExpr(from);
2949                         break;
2950                 case T_BoolExpr:
2951                         retval = _copyBoolExpr(from);
2952                         break;
2953                 case T_SubLink:
2954                         retval = _copySubLink(from);
2955                         break;
2956                 case T_SubPlan:
2957                         retval = _copySubPlan(from);
2958                         break;
2959                 case T_FieldSelect:
2960                         retval = _copyFieldSelect(from);
2961                         break;
2962                 case T_FieldStore:
2963                         retval = _copyFieldStore(from);
2964                         break;
2965                 case T_RelabelType:
2966                         retval = _copyRelabelType(from);
2967                         break;
2968                 case T_ConvertRowtypeExpr:
2969                         retval = _copyConvertRowtypeExpr(from);
2970                         break;
2971                 case T_CaseExpr:
2972                         retval = _copyCaseExpr(from);
2973                         break;
2974                 case T_CaseWhen:
2975                         retval = _copyCaseWhen(from);
2976                         break;
2977                 case T_CaseTestExpr:
2978                         retval = _copyCaseTestExpr(from);
2979                         break;
2980                 case T_ArrayExpr:
2981                         retval = _copyArrayExpr(from);
2982                         break;
2983                 case T_RowExpr:
2984                         retval = _copyRowExpr(from);
2985                         break;
2986                 case T_RowCompareExpr:
2987                         retval = _copyRowCompareExpr(from);
2988                         break;
2989                 case T_CoalesceExpr:
2990                         retval = _copyCoalesceExpr(from);
2991                         break;
2992                 case T_MinMaxExpr:
2993                         retval = _copyMinMaxExpr(from);
2994                         break;
2995                 case T_XmlExpr:
2996                         retval = _copyXmlExpr(from);
2997                         break;
2998                 case T_NullIfExpr:
2999                         retval = _copyNullIfExpr(from);
3000                         break;
3001                 case T_NullTest:
3002                         retval = _copyNullTest(from);
3003                         break;
3004                 case T_BooleanTest:
3005                         retval = _copyBooleanTest(from);
3006                         break;
3007                 case T_CoerceToDomain:
3008                         retval = _copyCoerceToDomain(from);
3009                         break;
3010                 case T_CoerceToDomainValue:
3011                         retval = _copyCoerceToDomainValue(from);
3012                         break;
3013                 case T_SetToDefault:
3014                         retval = _copySetToDefault(from);
3015                         break;
3016                 case T_TargetEntry:
3017                         retval = _copyTargetEntry(from);
3018                         break;
3019                 case T_RangeTblRef:
3020                         retval = _copyRangeTblRef(from);
3021                         break;
3022                 case T_JoinExpr:
3023                         retval = _copyJoinExpr(from);
3024                         break;
3025                 case T_FromExpr:
3026                         retval = _copyFromExpr(from);
3027                         break;
3028
3029                         /*
3030                          * RELATION NODES
3031                          */
3032                 case T_PathKey:
3033                         retval = _copyPathKey(from);
3034                         break;
3035                 case T_RestrictInfo:
3036                         retval = _copyRestrictInfo(from);
3037                         break;
3038                 case T_OuterJoinInfo:
3039                         retval = _copyOuterJoinInfo(from);
3040                         break;
3041                 case T_InClauseInfo:
3042                         retval = _copyInClauseInfo(from);
3043                         break;
3044                 case T_AppendRelInfo:
3045                         retval = _copyAppendRelInfo(from);
3046                         break;
3047
3048                         /*
3049                          * VALUE NODES
3050                          */
3051                 case T_Integer:
3052                 case T_Float:
3053                 case T_String:
3054                 case T_BitString:
3055                 case T_Null:
3056                         retval = _copyValue(from);
3057                         break;
3058
3059                         /*
3060                          * LIST NODES
3061                          */
3062                 case T_List:
3063                         retval = _copyList(from);
3064                         break;
3065
3066                         /*
3067                          * Lists of integers and OIDs don't need to be deep-copied, so we
3068                          * perform a shallow copy via list_copy()
3069                          */
3070                 case T_IntList:
3071                 case T_OidList:
3072                         retval = list_copy(from);
3073                         break;
3074
3075                         /*
3076                          * PARSE NODES
3077                          */
3078                 case T_Query:
3079                         retval = _copyQuery(from);
3080                         break;
3081                 case T_InsertStmt:
3082                         retval = _copyInsertStmt(from);
3083                         break;
3084                 case T_DeleteStmt:
3085                         retval = _copyDeleteStmt(from);
3086                         break;
3087                 case T_UpdateStmt:
3088                         retval = _copyUpdateStmt(from);
3089                         break;
3090                 case T_SelectStmt:
3091                         retval = _copySelectStmt(from);
3092                         break;
3093                 case T_SetOperationStmt:
3094                         retval = _copySetOperationStmt(from);
3095                         break;
3096                 case T_AlterTableStmt:
3097                         retval = _copyAlterTableStmt(from);
3098                         break;
3099                 case T_AlterTableCmd:
3100                         retval = _copyAlterTableCmd(from);
3101                         break;
3102                 case T_AlterDomainStmt:
3103                         retval = _copyAlterDomainStmt(from);
3104                         break;
3105                 case T_GrantStmt:
3106                         retval = _copyGrantStmt(from);
3107                         break;
3108                 case T_GrantRoleStmt:
3109                         retval = _copyGrantRoleStmt(from);
3110                         break;
3111                 case T_DeclareCursorStmt:
3112                         retval = _copyDeclareCursorStmt(from);
3113                         break;
3114                 case T_ClosePortalStmt:
3115                         retval = _copyClosePortalStmt(from);
3116                         break;
3117                 case T_ClusterStmt:
3118                         retval = _copyClusterStmt(from);
3119                         break;
3120                 case T_CopyStmt:
3121                         retval = _copyCopyStmt(from);
3122                         break;
3123                 case T_CreateStmt:
3124                         retval = _copyCreateStmt(from);
3125                         break;
3126                 case T_InhRelation:
3127                         retval = _copyInhRelation(from);
3128                         break;
3129                 case T_DefineStmt:
3130                         retval = _copyDefineStmt(from);
3131                         break;
3132                 case T_DropStmt:
3133                         retval = _copyDropStmt(from);
3134                         break;
3135                 case T_TruncateStmt:
3136                         retval = _copyTruncateStmt(from);
3137                         break;
3138                 case T_CommentStmt:
3139                         retval = _copyCommentStmt(from);
3140                         break;
3141                 case T_FetchStmt:
3142                         retval = _copyFetchStmt(from);
3143                         break;
3144                 case T_IndexStmt:
3145                         retval = _copyIndexStmt(from);
3146                         break;
3147                 case T_CreateFunctionStmt:
3148                         retval = _copyCreateFunctionStmt(from);
3149                         break;
3150                 case T_FunctionParameter:
3151                         retval = _copyFunctionParameter(from);
3152                         break;
3153                 case T_AlterFunctionStmt:
3154                         retval = _copyAlterFunctionStmt(from);
3155                         break;
3156                 case T_RemoveFuncStmt:
3157                         retval = _copyRemoveFuncStmt(from);
3158                         break;
3159                 case T_RemoveOpClassStmt:
3160                         retval = _copyRemoveOpClassStmt(from);
3161                         break;
3162                 case T_RenameStmt:
3163                         retval = _copyRenameStmt(from);
3164                         break;
3165                 case T_AlterObjectSchemaStmt:
3166                         retval = _copyAlterObjectSchemaStmt(from);
3167                         break;
3168                 case T_AlterOwnerStmt:
3169                         retval = _copyAlterOwnerStmt(from);
3170                         break;
3171                 case T_RuleStmt:
3172                         retval = _copyRuleStmt(from);
3173                         break;
3174                 case T_NotifyStmt:
3175                         retval = _copyNotifyStmt(from);
3176                         break;
3177                 case T_ListenStmt:
3178                         retval = _copyListenStmt(from);
3179                         break;
3180                 case T_UnlistenStmt:
3181                         retval = _copyUnlistenStmt(from);
3182                         break;
3183                 case T_TransactionStmt:
3184                         retval = _copyTransactionStmt(from);
3185                         break;
3186                 case T_CompositeTypeStmt:
3187                         retval = _copyCompositeTypeStmt(from);
3188                         break;
3189                 case T_ViewStmt:
3190                         retval = _copyViewStmt(from);
3191                         break;
3192                 case T_LoadStmt:
3193                         retval = _copyLoadStmt(from);
3194                         break;
3195                 case T_CreateDomainStmt:
3196                         retval = _copyCreateDomainStmt(from);
3197                         break;
3198                 case T_CreateOpClassStmt:
3199                         retval = _copyCreateOpClassStmt(from);
3200                         break;
3201                 case T_CreateOpClassItem:
3202                         retval = _copyCreateOpClassItem(from);
3203                         break;
3204                 case T_CreatedbStmt:
3205                         retval = _copyCreatedbStmt(from);
3206                         break;
3207                 case T_AlterDatabaseStmt:
3208                         retval = _copyAlterDatabaseStmt(from);
3209                         break;
3210                 case T_AlterDatabaseSetStmt:
3211                         retval = _copyAlterDatabaseSetStmt(from);
3212                         break;
3213                 case T_DropdbStmt:
3214                         retval = _copyDropdbStmt(from);
3215                         break;
3216                 case T_VacuumStmt:
3217                         retval = _copyVacuumStmt(from);
3218                         break;
3219                 case T_ExplainStmt:
3220                         retval = _copyExplainStmt(from);
3221                         break;
3222                 case T_CreateSeqStmt:
3223                         retval = _copyCreateSeqStmt(from);
3224                         break;
3225                 case T_AlterSeqStmt:
3226                         retval = _copyAlterSeqStmt(from);
3227                         break;
3228                 case T_VariableSetStmt:
3229                         retval = _copyVariableSetStmt(from);
3230                         break;
3231                 case T_VariableShowStmt:
3232                         retval = _copyVariableShowStmt(from);
3233                         break;
3234                 case T_VariableResetStmt:
3235                         retval = _copyVariableResetStmt(from);
3236                         break;
3237                 case T_CreateTableSpaceStmt:
3238                         retval = _copyCreateTableSpaceStmt(from);
3239                         break;
3240                 case T_DropTableSpaceStmt:
3241                         retval = _copyDropTableSpaceStmt(from);
3242                         break;
3243                 case T_CreateTrigStmt:
3244                         retval = _copyCreateTrigStmt(from);
3245                         break;
3246                 case T_DropPropertyStmt:
3247                         retval = _copyDropPropertyStmt(from);
3248                         break;
3249                 case T_CreatePLangStmt:
3250                         retval = _copyCreatePLangStmt(from);
3251                         break;
3252                 case T_DropPLangStmt:
3253                         retval = _copyDropPLangStmt(from);
3254                         break;
3255                 case T_CreateRoleStmt:
3256                         retval = _copyCreateRoleStmt(from);
3257                         break;
3258                 case T_AlterRoleStmt:
3259                         retval = _copyAlterRoleStmt(from);
3260                         break;
3261                 case T_AlterRoleSetStmt:
3262                         retval = _copyAlterRoleSetStmt(from);
3263                         break;
3264                 case T_DropRoleStmt:
3265                         retval = _copyDropRoleStmt(from);
3266                         break;
3267                 case T_LockStmt:
3268                         retval = _copyLockStmt(from);
3269                         break;
3270                 case T_ConstraintsSetStmt:
3271                         retval = _copyConstraintsSetStmt(from);
3272                         break;
3273                 case T_ReindexStmt:
3274                         retval = _copyReindexStmt(from);
3275                         break;
3276                 case T_CheckPointStmt:
3277                         retval = (void *) makeNode(CheckPointStmt);
3278                         break;
3279                 case T_CreateSchemaStmt:
3280                         retval = _copyCreateSchemaStmt(from);
3281                         break;
3282                 case T_CreateConversionStmt:
3283                         retval = _copyCreateConversionStmt(from);
3284                         break;
3285                 case T_CreateCastStmt:
3286                         retval = _copyCreateCastStmt(from);
3287                         break;
3288                 case T_DropCastStmt:
3289                         retval = _copyDropCastStmt(from);
3290                         break;
3291                 case T_PrepareStmt:
3292                         retval = _copyPrepareStmt(from);
3293                         break;
3294                 case T_ExecuteStmt:
3295                         retval = _copyExecuteStmt(from);
3296                         break;
3297                 case T_DeallocateStmt:
3298                         retval = _copyDeallocateStmt(from);
3299                         break;
3300                 case T_DropOwnedStmt:
3301                         retval = _copyDropOwnedStmt(from);
3302                         break;
3303                 case T_ReassignOwnedStmt:
3304                         retval = _copyReassignOwnedStmt(from);
3305                         break;
3306
3307                 case T_A_Expr:
3308                         retval = _copyAExpr(from);
3309                         break;
3310                 case T_ColumnRef:
3311                         retval = _copyColumnRef(from);
3312                         break;
3313                 case T_ParamRef:
3314                         retval = _copyParamRef(from);
3315                         break;
3316                 case T_A_Const:
3317                         retval = _copyAConst(from);
3318                         break;
3319                 case T_FuncCall:
3320                         retval = _copyFuncCall(from);
3321                         break;
3322                 case T_A_Indices:
3323                         retval = _copyAIndices(from);
3324                         break;
3325                 case T_A_Indirection:
3326                         retval = _copyA_Indirection(from);
3327                         break;
3328                 case T_ResTarget:
3329                         retval = _copyResTarget(from);
3330                         break;
3331                 case T_TypeCast:
3332                         retval = _copyTypeCast(from);
3333                         break;
3334                 case T_SortBy:
3335                         retval = _copySortBy(from);
3336                         break;
3337                 case T_RangeSubselect:
3338                         retval = _copyRangeSubselect(from);
3339                         break;
3340                 case T_RangeFunction:
3341                         retval = _copyRangeFunction(from);
3342                         break;
3343                 case T_TypeName:
3344                         retval = _copyTypeName(from);
3345                         break;
3346                 case T_IndexElem:
3347                         retval = _copyIndexElem(from);
3348                         break;
3349                 case T_ColumnDef:
3350                         retval = _copyColumnDef(from);
3351                         break;
3352                 case T_Constraint:
3353                         retval = _copyConstraint(from);
3354                         break;
3355                 case T_DefElem:
3356                         retval = _copyDefElem(from);
3357                         break;
3358                 case T_LockingClause:
3359                         retval = _copyLockingClause(from);
3360                         break;
3361                 case T_RangeTblEntry:
3362                         retval = _copyRangeTblEntry(from);
3363                         break;
3364                 case T_SortClause:
3365                         retval = _copySortClause(from);
3366                         break;
3367                 case T_GroupClause:
3368                         retval = _copyGroupClause(from);
3369                         break;
3370                 case T_RowMarkClause:
3371                         retval = _copyRowMarkClause(from);
3372                         break;
3373                 case T_FkConstraint:
3374                         retval = _copyFkConstraint(from);
3375                         break;
3376                 case T_PrivGrantee:
3377                         retval = _copyPrivGrantee(from);
3378                         break;
3379                 case T_FuncWithArgs:
3380                         retval = _copyFuncWithArgs(from);
3381                         break;
3382
3383                 default:
3384                         elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
3385                         retval = from;          /* keep compiler quiet */
3386                         break;
3387         }
3388
3389         return retval;
3390 }