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