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