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