]> granicus.if.org Git - postgresql/blob - src/backend/nodes/copyfuncs.c
Clean up plantree representation of SubPlan-s --- SubLink does not appear
[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-2002, PostgreSQL Global Development Group
15  * Portions Copyright (c) 1994, Regents of the University of California
16  *
17  * IDENTIFICATION
18  *        $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.233 2002/12/14 00:17:50 tgl Exp $
19  *
20  *-------------------------------------------------------------------------
21  */
22
23 #include "postgres.h"
24
25 #include "nodes/parsenodes.h"
26 #include "nodes/plannodes.h"
27 #include "nodes/relation.h"
28 #include "utils/datum.h"
29
30
31 /*
32  * Macros to simplify copying of different kinds of fields.  Use these
33  * wherever possible to reduce the chance for silly typos.  Note that these
34  * hard-wire the convention that the local variables in a Copy routine are
35  * named 'newnode' and 'from'.
36  */
37
38 /* Copy a simple scalar field (int, float, bool, enum, etc) */
39 #define COPY_SCALAR_FIELD(fldname) \
40         (newnode->fldname = from->fldname)
41
42 /* Copy a field that is a pointer to some kind of Node or Node tree */
43 #define COPY_NODE_FIELD(fldname) \
44         (newnode->fldname = copyObject(from->fldname))
45
46 /* Copy a field that is a pointer to a list of integers */
47 #define COPY_INTLIST_FIELD(fldname) \
48         (newnode->fldname = listCopy(from->fldname))
49
50 /* Copy a field that is a pointer to a C string, or perhaps NULL */
51 #define COPY_STRING_FIELD(fldname) \
52         (newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)
53
54 /* Copy a field that is a pointer to a simple palloc'd object of size sz */
55 #define COPY_POINTER_FIELD(fldname, sz) \
56         do { \
57                 Size    _size = (sz); \
58                 newnode->fldname = palloc(_size); \
59                 memcpy(newnode->fldname, from->fldname, _size); \
60         } while (0)
61
62
63 /*
64  * listCopy
65  *        This copy function only copies the "cons-cells" of the list, not the
66  *        pointed-to objects.  (Use copyObject if you want a "deep" copy.)
67  *
68  *        We also use this function for copying lists of integers, which is
69  *        grotty but unlikely to break --- it could fail if sizeof(pointer)
70  *        is less than sizeof(int), but I don't know any such machines...
71  *
72  *        Note that copyObject will surely coredump if applied to a list
73  *        of integers!
74  */
75 List *
76 listCopy(List *list)
77 {
78         List       *newlist,
79                            *l,
80                            *nl;
81
82         /* rather ugly coding for speed... */
83         if (list == NIL)
84                 return NIL;
85
86         newlist = nl = makeList1(lfirst(list));
87
88         foreach(l, lnext(list))
89         {
90                 lnext(nl) = makeList1(lfirst(l));
91                 nl = lnext(nl);
92         }
93         return newlist;
94 }
95
96 /* ****************************************************************
97  *                                       plannodes.h copy functions
98  * ****************************************************************
99  */
100
101 /*
102  * CopyPlanFields
103  *
104  *              This function copies the fields of the Plan node.  It is used by
105  *              all the copy functions for classes which inherit from Plan.
106  */
107 static void
108 CopyPlanFields(Plan *from, Plan *newnode)
109 {
110         COPY_SCALAR_FIELD(startup_cost);
111         COPY_SCALAR_FIELD(total_cost);
112         COPY_SCALAR_FIELD(plan_rows);
113         COPY_SCALAR_FIELD(plan_width);
114         COPY_NODE_FIELD(targetlist);
115         COPY_NODE_FIELD(qual);
116         COPY_NODE_FIELD(lefttree);
117         COPY_NODE_FIELD(righttree);
118         COPY_NODE_FIELD(initPlan);
119         COPY_INTLIST_FIELD(extParam);
120         COPY_INTLIST_FIELD(locParam);
121         COPY_SCALAR_FIELD(nParamExec);
122 }
123
124 /*
125  * _copyPlan
126  */
127 static Plan *
128 _copyPlan(Plan *from)
129 {
130         Plan       *newnode = makeNode(Plan);
131
132         /*
133          * copy node superclass fields
134          */
135         CopyPlanFields(from, newnode);
136
137         return newnode;
138 }
139
140
141 /*
142  * _copyResult
143  */
144 static Result *
145 _copyResult(Result *from)
146 {
147         Result     *newnode = makeNode(Result);
148
149         /*
150          * copy node superclass fields
151          */
152         CopyPlanFields((Plan *) from, (Plan *) newnode);
153
154         /*
155          * copy remainder of node
156          */
157         COPY_NODE_FIELD(resconstantqual);
158
159         return newnode;
160 }
161
162 /*
163  * _copyAppend
164  */
165 static Append *
166 _copyAppend(Append *from)
167 {
168         Append     *newnode = makeNode(Append);
169
170         /*
171          * copy node superclass fields
172          */
173         CopyPlanFields((Plan *) from, (Plan *) newnode);
174
175         /*
176          * copy remainder of node
177          */
178         COPY_NODE_FIELD(appendplans);
179         COPY_SCALAR_FIELD(isTarget);
180
181         return newnode;
182 }
183
184
185 /*
186  * CopyScanFields
187  *
188  *              This function copies the fields of the Scan node.  It is used by
189  *              all the copy functions for classes which inherit from Scan.
190  */
191 static void
192 CopyScanFields(Scan *from, Scan *newnode)
193 {
194         CopyPlanFields((Plan *) from, (Plan *) newnode);
195
196         COPY_SCALAR_FIELD(scanrelid);
197 }
198
199 /*
200  * _copyScan
201  */
202 static Scan *
203 _copyScan(Scan *from)
204 {
205         Scan       *newnode = makeNode(Scan);
206
207         /*
208          * copy node superclass fields
209          */
210         CopyScanFields((Scan *) from, (Scan *) newnode);
211
212         return newnode;
213 }
214
215 /*
216  * _copySeqScan
217  */
218 static SeqScan *
219 _copySeqScan(SeqScan *from)
220 {
221         SeqScan    *newnode = makeNode(SeqScan);
222
223         /*
224          * copy node superclass fields
225          */
226         CopyScanFields((Scan *) from, (Scan *) newnode);
227
228         return newnode;
229 }
230
231 /*
232  * _copyIndexScan
233  */
234 static IndexScan *
235 _copyIndexScan(IndexScan *from)
236 {
237         IndexScan  *newnode = makeNode(IndexScan);
238
239         /*
240          * copy node superclass fields
241          */
242         CopyScanFields((Scan *) from, (Scan *) newnode);
243
244         /*
245          * copy remainder of node
246          */
247         COPY_INTLIST_FIELD(indxid);
248         COPY_NODE_FIELD(indxqual);
249         COPY_NODE_FIELD(indxqualorig);
250         COPY_SCALAR_FIELD(indxorderdir);
251
252         return newnode;
253 }
254
255 /*
256  * _copyTidScan
257  */
258 static TidScan *
259 _copyTidScan(TidScan *from)
260 {
261         TidScan    *newnode = makeNode(TidScan);
262
263         /*
264          * copy node superclass fields
265          */
266         CopyScanFields((Scan *) from, (Scan *) newnode);
267
268         /*
269          * copy remainder of node
270          */
271         COPY_NODE_FIELD(tideval);
272
273         return newnode;
274 }
275
276 /*
277  * _copySubqueryScan
278  */
279 static SubqueryScan *
280 _copySubqueryScan(SubqueryScan *from)
281 {
282         SubqueryScan *newnode = makeNode(SubqueryScan);
283
284         /*
285          * copy node superclass fields
286          */
287         CopyScanFields((Scan *) from, (Scan *) newnode);
288
289         /*
290          * copy remainder of node
291          */
292         COPY_NODE_FIELD(subplan);
293
294         return newnode;
295 }
296
297 /*
298  * _copyFunctionScan
299  */
300 static FunctionScan *
301 _copyFunctionScan(FunctionScan *from)
302 {
303         FunctionScan *newnode = makeNode(FunctionScan);
304
305         /*
306          * copy node superclass fields
307          */
308         CopyScanFields((Scan *) from, (Scan *) newnode);
309
310         return newnode;
311 }
312
313 /*
314  * CopyJoinFields
315  *
316  *              This function copies the fields of the Join node.  It is used by
317  *              all the copy functions for classes which inherit from Join.
318  */
319 static void
320 CopyJoinFields(Join *from, Join *newnode)
321 {
322         CopyPlanFields((Plan *) from, (Plan *) newnode);
323
324         COPY_SCALAR_FIELD(jointype);
325         COPY_NODE_FIELD(joinqual);
326 }
327
328
329 /*
330  * _copyJoin
331  */
332 static Join *
333 _copyJoin(Join *from)
334 {
335         Join       *newnode = makeNode(Join);
336
337         /*
338          * copy node superclass fields
339          */
340         CopyJoinFields(from, newnode);
341
342         return newnode;
343 }
344
345
346 /*
347  * _copyNestLoop
348  */
349 static NestLoop *
350 _copyNestLoop(NestLoop *from)
351 {
352         NestLoop   *newnode = makeNode(NestLoop);
353
354         /*
355          * copy node superclass fields
356          */
357         CopyJoinFields((Join *) from, (Join *) newnode);
358
359         return newnode;
360 }
361
362
363 /*
364  * _copyMergeJoin
365  */
366 static MergeJoin *
367 _copyMergeJoin(MergeJoin *from)
368 {
369         MergeJoin  *newnode = makeNode(MergeJoin);
370
371         /*
372          * copy node superclass fields
373          */
374         CopyJoinFields((Join *) from, (Join *) newnode);
375
376         /*
377          * copy remainder of node
378          */
379         COPY_NODE_FIELD(mergeclauses);
380
381         return newnode;
382 }
383
384 /*
385  * _copyHashJoin
386  */
387 static HashJoin *
388 _copyHashJoin(HashJoin *from)
389 {
390         HashJoin   *newnode = makeNode(HashJoin);
391
392         /*
393          * copy node superclass fields
394          */
395         CopyJoinFields((Join *) from, (Join *) newnode);
396
397         /*
398          * copy remainder of node
399          */
400         COPY_NODE_FIELD(hashclauses);
401
402         return newnode;
403 }
404
405
406 /*
407  * _copyMaterial
408  */
409 static Material *
410 _copyMaterial(Material *from)
411 {
412         Material   *newnode = makeNode(Material);
413
414         /*
415          * copy node superclass fields
416          */
417         CopyPlanFields((Plan *) from, (Plan *) newnode);
418
419         return newnode;
420 }
421
422
423 /*
424  * _copySort
425  */
426 static Sort *
427 _copySort(Sort *from)
428 {
429         Sort       *newnode = makeNode(Sort);
430
431         /*
432          * copy node superclass fields
433          */
434         CopyPlanFields((Plan *) from, (Plan *) newnode);
435
436         COPY_SCALAR_FIELD(keycount);
437
438         return newnode;
439 }
440
441
442 /*
443  * _copyGroup
444  */
445 static Group *
446 _copyGroup(Group *from)
447 {
448         Group      *newnode = makeNode(Group);
449
450         CopyPlanFields((Plan *) from, (Plan *) newnode);
451
452         COPY_SCALAR_FIELD(numCols);
453         COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
454
455         return newnode;
456 }
457
458 /*
459  * _copyAgg
460  */
461 static Agg *
462 _copyAgg(Agg *from)
463 {
464         Agg                *newnode = makeNode(Agg);
465
466         CopyPlanFields((Plan *) from, (Plan *) newnode);
467
468         COPY_SCALAR_FIELD(aggstrategy);
469         COPY_SCALAR_FIELD(numCols);
470         if (from->numCols > 0)
471                 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
472         COPY_SCALAR_FIELD(numGroups);
473
474         return newnode;
475 }
476
477 /*
478  * _copyUnique
479  */
480 static Unique *
481 _copyUnique(Unique *from)
482 {
483         Unique     *newnode = makeNode(Unique);
484
485         /*
486          * copy node superclass fields
487          */
488         CopyPlanFields((Plan *) from, (Plan *) newnode);
489
490         /*
491          * copy remainder of node
492          */
493         COPY_SCALAR_FIELD(numCols);
494         COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
495
496         return newnode;
497 }
498
499 /*
500  * _copyHash
501  */
502 static Hash *
503 _copyHash(Hash *from)
504 {
505         Hash       *newnode = makeNode(Hash);
506
507         /*
508          * copy node superclass fields
509          */
510         CopyPlanFields((Plan *) from, (Plan *) newnode);
511
512         /*
513          * copy remainder of node
514          */
515         COPY_NODE_FIELD(hashkeys);
516
517         return newnode;
518 }
519
520 /*
521  * _copySetOp
522  */
523 static SetOp *
524 _copySetOp(SetOp *from)
525 {
526         SetOp      *newnode = makeNode(SetOp);
527
528         /*
529          * copy node superclass fields
530          */
531         CopyPlanFields((Plan *) from, (Plan *) newnode);
532
533         /*
534          * copy remainder of node
535          */
536         COPY_SCALAR_FIELD(cmd);
537         COPY_SCALAR_FIELD(numCols);
538         COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
539         COPY_SCALAR_FIELD(flagColIdx);
540
541         return newnode;
542 }
543
544 /*
545  * _copyLimit
546  */
547 static Limit *
548 _copyLimit(Limit *from)
549 {
550         Limit      *newnode = makeNode(Limit);
551
552         /*
553          * copy node superclass fields
554          */
555         CopyPlanFields((Plan *) from, (Plan *) newnode);
556
557         /*
558          * copy remainder of node
559          */
560         COPY_NODE_FIELD(limitOffset);
561         COPY_NODE_FIELD(limitCount);
562
563         return newnode;
564 }
565
566 /* ****************************************************************
567  *                                         primnodes.h copy functions
568  * ****************************************************************
569  */
570
571 /*
572  * _copyResdom
573  */
574 static Resdom *
575 _copyResdom(Resdom *from)
576 {
577         Resdom     *newnode = makeNode(Resdom);
578
579         COPY_SCALAR_FIELD(resno);
580         COPY_SCALAR_FIELD(restype);
581         COPY_SCALAR_FIELD(restypmod);
582         COPY_STRING_FIELD(resname);
583         COPY_SCALAR_FIELD(ressortgroupref);
584         COPY_SCALAR_FIELD(reskey);
585         COPY_SCALAR_FIELD(reskeyop);
586         COPY_SCALAR_FIELD(resjunk);
587
588         return newnode;
589 }
590
591 /*
592  * _copyAlias
593  */
594 static Alias *
595 _copyAlias(Alias *from)
596 {
597         Alias      *newnode = makeNode(Alias);
598
599         COPY_STRING_FIELD(aliasname);
600         COPY_NODE_FIELD(colnames);
601
602         return newnode;
603 }
604
605 /*
606  * _copyRangeVar
607  */
608 static RangeVar *
609 _copyRangeVar(RangeVar *from)
610 {
611         RangeVar   *newnode = makeNode(RangeVar);
612
613         COPY_STRING_FIELD(catalogname);
614         COPY_STRING_FIELD(schemaname);
615         COPY_STRING_FIELD(relname);
616         COPY_SCALAR_FIELD(inhOpt);
617         COPY_SCALAR_FIELD(istemp);
618         COPY_NODE_FIELD(alias);
619
620         return newnode;
621 }
622
623 /*
624  * We don't need a _copyExpr because Expr is an abstract supertype which
625  * should never actually get instantiated.  Also, since it has no common
626  * fields except NodeTag, there's no need for a helper routine to factor
627  * out copying the common fields...
628  */
629
630 /*
631  * _copyVar
632  */
633 static Var *
634 _copyVar(Var *from)
635 {
636         Var                *newnode = makeNode(Var);
637
638         COPY_SCALAR_FIELD(varno);
639         COPY_SCALAR_FIELD(varattno);
640         COPY_SCALAR_FIELD(vartype);
641         COPY_SCALAR_FIELD(vartypmod);
642         COPY_SCALAR_FIELD(varlevelsup);
643         COPY_SCALAR_FIELD(varnoold);
644         COPY_SCALAR_FIELD(varoattno);
645
646         return newnode;
647 }
648
649 /*
650  * _copyConst
651  */
652 static Const *
653 _copyConst(Const *from)
654 {
655         Const      *newnode = makeNode(Const);
656
657         COPY_SCALAR_FIELD(consttype);
658         COPY_SCALAR_FIELD(constlen);
659
660         if (from->constbyval || from->constisnull)
661         {
662                 /*
663                  * passed by value so just copy the datum. Also, don't try to copy
664                  * struct when value is null!
665                  */
666                 newnode->constvalue = from->constvalue;
667         }
668         else
669         {
670                 /*
671                  * passed by reference.  We need a palloc'd copy.
672                  */
673                 newnode->constvalue = datumCopy(from->constvalue,
674                                                                                 from->constbyval,
675                                                                                 from->constlen);
676         }
677
678         COPY_SCALAR_FIELD(constisnull);
679         COPY_SCALAR_FIELD(constbyval);
680
681         return newnode;
682 }
683
684 /*
685  * _copyParam
686  */
687 static Param *
688 _copyParam(Param *from)
689 {
690         Param      *newnode = makeNode(Param);
691
692         COPY_SCALAR_FIELD(paramkind);
693         COPY_SCALAR_FIELD(paramid);
694         COPY_STRING_FIELD(paramname);
695         COPY_SCALAR_FIELD(paramtype);
696
697         return newnode;
698 }
699
700 /*
701  * _copyAggref
702  */
703 static Aggref *
704 _copyAggref(Aggref *from)
705 {
706         Aggref     *newnode = makeNode(Aggref);
707
708         COPY_SCALAR_FIELD(aggfnoid);
709         COPY_SCALAR_FIELD(aggtype);
710         COPY_NODE_FIELD(target);
711         COPY_SCALAR_FIELD(aggstar);
712         COPY_SCALAR_FIELD(aggdistinct);
713
714         return newnode;
715 }
716
717 /*
718  * _copyArrayRef
719  */
720 static ArrayRef *
721 _copyArrayRef(ArrayRef *from)
722 {
723         ArrayRef   *newnode = makeNode(ArrayRef);
724
725         COPY_SCALAR_FIELD(refrestype);
726         COPY_SCALAR_FIELD(refattrlength);
727         COPY_SCALAR_FIELD(refelemlength);
728         COPY_SCALAR_FIELD(refelembyval);
729         COPY_SCALAR_FIELD(refelemalign);
730         COPY_NODE_FIELD(refupperindexpr);
731         COPY_NODE_FIELD(reflowerindexpr);
732         COPY_NODE_FIELD(refexpr);
733         COPY_NODE_FIELD(refassgnexpr);
734
735         return newnode;
736 }
737
738 /*
739  * _copyFuncExpr
740  */
741 static FuncExpr *
742 _copyFuncExpr(FuncExpr *from)
743 {
744         FuncExpr           *newnode = makeNode(FuncExpr);
745
746         COPY_SCALAR_FIELD(funcid);
747         COPY_SCALAR_FIELD(funcresulttype);
748         COPY_SCALAR_FIELD(funcretset);
749         COPY_SCALAR_FIELD(funcformat);
750         COPY_NODE_FIELD(args);
751
752         return newnode;
753 }
754
755 /*
756  * _copyOpExpr
757  */
758 static OpExpr *
759 _copyOpExpr(OpExpr *from)
760 {
761         OpExpr     *newnode = makeNode(OpExpr);
762
763         COPY_SCALAR_FIELD(opno);
764         COPY_SCALAR_FIELD(opfuncid);
765         COPY_SCALAR_FIELD(opresulttype);
766         COPY_SCALAR_FIELD(opretset);
767         COPY_NODE_FIELD(args);
768
769         return newnode;
770 }
771
772 /*
773  * _copyDistinctExpr
774  */
775 static DistinctExpr *
776 _copyDistinctExpr(DistinctExpr *from)
777 {
778         DistinctExpr       *newnode = makeNode(DistinctExpr);
779
780         COPY_SCALAR_FIELD(opno);
781         COPY_SCALAR_FIELD(opfuncid);
782         COPY_SCALAR_FIELD(opresulttype);
783         COPY_SCALAR_FIELD(opretset);
784         COPY_NODE_FIELD(args);
785
786         return newnode;
787 }
788
789 /*
790  * _copyBoolExpr
791  */
792 static BoolExpr *
793 _copyBoolExpr(BoolExpr *from)
794 {
795         BoolExpr           *newnode = makeNode(BoolExpr);
796
797         COPY_SCALAR_FIELD(boolop);
798         COPY_NODE_FIELD(args);
799
800         return newnode;
801 }
802
803 /*
804  * _copySubLink
805  */
806 static SubLink *
807 _copySubLink(SubLink *from)
808 {
809         SubLink    *newnode = makeNode(SubLink);
810
811         COPY_SCALAR_FIELD(subLinkType);
812         COPY_SCALAR_FIELD(useor);
813         COPY_NODE_FIELD(lefthand);
814         COPY_NODE_FIELD(oper);
815         COPY_NODE_FIELD(subselect);
816
817         return newnode;
818 }
819
820 /*
821  * _copySubPlan
822  */
823 static SubPlan *
824 _copySubPlan(SubPlan *from)
825 {
826         SubPlan    *newnode = makeNode(SubPlan);
827
828         COPY_SCALAR_FIELD(subLinkType);
829         COPY_SCALAR_FIELD(useor);
830         COPY_NODE_FIELD(oper);
831         COPY_NODE_FIELD(plan);
832         COPY_SCALAR_FIELD(plan_id);
833         COPY_NODE_FIELD(rtable);
834         COPY_INTLIST_FIELD(setParam);
835         COPY_INTLIST_FIELD(parParam);
836         COPY_NODE_FIELD(args);
837
838         return newnode;
839 }
840
841 /*
842  * _copyFieldSelect
843  */
844 static FieldSelect *
845 _copyFieldSelect(FieldSelect *from)
846 {
847         FieldSelect *newnode = makeNode(FieldSelect);
848
849         COPY_NODE_FIELD(arg);
850         COPY_SCALAR_FIELD(fieldnum);
851         COPY_SCALAR_FIELD(resulttype);
852         COPY_SCALAR_FIELD(resulttypmod);
853
854         return newnode;
855 }
856
857 /*
858  * _copyRelabelType
859  */
860 static RelabelType *
861 _copyRelabelType(RelabelType *from)
862 {
863         RelabelType *newnode = makeNode(RelabelType);
864
865         COPY_NODE_FIELD(arg);
866         COPY_SCALAR_FIELD(resulttype);
867         COPY_SCALAR_FIELD(resulttypmod);
868         COPY_SCALAR_FIELD(relabelformat);
869
870         return newnode;
871 }
872
873 /*
874  * _copyCaseExpr
875  */
876 static CaseExpr *
877 _copyCaseExpr(CaseExpr *from)
878 {
879         CaseExpr   *newnode = makeNode(CaseExpr);
880
881         COPY_SCALAR_FIELD(casetype);
882         COPY_NODE_FIELD(arg);
883         COPY_NODE_FIELD(args);
884         COPY_NODE_FIELD(defresult);
885
886         return newnode;
887 }
888
889 /*
890  * _copyCaseWhen
891  */
892 static CaseWhen *
893 _copyCaseWhen(CaseWhen *from)
894 {
895         CaseWhen   *newnode = makeNode(CaseWhen);
896
897         COPY_NODE_FIELD(expr);
898         COPY_NODE_FIELD(result);
899
900         return newnode;
901 }
902
903 /*
904  * _copyNullTest
905  */
906 static NullTest *
907 _copyNullTest(NullTest *from)
908 {
909         NullTest   *newnode = makeNode(NullTest);
910
911         COPY_NODE_FIELD(arg);
912         COPY_SCALAR_FIELD(nulltesttype);
913
914         return newnode;
915 }
916
917 /*
918  * _copyBooleanTest
919  */
920 static BooleanTest *
921 _copyBooleanTest(BooleanTest *from)
922 {
923         BooleanTest *newnode = makeNode(BooleanTest);
924
925         COPY_NODE_FIELD(arg);
926         COPY_SCALAR_FIELD(booltesttype);
927
928         return newnode;
929 }
930
931 /*
932  * _copyConstraintTest
933  */
934 static ConstraintTest *
935 _copyConstraintTest(ConstraintTest *from)
936 {
937         ConstraintTest *newnode = makeNode(ConstraintTest);
938
939         COPY_NODE_FIELD(arg);
940         COPY_SCALAR_FIELD(testtype);
941         COPY_STRING_FIELD(name);
942         COPY_STRING_FIELD(domname);
943         COPY_NODE_FIELD(check_expr);
944
945         return newnode;
946 }
947
948 /*
949  * _copyConstraintTestValue
950  */
951 static ConstraintTestValue *
952 _copyConstraintTestValue(ConstraintTestValue *from)
953 {
954         ConstraintTestValue *newnode = makeNode(ConstraintTestValue);
955
956         COPY_SCALAR_FIELD(typeId);
957         COPY_SCALAR_FIELD(typeMod);
958
959         return newnode;
960 }
961
962 /*
963  * _copyTargetEntry
964  */
965 static TargetEntry *
966 _copyTargetEntry(TargetEntry *from)
967 {
968         TargetEntry *newnode = makeNode(TargetEntry);
969
970         COPY_NODE_FIELD(resdom);
971         COPY_NODE_FIELD(expr);
972
973         return newnode;
974 }
975
976 /*
977  * _copyRangeTblRef
978  */
979 static RangeTblRef *
980 _copyRangeTblRef(RangeTblRef *from)
981 {
982         RangeTblRef *newnode = makeNode(RangeTblRef);
983
984         COPY_SCALAR_FIELD(rtindex);
985
986         return newnode;
987 }
988
989 /*
990  * _copyJoinExpr
991  */
992 static JoinExpr *
993 _copyJoinExpr(JoinExpr *from)
994 {
995         JoinExpr   *newnode = makeNode(JoinExpr);
996
997         COPY_SCALAR_FIELD(jointype);
998         COPY_SCALAR_FIELD(isNatural);
999         COPY_NODE_FIELD(larg);
1000         COPY_NODE_FIELD(rarg);
1001         COPY_NODE_FIELD(using);
1002         COPY_NODE_FIELD(quals);
1003         COPY_NODE_FIELD(alias);
1004         COPY_SCALAR_FIELD(rtindex);
1005
1006         return newnode;
1007 }
1008
1009 /*
1010  * _copyFromExpr
1011  */
1012 static FromExpr *
1013 _copyFromExpr(FromExpr *from)
1014 {
1015         FromExpr   *newnode = makeNode(FromExpr);
1016
1017         COPY_NODE_FIELD(fromlist);
1018         COPY_NODE_FIELD(quals);
1019
1020         return newnode;
1021 }
1022
1023 /* ****************************************************************
1024  *                                              relation.h copy functions
1025  *
1026  * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1027  * There are some subsidiary structs that are useful to copy, though.
1028  * ****************************************************************
1029  */
1030
1031 /*
1032  * _copyPathKeyItem
1033  */
1034 static PathKeyItem *
1035 _copyPathKeyItem(PathKeyItem *from)
1036 {
1037         PathKeyItem *newnode = makeNode(PathKeyItem);
1038
1039         COPY_NODE_FIELD(key);
1040         COPY_SCALAR_FIELD(sortop);
1041
1042         return newnode;
1043 }
1044
1045 /*
1046  * _copyRestrictInfo
1047  */
1048 static RestrictInfo *
1049 _copyRestrictInfo(RestrictInfo *from)
1050 {
1051         RestrictInfo *newnode = makeNode(RestrictInfo);
1052
1053         COPY_NODE_FIELD(clause);
1054         COPY_SCALAR_FIELD(ispusheddown);
1055         COPY_NODE_FIELD(subclauseindices); /* XXX probably bad */
1056         COPY_SCALAR_FIELD(eval_cost);
1057         COPY_SCALAR_FIELD(this_selec);
1058         COPY_SCALAR_FIELD(mergejoinoperator);
1059         COPY_SCALAR_FIELD(left_sortop);
1060         COPY_SCALAR_FIELD(right_sortop);
1061
1062         /*
1063          * Do not copy pathkeys, since they'd not be canonical in a copied
1064          * query
1065          */
1066         newnode->left_pathkey = NIL;
1067         newnode->right_pathkey = NIL;
1068
1069         COPY_SCALAR_FIELD(left_mergescansel);
1070         COPY_SCALAR_FIELD(right_mergescansel);
1071         COPY_SCALAR_FIELD(hashjoinoperator);
1072         COPY_SCALAR_FIELD(left_bucketsize);
1073         COPY_SCALAR_FIELD(right_bucketsize);
1074
1075         return newnode;
1076 }
1077
1078 /*
1079  * _copyJoinInfo
1080  */
1081 static JoinInfo *
1082 _copyJoinInfo(JoinInfo *from)
1083 {
1084         JoinInfo   *newnode = makeNode(JoinInfo);
1085
1086         COPY_INTLIST_FIELD(unjoined_relids);
1087         COPY_NODE_FIELD(jinfo_restrictinfo);
1088
1089         return newnode;
1090 }
1091
1092 /* ****************************************************************
1093  *                                      parsenodes.h copy functions
1094  * ****************************************************************
1095  */
1096
1097 static RangeTblEntry *
1098 _copyRangeTblEntry(RangeTblEntry *from)
1099 {
1100         RangeTblEntry *newnode = makeNode(RangeTblEntry);
1101
1102         COPY_SCALAR_FIELD(rtekind);
1103         COPY_SCALAR_FIELD(relid);
1104         COPY_NODE_FIELD(subquery);
1105         COPY_NODE_FIELD(funcexpr);
1106         COPY_NODE_FIELD(coldeflist);
1107         COPY_SCALAR_FIELD(jointype);
1108         COPY_NODE_FIELD(joinaliasvars);
1109         COPY_NODE_FIELD(alias);
1110         COPY_NODE_FIELD(eref);
1111         COPY_SCALAR_FIELD(inh);
1112         COPY_SCALAR_FIELD(inFromCl);
1113         COPY_SCALAR_FIELD(checkForRead);
1114         COPY_SCALAR_FIELD(checkForWrite);
1115         COPY_SCALAR_FIELD(checkAsUser);
1116
1117         return newnode;
1118 }
1119
1120 static FkConstraint *
1121 _copyFkConstraint(FkConstraint *from)
1122 {
1123         FkConstraint *newnode = makeNode(FkConstraint);
1124
1125         COPY_STRING_FIELD(constr_name);
1126         COPY_NODE_FIELD(pktable);
1127         COPY_NODE_FIELD(fk_attrs);
1128         COPY_NODE_FIELD(pk_attrs);
1129         COPY_SCALAR_FIELD(fk_matchtype);
1130         COPY_SCALAR_FIELD(fk_upd_action);
1131         COPY_SCALAR_FIELD(fk_del_action);
1132         COPY_SCALAR_FIELD(deferrable);
1133         COPY_SCALAR_FIELD(initdeferred);
1134         COPY_SCALAR_FIELD(skip_validation);
1135
1136         return newnode;
1137 }
1138
1139 static SortClause *
1140 _copySortClause(SortClause *from)
1141 {
1142         SortClause *newnode = makeNode(SortClause);
1143
1144         COPY_SCALAR_FIELD(tleSortGroupRef);
1145         COPY_SCALAR_FIELD(sortop);
1146
1147         return newnode;
1148 }
1149
1150 static GroupClause *
1151 _copyGroupClause(GroupClause *from)
1152 {
1153         GroupClause *newnode = makeNode(GroupClause);
1154
1155         COPY_SCALAR_FIELD(tleSortGroupRef);
1156         COPY_SCALAR_FIELD(sortop);
1157
1158         return newnode;
1159 }
1160
1161 static A_Expr *
1162 _copyAExpr(A_Expr *from)
1163 {
1164         A_Expr     *newnode = makeNode(A_Expr);
1165
1166         COPY_SCALAR_FIELD(oper);
1167         COPY_NODE_FIELD(name);
1168         COPY_NODE_FIELD(lexpr);
1169         COPY_NODE_FIELD(rexpr);
1170
1171         return newnode;
1172 }
1173
1174 static ColumnRef *
1175 _copyColumnRef(ColumnRef *from)
1176 {
1177         ColumnRef  *newnode = makeNode(ColumnRef);
1178
1179         COPY_NODE_FIELD(fields);
1180         COPY_NODE_FIELD(indirection);
1181
1182         return newnode;
1183 }
1184
1185 static ParamRef *
1186 _copyParamRef(ParamRef *from)
1187 {
1188         ParamRef   *newnode = makeNode(ParamRef);
1189
1190         COPY_SCALAR_FIELD(number);
1191         COPY_NODE_FIELD(fields);
1192         COPY_NODE_FIELD(indirection);
1193
1194         return newnode;
1195 }
1196
1197 static A_Const *
1198 _copyAConst(A_Const *from)
1199 {
1200         A_Const    *newnode = makeNode(A_Const);
1201
1202         /* This part must duplicate _copyValue */
1203         COPY_SCALAR_FIELD(val.type);
1204         switch (from->val.type)
1205         {
1206                 case T_Integer:
1207                         COPY_SCALAR_FIELD(val.val.ival);
1208                         break;
1209                 case T_Float:
1210                 case T_String:
1211                 case T_BitString:
1212                         COPY_STRING_FIELD(val.val.str);
1213                         break;
1214                 case T_Null:
1215                         /* nothing to do */
1216                         break;
1217                 default:
1218                         elog(ERROR, "_copyAConst: unknown node type %d", from->val.type);
1219                         break;
1220         }
1221
1222         COPY_NODE_FIELD(typename);
1223
1224         return newnode;
1225 }
1226
1227 static FuncCall *
1228 _copyFuncCall(FuncCall *from)
1229 {
1230         FuncCall   *newnode = makeNode(FuncCall);
1231
1232         COPY_NODE_FIELD(funcname);
1233         COPY_NODE_FIELD(args);
1234         COPY_SCALAR_FIELD(agg_star);
1235         COPY_SCALAR_FIELD(agg_distinct);
1236
1237         return newnode;
1238 }
1239
1240 static A_Indices *
1241 _copyAIndices(A_Indices *from)
1242 {
1243         A_Indices  *newnode = makeNode(A_Indices);
1244
1245         COPY_NODE_FIELD(lidx);
1246         COPY_NODE_FIELD(uidx);
1247
1248         return newnode;
1249 }
1250
1251 static ExprFieldSelect *
1252 _copyExprFieldSelect(ExprFieldSelect *from)
1253 {
1254         ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
1255
1256         COPY_NODE_FIELD(arg);
1257         COPY_NODE_FIELD(fields);
1258         COPY_NODE_FIELD(indirection);
1259
1260         return newnode;
1261 }
1262
1263 static ResTarget *
1264 _copyResTarget(ResTarget *from)
1265 {
1266         ResTarget  *newnode = makeNode(ResTarget);
1267
1268         COPY_STRING_FIELD(name);
1269         COPY_NODE_FIELD(indirection);
1270         COPY_NODE_FIELD(val);
1271
1272         return newnode;
1273 }
1274
1275 static TypeName *
1276 _copyTypeName(TypeName *from)
1277 {
1278         TypeName   *newnode = makeNode(TypeName);
1279
1280         COPY_NODE_FIELD(names);
1281         COPY_SCALAR_FIELD(typeid);
1282         COPY_SCALAR_FIELD(timezone);
1283         COPY_SCALAR_FIELD(setof);
1284         COPY_SCALAR_FIELD(pct_type);
1285         COPY_SCALAR_FIELD(typmod);
1286         COPY_NODE_FIELD(arrayBounds);
1287
1288         return newnode;
1289 }
1290
1291 static SortGroupBy *
1292 _copySortGroupBy(SortGroupBy *from)
1293 {
1294         SortGroupBy *newnode = makeNode(SortGroupBy);
1295
1296         COPY_NODE_FIELD(useOp);
1297         COPY_NODE_FIELD(node);
1298
1299         return newnode;
1300 }
1301
1302 static RangeSubselect *
1303 _copyRangeSubselect(RangeSubselect *from)
1304 {
1305         RangeSubselect *newnode = makeNode(RangeSubselect);
1306
1307         COPY_NODE_FIELD(subquery);
1308         COPY_NODE_FIELD(alias);
1309
1310         return newnode;
1311 }
1312
1313 static RangeFunction *
1314 _copyRangeFunction(RangeFunction *from)
1315 {
1316         RangeFunction *newnode = makeNode(RangeFunction);
1317
1318         COPY_NODE_FIELD(funccallnode);
1319         COPY_NODE_FIELD(alias);
1320         COPY_NODE_FIELD(coldeflist);
1321
1322         return newnode;
1323 }
1324
1325 static TypeCast *
1326 _copyTypeCast(TypeCast *from)
1327 {
1328         TypeCast   *newnode = makeNode(TypeCast);
1329
1330         COPY_NODE_FIELD(arg);
1331         COPY_NODE_FIELD(typename);
1332
1333         return newnode;
1334 }
1335
1336 static IndexElem *
1337 _copyIndexElem(IndexElem *from)
1338 {
1339         IndexElem  *newnode = makeNode(IndexElem);
1340
1341         COPY_STRING_FIELD(name);
1342         COPY_NODE_FIELD(funcname);
1343         COPY_NODE_FIELD(args);
1344         COPY_NODE_FIELD(opclass);
1345
1346         return newnode;
1347 }
1348
1349 static ColumnDef *
1350 _copyColumnDef(ColumnDef *from)
1351 {
1352         ColumnDef  *newnode = makeNode(ColumnDef);
1353
1354         COPY_STRING_FIELD(colname);
1355         COPY_NODE_FIELD(typename);
1356         COPY_SCALAR_FIELD(inhcount);
1357         COPY_SCALAR_FIELD(is_local);
1358         COPY_SCALAR_FIELD(is_not_null);
1359         COPY_NODE_FIELD(raw_default);
1360         COPY_STRING_FIELD(cooked_default);
1361         COPY_NODE_FIELD(constraints);
1362         COPY_NODE_FIELD(support);
1363
1364         return newnode;
1365 }
1366
1367 static Constraint *
1368 _copyConstraint(Constraint *from)
1369 {
1370         Constraint *newnode = makeNode(Constraint);
1371
1372         COPY_SCALAR_FIELD(contype);
1373         COPY_STRING_FIELD(name);
1374         COPY_NODE_FIELD(raw_expr);
1375         COPY_STRING_FIELD(cooked_expr);
1376         COPY_NODE_FIELD(keys);
1377
1378         return newnode;
1379 }
1380
1381 static DefElem *
1382 _copyDefElem(DefElem *from)
1383 {
1384         DefElem    *newnode = makeNode(DefElem);
1385
1386         COPY_STRING_FIELD(defname);
1387         COPY_NODE_FIELD(arg);
1388
1389         return newnode;
1390 }
1391
1392 static Query *
1393 _copyQuery(Query *from)
1394 {
1395         Query      *newnode = makeNode(Query);
1396
1397         COPY_SCALAR_FIELD(commandType);
1398         COPY_SCALAR_FIELD(querySource);
1399         COPY_NODE_FIELD(utilityStmt);
1400         COPY_SCALAR_FIELD(resultRelation);
1401         COPY_NODE_FIELD(into);
1402         COPY_SCALAR_FIELD(isPortal);
1403         COPY_SCALAR_FIELD(isBinary);
1404         COPY_SCALAR_FIELD(hasAggs);
1405         COPY_SCALAR_FIELD(hasSubLinks);
1406         COPY_NODE_FIELD(rtable);
1407         COPY_NODE_FIELD(jointree);
1408         COPY_INTLIST_FIELD(rowMarks);
1409         COPY_NODE_FIELD(targetList);
1410         COPY_NODE_FIELD(groupClause);
1411         COPY_NODE_FIELD(havingQual);
1412         COPY_NODE_FIELD(distinctClause);
1413         COPY_NODE_FIELD(sortClause);
1414         COPY_NODE_FIELD(limitOffset);
1415         COPY_NODE_FIELD(limitCount);
1416         COPY_NODE_FIELD(setOperations);
1417         COPY_INTLIST_FIELD(resultRelations);
1418
1419         /*
1420          * We do not copy the planner internal fields: base_rel_list,
1421          * other_rel_list, join_rel_list, equi_key_list, query_pathkeys,
1422          * hasJoinRTEs.  That would get us into copying RelOptInfo/Path
1423          * trees, which we don't want to do.
1424          */
1425
1426         return newnode;
1427 }
1428
1429 static InsertStmt *
1430 _copyInsertStmt(InsertStmt *from)
1431 {
1432         InsertStmt *newnode = makeNode(InsertStmt);
1433
1434         COPY_NODE_FIELD(relation);
1435         COPY_NODE_FIELD(cols);
1436         COPY_NODE_FIELD(targetList);
1437         COPY_NODE_FIELD(selectStmt);
1438
1439         return newnode;
1440 }
1441
1442 static DeleteStmt *
1443 _copyDeleteStmt(DeleteStmt *from)
1444 {
1445         DeleteStmt *newnode = makeNode(DeleteStmt);
1446
1447         COPY_NODE_FIELD(relation);
1448         COPY_NODE_FIELD(whereClause);
1449
1450         return newnode;
1451 }
1452
1453 static UpdateStmt *
1454 _copyUpdateStmt(UpdateStmt *from)
1455 {
1456         UpdateStmt *newnode = makeNode(UpdateStmt);
1457
1458         COPY_NODE_FIELD(relation);
1459         COPY_NODE_FIELD(targetList);
1460         COPY_NODE_FIELD(whereClause);
1461         COPY_NODE_FIELD(fromClause);
1462
1463         return newnode;
1464 }
1465
1466 static SelectStmt *
1467 _copySelectStmt(SelectStmt *from)
1468 {
1469         SelectStmt *newnode = makeNode(SelectStmt);
1470
1471         COPY_NODE_FIELD(distinctClause);
1472         COPY_NODE_FIELD(into);
1473         COPY_NODE_FIELD(intoColNames);
1474         COPY_NODE_FIELD(targetList);
1475         COPY_NODE_FIELD(fromClause);
1476         COPY_NODE_FIELD(whereClause);
1477         COPY_NODE_FIELD(groupClause);
1478         COPY_NODE_FIELD(havingClause);
1479         COPY_NODE_FIELD(sortClause);
1480         COPY_STRING_FIELD(portalname);
1481         COPY_SCALAR_FIELD(binary);
1482         COPY_NODE_FIELD(limitOffset);
1483         COPY_NODE_FIELD(limitCount);
1484         COPY_NODE_FIELD(forUpdate);
1485         COPY_SCALAR_FIELD(op);
1486         COPY_SCALAR_FIELD(all);
1487         COPY_NODE_FIELD(larg);
1488         COPY_NODE_FIELD(rarg);
1489
1490         return newnode;
1491 }
1492
1493 static SetOperationStmt *
1494 _copySetOperationStmt(SetOperationStmt *from)
1495 {
1496         SetOperationStmt *newnode = makeNode(SetOperationStmt);
1497
1498         COPY_SCALAR_FIELD(op);
1499         COPY_SCALAR_FIELD(all);
1500         COPY_NODE_FIELD(larg);
1501         COPY_NODE_FIELD(rarg);
1502         COPY_INTLIST_FIELD(colTypes);
1503
1504         return newnode;
1505 }
1506
1507 static AlterTableStmt *
1508 _copyAlterTableStmt(AlterTableStmt *from)
1509 {
1510         AlterTableStmt *newnode = makeNode(AlterTableStmt);
1511
1512         COPY_SCALAR_FIELD(subtype);
1513         COPY_NODE_FIELD(relation);
1514         COPY_STRING_FIELD(name);
1515         COPY_NODE_FIELD(def);
1516         COPY_SCALAR_FIELD(behavior);
1517
1518         return newnode;
1519 }
1520
1521 static AlterDomainStmt *
1522 _copyAlterDomainStmt(AlterDomainStmt *from)
1523 {
1524         AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1525
1526         COPY_SCALAR_FIELD(subtype);
1527         COPY_NODE_FIELD(typename);
1528         COPY_STRING_FIELD(name);
1529         COPY_NODE_FIELD(def);
1530         COPY_SCALAR_FIELD(behavior);
1531
1532         return newnode;
1533
1534
1535 static GrantStmt *
1536 _copyGrantStmt(GrantStmt *from)
1537 {
1538         GrantStmt  *newnode = makeNode(GrantStmt);
1539
1540         COPY_SCALAR_FIELD(is_grant);
1541         COPY_SCALAR_FIELD(objtype);
1542         COPY_NODE_FIELD(objects);
1543         COPY_INTLIST_FIELD(privileges);
1544         COPY_NODE_FIELD(grantees);
1545
1546         return newnode;
1547 }
1548
1549 static PrivGrantee *
1550 _copyPrivGrantee(PrivGrantee *from)
1551 {
1552         PrivGrantee *newnode = makeNode(PrivGrantee);
1553
1554         COPY_STRING_FIELD(username);
1555         COPY_STRING_FIELD(groupname);
1556
1557         return newnode;
1558 }
1559
1560 static FuncWithArgs *
1561 _copyFuncWithArgs(FuncWithArgs *from)
1562 {
1563         FuncWithArgs *newnode = makeNode(FuncWithArgs);
1564
1565         COPY_NODE_FIELD(funcname);
1566         COPY_NODE_FIELD(funcargs);
1567
1568         return newnode;
1569 }
1570
1571 static InsertDefault *
1572 _copyInsertDefault(InsertDefault *from)
1573 {
1574         InsertDefault *newnode = makeNode(InsertDefault);
1575
1576         return newnode;
1577 }
1578
1579
1580 static ClosePortalStmt *
1581 _copyClosePortalStmt(ClosePortalStmt *from)
1582 {
1583         ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1584
1585         COPY_STRING_FIELD(portalname);
1586
1587         return newnode;
1588 }
1589
1590 static ClusterStmt *
1591 _copyClusterStmt(ClusterStmt *from)
1592 {
1593         ClusterStmt *newnode = makeNode(ClusterStmt);
1594
1595         COPY_NODE_FIELD(relation);
1596         COPY_STRING_FIELD(indexname);
1597
1598         return newnode;
1599 }
1600
1601 static CopyStmt *
1602 _copyCopyStmt(CopyStmt *from)
1603 {
1604         CopyStmt   *newnode = makeNode(CopyStmt);
1605
1606         COPY_NODE_FIELD(relation);
1607         COPY_NODE_FIELD(attlist);
1608         COPY_SCALAR_FIELD(is_from);
1609         COPY_STRING_FIELD(filename);
1610         COPY_NODE_FIELD(options);
1611
1612         return newnode;
1613 }
1614
1615 static CreateStmt *
1616 _copyCreateStmt(CreateStmt *from)
1617 {
1618         CreateStmt *newnode = makeNode(CreateStmt);
1619
1620         COPY_NODE_FIELD(relation);
1621         COPY_NODE_FIELD(tableElts);
1622         COPY_NODE_FIELD(inhRelations);
1623         COPY_NODE_FIELD(constraints);
1624         COPY_SCALAR_FIELD(hasoids);
1625         COPY_SCALAR_FIELD(oncommit);
1626
1627         return newnode;
1628 }
1629
1630 static DefineStmt *
1631 _copyDefineStmt(DefineStmt *from)
1632 {
1633         DefineStmt *newnode = makeNode(DefineStmt);
1634
1635         COPY_SCALAR_FIELD(defType);
1636         COPY_NODE_FIELD(defnames);
1637         COPY_NODE_FIELD(definition);
1638
1639         return newnode;
1640 }
1641
1642 static DropStmt *
1643 _copyDropStmt(DropStmt *from)
1644 {
1645         DropStmt   *newnode = makeNode(DropStmt);
1646
1647         COPY_NODE_FIELD(objects);
1648         COPY_SCALAR_FIELD(removeType);
1649         COPY_SCALAR_FIELD(behavior);
1650
1651         return newnode;
1652 }
1653
1654 static TruncateStmt *
1655 _copyTruncateStmt(TruncateStmt *from)
1656 {
1657         TruncateStmt *newnode = makeNode(TruncateStmt);
1658
1659         COPY_NODE_FIELD(relation);
1660
1661         return newnode;
1662 }
1663
1664 static CommentStmt *
1665 _copyCommentStmt(CommentStmt *from)
1666 {
1667         CommentStmt *newnode = makeNode(CommentStmt);
1668
1669         COPY_SCALAR_FIELD(objtype);
1670         COPY_NODE_FIELD(objname);
1671         COPY_NODE_FIELD(objargs);
1672         COPY_STRING_FIELD(comment);
1673
1674         return newnode;
1675 }
1676
1677 static FetchStmt *
1678 _copyFetchStmt(FetchStmt *from)
1679 {
1680         FetchStmt  *newnode = makeNode(FetchStmt);
1681
1682         COPY_SCALAR_FIELD(direction);
1683         COPY_SCALAR_FIELD(howMany);
1684         COPY_STRING_FIELD(portalname);
1685         COPY_SCALAR_FIELD(ismove);
1686
1687         return newnode;
1688 }
1689
1690 static IndexStmt *
1691 _copyIndexStmt(IndexStmt *from)
1692 {
1693         IndexStmt  *newnode = makeNode(IndexStmt);
1694
1695         COPY_STRING_FIELD(idxname);
1696         COPY_NODE_FIELD(relation);
1697         COPY_STRING_FIELD(accessMethod);
1698         COPY_NODE_FIELD(indexParams);
1699         COPY_NODE_FIELD(whereClause);
1700         COPY_NODE_FIELD(rangetable);
1701         COPY_SCALAR_FIELD(unique);
1702         COPY_SCALAR_FIELD(primary);
1703         COPY_SCALAR_FIELD(isconstraint);
1704
1705         return newnode;
1706 }
1707
1708 static CreateFunctionStmt *
1709 _copyCreateFunctionStmt(CreateFunctionStmt *from)
1710 {
1711         CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
1712
1713         COPY_SCALAR_FIELD(replace);
1714         COPY_NODE_FIELD(funcname);
1715         COPY_NODE_FIELD(argTypes);
1716         COPY_NODE_FIELD(returnType);
1717         COPY_NODE_FIELD(options);
1718         COPY_NODE_FIELD(withClause);
1719
1720         return newnode;
1721 }
1722
1723 static RemoveAggrStmt *
1724 _copyRemoveAggrStmt(RemoveAggrStmt *from)
1725 {
1726         RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1727
1728         COPY_NODE_FIELD(aggname);
1729         COPY_NODE_FIELD(aggtype);
1730         COPY_SCALAR_FIELD(behavior);
1731
1732         return newnode;
1733 }
1734
1735 static RemoveFuncStmt *
1736 _copyRemoveFuncStmt(RemoveFuncStmt *from)
1737 {
1738         RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
1739
1740         COPY_NODE_FIELD(funcname);
1741         COPY_NODE_FIELD(args);
1742         COPY_SCALAR_FIELD(behavior);
1743
1744         return newnode;
1745 }
1746
1747 static RemoveOperStmt *
1748 _copyRemoveOperStmt(RemoveOperStmt *from)
1749 {
1750         RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
1751
1752         COPY_NODE_FIELD(opname);
1753         COPY_NODE_FIELD(args);
1754         COPY_SCALAR_FIELD(behavior);
1755
1756         return newnode;
1757 }
1758
1759 static RemoveOpClassStmt *
1760 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
1761 {
1762         RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
1763
1764         COPY_NODE_FIELD(opclassname);
1765         COPY_STRING_FIELD(amname);
1766         COPY_SCALAR_FIELD(behavior);
1767
1768         return newnode;
1769 }
1770
1771 static RenameStmt *
1772 _copyRenameStmt(RenameStmt *from)
1773 {
1774         RenameStmt *newnode = makeNode(RenameStmt);
1775
1776         COPY_NODE_FIELD(relation);
1777         COPY_STRING_FIELD(oldname);
1778         COPY_STRING_FIELD(newname);
1779         COPY_SCALAR_FIELD(renameType);
1780
1781         return newnode;
1782 }
1783
1784 static RuleStmt *
1785 _copyRuleStmt(RuleStmt *from)
1786 {
1787         RuleStmt   *newnode = makeNode(RuleStmt);
1788
1789         COPY_NODE_FIELD(relation);
1790         COPY_STRING_FIELD(rulename);
1791         COPY_NODE_FIELD(whereClause);
1792         COPY_SCALAR_FIELD(event);
1793         COPY_SCALAR_FIELD(instead);
1794         COPY_NODE_FIELD(actions);
1795         COPY_SCALAR_FIELD(replace);
1796
1797         return newnode;
1798 }
1799
1800 static NotifyStmt *
1801 _copyNotifyStmt(NotifyStmt *from)
1802 {
1803         NotifyStmt *newnode = makeNode(NotifyStmt);
1804
1805         COPY_NODE_FIELD(relation);
1806
1807         return newnode;
1808 }
1809
1810 static ListenStmt *
1811 _copyListenStmt(ListenStmt *from)
1812 {
1813         ListenStmt *newnode = makeNode(ListenStmt);
1814
1815         COPY_NODE_FIELD(relation);
1816
1817         return newnode;
1818 }
1819
1820 static UnlistenStmt *
1821 _copyUnlistenStmt(UnlistenStmt *from)
1822 {
1823         UnlistenStmt *newnode = makeNode(UnlistenStmt);
1824
1825         COPY_NODE_FIELD(relation);
1826
1827         return newnode;
1828 }
1829
1830 static TransactionStmt *
1831 _copyTransactionStmt(TransactionStmt *from)
1832 {
1833         TransactionStmt *newnode = makeNode(TransactionStmt);
1834
1835         COPY_SCALAR_FIELD(command);
1836         COPY_NODE_FIELD(options);
1837
1838         return newnode;
1839 }
1840
1841 static CompositeTypeStmt *
1842 _copyCompositeTypeStmt(CompositeTypeStmt *from)
1843 {
1844         CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
1845
1846         COPY_NODE_FIELD(typevar);
1847         COPY_NODE_FIELD(coldeflist);
1848
1849         return newnode;
1850 }
1851
1852 static ViewStmt *
1853 _copyViewStmt(ViewStmt *from)
1854 {
1855         ViewStmt   *newnode = makeNode(ViewStmt);
1856
1857         COPY_NODE_FIELD(view);
1858         COPY_NODE_FIELD(aliases);
1859         COPY_NODE_FIELD(query);
1860         COPY_SCALAR_FIELD(replace);
1861
1862         return newnode;
1863 }
1864
1865 static LoadStmt *
1866 _copyLoadStmt(LoadStmt *from)
1867 {
1868         LoadStmt   *newnode = makeNode(LoadStmt);
1869
1870         COPY_STRING_FIELD(filename);
1871
1872         return newnode;
1873 }
1874
1875 static CreateDomainStmt *
1876 _copyCreateDomainStmt(CreateDomainStmt *from)
1877 {
1878         CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
1879
1880         COPY_NODE_FIELD(domainname);
1881         COPY_NODE_FIELD(typename);
1882         COPY_NODE_FIELD(constraints);
1883
1884         return newnode;
1885 }
1886
1887 static CreateOpClassStmt *
1888 _copyCreateOpClassStmt(CreateOpClassStmt *from)
1889 {
1890         CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
1891
1892         COPY_NODE_FIELD(opclassname);
1893         COPY_STRING_FIELD(amname);
1894         COPY_NODE_FIELD(datatype);
1895         COPY_NODE_FIELD(items);
1896         COPY_SCALAR_FIELD(isDefault);
1897
1898         return newnode;
1899 }
1900
1901 static CreateOpClassItem *
1902 _copyCreateOpClassItem(CreateOpClassItem *from)
1903 {
1904         CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
1905
1906         COPY_SCALAR_FIELD(itemtype);
1907         COPY_NODE_FIELD(name);
1908         COPY_NODE_FIELD(args);
1909         COPY_SCALAR_FIELD(number);
1910         COPY_SCALAR_FIELD(recheck);
1911         COPY_NODE_FIELD(storedtype);
1912
1913         return newnode;
1914 }
1915
1916 static CreatedbStmt *
1917 _copyCreatedbStmt(CreatedbStmt *from)
1918 {
1919         CreatedbStmt *newnode = makeNode(CreatedbStmt);
1920
1921         COPY_STRING_FIELD(dbname);
1922         COPY_NODE_FIELD(options);
1923
1924         return newnode;
1925 }
1926
1927 static AlterDatabaseSetStmt *
1928 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
1929 {
1930         AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
1931
1932         COPY_STRING_FIELD(dbname);
1933         COPY_STRING_FIELD(variable);
1934         COPY_NODE_FIELD(value);
1935
1936         return newnode;
1937 }
1938
1939 static DropdbStmt *
1940 _copyDropdbStmt(DropdbStmt *from)
1941 {
1942         DropdbStmt *newnode = makeNode(DropdbStmt);
1943
1944         COPY_STRING_FIELD(dbname);
1945
1946         return newnode;
1947 }
1948
1949 static VacuumStmt *
1950 _copyVacuumStmt(VacuumStmt *from)
1951 {
1952         VacuumStmt *newnode = makeNode(VacuumStmt);
1953
1954         COPY_SCALAR_FIELD(vacuum);
1955         COPY_SCALAR_FIELD(full);
1956         COPY_SCALAR_FIELD(analyze);
1957         COPY_SCALAR_FIELD(freeze);
1958         COPY_SCALAR_FIELD(verbose);
1959         COPY_NODE_FIELD(relation);
1960         COPY_NODE_FIELD(va_cols);
1961
1962         return newnode;
1963 }
1964
1965 static ExplainStmt *
1966 _copyExplainStmt(ExplainStmt *from)
1967 {
1968         ExplainStmt *newnode = makeNode(ExplainStmt);
1969
1970         COPY_NODE_FIELD(query);
1971         COPY_SCALAR_FIELD(verbose);
1972         COPY_SCALAR_FIELD(analyze);
1973
1974         return newnode;
1975 }
1976
1977 static CreateSeqStmt *
1978 _copyCreateSeqStmt(CreateSeqStmt *from)
1979 {
1980         CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
1981
1982         COPY_NODE_FIELD(sequence);
1983         COPY_NODE_FIELD(options);
1984
1985         return newnode;
1986 }
1987
1988 static VariableSetStmt *
1989 _copyVariableSetStmt(VariableSetStmt *from)
1990 {
1991         VariableSetStmt *newnode = makeNode(VariableSetStmt);
1992
1993         COPY_STRING_FIELD(name);
1994         COPY_NODE_FIELD(args);
1995         COPY_SCALAR_FIELD(is_local);
1996
1997         return newnode;
1998 }
1999
2000 static VariableShowStmt *
2001 _copyVariableShowStmt(VariableShowStmt *from)
2002 {
2003         VariableShowStmt *newnode = makeNode(VariableShowStmt);
2004
2005         COPY_STRING_FIELD(name);
2006
2007         return newnode;
2008 }
2009
2010 static VariableResetStmt *
2011 _copyVariableResetStmt(VariableResetStmt *from)
2012 {
2013         VariableResetStmt *newnode = makeNode(VariableResetStmt);
2014
2015         COPY_STRING_FIELD(name);
2016
2017         return newnode;
2018 }
2019
2020 static CreateTrigStmt *
2021 _copyCreateTrigStmt(CreateTrigStmt *from)
2022 {
2023         CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2024
2025         COPY_STRING_FIELD(trigname);
2026         COPY_NODE_FIELD(relation);
2027         COPY_NODE_FIELD(funcname);
2028         COPY_NODE_FIELD(args);
2029         COPY_SCALAR_FIELD(before);
2030         COPY_SCALAR_FIELD(row);
2031         strcpy(newnode->actions, from->actions); /* in-line string field */
2032         COPY_SCALAR_FIELD(isconstraint);
2033         COPY_SCALAR_FIELD(deferrable);
2034         COPY_SCALAR_FIELD(initdeferred);
2035         COPY_NODE_FIELD(constrrel);
2036
2037         return newnode;
2038 }
2039
2040 static DropPropertyStmt *
2041 _copyDropPropertyStmt(DropPropertyStmt *from)
2042 {
2043         DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2044
2045         COPY_NODE_FIELD(relation);
2046         COPY_STRING_FIELD(property);
2047         COPY_SCALAR_FIELD(removeType);
2048         COPY_SCALAR_FIELD(behavior);
2049
2050         return newnode;
2051 }
2052
2053 static CreatePLangStmt *
2054 _copyCreatePLangStmt(CreatePLangStmt *from)
2055 {
2056         CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2057
2058         COPY_STRING_FIELD(plname);
2059         COPY_NODE_FIELD(plhandler);
2060         COPY_NODE_FIELD(plvalidator);
2061         COPY_SCALAR_FIELD(pltrusted);
2062
2063         return newnode;
2064 }
2065
2066 static DropPLangStmt *
2067 _copyDropPLangStmt(DropPLangStmt *from)
2068 {
2069         DropPLangStmt *newnode = makeNode(DropPLangStmt);
2070
2071         COPY_STRING_FIELD(plname);
2072         COPY_SCALAR_FIELD(behavior);
2073
2074         return newnode;
2075 }
2076
2077 static CreateUserStmt *
2078 _copyCreateUserStmt(CreateUserStmt *from)
2079 {
2080         CreateUserStmt *newnode = makeNode(CreateUserStmt);
2081
2082         COPY_STRING_FIELD(user);
2083         COPY_NODE_FIELD(options);
2084
2085         return newnode;
2086 }
2087
2088 static AlterUserStmt *
2089 _copyAlterUserStmt(AlterUserStmt *from)
2090 {
2091         AlterUserStmt *newnode = makeNode(AlterUserStmt);
2092
2093         COPY_STRING_FIELD(user);
2094         COPY_NODE_FIELD(options);
2095
2096         return newnode;
2097 }
2098
2099 static AlterUserSetStmt *
2100 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2101 {
2102         AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2103
2104         COPY_STRING_FIELD(user);
2105         COPY_STRING_FIELD(variable);
2106         COPY_NODE_FIELD(value);
2107
2108         return newnode;
2109 }
2110
2111 static DropUserStmt *
2112 _copyDropUserStmt(DropUserStmt *from)
2113 {
2114         DropUserStmt *newnode = makeNode(DropUserStmt);
2115
2116         COPY_NODE_FIELD(users);
2117
2118         return newnode;
2119 }
2120
2121 static LockStmt *
2122 _copyLockStmt(LockStmt *from)
2123 {
2124         LockStmt   *newnode = makeNode(LockStmt);
2125
2126         COPY_NODE_FIELD(relations);
2127         COPY_SCALAR_FIELD(mode);
2128
2129         return newnode;
2130 }
2131
2132 static ConstraintsSetStmt *
2133 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2134 {
2135         ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2136
2137         COPY_NODE_FIELD(constraints);
2138         COPY_SCALAR_FIELD(deferred);
2139
2140         return newnode;
2141 }
2142
2143 static CreateGroupStmt *
2144 _copyCreateGroupStmt(CreateGroupStmt *from)
2145 {
2146         CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2147
2148         COPY_STRING_FIELD(name);
2149         COPY_NODE_FIELD(options);
2150
2151         return newnode;
2152 }
2153
2154 static AlterGroupStmt *
2155 _copyAlterGroupStmt(AlterGroupStmt *from)
2156 {
2157         AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2158
2159         COPY_STRING_FIELD(name);
2160         COPY_SCALAR_FIELD(action);
2161         COPY_NODE_FIELD(listUsers);
2162
2163         return newnode;
2164 }
2165
2166 static DropGroupStmt *
2167 _copyDropGroupStmt(DropGroupStmt *from)
2168 {
2169         DropGroupStmt *newnode = makeNode(DropGroupStmt);
2170
2171         COPY_STRING_FIELD(name);
2172
2173         return newnode;
2174 }
2175
2176 static ReindexStmt *
2177 _copyReindexStmt(ReindexStmt *from)
2178 {
2179         ReindexStmt *newnode = makeNode(ReindexStmt);
2180
2181         COPY_SCALAR_FIELD(reindexType);
2182         COPY_NODE_FIELD(relation);
2183         COPY_STRING_FIELD(name);
2184         COPY_SCALAR_FIELD(force);
2185         COPY_SCALAR_FIELD(all);
2186
2187         return newnode;
2188 }
2189
2190 static CreateSchemaStmt *
2191 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2192 {
2193         CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2194
2195         COPY_STRING_FIELD(schemaname);
2196         COPY_STRING_FIELD(authid);
2197         COPY_NODE_FIELD(schemaElts);
2198
2199         return newnode;
2200 }
2201
2202 static CreateConversionStmt *
2203 _copyCreateConversionStmt(CreateConversionStmt *from)
2204 {
2205         CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2206
2207         COPY_NODE_FIELD(conversion_name);
2208         COPY_STRING_FIELD(for_encoding_name);
2209         COPY_STRING_FIELD(to_encoding_name);
2210         COPY_NODE_FIELD(func_name);
2211         COPY_SCALAR_FIELD(def);
2212
2213         return newnode;
2214 }
2215
2216 static CreateCastStmt *
2217 _copyCreateCastStmt(CreateCastStmt *from)
2218 {
2219         CreateCastStmt *newnode = makeNode(CreateCastStmt);
2220
2221         COPY_NODE_FIELD(sourcetype);
2222         COPY_NODE_FIELD(targettype);
2223         COPY_NODE_FIELD(func);
2224         COPY_SCALAR_FIELD(context);
2225
2226         return newnode;
2227 }
2228
2229 static DropCastStmt *
2230 _copyDropCastStmt(DropCastStmt *from)
2231 {
2232         DropCastStmt *newnode = makeNode(DropCastStmt);
2233
2234         COPY_NODE_FIELD(sourcetype);
2235         COPY_NODE_FIELD(targettype);
2236         COPY_SCALAR_FIELD(behavior);
2237
2238         return newnode;
2239 }
2240
2241 static PrepareStmt *
2242 _copyPrepareStmt(PrepareStmt *from)
2243 {
2244         PrepareStmt *newnode = makeNode(PrepareStmt);
2245
2246         COPY_STRING_FIELD(name);
2247         COPY_NODE_FIELD(argtypes);
2248         COPY_INTLIST_FIELD(argtype_oids);
2249         COPY_NODE_FIELD(query);
2250
2251         return newnode;
2252 }
2253
2254 static ExecuteStmt *
2255 _copyExecuteStmt(ExecuteStmt *from)
2256 {
2257         ExecuteStmt *newnode = makeNode(ExecuteStmt);
2258
2259         COPY_STRING_FIELD(name);
2260         COPY_NODE_FIELD(into);
2261         COPY_NODE_FIELD(params);
2262
2263         return newnode;
2264 }
2265
2266 static DeallocateStmt *
2267 _copyDeallocateStmt(DeallocateStmt *from)
2268 {
2269         DeallocateStmt *newnode = makeNode(DeallocateStmt);
2270
2271         COPY_STRING_FIELD(name);
2272
2273         return newnode;
2274 }
2275
2276
2277 /* ****************************************************************
2278  *                                      pg_list.h copy functions
2279  * ****************************************************************
2280  */
2281
2282 static Value *
2283 _copyValue(Value *from)
2284 {
2285         Value      *newnode = makeNode(Value);
2286
2287         /* See also _copyAConst when changing this code! */
2288
2289         COPY_SCALAR_FIELD(type);
2290         switch (from->type)
2291         {
2292                 case T_Integer:
2293                         COPY_SCALAR_FIELD(val.ival);
2294                         break;
2295                 case T_Float:
2296                 case T_String:
2297                 case T_BitString:
2298                         COPY_STRING_FIELD(val.str);
2299                         break;
2300                 case T_Null:
2301                         /* nothing to do */
2302                         break;
2303                 default:
2304                         elog(ERROR, "_copyValue: unknown node type %d", from->type);
2305                         break;
2306         }
2307         return newnode;
2308 }
2309
2310 /*
2311  * copyObject
2312  *
2313  * Create a copy of a Node tree or list.  This is a "deep" copy: all
2314  * substructure is copied too, recursively.
2315  */
2316 void *
2317 copyObject(void *from)
2318 {
2319         void       *retval;
2320
2321         if (from == NULL)
2322                 return NULL;
2323
2324         switch (nodeTag(from))
2325         {
2326                         /*
2327                          * PLAN NODES
2328                          */
2329                 case T_Plan:
2330                         retval = _copyPlan(from);
2331                         break;
2332                 case T_Result:
2333                         retval = _copyResult(from);
2334                         break;
2335                 case T_Append:
2336                         retval = _copyAppend(from);
2337                         break;
2338                 case T_Scan:
2339                         retval = _copyScan(from);
2340                         break;
2341                 case T_SeqScan:
2342                         retval = _copySeqScan(from);
2343                         break;
2344                 case T_IndexScan:
2345                         retval = _copyIndexScan(from);
2346                         break;
2347                 case T_TidScan:
2348                         retval = _copyTidScan(from);
2349                         break;
2350                 case T_SubqueryScan:
2351                         retval = _copySubqueryScan(from);
2352                         break;
2353                 case T_FunctionScan:
2354                         retval = _copyFunctionScan(from);
2355                         break;
2356                 case T_Join:
2357                         retval = _copyJoin(from);
2358                         break;
2359                 case T_NestLoop:
2360                         retval = _copyNestLoop(from);
2361                         break;
2362                 case T_MergeJoin:
2363                         retval = _copyMergeJoin(from);
2364                         break;
2365                 case T_HashJoin:
2366                         retval = _copyHashJoin(from);
2367                         break;
2368                 case T_Material:
2369                         retval = _copyMaterial(from);
2370                         break;
2371                 case T_Sort:
2372                         retval = _copySort(from);
2373                         break;
2374                 case T_Group:
2375                         retval = _copyGroup(from);
2376                         break;
2377                 case T_Agg:
2378                         retval = _copyAgg(from);
2379                         break;
2380                 case T_Unique:
2381                         retval = _copyUnique(from);
2382                         break;
2383                 case T_Hash:
2384                         retval = _copyHash(from);
2385                         break;
2386                 case T_SetOp:
2387                         retval = _copySetOp(from);
2388                         break;
2389                 case T_Limit:
2390                         retval = _copyLimit(from);
2391                         break;
2392
2393                         /*
2394                          * PRIMITIVE NODES
2395                          */
2396                 case T_Resdom:
2397                         retval = _copyResdom(from);
2398                         break;
2399                 case T_Alias:
2400                         retval = _copyAlias(from);
2401                         break;
2402                 case T_RangeVar:
2403                         retval = _copyRangeVar(from);
2404                         break;
2405                 case T_Var:
2406                         retval = _copyVar(from);
2407                         break;
2408                 case T_Const:
2409                         retval = _copyConst(from);
2410                         break;
2411                 case T_Param:
2412                         retval = _copyParam(from);
2413                         break;
2414                 case T_Aggref:
2415                         retval = _copyAggref(from);
2416                         break;
2417                 case T_ArrayRef:
2418                         retval = _copyArrayRef(from);
2419                         break;
2420                 case T_FuncExpr:
2421                         retval = _copyFuncExpr(from);
2422                         break;
2423                 case T_OpExpr:
2424                         retval = _copyOpExpr(from);
2425                         break;
2426                 case T_DistinctExpr:
2427                         retval = _copyDistinctExpr(from);
2428                         break;
2429                 case T_BoolExpr:
2430                         retval = _copyBoolExpr(from);
2431                         break;
2432                 case T_SubLink:
2433                         retval = _copySubLink(from);
2434                         break;
2435                 case T_SubPlan:
2436                         retval = _copySubPlan(from);
2437                         break;
2438                 case T_FieldSelect:
2439                         retval = _copyFieldSelect(from);
2440                         break;
2441                 case T_RelabelType:
2442                         retval = _copyRelabelType(from);
2443                         break;
2444                 case T_CaseExpr:
2445                         retval = _copyCaseExpr(from);
2446                         break;
2447                 case T_CaseWhen:
2448                         retval = _copyCaseWhen(from);
2449                         break;
2450                 case T_NullTest:
2451                         retval = _copyNullTest(from);
2452                         break;
2453                 case T_BooleanTest:
2454                         retval = _copyBooleanTest(from);
2455                         break;
2456                 case T_ConstraintTest:
2457                         retval = _copyConstraintTest(from);
2458                         break;
2459                 case T_ConstraintTestValue:
2460                         retval = _copyConstraintTestValue(from);
2461                         break;
2462                 case T_TargetEntry:
2463                         retval = _copyTargetEntry(from);
2464                         break;
2465                 case T_RangeTblRef:
2466                         retval = _copyRangeTblRef(from);
2467                         break;
2468                 case T_JoinExpr:
2469                         retval = _copyJoinExpr(from);
2470                         break;
2471                 case T_FromExpr:
2472                         retval = _copyFromExpr(from);
2473                         break;
2474
2475                         /*
2476                          * RELATION NODES
2477                          */
2478                 case T_PathKeyItem:
2479                         retval = _copyPathKeyItem(from);
2480                         break;
2481                 case T_RestrictInfo:
2482                         retval = _copyRestrictInfo(from);
2483                         break;
2484                 case T_JoinInfo:
2485                         retval = _copyJoinInfo(from);
2486                         break;
2487
2488                         /*
2489                          * VALUE NODES
2490                          */
2491                 case T_Integer:
2492                 case T_Float:
2493                 case T_String:
2494                 case T_BitString:
2495                 case T_Null:
2496                         retval = _copyValue(from);
2497                         break;
2498                 case T_List:
2499                         {
2500                                 List       *list = from,
2501                                                    *l,
2502                                                    *nl;
2503
2504                                 /* rather ugly coding for speed... */
2505                                 /* Note the input list cannot be NIL if we got here. */
2506                                 nl = makeList1(copyObject(lfirst(list)));
2507                                 retval = nl;
2508
2509                                 foreach(l, lnext(list))
2510                                 {
2511                                         lnext(nl) = makeList1(copyObject(lfirst(l)));
2512                                         nl = lnext(nl);
2513                                 }
2514                         }
2515                         break;
2516
2517                         /*
2518                          * PARSE NODES
2519                          */
2520                 case T_Query:
2521                         retval = _copyQuery(from);
2522                         break;
2523                 case T_InsertStmt:
2524                         retval = _copyInsertStmt(from);
2525                         break;
2526                 case T_DeleteStmt:
2527                         retval = _copyDeleteStmt(from);
2528                         break;
2529                 case T_UpdateStmt:
2530                         retval = _copyUpdateStmt(from);
2531                         break;
2532                 case T_SelectStmt:
2533                         retval = _copySelectStmt(from);
2534                         break;
2535                 case T_SetOperationStmt:
2536                         retval = _copySetOperationStmt(from);
2537                         break;
2538                 case T_AlterTableStmt:
2539                         retval = _copyAlterTableStmt(from);
2540                         break;
2541                 case T_AlterDomainStmt:
2542                         retval = _copyAlterDomainStmt(from);
2543                         break;
2544                 case T_GrantStmt:
2545                         retval = _copyGrantStmt(from);
2546                         break;
2547                 case T_ClosePortalStmt:
2548                         retval = _copyClosePortalStmt(from);
2549                         break;
2550                 case T_ClusterStmt:
2551                         retval = _copyClusterStmt(from);
2552                         break;
2553                 case T_CopyStmt:
2554                         retval = _copyCopyStmt(from);
2555                         break;
2556                 case T_CreateStmt:
2557                         retval = _copyCreateStmt(from);
2558                         break;
2559                 case T_DefineStmt:
2560                         retval = _copyDefineStmt(from);
2561                         break;
2562                 case T_DropStmt:
2563                         retval = _copyDropStmt(from);
2564                         break;
2565                 case T_TruncateStmt:
2566                         retval = _copyTruncateStmt(from);
2567                         break;
2568                 case T_CommentStmt:
2569                         retval = _copyCommentStmt(from);
2570                         break;
2571                 case T_FetchStmt:
2572                         retval = _copyFetchStmt(from);
2573                         break;
2574                 case T_IndexStmt:
2575                         retval = _copyIndexStmt(from);
2576                         break;
2577                 case T_CreateFunctionStmt:
2578                         retval = _copyCreateFunctionStmt(from);
2579                         break;
2580                 case T_RemoveAggrStmt:
2581                         retval = _copyRemoveAggrStmt(from);
2582                         break;
2583                 case T_RemoveFuncStmt:
2584                         retval = _copyRemoveFuncStmt(from);
2585                         break;
2586                 case T_RemoveOperStmt:
2587                         retval = _copyRemoveOperStmt(from);
2588                         break;
2589                 case T_RemoveOpClassStmt:
2590                         retval = _copyRemoveOpClassStmt(from);
2591                         break;
2592                 case T_RenameStmt:
2593                         retval = _copyRenameStmt(from);
2594                         break;
2595                 case T_RuleStmt:
2596                         retval = _copyRuleStmt(from);
2597                         break;
2598                 case T_NotifyStmt:
2599                         retval = _copyNotifyStmt(from);
2600                         break;
2601                 case T_ListenStmt:
2602                         retval = _copyListenStmt(from);
2603                         break;
2604                 case T_UnlistenStmt:
2605                         retval = _copyUnlistenStmt(from);
2606                         break;
2607                 case T_TransactionStmt:
2608                         retval = _copyTransactionStmt(from);
2609                         break;
2610                 case T_CompositeTypeStmt:
2611                         retval = _copyCompositeTypeStmt(from);
2612                         break;
2613                 case T_ViewStmt:
2614                         retval = _copyViewStmt(from);
2615                         break;
2616                 case T_LoadStmt:
2617                         retval = _copyLoadStmt(from);
2618                         break;
2619                 case T_CreateDomainStmt:
2620                         retval = _copyCreateDomainStmt(from);
2621                         break;
2622                 case T_CreateOpClassStmt:
2623                         retval = _copyCreateOpClassStmt(from);
2624                         break;
2625                 case T_CreateOpClassItem:
2626                         retval = _copyCreateOpClassItem(from);
2627                         break;
2628                 case T_CreatedbStmt:
2629                         retval = _copyCreatedbStmt(from);
2630                         break;
2631                 case T_AlterDatabaseSetStmt:
2632                         retval = _copyAlterDatabaseSetStmt(from);
2633                         break;
2634                 case T_DropdbStmt:
2635                         retval = _copyDropdbStmt(from);
2636                         break;
2637                 case T_VacuumStmt:
2638                         retval = _copyVacuumStmt(from);
2639                         break;
2640                 case T_ExplainStmt:
2641                         retval = _copyExplainStmt(from);
2642                         break;
2643                 case T_CreateSeqStmt:
2644                         retval = _copyCreateSeqStmt(from);
2645                         break;
2646                 case T_VariableSetStmt:
2647                         retval = _copyVariableSetStmt(from);
2648                         break;
2649                 case T_VariableShowStmt:
2650                         retval = _copyVariableShowStmt(from);
2651                         break;
2652                 case T_VariableResetStmt:
2653                         retval = _copyVariableResetStmt(from);
2654                         break;
2655                 case T_CreateTrigStmt:
2656                         retval = _copyCreateTrigStmt(from);
2657                         break;
2658                 case T_DropPropertyStmt:
2659                         retval = _copyDropPropertyStmt(from);
2660                         break;
2661                 case T_CreatePLangStmt:
2662                         retval = _copyCreatePLangStmt(from);
2663                         break;
2664                 case T_DropPLangStmt:
2665                         retval = _copyDropPLangStmt(from);
2666                         break;
2667                 case T_CreateUserStmt:
2668                         retval = _copyCreateUserStmt(from);
2669                         break;
2670                 case T_AlterUserStmt:
2671                         retval = _copyAlterUserStmt(from);
2672                         break;
2673                 case T_AlterUserSetStmt:
2674                         retval = _copyAlterUserSetStmt(from);
2675                         break;
2676                 case T_DropUserStmt:
2677                         retval = _copyDropUserStmt(from);
2678                         break;
2679                 case T_LockStmt:
2680                         retval = _copyLockStmt(from);
2681                         break;
2682                 case T_ConstraintsSetStmt:
2683                         retval = _copyConstraintsSetStmt(from);
2684                         break;
2685                 case T_CreateGroupStmt:
2686                         retval = _copyCreateGroupStmt(from);
2687                         break;
2688                 case T_AlterGroupStmt:
2689                         retval = _copyAlterGroupStmt(from);
2690                         break;
2691                 case T_DropGroupStmt:
2692                         retval = _copyDropGroupStmt(from);
2693                         break;
2694                 case T_ReindexStmt:
2695                         retval = _copyReindexStmt(from);
2696                         break;
2697                 case T_CheckPointStmt:
2698                         retval = (void *) makeNode(CheckPointStmt);
2699                         break;
2700                 case T_CreateSchemaStmt:
2701                         retval = _copyCreateSchemaStmt(from);
2702                         break;
2703                 case T_CreateConversionStmt:
2704                         retval = _copyCreateConversionStmt(from);
2705                         break;
2706                 case T_CreateCastStmt:
2707                         retval = _copyCreateCastStmt(from);
2708                         break;
2709                 case T_DropCastStmt:
2710                         retval = _copyDropCastStmt(from);
2711                         break;
2712                 case T_PrepareStmt:
2713                         retval = _copyPrepareStmt(from);
2714                         break;
2715                 case T_ExecuteStmt:
2716                         retval = _copyExecuteStmt(from);
2717                         break;
2718                 case T_DeallocateStmt:
2719                         retval = _copyDeallocateStmt(from);
2720                         break;
2721
2722                 case T_A_Expr:
2723                         retval = _copyAExpr(from);
2724                         break;
2725                 case T_ColumnRef:
2726                         retval = _copyColumnRef(from);
2727                         break;
2728                 case T_ParamRef:
2729                         retval = _copyParamRef(from);
2730                         break;
2731                 case T_A_Const:
2732                         retval = _copyAConst(from);
2733                         break;
2734                 case T_FuncCall:
2735                         retval = _copyFuncCall(from);
2736                         break;
2737                 case T_A_Indices:
2738                         retval = _copyAIndices(from);
2739                         break;
2740                 case T_ExprFieldSelect:
2741                         retval = _copyExprFieldSelect(from);
2742                         break;
2743                 case T_ResTarget:
2744                         retval = _copyResTarget(from);
2745                         break;
2746                 case T_TypeCast:
2747                         retval = _copyTypeCast(from);
2748                         break;
2749                 case T_SortGroupBy:
2750                         retval = _copySortGroupBy(from);
2751                         break;
2752                 case T_RangeSubselect:
2753                         retval = _copyRangeSubselect(from);
2754                         break;
2755                 case T_RangeFunction:
2756                         retval = _copyRangeFunction(from);
2757                         break;
2758                 case T_TypeName:
2759                         retval = _copyTypeName(from);
2760                         break;
2761                 case T_IndexElem:
2762                         retval = _copyIndexElem(from);
2763                         break;
2764                 case T_ColumnDef:
2765                         retval = _copyColumnDef(from);
2766                         break;
2767                 case T_Constraint:
2768                         retval = _copyConstraint(from);
2769                         break;
2770                 case T_DefElem:
2771                         retval = _copyDefElem(from);
2772                         break;
2773                 case T_RangeTblEntry:
2774                         retval = _copyRangeTblEntry(from);
2775                         break;
2776                 case T_SortClause:
2777                         retval = _copySortClause(from);
2778                         break;
2779                 case T_GroupClause:
2780                         retval = _copyGroupClause(from);
2781                         break;
2782                 case T_FkConstraint:
2783                         retval = _copyFkConstraint(from);
2784                         break;
2785                 case T_PrivGrantee:
2786                         retval = _copyPrivGrantee(from);
2787                         break;
2788                 case T_FuncWithArgs:
2789                         retval = _copyFuncWithArgs(from);
2790                         break;
2791                 case T_InsertDefault:
2792                         retval = _copyInsertDefault(from);
2793                         break;
2794
2795                 default:
2796                         elog(ERROR, "copyObject: don't know how to copy node type %d",
2797                                  nodeTag(from));
2798                         retval = from;          /* keep compiler quiet */
2799                         break;
2800         }
2801
2802         return retval;
2803 }