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