]> granicus.if.org Git - postgresql/blob - src/backend/nodes/copyfuncs.c
refactor ALTER some-obj SET OWNER implementation
[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-2012, PostgreSQL Global Development Group
15  * Portions Copyright (c) 1994, Regents of the University of California
16  *
17  * IDENTIFICATION
18  *        src/backend/nodes/copyfuncs.c
19  *
20  *-------------------------------------------------------------------------
21  */
22
23 #include "postgres.h"
24
25 #include "miscadmin.h"
26 #include "nodes/plannodes.h"
27 #include "nodes/relation.h"
28 #include "utils/datum.h"
29
30
31 /*
32  * Macros to simplify copying of different kinds of fields.  Use these
33  * wherever possible to reduce the chance for silly typos.      Note that these
34  * hard-wire the convention that the local variables in a Copy routine are
35  * named 'newnode' and 'from'.
36  */
37
38 /* Copy a simple scalar field (int, float, bool, enum, etc) */
39 #define COPY_SCALAR_FIELD(fldname) \
40         (newnode->fldname = from->fldname)
41
42 /* Copy a field that is a pointer to some kind of Node or Node tree */
43 #define COPY_NODE_FIELD(fldname) \
44         (newnode->fldname = copyObject(from->fldname))
45
46 /* Copy a field that is a pointer to a Bitmapset */
47 #define COPY_BITMAPSET_FIELD(fldname) \
48         (newnode->fldname = bms_copy(from->fldname))
49
50 /* Copy a field that is a pointer to a C string, or perhaps NULL */
51 #define COPY_STRING_FIELD(fldname) \
52         (newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)
53
54 /* Copy a field that is a pointer to a simple palloc'd object of size sz */
55 #define COPY_POINTER_FIELD(fldname, sz) \
56         do { \
57                 Size    _size = (sz); \
58                 newnode->fldname = palloc(_size); \
59                 memcpy(newnode->fldname, from->fldname, _size); \
60         } while (0)
61
62 /* Copy a parse location field (for Copy, this is same as scalar case) */
63 #define COPY_LOCATION_FIELD(fldname) \
64         (newnode->fldname = from->fldname)
65
66
67 /* ****************************************************************
68  *                                       plannodes.h copy functions
69  * ****************************************************************
70  */
71
72 /*
73  * _copyPlannedStmt
74  */
75 static PlannedStmt *
76 _copyPlannedStmt(const PlannedStmt *from)
77 {
78         PlannedStmt *newnode = makeNode(PlannedStmt);
79
80         COPY_SCALAR_FIELD(commandType);
81         COPY_SCALAR_FIELD(queryId);
82         COPY_SCALAR_FIELD(hasReturning);
83         COPY_SCALAR_FIELD(hasModifyingCTE);
84         COPY_SCALAR_FIELD(canSetTag);
85         COPY_SCALAR_FIELD(transientPlan);
86         COPY_NODE_FIELD(planTree);
87         COPY_NODE_FIELD(rtable);
88         COPY_NODE_FIELD(resultRelations);
89         COPY_NODE_FIELD(utilityStmt);
90         COPY_NODE_FIELD(subplans);
91         COPY_BITMAPSET_FIELD(rewindPlanIDs);
92         COPY_NODE_FIELD(rowMarks);
93         COPY_NODE_FIELD(relationOids);
94         COPY_NODE_FIELD(invalItems);
95         COPY_SCALAR_FIELD(nParamExec);
96
97         return newnode;
98 }
99
100 /*
101  * CopyPlanFields
102  *
103  *              This function copies the fields of the Plan node.  It is used by
104  *              all the copy functions for classes which inherit from Plan.
105  */
106 static void
107 CopyPlanFields(const Plan *from, Plan *newnode)
108 {
109         COPY_SCALAR_FIELD(startup_cost);
110         COPY_SCALAR_FIELD(total_cost);
111         COPY_SCALAR_FIELD(plan_rows);
112         COPY_SCALAR_FIELD(plan_width);
113         COPY_NODE_FIELD(targetlist);
114         COPY_NODE_FIELD(qual);
115         COPY_NODE_FIELD(lefttree);
116         COPY_NODE_FIELD(righttree);
117         COPY_NODE_FIELD(initPlan);
118         COPY_BITMAPSET_FIELD(extParam);
119         COPY_BITMAPSET_FIELD(allParam);
120 }
121
122 /*
123  * _copyPlan
124  */
125 static Plan *
126 _copyPlan(const Plan *from)
127 {
128         Plan       *newnode = makeNode(Plan);
129
130         /*
131          * copy node superclass fields
132          */
133         CopyPlanFields(from, newnode);
134
135         return newnode;
136 }
137
138
139 /*
140  * _copyResult
141  */
142 static Result *
143 _copyResult(const Result *from)
144 {
145         Result     *newnode = makeNode(Result);
146
147         /*
148          * copy node superclass fields
149          */
150         CopyPlanFields((const Plan *) from, (Plan *) newnode);
151
152         /*
153          * copy remainder of node
154          */
155         COPY_NODE_FIELD(resconstantqual);
156
157         return newnode;
158 }
159
160 /*
161  * _copyModifyTable
162  */
163 static ModifyTable *
164 _copyModifyTable(const ModifyTable *from)
165 {
166         ModifyTable *newnode = makeNode(ModifyTable);
167
168         /*
169          * copy node superclass fields
170          */
171         CopyPlanFields((const Plan *) from, (Plan *) newnode);
172
173         /*
174          * copy remainder of node
175          */
176         COPY_SCALAR_FIELD(operation);
177         COPY_SCALAR_FIELD(canSetTag);
178         COPY_NODE_FIELD(resultRelations);
179         COPY_SCALAR_FIELD(resultRelIndex);
180         COPY_NODE_FIELD(plans);
181         COPY_NODE_FIELD(returningLists);
182         COPY_NODE_FIELD(rowMarks);
183         COPY_SCALAR_FIELD(epqParam);
184
185         return newnode;
186 }
187
188 /*
189  * _copyAppend
190  */
191 static Append *
192 _copyAppend(const Append *from)
193 {
194         Append     *newnode = makeNode(Append);
195
196         /*
197          * copy node superclass fields
198          */
199         CopyPlanFields((const Plan *) from, (Plan *) newnode);
200
201         /*
202          * copy remainder of node
203          */
204         COPY_NODE_FIELD(appendplans);
205
206         return newnode;
207 }
208
209 /*
210  * _copyMergeAppend
211  */
212 static MergeAppend *
213 _copyMergeAppend(const MergeAppend *from)
214 {
215         MergeAppend *newnode = makeNode(MergeAppend);
216
217         /*
218          * copy node superclass fields
219          */
220         CopyPlanFields((const Plan *) from, (Plan *) newnode);
221
222         /*
223          * copy remainder of node
224          */
225         COPY_NODE_FIELD(mergeplans);
226         COPY_SCALAR_FIELD(numCols);
227         COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
228         COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
229         COPY_POINTER_FIELD(collations, from->numCols * sizeof(Oid));
230         COPY_POINTER_FIELD(nullsFirst, from->numCols * sizeof(bool));
231
232         return newnode;
233 }
234
235 /*
236  * _copyRecursiveUnion
237  */
238 static RecursiveUnion *
239 _copyRecursiveUnion(const RecursiveUnion *from)
240 {
241         RecursiveUnion *newnode = makeNode(RecursiveUnion);
242
243         /*
244          * copy node superclass fields
245          */
246         CopyPlanFields((const Plan *) from, (Plan *) newnode);
247
248         /*
249          * copy remainder of node
250          */
251         COPY_SCALAR_FIELD(wtParam);
252         COPY_SCALAR_FIELD(numCols);
253         if (from->numCols > 0)
254         {
255                 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
256                 COPY_POINTER_FIELD(dupOperators, from->numCols * sizeof(Oid));
257         }
258         COPY_SCALAR_FIELD(numGroups);
259
260         return newnode;
261 }
262
263 /*
264  * _copyBitmapAnd
265  */
266 static BitmapAnd *
267 _copyBitmapAnd(const BitmapAnd *from)
268 {
269         BitmapAnd  *newnode = makeNode(BitmapAnd);
270
271         /*
272          * copy node superclass fields
273          */
274         CopyPlanFields((const Plan *) from, (Plan *) newnode);
275
276         /*
277          * copy remainder of node
278          */
279         COPY_NODE_FIELD(bitmapplans);
280
281         return newnode;
282 }
283
284 /*
285  * _copyBitmapOr
286  */
287 static BitmapOr *
288 _copyBitmapOr(const BitmapOr *from)
289 {
290         BitmapOr   *newnode = makeNode(BitmapOr);
291
292         /*
293          * copy node superclass fields
294          */
295         CopyPlanFields((const Plan *) from, (Plan *) newnode);
296
297         /*
298          * copy remainder of node
299          */
300         COPY_NODE_FIELD(bitmapplans);
301
302         return newnode;
303 }
304
305
306 /*
307  * CopyScanFields
308  *
309  *              This function copies the fields of the Scan node.  It is used by
310  *              all the copy functions for classes which inherit from Scan.
311  */
312 static void
313 CopyScanFields(const Scan *from, Scan *newnode)
314 {
315         CopyPlanFields((const Plan *) from, (Plan *) newnode);
316
317         COPY_SCALAR_FIELD(scanrelid);
318 }
319
320 /*
321  * _copyScan
322  */
323 static Scan *
324 _copyScan(const Scan *from)
325 {
326         Scan       *newnode = makeNode(Scan);
327
328         /*
329          * copy node superclass fields
330          */
331         CopyScanFields((const Scan *) from, (Scan *) newnode);
332
333         return newnode;
334 }
335
336 /*
337  * _copySeqScan
338  */
339 static SeqScan *
340 _copySeqScan(const SeqScan *from)
341 {
342         SeqScan    *newnode = makeNode(SeqScan);
343
344         /*
345          * copy node superclass fields
346          */
347         CopyScanFields((const Scan *) from, (Scan *) newnode);
348
349         return newnode;
350 }
351
352 /*
353  * _copyIndexScan
354  */
355 static IndexScan *
356 _copyIndexScan(const IndexScan *from)
357 {
358         IndexScan  *newnode = makeNode(IndexScan);
359
360         /*
361          * copy node superclass fields
362          */
363         CopyScanFields((const Scan *) from, (Scan *) newnode);
364
365         /*
366          * copy remainder of node
367          */
368         COPY_SCALAR_FIELD(indexid);
369         COPY_NODE_FIELD(indexqual);
370         COPY_NODE_FIELD(indexqualorig);
371         COPY_NODE_FIELD(indexorderby);
372         COPY_NODE_FIELD(indexorderbyorig);
373         COPY_SCALAR_FIELD(indexorderdir);
374
375         return newnode;
376 }
377
378 /*
379  * _copyIndexOnlyScan
380  */
381 static IndexOnlyScan *
382 _copyIndexOnlyScan(const IndexOnlyScan *from)
383 {
384         IndexOnlyScan *newnode = makeNode(IndexOnlyScan);
385
386         /*
387          * copy node superclass fields
388          */
389         CopyScanFields((const Scan *) from, (Scan *) newnode);
390
391         /*
392          * copy remainder of node
393          */
394         COPY_SCALAR_FIELD(indexid);
395         COPY_NODE_FIELD(indexqual);
396         COPY_NODE_FIELD(indexorderby);
397         COPY_NODE_FIELD(indextlist);
398         COPY_SCALAR_FIELD(indexorderdir);
399
400         return newnode;
401 }
402
403 /*
404  * _copyBitmapIndexScan
405  */
406 static BitmapIndexScan *
407 _copyBitmapIndexScan(const BitmapIndexScan *from)
408 {
409         BitmapIndexScan *newnode = makeNode(BitmapIndexScan);
410
411         /*
412          * copy node superclass fields
413          */
414         CopyScanFields((const Scan *) from, (Scan *) newnode);
415
416         /*
417          * copy remainder of node
418          */
419         COPY_SCALAR_FIELD(indexid);
420         COPY_NODE_FIELD(indexqual);
421         COPY_NODE_FIELD(indexqualorig);
422
423         return newnode;
424 }
425
426 /*
427  * _copyBitmapHeapScan
428  */
429 static BitmapHeapScan *
430 _copyBitmapHeapScan(const BitmapHeapScan *from)
431 {
432         BitmapHeapScan *newnode = makeNode(BitmapHeapScan);
433
434         /*
435          * copy node superclass fields
436          */
437         CopyScanFields((const Scan *) from, (Scan *) newnode);
438
439         /*
440          * copy remainder of node
441          */
442         COPY_NODE_FIELD(bitmapqualorig);
443
444         return newnode;
445 }
446
447 /*
448  * _copyTidScan
449  */
450 static TidScan *
451 _copyTidScan(const TidScan *from)
452 {
453         TidScan    *newnode = makeNode(TidScan);
454
455         /*
456          * copy node superclass fields
457          */
458         CopyScanFields((const Scan *) from, (Scan *) newnode);
459
460         /*
461          * copy remainder of node
462          */
463         COPY_NODE_FIELD(tidquals);
464
465         return newnode;
466 }
467
468 /*
469  * _copySubqueryScan
470  */
471 static SubqueryScan *
472 _copySubqueryScan(const SubqueryScan *from)
473 {
474         SubqueryScan *newnode = makeNode(SubqueryScan);
475
476         /*
477          * copy node superclass fields
478          */
479         CopyScanFields((const Scan *) from, (Scan *) newnode);
480
481         /*
482          * copy remainder of node
483          */
484         COPY_NODE_FIELD(subplan);
485
486         return newnode;
487 }
488
489 /*
490  * _copyFunctionScan
491  */
492 static FunctionScan *
493 _copyFunctionScan(const FunctionScan *from)
494 {
495         FunctionScan *newnode = makeNode(FunctionScan);
496
497         /*
498          * copy node superclass fields
499          */
500         CopyScanFields((const Scan *) from, (Scan *) newnode);
501
502         /*
503          * copy remainder of node
504          */
505         COPY_NODE_FIELD(funcexpr);
506         COPY_NODE_FIELD(funccolnames);
507         COPY_NODE_FIELD(funccoltypes);
508         COPY_NODE_FIELD(funccoltypmods);
509         COPY_NODE_FIELD(funccolcollations);
510
511         return newnode;
512 }
513
514 /*
515  * _copyValuesScan
516  */
517 static ValuesScan *
518 _copyValuesScan(const ValuesScan *from)
519 {
520         ValuesScan *newnode = makeNode(ValuesScan);
521
522         /*
523          * copy node superclass fields
524          */
525         CopyScanFields((const Scan *) from, (Scan *) newnode);
526
527         /*
528          * copy remainder of node
529          */
530         COPY_NODE_FIELD(values_lists);
531
532         return newnode;
533 }
534
535 /*
536  * _copyCteScan
537  */
538 static CteScan *
539 _copyCteScan(const CteScan *from)
540 {
541         CteScan    *newnode = makeNode(CteScan);
542
543         /*
544          * copy node superclass fields
545          */
546         CopyScanFields((const Scan *) from, (Scan *) newnode);
547
548         /*
549          * copy remainder of node
550          */
551         COPY_SCALAR_FIELD(ctePlanId);
552         COPY_SCALAR_FIELD(cteParam);
553
554         return newnode;
555 }
556
557 /*
558  * _copyWorkTableScan
559  */
560 static WorkTableScan *
561 _copyWorkTableScan(const WorkTableScan *from)
562 {
563         WorkTableScan *newnode = makeNode(WorkTableScan);
564
565         /*
566          * copy node superclass fields
567          */
568         CopyScanFields((const Scan *) from, (Scan *) newnode);
569
570         /*
571          * copy remainder of node
572          */
573         COPY_SCALAR_FIELD(wtParam);
574
575         return newnode;
576 }
577
578 /*
579  * _copyForeignScan
580  */
581 static ForeignScan *
582 _copyForeignScan(const ForeignScan *from)
583 {
584         ForeignScan *newnode = makeNode(ForeignScan);
585
586         /*
587          * copy node superclass fields
588          */
589         CopyScanFields((const Scan *) from, (Scan *) newnode);
590
591         /*
592          * copy remainder of node
593          */
594         COPY_NODE_FIELD(fdw_exprs);
595         COPY_NODE_FIELD(fdw_private);
596         COPY_SCALAR_FIELD(fsSystemCol);
597
598         return newnode;
599 }
600
601 /*
602  * CopyJoinFields
603  *
604  *              This function copies the fields of the Join node.  It is used by
605  *              all the copy functions for classes which inherit from Join.
606  */
607 static void
608 CopyJoinFields(const Join *from, Join *newnode)
609 {
610         CopyPlanFields((const Plan *) from, (Plan *) newnode);
611
612         COPY_SCALAR_FIELD(jointype);
613         COPY_NODE_FIELD(joinqual);
614 }
615
616
617 /*
618  * _copyJoin
619  */
620 static Join *
621 _copyJoin(const Join *from)
622 {
623         Join       *newnode = makeNode(Join);
624
625         /*
626          * copy node superclass fields
627          */
628         CopyJoinFields(from, newnode);
629
630         return newnode;
631 }
632
633
634 /*
635  * _copyNestLoop
636  */
637 static NestLoop *
638 _copyNestLoop(const NestLoop *from)
639 {
640         NestLoop   *newnode = makeNode(NestLoop);
641
642         /*
643          * copy node superclass fields
644          */
645         CopyJoinFields((const Join *) from, (Join *) newnode);
646
647         /*
648          * copy remainder of node
649          */
650         COPY_NODE_FIELD(nestParams);
651
652         return newnode;
653 }
654
655
656 /*
657  * _copyMergeJoin
658  */
659 static MergeJoin *
660 _copyMergeJoin(const MergeJoin *from)
661 {
662         MergeJoin  *newnode = makeNode(MergeJoin);
663         int                     numCols;
664
665         /*
666          * copy node superclass fields
667          */
668         CopyJoinFields((const Join *) from, (Join *) newnode);
669
670         /*
671          * copy remainder of node
672          */
673         COPY_NODE_FIELD(mergeclauses);
674         numCols = list_length(from->mergeclauses);
675         if (numCols > 0)
676         {
677                 COPY_POINTER_FIELD(mergeFamilies, numCols * sizeof(Oid));
678                 COPY_POINTER_FIELD(mergeCollations, numCols * sizeof(Oid));
679                 COPY_POINTER_FIELD(mergeStrategies, numCols * sizeof(int));
680                 COPY_POINTER_FIELD(mergeNullsFirst, numCols * sizeof(bool));
681         }
682
683         return newnode;
684 }
685
686 /*
687  * _copyHashJoin
688  */
689 static HashJoin *
690 _copyHashJoin(const HashJoin *from)
691 {
692         HashJoin   *newnode = makeNode(HashJoin);
693
694         /*
695          * copy node superclass fields
696          */
697         CopyJoinFields((const Join *) from, (Join *) newnode);
698
699         /*
700          * copy remainder of node
701          */
702         COPY_NODE_FIELD(hashclauses);
703
704         return newnode;
705 }
706
707
708 /*
709  * _copyMaterial
710  */
711 static Material *
712 _copyMaterial(const Material *from)
713 {
714         Material   *newnode = makeNode(Material);
715
716         /*
717          * copy node superclass fields
718          */
719         CopyPlanFields((const Plan *) from, (Plan *) newnode);
720
721         return newnode;
722 }
723
724
725 /*
726  * _copySort
727  */
728 static Sort *
729 _copySort(const Sort *from)
730 {
731         Sort       *newnode = makeNode(Sort);
732
733         /*
734          * copy node superclass fields
735          */
736         CopyPlanFields((const Plan *) from, (Plan *) newnode);
737
738         COPY_SCALAR_FIELD(numCols);
739         COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
740         COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
741         COPY_POINTER_FIELD(collations, from->numCols * sizeof(Oid));
742         COPY_POINTER_FIELD(nullsFirst, from->numCols * sizeof(bool));
743
744         return newnode;
745 }
746
747
748 /*
749  * _copyGroup
750  */
751 static Group *
752 _copyGroup(const Group *from)
753 {
754         Group      *newnode = makeNode(Group);
755
756         CopyPlanFields((const Plan *) from, (Plan *) newnode);
757
758         COPY_SCALAR_FIELD(numCols);
759         COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
760         COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
761
762         return newnode;
763 }
764
765 /*
766  * _copyAgg
767  */
768 static Agg *
769 _copyAgg(const Agg *from)
770 {
771         Agg                *newnode = makeNode(Agg);
772
773         CopyPlanFields((const Plan *) from, (Plan *) newnode);
774
775         COPY_SCALAR_FIELD(aggstrategy);
776         COPY_SCALAR_FIELD(numCols);
777         if (from->numCols > 0)
778         {
779                 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
780                 COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
781         }
782         COPY_SCALAR_FIELD(numGroups);
783
784         return newnode;
785 }
786
787 /*
788  * _copyWindowAgg
789  */
790 static WindowAgg *
791 _copyWindowAgg(const WindowAgg *from)
792 {
793         WindowAgg  *newnode = makeNode(WindowAgg);
794
795         CopyPlanFields((const Plan *) from, (Plan *) newnode);
796
797         COPY_SCALAR_FIELD(winref);
798         COPY_SCALAR_FIELD(partNumCols);
799         if (from->partNumCols > 0)
800         {
801                 COPY_POINTER_FIELD(partColIdx, from->partNumCols * sizeof(AttrNumber));
802                 COPY_POINTER_FIELD(partOperators, from->partNumCols * sizeof(Oid));
803         }
804         COPY_SCALAR_FIELD(ordNumCols);
805         if (from->ordNumCols > 0)
806         {
807                 COPY_POINTER_FIELD(ordColIdx, from->ordNumCols * sizeof(AttrNumber));
808                 COPY_POINTER_FIELD(ordOperators, from->ordNumCols * sizeof(Oid));
809         }
810         COPY_SCALAR_FIELD(frameOptions);
811         COPY_NODE_FIELD(startOffset);
812         COPY_NODE_FIELD(endOffset);
813
814         return newnode;
815 }
816
817 /*
818  * _copyUnique
819  */
820 static Unique *
821 _copyUnique(const Unique *from)
822 {
823         Unique     *newnode = makeNode(Unique);
824
825         /*
826          * copy node superclass fields
827          */
828         CopyPlanFields((const Plan *) from, (Plan *) newnode);
829
830         /*
831          * copy remainder of node
832          */
833         COPY_SCALAR_FIELD(numCols);
834         COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
835         COPY_POINTER_FIELD(uniqOperators, from->numCols * sizeof(Oid));
836
837         return newnode;
838 }
839
840 /*
841  * _copyHash
842  */
843 static Hash *
844 _copyHash(const Hash *from)
845 {
846         Hash       *newnode = makeNode(Hash);
847
848         /*
849          * copy node superclass fields
850          */
851         CopyPlanFields((const Plan *) from, (Plan *) newnode);
852
853         /*
854          * copy remainder of node
855          */
856         COPY_SCALAR_FIELD(skewTable);
857         COPY_SCALAR_FIELD(skewColumn);
858         COPY_SCALAR_FIELD(skewInherit);
859         COPY_SCALAR_FIELD(skewColType);
860         COPY_SCALAR_FIELD(skewColTypmod);
861
862         return newnode;
863 }
864
865 /*
866  * _copySetOp
867  */
868 static SetOp *
869 _copySetOp(const SetOp *from)
870 {
871         SetOp      *newnode = makeNode(SetOp);
872
873         /*
874          * copy node superclass fields
875          */
876         CopyPlanFields((const Plan *) from, (Plan *) newnode);
877
878         /*
879          * copy remainder of node
880          */
881         COPY_SCALAR_FIELD(cmd);
882         COPY_SCALAR_FIELD(strategy);
883         COPY_SCALAR_FIELD(numCols);
884         COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
885         COPY_POINTER_FIELD(dupOperators, from->numCols * sizeof(Oid));
886         COPY_SCALAR_FIELD(flagColIdx);
887         COPY_SCALAR_FIELD(firstFlag);
888         COPY_SCALAR_FIELD(numGroups);
889
890         return newnode;
891 }
892
893 /*
894  * _copyLockRows
895  */
896 static LockRows *
897 _copyLockRows(const LockRows *from)
898 {
899         LockRows   *newnode = makeNode(LockRows);
900
901         /*
902          * copy node superclass fields
903          */
904         CopyPlanFields((const Plan *) from, (Plan *) newnode);
905
906         /*
907          * copy remainder of node
908          */
909         COPY_NODE_FIELD(rowMarks);
910         COPY_SCALAR_FIELD(epqParam);
911
912         return newnode;
913 }
914
915 /*
916  * _copyLimit
917  */
918 static Limit *
919 _copyLimit(const Limit *from)
920 {
921         Limit      *newnode = makeNode(Limit);
922
923         /*
924          * copy node superclass fields
925          */
926         CopyPlanFields((const Plan *) from, (Plan *) newnode);
927
928         /*
929          * copy remainder of node
930          */
931         COPY_NODE_FIELD(limitOffset);
932         COPY_NODE_FIELD(limitCount);
933
934         return newnode;
935 }
936
937 /*
938  * _copyNestLoopParam
939  */
940 static NestLoopParam *
941 _copyNestLoopParam(const NestLoopParam *from)
942 {
943         NestLoopParam *newnode = makeNode(NestLoopParam);
944
945         COPY_SCALAR_FIELD(paramno);
946         COPY_NODE_FIELD(paramval);
947
948         return newnode;
949 }
950
951 /*
952  * _copyPlanRowMark
953  */
954 static PlanRowMark *
955 _copyPlanRowMark(const PlanRowMark *from)
956 {
957         PlanRowMark *newnode = makeNode(PlanRowMark);
958
959         COPY_SCALAR_FIELD(rti);
960         COPY_SCALAR_FIELD(prti);
961         COPY_SCALAR_FIELD(rowmarkId);
962         COPY_SCALAR_FIELD(markType);
963         COPY_SCALAR_FIELD(noWait);
964         COPY_SCALAR_FIELD(isParent);
965
966         return newnode;
967 }
968
969 /*
970  * _copyPlanInvalItem
971  */
972 static PlanInvalItem *
973 _copyPlanInvalItem(const PlanInvalItem *from)
974 {
975         PlanInvalItem *newnode = makeNode(PlanInvalItem);
976
977         COPY_SCALAR_FIELD(cacheId);
978         COPY_SCALAR_FIELD(hashValue);
979
980         return newnode;
981 }
982
983 /* ****************************************************************
984  *                                         primnodes.h copy functions
985  * ****************************************************************
986  */
987
988 /*
989  * _copyAlias
990  */
991 static Alias *
992 _copyAlias(const Alias *from)
993 {
994         Alias      *newnode = makeNode(Alias);
995
996         COPY_STRING_FIELD(aliasname);
997         COPY_NODE_FIELD(colnames);
998
999         return newnode;
1000 }
1001
1002 /*
1003  * _copyRangeVar
1004  */
1005 static RangeVar *
1006 _copyRangeVar(const RangeVar *from)
1007 {
1008         RangeVar   *newnode = makeNode(RangeVar);
1009
1010         COPY_STRING_FIELD(catalogname);
1011         COPY_STRING_FIELD(schemaname);
1012         COPY_STRING_FIELD(relname);
1013         COPY_SCALAR_FIELD(inhOpt);
1014         COPY_SCALAR_FIELD(relpersistence);
1015         COPY_NODE_FIELD(alias);
1016         COPY_LOCATION_FIELD(location);
1017
1018         return newnode;
1019 }
1020
1021 /*
1022  * _copyIntoClause
1023  */
1024 static IntoClause *
1025 _copyIntoClause(const IntoClause *from)
1026 {
1027         IntoClause *newnode = makeNode(IntoClause);
1028
1029         COPY_NODE_FIELD(rel);
1030         COPY_NODE_FIELD(colNames);
1031         COPY_NODE_FIELD(options);
1032         COPY_SCALAR_FIELD(onCommit);
1033         COPY_STRING_FIELD(tableSpaceName);
1034         COPY_SCALAR_FIELD(skipData);
1035
1036         return newnode;
1037 }
1038
1039 /*
1040  * We don't need a _copyExpr because Expr is an abstract supertype which
1041  * should never actually get instantiated.      Also, since it has no common
1042  * fields except NodeTag, there's no need for a helper routine to factor
1043  * out copying the common fields...
1044  */
1045
1046 /*
1047  * _copyVar
1048  */
1049 static Var *
1050 _copyVar(const Var *from)
1051 {
1052         Var                *newnode = makeNode(Var);
1053
1054         COPY_SCALAR_FIELD(varno);
1055         COPY_SCALAR_FIELD(varattno);
1056         COPY_SCALAR_FIELD(vartype);
1057         COPY_SCALAR_FIELD(vartypmod);
1058         COPY_SCALAR_FIELD(varcollid);
1059         COPY_SCALAR_FIELD(varlevelsup);
1060         COPY_SCALAR_FIELD(varnoold);
1061         COPY_SCALAR_FIELD(varoattno);
1062         COPY_LOCATION_FIELD(location);
1063
1064         return newnode;
1065 }
1066
1067 /*
1068  * _copyConst
1069  */
1070 static Const *
1071 _copyConst(const Const *from)
1072 {
1073         Const      *newnode = makeNode(Const);
1074
1075         COPY_SCALAR_FIELD(consttype);
1076         COPY_SCALAR_FIELD(consttypmod);
1077         COPY_SCALAR_FIELD(constcollid);
1078         COPY_SCALAR_FIELD(constlen);
1079
1080         if (from->constbyval || from->constisnull)
1081         {
1082                 /*
1083                  * passed by value so just copy the datum. Also, don't try to copy
1084                  * struct when value is null!
1085                  */
1086                 newnode->constvalue = from->constvalue;
1087         }
1088         else
1089         {
1090                 /*
1091                  * passed by reference.  We need a palloc'd copy.
1092                  */
1093                 newnode->constvalue = datumCopy(from->constvalue,
1094                                                                                 from->constbyval,
1095                                                                                 from->constlen);
1096         }
1097
1098         COPY_SCALAR_FIELD(constisnull);
1099         COPY_SCALAR_FIELD(constbyval);
1100         COPY_LOCATION_FIELD(location);
1101
1102         return newnode;
1103 }
1104
1105 /*
1106  * _copyParam
1107  */
1108 static Param *
1109 _copyParam(const Param *from)
1110 {
1111         Param      *newnode = makeNode(Param);
1112
1113         COPY_SCALAR_FIELD(paramkind);
1114         COPY_SCALAR_FIELD(paramid);
1115         COPY_SCALAR_FIELD(paramtype);
1116         COPY_SCALAR_FIELD(paramtypmod);
1117         COPY_SCALAR_FIELD(paramcollid);
1118         COPY_LOCATION_FIELD(location);
1119
1120         return newnode;
1121 }
1122
1123 /*
1124  * _copyAggref
1125  */
1126 static Aggref *
1127 _copyAggref(const Aggref *from)
1128 {
1129         Aggref     *newnode = makeNode(Aggref);
1130
1131         COPY_SCALAR_FIELD(aggfnoid);
1132         COPY_SCALAR_FIELD(aggtype);
1133         COPY_SCALAR_FIELD(aggcollid);
1134         COPY_SCALAR_FIELD(inputcollid);
1135         COPY_NODE_FIELD(args);
1136         COPY_NODE_FIELD(aggorder);
1137         COPY_NODE_FIELD(aggdistinct);
1138         COPY_SCALAR_FIELD(aggstar);
1139         COPY_SCALAR_FIELD(agglevelsup);
1140         COPY_LOCATION_FIELD(location);
1141
1142         return newnode;
1143 }
1144
1145 /*
1146  * _copyWindowFunc
1147  */
1148 static WindowFunc *
1149 _copyWindowFunc(const WindowFunc *from)
1150 {
1151         WindowFunc *newnode = makeNode(WindowFunc);
1152
1153         COPY_SCALAR_FIELD(winfnoid);
1154         COPY_SCALAR_FIELD(wintype);
1155         COPY_SCALAR_FIELD(wincollid);
1156         COPY_SCALAR_FIELD(inputcollid);
1157         COPY_NODE_FIELD(args);
1158         COPY_SCALAR_FIELD(winref);
1159         COPY_SCALAR_FIELD(winstar);
1160         COPY_SCALAR_FIELD(winagg);
1161         COPY_LOCATION_FIELD(location);
1162
1163         return newnode;
1164 }
1165
1166 /*
1167  * _copyArrayRef
1168  */
1169 static ArrayRef *
1170 _copyArrayRef(const ArrayRef *from)
1171 {
1172         ArrayRef   *newnode = makeNode(ArrayRef);
1173
1174         COPY_SCALAR_FIELD(refarraytype);
1175         COPY_SCALAR_FIELD(refelemtype);
1176         COPY_SCALAR_FIELD(reftypmod);
1177         COPY_SCALAR_FIELD(refcollid);
1178         COPY_NODE_FIELD(refupperindexpr);
1179         COPY_NODE_FIELD(reflowerindexpr);
1180         COPY_NODE_FIELD(refexpr);
1181         COPY_NODE_FIELD(refassgnexpr);
1182
1183         return newnode;
1184 }
1185
1186 /*
1187  * _copyFuncExpr
1188  */
1189 static FuncExpr *
1190 _copyFuncExpr(const FuncExpr *from)
1191 {
1192         FuncExpr   *newnode = makeNode(FuncExpr);
1193
1194         COPY_SCALAR_FIELD(funcid);
1195         COPY_SCALAR_FIELD(funcresulttype);
1196         COPY_SCALAR_FIELD(funcretset);
1197         COPY_SCALAR_FIELD(funcformat);
1198         COPY_SCALAR_FIELD(funccollid);
1199         COPY_SCALAR_FIELD(inputcollid);
1200         COPY_NODE_FIELD(args);
1201         COPY_LOCATION_FIELD(location);
1202
1203         return newnode;
1204 }
1205
1206 /*
1207  * _copyNamedArgExpr *
1208  */
1209 static NamedArgExpr *
1210 _copyNamedArgExpr(const NamedArgExpr *from)
1211 {
1212         NamedArgExpr *newnode = makeNode(NamedArgExpr);
1213
1214         COPY_NODE_FIELD(arg);
1215         COPY_STRING_FIELD(name);
1216         COPY_SCALAR_FIELD(argnumber);
1217         COPY_LOCATION_FIELD(location);
1218
1219         return newnode;
1220 }
1221
1222 /*
1223  * _copyOpExpr
1224  */
1225 static OpExpr *
1226 _copyOpExpr(const OpExpr *from)
1227 {
1228         OpExpr     *newnode = makeNode(OpExpr);
1229
1230         COPY_SCALAR_FIELD(opno);
1231         COPY_SCALAR_FIELD(opfuncid);
1232         COPY_SCALAR_FIELD(opresulttype);
1233         COPY_SCALAR_FIELD(opretset);
1234         COPY_SCALAR_FIELD(opcollid);
1235         COPY_SCALAR_FIELD(inputcollid);
1236         COPY_NODE_FIELD(args);
1237         COPY_LOCATION_FIELD(location);
1238
1239         return newnode;
1240 }
1241
1242 /*
1243  * _copyDistinctExpr (same as OpExpr)
1244  */
1245 static DistinctExpr *
1246 _copyDistinctExpr(const DistinctExpr *from)
1247 {
1248         DistinctExpr *newnode = makeNode(DistinctExpr);
1249
1250         COPY_SCALAR_FIELD(opno);
1251         COPY_SCALAR_FIELD(opfuncid);
1252         COPY_SCALAR_FIELD(opresulttype);
1253         COPY_SCALAR_FIELD(opretset);
1254         COPY_SCALAR_FIELD(opcollid);
1255         COPY_SCALAR_FIELD(inputcollid);
1256         COPY_NODE_FIELD(args);
1257         COPY_LOCATION_FIELD(location);
1258
1259         return newnode;
1260 }
1261
1262 /*
1263  * _copyNullIfExpr (same as OpExpr)
1264  */
1265 static NullIfExpr *
1266 _copyNullIfExpr(const NullIfExpr *from)
1267 {
1268         NullIfExpr *newnode = makeNode(NullIfExpr);
1269
1270         COPY_SCALAR_FIELD(opno);
1271         COPY_SCALAR_FIELD(opfuncid);
1272         COPY_SCALAR_FIELD(opresulttype);
1273         COPY_SCALAR_FIELD(opretset);
1274         COPY_SCALAR_FIELD(opcollid);
1275         COPY_SCALAR_FIELD(inputcollid);
1276         COPY_NODE_FIELD(args);
1277         COPY_LOCATION_FIELD(location);
1278
1279         return newnode;
1280 }
1281
1282 /*
1283  * _copyScalarArrayOpExpr
1284  */
1285 static ScalarArrayOpExpr *
1286 _copyScalarArrayOpExpr(const ScalarArrayOpExpr *from)
1287 {
1288         ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
1289
1290         COPY_SCALAR_FIELD(opno);
1291         COPY_SCALAR_FIELD(opfuncid);
1292         COPY_SCALAR_FIELD(useOr);
1293         COPY_SCALAR_FIELD(inputcollid);
1294         COPY_NODE_FIELD(args);
1295         COPY_LOCATION_FIELD(location);
1296
1297         return newnode;
1298 }
1299
1300 /*
1301  * _copyBoolExpr
1302  */
1303 static BoolExpr *
1304 _copyBoolExpr(const BoolExpr *from)
1305 {
1306         BoolExpr   *newnode = makeNode(BoolExpr);
1307
1308         COPY_SCALAR_FIELD(boolop);
1309         COPY_NODE_FIELD(args);
1310         COPY_LOCATION_FIELD(location);
1311
1312         return newnode;
1313 }
1314
1315 /*
1316  * _copySubLink
1317  */
1318 static SubLink *
1319 _copySubLink(const SubLink *from)
1320 {
1321         SubLink    *newnode = makeNode(SubLink);
1322
1323         COPY_SCALAR_FIELD(subLinkType);
1324         COPY_NODE_FIELD(testexpr);
1325         COPY_NODE_FIELD(operName);
1326         COPY_NODE_FIELD(subselect);
1327         COPY_LOCATION_FIELD(location);
1328
1329         return newnode;
1330 }
1331
1332 /*
1333  * _copySubPlan
1334  */
1335 static SubPlan *
1336 _copySubPlan(const SubPlan *from)
1337 {
1338         SubPlan    *newnode = makeNode(SubPlan);
1339
1340         COPY_SCALAR_FIELD(subLinkType);
1341         COPY_NODE_FIELD(testexpr);
1342         COPY_NODE_FIELD(paramIds);
1343         COPY_SCALAR_FIELD(plan_id);
1344         COPY_STRING_FIELD(plan_name);
1345         COPY_SCALAR_FIELD(firstColType);
1346         COPY_SCALAR_FIELD(firstColTypmod);
1347         COPY_SCALAR_FIELD(firstColCollation);
1348         COPY_SCALAR_FIELD(useHashTable);
1349         COPY_SCALAR_FIELD(unknownEqFalse);
1350         COPY_NODE_FIELD(setParam);
1351         COPY_NODE_FIELD(parParam);
1352         COPY_NODE_FIELD(args);
1353         COPY_SCALAR_FIELD(startup_cost);
1354         COPY_SCALAR_FIELD(per_call_cost);
1355
1356         return newnode;
1357 }
1358
1359 /*
1360  * _copyAlternativeSubPlan
1361  */
1362 static AlternativeSubPlan *
1363 _copyAlternativeSubPlan(const AlternativeSubPlan *from)
1364 {
1365         AlternativeSubPlan *newnode = makeNode(AlternativeSubPlan);
1366
1367         COPY_NODE_FIELD(subplans);
1368
1369         return newnode;
1370 }
1371
1372 /*
1373  * _copyFieldSelect
1374  */
1375 static FieldSelect *
1376 _copyFieldSelect(const FieldSelect *from)
1377 {
1378         FieldSelect *newnode = makeNode(FieldSelect);
1379
1380         COPY_NODE_FIELD(arg);
1381         COPY_SCALAR_FIELD(fieldnum);
1382         COPY_SCALAR_FIELD(resulttype);
1383         COPY_SCALAR_FIELD(resulttypmod);
1384         COPY_SCALAR_FIELD(resultcollid);
1385
1386         return newnode;
1387 }
1388
1389 /*
1390  * _copyFieldStore
1391  */
1392 static FieldStore *
1393 _copyFieldStore(const FieldStore *from)
1394 {
1395         FieldStore *newnode = makeNode(FieldStore);
1396
1397         COPY_NODE_FIELD(arg);
1398         COPY_NODE_FIELD(newvals);
1399         COPY_NODE_FIELD(fieldnums);
1400         COPY_SCALAR_FIELD(resulttype);
1401
1402         return newnode;
1403 }
1404
1405 /*
1406  * _copyRelabelType
1407  */
1408 static RelabelType *
1409 _copyRelabelType(const RelabelType *from)
1410 {
1411         RelabelType *newnode = makeNode(RelabelType);
1412
1413         COPY_NODE_FIELD(arg);
1414         COPY_SCALAR_FIELD(resulttype);
1415         COPY_SCALAR_FIELD(resulttypmod);
1416         COPY_SCALAR_FIELD(resultcollid);
1417         COPY_SCALAR_FIELD(relabelformat);
1418         COPY_LOCATION_FIELD(location);
1419
1420         return newnode;
1421 }
1422
1423 /*
1424  * _copyCoerceViaIO
1425  */
1426 static CoerceViaIO *
1427 _copyCoerceViaIO(const CoerceViaIO *from)
1428 {
1429         CoerceViaIO *newnode = makeNode(CoerceViaIO);
1430
1431         COPY_NODE_FIELD(arg);
1432         COPY_SCALAR_FIELD(resulttype);
1433         COPY_SCALAR_FIELD(resultcollid);
1434         COPY_SCALAR_FIELD(coerceformat);
1435         COPY_LOCATION_FIELD(location);
1436
1437         return newnode;
1438 }
1439
1440 /*
1441  * _copyArrayCoerceExpr
1442  */
1443 static ArrayCoerceExpr *
1444 _copyArrayCoerceExpr(const ArrayCoerceExpr *from)
1445 {
1446         ArrayCoerceExpr *newnode = makeNode(ArrayCoerceExpr);
1447
1448         COPY_NODE_FIELD(arg);
1449         COPY_SCALAR_FIELD(elemfuncid);
1450         COPY_SCALAR_FIELD(resulttype);
1451         COPY_SCALAR_FIELD(resulttypmod);
1452         COPY_SCALAR_FIELD(resultcollid);
1453         COPY_SCALAR_FIELD(isExplicit);
1454         COPY_SCALAR_FIELD(coerceformat);
1455         COPY_LOCATION_FIELD(location);
1456
1457         return newnode;
1458 }
1459
1460 /*
1461  * _copyConvertRowtypeExpr
1462  */
1463 static ConvertRowtypeExpr *
1464 _copyConvertRowtypeExpr(const ConvertRowtypeExpr *from)
1465 {
1466         ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);
1467
1468         COPY_NODE_FIELD(arg);
1469         COPY_SCALAR_FIELD(resulttype);
1470         COPY_SCALAR_FIELD(convertformat);
1471         COPY_LOCATION_FIELD(location);
1472
1473         return newnode;
1474 }
1475
1476 /*
1477  * _copyCollateExpr
1478  */
1479 static CollateExpr *
1480 _copyCollateExpr(const CollateExpr *from)
1481 {
1482         CollateExpr *newnode = makeNode(CollateExpr);
1483
1484         COPY_NODE_FIELD(arg);
1485         COPY_SCALAR_FIELD(collOid);
1486         COPY_LOCATION_FIELD(location);
1487
1488         return newnode;
1489 }
1490
1491 /*
1492  * _copyCaseExpr
1493  */
1494 static CaseExpr *
1495 _copyCaseExpr(const CaseExpr *from)
1496 {
1497         CaseExpr   *newnode = makeNode(CaseExpr);
1498
1499         COPY_SCALAR_FIELD(casetype);
1500         COPY_SCALAR_FIELD(casecollid);
1501         COPY_NODE_FIELD(arg);
1502         COPY_NODE_FIELD(args);
1503         COPY_NODE_FIELD(defresult);
1504         COPY_LOCATION_FIELD(location);
1505
1506         return newnode;
1507 }
1508
1509 /*
1510  * _copyCaseWhen
1511  */
1512 static CaseWhen *
1513 _copyCaseWhen(const CaseWhen *from)
1514 {
1515         CaseWhen   *newnode = makeNode(CaseWhen);
1516
1517         COPY_NODE_FIELD(expr);
1518         COPY_NODE_FIELD(result);
1519         COPY_LOCATION_FIELD(location);
1520
1521         return newnode;
1522 }
1523
1524 /*
1525  * _copyCaseTestExpr
1526  */
1527 static CaseTestExpr *
1528 _copyCaseTestExpr(const CaseTestExpr *from)
1529 {
1530         CaseTestExpr *newnode = makeNode(CaseTestExpr);
1531
1532         COPY_SCALAR_FIELD(typeId);
1533         COPY_SCALAR_FIELD(typeMod);
1534         COPY_SCALAR_FIELD(collation);
1535
1536         return newnode;
1537 }
1538
1539 /*
1540  * _copyArrayExpr
1541  */
1542 static ArrayExpr *
1543 _copyArrayExpr(const ArrayExpr *from)
1544 {
1545         ArrayExpr  *newnode = makeNode(ArrayExpr);
1546
1547         COPY_SCALAR_FIELD(array_typeid);
1548         COPY_SCALAR_FIELD(array_collid);
1549         COPY_SCALAR_FIELD(element_typeid);
1550         COPY_NODE_FIELD(elements);
1551         COPY_SCALAR_FIELD(multidims);
1552         COPY_LOCATION_FIELD(location);
1553
1554         return newnode;
1555 }
1556
1557 /*
1558  * _copyRowExpr
1559  */
1560 static RowExpr *
1561 _copyRowExpr(const RowExpr *from)
1562 {
1563         RowExpr    *newnode = makeNode(RowExpr);
1564
1565         COPY_NODE_FIELD(args);
1566         COPY_SCALAR_FIELD(row_typeid);
1567         COPY_SCALAR_FIELD(row_format);
1568         COPY_NODE_FIELD(colnames);
1569         COPY_LOCATION_FIELD(location);
1570
1571         return newnode;
1572 }
1573
1574 /*
1575  * _copyRowCompareExpr
1576  */
1577 static RowCompareExpr *
1578 _copyRowCompareExpr(const RowCompareExpr *from)
1579 {
1580         RowCompareExpr *newnode = makeNode(RowCompareExpr);
1581
1582         COPY_SCALAR_FIELD(rctype);
1583         COPY_NODE_FIELD(opnos);
1584         COPY_NODE_FIELD(opfamilies);
1585         COPY_NODE_FIELD(inputcollids);
1586         COPY_NODE_FIELD(largs);
1587         COPY_NODE_FIELD(rargs);
1588
1589         return newnode;
1590 }
1591
1592 /*
1593  * _copyCoalesceExpr
1594  */
1595 static CoalesceExpr *
1596 _copyCoalesceExpr(const CoalesceExpr *from)
1597 {
1598         CoalesceExpr *newnode = makeNode(CoalesceExpr);
1599
1600         COPY_SCALAR_FIELD(coalescetype);
1601         COPY_SCALAR_FIELD(coalescecollid);
1602         COPY_NODE_FIELD(args);
1603         COPY_LOCATION_FIELD(location);
1604
1605         return newnode;
1606 }
1607
1608 /*
1609  * _copyMinMaxExpr
1610  */
1611 static MinMaxExpr *
1612 _copyMinMaxExpr(const MinMaxExpr *from)
1613 {
1614         MinMaxExpr *newnode = makeNode(MinMaxExpr);
1615
1616         COPY_SCALAR_FIELD(minmaxtype);
1617         COPY_SCALAR_FIELD(minmaxcollid);
1618         COPY_SCALAR_FIELD(inputcollid);
1619         COPY_SCALAR_FIELD(op);
1620         COPY_NODE_FIELD(args);
1621         COPY_LOCATION_FIELD(location);
1622
1623         return newnode;
1624 }
1625
1626 /*
1627  * _copyXmlExpr
1628  */
1629 static XmlExpr *
1630 _copyXmlExpr(const XmlExpr *from)
1631 {
1632         XmlExpr    *newnode = makeNode(XmlExpr);
1633
1634         COPY_SCALAR_FIELD(op);
1635         COPY_STRING_FIELD(name);
1636         COPY_NODE_FIELD(named_args);
1637         COPY_NODE_FIELD(arg_names);
1638         COPY_NODE_FIELD(args);
1639         COPY_SCALAR_FIELD(xmloption);
1640         COPY_SCALAR_FIELD(type);
1641         COPY_SCALAR_FIELD(typmod);
1642         COPY_LOCATION_FIELD(location);
1643
1644         return newnode;
1645 }
1646
1647 /*
1648  * _copyNullTest
1649  */
1650 static NullTest *
1651 _copyNullTest(const NullTest *from)
1652 {
1653         NullTest   *newnode = makeNode(NullTest);
1654
1655         COPY_NODE_FIELD(arg);
1656         COPY_SCALAR_FIELD(nulltesttype);
1657         COPY_SCALAR_FIELD(argisrow);
1658
1659         return newnode;
1660 }
1661
1662 /*
1663  * _copyBooleanTest
1664  */
1665 static BooleanTest *
1666 _copyBooleanTest(const BooleanTest *from)
1667 {
1668         BooleanTest *newnode = makeNode(BooleanTest);
1669
1670         COPY_NODE_FIELD(arg);
1671         COPY_SCALAR_FIELD(booltesttype);
1672
1673         return newnode;
1674 }
1675
1676 /*
1677  * _copyCoerceToDomain
1678  */
1679 static CoerceToDomain *
1680 _copyCoerceToDomain(const CoerceToDomain *from)
1681 {
1682         CoerceToDomain *newnode = makeNode(CoerceToDomain);
1683
1684         COPY_NODE_FIELD(arg);
1685         COPY_SCALAR_FIELD(resulttype);
1686         COPY_SCALAR_FIELD(resulttypmod);
1687         COPY_SCALAR_FIELD(resultcollid);
1688         COPY_SCALAR_FIELD(coercionformat);
1689         COPY_LOCATION_FIELD(location);
1690
1691         return newnode;
1692 }
1693
1694 /*
1695  * _copyCoerceToDomainValue
1696  */
1697 static CoerceToDomainValue *
1698 _copyCoerceToDomainValue(const CoerceToDomainValue *from)
1699 {
1700         CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1701
1702         COPY_SCALAR_FIELD(typeId);
1703         COPY_SCALAR_FIELD(typeMod);
1704         COPY_SCALAR_FIELD(collation);
1705         COPY_LOCATION_FIELD(location);
1706
1707         return newnode;
1708 }
1709
1710 /*
1711  * _copySetToDefault
1712  */
1713 static SetToDefault *
1714 _copySetToDefault(const SetToDefault *from)
1715 {
1716         SetToDefault *newnode = makeNode(SetToDefault);
1717
1718         COPY_SCALAR_FIELD(typeId);
1719         COPY_SCALAR_FIELD(typeMod);
1720         COPY_SCALAR_FIELD(collation);
1721         COPY_LOCATION_FIELD(location);
1722
1723         return newnode;
1724 }
1725
1726 /*
1727  * _copyCurrentOfExpr
1728  */
1729 static CurrentOfExpr *
1730 _copyCurrentOfExpr(const CurrentOfExpr *from)
1731 {
1732         CurrentOfExpr *newnode = makeNode(CurrentOfExpr);
1733
1734         COPY_SCALAR_FIELD(cvarno);
1735         COPY_STRING_FIELD(cursor_name);
1736         COPY_SCALAR_FIELD(cursor_param);
1737
1738         return newnode;
1739 }
1740
1741 /*
1742  * _copyTargetEntry
1743  */
1744 static TargetEntry *
1745 _copyTargetEntry(const TargetEntry *from)
1746 {
1747         TargetEntry *newnode = makeNode(TargetEntry);
1748
1749         COPY_NODE_FIELD(expr);
1750         COPY_SCALAR_FIELD(resno);
1751         COPY_STRING_FIELD(resname);
1752         COPY_SCALAR_FIELD(ressortgroupref);
1753         COPY_SCALAR_FIELD(resorigtbl);
1754         COPY_SCALAR_FIELD(resorigcol);
1755         COPY_SCALAR_FIELD(resjunk);
1756
1757         return newnode;
1758 }
1759
1760 /*
1761  * _copyRangeTblRef
1762  */
1763 static RangeTblRef *
1764 _copyRangeTblRef(const RangeTblRef *from)
1765 {
1766         RangeTblRef *newnode = makeNode(RangeTblRef);
1767
1768         COPY_SCALAR_FIELD(rtindex);
1769
1770         return newnode;
1771 }
1772
1773 /*
1774  * _copyJoinExpr
1775  */
1776 static JoinExpr *
1777 _copyJoinExpr(const JoinExpr *from)
1778 {
1779         JoinExpr   *newnode = makeNode(JoinExpr);
1780
1781         COPY_SCALAR_FIELD(jointype);
1782         COPY_SCALAR_FIELD(isNatural);
1783         COPY_NODE_FIELD(larg);
1784         COPY_NODE_FIELD(rarg);
1785         COPY_NODE_FIELD(usingClause);
1786         COPY_NODE_FIELD(quals);
1787         COPY_NODE_FIELD(alias);
1788         COPY_SCALAR_FIELD(rtindex);
1789
1790         return newnode;
1791 }
1792
1793 /*
1794  * _copyFromExpr
1795  */
1796 static FromExpr *
1797 _copyFromExpr(const FromExpr *from)
1798 {
1799         FromExpr   *newnode = makeNode(FromExpr);
1800
1801         COPY_NODE_FIELD(fromlist);
1802         COPY_NODE_FIELD(quals);
1803
1804         return newnode;
1805 }
1806
1807 /* ****************************************************************
1808  *                                              relation.h copy functions
1809  *
1810  * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1811  * There are some subsidiary structs that are useful to copy, though.
1812  * ****************************************************************
1813  */
1814
1815 /*
1816  * _copyPathKey
1817  */
1818 static PathKey *
1819 _copyPathKey(const PathKey *from)
1820 {
1821         PathKey    *newnode = makeNode(PathKey);
1822
1823         /* EquivalenceClasses are never moved, so just shallow-copy the pointer */
1824         COPY_SCALAR_FIELD(pk_eclass);
1825         COPY_SCALAR_FIELD(pk_opfamily);
1826         COPY_SCALAR_FIELD(pk_strategy);
1827         COPY_SCALAR_FIELD(pk_nulls_first);
1828
1829         return newnode;
1830 }
1831
1832 /*
1833  * _copyRestrictInfo
1834  */
1835 static RestrictInfo *
1836 _copyRestrictInfo(const RestrictInfo *from)
1837 {
1838         RestrictInfo *newnode = makeNode(RestrictInfo);
1839
1840         COPY_NODE_FIELD(clause);
1841         COPY_SCALAR_FIELD(is_pushed_down);
1842         COPY_SCALAR_FIELD(outerjoin_delayed);
1843         COPY_SCALAR_FIELD(can_join);
1844         COPY_SCALAR_FIELD(pseudoconstant);
1845         COPY_BITMAPSET_FIELD(clause_relids);
1846         COPY_BITMAPSET_FIELD(required_relids);
1847         COPY_BITMAPSET_FIELD(outer_relids);
1848         COPY_BITMAPSET_FIELD(nullable_relids);
1849         COPY_BITMAPSET_FIELD(left_relids);
1850         COPY_BITMAPSET_FIELD(right_relids);
1851         COPY_NODE_FIELD(orclause);
1852         /* EquivalenceClasses are never copied, so shallow-copy the pointers */
1853         COPY_SCALAR_FIELD(parent_ec);
1854         COPY_SCALAR_FIELD(eval_cost);
1855         COPY_SCALAR_FIELD(norm_selec);
1856         COPY_SCALAR_FIELD(outer_selec);
1857         COPY_NODE_FIELD(mergeopfamilies);
1858         /* EquivalenceClasses are never copied, so shallow-copy the pointers */
1859         COPY_SCALAR_FIELD(left_ec);
1860         COPY_SCALAR_FIELD(right_ec);
1861         COPY_SCALAR_FIELD(left_em);
1862         COPY_SCALAR_FIELD(right_em);
1863         /* MergeScanSelCache isn't a Node, so hard to copy; just reset cache */
1864         newnode->scansel_cache = NIL;
1865         COPY_SCALAR_FIELD(outer_is_left);
1866         COPY_SCALAR_FIELD(hashjoinoperator);
1867         COPY_SCALAR_FIELD(left_bucketsize);
1868         COPY_SCALAR_FIELD(right_bucketsize);
1869
1870         return newnode;
1871 }
1872
1873 /*
1874  * _copyPlaceHolderVar
1875  */
1876 static PlaceHolderVar *
1877 _copyPlaceHolderVar(const PlaceHolderVar *from)
1878 {
1879         PlaceHolderVar *newnode = makeNode(PlaceHolderVar);
1880
1881         COPY_NODE_FIELD(phexpr);
1882         COPY_BITMAPSET_FIELD(phrels);
1883         COPY_SCALAR_FIELD(phid);
1884         COPY_SCALAR_FIELD(phlevelsup);
1885
1886         return newnode;
1887 }
1888
1889 /*
1890  * _copySpecialJoinInfo
1891  */
1892 static SpecialJoinInfo *
1893 _copySpecialJoinInfo(const SpecialJoinInfo *from)
1894 {
1895         SpecialJoinInfo *newnode = makeNode(SpecialJoinInfo);
1896
1897         COPY_BITMAPSET_FIELD(min_lefthand);
1898         COPY_BITMAPSET_FIELD(min_righthand);
1899         COPY_BITMAPSET_FIELD(syn_lefthand);
1900         COPY_BITMAPSET_FIELD(syn_righthand);
1901         COPY_SCALAR_FIELD(jointype);
1902         COPY_SCALAR_FIELD(lhs_strict);
1903         COPY_SCALAR_FIELD(delay_upper_joins);
1904         COPY_NODE_FIELD(join_quals);
1905
1906         return newnode;
1907 }
1908
1909 /*
1910  * _copyLateralJoinInfo
1911  */
1912 static LateralJoinInfo *
1913 _copyLateralJoinInfo(const LateralJoinInfo *from)
1914 {
1915         LateralJoinInfo *newnode = makeNode(LateralJoinInfo);
1916
1917         COPY_SCALAR_FIELD(lateral_rhs);
1918         COPY_BITMAPSET_FIELD(lateral_lhs);
1919
1920         return newnode;
1921 }
1922
1923 /*
1924  * _copyAppendRelInfo
1925  */
1926 static AppendRelInfo *
1927 _copyAppendRelInfo(const AppendRelInfo *from)
1928 {
1929         AppendRelInfo *newnode = makeNode(AppendRelInfo);
1930
1931         COPY_SCALAR_FIELD(parent_relid);
1932         COPY_SCALAR_FIELD(child_relid);
1933         COPY_SCALAR_FIELD(parent_reltype);
1934         COPY_SCALAR_FIELD(child_reltype);
1935         COPY_NODE_FIELD(translated_vars);
1936         COPY_SCALAR_FIELD(parent_reloid);
1937
1938         return newnode;
1939 }
1940
1941 /*
1942  * _copyPlaceHolderInfo
1943  */
1944 static PlaceHolderInfo *
1945 _copyPlaceHolderInfo(const PlaceHolderInfo *from)
1946 {
1947         PlaceHolderInfo *newnode = makeNode(PlaceHolderInfo);
1948
1949         COPY_SCALAR_FIELD(phid);
1950         COPY_NODE_FIELD(ph_var);
1951         COPY_BITMAPSET_FIELD(ph_eval_at);
1952         COPY_BITMAPSET_FIELD(ph_needed);
1953         COPY_BITMAPSET_FIELD(ph_may_need);
1954         COPY_SCALAR_FIELD(ph_width);
1955
1956         return newnode;
1957 }
1958
1959 /* ****************************************************************
1960  *                                      parsenodes.h copy functions
1961  * ****************************************************************
1962  */
1963
1964 static RangeTblEntry *
1965 _copyRangeTblEntry(const RangeTblEntry *from)
1966 {
1967         RangeTblEntry *newnode = makeNode(RangeTblEntry);
1968
1969         COPY_SCALAR_FIELD(rtekind);
1970         COPY_SCALAR_FIELD(relid);
1971         COPY_SCALAR_FIELD(relkind);
1972         COPY_NODE_FIELD(subquery);
1973         COPY_SCALAR_FIELD(security_barrier);
1974         COPY_SCALAR_FIELD(jointype);
1975         COPY_NODE_FIELD(joinaliasvars);
1976         COPY_NODE_FIELD(funcexpr);
1977         COPY_NODE_FIELD(funccoltypes);
1978         COPY_NODE_FIELD(funccoltypmods);
1979         COPY_NODE_FIELD(funccolcollations);
1980         COPY_NODE_FIELD(values_lists);
1981         COPY_NODE_FIELD(values_collations);
1982         COPY_STRING_FIELD(ctename);
1983         COPY_SCALAR_FIELD(ctelevelsup);
1984         COPY_SCALAR_FIELD(self_reference);
1985         COPY_NODE_FIELD(ctecoltypes);
1986         COPY_NODE_FIELD(ctecoltypmods);
1987         COPY_NODE_FIELD(ctecolcollations);
1988         COPY_NODE_FIELD(alias);
1989         COPY_NODE_FIELD(eref);
1990         COPY_SCALAR_FIELD(lateral);
1991         COPY_SCALAR_FIELD(inh);
1992         COPY_SCALAR_FIELD(inFromCl);
1993         COPY_SCALAR_FIELD(requiredPerms);
1994         COPY_SCALAR_FIELD(checkAsUser);
1995         COPY_BITMAPSET_FIELD(selectedCols);
1996         COPY_BITMAPSET_FIELD(modifiedCols);
1997
1998         return newnode;
1999 }
2000
2001 static SortGroupClause *
2002 _copySortGroupClause(const SortGroupClause *from)
2003 {
2004         SortGroupClause *newnode = makeNode(SortGroupClause);
2005
2006         COPY_SCALAR_FIELD(tleSortGroupRef);
2007         COPY_SCALAR_FIELD(eqop);
2008         COPY_SCALAR_FIELD(sortop);
2009         COPY_SCALAR_FIELD(nulls_first);
2010         COPY_SCALAR_FIELD(hashable);
2011
2012         return newnode;
2013 }
2014
2015 static WindowClause *
2016 _copyWindowClause(const WindowClause *from)
2017 {
2018         WindowClause *newnode = makeNode(WindowClause);
2019
2020         COPY_STRING_FIELD(name);
2021         COPY_STRING_FIELD(refname);
2022         COPY_NODE_FIELD(partitionClause);
2023         COPY_NODE_FIELD(orderClause);
2024         COPY_SCALAR_FIELD(frameOptions);
2025         COPY_NODE_FIELD(startOffset);
2026         COPY_NODE_FIELD(endOffset);
2027         COPY_SCALAR_FIELD(winref);
2028         COPY_SCALAR_FIELD(copiedOrder);
2029
2030         return newnode;
2031 }
2032
2033 static RowMarkClause *
2034 _copyRowMarkClause(const RowMarkClause *from)
2035 {
2036         RowMarkClause *newnode = makeNode(RowMarkClause);
2037
2038         COPY_SCALAR_FIELD(rti);
2039         COPY_SCALAR_FIELD(forUpdate);
2040         COPY_SCALAR_FIELD(noWait);
2041         COPY_SCALAR_FIELD(pushedDown);
2042
2043         return newnode;
2044 }
2045
2046 static WithClause *
2047 _copyWithClause(const WithClause *from)
2048 {
2049         WithClause *newnode = makeNode(WithClause);
2050
2051         COPY_NODE_FIELD(ctes);
2052         COPY_SCALAR_FIELD(recursive);
2053         COPY_LOCATION_FIELD(location);
2054
2055         return newnode;
2056 }
2057
2058 static CommonTableExpr *
2059 _copyCommonTableExpr(const CommonTableExpr *from)
2060 {
2061         CommonTableExpr *newnode = makeNode(CommonTableExpr);
2062
2063         COPY_STRING_FIELD(ctename);
2064         COPY_NODE_FIELD(aliascolnames);
2065         COPY_NODE_FIELD(ctequery);
2066         COPY_LOCATION_FIELD(location);
2067         COPY_SCALAR_FIELD(cterecursive);
2068         COPY_SCALAR_FIELD(cterefcount);
2069         COPY_NODE_FIELD(ctecolnames);
2070         COPY_NODE_FIELD(ctecoltypes);
2071         COPY_NODE_FIELD(ctecoltypmods);
2072         COPY_NODE_FIELD(ctecolcollations);
2073
2074         return newnode;
2075 }
2076
2077 static A_Expr *
2078 _copyAExpr(const A_Expr *from)
2079 {
2080         A_Expr     *newnode = makeNode(A_Expr);
2081
2082         COPY_SCALAR_FIELD(kind);
2083         COPY_NODE_FIELD(name);
2084         COPY_NODE_FIELD(lexpr);
2085         COPY_NODE_FIELD(rexpr);
2086         COPY_LOCATION_FIELD(location);
2087
2088         return newnode;
2089 }
2090
2091 static ColumnRef *
2092 _copyColumnRef(const ColumnRef *from)
2093 {
2094         ColumnRef  *newnode = makeNode(ColumnRef);
2095
2096         COPY_NODE_FIELD(fields);
2097         COPY_LOCATION_FIELD(location);
2098
2099         return newnode;
2100 }
2101
2102 static ParamRef *
2103 _copyParamRef(const ParamRef *from)
2104 {
2105         ParamRef   *newnode = makeNode(ParamRef);
2106
2107         COPY_SCALAR_FIELD(number);
2108         COPY_LOCATION_FIELD(location);
2109
2110         return newnode;
2111 }
2112
2113 static A_Const *
2114 _copyAConst(const A_Const *from)
2115 {
2116         A_Const    *newnode = makeNode(A_Const);
2117
2118         /* This part must duplicate _copyValue */
2119         COPY_SCALAR_FIELD(val.type);
2120         switch (from->val.type)
2121         {
2122                 case T_Integer:
2123                         COPY_SCALAR_FIELD(val.val.ival);
2124                         break;
2125                 case T_Float:
2126                 case T_String:
2127                 case T_BitString:
2128                         COPY_STRING_FIELD(val.val.str);
2129                         break;
2130                 case T_Null:
2131                         /* nothing to do */
2132                         break;
2133                 default:
2134                         elog(ERROR, "unrecognized node type: %d",
2135                                  (int) from->val.type);
2136                         break;
2137         }
2138
2139         COPY_LOCATION_FIELD(location);
2140
2141         return newnode;
2142 }
2143
2144 static FuncCall *
2145 _copyFuncCall(const FuncCall *from)
2146 {
2147         FuncCall   *newnode = makeNode(FuncCall);
2148
2149         COPY_NODE_FIELD(funcname);
2150         COPY_NODE_FIELD(args);
2151         COPY_NODE_FIELD(agg_order);
2152         COPY_SCALAR_FIELD(agg_star);
2153         COPY_SCALAR_FIELD(agg_distinct);
2154         COPY_SCALAR_FIELD(func_variadic);
2155         COPY_NODE_FIELD(over);
2156         COPY_LOCATION_FIELD(location);
2157
2158         return newnode;
2159 }
2160
2161 static A_Star *
2162 _copyAStar(const A_Star *from)
2163 {
2164         A_Star     *newnode = makeNode(A_Star);
2165
2166         return newnode;
2167 }
2168
2169 static A_Indices *
2170 _copyAIndices(const A_Indices *from)
2171 {
2172         A_Indices  *newnode = makeNode(A_Indices);
2173
2174         COPY_NODE_FIELD(lidx);
2175         COPY_NODE_FIELD(uidx);
2176
2177         return newnode;
2178 }
2179
2180 static A_Indirection *
2181 _copyA_Indirection(const A_Indirection *from)
2182 {
2183         A_Indirection *newnode = makeNode(A_Indirection);
2184
2185         COPY_NODE_FIELD(arg);
2186         COPY_NODE_FIELD(indirection);
2187
2188         return newnode;
2189 }
2190
2191 static A_ArrayExpr *
2192 _copyA_ArrayExpr(const A_ArrayExpr *from)
2193 {
2194         A_ArrayExpr *newnode = makeNode(A_ArrayExpr);
2195
2196         COPY_NODE_FIELD(elements);
2197         COPY_LOCATION_FIELD(location);
2198
2199         return newnode;
2200 }
2201
2202 static ResTarget *
2203 _copyResTarget(const ResTarget *from)
2204 {
2205         ResTarget  *newnode = makeNode(ResTarget);
2206
2207         COPY_STRING_FIELD(name);
2208         COPY_NODE_FIELD(indirection);
2209         COPY_NODE_FIELD(val);
2210         COPY_LOCATION_FIELD(location);
2211
2212         return newnode;
2213 }
2214
2215 static TypeName *
2216 _copyTypeName(const TypeName *from)
2217 {
2218         TypeName   *newnode = makeNode(TypeName);
2219
2220         COPY_NODE_FIELD(names);
2221         COPY_SCALAR_FIELD(typeOid);
2222         COPY_SCALAR_FIELD(setof);
2223         COPY_SCALAR_FIELD(pct_type);
2224         COPY_NODE_FIELD(typmods);
2225         COPY_SCALAR_FIELD(typemod);
2226         COPY_NODE_FIELD(arrayBounds);
2227         COPY_LOCATION_FIELD(location);
2228
2229         return newnode;
2230 }
2231
2232 static SortBy *
2233 _copySortBy(const SortBy *from)
2234 {
2235         SortBy     *newnode = makeNode(SortBy);
2236
2237         COPY_NODE_FIELD(node);
2238         COPY_SCALAR_FIELD(sortby_dir);
2239         COPY_SCALAR_FIELD(sortby_nulls);
2240         COPY_NODE_FIELD(useOp);
2241         COPY_LOCATION_FIELD(location);
2242
2243         return newnode;
2244 }
2245
2246 static WindowDef *
2247 _copyWindowDef(const WindowDef *from)
2248 {
2249         WindowDef  *newnode = makeNode(WindowDef);
2250
2251         COPY_STRING_FIELD(name);
2252         COPY_STRING_FIELD(refname);
2253         COPY_NODE_FIELD(partitionClause);
2254         COPY_NODE_FIELD(orderClause);
2255         COPY_SCALAR_FIELD(frameOptions);
2256         COPY_NODE_FIELD(startOffset);
2257         COPY_NODE_FIELD(endOffset);
2258         COPY_LOCATION_FIELD(location);
2259
2260         return newnode;
2261 }
2262
2263 static RangeSubselect *
2264 _copyRangeSubselect(const RangeSubselect *from)
2265 {
2266         RangeSubselect *newnode = makeNode(RangeSubselect);
2267
2268         COPY_SCALAR_FIELD(lateral);
2269         COPY_NODE_FIELD(subquery);
2270         COPY_NODE_FIELD(alias);
2271
2272         return newnode;
2273 }
2274
2275 static RangeFunction *
2276 _copyRangeFunction(const RangeFunction *from)
2277 {
2278         RangeFunction *newnode = makeNode(RangeFunction);
2279
2280         COPY_SCALAR_FIELD(lateral);
2281         COPY_NODE_FIELD(funccallnode);
2282         COPY_NODE_FIELD(alias);
2283         COPY_NODE_FIELD(coldeflist);
2284
2285         return newnode;
2286 }
2287
2288 static TypeCast *
2289 _copyTypeCast(const TypeCast *from)
2290 {
2291         TypeCast   *newnode = makeNode(TypeCast);
2292
2293         COPY_NODE_FIELD(arg);
2294         COPY_NODE_FIELD(typeName);
2295         COPY_LOCATION_FIELD(location);
2296
2297         return newnode;
2298 }
2299
2300 static CollateClause *
2301 _copyCollateClause(const CollateClause *from)
2302 {
2303         CollateClause *newnode = makeNode(CollateClause);
2304
2305         COPY_NODE_FIELD(arg);
2306         COPY_NODE_FIELD(collname);
2307         COPY_LOCATION_FIELD(location);
2308
2309         return newnode;
2310 }
2311
2312 static IndexElem *
2313 _copyIndexElem(const IndexElem *from)
2314 {
2315         IndexElem  *newnode = makeNode(IndexElem);
2316
2317         COPY_STRING_FIELD(name);
2318         COPY_NODE_FIELD(expr);
2319         COPY_STRING_FIELD(indexcolname);
2320         COPY_NODE_FIELD(collation);
2321         COPY_NODE_FIELD(opclass);
2322         COPY_SCALAR_FIELD(ordering);
2323         COPY_SCALAR_FIELD(nulls_ordering);
2324
2325         return newnode;
2326 }
2327
2328 static ColumnDef *
2329 _copyColumnDef(const ColumnDef *from)
2330 {
2331         ColumnDef  *newnode = makeNode(ColumnDef);
2332
2333         COPY_STRING_FIELD(colname);
2334         COPY_NODE_FIELD(typeName);
2335         COPY_SCALAR_FIELD(inhcount);
2336         COPY_SCALAR_FIELD(is_local);
2337         COPY_SCALAR_FIELD(is_not_null);
2338         COPY_SCALAR_FIELD(is_from_type);
2339         COPY_SCALAR_FIELD(storage);
2340         COPY_NODE_FIELD(raw_default);
2341         COPY_NODE_FIELD(cooked_default);
2342         COPY_NODE_FIELD(collClause);
2343         COPY_SCALAR_FIELD(collOid);
2344         COPY_NODE_FIELD(constraints);
2345         COPY_NODE_FIELD(fdwoptions);
2346
2347         return newnode;
2348 }
2349
2350 static Constraint *
2351 _copyConstraint(const Constraint *from)
2352 {
2353         Constraint *newnode = makeNode(Constraint);
2354
2355         COPY_SCALAR_FIELD(contype);
2356         COPY_STRING_FIELD(conname);
2357         COPY_SCALAR_FIELD(deferrable);
2358         COPY_SCALAR_FIELD(initdeferred);
2359         COPY_LOCATION_FIELD(location);
2360         COPY_SCALAR_FIELD(is_no_inherit);
2361         COPY_NODE_FIELD(raw_expr);
2362         COPY_STRING_FIELD(cooked_expr);
2363         COPY_NODE_FIELD(keys);
2364         COPY_NODE_FIELD(exclusions);
2365         COPY_NODE_FIELD(options);
2366         COPY_STRING_FIELD(indexname);
2367         COPY_STRING_FIELD(indexspace);
2368         COPY_STRING_FIELD(access_method);
2369         COPY_NODE_FIELD(where_clause);
2370         COPY_NODE_FIELD(pktable);
2371         COPY_NODE_FIELD(fk_attrs);
2372         COPY_NODE_FIELD(pk_attrs);
2373         COPY_SCALAR_FIELD(fk_matchtype);
2374         COPY_SCALAR_FIELD(fk_upd_action);
2375         COPY_SCALAR_FIELD(fk_del_action);
2376         COPY_NODE_FIELD(old_conpfeqop);
2377         COPY_SCALAR_FIELD(skip_validation);
2378         COPY_SCALAR_FIELD(initially_valid);
2379
2380         return newnode;
2381 }
2382
2383 static DefElem *
2384 _copyDefElem(const DefElem *from)
2385 {
2386         DefElem    *newnode = makeNode(DefElem);
2387
2388         COPY_STRING_FIELD(defnamespace);
2389         COPY_STRING_FIELD(defname);
2390         COPY_NODE_FIELD(arg);
2391         COPY_SCALAR_FIELD(defaction);
2392
2393         return newnode;
2394 }
2395
2396 static LockingClause *
2397 _copyLockingClause(const LockingClause *from)
2398 {
2399         LockingClause *newnode = makeNode(LockingClause);
2400
2401         COPY_NODE_FIELD(lockedRels);
2402         COPY_SCALAR_FIELD(forUpdate);
2403         COPY_SCALAR_FIELD(noWait);
2404
2405         return newnode;
2406 }
2407
2408 static XmlSerialize *
2409 _copyXmlSerialize(const XmlSerialize *from)
2410 {
2411         XmlSerialize *newnode = makeNode(XmlSerialize);
2412
2413         COPY_SCALAR_FIELD(xmloption);
2414         COPY_NODE_FIELD(expr);
2415         COPY_NODE_FIELD(typeName);
2416         COPY_LOCATION_FIELD(location);
2417
2418         return newnode;
2419 }
2420
2421 static Query *
2422 _copyQuery(const Query *from)
2423 {
2424         Query      *newnode = makeNode(Query);
2425
2426         COPY_SCALAR_FIELD(commandType);
2427         COPY_SCALAR_FIELD(querySource);
2428         COPY_SCALAR_FIELD(queryId);
2429         COPY_SCALAR_FIELD(canSetTag);
2430         COPY_NODE_FIELD(utilityStmt);
2431         COPY_SCALAR_FIELD(resultRelation);
2432         COPY_SCALAR_FIELD(hasAggs);
2433         COPY_SCALAR_FIELD(hasWindowFuncs);
2434         COPY_SCALAR_FIELD(hasSubLinks);
2435         COPY_SCALAR_FIELD(hasDistinctOn);
2436         COPY_SCALAR_FIELD(hasRecursive);
2437         COPY_SCALAR_FIELD(hasModifyingCTE);
2438         COPY_SCALAR_FIELD(hasForUpdate);
2439         COPY_NODE_FIELD(cteList);
2440         COPY_NODE_FIELD(rtable);
2441         COPY_NODE_FIELD(jointree);
2442         COPY_NODE_FIELD(targetList);
2443         COPY_NODE_FIELD(returningList);
2444         COPY_NODE_FIELD(groupClause);
2445         COPY_NODE_FIELD(havingQual);
2446         COPY_NODE_FIELD(windowClause);
2447         COPY_NODE_FIELD(distinctClause);
2448         COPY_NODE_FIELD(sortClause);
2449         COPY_NODE_FIELD(limitOffset);
2450         COPY_NODE_FIELD(limitCount);
2451         COPY_NODE_FIELD(rowMarks);
2452         COPY_NODE_FIELD(setOperations);
2453         COPY_NODE_FIELD(constraintDeps);
2454
2455         return newnode;
2456 }
2457
2458 static InsertStmt *
2459 _copyInsertStmt(const InsertStmt *from)
2460 {
2461         InsertStmt *newnode = makeNode(InsertStmt);
2462
2463         COPY_NODE_FIELD(relation);
2464         COPY_NODE_FIELD(cols);
2465         COPY_NODE_FIELD(selectStmt);
2466         COPY_NODE_FIELD(returningList);
2467         COPY_NODE_FIELD(withClause);
2468
2469         return newnode;
2470 }
2471
2472 static DeleteStmt *
2473 _copyDeleteStmt(const DeleteStmt *from)
2474 {
2475         DeleteStmt *newnode = makeNode(DeleteStmt);
2476
2477         COPY_NODE_FIELD(relation);
2478         COPY_NODE_FIELD(usingClause);
2479         COPY_NODE_FIELD(whereClause);
2480         COPY_NODE_FIELD(returningList);
2481         COPY_NODE_FIELD(withClause);
2482
2483         return newnode;
2484 }
2485
2486 static UpdateStmt *
2487 _copyUpdateStmt(const UpdateStmt *from)
2488 {
2489         UpdateStmt *newnode = makeNode(UpdateStmt);
2490
2491         COPY_NODE_FIELD(relation);
2492         COPY_NODE_FIELD(targetList);
2493         COPY_NODE_FIELD(whereClause);
2494         COPY_NODE_FIELD(fromClause);
2495         COPY_NODE_FIELD(returningList);
2496         COPY_NODE_FIELD(withClause);
2497
2498         return newnode;
2499 }
2500
2501 static SelectStmt *
2502 _copySelectStmt(const SelectStmt *from)
2503 {
2504         SelectStmt *newnode = makeNode(SelectStmt);
2505
2506         COPY_NODE_FIELD(distinctClause);
2507         COPY_NODE_FIELD(intoClause);
2508         COPY_NODE_FIELD(targetList);
2509         COPY_NODE_FIELD(fromClause);
2510         COPY_NODE_FIELD(whereClause);
2511         COPY_NODE_FIELD(groupClause);
2512         COPY_NODE_FIELD(havingClause);
2513         COPY_NODE_FIELD(windowClause);
2514         COPY_NODE_FIELD(valuesLists);
2515         COPY_NODE_FIELD(sortClause);
2516         COPY_NODE_FIELD(limitOffset);
2517         COPY_NODE_FIELD(limitCount);
2518         COPY_NODE_FIELD(lockingClause);
2519         COPY_NODE_FIELD(withClause);
2520         COPY_SCALAR_FIELD(op);
2521         COPY_SCALAR_FIELD(all);
2522         COPY_NODE_FIELD(larg);
2523         COPY_NODE_FIELD(rarg);
2524
2525         return newnode;
2526 }
2527
2528 static SetOperationStmt *
2529 _copySetOperationStmt(const SetOperationStmt *from)
2530 {
2531         SetOperationStmt *newnode = makeNode(SetOperationStmt);
2532
2533         COPY_SCALAR_FIELD(op);
2534         COPY_SCALAR_FIELD(all);
2535         COPY_NODE_FIELD(larg);
2536         COPY_NODE_FIELD(rarg);
2537         COPY_NODE_FIELD(colTypes);
2538         COPY_NODE_FIELD(colTypmods);
2539         COPY_NODE_FIELD(colCollations);
2540         COPY_NODE_FIELD(groupClauses);
2541
2542         return newnode;
2543 }
2544
2545 static AlterTableStmt *
2546 _copyAlterTableStmt(const AlterTableStmt *from)
2547 {
2548         AlterTableStmt *newnode = makeNode(AlterTableStmt);
2549
2550         COPY_NODE_FIELD(relation);
2551         COPY_NODE_FIELD(cmds);
2552         COPY_SCALAR_FIELD(relkind);
2553         COPY_SCALAR_FIELD(missing_ok);
2554
2555         return newnode;
2556 }
2557
2558 static AlterTableCmd *
2559 _copyAlterTableCmd(const AlterTableCmd *from)
2560 {
2561         AlterTableCmd *newnode = makeNode(AlterTableCmd);
2562
2563         COPY_SCALAR_FIELD(subtype);
2564         COPY_STRING_FIELD(name);
2565         COPY_NODE_FIELD(def);
2566         COPY_SCALAR_FIELD(behavior);
2567         COPY_SCALAR_FIELD(missing_ok);
2568
2569         return newnode;
2570 }
2571
2572 static AlterDomainStmt *
2573 _copyAlterDomainStmt(const AlterDomainStmt *from)
2574 {
2575         AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
2576
2577         COPY_SCALAR_FIELD(subtype);
2578         COPY_NODE_FIELD(typeName);
2579         COPY_STRING_FIELD(name);
2580         COPY_NODE_FIELD(def);
2581         COPY_SCALAR_FIELD(behavior);
2582         COPY_SCALAR_FIELD(missing_ok);
2583
2584         return newnode;
2585 }
2586
2587 static GrantStmt *
2588 _copyGrantStmt(const GrantStmt *from)
2589 {
2590         GrantStmt  *newnode = makeNode(GrantStmt);
2591
2592         COPY_SCALAR_FIELD(is_grant);
2593         COPY_SCALAR_FIELD(targtype);
2594         COPY_SCALAR_FIELD(objtype);
2595         COPY_NODE_FIELD(objects);
2596         COPY_NODE_FIELD(privileges);
2597         COPY_NODE_FIELD(grantees);
2598         COPY_SCALAR_FIELD(grant_option);
2599         COPY_SCALAR_FIELD(behavior);
2600
2601         return newnode;
2602 }
2603
2604 static PrivGrantee *
2605 _copyPrivGrantee(const PrivGrantee *from)
2606 {
2607         PrivGrantee *newnode = makeNode(PrivGrantee);
2608
2609         COPY_STRING_FIELD(rolname);
2610
2611         return newnode;
2612 }
2613
2614 static FuncWithArgs *
2615 _copyFuncWithArgs(const FuncWithArgs *from)
2616 {
2617         FuncWithArgs *newnode = makeNode(FuncWithArgs);
2618
2619         COPY_NODE_FIELD(funcname);
2620         COPY_NODE_FIELD(funcargs);
2621
2622         return newnode;
2623 }
2624
2625 static AccessPriv *
2626 _copyAccessPriv(const AccessPriv *from)
2627 {
2628         AccessPriv *newnode = makeNode(AccessPriv);
2629
2630         COPY_STRING_FIELD(priv_name);
2631         COPY_NODE_FIELD(cols);
2632
2633         return newnode;
2634 }
2635
2636 static GrantRoleStmt *
2637 _copyGrantRoleStmt(const GrantRoleStmt *from)
2638 {
2639         GrantRoleStmt *newnode = makeNode(GrantRoleStmt);
2640
2641         COPY_NODE_FIELD(granted_roles);
2642         COPY_NODE_FIELD(grantee_roles);
2643         COPY_SCALAR_FIELD(is_grant);
2644         COPY_SCALAR_FIELD(admin_opt);
2645         COPY_STRING_FIELD(grantor);
2646         COPY_SCALAR_FIELD(behavior);
2647
2648         return newnode;
2649 }
2650
2651 static AlterDefaultPrivilegesStmt *
2652 _copyAlterDefaultPrivilegesStmt(const AlterDefaultPrivilegesStmt *from)
2653 {
2654         AlterDefaultPrivilegesStmt *newnode = makeNode(AlterDefaultPrivilegesStmt);
2655
2656         COPY_NODE_FIELD(options);
2657         COPY_NODE_FIELD(action);
2658
2659         return newnode;
2660 }
2661
2662 static DeclareCursorStmt *
2663 _copyDeclareCursorStmt(const DeclareCursorStmt *from)
2664 {
2665         DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
2666
2667         COPY_STRING_FIELD(portalname);
2668         COPY_SCALAR_FIELD(options);
2669         COPY_NODE_FIELD(query);
2670
2671         return newnode;
2672 }
2673
2674 static ClosePortalStmt *
2675 _copyClosePortalStmt(const ClosePortalStmt *from)
2676 {
2677         ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
2678
2679         COPY_STRING_FIELD(portalname);
2680
2681         return newnode;
2682 }
2683
2684 static ClusterStmt *
2685 _copyClusterStmt(const ClusterStmt *from)
2686 {
2687         ClusterStmt *newnode = makeNode(ClusterStmt);
2688
2689         COPY_NODE_FIELD(relation);
2690         COPY_STRING_FIELD(indexname);
2691         COPY_SCALAR_FIELD(verbose);
2692
2693         return newnode;
2694 }
2695
2696 static CopyStmt *
2697 _copyCopyStmt(const CopyStmt *from)
2698 {
2699         CopyStmt   *newnode = makeNode(CopyStmt);
2700
2701         COPY_NODE_FIELD(relation);
2702         COPY_NODE_FIELD(query);
2703         COPY_NODE_FIELD(attlist);
2704         COPY_SCALAR_FIELD(is_from);
2705         COPY_STRING_FIELD(filename);
2706         COPY_NODE_FIELD(options);
2707
2708         return newnode;
2709 }
2710
2711 /*
2712  * CopyCreateStmtFields
2713  *
2714  *              This function copies the fields of the CreateStmt node.  It is used by
2715  *              copy functions for classes which inherit from CreateStmt.
2716  */
2717 static void
2718 CopyCreateStmtFields(const CreateStmt *from, CreateStmt *newnode)
2719 {
2720         COPY_NODE_FIELD(relation);
2721         COPY_NODE_FIELD(tableElts);
2722         COPY_NODE_FIELD(inhRelations);
2723         COPY_NODE_FIELD(ofTypename);
2724         COPY_NODE_FIELD(constraints);
2725         COPY_NODE_FIELD(options);
2726         COPY_SCALAR_FIELD(oncommit);
2727         COPY_STRING_FIELD(tablespacename);
2728         COPY_SCALAR_FIELD(if_not_exists);
2729 }
2730
2731 static CreateStmt *
2732 _copyCreateStmt(const CreateStmt *from)
2733 {
2734         CreateStmt *newnode = makeNode(CreateStmt);
2735
2736         CopyCreateStmtFields(from, newnode);
2737
2738         return newnode;
2739 }
2740
2741 static TableLikeClause *
2742 _copyTableLikeClause(const TableLikeClause *from)
2743 {
2744         TableLikeClause *newnode = makeNode(TableLikeClause);
2745
2746         COPY_NODE_FIELD(relation);
2747         COPY_SCALAR_FIELD(options);
2748
2749         return newnode;
2750 }
2751
2752 static DefineStmt *
2753 _copyDefineStmt(const DefineStmt *from)
2754 {
2755         DefineStmt *newnode = makeNode(DefineStmt);
2756
2757         COPY_SCALAR_FIELD(kind);
2758         COPY_SCALAR_FIELD(oldstyle);
2759         COPY_NODE_FIELD(defnames);
2760         COPY_NODE_FIELD(args);
2761         COPY_NODE_FIELD(definition);
2762
2763         return newnode;
2764 }
2765
2766 static DropStmt *
2767 _copyDropStmt(const DropStmt *from)
2768 {
2769         DropStmt   *newnode = makeNode(DropStmt);
2770
2771         COPY_NODE_FIELD(objects);
2772         COPY_NODE_FIELD(arguments);
2773         COPY_SCALAR_FIELD(removeType);
2774         COPY_SCALAR_FIELD(behavior);
2775         COPY_SCALAR_FIELD(missing_ok);
2776         COPY_SCALAR_FIELD(concurrent);
2777
2778         return newnode;
2779 }
2780
2781 static TruncateStmt *
2782 _copyTruncateStmt(const TruncateStmt *from)
2783 {
2784         TruncateStmt *newnode = makeNode(TruncateStmt);
2785
2786         COPY_NODE_FIELD(relations);
2787         COPY_SCALAR_FIELD(restart_seqs);
2788         COPY_SCALAR_FIELD(behavior);
2789
2790         return newnode;
2791 }
2792
2793 static CommentStmt *
2794 _copyCommentStmt(const CommentStmt *from)
2795 {
2796         CommentStmt *newnode = makeNode(CommentStmt);
2797
2798         COPY_SCALAR_FIELD(objtype);
2799         COPY_NODE_FIELD(objname);
2800         COPY_NODE_FIELD(objargs);
2801         COPY_STRING_FIELD(comment);
2802
2803         return newnode;
2804 }
2805
2806 static SecLabelStmt *
2807 _copySecLabelStmt(const SecLabelStmt *from)
2808 {
2809         SecLabelStmt *newnode = makeNode(SecLabelStmt);
2810
2811         COPY_SCALAR_FIELD(objtype);
2812         COPY_NODE_FIELD(objname);
2813         COPY_NODE_FIELD(objargs);
2814         COPY_STRING_FIELD(provider);
2815         COPY_STRING_FIELD(label);
2816
2817         return newnode;
2818 }
2819
2820 static FetchStmt *
2821 _copyFetchStmt(const FetchStmt *from)
2822 {
2823         FetchStmt  *newnode = makeNode(FetchStmt);
2824
2825         COPY_SCALAR_FIELD(direction);
2826         COPY_SCALAR_FIELD(howMany);
2827         COPY_STRING_FIELD(portalname);
2828         COPY_SCALAR_FIELD(ismove);
2829
2830         return newnode;
2831 }
2832
2833 static IndexStmt *
2834 _copyIndexStmt(const IndexStmt *from)
2835 {
2836         IndexStmt  *newnode = makeNode(IndexStmt);
2837
2838         COPY_STRING_FIELD(idxname);
2839         COPY_NODE_FIELD(relation);
2840         COPY_STRING_FIELD(accessMethod);
2841         COPY_STRING_FIELD(tableSpace);
2842         COPY_NODE_FIELD(indexParams);
2843         COPY_NODE_FIELD(options);
2844         COPY_NODE_FIELD(whereClause);
2845         COPY_NODE_FIELD(excludeOpNames);
2846         COPY_STRING_FIELD(idxcomment);
2847         COPY_SCALAR_FIELD(indexOid);
2848         COPY_SCALAR_FIELD(oldNode);
2849         COPY_SCALAR_FIELD(unique);
2850         COPY_SCALAR_FIELD(primary);
2851         COPY_SCALAR_FIELD(isconstraint);
2852         COPY_SCALAR_FIELD(deferrable);
2853         COPY_SCALAR_FIELD(initdeferred);
2854         COPY_SCALAR_FIELD(concurrent);
2855
2856         return newnode;
2857 }
2858
2859 static CreateFunctionStmt *
2860 _copyCreateFunctionStmt(const CreateFunctionStmt *from)
2861 {
2862         CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
2863
2864         COPY_SCALAR_FIELD(replace);
2865         COPY_NODE_FIELD(funcname);
2866         COPY_NODE_FIELD(parameters);
2867         COPY_NODE_FIELD(returnType);
2868         COPY_NODE_FIELD(options);
2869         COPY_NODE_FIELD(withClause);
2870
2871         return newnode;
2872 }
2873
2874 static FunctionParameter *
2875 _copyFunctionParameter(const FunctionParameter *from)
2876 {
2877         FunctionParameter *newnode = makeNode(FunctionParameter);
2878
2879         COPY_STRING_FIELD(name);
2880         COPY_NODE_FIELD(argType);
2881         COPY_SCALAR_FIELD(mode);
2882         COPY_NODE_FIELD(defexpr);
2883
2884         return newnode;
2885 }
2886
2887 static AlterFunctionStmt *
2888 _copyAlterFunctionStmt(const AlterFunctionStmt *from)
2889 {
2890         AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);
2891
2892         COPY_NODE_FIELD(func);
2893         COPY_NODE_FIELD(actions);
2894
2895         return newnode;
2896 }
2897
2898 static DoStmt *
2899 _copyDoStmt(const DoStmt *from)
2900 {
2901         DoStmt     *newnode = makeNode(DoStmt);
2902
2903         COPY_NODE_FIELD(args);
2904
2905         return newnode;
2906 }
2907
2908 static RenameStmt *
2909 _copyRenameStmt(const RenameStmt *from)
2910 {
2911         RenameStmt *newnode = makeNode(RenameStmt);
2912
2913         COPY_SCALAR_FIELD(renameType);
2914         COPY_SCALAR_FIELD(relationType);
2915         COPY_NODE_FIELD(relation);
2916         COPY_NODE_FIELD(object);
2917         COPY_NODE_FIELD(objarg);
2918         COPY_STRING_FIELD(subname);
2919         COPY_STRING_FIELD(newname);
2920         COPY_SCALAR_FIELD(behavior);
2921         COPY_SCALAR_FIELD(missing_ok);
2922
2923         return newnode;
2924 }
2925
2926 static AlterObjectSchemaStmt *
2927 _copyAlterObjectSchemaStmt(const AlterObjectSchemaStmt *from)
2928 {
2929         AlterObjectSchemaStmt *newnode = makeNode(AlterObjectSchemaStmt);
2930
2931         COPY_SCALAR_FIELD(objectType);
2932         COPY_NODE_FIELD(relation);
2933         COPY_NODE_FIELD(object);
2934         COPY_NODE_FIELD(objarg);
2935         COPY_STRING_FIELD(newschema);
2936         COPY_SCALAR_FIELD(missing_ok);
2937
2938         return newnode;
2939 }
2940
2941 static AlterOwnerStmt *
2942 _copyAlterOwnerStmt(const AlterOwnerStmt *from)
2943 {
2944         AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);
2945
2946         COPY_SCALAR_FIELD(objectType);
2947         COPY_NODE_FIELD(relation);
2948         COPY_NODE_FIELD(object);
2949         COPY_NODE_FIELD(objarg);
2950         COPY_STRING_FIELD(newowner);
2951
2952         return newnode;
2953 }
2954
2955 static RuleStmt *
2956 _copyRuleStmt(const RuleStmt *from)
2957 {
2958         RuleStmt   *newnode = makeNode(RuleStmt);
2959
2960         COPY_NODE_FIELD(relation);
2961         COPY_STRING_FIELD(rulename);
2962         COPY_NODE_FIELD(whereClause);
2963         COPY_SCALAR_FIELD(event);
2964         COPY_SCALAR_FIELD(instead);
2965         COPY_NODE_FIELD(actions);
2966         COPY_SCALAR_FIELD(replace);
2967
2968         return newnode;
2969 }
2970
2971 static NotifyStmt *
2972 _copyNotifyStmt(const NotifyStmt *from)
2973 {
2974         NotifyStmt *newnode = makeNode(NotifyStmt);
2975
2976         COPY_STRING_FIELD(conditionname);
2977         COPY_STRING_FIELD(payload);
2978
2979         return newnode;
2980 }
2981
2982 static ListenStmt *
2983 _copyListenStmt(const ListenStmt *from)
2984 {
2985         ListenStmt *newnode = makeNode(ListenStmt);
2986
2987         COPY_STRING_FIELD(conditionname);
2988
2989         return newnode;
2990 }
2991
2992 static UnlistenStmt *
2993 _copyUnlistenStmt(const UnlistenStmt *from)
2994 {
2995         UnlistenStmt *newnode = makeNode(UnlistenStmt);
2996
2997         COPY_STRING_FIELD(conditionname);
2998
2999         return newnode;
3000 }
3001
3002 static TransactionStmt *
3003 _copyTransactionStmt(const TransactionStmt *from)
3004 {
3005         TransactionStmt *newnode = makeNode(TransactionStmt);
3006
3007         COPY_SCALAR_FIELD(kind);
3008         COPY_NODE_FIELD(options);
3009         COPY_STRING_FIELD(gid);
3010
3011         return newnode;
3012 }
3013
3014 static CompositeTypeStmt *
3015 _copyCompositeTypeStmt(const CompositeTypeStmt *from)
3016 {
3017         CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
3018
3019         COPY_NODE_FIELD(typevar);
3020         COPY_NODE_FIELD(coldeflist);
3021
3022         return newnode;
3023 }
3024
3025 static CreateEnumStmt *
3026 _copyCreateEnumStmt(const CreateEnumStmt *from)
3027 {
3028         CreateEnumStmt *newnode = makeNode(CreateEnumStmt);
3029
3030         COPY_NODE_FIELD(typeName);
3031         COPY_NODE_FIELD(vals);
3032
3033         return newnode;
3034 }
3035
3036 static CreateRangeStmt *
3037 _copyCreateRangeStmt(const CreateRangeStmt *from)
3038 {
3039         CreateRangeStmt *newnode = makeNode(CreateRangeStmt);
3040
3041         COPY_NODE_FIELD(typeName);
3042         COPY_NODE_FIELD(params);
3043
3044         return newnode;
3045 }
3046
3047 static AlterEnumStmt *
3048 _copyAlterEnumStmt(const AlterEnumStmt *from)
3049 {
3050         AlterEnumStmt *newnode = makeNode(AlterEnumStmt);
3051
3052         COPY_NODE_FIELD(typeName);
3053         COPY_STRING_FIELD(newVal);
3054         COPY_STRING_FIELD(newValNeighbor);
3055         COPY_SCALAR_FIELD(newValIsAfter);
3056         COPY_SCALAR_FIELD(skipIfExists);
3057
3058         return newnode;
3059 }
3060
3061 static ViewStmt *
3062 _copyViewStmt(const ViewStmt *from)
3063 {
3064         ViewStmt   *newnode = makeNode(ViewStmt);
3065
3066         COPY_NODE_FIELD(view);
3067         COPY_NODE_FIELD(aliases);
3068         COPY_NODE_FIELD(query);
3069         COPY_SCALAR_FIELD(replace);
3070         COPY_NODE_FIELD(options);
3071
3072         return newnode;
3073 }
3074
3075 static LoadStmt *
3076 _copyLoadStmt(const LoadStmt *from)
3077 {
3078         LoadStmt   *newnode = makeNode(LoadStmt);
3079
3080         COPY_STRING_FIELD(filename);
3081
3082         return newnode;
3083 }
3084
3085 static CreateDomainStmt *
3086 _copyCreateDomainStmt(const CreateDomainStmt *from)
3087 {
3088         CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
3089
3090         COPY_NODE_FIELD(domainname);
3091         COPY_NODE_FIELD(typeName);
3092         COPY_NODE_FIELD(collClause);
3093         COPY_NODE_FIELD(constraints);
3094
3095         return newnode;
3096 }
3097
3098 static CreateOpClassStmt *
3099 _copyCreateOpClassStmt(const CreateOpClassStmt *from)
3100 {
3101         CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
3102
3103         COPY_NODE_FIELD(opclassname);
3104         COPY_NODE_FIELD(opfamilyname);
3105         COPY_STRING_FIELD(amname);
3106         COPY_NODE_FIELD(datatype);
3107         COPY_NODE_FIELD(items);
3108         COPY_SCALAR_FIELD(isDefault);
3109
3110         return newnode;
3111 }
3112
3113 static CreateOpClassItem *
3114 _copyCreateOpClassItem(const CreateOpClassItem *from)
3115 {
3116         CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
3117
3118         COPY_SCALAR_FIELD(itemtype);
3119         COPY_NODE_FIELD(name);
3120         COPY_NODE_FIELD(args);
3121         COPY_SCALAR_FIELD(number);
3122         COPY_NODE_FIELD(order_family);
3123         COPY_NODE_FIELD(class_args);
3124         COPY_NODE_FIELD(storedtype);
3125
3126         return newnode;
3127 }
3128
3129 static CreateOpFamilyStmt *
3130 _copyCreateOpFamilyStmt(const CreateOpFamilyStmt *from)
3131 {
3132         CreateOpFamilyStmt *newnode = makeNode(CreateOpFamilyStmt);
3133
3134         COPY_NODE_FIELD(opfamilyname);
3135         COPY_STRING_FIELD(amname);
3136
3137         return newnode;
3138 }
3139
3140 static AlterOpFamilyStmt *
3141 _copyAlterOpFamilyStmt(const AlterOpFamilyStmt *from)
3142 {
3143         AlterOpFamilyStmt *newnode = makeNode(AlterOpFamilyStmt);
3144
3145         COPY_NODE_FIELD(opfamilyname);
3146         COPY_STRING_FIELD(amname);
3147         COPY_SCALAR_FIELD(isDrop);
3148         COPY_NODE_FIELD(items);
3149
3150         return newnode;
3151 }
3152
3153 static CreatedbStmt *
3154 _copyCreatedbStmt(const CreatedbStmt *from)
3155 {
3156         CreatedbStmt *newnode = makeNode(CreatedbStmt);
3157
3158         COPY_STRING_FIELD(dbname);
3159         COPY_NODE_FIELD(options);
3160
3161         return newnode;
3162 }
3163
3164 static AlterDatabaseStmt *
3165 _copyAlterDatabaseStmt(const AlterDatabaseStmt *from)
3166 {
3167         AlterDatabaseStmt *newnode = makeNode(AlterDatabaseStmt);
3168
3169         COPY_STRING_FIELD(dbname);
3170         COPY_NODE_FIELD(options);
3171
3172         return newnode;
3173 }
3174
3175 static AlterDatabaseSetStmt *
3176 _copyAlterDatabaseSetStmt(const AlterDatabaseSetStmt *from)
3177 {
3178         AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
3179
3180         COPY_STRING_FIELD(dbname);
3181         COPY_NODE_FIELD(setstmt);
3182
3183         return newnode;
3184 }
3185
3186 static DropdbStmt *
3187 _copyDropdbStmt(const DropdbStmt *from)
3188 {
3189         DropdbStmt *newnode = makeNode(DropdbStmt);
3190
3191         COPY_STRING_FIELD(dbname);
3192         COPY_SCALAR_FIELD(missing_ok);
3193
3194         return newnode;
3195 }
3196
3197 static VacuumStmt *
3198 _copyVacuumStmt(const VacuumStmt *from)
3199 {
3200         VacuumStmt *newnode = makeNode(VacuumStmt);
3201
3202         COPY_SCALAR_FIELD(options);
3203         COPY_SCALAR_FIELD(freeze_min_age);
3204         COPY_SCALAR_FIELD(freeze_table_age);
3205         COPY_NODE_FIELD(relation);
3206         COPY_NODE_FIELD(va_cols);
3207
3208         return newnode;
3209 }
3210
3211 static ExplainStmt *
3212 _copyExplainStmt(const ExplainStmt *from)
3213 {
3214         ExplainStmt *newnode = makeNode(ExplainStmt);
3215
3216         COPY_NODE_FIELD(query);
3217         COPY_NODE_FIELD(options);
3218
3219         return newnode;
3220 }
3221
3222 static CreateTableAsStmt *
3223 _copyCreateTableAsStmt(const CreateTableAsStmt *from)
3224 {
3225         CreateTableAsStmt *newnode = makeNode(CreateTableAsStmt);
3226
3227         COPY_NODE_FIELD(query);
3228         COPY_NODE_FIELD(into);
3229         COPY_SCALAR_FIELD(is_select_into);
3230
3231         return newnode;
3232 }
3233
3234 static CreateSeqStmt *
3235 _copyCreateSeqStmt(const CreateSeqStmt *from)
3236 {
3237         CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
3238
3239         COPY_NODE_FIELD(sequence);
3240         COPY_NODE_FIELD(options);
3241         COPY_SCALAR_FIELD(ownerId);
3242
3243         return newnode;
3244 }
3245
3246 static AlterSeqStmt *
3247 _copyAlterSeqStmt(const AlterSeqStmt *from)
3248 {
3249         AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
3250
3251         COPY_NODE_FIELD(sequence);
3252         COPY_NODE_FIELD(options);
3253         COPY_SCALAR_FIELD(missing_ok);
3254
3255         return newnode;
3256 }
3257
3258 static VariableSetStmt *
3259 _copyVariableSetStmt(const VariableSetStmt *from)
3260 {
3261         VariableSetStmt *newnode = makeNode(VariableSetStmt);
3262
3263         COPY_SCALAR_FIELD(kind);
3264         COPY_STRING_FIELD(name);
3265         COPY_NODE_FIELD(args);
3266         COPY_SCALAR_FIELD(is_local);
3267
3268         return newnode;
3269 }
3270
3271 static VariableShowStmt *
3272 _copyVariableShowStmt(const VariableShowStmt *from)
3273 {
3274         VariableShowStmt *newnode = makeNode(VariableShowStmt);
3275
3276         COPY_STRING_FIELD(name);
3277
3278         return newnode;
3279 }
3280
3281 static DiscardStmt *
3282 _copyDiscardStmt(const DiscardStmt *from)
3283 {
3284         DiscardStmt *newnode = makeNode(DiscardStmt);
3285
3286         COPY_SCALAR_FIELD(target);
3287
3288         return newnode;
3289 }
3290
3291 static CreateTableSpaceStmt *
3292 _copyCreateTableSpaceStmt(const CreateTableSpaceStmt *from)
3293 {
3294         CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
3295
3296         COPY_STRING_FIELD(tablespacename);
3297         COPY_STRING_FIELD(owner);
3298         COPY_STRING_FIELD(location);
3299
3300         return newnode;
3301 }
3302
3303 static DropTableSpaceStmt *
3304 _copyDropTableSpaceStmt(const DropTableSpaceStmt *from)
3305 {
3306         DropTableSpaceStmt *newnode = makeNode(DropTableSpaceStmt);
3307
3308         COPY_STRING_FIELD(tablespacename);
3309         COPY_SCALAR_FIELD(missing_ok);
3310
3311         return newnode;
3312 }
3313
3314 static AlterTableSpaceOptionsStmt *
3315 _copyAlterTableSpaceOptionsStmt(const AlterTableSpaceOptionsStmt *from)
3316 {
3317         AlterTableSpaceOptionsStmt *newnode = makeNode(AlterTableSpaceOptionsStmt);
3318
3319         COPY_STRING_FIELD(tablespacename);
3320         COPY_NODE_FIELD(options);
3321         COPY_SCALAR_FIELD(isReset);
3322
3323         return newnode;
3324 }
3325
3326 static CreateExtensionStmt *
3327 _copyCreateExtensionStmt(const CreateExtensionStmt *from)
3328 {
3329         CreateExtensionStmt *newnode = makeNode(CreateExtensionStmt);
3330
3331         COPY_STRING_FIELD(extname);
3332         COPY_SCALAR_FIELD(if_not_exists);
3333         COPY_NODE_FIELD(options);
3334
3335         return newnode;
3336 }
3337
3338 static AlterExtensionStmt *
3339 _copyAlterExtensionStmt(const AlterExtensionStmt *from)
3340 {
3341         AlterExtensionStmt *newnode = makeNode(AlterExtensionStmt);
3342
3343         COPY_STRING_FIELD(extname);
3344         COPY_NODE_FIELD(options);
3345
3346         return newnode;
3347 }
3348
3349 static AlterExtensionContentsStmt *
3350 _copyAlterExtensionContentsStmt(const AlterExtensionContentsStmt *from)
3351 {
3352         AlterExtensionContentsStmt *newnode = makeNode(AlterExtensionContentsStmt);
3353
3354         COPY_STRING_FIELD(extname);
3355         COPY_SCALAR_FIELD(action);
3356         COPY_SCALAR_FIELD(objtype);
3357         COPY_NODE_FIELD(objname);
3358         COPY_NODE_FIELD(objargs);
3359
3360         return newnode;
3361 }
3362
3363 static CreateFdwStmt *
3364 _copyCreateFdwStmt(const CreateFdwStmt *from)
3365 {
3366         CreateFdwStmt *newnode = makeNode(CreateFdwStmt);
3367
3368         COPY_STRING_FIELD(fdwname);
3369         COPY_NODE_FIELD(func_options);
3370         COPY_NODE_FIELD(options);
3371
3372         return newnode;
3373 }
3374
3375 static AlterFdwStmt *
3376 _copyAlterFdwStmt(const AlterFdwStmt *from)
3377 {
3378         AlterFdwStmt *newnode = makeNode(AlterFdwStmt);
3379
3380         COPY_STRING_FIELD(fdwname);
3381         COPY_NODE_FIELD(func_options);
3382         COPY_NODE_FIELD(options);
3383
3384         return newnode;
3385 }
3386
3387 static CreateForeignServerStmt *
3388 _copyCreateForeignServerStmt(const CreateForeignServerStmt *from)
3389 {
3390         CreateForeignServerStmt *newnode = makeNode(CreateForeignServerStmt);
3391
3392         COPY_STRING_FIELD(servername);
3393         COPY_STRING_FIELD(servertype);
3394         COPY_STRING_FIELD(version);
3395         COPY_STRING_FIELD(fdwname);
3396         COPY_NODE_FIELD(options);
3397
3398         return newnode;
3399 }
3400
3401 static AlterForeignServerStmt *
3402 _copyAlterForeignServerStmt(const AlterForeignServerStmt *from)
3403 {
3404         AlterForeignServerStmt *newnode = makeNode(AlterForeignServerStmt);
3405
3406         COPY_STRING_FIELD(servername);
3407         COPY_STRING_FIELD(version);
3408         COPY_NODE_FIELD(options);
3409         COPY_SCALAR_FIELD(has_version);
3410
3411         return newnode;
3412 }
3413
3414 static CreateUserMappingStmt *
3415 _copyCreateUserMappingStmt(const CreateUserMappingStmt *from)
3416 {
3417         CreateUserMappingStmt *newnode = makeNode(CreateUserMappingStmt);
3418
3419         COPY_STRING_FIELD(username);
3420         COPY_STRING_FIELD(servername);
3421         COPY_NODE_FIELD(options);
3422
3423         return newnode;
3424 }
3425
3426 static AlterUserMappingStmt *
3427 _copyAlterUserMappingStmt(const AlterUserMappingStmt *from)
3428 {
3429         AlterUserMappingStmt *newnode = makeNode(AlterUserMappingStmt);
3430
3431         COPY_STRING_FIELD(username);
3432         COPY_STRING_FIELD(servername);
3433         COPY_NODE_FIELD(options);
3434
3435         return newnode;
3436 }
3437
3438 static DropUserMappingStmt *
3439 _copyDropUserMappingStmt(const DropUserMappingStmt *from)
3440 {
3441         DropUserMappingStmt *newnode = makeNode(DropUserMappingStmt);
3442
3443         COPY_STRING_FIELD(username);
3444         COPY_STRING_FIELD(servername);
3445         COPY_SCALAR_FIELD(missing_ok);
3446
3447         return newnode;
3448 }
3449
3450 static CreateForeignTableStmt *
3451 _copyCreateForeignTableStmt(const CreateForeignTableStmt *from)
3452 {
3453         CreateForeignTableStmt *newnode = makeNode(CreateForeignTableStmt);
3454
3455         CopyCreateStmtFields((const CreateStmt *) from, (CreateStmt *) newnode);
3456
3457         COPY_STRING_FIELD(servername);
3458         COPY_NODE_FIELD(options);
3459
3460         return newnode;
3461 }
3462
3463 static CreateTrigStmt *
3464 _copyCreateTrigStmt(const CreateTrigStmt *from)
3465 {
3466         CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
3467
3468         COPY_STRING_FIELD(trigname);
3469         COPY_NODE_FIELD(relation);
3470         COPY_NODE_FIELD(funcname);
3471         COPY_NODE_FIELD(args);
3472         COPY_SCALAR_FIELD(row);
3473         COPY_SCALAR_FIELD(timing);
3474         COPY_SCALAR_FIELD(events);
3475         COPY_NODE_FIELD(columns);
3476         COPY_NODE_FIELD(whenClause);
3477         COPY_SCALAR_FIELD(isconstraint);
3478         COPY_SCALAR_FIELD(deferrable);
3479         COPY_SCALAR_FIELD(initdeferred);
3480         COPY_NODE_FIELD(constrrel);
3481
3482         return newnode;
3483 }
3484
3485 static CreateEventTrigStmt *
3486 _copyCreateEventTrigStmt(const CreateEventTrigStmt *from)
3487 {
3488         CreateEventTrigStmt *newnode = makeNode(CreateEventTrigStmt);
3489
3490         COPY_STRING_FIELD(trigname);
3491         COPY_SCALAR_FIELD(eventname);
3492         COPY_NODE_FIELD(whenclause);
3493         COPY_NODE_FIELD(funcname);
3494
3495         return newnode;
3496 }
3497
3498 static AlterEventTrigStmt *
3499 _copyAlterEventTrigStmt(const AlterEventTrigStmt *from)
3500 {
3501         AlterEventTrigStmt *newnode = makeNode(AlterEventTrigStmt);
3502
3503         COPY_STRING_FIELD(trigname);
3504         COPY_SCALAR_FIELD(tgenabled);
3505
3506         return newnode;
3507 }
3508
3509 static CreatePLangStmt *
3510 _copyCreatePLangStmt(const CreatePLangStmt *from)
3511 {
3512         CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
3513
3514         COPY_SCALAR_FIELD(replace);
3515         COPY_STRING_FIELD(plname);
3516         COPY_NODE_FIELD(plhandler);
3517         COPY_NODE_FIELD(plinline);
3518         COPY_NODE_FIELD(plvalidator);
3519         COPY_SCALAR_FIELD(pltrusted);
3520
3521         return newnode;
3522 }
3523
3524 static CreateRoleStmt *
3525 _copyCreateRoleStmt(const CreateRoleStmt *from)
3526 {
3527         CreateRoleStmt *newnode = makeNode(CreateRoleStmt);
3528
3529         COPY_SCALAR_FIELD(stmt_type);
3530         COPY_STRING_FIELD(role);
3531         COPY_NODE_FIELD(options);
3532
3533         return newnode;
3534 }
3535
3536 static AlterRoleStmt *
3537 _copyAlterRoleStmt(const AlterRoleStmt *from)
3538 {
3539         AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
3540
3541         COPY_STRING_FIELD(role);
3542         COPY_NODE_FIELD(options);
3543         COPY_SCALAR_FIELD(action);
3544
3545         return newnode;
3546 }
3547
3548 static AlterRoleSetStmt *
3549 _copyAlterRoleSetStmt(const AlterRoleSetStmt *from)
3550 {
3551         AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
3552
3553         COPY_STRING_FIELD(role);
3554         COPY_STRING_FIELD(database);
3555         COPY_NODE_FIELD(setstmt);
3556
3557         return newnode;
3558 }
3559
3560 static DropRoleStmt *
3561 _copyDropRoleStmt(const DropRoleStmt *from)
3562 {
3563         DropRoleStmt *newnode = makeNode(DropRoleStmt);
3564
3565         COPY_NODE_FIELD(roles);
3566         COPY_SCALAR_FIELD(missing_ok);
3567
3568         return newnode;
3569 }
3570
3571 static LockStmt *
3572 _copyLockStmt(const LockStmt *from)
3573 {
3574         LockStmt   *newnode = makeNode(LockStmt);
3575
3576         COPY_NODE_FIELD(relations);
3577         COPY_SCALAR_FIELD(mode);
3578         COPY_SCALAR_FIELD(nowait);
3579
3580         return newnode;
3581 }
3582
3583 static ConstraintsSetStmt *
3584 _copyConstraintsSetStmt(const ConstraintsSetStmt *from)
3585 {
3586         ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
3587
3588         COPY_NODE_FIELD(constraints);
3589         COPY_SCALAR_FIELD(deferred);
3590
3591         return newnode;
3592 }
3593
3594 static ReindexStmt *
3595 _copyReindexStmt(const ReindexStmt *from)
3596 {
3597         ReindexStmt *newnode = makeNode(ReindexStmt);
3598
3599         COPY_SCALAR_FIELD(kind);
3600         COPY_NODE_FIELD(relation);
3601         COPY_STRING_FIELD(name);
3602         COPY_SCALAR_FIELD(do_system);
3603         COPY_SCALAR_FIELD(do_user);
3604
3605         return newnode;
3606 }
3607
3608 static CreateSchemaStmt *
3609 _copyCreateSchemaStmt(const CreateSchemaStmt *from)
3610 {
3611         CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
3612
3613         COPY_STRING_FIELD(schemaname);
3614         COPY_STRING_FIELD(authid);
3615         COPY_NODE_FIELD(schemaElts);
3616
3617         return newnode;
3618 }
3619
3620 static CreateConversionStmt *
3621 _copyCreateConversionStmt(const CreateConversionStmt *from)
3622 {
3623         CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
3624
3625         COPY_NODE_FIELD(conversion_name);
3626         COPY_STRING_FIELD(for_encoding_name);
3627         COPY_STRING_FIELD(to_encoding_name);
3628         COPY_NODE_FIELD(func_name);
3629         COPY_SCALAR_FIELD(def);
3630
3631         return newnode;
3632 }
3633
3634 static CreateCastStmt *
3635 _copyCreateCastStmt(const CreateCastStmt *from)
3636 {
3637         CreateCastStmt *newnode = makeNode(CreateCastStmt);
3638
3639         COPY_NODE_FIELD(sourcetype);
3640         COPY_NODE_FIELD(targettype);
3641         COPY_NODE_FIELD(func);
3642         COPY_SCALAR_FIELD(context);
3643         COPY_SCALAR_FIELD(inout);
3644
3645         return newnode;
3646 }
3647
3648 static PrepareStmt *
3649 _copyPrepareStmt(const PrepareStmt *from)
3650 {
3651         PrepareStmt *newnode = makeNode(PrepareStmt);
3652
3653         COPY_STRING_FIELD(name);
3654         COPY_NODE_FIELD(argtypes);
3655         COPY_NODE_FIELD(query);
3656
3657         return newnode;
3658 }
3659
3660 static ExecuteStmt *
3661 _copyExecuteStmt(const ExecuteStmt *from)
3662 {
3663         ExecuteStmt *newnode = makeNode(ExecuteStmt);
3664
3665         COPY_STRING_FIELD(name);
3666         COPY_NODE_FIELD(params);
3667
3668         return newnode;
3669 }
3670
3671 static DeallocateStmt *
3672 _copyDeallocateStmt(const DeallocateStmt *from)
3673 {
3674         DeallocateStmt *newnode = makeNode(DeallocateStmt);
3675
3676         COPY_STRING_FIELD(name);
3677
3678         return newnode;
3679 }
3680
3681 static DropOwnedStmt *
3682 _copyDropOwnedStmt(const DropOwnedStmt *from)
3683 {
3684         DropOwnedStmt *newnode = makeNode(DropOwnedStmt);
3685
3686         COPY_NODE_FIELD(roles);
3687         COPY_SCALAR_FIELD(behavior);
3688
3689         return newnode;
3690 }
3691
3692 static ReassignOwnedStmt *
3693 _copyReassignOwnedStmt(const ReassignOwnedStmt *from)
3694 {
3695         ReassignOwnedStmt *newnode = makeNode(ReassignOwnedStmt);
3696
3697         COPY_NODE_FIELD(roles);
3698         COPY_STRING_FIELD(newrole);
3699
3700         return newnode;
3701 }
3702
3703 static AlterTSDictionaryStmt *
3704 _copyAlterTSDictionaryStmt(const AlterTSDictionaryStmt *from)
3705 {
3706         AlterTSDictionaryStmt *newnode = makeNode(AlterTSDictionaryStmt);
3707
3708         COPY_NODE_FIELD(dictname);
3709         COPY_NODE_FIELD(options);
3710
3711         return newnode;
3712 }
3713
3714 static AlterTSConfigurationStmt *
3715 _copyAlterTSConfigurationStmt(const AlterTSConfigurationStmt *from)
3716 {
3717         AlterTSConfigurationStmt *newnode = makeNode(AlterTSConfigurationStmt);
3718
3719         COPY_NODE_FIELD(cfgname);
3720         COPY_NODE_FIELD(tokentype);
3721         COPY_NODE_FIELD(dicts);
3722         COPY_SCALAR_FIELD(override);
3723         COPY_SCALAR_FIELD(replace);
3724         COPY_SCALAR_FIELD(missing_ok);
3725
3726         return newnode;
3727 }
3728
3729 /* ****************************************************************
3730  *                                      pg_list.h copy functions
3731  * ****************************************************************
3732  */
3733
3734 /*
3735  * Perform a deep copy of the specified list, using copyObject(). The
3736  * list MUST be of type T_List; T_IntList and T_OidList nodes don't
3737  * need deep copies, so they should be copied via list_copy()
3738  */
3739 #define COPY_NODE_CELL(new, old)                                        \
3740         (new) = (ListCell *) palloc(sizeof(ListCell));  \
3741         lfirst(new) = copyObject(lfirst(old));
3742
3743 static List *
3744 _copyList(const List *from)
3745 {
3746         List       *new;
3747         ListCell   *curr_old;
3748         ListCell   *prev_new;
3749
3750         Assert(list_length(from) >= 1);
3751
3752         new = makeNode(List);
3753         new->length = from->length;
3754
3755         COPY_NODE_CELL(new->head, from->head);
3756         prev_new = new->head;
3757         curr_old = lnext(from->head);
3758
3759         while (curr_old)
3760         {
3761                 COPY_NODE_CELL(prev_new->next, curr_old);
3762                 prev_new = prev_new->next;
3763                 curr_old = curr_old->next;
3764         }
3765         prev_new->next = NULL;
3766         new->tail = prev_new;
3767
3768         return new;
3769 }
3770
3771 /* ****************************************************************
3772  *                                      value.h copy functions
3773  * ****************************************************************
3774  */
3775 static Value *
3776 _copyValue(const Value *from)
3777 {
3778         Value      *newnode = makeNode(Value);
3779
3780         /* See also _copyAConst when changing this code! */
3781
3782         COPY_SCALAR_FIELD(type);
3783         switch (from->type)
3784         {
3785                 case T_Integer:
3786                         COPY_SCALAR_FIELD(val.ival);
3787                         break;
3788                 case T_Float:
3789                 case T_String:
3790                 case T_BitString:
3791                         COPY_STRING_FIELD(val.str);
3792                         break;
3793                 case T_Null:
3794                         /* nothing to do */
3795                         break;
3796                 default:
3797                         elog(ERROR, "unrecognized node type: %d",
3798                                  (int) from->type);
3799                         break;
3800         }
3801         return newnode;
3802 }
3803
3804 /*
3805  * copyObject
3806  *
3807  * Create a copy of a Node tree or list.  This is a "deep" copy: all
3808  * substructure is copied too, recursively.
3809  */
3810 void *
3811 copyObject(const void *from)
3812 {
3813         void       *retval;
3814
3815         if (from == NULL)
3816                 return NULL;
3817
3818         /* Guard against stack overflow due to overly complex expressions */
3819         check_stack_depth();
3820
3821         switch (nodeTag(from))
3822         {
3823                         /*
3824                          * PLAN NODES
3825                          */
3826                 case T_PlannedStmt:
3827                         retval = _copyPlannedStmt(from);
3828                         break;
3829                 case T_Plan:
3830                         retval = _copyPlan(from);
3831                         break;
3832                 case T_Result:
3833                         retval = _copyResult(from);
3834                         break;
3835                 case T_ModifyTable:
3836                         retval = _copyModifyTable(from);
3837                         break;
3838                 case T_Append:
3839                         retval = _copyAppend(from);
3840                         break;
3841                 case T_MergeAppend:
3842                         retval = _copyMergeAppend(from);
3843                         break;
3844                 case T_RecursiveUnion:
3845                         retval = _copyRecursiveUnion(from);
3846                         break;
3847                 case T_BitmapAnd:
3848                         retval = _copyBitmapAnd(from);
3849                         break;
3850                 case T_BitmapOr:
3851                         retval = _copyBitmapOr(from);
3852                         break;
3853                 case T_Scan:
3854                         retval = _copyScan(from);
3855                         break;
3856                 case T_SeqScan:
3857                         retval = _copySeqScan(from);
3858                         break;
3859                 case T_IndexScan:
3860                         retval = _copyIndexScan(from);
3861                         break;
3862                 case T_IndexOnlyScan:
3863                         retval = _copyIndexOnlyScan(from);
3864                         break;
3865                 case T_BitmapIndexScan:
3866                         retval = _copyBitmapIndexScan(from);
3867                         break;
3868                 case T_BitmapHeapScan:
3869                         retval = _copyBitmapHeapScan(from);
3870                         break;
3871                 case T_TidScan:
3872                         retval = _copyTidScan(from);
3873                         break;
3874                 case T_SubqueryScan:
3875                         retval = _copySubqueryScan(from);
3876                         break;
3877                 case T_FunctionScan:
3878                         retval = _copyFunctionScan(from);
3879                         break;
3880                 case T_ValuesScan:
3881                         retval = _copyValuesScan(from);
3882                         break;
3883                 case T_CteScan:
3884                         retval = _copyCteScan(from);
3885                         break;
3886                 case T_WorkTableScan:
3887                         retval = _copyWorkTableScan(from);
3888                         break;
3889                 case T_ForeignScan:
3890                         retval = _copyForeignScan(from);
3891                         break;
3892                 case T_Join:
3893                         retval = _copyJoin(from);
3894                         break;
3895                 case T_NestLoop:
3896                         retval = _copyNestLoop(from);
3897                         break;
3898                 case T_MergeJoin:
3899                         retval = _copyMergeJoin(from);
3900                         break;
3901                 case T_HashJoin:
3902                         retval = _copyHashJoin(from);
3903                         break;
3904                 case T_Material:
3905                         retval = _copyMaterial(from);
3906                         break;
3907                 case T_Sort:
3908                         retval = _copySort(from);
3909                         break;
3910                 case T_Group:
3911                         retval = _copyGroup(from);
3912                         break;
3913                 case T_Agg:
3914                         retval = _copyAgg(from);
3915                         break;
3916                 case T_WindowAgg:
3917                         retval = _copyWindowAgg(from);
3918                         break;
3919                 case T_Unique:
3920                         retval = _copyUnique(from);
3921                         break;
3922                 case T_Hash:
3923                         retval = _copyHash(from);
3924                         break;
3925                 case T_SetOp:
3926                         retval = _copySetOp(from);
3927                         break;
3928                 case T_LockRows:
3929                         retval = _copyLockRows(from);
3930                         break;
3931                 case T_Limit:
3932                         retval = _copyLimit(from);
3933                         break;
3934                 case T_NestLoopParam:
3935                         retval = _copyNestLoopParam(from);
3936                         break;
3937                 case T_PlanRowMark:
3938                         retval = _copyPlanRowMark(from);
3939                         break;
3940                 case T_PlanInvalItem:
3941                         retval = _copyPlanInvalItem(from);
3942                         break;
3943
3944                         /*
3945                          * PRIMITIVE NODES
3946                          */
3947                 case T_Alias:
3948                         retval = _copyAlias(from);
3949                         break;
3950                 case T_RangeVar:
3951                         retval = _copyRangeVar(from);
3952                         break;
3953                 case T_IntoClause:
3954                         retval = _copyIntoClause(from);
3955                         break;
3956                 case T_Var:
3957                         retval = _copyVar(from);
3958                         break;
3959                 case T_Const:
3960                         retval = _copyConst(from);
3961                         break;
3962                 case T_Param:
3963                         retval = _copyParam(from);
3964                         break;
3965                 case T_Aggref:
3966                         retval = _copyAggref(from);
3967                         break;
3968                 case T_WindowFunc:
3969                         retval = _copyWindowFunc(from);
3970                         break;
3971                 case T_ArrayRef:
3972                         retval = _copyArrayRef(from);
3973                         break;
3974                 case T_FuncExpr:
3975                         retval = _copyFuncExpr(from);
3976                         break;
3977                 case T_NamedArgExpr:
3978                         retval = _copyNamedArgExpr(from);
3979                         break;
3980                 case T_OpExpr:
3981                         retval = _copyOpExpr(from);
3982                         break;
3983                 case T_DistinctExpr:
3984                         retval = _copyDistinctExpr(from);
3985                         break;
3986                 case T_NullIfExpr:
3987                         retval = _copyNullIfExpr(from);
3988                         break;
3989                 case T_ScalarArrayOpExpr:
3990                         retval = _copyScalarArrayOpExpr(from);
3991                         break;
3992                 case T_BoolExpr:
3993                         retval = _copyBoolExpr(from);
3994                         break;
3995                 case T_SubLink:
3996                         retval = _copySubLink(from);
3997                         break;
3998                 case T_SubPlan:
3999                         retval = _copySubPlan(from);
4000                         break;
4001                 case T_AlternativeSubPlan:
4002                         retval = _copyAlternativeSubPlan(from);
4003                         break;
4004                 case T_FieldSelect:
4005                         retval = _copyFieldSelect(from);
4006                         break;
4007                 case T_FieldStore:
4008                         retval = _copyFieldStore(from);
4009                         break;
4010                 case T_RelabelType:
4011                         retval = _copyRelabelType(from);
4012                         break;
4013                 case T_CoerceViaIO:
4014                         retval = _copyCoerceViaIO(from);
4015                         break;
4016                 case T_ArrayCoerceExpr:
4017                         retval = _copyArrayCoerceExpr(from);
4018                         break;
4019                 case T_ConvertRowtypeExpr:
4020                         retval = _copyConvertRowtypeExpr(from);
4021                         break;
4022                 case T_CollateExpr:
4023                         retval = _copyCollateExpr(from);
4024                         break;
4025                 case T_CaseExpr:
4026                         retval = _copyCaseExpr(from);
4027                         break;
4028                 case T_CaseWhen:
4029                         retval = _copyCaseWhen(from);
4030                         break;
4031                 case T_CaseTestExpr:
4032                         retval = _copyCaseTestExpr(from);
4033                         break;
4034                 case T_ArrayExpr:
4035                         retval = _copyArrayExpr(from);
4036                         break;
4037                 case T_RowExpr:
4038                         retval = _copyRowExpr(from);
4039                         break;
4040                 case T_RowCompareExpr:
4041                         retval = _copyRowCompareExpr(from);
4042                         break;
4043                 case T_CoalesceExpr:
4044                         retval = _copyCoalesceExpr(from);
4045                         break;
4046                 case T_MinMaxExpr:
4047                         retval = _copyMinMaxExpr(from);
4048                         break;
4049                 case T_XmlExpr:
4050                         retval = _copyXmlExpr(from);
4051                         break;
4052                 case T_NullTest:
4053                         retval = _copyNullTest(from);
4054                         break;
4055                 case T_BooleanTest:
4056                         retval = _copyBooleanTest(from);
4057                         break;
4058                 case T_CoerceToDomain:
4059                         retval = _copyCoerceToDomain(from);
4060                         break;
4061                 case T_CoerceToDomainValue:
4062                         retval = _copyCoerceToDomainValue(from);
4063                         break;
4064                 case T_SetToDefault:
4065                         retval = _copySetToDefault(from);
4066                         break;
4067                 case T_CurrentOfExpr:
4068                         retval = _copyCurrentOfExpr(from);
4069                         break;
4070                 case T_TargetEntry:
4071                         retval = _copyTargetEntry(from);
4072                         break;
4073                 case T_RangeTblRef:
4074                         retval = _copyRangeTblRef(from);
4075                         break;
4076                 case T_JoinExpr:
4077                         retval = _copyJoinExpr(from);
4078                         break;
4079                 case T_FromExpr:
4080                         retval = _copyFromExpr(from);
4081                         break;
4082
4083                         /*
4084                          * RELATION NODES
4085                          */
4086                 case T_PathKey:
4087                         retval = _copyPathKey(from);
4088                         break;
4089                 case T_RestrictInfo:
4090                         retval = _copyRestrictInfo(from);
4091                         break;
4092                 case T_PlaceHolderVar:
4093                         retval = _copyPlaceHolderVar(from);
4094                         break;
4095                 case T_SpecialJoinInfo:
4096                         retval = _copySpecialJoinInfo(from);
4097                         break;
4098                 case T_LateralJoinInfo:
4099                         retval = _copyLateralJoinInfo(from);
4100                         break;
4101                 case T_AppendRelInfo:
4102                         retval = _copyAppendRelInfo(from);
4103                         break;
4104                 case T_PlaceHolderInfo:
4105                         retval = _copyPlaceHolderInfo(from);
4106                         break;
4107
4108                         /*
4109                          * VALUE NODES
4110                          */
4111                 case T_Integer:
4112                 case T_Float:
4113                 case T_String:
4114                 case T_BitString:
4115                 case T_Null:
4116                         retval = _copyValue(from);
4117                         break;
4118
4119                         /*
4120                          * LIST NODES
4121                          */
4122                 case T_List:
4123                         retval = _copyList(from);
4124                         break;
4125
4126                         /*
4127                          * Lists of integers and OIDs don't need to be deep-copied, so we
4128                          * perform a shallow copy via list_copy()
4129                          */
4130                 case T_IntList:
4131                 case T_OidList:
4132                         retval = list_copy(from);
4133                         break;
4134
4135                         /*
4136                          * PARSE NODES
4137                          */
4138                 case T_Query:
4139                         retval = _copyQuery(from);
4140                         break;
4141                 case T_InsertStmt:
4142                         retval = _copyInsertStmt(from);
4143                         break;
4144                 case T_DeleteStmt:
4145                         retval = _copyDeleteStmt(from);
4146                         break;
4147                 case T_UpdateStmt:
4148                         retval = _copyUpdateStmt(from);
4149                         break;
4150                 case T_SelectStmt:
4151                         retval = _copySelectStmt(from);
4152                         break;
4153                 case T_SetOperationStmt:
4154                         retval = _copySetOperationStmt(from);
4155                         break;
4156                 case T_AlterTableStmt:
4157                         retval = _copyAlterTableStmt(from);
4158                         break;
4159                 case T_AlterTableCmd:
4160                         retval = _copyAlterTableCmd(from);
4161                         break;
4162                 case T_AlterDomainStmt:
4163                         retval = _copyAlterDomainStmt(from);
4164                         break;
4165                 case T_GrantStmt:
4166                         retval = _copyGrantStmt(from);
4167                         break;
4168                 case T_GrantRoleStmt:
4169                         retval = _copyGrantRoleStmt(from);
4170                         break;
4171                 case T_AlterDefaultPrivilegesStmt:
4172                         retval = _copyAlterDefaultPrivilegesStmt(from);
4173                         break;
4174                 case T_DeclareCursorStmt:
4175                         retval = _copyDeclareCursorStmt(from);
4176                         break;
4177                 case T_ClosePortalStmt:
4178                         retval = _copyClosePortalStmt(from);
4179                         break;
4180                 case T_ClusterStmt:
4181                         retval = _copyClusterStmt(from);
4182                         break;
4183                 case T_CopyStmt:
4184                         retval = _copyCopyStmt(from);
4185                         break;
4186                 case T_CreateStmt:
4187                         retval = _copyCreateStmt(from);
4188                         break;
4189                 case T_TableLikeClause:
4190                         retval = _copyTableLikeClause(from);
4191                         break;
4192                 case T_DefineStmt:
4193                         retval = _copyDefineStmt(from);
4194                         break;
4195                 case T_DropStmt:
4196                         retval = _copyDropStmt(from);
4197                         break;
4198                 case T_TruncateStmt:
4199                         retval = _copyTruncateStmt(from);
4200                         break;
4201                 case T_CommentStmt:
4202                         retval = _copyCommentStmt(from);
4203                         break;
4204                 case T_SecLabelStmt:
4205                         retval = _copySecLabelStmt(from);
4206                         break;
4207                 case T_FetchStmt:
4208                         retval = _copyFetchStmt(from);
4209                         break;
4210                 case T_IndexStmt:
4211                         retval = _copyIndexStmt(from);
4212                         break;
4213                 case T_CreateFunctionStmt:
4214                         retval = _copyCreateFunctionStmt(from);
4215                         break;
4216                 case T_FunctionParameter:
4217                         retval = _copyFunctionParameter(from);
4218                         break;
4219                 case T_AlterFunctionStmt:
4220                         retval = _copyAlterFunctionStmt(from);
4221                         break;
4222                 case T_DoStmt:
4223                         retval = _copyDoStmt(from);
4224                         break;
4225                 case T_RenameStmt:
4226                         retval = _copyRenameStmt(from);
4227                         break;
4228                 case T_AlterObjectSchemaStmt:
4229                         retval = _copyAlterObjectSchemaStmt(from);
4230                         break;
4231                 case T_AlterOwnerStmt:
4232                         retval = _copyAlterOwnerStmt(from);
4233                         break;
4234                 case T_RuleStmt:
4235                         retval = _copyRuleStmt(from);
4236                         break;
4237                 case T_NotifyStmt:
4238                         retval = _copyNotifyStmt(from);
4239                         break;
4240                 case T_ListenStmt:
4241                         retval = _copyListenStmt(from);
4242                         break;
4243                 case T_UnlistenStmt:
4244                         retval = _copyUnlistenStmt(from);
4245                         break;
4246                 case T_TransactionStmt:
4247                         retval = _copyTransactionStmt(from);
4248                         break;
4249                 case T_CompositeTypeStmt:
4250                         retval = _copyCompositeTypeStmt(from);
4251                         break;
4252                 case T_CreateEnumStmt:
4253                         retval = _copyCreateEnumStmt(from);
4254                         break;
4255                 case T_CreateRangeStmt:
4256                         retval = _copyCreateRangeStmt(from);
4257                         break;
4258                 case T_AlterEnumStmt:
4259                         retval = _copyAlterEnumStmt(from);
4260                         break;
4261                 case T_ViewStmt:
4262                         retval = _copyViewStmt(from);
4263                         break;
4264                 case T_LoadStmt:
4265                         retval = _copyLoadStmt(from);
4266                         break;
4267                 case T_CreateDomainStmt:
4268                         retval = _copyCreateDomainStmt(from);
4269                         break;
4270                 case T_CreateOpClassStmt:
4271                         retval = _copyCreateOpClassStmt(from);
4272                         break;
4273                 case T_CreateOpClassItem:
4274                         retval = _copyCreateOpClassItem(from);
4275                         break;
4276                 case T_CreateOpFamilyStmt:
4277                         retval = _copyCreateOpFamilyStmt(from);
4278                         break;
4279                 case T_AlterOpFamilyStmt:
4280                         retval = _copyAlterOpFamilyStmt(from);
4281                         break;
4282                 case T_CreatedbStmt:
4283                         retval = _copyCreatedbStmt(from);
4284                         break;
4285                 case T_AlterDatabaseStmt:
4286                         retval = _copyAlterDatabaseStmt(from);
4287                         break;
4288                 case T_AlterDatabaseSetStmt:
4289                         retval = _copyAlterDatabaseSetStmt(from);
4290                         break;
4291                 case T_DropdbStmt:
4292                         retval = _copyDropdbStmt(from);
4293                         break;
4294                 case T_VacuumStmt:
4295                         retval = _copyVacuumStmt(from);
4296                         break;
4297                 case T_ExplainStmt:
4298                         retval = _copyExplainStmt(from);
4299                         break;
4300                 case T_CreateTableAsStmt:
4301                         retval = _copyCreateTableAsStmt(from);
4302                         break;
4303                 case T_CreateSeqStmt:
4304                         retval = _copyCreateSeqStmt(from);
4305                         break;
4306                 case T_AlterSeqStmt:
4307                         retval = _copyAlterSeqStmt(from);
4308                         break;
4309                 case T_VariableSetStmt:
4310                         retval = _copyVariableSetStmt(from);
4311                         break;
4312                 case T_VariableShowStmt:
4313                         retval = _copyVariableShowStmt(from);
4314                         break;
4315                 case T_DiscardStmt:
4316                         retval = _copyDiscardStmt(from);
4317                         break;
4318                 case T_CreateTableSpaceStmt:
4319                         retval = _copyCreateTableSpaceStmt(from);
4320                         break;
4321                 case T_DropTableSpaceStmt:
4322                         retval = _copyDropTableSpaceStmt(from);
4323                         break;
4324                 case T_AlterTableSpaceOptionsStmt:
4325                         retval = _copyAlterTableSpaceOptionsStmt(from);
4326                         break;
4327                 case T_CreateExtensionStmt:
4328                         retval = _copyCreateExtensionStmt(from);
4329                         break;
4330                 case T_AlterExtensionStmt:
4331                         retval = _copyAlterExtensionStmt(from);
4332                         break;
4333                 case T_AlterExtensionContentsStmt:
4334                         retval = _copyAlterExtensionContentsStmt(from);
4335                         break;
4336                 case T_CreateFdwStmt:
4337                         retval = _copyCreateFdwStmt(from);
4338                         break;
4339                 case T_AlterFdwStmt:
4340                         retval = _copyAlterFdwStmt(from);
4341                         break;
4342                 case T_CreateForeignServerStmt:
4343                         retval = _copyCreateForeignServerStmt(from);
4344                         break;
4345                 case T_AlterForeignServerStmt:
4346                         retval = _copyAlterForeignServerStmt(from);
4347                         break;
4348                 case T_CreateUserMappingStmt:
4349                         retval = _copyCreateUserMappingStmt(from);
4350                         break;
4351                 case T_AlterUserMappingStmt:
4352                         retval = _copyAlterUserMappingStmt(from);
4353                         break;
4354                 case T_DropUserMappingStmt:
4355                         retval = _copyDropUserMappingStmt(from);
4356                         break;
4357                 case T_CreateForeignTableStmt:
4358                         retval = _copyCreateForeignTableStmt(from);
4359                         break;
4360                 case T_CreateTrigStmt:
4361                         retval = _copyCreateTrigStmt(from);
4362                         break;
4363                 case T_CreateEventTrigStmt:
4364                         retval = _copyCreateEventTrigStmt(from);
4365                         break;
4366                 case T_AlterEventTrigStmt:
4367                         retval = _copyAlterEventTrigStmt(from);
4368                         break;
4369                 case T_CreatePLangStmt:
4370                         retval = _copyCreatePLangStmt(from);
4371                         break;
4372                 case T_CreateRoleStmt:
4373                         retval = _copyCreateRoleStmt(from);
4374                         break;
4375                 case T_AlterRoleStmt:
4376                         retval = _copyAlterRoleStmt(from);
4377                         break;
4378                 case T_AlterRoleSetStmt:
4379                         retval = _copyAlterRoleSetStmt(from);
4380                         break;
4381                 case T_DropRoleStmt:
4382                         retval = _copyDropRoleStmt(from);
4383                         break;
4384                 case T_LockStmt:
4385                         retval = _copyLockStmt(from);
4386                         break;
4387                 case T_ConstraintsSetStmt:
4388                         retval = _copyConstraintsSetStmt(from);
4389                         break;
4390                 case T_ReindexStmt:
4391                         retval = _copyReindexStmt(from);
4392                         break;
4393                 case T_CheckPointStmt:
4394                         retval = (void *) makeNode(CheckPointStmt);
4395                         break;
4396                 case T_CreateSchemaStmt:
4397                         retval = _copyCreateSchemaStmt(from);
4398                         break;
4399                 case T_CreateConversionStmt:
4400                         retval = _copyCreateConversionStmt(from);
4401                         break;
4402                 case T_CreateCastStmt:
4403                         retval = _copyCreateCastStmt(from);
4404                         break;
4405                 case T_PrepareStmt:
4406                         retval = _copyPrepareStmt(from);
4407                         break;
4408                 case T_ExecuteStmt:
4409                         retval = _copyExecuteStmt(from);
4410                         break;
4411                 case T_DeallocateStmt:
4412                         retval = _copyDeallocateStmt(from);
4413                         break;
4414                 case T_DropOwnedStmt:
4415                         retval = _copyDropOwnedStmt(from);
4416                         break;
4417                 case T_ReassignOwnedStmt:
4418                         retval = _copyReassignOwnedStmt(from);
4419                         break;
4420                 case T_AlterTSDictionaryStmt:
4421                         retval = _copyAlterTSDictionaryStmt(from);
4422                         break;
4423                 case T_AlterTSConfigurationStmt:
4424                         retval = _copyAlterTSConfigurationStmt(from);
4425                         break;
4426
4427                 case T_A_Expr:
4428                         retval = _copyAExpr(from);
4429                         break;
4430                 case T_ColumnRef:
4431                         retval = _copyColumnRef(from);
4432                         break;
4433                 case T_ParamRef:
4434                         retval = _copyParamRef(from);
4435                         break;
4436                 case T_A_Const:
4437                         retval = _copyAConst(from);
4438                         break;
4439                 case T_FuncCall:
4440                         retval = _copyFuncCall(from);
4441                         break;
4442                 case T_A_Star:
4443                         retval = _copyAStar(from);
4444                         break;
4445                 case T_A_Indices:
4446                         retval = _copyAIndices(from);
4447                         break;
4448                 case T_A_Indirection:
4449                         retval = _copyA_Indirection(from);
4450                         break;
4451                 case T_A_ArrayExpr:
4452                         retval = _copyA_ArrayExpr(from);
4453                         break;
4454                 case T_ResTarget:
4455                         retval = _copyResTarget(from);
4456                         break;
4457                 case T_TypeCast:
4458                         retval = _copyTypeCast(from);
4459                         break;
4460                 case T_CollateClause:
4461                         retval = _copyCollateClause(from);
4462                         break;
4463                 case T_SortBy:
4464                         retval = _copySortBy(from);
4465                         break;
4466                 case T_WindowDef:
4467                         retval = _copyWindowDef(from);
4468                         break;
4469                 case T_RangeSubselect:
4470                         retval = _copyRangeSubselect(from);
4471                         break;
4472                 case T_RangeFunction:
4473                         retval = _copyRangeFunction(from);
4474                         break;
4475                 case T_TypeName:
4476                         retval = _copyTypeName(from);
4477                         break;
4478                 case T_IndexElem:
4479                         retval = _copyIndexElem(from);
4480                         break;
4481                 case T_ColumnDef:
4482                         retval = _copyColumnDef(from);
4483                         break;
4484                 case T_Constraint:
4485                         retval = _copyConstraint(from);
4486                         break;
4487                 case T_DefElem:
4488                         retval = _copyDefElem(from);
4489                         break;
4490                 case T_LockingClause:
4491                         retval = _copyLockingClause(from);
4492                         break;
4493                 case T_RangeTblEntry:
4494                         retval = _copyRangeTblEntry(from);
4495                         break;
4496                 case T_SortGroupClause:
4497                         retval = _copySortGroupClause(from);
4498                         break;
4499                 case T_WindowClause:
4500                         retval = _copyWindowClause(from);
4501                         break;
4502                 case T_RowMarkClause:
4503                         retval = _copyRowMarkClause(from);
4504                         break;
4505                 case T_WithClause:
4506                         retval = _copyWithClause(from);
4507                         break;
4508                 case T_CommonTableExpr:
4509                         retval = _copyCommonTableExpr(from);
4510                         break;
4511                 case T_PrivGrantee:
4512                         retval = _copyPrivGrantee(from);
4513                         break;
4514                 case T_FuncWithArgs:
4515                         retval = _copyFuncWithArgs(from);
4516                         break;
4517                 case T_AccessPriv:
4518                         retval = _copyAccessPriv(from);
4519                         break;
4520                 case T_XmlSerialize:
4521                         retval = _copyXmlSerialize(from);
4522                         break;
4523
4524                 default:
4525                         elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
4526                         retval = 0;                     /* keep compiler quiet */
4527                         break;
4528         }
4529
4530         return retval;
4531 }