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