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