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