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