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