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