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