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