]> granicus.if.org Git - postgresql/blob - src/backend/nodes/copyfuncs.c
Teach planner about some cases where a restriction clause can be
[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-2005, 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.311 2005/07/02 23:00:39 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(tideval);
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_SCALAR_FIELD(useOr);
866         COPY_NODE_FIELD(lefthand);
867         COPY_NODE_FIELD(operName);
868         COPY_NODE_FIELD(operOids);
869         COPY_NODE_FIELD(subselect);
870
871         return newnode;
872 }
873
874 /*
875  * _copySubPlan
876  */
877 static SubPlan *
878 _copySubPlan(SubPlan *from)
879 {
880         SubPlan    *newnode = makeNode(SubPlan);
881
882         COPY_SCALAR_FIELD(subLinkType);
883         COPY_SCALAR_FIELD(useOr);
884         COPY_NODE_FIELD(exprs);
885         COPY_NODE_FIELD(paramIds);
886         COPY_NODE_FIELD(plan);
887         COPY_SCALAR_FIELD(plan_id);
888         COPY_NODE_FIELD(rtable);
889         COPY_SCALAR_FIELD(useHashTable);
890         COPY_SCALAR_FIELD(unknownEqFalse);
891         COPY_NODE_FIELD(setParam);
892         COPY_NODE_FIELD(parParam);
893         COPY_NODE_FIELD(args);
894
895         return newnode;
896 }
897
898 /*
899  * _copyFieldSelect
900  */
901 static FieldSelect *
902 _copyFieldSelect(FieldSelect *from)
903 {
904         FieldSelect *newnode = makeNode(FieldSelect);
905
906         COPY_NODE_FIELD(arg);
907         COPY_SCALAR_FIELD(fieldnum);
908         COPY_SCALAR_FIELD(resulttype);
909         COPY_SCALAR_FIELD(resulttypmod);
910
911         return newnode;
912 }
913
914 /*
915  * _copyFieldStore
916  */
917 static FieldStore *
918 _copyFieldStore(FieldStore *from)
919 {
920         FieldStore *newnode = makeNode(FieldStore);
921
922         COPY_NODE_FIELD(arg);
923         COPY_NODE_FIELD(newvals);
924         COPY_NODE_FIELD(fieldnums);
925         COPY_SCALAR_FIELD(resulttype);
926
927         return newnode;
928 }
929
930 /*
931  * _copyRelabelType
932  */
933 static RelabelType *
934 _copyRelabelType(RelabelType *from)
935 {
936         RelabelType *newnode = makeNode(RelabelType);
937
938         COPY_NODE_FIELD(arg);
939         COPY_SCALAR_FIELD(resulttype);
940         COPY_SCALAR_FIELD(resulttypmod);
941         COPY_SCALAR_FIELD(relabelformat);
942
943         return newnode;
944 }
945
946 /*
947  * _copyConvertRowtypeExpr
948  */
949 static ConvertRowtypeExpr *
950 _copyConvertRowtypeExpr(ConvertRowtypeExpr *from)
951 {
952         ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);
953
954         COPY_NODE_FIELD(arg);
955         COPY_SCALAR_FIELD(resulttype);
956         COPY_SCALAR_FIELD(convertformat);
957
958         return newnode;
959 }
960
961 /*
962  * _copyCaseExpr
963  */
964 static CaseExpr *
965 _copyCaseExpr(CaseExpr *from)
966 {
967         CaseExpr   *newnode = makeNode(CaseExpr);
968
969         COPY_SCALAR_FIELD(casetype);
970         COPY_NODE_FIELD(arg);
971         COPY_NODE_FIELD(args);
972         COPY_NODE_FIELD(defresult);
973
974         return newnode;
975 }
976
977 /*
978  * _copyCaseWhen
979  */
980 static CaseWhen *
981 _copyCaseWhen(CaseWhen *from)
982 {
983         CaseWhen   *newnode = makeNode(CaseWhen);
984
985         COPY_NODE_FIELD(expr);
986         COPY_NODE_FIELD(result);
987
988         return newnode;
989 }
990
991 /*
992  * _copyCaseTestExpr
993  */
994 static CaseTestExpr *
995 _copyCaseTestExpr(CaseTestExpr *from)
996 {
997         CaseTestExpr *newnode = makeNode(CaseTestExpr);
998
999         COPY_SCALAR_FIELD(typeId);
1000         COPY_SCALAR_FIELD(typeMod);
1001
1002         return newnode;
1003 }
1004
1005 /*
1006  * _copyArrayExpr
1007  */
1008 static ArrayExpr *
1009 _copyArrayExpr(ArrayExpr *from)
1010 {
1011         ArrayExpr  *newnode = makeNode(ArrayExpr);
1012
1013         COPY_SCALAR_FIELD(array_typeid);
1014         COPY_SCALAR_FIELD(element_typeid);
1015         COPY_NODE_FIELD(elements);
1016         COPY_SCALAR_FIELD(multidims);
1017
1018         return newnode;
1019 }
1020
1021 /*
1022  * _copyRowExpr
1023  */
1024 static RowExpr *
1025 _copyRowExpr(RowExpr *from)
1026 {
1027         RowExpr    *newnode = makeNode(RowExpr);
1028
1029         COPY_NODE_FIELD(args);
1030         COPY_SCALAR_FIELD(row_typeid);
1031         COPY_SCALAR_FIELD(row_format);
1032
1033         return newnode;
1034 }
1035
1036 /*
1037  * _copyCoalesceExpr
1038  */
1039 static CoalesceExpr *
1040 _copyCoalesceExpr(CoalesceExpr *from)
1041 {
1042         CoalesceExpr *newnode = makeNode(CoalesceExpr);
1043
1044         COPY_SCALAR_FIELD(coalescetype);
1045         COPY_NODE_FIELD(args);
1046
1047         return newnode;
1048 }
1049
1050 /*
1051  * _copyMinMaxExpr
1052  */
1053 static MinMaxExpr *
1054 _copyMinMaxExpr(MinMaxExpr *from)
1055 {
1056         MinMaxExpr *newnode = makeNode(MinMaxExpr);
1057
1058         COPY_SCALAR_FIELD(minmaxtype);
1059         COPY_SCALAR_FIELD(op);
1060         COPY_NODE_FIELD(args);
1061
1062         return newnode;
1063 }
1064
1065 /*
1066  * _copyNullIfExpr (same as OpExpr)
1067  */
1068 static NullIfExpr *
1069 _copyNullIfExpr(NullIfExpr *from)
1070 {
1071         NullIfExpr *newnode = makeNode(NullIfExpr);
1072
1073         COPY_SCALAR_FIELD(opno);
1074         COPY_SCALAR_FIELD(opfuncid);
1075         COPY_SCALAR_FIELD(opresulttype);
1076         COPY_SCALAR_FIELD(opretset);
1077         COPY_NODE_FIELD(args);
1078
1079         return newnode;
1080 }
1081
1082 /*
1083  * _copyNullTest
1084  */
1085 static NullTest *
1086 _copyNullTest(NullTest *from)
1087 {
1088         NullTest   *newnode = makeNode(NullTest);
1089
1090         COPY_NODE_FIELD(arg);
1091         COPY_SCALAR_FIELD(nulltesttype);
1092
1093         return newnode;
1094 }
1095
1096 /*
1097  * _copyBooleanTest
1098  */
1099 static BooleanTest *
1100 _copyBooleanTest(BooleanTest *from)
1101 {
1102         BooleanTest *newnode = makeNode(BooleanTest);
1103
1104         COPY_NODE_FIELD(arg);
1105         COPY_SCALAR_FIELD(booltesttype);
1106
1107         return newnode;
1108 }
1109
1110 /*
1111  * _copyCoerceToDomain
1112  */
1113 static CoerceToDomain *
1114 _copyCoerceToDomain(CoerceToDomain *from)
1115 {
1116         CoerceToDomain *newnode = makeNode(CoerceToDomain);
1117
1118         COPY_NODE_FIELD(arg);
1119         COPY_SCALAR_FIELD(resulttype);
1120         COPY_SCALAR_FIELD(resulttypmod);
1121         COPY_SCALAR_FIELD(coercionformat);
1122
1123         return newnode;
1124 }
1125
1126 /*
1127  * _copyCoerceToDomainValue
1128  */
1129 static CoerceToDomainValue *
1130 _copyCoerceToDomainValue(CoerceToDomainValue *from)
1131 {
1132         CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1133
1134         COPY_SCALAR_FIELD(typeId);
1135         COPY_SCALAR_FIELD(typeMod);
1136
1137         return newnode;
1138 }
1139
1140 /*
1141  * _copySetToDefault
1142  */
1143 static SetToDefault *
1144 _copySetToDefault(SetToDefault *from)
1145 {
1146         SetToDefault *newnode = makeNode(SetToDefault);
1147
1148         COPY_SCALAR_FIELD(typeId);
1149         COPY_SCALAR_FIELD(typeMod);
1150
1151         return newnode;
1152 }
1153
1154 /*
1155  * _copyTargetEntry
1156  */
1157 static TargetEntry *
1158 _copyTargetEntry(TargetEntry *from)
1159 {
1160         TargetEntry *newnode = makeNode(TargetEntry);
1161
1162         COPY_NODE_FIELD(expr);
1163         COPY_SCALAR_FIELD(resno);
1164         COPY_STRING_FIELD(resname);
1165         COPY_SCALAR_FIELD(ressortgroupref);
1166         COPY_SCALAR_FIELD(resorigtbl);
1167         COPY_SCALAR_FIELD(resorigcol);
1168         COPY_SCALAR_FIELD(resjunk);
1169
1170         return newnode;
1171 }
1172
1173 /*
1174  * _copyRangeTblRef
1175  */
1176 static RangeTblRef *
1177 _copyRangeTblRef(RangeTblRef *from)
1178 {
1179         RangeTblRef *newnode = makeNode(RangeTblRef);
1180
1181         COPY_SCALAR_FIELD(rtindex);
1182
1183         return newnode;
1184 }
1185
1186 /*
1187  * _copyJoinExpr
1188  */
1189 static JoinExpr *
1190 _copyJoinExpr(JoinExpr *from)
1191 {
1192         JoinExpr   *newnode = makeNode(JoinExpr);
1193
1194         COPY_SCALAR_FIELD(jointype);
1195         COPY_SCALAR_FIELD(isNatural);
1196         COPY_NODE_FIELD(larg);
1197         COPY_NODE_FIELD(rarg);
1198         COPY_NODE_FIELD(using);
1199         COPY_NODE_FIELD(quals);
1200         COPY_NODE_FIELD(alias);
1201         COPY_SCALAR_FIELD(rtindex);
1202
1203         return newnode;
1204 }
1205
1206 /*
1207  * _copyFromExpr
1208  */
1209 static FromExpr *
1210 _copyFromExpr(FromExpr *from)
1211 {
1212         FromExpr   *newnode = makeNode(FromExpr);
1213
1214         COPY_NODE_FIELD(fromlist);
1215         COPY_NODE_FIELD(quals);
1216
1217         return newnode;
1218 }
1219
1220 /* ****************************************************************
1221  *                                              relation.h copy functions
1222  *
1223  * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1224  * There are some subsidiary structs that are useful to copy, though.
1225  * ****************************************************************
1226  */
1227
1228 /*
1229  * _copyPathKeyItem
1230  */
1231 static PathKeyItem *
1232 _copyPathKeyItem(PathKeyItem *from)
1233 {
1234         PathKeyItem *newnode = makeNode(PathKeyItem);
1235
1236         COPY_NODE_FIELD(key);
1237         COPY_SCALAR_FIELD(sortop);
1238
1239         return newnode;
1240 }
1241
1242 /*
1243  * _copyRestrictInfo
1244  */
1245 static RestrictInfo *
1246 _copyRestrictInfo(RestrictInfo *from)
1247 {
1248         RestrictInfo *newnode = makeNode(RestrictInfo);
1249
1250         COPY_NODE_FIELD(clause);
1251         COPY_SCALAR_FIELD(is_pushed_down);
1252         COPY_SCALAR_FIELD(can_join);
1253         COPY_BITMAPSET_FIELD(clause_relids);
1254         COPY_BITMAPSET_FIELD(required_relids);
1255         COPY_BITMAPSET_FIELD(left_relids);
1256         COPY_BITMAPSET_FIELD(right_relids);
1257         COPY_NODE_FIELD(orclause);
1258         COPY_SCALAR_FIELD(eval_cost);
1259         COPY_SCALAR_FIELD(this_selec);
1260         COPY_SCALAR_FIELD(mergejoinoperator);
1261         COPY_SCALAR_FIELD(left_sortop);
1262         COPY_SCALAR_FIELD(right_sortop);
1263
1264         /*
1265          * Do not copy pathkeys, since they'd not be canonical in a copied
1266          * query
1267          */
1268         newnode->left_pathkey = NIL;
1269         newnode->right_pathkey = NIL;
1270
1271         COPY_SCALAR_FIELD(left_mergescansel);
1272         COPY_SCALAR_FIELD(right_mergescansel);
1273         COPY_SCALAR_FIELD(hashjoinoperator);
1274         COPY_SCALAR_FIELD(left_bucketsize);
1275         COPY_SCALAR_FIELD(right_bucketsize);
1276
1277         return newnode;
1278 }
1279
1280 /*
1281  * _copyInClauseInfo
1282  */
1283 static InClauseInfo *
1284 _copyInClauseInfo(InClauseInfo *from)
1285 {
1286         InClauseInfo *newnode = makeNode(InClauseInfo);
1287
1288         COPY_BITMAPSET_FIELD(lefthand);
1289         COPY_BITMAPSET_FIELD(righthand);
1290         COPY_NODE_FIELD(sub_targetlist);
1291
1292         return newnode;
1293 }
1294
1295 /* ****************************************************************
1296  *                                      parsenodes.h copy functions
1297  * ****************************************************************
1298  */
1299
1300 static RangeTblEntry *
1301 _copyRangeTblEntry(RangeTblEntry *from)
1302 {
1303         RangeTblEntry *newnode = makeNode(RangeTblEntry);
1304
1305         COPY_SCALAR_FIELD(rtekind);
1306         COPY_SCALAR_FIELD(relid);
1307         COPY_NODE_FIELD(subquery);
1308         COPY_NODE_FIELD(funcexpr);
1309         COPY_NODE_FIELD(coldeflist);
1310         COPY_SCALAR_FIELD(jointype);
1311         COPY_NODE_FIELD(joinaliasvars);
1312         COPY_NODE_FIELD(alias);
1313         COPY_NODE_FIELD(eref);
1314         COPY_SCALAR_FIELD(inh);
1315         COPY_SCALAR_FIELD(inFromCl);
1316         COPY_SCALAR_FIELD(requiredPerms);
1317         COPY_SCALAR_FIELD(checkAsUser);
1318
1319         return newnode;
1320 }
1321
1322 static FkConstraint *
1323 _copyFkConstraint(FkConstraint *from)
1324 {
1325         FkConstraint *newnode = makeNode(FkConstraint);
1326
1327         COPY_STRING_FIELD(constr_name);
1328         COPY_NODE_FIELD(pktable);
1329         COPY_NODE_FIELD(fk_attrs);
1330         COPY_NODE_FIELD(pk_attrs);
1331         COPY_SCALAR_FIELD(fk_matchtype);
1332         COPY_SCALAR_FIELD(fk_upd_action);
1333         COPY_SCALAR_FIELD(fk_del_action);
1334         COPY_SCALAR_FIELD(deferrable);
1335         COPY_SCALAR_FIELD(initdeferred);
1336         COPY_SCALAR_FIELD(skip_validation);
1337
1338         return newnode;
1339 }
1340
1341 static SortClause *
1342 _copySortClause(SortClause *from)
1343 {
1344         SortClause *newnode = makeNode(SortClause);
1345
1346         COPY_SCALAR_FIELD(tleSortGroupRef);
1347         COPY_SCALAR_FIELD(sortop);
1348
1349         return newnode;
1350 }
1351
1352 static GroupClause *
1353 _copyGroupClause(GroupClause *from)
1354 {
1355         GroupClause *newnode = makeNode(GroupClause);
1356
1357         COPY_SCALAR_FIELD(tleSortGroupRef);
1358         COPY_SCALAR_FIELD(sortop);
1359
1360         return newnode;
1361 }
1362
1363 static A_Expr *
1364 _copyAExpr(A_Expr *from)
1365 {
1366         A_Expr     *newnode = makeNode(A_Expr);
1367
1368         COPY_SCALAR_FIELD(kind);
1369         COPY_NODE_FIELD(name);
1370         COPY_NODE_FIELD(lexpr);
1371         COPY_NODE_FIELD(rexpr);
1372
1373         return newnode;
1374 }
1375
1376 static ColumnRef *
1377 _copyColumnRef(ColumnRef *from)
1378 {
1379         ColumnRef  *newnode = makeNode(ColumnRef);
1380
1381         COPY_NODE_FIELD(fields);
1382
1383         return newnode;
1384 }
1385
1386 static ParamRef *
1387 _copyParamRef(ParamRef *from)
1388 {
1389         ParamRef   *newnode = makeNode(ParamRef);
1390
1391         COPY_SCALAR_FIELD(number);
1392
1393         return newnode;
1394 }
1395
1396 static A_Const *
1397 _copyAConst(A_Const *from)
1398 {
1399         A_Const    *newnode = makeNode(A_Const);
1400
1401         /* This part must duplicate _copyValue */
1402         COPY_SCALAR_FIELD(val.type);
1403         switch (from->val.type)
1404         {
1405                 case T_Integer:
1406                         COPY_SCALAR_FIELD(val.val.ival);
1407                         break;
1408                 case T_Float:
1409                 case T_String:
1410                 case T_BitString:
1411                         COPY_STRING_FIELD(val.val.str);
1412                         break;
1413                 case T_Null:
1414                         /* nothing to do */
1415                         break;
1416                 default:
1417                         elog(ERROR, "unrecognized node type: %d",
1418                                  (int) from->val.type);
1419                         break;
1420         }
1421
1422         COPY_NODE_FIELD(typename);
1423
1424         return newnode;
1425 }
1426
1427 static FuncCall *
1428 _copyFuncCall(FuncCall *from)
1429 {
1430         FuncCall   *newnode = makeNode(FuncCall);
1431
1432         COPY_NODE_FIELD(funcname);
1433         COPY_NODE_FIELD(args);
1434         COPY_SCALAR_FIELD(agg_star);
1435         COPY_SCALAR_FIELD(agg_distinct);
1436
1437         return newnode;
1438 }
1439
1440 static A_Indices *
1441 _copyAIndices(A_Indices *from)
1442 {
1443         A_Indices  *newnode = makeNode(A_Indices);
1444
1445         COPY_NODE_FIELD(lidx);
1446         COPY_NODE_FIELD(uidx);
1447
1448         return newnode;
1449 }
1450
1451 static A_Indirection *
1452 _copyA_Indirection(A_Indirection *from)
1453 {
1454         A_Indirection *newnode = makeNode(A_Indirection);
1455
1456         COPY_NODE_FIELD(arg);
1457         COPY_NODE_FIELD(indirection);
1458
1459         return newnode;
1460 }
1461
1462 static ResTarget *
1463 _copyResTarget(ResTarget *from)
1464 {
1465         ResTarget  *newnode = makeNode(ResTarget);
1466
1467         COPY_STRING_FIELD(name);
1468         COPY_NODE_FIELD(indirection);
1469         COPY_NODE_FIELD(val);
1470
1471         return newnode;
1472 }
1473
1474 static TypeName *
1475 _copyTypeName(TypeName *from)
1476 {
1477         TypeName   *newnode = makeNode(TypeName);
1478
1479         COPY_NODE_FIELD(names);
1480         COPY_SCALAR_FIELD(typeid);
1481         COPY_SCALAR_FIELD(timezone);
1482         COPY_SCALAR_FIELD(setof);
1483         COPY_SCALAR_FIELD(pct_type);
1484         COPY_SCALAR_FIELD(typmod);
1485         COPY_NODE_FIELD(arrayBounds);
1486
1487         return newnode;
1488 }
1489
1490 static SortBy *
1491 _copySortBy(SortBy *from)
1492 {
1493         SortBy     *newnode = makeNode(SortBy);
1494
1495         COPY_SCALAR_FIELD(sortby_kind);
1496         COPY_NODE_FIELD(useOp);
1497         COPY_NODE_FIELD(node);
1498
1499         return newnode;
1500 }
1501
1502 static RangeSubselect *
1503 _copyRangeSubselect(RangeSubselect *from)
1504 {
1505         RangeSubselect *newnode = makeNode(RangeSubselect);
1506
1507         COPY_NODE_FIELD(subquery);
1508         COPY_NODE_FIELD(alias);
1509
1510         return newnode;
1511 }
1512
1513 static RangeFunction *
1514 _copyRangeFunction(RangeFunction *from)
1515 {
1516         RangeFunction *newnode = makeNode(RangeFunction);
1517
1518         COPY_NODE_FIELD(funccallnode);
1519         COPY_NODE_FIELD(alias);
1520         COPY_NODE_FIELD(coldeflist);
1521
1522         return newnode;
1523 }
1524
1525 static TypeCast *
1526 _copyTypeCast(TypeCast *from)
1527 {
1528         TypeCast   *newnode = makeNode(TypeCast);
1529
1530         COPY_NODE_FIELD(arg);
1531         COPY_NODE_FIELD(typename);
1532
1533         return newnode;
1534 }
1535
1536 static IndexElem *
1537 _copyIndexElem(IndexElem *from)
1538 {
1539         IndexElem  *newnode = makeNode(IndexElem);
1540
1541         COPY_STRING_FIELD(name);
1542         COPY_NODE_FIELD(expr);
1543         COPY_NODE_FIELD(opclass);
1544
1545         return newnode;
1546 }
1547
1548 static ColumnDef *
1549 _copyColumnDef(ColumnDef *from)
1550 {
1551         ColumnDef  *newnode = makeNode(ColumnDef);
1552
1553         COPY_STRING_FIELD(colname);
1554         COPY_NODE_FIELD(typename);
1555         COPY_SCALAR_FIELD(inhcount);
1556         COPY_SCALAR_FIELD(is_local);
1557         COPY_SCALAR_FIELD(is_not_null);
1558         COPY_NODE_FIELD(raw_default);
1559         COPY_STRING_FIELD(cooked_default);
1560         COPY_NODE_FIELD(constraints);
1561         COPY_NODE_FIELD(support);
1562
1563         return newnode;
1564 }
1565
1566 static Constraint *
1567 _copyConstraint(Constraint *from)
1568 {
1569         Constraint *newnode = makeNode(Constraint);
1570
1571         COPY_SCALAR_FIELD(contype);
1572         COPY_STRING_FIELD(name);
1573         COPY_NODE_FIELD(raw_expr);
1574         COPY_STRING_FIELD(cooked_expr);
1575         COPY_NODE_FIELD(keys);
1576         COPY_STRING_FIELD(indexspace);
1577
1578         return newnode;
1579 }
1580
1581 static DefElem *
1582 _copyDefElem(DefElem *from)
1583 {
1584         DefElem    *newnode = makeNode(DefElem);
1585
1586         COPY_STRING_FIELD(defname);
1587         COPY_NODE_FIELD(arg);
1588
1589         return newnode;
1590 }
1591
1592 static Query *
1593 _copyQuery(Query *from)
1594 {
1595         Query      *newnode = makeNode(Query);
1596
1597         COPY_SCALAR_FIELD(commandType);
1598         COPY_SCALAR_FIELD(querySource);
1599         COPY_SCALAR_FIELD(canSetTag);
1600         COPY_NODE_FIELD(utilityStmt);
1601         COPY_SCALAR_FIELD(resultRelation);
1602         COPY_NODE_FIELD(into);
1603         COPY_SCALAR_FIELD(intoHasOids);
1604         COPY_SCALAR_FIELD(hasAggs);
1605         COPY_SCALAR_FIELD(hasSubLinks);
1606         COPY_NODE_FIELD(rtable);
1607         COPY_NODE_FIELD(jointree);
1608         COPY_NODE_FIELD(rowMarks);
1609         COPY_SCALAR_FIELD(forUpdate);
1610         COPY_NODE_FIELD(targetList);
1611         COPY_NODE_FIELD(groupClause);
1612         COPY_NODE_FIELD(havingQual);
1613         COPY_NODE_FIELD(distinctClause);
1614         COPY_NODE_FIELD(sortClause);
1615         COPY_NODE_FIELD(limitOffset);
1616         COPY_NODE_FIELD(limitCount);
1617         COPY_NODE_FIELD(setOperations);
1618         COPY_NODE_FIELD(resultRelations);
1619
1620         return newnode;
1621 }
1622
1623 static InsertStmt *
1624 _copyInsertStmt(InsertStmt *from)
1625 {
1626         InsertStmt *newnode = makeNode(InsertStmt);
1627
1628         COPY_NODE_FIELD(relation);
1629         COPY_NODE_FIELD(cols);
1630         COPY_NODE_FIELD(targetList);
1631         COPY_NODE_FIELD(selectStmt);
1632
1633         return newnode;
1634 }
1635
1636 static DeleteStmt *
1637 _copyDeleteStmt(DeleteStmt *from)
1638 {
1639         DeleteStmt *newnode = makeNode(DeleteStmt);
1640
1641         COPY_NODE_FIELD(relation);
1642         COPY_NODE_FIELD(whereClause);
1643         COPY_NODE_FIELD(usingClause);
1644
1645         return newnode;
1646 }
1647
1648 static UpdateStmt *
1649 _copyUpdateStmt(UpdateStmt *from)
1650 {
1651         UpdateStmt *newnode = makeNode(UpdateStmt);
1652
1653         COPY_NODE_FIELD(relation);
1654         COPY_NODE_FIELD(targetList);
1655         COPY_NODE_FIELD(whereClause);
1656         COPY_NODE_FIELD(fromClause);
1657
1658         return newnode;
1659 }
1660
1661 static SelectStmt *
1662 _copySelectStmt(SelectStmt *from)
1663 {
1664         SelectStmt *newnode = makeNode(SelectStmt);
1665
1666         COPY_NODE_FIELD(distinctClause);
1667         COPY_NODE_FIELD(into);
1668         COPY_NODE_FIELD(intoColNames);
1669         COPY_SCALAR_FIELD(intoHasOids);
1670         COPY_NODE_FIELD(targetList);
1671         COPY_NODE_FIELD(fromClause);
1672         COPY_NODE_FIELD(whereClause);
1673         COPY_NODE_FIELD(groupClause);
1674         COPY_NODE_FIELD(havingClause);
1675         COPY_NODE_FIELD(sortClause);
1676         COPY_NODE_FIELD(limitOffset);
1677         COPY_NODE_FIELD(limitCount);
1678         COPY_NODE_FIELD(lockedRels);
1679         COPY_SCALAR_FIELD(forUpdate);
1680         COPY_SCALAR_FIELD(op);
1681         COPY_SCALAR_FIELD(all);
1682         COPY_NODE_FIELD(larg);
1683         COPY_NODE_FIELD(rarg);
1684
1685         return newnode;
1686 }
1687
1688 static SetOperationStmt *
1689 _copySetOperationStmt(SetOperationStmt *from)
1690 {
1691         SetOperationStmt *newnode = makeNode(SetOperationStmt);
1692
1693         COPY_SCALAR_FIELD(op);
1694         COPY_SCALAR_FIELD(all);
1695         COPY_NODE_FIELD(larg);
1696         COPY_NODE_FIELD(rarg);
1697         COPY_NODE_FIELD(colTypes);
1698
1699         return newnode;
1700 }
1701
1702 static AlterTableStmt *
1703 _copyAlterTableStmt(AlterTableStmt *from)
1704 {
1705         AlterTableStmt *newnode = makeNode(AlterTableStmt);
1706
1707         COPY_NODE_FIELD(relation);
1708         COPY_NODE_FIELD(cmds);
1709         COPY_SCALAR_FIELD(relkind);
1710
1711         return newnode;
1712 }
1713
1714 static AlterTableCmd *
1715 _copyAlterTableCmd(AlterTableCmd *from)
1716 {
1717         AlterTableCmd *newnode = makeNode(AlterTableCmd);
1718
1719         COPY_SCALAR_FIELD(subtype);
1720         COPY_STRING_FIELD(name);
1721         COPY_NODE_FIELD(def);
1722         COPY_NODE_FIELD(transform);
1723         COPY_SCALAR_FIELD(behavior);
1724
1725         return newnode;
1726 }
1727
1728 static AlterDomainStmt *
1729 _copyAlterDomainStmt(AlterDomainStmt *from)
1730 {
1731         AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1732
1733         COPY_SCALAR_FIELD(subtype);
1734         COPY_NODE_FIELD(typename);
1735         COPY_STRING_FIELD(name);
1736         COPY_NODE_FIELD(def);
1737         COPY_SCALAR_FIELD(behavior);
1738
1739         return newnode;
1740 }
1741
1742 static GrantStmt *
1743 _copyGrantStmt(GrantStmt *from)
1744 {
1745         GrantStmt  *newnode = makeNode(GrantStmt);
1746
1747         COPY_SCALAR_FIELD(is_grant);
1748         COPY_SCALAR_FIELD(objtype);
1749         COPY_NODE_FIELD(objects);
1750         COPY_NODE_FIELD(privileges);
1751         COPY_NODE_FIELD(grantees);
1752         COPY_SCALAR_FIELD(grant_option);
1753         COPY_SCALAR_FIELD(behavior);
1754
1755         return newnode;
1756 }
1757
1758 static PrivGrantee *
1759 _copyPrivGrantee(PrivGrantee *from)
1760 {
1761         PrivGrantee *newnode = makeNode(PrivGrantee);
1762
1763         COPY_STRING_FIELD(rolname);
1764
1765         return newnode;
1766 }
1767
1768 static FuncWithArgs *
1769 _copyFuncWithArgs(FuncWithArgs *from)
1770 {
1771         FuncWithArgs *newnode = makeNode(FuncWithArgs);
1772
1773         COPY_NODE_FIELD(funcname);
1774         COPY_NODE_FIELD(funcargs);
1775
1776         return newnode;
1777 }
1778
1779 static GrantRoleStmt *
1780 _copyGrantRoleStmt(GrantRoleStmt *from)
1781 {
1782         GrantRoleStmt  *newnode = makeNode(GrantRoleStmt);
1783
1784         COPY_NODE_FIELD(granted_roles);
1785         COPY_NODE_FIELD(grantee_roles);
1786         COPY_SCALAR_FIELD(is_grant);
1787         COPY_SCALAR_FIELD(admin_opt);
1788         COPY_STRING_FIELD(grantor);
1789         COPY_SCALAR_FIELD(behavior);
1790
1791         return newnode;
1792 }
1793
1794 static DeclareCursorStmt *
1795 _copyDeclareCursorStmt(DeclareCursorStmt *from)
1796 {
1797         DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
1798
1799         COPY_STRING_FIELD(portalname);
1800         COPY_SCALAR_FIELD(options);
1801         COPY_NODE_FIELD(query);
1802
1803         return newnode;
1804 }
1805
1806 static ClosePortalStmt *
1807 _copyClosePortalStmt(ClosePortalStmt *from)
1808 {
1809         ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1810
1811         COPY_STRING_FIELD(portalname);
1812
1813         return newnode;
1814 }
1815
1816 static ClusterStmt *
1817 _copyClusterStmt(ClusterStmt *from)
1818 {
1819         ClusterStmt *newnode = makeNode(ClusterStmt);
1820
1821         COPY_NODE_FIELD(relation);
1822         COPY_STRING_FIELD(indexname);
1823
1824         return newnode;
1825 }
1826
1827 static CopyStmt *
1828 _copyCopyStmt(CopyStmt *from)
1829 {
1830         CopyStmt   *newnode = makeNode(CopyStmt);
1831
1832         COPY_NODE_FIELD(relation);
1833         COPY_NODE_FIELD(attlist);
1834         COPY_SCALAR_FIELD(is_from);
1835         COPY_STRING_FIELD(filename);
1836         COPY_NODE_FIELD(options);
1837
1838         return newnode;
1839 }
1840
1841 static CreateStmt *
1842 _copyCreateStmt(CreateStmt *from)
1843 {
1844         CreateStmt *newnode = makeNode(CreateStmt);
1845
1846         COPY_NODE_FIELD(relation);
1847         COPY_NODE_FIELD(tableElts);
1848         COPY_NODE_FIELD(inhRelations);
1849         COPY_NODE_FIELD(constraints);
1850         COPY_SCALAR_FIELD(hasoids);
1851         COPY_SCALAR_FIELD(oncommit);
1852         COPY_STRING_FIELD(tablespacename);
1853
1854         return newnode;
1855 }
1856
1857 static InhRelation *
1858 _copyInhRelation(InhRelation *from)
1859 {
1860         InhRelation *newnode = makeNode(InhRelation);
1861
1862         COPY_NODE_FIELD(relation);
1863         COPY_SCALAR_FIELD(including_defaults);
1864
1865         return newnode;
1866 }
1867
1868 static DefineStmt *
1869 _copyDefineStmt(DefineStmt *from)
1870 {
1871         DefineStmt *newnode = makeNode(DefineStmt);
1872
1873         COPY_SCALAR_FIELD(kind);
1874         COPY_NODE_FIELD(defnames);
1875         COPY_NODE_FIELD(definition);
1876
1877         return newnode;
1878 }
1879
1880 static DropStmt *
1881 _copyDropStmt(DropStmt *from)
1882 {
1883         DropStmt   *newnode = makeNode(DropStmt);
1884
1885         COPY_NODE_FIELD(objects);
1886         COPY_SCALAR_FIELD(removeType);
1887         COPY_SCALAR_FIELD(behavior);
1888
1889         return newnode;
1890 }
1891
1892 static TruncateStmt *
1893 _copyTruncateStmt(TruncateStmt *from)
1894 {
1895         TruncateStmt *newnode = makeNode(TruncateStmt);
1896
1897         COPY_NODE_FIELD(relations);
1898
1899         return newnode;
1900 }
1901
1902 static CommentStmt *
1903 _copyCommentStmt(CommentStmt *from)
1904 {
1905         CommentStmt *newnode = makeNode(CommentStmt);
1906
1907         COPY_SCALAR_FIELD(objtype);
1908         COPY_NODE_FIELD(objname);
1909         COPY_NODE_FIELD(objargs);
1910         COPY_STRING_FIELD(comment);
1911
1912         return newnode;
1913 }
1914
1915 static FetchStmt *
1916 _copyFetchStmt(FetchStmt *from)
1917 {
1918         FetchStmt  *newnode = makeNode(FetchStmt);
1919
1920         COPY_SCALAR_FIELD(direction);
1921         COPY_SCALAR_FIELD(howMany);
1922         COPY_STRING_FIELD(portalname);
1923         COPY_SCALAR_FIELD(ismove);
1924
1925         return newnode;
1926 }
1927
1928 static IndexStmt *
1929 _copyIndexStmt(IndexStmt *from)
1930 {
1931         IndexStmt  *newnode = makeNode(IndexStmt);
1932
1933         COPY_STRING_FIELD(idxname);
1934         COPY_NODE_FIELD(relation);
1935         COPY_STRING_FIELD(accessMethod);
1936         COPY_STRING_FIELD(tableSpace);
1937         COPY_NODE_FIELD(indexParams);
1938         COPY_NODE_FIELD(whereClause);
1939         COPY_NODE_FIELD(rangetable);
1940         COPY_SCALAR_FIELD(unique);
1941         COPY_SCALAR_FIELD(primary);
1942         COPY_SCALAR_FIELD(isconstraint);
1943
1944         return newnode;
1945 }
1946
1947 static CreateFunctionStmt *
1948 _copyCreateFunctionStmt(CreateFunctionStmt *from)
1949 {
1950         CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
1951
1952         COPY_SCALAR_FIELD(replace);
1953         COPY_NODE_FIELD(funcname);
1954         COPY_NODE_FIELD(parameters);
1955         COPY_NODE_FIELD(returnType);
1956         COPY_NODE_FIELD(options);
1957         COPY_NODE_FIELD(withClause);
1958
1959         return newnode;
1960 }
1961
1962 static FunctionParameter *
1963 _copyFunctionParameter(FunctionParameter *from)
1964 {
1965         FunctionParameter *newnode = makeNode(FunctionParameter);
1966
1967         COPY_STRING_FIELD(name);
1968         COPY_NODE_FIELD(argType);
1969         COPY_SCALAR_FIELD(mode);
1970
1971         return newnode;
1972 }
1973
1974 static AlterFunctionStmt *
1975 _copyAlterFunctionStmt(AlterFunctionStmt *from)
1976 {
1977         AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);
1978
1979         COPY_NODE_FIELD(func);
1980         COPY_NODE_FIELD(actions);
1981
1982         return newnode;
1983 }
1984
1985 static RemoveAggrStmt *
1986 _copyRemoveAggrStmt(RemoveAggrStmt *from)
1987 {
1988         RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1989
1990         COPY_NODE_FIELD(aggname);
1991         COPY_NODE_FIELD(aggtype);
1992         COPY_SCALAR_FIELD(behavior);
1993
1994         return newnode;
1995 }
1996
1997 static RemoveFuncStmt *
1998 _copyRemoveFuncStmt(RemoveFuncStmt *from)
1999 {
2000         RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2001
2002         COPY_NODE_FIELD(funcname);
2003         COPY_NODE_FIELD(args);
2004         COPY_SCALAR_FIELD(behavior);
2005
2006         return newnode;
2007 }
2008
2009 static RemoveOperStmt *
2010 _copyRemoveOperStmt(RemoveOperStmt *from)
2011 {
2012         RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
2013
2014         COPY_NODE_FIELD(opname);
2015         COPY_NODE_FIELD(args);
2016         COPY_SCALAR_FIELD(behavior);
2017
2018         return newnode;
2019 }
2020
2021 static RemoveOpClassStmt *
2022 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
2023 {
2024         RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
2025
2026         COPY_NODE_FIELD(opclassname);
2027         COPY_STRING_FIELD(amname);
2028         COPY_SCALAR_FIELD(behavior);
2029
2030         return newnode;
2031 }
2032
2033 static RenameStmt *
2034 _copyRenameStmt(RenameStmt *from)
2035 {
2036         RenameStmt *newnode = makeNode(RenameStmt);
2037
2038         COPY_NODE_FIELD(relation);
2039         COPY_NODE_FIELD(object);
2040         COPY_NODE_FIELD(objarg);
2041         COPY_STRING_FIELD(subname);
2042         COPY_STRING_FIELD(newname);
2043         COPY_SCALAR_FIELD(renameType);
2044
2045         return newnode;
2046 }
2047
2048 static AlterOwnerStmt *
2049 _copyAlterOwnerStmt(AlterOwnerStmt *from)
2050 {
2051         AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);
2052
2053         COPY_NODE_FIELD(relation);
2054         COPY_NODE_FIELD(object);
2055         COPY_NODE_FIELD(objarg);
2056         COPY_STRING_FIELD(addname);
2057         COPY_STRING_FIELD(newowner);
2058         COPY_SCALAR_FIELD(objectType);
2059
2060         return newnode;
2061 }
2062
2063 static RuleStmt *
2064 _copyRuleStmt(RuleStmt *from)
2065 {
2066         RuleStmt   *newnode = makeNode(RuleStmt);
2067
2068         COPY_NODE_FIELD(relation);
2069         COPY_STRING_FIELD(rulename);
2070         COPY_NODE_FIELD(whereClause);
2071         COPY_SCALAR_FIELD(event);
2072         COPY_SCALAR_FIELD(instead);
2073         COPY_NODE_FIELD(actions);
2074         COPY_SCALAR_FIELD(replace);
2075
2076         return newnode;
2077 }
2078
2079 static NotifyStmt *
2080 _copyNotifyStmt(NotifyStmt *from)
2081 {
2082         NotifyStmt *newnode = makeNode(NotifyStmt);
2083
2084         COPY_NODE_FIELD(relation);
2085
2086         return newnode;
2087 }
2088
2089 static ListenStmt *
2090 _copyListenStmt(ListenStmt *from)
2091 {
2092         ListenStmt *newnode = makeNode(ListenStmt);
2093
2094         COPY_NODE_FIELD(relation);
2095
2096         return newnode;
2097 }
2098
2099 static UnlistenStmt *
2100 _copyUnlistenStmt(UnlistenStmt *from)
2101 {
2102         UnlistenStmt *newnode = makeNode(UnlistenStmt);
2103
2104         COPY_NODE_FIELD(relation);
2105
2106         return newnode;
2107 }
2108
2109 static TransactionStmt *
2110 _copyTransactionStmt(TransactionStmt *from)
2111 {
2112         TransactionStmt *newnode = makeNode(TransactionStmt);
2113
2114         COPY_SCALAR_FIELD(kind);
2115         COPY_NODE_FIELD(options);
2116         COPY_STRING_FIELD(gid);
2117
2118         return newnode;
2119 }
2120
2121 static CompositeTypeStmt *
2122 _copyCompositeTypeStmt(CompositeTypeStmt *from)
2123 {
2124         CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
2125
2126         COPY_NODE_FIELD(typevar);
2127         COPY_NODE_FIELD(coldeflist);
2128
2129         return newnode;
2130 }
2131
2132 static ViewStmt *
2133 _copyViewStmt(ViewStmt *from)
2134 {
2135         ViewStmt   *newnode = makeNode(ViewStmt);
2136
2137         COPY_NODE_FIELD(view);
2138         COPY_NODE_FIELD(aliases);
2139         COPY_NODE_FIELD(query);
2140         COPY_SCALAR_FIELD(replace);
2141
2142         return newnode;
2143 }
2144
2145 static LoadStmt *
2146 _copyLoadStmt(LoadStmt *from)
2147 {
2148         LoadStmt   *newnode = makeNode(LoadStmt);
2149
2150         COPY_STRING_FIELD(filename);
2151
2152         return newnode;
2153 }
2154
2155 static CreateDomainStmt *
2156 _copyCreateDomainStmt(CreateDomainStmt *from)
2157 {
2158         CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2159
2160         COPY_NODE_FIELD(domainname);
2161         COPY_NODE_FIELD(typename);
2162         COPY_NODE_FIELD(constraints);
2163
2164         return newnode;
2165 }
2166
2167 static CreateOpClassStmt *
2168 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2169 {
2170         CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2171
2172         COPY_NODE_FIELD(opclassname);
2173         COPY_STRING_FIELD(amname);
2174         COPY_NODE_FIELD(datatype);
2175         COPY_NODE_FIELD(items);
2176         COPY_SCALAR_FIELD(isDefault);
2177
2178         return newnode;
2179 }
2180
2181 static CreateOpClassItem *
2182 _copyCreateOpClassItem(CreateOpClassItem *from)
2183 {
2184         CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2185
2186         COPY_SCALAR_FIELD(itemtype);
2187         COPY_NODE_FIELD(name);
2188         COPY_NODE_FIELD(args);
2189         COPY_SCALAR_FIELD(number);
2190         COPY_SCALAR_FIELD(recheck);
2191         COPY_NODE_FIELD(storedtype);
2192
2193         return newnode;
2194 }
2195
2196 static CreatedbStmt *
2197 _copyCreatedbStmt(CreatedbStmt *from)
2198 {
2199         CreatedbStmt *newnode = makeNode(CreatedbStmt);
2200
2201         COPY_STRING_FIELD(dbname);
2202         COPY_NODE_FIELD(options);
2203
2204         return newnode;
2205 }
2206
2207 static AlterDatabaseSetStmt *
2208 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2209 {
2210         AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2211
2212         COPY_STRING_FIELD(dbname);
2213         COPY_STRING_FIELD(variable);
2214         COPY_NODE_FIELD(value);
2215
2216         return newnode;
2217 }
2218
2219 static DropdbStmt *
2220 _copyDropdbStmt(DropdbStmt *from)
2221 {
2222         DropdbStmt *newnode = makeNode(DropdbStmt);
2223
2224         COPY_STRING_FIELD(dbname);
2225
2226         return newnode;
2227 }
2228
2229 static VacuumStmt *
2230 _copyVacuumStmt(VacuumStmt *from)
2231 {
2232         VacuumStmt *newnode = makeNode(VacuumStmt);
2233
2234         COPY_SCALAR_FIELD(vacuum);
2235         COPY_SCALAR_FIELD(full);
2236         COPY_SCALAR_FIELD(analyze);
2237         COPY_SCALAR_FIELD(freeze);
2238         COPY_SCALAR_FIELD(verbose);
2239         COPY_NODE_FIELD(relation);
2240         COPY_NODE_FIELD(va_cols);
2241
2242         return newnode;
2243 }
2244
2245 static ExplainStmt *
2246 _copyExplainStmt(ExplainStmt *from)
2247 {
2248         ExplainStmt *newnode = makeNode(ExplainStmt);
2249
2250         COPY_NODE_FIELD(query);
2251         COPY_SCALAR_FIELD(verbose);
2252         COPY_SCALAR_FIELD(analyze);
2253
2254         return newnode;
2255 }
2256
2257 static CreateSeqStmt *
2258 _copyCreateSeqStmt(CreateSeqStmt *from)
2259 {
2260         CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2261
2262         COPY_NODE_FIELD(sequence);
2263         COPY_NODE_FIELD(options);
2264
2265         return newnode;
2266 }
2267
2268 static AlterSeqStmt *
2269 _copyAlterSeqStmt(AlterSeqStmt *from)
2270 {
2271         AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
2272
2273         COPY_NODE_FIELD(sequence);
2274         COPY_NODE_FIELD(options);
2275
2276         return newnode;
2277 }
2278
2279 static VariableSetStmt *
2280 _copyVariableSetStmt(VariableSetStmt *from)
2281 {
2282         VariableSetStmt *newnode = makeNode(VariableSetStmt);
2283
2284         COPY_STRING_FIELD(name);
2285         COPY_NODE_FIELD(args);
2286         COPY_SCALAR_FIELD(is_local);
2287
2288         return newnode;
2289 }
2290
2291 static VariableShowStmt *
2292 _copyVariableShowStmt(VariableShowStmt *from)
2293 {
2294         VariableShowStmt *newnode = makeNode(VariableShowStmt);
2295
2296         COPY_STRING_FIELD(name);
2297
2298         return newnode;
2299 }
2300
2301 static VariableResetStmt *
2302 _copyVariableResetStmt(VariableResetStmt *from)
2303 {
2304         VariableResetStmt *newnode = makeNode(VariableResetStmt);
2305
2306         COPY_STRING_FIELD(name);
2307
2308         return newnode;
2309 }
2310
2311 static CreateTableSpaceStmt *
2312 _copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
2313 {
2314         CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
2315
2316         COPY_STRING_FIELD(tablespacename);
2317         COPY_STRING_FIELD(owner);
2318         COPY_STRING_FIELD(location);
2319
2320         return newnode;
2321 }
2322
2323 static DropTableSpaceStmt *
2324 _copyDropTableSpaceStmt(DropTableSpaceStmt *from)
2325 {
2326         DropTableSpaceStmt *newnode = makeNode(DropTableSpaceStmt);
2327
2328         COPY_STRING_FIELD(tablespacename);
2329
2330         return newnode;
2331 }
2332
2333 static CreateTrigStmt *
2334 _copyCreateTrigStmt(CreateTrigStmt *from)
2335 {
2336         CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2337
2338         COPY_STRING_FIELD(trigname);
2339         COPY_NODE_FIELD(relation);
2340         COPY_NODE_FIELD(funcname);
2341         COPY_NODE_FIELD(args);
2342         COPY_SCALAR_FIELD(before);
2343         COPY_SCALAR_FIELD(row);
2344         strcpy(newnode->actions, from->actions);        /* in-line string field */
2345         COPY_SCALAR_FIELD(isconstraint);
2346         COPY_SCALAR_FIELD(deferrable);
2347         COPY_SCALAR_FIELD(initdeferred);
2348         COPY_NODE_FIELD(constrrel);
2349
2350         return newnode;
2351 }
2352
2353 static DropPropertyStmt *
2354 _copyDropPropertyStmt(DropPropertyStmt *from)
2355 {
2356         DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2357
2358         COPY_NODE_FIELD(relation);
2359         COPY_STRING_FIELD(property);
2360         COPY_SCALAR_FIELD(removeType);
2361         COPY_SCALAR_FIELD(behavior);
2362
2363         return newnode;
2364 }
2365
2366 static CreatePLangStmt *
2367 _copyCreatePLangStmt(CreatePLangStmt *from)
2368 {
2369         CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2370
2371         COPY_STRING_FIELD(plname);
2372         COPY_NODE_FIELD(plhandler);
2373         COPY_NODE_FIELD(plvalidator);
2374         COPY_SCALAR_FIELD(pltrusted);
2375
2376         return newnode;
2377 }
2378
2379 static DropPLangStmt *
2380 _copyDropPLangStmt(DropPLangStmt *from)
2381 {
2382         DropPLangStmt *newnode = makeNode(DropPLangStmt);
2383
2384         COPY_STRING_FIELD(plname);
2385         COPY_SCALAR_FIELD(behavior);
2386
2387         return newnode;
2388 }
2389
2390 static CreateRoleStmt *
2391 _copyCreateRoleStmt(CreateRoleStmt *from)
2392 {
2393         CreateRoleStmt *newnode = makeNode(CreateRoleStmt);
2394
2395         COPY_STRING_FIELD(role);
2396         COPY_NODE_FIELD(options);
2397
2398         return newnode;
2399 }
2400
2401 static AlterRoleStmt *
2402 _copyAlterRoleStmt(AlterRoleStmt *from)
2403 {
2404         AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
2405
2406         COPY_STRING_FIELD(role);
2407         COPY_NODE_FIELD(options);
2408         COPY_SCALAR_FIELD(action);
2409
2410         return newnode;
2411 }
2412
2413 static AlterRoleSetStmt *
2414 _copyAlterRoleSetStmt(AlterRoleSetStmt *from)
2415 {
2416         AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
2417
2418         COPY_STRING_FIELD(role);
2419         COPY_STRING_FIELD(variable);
2420         COPY_NODE_FIELD(value);
2421
2422         return newnode;
2423 }
2424
2425 static DropRoleStmt *
2426 _copyDropRoleStmt(DropRoleStmt *from)
2427 {
2428         DropRoleStmt *newnode = makeNode(DropRoleStmt);
2429
2430         COPY_NODE_FIELD(roles);
2431
2432         return newnode;
2433 }
2434
2435 static LockStmt *
2436 _copyLockStmt(LockStmt *from)
2437 {
2438         LockStmt   *newnode = makeNode(LockStmt);
2439
2440         COPY_NODE_FIELD(relations);
2441         COPY_SCALAR_FIELD(mode);
2442         COPY_SCALAR_FIELD(nowait);
2443
2444         return newnode;
2445 }
2446
2447 static ConstraintsSetStmt *
2448 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2449 {
2450         ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2451
2452         COPY_NODE_FIELD(constraints);
2453         COPY_SCALAR_FIELD(deferred);
2454
2455         return newnode;
2456 }
2457
2458 static ReindexStmt *
2459 _copyReindexStmt(ReindexStmt *from)
2460 {
2461         ReindexStmt *newnode = makeNode(ReindexStmt);
2462
2463         COPY_SCALAR_FIELD(kind);
2464         COPY_NODE_FIELD(relation);
2465         COPY_STRING_FIELD(name);
2466         COPY_SCALAR_FIELD(do_system);
2467         COPY_SCALAR_FIELD(do_user);
2468
2469         return newnode;
2470 }
2471
2472 static CreateSchemaStmt *
2473 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2474 {
2475         CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2476
2477         COPY_STRING_FIELD(schemaname);
2478         COPY_STRING_FIELD(authid);
2479         COPY_NODE_FIELD(schemaElts);
2480
2481         return newnode;
2482 }
2483
2484 static CreateConversionStmt *
2485 _copyCreateConversionStmt(CreateConversionStmt *from)
2486 {
2487         CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2488
2489         COPY_NODE_FIELD(conversion_name);
2490         COPY_STRING_FIELD(for_encoding_name);
2491         COPY_STRING_FIELD(to_encoding_name);
2492         COPY_NODE_FIELD(func_name);
2493         COPY_SCALAR_FIELD(def);
2494
2495         return newnode;
2496 }
2497
2498 static CreateCastStmt *
2499 _copyCreateCastStmt(CreateCastStmt *from)
2500 {
2501         CreateCastStmt *newnode = makeNode(CreateCastStmt);
2502
2503         COPY_NODE_FIELD(sourcetype);
2504         COPY_NODE_FIELD(targettype);
2505         COPY_NODE_FIELD(func);
2506         COPY_SCALAR_FIELD(context);
2507
2508         return newnode;
2509 }
2510
2511 static DropCastStmt *
2512 _copyDropCastStmt(DropCastStmt *from)
2513 {
2514         DropCastStmt *newnode = makeNode(DropCastStmt);
2515
2516         COPY_NODE_FIELD(sourcetype);
2517         COPY_NODE_FIELD(targettype);
2518         COPY_SCALAR_FIELD(behavior);
2519
2520         return newnode;
2521 }
2522
2523 static PrepareStmt *
2524 _copyPrepareStmt(PrepareStmt *from)
2525 {
2526         PrepareStmt *newnode = makeNode(PrepareStmt);
2527
2528         COPY_STRING_FIELD(name);
2529         COPY_NODE_FIELD(argtypes);
2530         COPY_NODE_FIELD(argtype_oids);
2531         COPY_NODE_FIELD(query);
2532
2533         return newnode;
2534 }
2535
2536 static ExecuteStmt *
2537 _copyExecuteStmt(ExecuteStmt *from)
2538 {
2539         ExecuteStmt *newnode = makeNode(ExecuteStmt);
2540
2541         COPY_STRING_FIELD(name);
2542         COPY_NODE_FIELD(into);
2543         COPY_NODE_FIELD(params);
2544
2545         return newnode;
2546 }
2547
2548 static DeallocateStmt *
2549 _copyDeallocateStmt(DeallocateStmt *from)
2550 {
2551         DeallocateStmt *newnode = makeNode(DeallocateStmt);
2552
2553         COPY_STRING_FIELD(name);
2554
2555         return newnode;
2556 }
2557
2558
2559 /* ****************************************************************
2560  *                                      pg_list.h copy functions
2561  * ****************************************************************
2562  */
2563
2564 /*
2565  * Perform a deep copy of the specified list, using copyObject(). The
2566  * list MUST be of type T_List; T_IntList and T_OidList nodes don't
2567  * need deep copies, so they should be copied via list_copy()
2568  */
2569 #define COPY_NODE_CELL(new, old)                                        \
2570         (new) = (ListCell *) palloc(sizeof(ListCell));  \
2571         lfirst(new) = copyObject(lfirst(old));
2572
2573 static List *
2574 _copyList(List *from)
2575 {
2576         List       *new;
2577         ListCell   *curr_old;
2578         ListCell   *prev_new;
2579
2580         Assert(list_length(from) >= 1);
2581
2582         new = makeNode(List);
2583         new->length = from->length;
2584
2585         COPY_NODE_CELL(new->head, from->head);
2586         prev_new = new->head;
2587         curr_old = lnext(from->head);
2588
2589         while (curr_old)
2590         {
2591                 COPY_NODE_CELL(prev_new->next, curr_old);
2592                 prev_new = prev_new->next;
2593                 curr_old = curr_old->next;
2594         }
2595         prev_new->next = NULL;
2596         new->tail = prev_new;
2597
2598         return new;
2599 }
2600
2601 /* ****************************************************************
2602  *                                      value.h copy functions
2603  * ****************************************************************
2604  */
2605 static Value *
2606 _copyValue(Value *from)
2607 {
2608         Value      *newnode = makeNode(Value);
2609
2610         /* See also _copyAConst when changing this code! */
2611
2612         COPY_SCALAR_FIELD(type);
2613         switch (from->type)
2614         {
2615                 case T_Integer:
2616                         COPY_SCALAR_FIELD(val.ival);
2617                         break;
2618                 case T_Float:
2619                 case T_String:
2620                 case T_BitString:
2621                         COPY_STRING_FIELD(val.str);
2622                         break;
2623                 case T_Null:
2624                         /* nothing to do */
2625                         break;
2626                 default:
2627                         elog(ERROR, "unrecognized node type: %d",
2628                                  (int) from->type);
2629                         break;
2630         }
2631         return newnode;
2632 }
2633
2634 /*
2635  * copyObject
2636  *
2637  * Create a copy of a Node tree or list.  This is a "deep" copy: all
2638  * substructure is copied too, recursively.
2639  */
2640 void *
2641 copyObject(void *from)
2642 {
2643         void       *retval;
2644
2645         if (from == NULL)
2646                 return NULL;
2647
2648         switch (nodeTag(from))
2649         {
2650                         /*
2651                          * PLAN NODES
2652                          */
2653                 case T_Plan:
2654                         retval = _copyPlan(from);
2655                         break;
2656                 case T_Result:
2657                         retval = _copyResult(from);
2658                         break;
2659                 case T_Append:
2660                         retval = _copyAppend(from);
2661                         break;
2662                 case T_BitmapAnd:
2663                         retval = _copyBitmapAnd(from);
2664                         break;
2665                 case T_BitmapOr:
2666                         retval = _copyBitmapOr(from);
2667                         break;
2668                 case T_Scan:
2669                         retval = _copyScan(from);
2670                         break;
2671                 case T_SeqScan:
2672                         retval = _copySeqScan(from);
2673                         break;
2674                 case T_IndexScan:
2675                         retval = _copyIndexScan(from);
2676                         break;
2677                 case T_BitmapIndexScan:
2678                         retval = _copyBitmapIndexScan(from);
2679                         break;
2680                 case T_BitmapHeapScan:
2681                         retval = _copyBitmapHeapScan(from);
2682                         break;
2683                 case T_TidScan:
2684                         retval = _copyTidScan(from);
2685                         break;
2686                 case T_SubqueryScan:
2687                         retval = _copySubqueryScan(from);
2688                         break;
2689                 case T_FunctionScan:
2690                         retval = _copyFunctionScan(from);
2691                         break;
2692                 case T_Join:
2693                         retval = _copyJoin(from);
2694                         break;
2695                 case T_NestLoop:
2696                         retval = _copyNestLoop(from);
2697                         break;
2698                 case T_MergeJoin:
2699                         retval = _copyMergeJoin(from);
2700                         break;
2701                 case T_HashJoin:
2702                         retval = _copyHashJoin(from);
2703                         break;
2704                 case T_Material:
2705                         retval = _copyMaterial(from);
2706                         break;
2707                 case T_Sort:
2708                         retval = _copySort(from);
2709                         break;
2710                 case T_Group:
2711                         retval = _copyGroup(from);
2712                         break;
2713                 case T_Agg:
2714                         retval = _copyAgg(from);
2715                         break;
2716                 case T_Unique:
2717                         retval = _copyUnique(from);
2718                         break;
2719                 case T_Hash:
2720                         retval = _copyHash(from);
2721                         break;
2722                 case T_SetOp:
2723                         retval = _copySetOp(from);
2724                         break;
2725                 case T_Limit:
2726                         retval = _copyLimit(from);
2727                         break;
2728
2729                         /*
2730                          * PRIMITIVE NODES
2731                          */
2732                 case T_Alias:
2733                         retval = _copyAlias(from);
2734                         break;
2735                 case T_RangeVar:
2736                         retval = _copyRangeVar(from);
2737                         break;
2738                 case T_Var:
2739                         retval = _copyVar(from);
2740                         break;
2741                 case T_Const:
2742                         retval = _copyConst(from);
2743                         break;
2744                 case T_Param:
2745                         retval = _copyParam(from);
2746                         break;
2747                 case T_Aggref:
2748                         retval = _copyAggref(from);
2749                         break;
2750                 case T_ArrayRef:
2751                         retval = _copyArrayRef(from);
2752                         break;
2753                 case T_FuncExpr:
2754                         retval = _copyFuncExpr(from);
2755                         break;
2756                 case T_OpExpr:
2757                         retval = _copyOpExpr(from);
2758                         break;
2759                 case T_DistinctExpr:
2760                         retval = _copyDistinctExpr(from);
2761                         break;
2762                 case T_ScalarArrayOpExpr:
2763                         retval = _copyScalarArrayOpExpr(from);
2764                         break;
2765                 case T_BoolExpr:
2766                         retval = _copyBoolExpr(from);
2767                         break;
2768                 case T_SubLink:
2769                         retval = _copySubLink(from);
2770                         break;
2771                 case T_SubPlan:
2772                         retval = _copySubPlan(from);
2773                         break;
2774                 case T_FieldSelect:
2775                         retval = _copyFieldSelect(from);
2776                         break;
2777                 case T_FieldStore:
2778                         retval = _copyFieldStore(from);
2779                         break;
2780                 case T_RelabelType:
2781                         retval = _copyRelabelType(from);
2782                         break;
2783                 case T_ConvertRowtypeExpr:
2784                         retval = _copyConvertRowtypeExpr(from);
2785                         break;
2786                 case T_CaseExpr:
2787                         retval = _copyCaseExpr(from);
2788                         break;
2789                 case T_CaseWhen:
2790                         retval = _copyCaseWhen(from);
2791                         break;
2792                 case T_CaseTestExpr:
2793                         retval = _copyCaseTestExpr(from);
2794                         break;
2795                 case T_ArrayExpr:
2796                         retval = _copyArrayExpr(from);
2797                         break;
2798                 case T_RowExpr:
2799                         retval = _copyRowExpr(from);
2800                         break;
2801                 case T_CoalesceExpr:
2802                         retval = _copyCoalesceExpr(from);
2803                         break;
2804                 case T_MinMaxExpr:
2805                         retval = _copyMinMaxExpr(from);
2806                         break;
2807                 case T_NullIfExpr:
2808                         retval = _copyNullIfExpr(from);
2809                         break;
2810                 case T_NullTest:
2811                         retval = _copyNullTest(from);
2812                         break;
2813                 case T_BooleanTest:
2814                         retval = _copyBooleanTest(from);
2815                         break;
2816                 case T_CoerceToDomain:
2817                         retval = _copyCoerceToDomain(from);
2818                         break;
2819                 case T_CoerceToDomainValue:
2820                         retval = _copyCoerceToDomainValue(from);
2821                         break;
2822                 case T_SetToDefault:
2823                         retval = _copySetToDefault(from);
2824                         break;
2825                 case T_TargetEntry:
2826                         retval = _copyTargetEntry(from);
2827                         break;
2828                 case T_RangeTblRef:
2829                         retval = _copyRangeTblRef(from);
2830                         break;
2831                 case T_JoinExpr:
2832                         retval = _copyJoinExpr(from);
2833                         break;
2834                 case T_FromExpr:
2835                         retval = _copyFromExpr(from);
2836                         break;
2837
2838                         /*
2839                          * RELATION NODES
2840                          */
2841                 case T_PathKeyItem:
2842                         retval = _copyPathKeyItem(from);
2843                         break;
2844                 case T_RestrictInfo:
2845                         retval = _copyRestrictInfo(from);
2846                         break;
2847                 case T_InClauseInfo:
2848                         retval = _copyInClauseInfo(from);
2849                         break;
2850
2851                         /*
2852                          * VALUE NODES
2853                          */
2854                 case T_Integer:
2855                 case T_Float:
2856                 case T_String:
2857                 case T_BitString:
2858                 case T_Null:
2859                         retval = _copyValue(from);
2860                         break;
2861
2862                         /*
2863                          * LIST NODES
2864                          */
2865                 case T_List:
2866                         retval = _copyList(from);
2867                         break;
2868
2869                         /*
2870                          * Lists of integers and OIDs don't need to be deep-copied, so
2871                          * we perform a shallow copy via list_copy()
2872                          */
2873                 case T_IntList:
2874                 case T_OidList:
2875                         retval = list_copy(from);
2876                         break;
2877
2878                         /*
2879                          * PARSE NODES
2880                          */
2881                 case T_Query:
2882                         retval = _copyQuery(from);
2883                         break;
2884                 case T_InsertStmt:
2885                         retval = _copyInsertStmt(from);
2886                         break;
2887                 case T_DeleteStmt:
2888                         retval = _copyDeleteStmt(from);
2889                         break;
2890                 case T_UpdateStmt:
2891                         retval = _copyUpdateStmt(from);
2892                         break;
2893                 case T_SelectStmt:
2894                         retval = _copySelectStmt(from);
2895                         break;
2896                 case T_SetOperationStmt:
2897                         retval = _copySetOperationStmt(from);
2898                         break;
2899                 case T_AlterTableStmt:
2900                         retval = _copyAlterTableStmt(from);
2901                         break;
2902                 case T_AlterTableCmd:
2903                         retval = _copyAlterTableCmd(from);
2904                         break;
2905                 case T_AlterDomainStmt:
2906                         retval = _copyAlterDomainStmt(from);
2907                         break;
2908                 case T_GrantStmt:
2909                         retval = _copyGrantStmt(from);
2910                         break;
2911                 case T_GrantRoleStmt:
2912                         retval = _copyGrantRoleStmt(from);
2913                         break;
2914                 case T_DeclareCursorStmt:
2915                         retval = _copyDeclareCursorStmt(from);
2916                         break;
2917                 case T_ClosePortalStmt:
2918                         retval = _copyClosePortalStmt(from);
2919                         break;
2920                 case T_ClusterStmt:
2921                         retval = _copyClusterStmt(from);
2922                         break;
2923                 case T_CopyStmt:
2924                         retval = _copyCopyStmt(from);
2925                         break;
2926                 case T_CreateStmt:
2927                         retval = _copyCreateStmt(from);
2928                         break;
2929                 case T_InhRelation:
2930                         retval = _copyInhRelation(from);
2931                         break;
2932                 case T_DefineStmt:
2933                         retval = _copyDefineStmt(from);
2934                         break;
2935                 case T_DropStmt:
2936                         retval = _copyDropStmt(from);
2937                         break;
2938                 case T_TruncateStmt:
2939                         retval = _copyTruncateStmt(from);
2940                         break;
2941                 case T_CommentStmt:
2942                         retval = _copyCommentStmt(from);
2943                         break;
2944                 case T_FetchStmt:
2945                         retval = _copyFetchStmt(from);
2946                         break;
2947                 case T_IndexStmt:
2948                         retval = _copyIndexStmt(from);
2949                         break;
2950                 case T_CreateFunctionStmt:
2951                         retval = _copyCreateFunctionStmt(from);
2952                         break;
2953                 case T_FunctionParameter:
2954                         retval = _copyFunctionParameter(from);
2955                         break;
2956                 case T_AlterFunctionStmt:
2957                         retval = _copyAlterFunctionStmt(from);
2958                         break;
2959                 case T_RemoveAggrStmt:
2960                         retval = _copyRemoveAggrStmt(from);
2961                         break;
2962                 case T_RemoveFuncStmt:
2963                         retval = _copyRemoveFuncStmt(from);
2964                         break;
2965                 case T_RemoveOperStmt:
2966                         retval = _copyRemoveOperStmt(from);
2967                         break;
2968                 case T_RemoveOpClassStmt:
2969                         retval = _copyRemoveOpClassStmt(from);
2970                         break;
2971                 case T_RenameStmt:
2972                         retval = _copyRenameStmt(from);
2973                         break;
2974                 case T_AlterOwnerStmt:
2975                         retval = _copyAlterOwnerStmt(from);
2976                         break;
2977                 case T_RuleStmt:
2978                         retval = _copyRuleStmt(from);
2979                         break;
2980                 case T_NotifyStmt:
2981                         retval = _copyNotifyStmt(from);
2982                         break;
2983                 case T_ListenStmt:
2984                         retval = _copyListenStmt(from);
2985                         break;
2986                 case T_UnlistenStmt:
2987                         retval = _copyUnlistenStmt(from);
2988                         break;
2989                 case T_TransactionStmt:
2990                         retval = _copyTransactionStmt(from);
2991                         break;
2992                 case T_CompositeTypeStmt:
2993                         retval = _copyCompositeTypeStmt(from);
2994                         break;
2995                 case T_ViewStmt:
2996                         retval = _copyViewStmt(from);
2997                         break;
2998                 case T_LoadStmt:
2999                         retval = _copyLoadStmt(from);
3000                         break;
3001                 case T_CreateDomainStmt:
3002                         retval = _copyCreateDomainStmt(from);
3003                         break;
3004                 case T_CreateOpClassStmt:
3005                         retval = _copyCreateOpClassStmt(from);
3006                         break;
3007                 case T_CreateOpClassItem:
3008                         retval = _copyCreateOpClassItem(from);
3009                         break;
3010                 case T_CreatedbStmt:
3011                         retval = _copyCreatedbStmt(from);
3012                         break;
3013                 case T_AlterDatabaseSetStmt:
3014                         retval = _copyAlterDatabaseSetStmt(from);
3015                         break;
3016                 case T_DropdbStmt:
3017                         retval = _copyDropdbStmt(from);
3018                         break;
3019                 case T_VacuumStmt:
3020                         retval = _copyVacuumStmt(from);
3021                         break;
3022                 case T_ExplainStmt:
3023                         retval = _copyExplainStmt(from);
3024                         break;
3025                 case T_CreateSeqStmt:
3026                         retval = _copyCreateSeqStmt(from);
3027                         break;
3028                 case T_AlterSeqStmt:
3029                         retval = _copyAlterSeqStmt(from);
3030                         break;
3031                 case T_VariableSetStmt:
3032                         retval = _copyVariableSetStmt(from);
3033                         break;
3034                 case T_VariableShowStmt:
3035                         retval = _copyVariableShowStmt(from);
3036                         break;
3037                 case T_VariableResetStmt:
3038                         retval = _copyVariableResetStmt(from);
3039                         break;
3040                 case T_CreateTableSpaceStmt:
3041                         retval = _copyCreateTableSpaceStmt(from);
3042                         break;
3043                 case T_DropTableSpaceStmt:
3044                         retval = _copyDropTableSpaceStmt(from);
3045                         break;
3046                 case T_CreateTrigStmt:
3047                         retval = _copyCreateTrigStmt(from);
3048                         break;
3049                 case T_DropPropertyStmt:
3050                         retval = _copyDropPropertyStmt(from);
3051                         break;
3052                 case T_CreatePLangStmt:
3053                         retval = _copyCreatePLangStmt(from);
3054                         break;
3055                 case T_DropPLangStmt:
3056                         retval = _copyDropPLangStmt(from);
3057                         break;
3058                 case T_CreateRoleStmt:
3059                         retval = _copyCreateRoleStmt(from);
3060                         break;
3061                 case T_AlterRoleStmt:
3062                         retval = _copyAlterRoleStmt(from);
3063                         break;
3064                 case T_AlterRoleSetStmt:
3065                         retval = _copyAlterRoleSetStmt(from);
3066                         break;
3067                 case T_DropRoleStmt:
3068                         retval = _copyDropRoleStmt(from);
3069                         break;
3070                 case T_LockStmt:
3071                         retval = _copyLockStmt(from);
3072                         break;
3073                 case T_ConstraintsSetStmt:
3074                         retval = _copyConstraintsSetStmt(from);
3075                         break;
3076                 case T_ReindexStmt:
3077                         retval = _copyReindexStmt(from);
3078                         break;
3079                 case T_CheckPointStmt:
3080                         retval = (void *) makeNode(CheckPointStmt);
3081                         break;
3082                 case T_CreateSchemaStmt:
3083                         retval = _copyCreateSchemaStmt(from);
3084                         break;
3085                 case T_CreateConversionStmt:
3086                         retval = _copyCreateConversionStmt(from);
3087                         break;
3088                 case T_CreateCastStmt:
3089                         retval = _copyCreateCastStmt(from);
3090                         break;
3091                 case T_DropCastStmt:
3092                         retval = _copyDropCastStmt(from);
3093                         break;
3094                 case T_PrepareStmt:
3095                         retval = _copyPrepareStmt(from);
3096                         break;
3097                 case T_ExecuteStmt:
3098                         retval = _copyExecuteStmt(from);
3099                         break;
3100                 case T_DeallocateStmt:
3101                         retval = _copyDeallocateStmt(from);
3102                         break;
3103
3104                 case T_A_Expr:
3105                         retval = _copyAExpr(from);
3106                         break;
3107                 case T_ColumnRef:
3108                         retval = _copyColumnRef(from);
3109                         break;
3110                 case T_ParamRef:
3111                         retval = _copyParamRef(from);
3112                         break;
3113                 case T_A_Const:
3114                         retval = _copyAConst(from);
3115                         break;
3116                 case T_FuncCall:
3117                         retval = _copyFuncCall(from);
3118                         break;
3119                 case T_A_Indices:
3120                         retval = _copyAIndices(from);
3121                         break;
3122                 case T_A_Indirection:
3123                         retval = _copyA_Indirection(from);
3124                         break;
3125                 case T_ResTarget:
3126                         retval = _copyResTarget(from);
3127                         break;
3128                 case T_TypeCast:
3129                         retval = _copyTypeCast(from);
3130                         break;
3131                 case T_SortBy:
3132                         retval = _copySortBy(from);
3133                         break;
3134                 case T_RangeSubselect:
3135                         retval = _copyRangeSubselect(from);
3136                         break;
3137                 case T_RangeFunction:
3138                         retval = _copyRangeFunction(from);
3139                         break;
3140                 case T_TypeName:
3141                         retval = _copyTypeName(from);
3142                         break;
3143                 case T_IndexElem:
3144                         retval = _copyIndexElem(from);
3145                         break;
3146                 case T_ColumnDef:
3147                         retval = _copyColumnDef(from);
3148                         break;
3149                 case T_Constraint:
3150                         retval = _copyConstraint(from);
3151                         break;
3152                 case T_DefElem:
3153                         retval = _copyDefElem(from);
3154                         break;
3155                 case T_RangeTblEntry:
3156                         retval = _copyRangeTblEntry(from);
3157                         break;
3158                 case T_SortClause:
3159                         retval = _copySortClause(from);
3160                         break;
3161                 case T_GroupClause:
3162                         retval = _copyGroupClause(from);
3163                         break;
3164                 case T_FkConstraint:
3165                         retval = _copyFkConstraint(from);
3166                         break;
3167                 case T_PrivGrantee:
3168                         retval = _copyPrivGrantee(from);
3169                         break;
3170                 case T_FuncWithArgs:
3171                         retval = _copyFuncWithArgs(from);
3172                         break;
3173
3174                 default:
3175                         elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
3176                         retval = from;          /* keep compiler quiet */
3177                         break;
3178         }
3179
3180         return retval;
3181 }