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