]> granicus.if.org Git - postgresql/blob - src/backend/nodes/copyfuncs.c
Further tweaking of parsetree & plantree representation of SubLinks.
[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.235 2003/01/10 21:08:10 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(operName);
815         COPY_INTLIST_FIELD(operOids);
816         COPY_NODE_FIELD(subselect);
817
818         return newnode;
819 }
820
821 /*
822  * _copySubPlan
823  */
824 static SubPlan *
825 _copySubPlan(SubPlan *from)
826 {
827         SubPlan    *newnode = makeNode(SubPlan);
828
829         COPY_SCALAR_FIELD(subLinkType);
830         COPY_SCALAR_FIELD(useOr);
831         COPY_NODE_FIELD(exprs);
832         COPY_INTLIST_FIELD(paramIds);
833         COPY_NODE_FIELD(plan);
834         COPY_SCALAR_FIELD(plan_id);
835         COPY_NODE_FIELD(rtable);
836         COPY_SCALAR_FIELD(useHashTable);
837         COPY_SCALAR_FIELD(unknownEqFalse);
838         COPY_INTLIST_FIELD(setParam);
839         COPY_INTLIST_FIELD(parParam);
840         COPY_NODE_FIELD(args);
841
842         return newnode;
843 }
844
845 /*
846  * _copyFieldSelect
847  */
848 static FieldSelect *
849 _copyFieldSelect(FieldSelect *from)
850 {
851         FieldSelect *newnode = makeNode(FieldSelect);
852
853         COPY_NODE_FIELD(arg);
854         COPY_SCALAR_FIELD(fieldnum);
855         COPY_SCALAR_FIELD(resulttype);
856         COPY_SCALAR_FIELD(resulttypmod);
857
858         return newnode;
859 }
860
861 /*
862  * _copyRelabelType
863  */
864 static RelabelType *
865 _copyRelabelType(RelabelType *from)
866 {
867         RelabelType *newnode = makeNode(RelabelType);
868
869         COPY_NODE_FIELD(arg);
870         COPY_SCALAR_FIELD(resulttype);
871         COPY_SCALAR_FIELD(resulttypmod);
872         COPY_SCALAR_FIELD(relabelformat);
873
874         return newnode;
875 }
876
877 /*
878  * _copyCaseExpr
879  */
880 static CaseExpr *
881 _copyCaseExpr(CaseExpr *from)
882 {
883         CaseExpr   *newnode = makeNode(CaseExpr);
884
885         COPY_SCALAR_FIELD(casetype);
886         COPY_NODE_FIELD(arg);
887         COPY_NODE_FIELD(args);
888         COPY_NODE_FIELD(defresult);
889
890         return newnode;
891 }
892
893 /*
894  * _copyCaseWhen
895  */
896 static CaseWhen *
897 _copyCaseWhen(CaseWhen *from)
898 {
899         CaseWhen   *newnode = makeNode(CaseWhen);
900
901         COPY_NODE_FIELD(expr);
902         COPY_NODE_FIELD(result);
903
904         return newnode;
905 }
906
907 /*
908  * _copyNullTest
909  */
910 static NullTest *
911 _copyNullTest(NullTest *from)
912 {
913         NullTest   *newnode = makeNode(NullTest);
914
915         COPY_NODE_FIELD(arg);
916         COPY_SCALAR_FIELD(nulltesttype);
917
918         return newnode;
919 }
920
921 /*
922  * _copyBooleanTest
923  */
924 static BooleanTest *
925 _copyBooleanTest(BooleanTest *from)
926 {
927         BooleanTest *newnode = makeNode(BooleanTest);
928
929         COPY_NODE_FIELD(arg);
930         COPY_SCALAR_FIELD(booltesttype);
931
932         return newnode;
933 }
934
935 /*
936  * _copyConstraintTest
937  */
938 static ConstraintTest *
939 _copyConstraintTest(ConstraintTest *from)
940 {
941         ConstraintTest *newnode = makeNode(ConstraintTest);
942
943         COPY_NODE_FIELD(arg);
944         COPY_SCALAR_FIELD(testtype);
945         COPY_STRING_FIELD(name);
946         COPY_STRING_FIELD(domname);
947         COPY_NODE_FIELD(check_expr);
948
949         return newnode;
950 }
951
952 /*
953  * _copyConstraintTestValue
954  */
955 static ConstraintTestValue *
956 _copyConstraintTestValue(ConstraintTestValue *from)
957 {
958         ConstraintTestValue *newnode = makeNode(ConstraintTestValue);
959
960         COPY_SCALAR_FIELD(typeId);
961         COPY_SCALAR_FIELD(typeMod);
962
963         return newnode;
964 }
965
966 /*
967  * _copyTargetEntry
968  */
969 static TargetEntry *
970 _copyTargetEntry(TargetEntry *from)
971 {
972         TargetEntry *newnode = makeNode(TargetEntry);
973
974         COPY_NODE_FIELD(resdom);
975         COPY_NODE_FIELD(expr);
976
977         return newnode;
978 }
979
980 /*
981  * _copyRangeTblRef
982  */
983 static RangeTblRef *
984 _copyRangeTblRef(RangeTblRef *from)
985 {
986         RangeTblRef *newnode = makeNode(RangeTblRef);
987
988         COPY_SCALAR_FIELD(rtindex);
989
990         return newnode;
991 }
992
993 /*
994  * _copyJoinExpr
995  */
996 static JoinExpr *
997 _copyJoinExpr(JoinExpr *from)
998 {
999         JoinExpr   *newnode = makeNode(JoinExpr);
1000
1001         COPY_SCALAR_FIELD(jointype);
1002         COPY_SCALAR_FIELD(isNatural);
1003         COPY_NODE_FIELD(larg);
1004         COPY_NODE_FIELD(rarg);
1005         COPY_NODE_FIELD(using);
1006         COPY_NODE_FIELD(quals);
1007         COPY_NODE_FIELD(alias);
1008         COPY_SCALAR_FIELD(rtindex);
1009
1010         return newnode;
1011 }
1012
1013 /*
1014  * _copyFromExpr
1015  */
1016 static FromExpr *
1017 _copyFromExpr(FromExpr *from)
1018 {
1019         FromExpr   *newnode = makeNode(FromExpr);
1020
1021         COPY_NODE_FIELD(fromlist);
1022         COPY_NODE_FIELD(quals);
1023
1024         return newnode;
1025 }
1026
1027 /* ****************************************************************
1028  *                                              relation.h copy functions
1029  *
1030  * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1031  * There are some subsidiary structs that are useful to copy, though.
1032  * ****************************************************************
1033  */
1034
1035 /*
1036  * _copyPathKeyItem
1037  */
1038 static PathKeyItem *
1039 _copyPathKeyItem(PathKeyItem *from)
1040 {
1041         PathKeyItem *newnode = makeNode(PathKeyItem);
1042
1043         COPY_NODE_FIELD(key);
1044         COPY_SCALAR_FIELD(sortop);
1045
1046         return newnode;
1047 }
1048
1049 /*
1050  * _copyRestrictInfo
1051  */
1052 static RestrictInfo *
1053 _copyRestrictInfo(RestrictInfo *from)
1054 {
1055         RestrictInfo *newnode = makeNode(RestrictInfo);
1056
1057         COPY_NODE_FIELD(clause);
1058         COPY_SCALAR_FIELD(ispusheddown);
1059         COPY_NODE_FIELD(subclauseindices); /* XXX probably bad */
1060         COPY_SCALAR_FIELD(eval_cost);
1061         COPY_SCALAR_FIELD(this_selec);
1062         COPY_SCALAR_FIELD(mergejoinoperator);
1063         COPY_SCALAR_FIELD(left_sortop);
1064         COPY_SCALAR_FIELD(right_sortop);
1065
1066         /*
1067          * Do not copy pathkeys, since they'd not be canonical in a copied
1068          * query
1069          */
1070         newnode->left_pathkey = NIL;
1071         newnode->right_pathkey = NIL;
1072
1073         COPY_SCALAR_FIELD(left_mergescansel);
1074         COPY_SCALAR_FIELD(right_mergescansel);
1075         COPY_SCALAR_FIELD(hashjoinoperator);
1076         COPY_SCALAR_FIELD(left_bucketsize);
1077         COPY_SCALAR_FIELD(right_bucketsize);
1078
1079         return newnode;
1080 }
1081
1082 /*
1083  * _copyJoinInfo
1084  */
1085 static JoinInfo *
1086 _copyJoinInfo(JoinInfo *from)
1087 {
1088         JoinInfo   *newnode = makeNode(JoinInfo);
1089
1090         COPY_INTLIST_FIELD(unjoined_relids);
1091         COPY_NODE_FIELD(jinfo_restrictinfo);
1092
1093         return newnode;
1094 }
1095
1096 /* ****************************************************************
1097  *                                      parsenodes.h copy functions
1098  * ****************************************************************
1099  */
1100
1101 static RangeTblEntry *
1102 _copyRangeTblEntry(RangeTblEntry *from)
1103 {
1104         RangeTblEntry *newnode = makeNode(RangeTblEntry);
1105
1106         COPY_SCALAR_FIELD(rtekind);
1107         COPY_SCALAR_FIELD(relid);
1108         COPY_NODE_FIELD(subquery);
1109         COPY_NODE_FIELD(funcexpr);
1110         COPY_NODE_FIELD(coldeflist);
1111         COPY_SCALAR_FIELD(jointype);
1112         COPY_NODE_FIELD(joinaliasvars);
1113         COPY_NODE_FIELD(alias);
1114         COPY_NODE_FIELD(eref);
1115         COPY_SCALAR_FIELD(inh);
1116         COPY_SCALAR_FIELD(inFromCl);
1117         COPY_SCALAR_FIELD(checkForRead);
1118         COPY_SCALAR_FIELD(checkForWrite);
1119         COPY_SCALAR_FIELD(checkAsUser);
1120
1121         return newnode;
1122 }
1123
1124 static FkConstraint *
1125 _copyFkConstraint(FkConstraint *from)
1126 {
1127         FkConstraint *newnode = makeNode(FkConstraint);
1128
1129         COPY_STRING_FIELD(constr_name);
1130         COPY_NODE_FIELD(pktable);
1131         COPY_NODE_FIELD(fk_attrs);
1132         COPY_NODE_FIELD(pk_attrs);
1133         COPY_SCALAR_FIELD(fk_matchtype);
1134         COPY_SCALAR_FIELD(fk_upd_action);
1135         COPY_SCALAR_FIELD(fk_del_action);
1136         COPY_SCALAR_FIELD(deferrable);
1137         COPY_SCALAR_FIELD(initdeferred);
1138         COPY_SCALAR_FIELD(skip_validation);
1139
1140         return newnode;
1141 }
1142
1143 static SortClause *
1144 _copySortClause(SortClause *from)
1145 {
1146         SortClause *newnode = makeNode(SortClause);
1147
1148         COPY_SCALAR_FIELD(tleSortGroupRef);
1149         COPY_SCALAR_FIELD(sortop);
1150
1151         return newnode;
1152 }
1153
1154 static GroupClause *
1155 _copyGroupClause(GroupClause *from)
1156 {
1157         GroupClause *newnode = makeNode(GroupClause);
1158
1159         COPY_SCALAR_FIELD(tleSortGroupRef);
1160         COPY_SCALAR_FIELD(sortop);
1161
1162         return newnode;
1163 }
1164
1165 static A_Expr *
1166 _copyAExpr(A_Expr *from)
1167 {
1168         A_Expr     *newnode = makeNode(A_Expr);
1169
1170         COPY_SCALAR_FIELD(oper);
1171         COPY_NODE_FIELD(name);
1172         COPY_NODE_FIELD(lexpr);
1173         COPY_NODE_FIELD(rexpr);
1174
1175         return newnode;
1176 }
1177
1178 static ColumnRef *
1179 _copyColumnRef(ColumnRef *from)
1180 {
1181         ColumnRef  *newnode = makeNode(ColumnRef);
1182
1183         COPY_NODE_FIELD(fields);
1184         COPY_NODE_FIELD(indirection);
1185
1186         return newnode;
1187 }
1188
1189 static ParamRef *
1190 _copyParamRef(ParamRef *from)
1191 {
1192         ParamRef   *newnode = makeNode(ParamRef);
1193
1194         COPY_SCALAR_FIELD(number);
1195         COPY_NODE_FIELD(fields);
1196         COPY_NODE_FIELD(indirection);
1197
1198         return newnode;
1199 }
1200
1201 static A_Const *
1202 _copyAConst(A_Const *from)
1203 {
1204         A_Const    *newnode = makeNode(A_Const);
1205
1206         /* This part must duplicate _copyValue */
1207         COPY_SCALAR_FIELD(val.type);
1208         switch (from->val.type)
1209         {
1210                 case T_Integer:
1211                         COPY_SCALAR_FIELD(val.val.ival);
1212                         break;
1213                 case T_Float:
1214                 case T_String:
1215                 case T_BitString:
1216                         COPY_STRING_FIELD(val.val.str);
1217                         break;
1218                 case T_Null:
1219                         /* nothing to do */
1220                         break;
1221                 default:
1222                         elog(ERROR, "_copyAConst: unknown node type %d", from->val.type);
1223                         break;
1224         }
1225
1226         COPY_NODE_FIELD(typename);
1227
1228         return newnode;
1229 }
1230
1231 static FuncCall *
1232 _copyFuncCall(FuncCall *from)
1233 {
1234         FuncCall   *newnode = makeNode(FuncCall);
1235
1236         COPY_NODE_FIELD(funcname);
1237         COPY_NODE_FIELD(args);
1238         COPY_SCALAR_FIELD(agg_star);
1239         COPY_SCALAR_FIELD(agg_distinct);
1240
1241         return newnode;
1242 }
1243
1244 static A_Indices *
1245 _copyAIndices(A_Indices *from)
1246 {
1247         A_Indices  *newnode = makeNode(A_Indices);
1248
1249         COPY_NODE_FIELD(lidx);
1250         COPY_NODE_FIELD(uidx);
1251
1252         return newnode;
1253 }
1254
1255 static ExprFieldSelect *
1256 _copyExprFieldSelect(ExprFieldSelect *from)
1257 {
1258         ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
1259
1260         COPY_NODE_FIELD(arg);
1261         COPY_NODE_FIELD(fields);
1262         COPY_NODE_FIELD(indirection);
1263
1264         return newnode;
1265 }
1266
1267 static ResTarget *
1268 _copyResTarget(ResTarget *from)
1269 {
1270         ResTarget  *newnode = makeNode(ResTarget);
1271
1272         COPY_STRING_FIELD(name);
1273         COPY_NODE_FIELD(indirection);
1274         COPY_NODE_FIELD(val);
1275
1276         return newnode;
1277 }
1278
1279 static TypeName *
1280 _copyTypeName(TypeName *from)
1281 {
1282         TypeName   *newnode = makeNode(TypeName);
1283
1284         COPY_NODE_FIELD(names);
1285         COPY_SCALAR_FIELD(typeid);
1286         COPY_SCALAR_FIELD(timezone);
1287         COPY_SCALAR_FIELD(setof);
1288         COPY_SCALAR_FIELD(pct_type);
1289         COPY_SCALAR_FIELD(typmod);
1290         COPY_NODE_FIELD(arrayBounds);
1291
1292         return newnode;
1293 }
1294
1295 static SortGroupBy *
1296 _copySortGroupBy(SortGroupBy *from)
1297 {
1298         SortGroupBy *newnode = makeNode(SortGroupBy);
1299
1300         COPY_NODE_FIELD(useOp);
1301         COPY_NODE_FIELD(node);
1302
1303         return newnode;
1304 }
1305
1306 static RangeSubselect *
1307 _copyRangeSubselect(RangeSubselect *from)
1308 {
1309         RangeSubselect *newnode = makeNode(RangeSubselect);
1310
1311         COPY_NODE_FIELD(subquery);
1312         COPY_NODE_FIELD(alias);
1313
1314         return newnode;
1315 }
1316
1317 static RangeFunction *
1318 _copyRangeFunction(RangeFunction *from)
1319 {
1320         RangeFunction *newnode = makeNode(RangeFunction);
1321
1322         COPY_NODE_FIELD(funccallnode);
1323         COPY_NODE_FIELD(alias);
1324         COPY_NODE_FIELD(coldeflist);
1325
1326         return newnode;
1327 }
1328
1329 static TypeCast *
1330 _copyTypeCast(TypeCast *from)
1331 {
1332         TypeCast   *newnode = makeNode(TypeCast);
1333
1334         COPY_NODE_FIELD(arg);
1335         COPY_NODE_FIELD(typename);
1336
1337         return newnode;
1338 }
1339
1340 static IndexElem *
1341 _copyIndexElem(IndexElem *from)
1342 {
1343         IndexElem  *newnode = makeNode(IndexElem);
1344
1345         COPY_STRING_FIELD(name);
1346         COPY_NODE_FIELD(funcname);
1347         COPY_NODE_FIELD(args);
1348         COPY_NODE_FIELD(opclass);
1349
1350         return newnode;
1351 }
1352
1353 static ColumnDef *
1354 _copyColumnDef(ColumnDef *from)
1355 {
1356         ColumnDef  *newnode = makeNode(ColumnDef);
1357
1358         COPY_STRING_FIELD(colname);
1359         COPY_NODE_FIELD(typename);
1360         COPY_SCALAR_FIELD(inhcount);
1361         COPY_SCALAR_FIELD(is_local);
1362         COPY_SCALAR_FIELD(is_not_null);
1363         COPY_NODE_FIELD(raw_default);
1364         COPY_STRING_FIELD(cooked_default);
1365         COPY_NODE_FIELD(constraints);
1366         COPY_NODE_FIELD(support);
1367
1368         return newnode;
1369 }
1370
1371 static Constraint *
1372 _copyConstraint(Constraint *from)
1373 {
1374         Constraint *newnode = makeNode(Constraint);
1375
1376         COPY_SCALAR_FIELD(contype);
1377         COPY_STRING_FIELD(name);
1378         COPY_NODE_FIELD(raw_expr);
1379         COPY_STRING_FIELD(cooked_expr);
1380         COPY_NODE_FIELD(keys);
1381
1382         return newnode;
1383 }
1384
1385 static DefElem *
1386 _copyDefElem(DefElem *from)
1387 {
1388         DefElem    *newnode = makeNode(DefElem);
1389
1390         COPY_STRING_FIELD(defname);
1391         COPY_NODE_FIELD(arg);
1392
1393         return newnode;
1394 }
1395
1396 static Query *
1397 _copyQuery(Query *from)
1398 {
1399         Query      *newnode = makeNode(Query);
1400
1401         COPY_SCALAR_FIELD(commandType);
1402         COPY_SCALAR_FIELD(querySource);
1403         COPY_NODE_FIELD(utilityStmt);
1404         COPY_SCALAR_FIELD(resultRelation);
1405         COPY_NODE_FIELD(into);
1406         COPY_SCALAR_FIELD(isPortal);
1407         COPY_SCALAR_FIELD(isBinary);
1408         COPY_SCALAR_FIELD(hasAggs);
1409         COPY_SCALAR_FIELD(hasSubLinks);
1410         COPY_NODE_FIELD(rtable);
1411         COPY_NODE_FIELD(jointree);
1412         COPY_INTLIST_FIELD(rowMarks);
1413         COPY_NODE_FIELD(targetList);
1414         COPY_NODE_FIELD(groupClause);
1415         COPY_NODE_FIELD(havingQual);
1416         COPY_NODE_FIELD(distinctClause);
1417         COPY_NODE_FIELD(sortClause);
1418         COPY_NODE_FIELD(limitOffset);
1419         COPY_NODE_FIELD(limitCount);
1420         COPY_NODE_FIELD(setOperations);
1421         COPY_INTLIST_FIELD(resultRelations);
1422
1423         /*
1424          * We do not copy the planner internal fields: base_rel_list,
1425          * other_rel_list, join_rel_list, equi_key_list, query_pathkeys,
1426          * hasJoinRTEs.  That would get us into copying RelOptInfo/Path
1427          * trees, which we don't want to do.
1428          */
1429
1430         return newnode;
1431 }
1432
1433 static InsertStmt *
1434 _copyInsertStmt(InsertStmt *from)
1435 {
1436         InsertStmt *newnode = makeNode(InsertStmt);
1437
1438         COPY_NODE_FIELD(relation);
1439         COPY_NODE_FIELD(cols);
1440         COPY_NODE_FIELD(targetList);
1441         COPY_NODE_FIELD(selectStmt);
1442
1443         return newnode;
1444 }
1445
1446 static DeleteStmt *
1447 _copyDeleteStmt(DeleteStmt *from)
1448 {
1449         DeleteStmt *newnode = makeNode(DeleteStmt);
1450
1451         COPY_NODE_FIELD(relation);
1452         COPY_NODE_FIELD(whereClause);
1453
1454         return newnode;
1455 }
1456
1457 static UpdateStmt *
1458 _copyUpdateStmt(UpdateStmt *from)
1459 {
1460         UpdateStmt *newnode = makeNode(UpdateStmt);
1461
1462         COPY_NODE_FIELD(relation);
1463         COPY_NODE_FIELD(targetList);
1464         COPY_NODE_FIELD(whereClause);
1465         COPY_NODE_FIELD(fromClause);
1466
1467         return newnode;
1468 }
1469
1470 static SelectStmt *
1471 _copySelectStmt(SelectStmt *from)
1472 {
1473         SelectStmt *newnode = makeNode(SelectStmt);
1474
1475         COPY_NODE_FIELD(distinctClause);
1476         COPY_NODE_FIELD(into);
1477         COPY_NODE_FIELD(intoColNames);
1478         COPY_NODE_FIELD(targetList);
1479         COPY_NODE_FIELD(fromClause);
1480         COPY_NODE_FIELD(whereClause);
1481         COPY_NODE_FIELD(groupClause);
1482         COPY_NODE_FIELD(havingClause);
1483         COPY_NODE_FIELD(sortClause);
1484         COPY_STRING_FIELD(portalname);
1485         COPY_SCALAR_FIELD(binary);
1486         COPY_NODE_FIELD(limitOffset);
1487         COPY_NODE_FIELD(limitCount);
1488         COPY_NODE_FIELD(forUpdate);
1489         COPY_SCALAR_FIELD(op);
1490         COPY_SCALAR_FIELD(all);
1491         COPY_NODE_FIELD(larg);
1492         COPY_NODE_FIELD(rarg);
1493
1494         return newnode;
1495 }
1496
1497 static SetOperationStmt *
1498 _copySetOperationStmt(SetOperationStmt *from)
1499 {
1500         SetOperationStmt *newnode = makeNode(SetOperationStmt);
1501
1502         COPY_SCALAR_FIELD(op);
1503         COPY_SCALAR_FIELD(all);
1504         COPY_NODE_FIELD(larg);
1505         COPY_NODE_FIELD(rarg);
1506         COPY_INTLIST_FIELD(colTypes);
1507
1508         return newnode;
1509 }
1510
1511 static AlterTableStmt *
1512 _copyAlterTableStmt(AlterTableStmt *from)
1513 {
1514         AlterTableStmt *newnode = makeNode(AlterTableStmt);
1515
1516         COPY_SCALAR_FIELD(subtype);
1517         COPY_NODE_FIELD(relation);
1518         COPY_STRING_FIELD(name);
1519         COPY_NODE_FIELD(def);
1520         COPY_SCALAR_FIELD(behavior);
1521
1522         return newnode;
1523 }
1524
1525 static AlterDomainStmt *
1526 _copyAlterDomainStmt(AlterDomainStmt *from)
1527 {
1528         AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1529
1530         COPY_SCALAR_FIELD(subtype);
1531         COPY_NODE_FIELD(typename);
1532         COPY_STRING_FIELD(name);
1533         COPY_NODE_FIELD(def);
1534         COPY_SCALAR_FIELD(behavior);
1535
1536         return newnode;
1537
1538
1539 static GrantStmt *
1540 _copyGrantStmt(GrantStmt *from)
1541 {
1542         GrantStmt  *newnode = makeNode(GrantStmt);
1543
1544         COPY_SCALAR_FIELD(is_grant);
1545         COPY_SCALAR_FIELD(objtype);
1546         COPY_NODE_FIELD(objects);
1547         COPY_INTLIST_FIELD(privileges);
1548         COPY_NODE_FIELD(grantees);
1549
1550         return newnode;
1551 }
1552
1553 static PrivGrantee *
1554 _copyPrivGrantee(PrivGrantee *from)
1555 {
1556         PrivGrantee *newnode = makeNode(PrivGrantee);
1557
1558         COPY_STRING_FIELD(username);
1559         COPY_STRING_FIELD(groupname);
1560
1561         return newnode;
1562 }
1563
1564 static FuncWithArgs *
1565 _copyFuncWithArgs(FuncWithArgs *from)
1566 {
1567         FuncWithArgs *newnode = makeNode(FuncWithArgs);
1568
1569         COPY_NODE_FIELD(funcname);
1570         COPY_NODE_FIELD(funcargs);
1571
1572         return newnode;
1573 }
1574
1575 static InsertDefault *
1576 _copyInsertDefault(InsertDefault *from)
1577 {
1578         InsertDefault *newnode = makeNode(InsertDefault);
1579
1580         return newnode;
1581 }
1582
1583
1584 static ClosePortalStmt *
1585 _copyClosePortalStmt(ClosePortalStmt *from)
1586 {
1587         ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1588
1589         COPY_STRING_FIELD(portalname);
1590
1591         return newnode;
1592 }
1593
1594 static ClusterStmt *
1595 _copyClusterStmt(ClusterStmt *from)
1596 {
1597         ClusterStmt *newnode = makeNode(ClusterStmt);
1598
1599         COPY_NODE_FIELD(relation);
1600         COPY_STRING_FIELD(indexname);
1601
1602         return newnode;
1603 }
1604
1605 static CopyStmt *
1606 _copyCopyStmt(CopyStmt *from)
1607 {
1608         CopyStmt   *newnode = makeNode(CopyStmt);
1609
1610         COPY_NODE_FIELD(relation);
1611         COPY_NODE_FIELD(attlist);
1612         COPY_SCALAR_FIELD(is_from);
1613         COPY_STRING_FIELD(filename);
1614         COPY_NODE_FIELD(options);
1615
1616         return newnode;
1617 }
1618
1619 static CreateStmt *
1620 _copyCreateStmt(CreateStmt *from)
1621 {
1622         CreateStmt *newnode = makeNode(CreateStmt);
1623
1624         COPY_NODE_FIELD(relation);
1625         COPY_NODE_FIELD(tableElts);
1626         COPY_NODE_FIELD(inhRelations);
1627         COPY_NODE_FIELD(constraints);
1628         COPY_SCALAR_FIELD(hasoids);
1629         COPY_SCALAR_FIELD(oncommit);
1630
1631         return newnode;
1632 }
1633
1634 static DefineStmt *
1635 _copyDefineStmt(DefineStmt *from)
1636 {
1637         DefineStmt *newnode = makeNode(DefineStmt);
1638
1639         COPY_SCALAR_FIELD(defType);
1640         COPY_NODE_FIELD(defnames);
1641         COPY_NODE_FIELD(definition);
1642
1643         return newnode;
1644 }
1645
1646 static DropStmt *
1647 _copyDropStmt(DropStmt *from)
1648 {
1649         DropStmt   *newnode = makeNode(DropStmt);
1650
1651         COPY_NODE_FIELD(objects);
1652         COPY_SCALAR_FIELD(removeType);
1653         COPY_SCALAR_FIELD(behavior);
1654
1655         return newnode;
1656 }
1657
1658 static TruncateStmt *
1659 _copyTruncateStmt(TruncateStmt *from)
1660 {
1661         TruncateStmt *newnode = makeNode(TruncateStmt);
1662
1663         COPY_NODE_FIELD(relation);
1664
1665         return newnode;
1666 }
1667
1668 static CommentStmt *
1669 _copyCommentStmt(CommentStmt *from)
1670 {
1671         CommentStmt *newnode = makeNode(CommentStmt);
1672
1673         COPY_SCALAR_FIELD(objtype);
1674         COPY_NODE_FIELD(objname);
1675         COPY_NODE_FIELD(objargs);
1676         COPY_STRING_FIELD(comment);
1677
1678         return newnode;
1679 }
1680
1681 static FetchStmt *
1682 _copyFetchStmt(FetchStmt *from)
1683 {
1684         FetchStmt  *newnode = makeNode(FetchStmt);
1685
1686         COPY_SCALAR_FIELD(direction);
1687         COPY_SCALAR_FIELD(howMany);
1688         COPY_STRING_FIELD(portalname);
1689         COPY_SCALAR_FIELD(ismove);
1690
1691         return newnode;
1692 }
1693
1694 static IndexStmt *
1695 _copyIndexStmt(IndexStmt *from)
1696 {
1697         IndexStmt  *newnode = makeNode(IndexStmt);
1698
1699         COPY_STRING_FIELD(idxname);
1700         COPY_NODE_FIELD(relation);
1701         COPY_STRING_FIELD(accessMethod);
1702         COPY_NODE_FIELD(indexParams);
1703         COPY_NODE_FIELD(whereClause);
1704         COPY_NODE_FIELD(rangetable);
1705         COPY_SCALAR_FIELD(unique);
1706         COPY_SCALAR_FIELD(primary);
1707         COPY_SCALAR_FIELD(isconstraint);
1708
1709         return newnode;
1710 }
1711
1712 static CreateFunctionStmt *
1713 _copyCreateFunctionStmt(CreateFunctionStmt *from)
1714 {
1715         CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
1716
1717         COPY_SCALAR_FIELD(replace);
1718         COPY_NODE_FIELD(funcname);
1719         COPY_NODE_FIELD(argTypes);
1720         COPY_NODE_FIELD(returnType);
1721         COPY_NODE_FIELD(options);
1722         COPY_NODE_FIELD(withClause);
1723
1724         return newnode;
1725 }
1726
1727 static RemoveAggrStmt *
1728 _copyRemoveAggrStmt(RemoveAggrStmt *from)
1729 {
1730         RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1731
1732         COPY_NODE_FIELD(aggname);
1733         COPY_NODE_FIELD(aggtype);
1734         COPY_SCALAR_FIELD(behavior);
1735
1736         return newnode;
1737 }
1738
1739 static RemoveFuncStmt *
1740 _copyRemoveFuncStmt(RemoveFuncStmt *from)
1741 {
1742         RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
1743
1744         COPY_NODE_FIELD(funcname);
1745         COPY_NODE_FIELD(args);
1746         COPY_SCALAR_FIELD(behavior);
1747
1748         return newnode;
1749 }
1750
1751 static RemoveOperStmt *
1752 _copyRemoveOperStmt(RemoveOperStmt *from)
1753 {
1754         RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
1755
1756         COPY_NODE_FIELD(opname);
1757         COPY_NODE_FIELD(args);
1758         COPY_SCALAR_FIELD(behavior);
1759
1760         return newnode;
1761 }
1762
1763 static RemoveOpClassStmt *
1764 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
1765 {
1766         RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
1767
1768         COPY_NODE_FIELD(opclassname);
1769         COPY_STRING_FIELD(amname);
1770         COPY_SCALAR_FIELD(behavior);
1771
1772         return newnode;
1773 }
1774
1775 static RenameStmt *
1776 _copyRenameStmt(RenameStmt *from)
1777 {
1778         RenameStmt *newnode = makeNode(RenameStmt);
1779
1780         COPY_NODE_FIELD(relation);
1781         COPY_STRING_FIELD(oldname);
1782         COPY_STRING_FIELD(newname);
1783         COPY_SCALAR_FIELD(renameType);
1784
1785         return newnode;
1786 }
1787
1788 static RuleStmt *
1789 _copyRuleStmt(RuleStmt *from)
1790 {
1791         RuleStmt   *newnode = makeNode(RuleStmt);
1792
1793         COPY_NODE_FIELD(relation);
1794         COPY_STRING_FIELD(rulename);
1795         COPY_NODE_FIELD(whereClause);
1796         COPY_SCALAR_FIELD(event);
1797         COPY_SCALAR_FIELD(instead);
1798         COPY_NODE_FIELD(actions);
1799         COPY_SCALAR_FIELD(replace);
1800
1801         return newnode;
1802 }
1803
1804 static NotifyStmt *
1805 _copyNotifyStmt(NotifyStmt *from)
1806 {
1807         NotifyStmt *newnode = makeNode(NotifyStmt);
1808
1809         COPY_NODE_FIELD(relation);
1810
1811         return newnode;
1812 }
1813
1814 static ListenStmt *
1815 _copyListenStmt(ListenStmt *from)
1816 {
1817         ListenStmt *newnode = makeNode(ListenStmt);
1818
1819         COPY_NODE_FIELD(relation);
1820
1821         return newnode;
1822 }
1823
1824 static UnlistenStmt *
1825 _copyUnlistenStmt(UnlistenStmt *from)
1826 {
1827         UnlistenStmt *newnode = makeNode(UnlistenStmt);
1828
1829         COPY_NODE_FIELD(relation);
1830
1831         return newnode;
1832 }
1833
1834 static TransactionStmt *
1835 _copyTransactionStmt(TransactionStmt *from)
1836 {
1837         TransactionStmt *newnode = makeNode(TransactionStmt);
1838
1839         COPY_SCALAR_FIELD(command);
1840         COPY_NODE_FIELD(options);
1841
1842         return newnode;
1843 }
1844
1845 static CompositeTypeStmt *
1846 _copyCompositeTypeStmt(CompositeTypeStmt *from)
1847 {
1848         CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
1849
1850         COPY_NODE_FIELD(typevar);
1851         COPY_NODE_FIELD(coldeflist);
1852
1853         return newnode;
1854 }
1855
1856 static ViewStmt *
1857 _copyViewStmt(ViewStmt *from)
1858 {
1859         ViewStmt   *newnode = makeNode(ViewStmt);
1860
1861         COPY_NODE_FIELD(view);
1862         COPY_NODE_FIELD(aliases);
1863         COPY_NODE_FIELD(query);
1864         COPY_SCALAR_FIELD(replace);
1865
1866         return newnode;
1867 }
1868
1869 static LoadStmt *
1870 _copyLoadStmt(LoadStmt *from)
1871 {
1872         LoadStmt   *newnode = makeNode(LoadStmt);
1873
1874         COPY_STRING_FIELD(filename);
1875
1876         return newnode;
1877 }
1878
1879 static CreateDomainStmt *
1880 _copyCreateDomainStmt(CreateDomainStmt *from)
1881 {
1882         CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
1883
1884         COPY_NODE_FIELD(domainname);
1885         COPY_NODE_FIELD(typename);
1886         COPY_NODE_FIELD(constraints);
1887
1888         return newnode;
1889 }
1890
1891 static CreateOpClassStmt *
1892 _copyCreateOpClassStmt(CreateOpClassStmt *from)
1893 {
1894         CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
1895
1896         COPY_NODE_FIELD(opclassname);
1897         COPY_STRING_FIELD(amname);
1898         COPY_NODE_FIELD(datatype);
1899         COPY_NODE_FIELD(items);
1900         COPY_SCALAR_FIELD(isDefault);
1901
1902         return newnode;
1903 }
1904
1905 static CreateOpClassItem *
1906 _copyCreateOpClassItem(CreateOpClassItem *from)
1907 {
1908         CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
1909
1910         COPY_SCALAR_FIELD(itemtype);
1911         COPY_NODE_FIELD(name);
1912         COPY_NODE_FIELD(args);
1913         COPY_SCALAR_FIELD(number);
1914         COPY_SCALAR_FIELD(recheck);
1915         COPY_NODE_FIELD(storedtype);
1916
1917         return newnode;
1918 }
1919
1920 static CreatedbStmt *
1921 _copyCreatedbStmt(CreatedbStmt *from)
1922 {
1923         CreatedbStmt *newnode = makeNode(CreatedbStmt);
1924
1925         COPY_STRING_FIELD(dbname);
1926         COPY_NODE_FIELD(options);
1927
1928         return newnode;
1929 }
1930
1931 static AlterDatabaseSetStmt *
1932 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
1933 {
1934         AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
1935
1936         COPY_STRING_FIELD(dbname);
1937         COPY_STRING_FIELD(variable);
1938         COPY_NODE_FIELD(value);
1939
1940         return newnode;
1941 }
1942
1943 static DropdbStmt *
1944 _copyDropdbStmt(DropdbStmt *from)
1945 {
1946         DropdbStmt *newnode = makeNode(DropdbStmt);
1947
1948         COPY_STRING_FIELD(dbname);
1949
1950         return newnode;
1951 }
1952
1953 static VacuumStmt *
1954 _copyVacuumStmt(VacuumStmt *from)
1955 {
1956         VacuumStmt *newnode = makeNode(VacuumStmt);
1957
1958         COPY_SCALAR_FIELD(vacuum);
1959         COPY_SCALAR_FIELD(full);
1960         COPY_SCALAR_FIELD(analyze);
1961         COPY_SCALAR_FIELD(freeze);
1962         COPY_SCALAR_FIELD(verbose);
1963         COPY_NODE_FIELD(relation);
1964         COPY_NODE_FIELD(va_cols);
1965
1966         return newnode;
1967 }
1968
1969 static ExplainStmt *
1970 _copyExplainStmt(ExplainStmt *from)
1971 {
1972         ExplainStmt *newnode = makeNode(ExplainStmt);
1973
1974         COPY_NODE_FIELD(query);
1975         COPY_SCALAR_FIELD(verbose);
1976         COPY_SCALAR_FIELD(analyze);
1977
1978         return newnode;
1979 }
1980
1981 static CreateSeqStmt *
1982 _copyCreateSeqStmt(CreateSeqStmt *from)
1983 {
1984         CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
1985
1986         COPY_NODE_FIELD(sequence);
1987         COPY_NODE_FIELD(options);
1988
1989         return newnode;
1990 }
1991
1992 static VariableSetStmt *
1993 _copyVariableSetStmt(VariableSetStmt *from)
1994 {
1995         VariableSetStmt *newnode = makeNode(VariableSetStmt);
1996
1997         COPY_STRING_FIELD(name);
1998         COPY_NODE_FIELD(args);
1999         COPY_SCALAR_FIELD(is_local);
2000
2001         return newnode;
2002 }
2003
2004 static VariableShowStmt *
2005 _copyVariableShowStmt(VariableShowStmt *from)
2006 {
2007         VariableShowStmt *newnode = makeNode(VariableShowStmt);
2008
2009         COPY_STRING_FIELD(name);
2010
2011         return newnode;
2012 }
2013
2014 static VariableResetStmt *
2015 _copyVariableResetStmt(VariableResetStmt *from)
2016 {
2017         VariableResetStmt *newnode = makeNode(VariableResetStmt);
2018
2019         COPY_STRING_FIELD(name);
2020
2021         return newnode;
2022 }
2023
2024 static CreateTrigStmt *
2025 _copyCreateTrigStmt(CreateTrigStmt *from)
2026 {
2027         CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2028
2029         COPY_STRING_FIELD(trigname);
2030         COPY_NODE_FIELD(relation);
2031         COPY_NODE_FIELD(funcname);
2032         COPY_NODE_FIELD(args);
2033         COPY_SCALAR_FIELD(before);
2034         COPY_SCALAR_FIELD(row);
2035         strcpy(newnode->actions, from->actions); /* in-line string field */
2036         COPY_SCALAR_FIELD(isconstraint);
2037         COPY_SCALAR_FIELD(deferrable);
2038         COPY_SCALAR_FIELD(initdeferred);
2039         COPY_NODE_FIELD(constrrel);
2040
2041         return newnode;
2042 }
2043
2044 static DropPropertyStmt *
2045 _copyDropPropertyStmt(DropPropertyStmt *from)
2046 {
2047         DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2048
2049         COPY_NODE_FIELD(relation);
2050         COPY_STRING_FIELD(property);
2051         COPY_SCALAR_FIELD(removeType);
2052         COPY_SCALAR_FIELD(behavior);
2053
2054         return newnode;
2055 }
2056
2057 static CreatePLangStmt *
2058 _copyCreatePLangStmt(CreatePLangStmt *from)
2059 {
2060         CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2061
2062         COPY_STRING_FIELD(plname);
2063         COPY_NODE_FIELD(plhandler);
2064         COPY_NODE_FIELD(plvalidator);
2065         COPY_SCALAR_FIELD(pltrusted);
2066
2067         return newnode;
2068 }
2069
2070 static DropPLangStmt *
2071 _copyDropPLangStmt(DropPLangStmt *from)
2072 {
2073         DropPLangStmt *newnode = makeNode(DropPLangStmt);
2074
2075         COPY_STRING_FIELD(plname);
2076         COPY_SCALAR_FIELD(behavior);
2077
2078         return newnode;
2079 }
2080
2081 static CreateUserStmt *
2082 _copyCreateUserStmt(CreateUserStmt *from)
2083 {
2084         CreateUserStmt *newnode = makeNode(CreateUserStmt);
2085
2086         COPY_STRING_FIELD(user);
2087         COPY_NODE_FIELD(options);
2088
2089         return newnode;
2090 }
2091
2092 static AlterUserStmt *
2093 _copyAlterUserStmt(AlterUserStmt *from)
2094 {
2095         AlterUserStmt *newnode = makeNode(AlterUserStmt);
2096
2097         COPY_STRING_FIELD(user);
2098         COPY_NODE_FIELD(options);
2099
2100         return newnode;
2101 }
2102
2103 static AlterUserSetStmt *
2104 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2105 {
2106         AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2107
2108         COPY_STRING_FIELD(user);
2109         COPY_STRING_FIELD(variable);
2110         COPY_NODE_FIELD(value);
2111
2112         return newnode;
2113 }
2114
2115 static DropUserStmt *
2116 _copyDropUserStmt(DropUserStmt *from)
2117 {
2118         DropUserStmt *newnode = makeNode(DropUserStmt);
2119
2120         COPY_NODE_FIELD(users);
2121
2122         return newnode;
2123 }
2124
2125 static LockStmt *
2126 _copyLockStmt(LockStmt *from)
2127 {
2128         LockStmt   *newnode = makeNode(LockStmt);
2129
2130         COPY_NODE_FIELD(relations);
2131         COPY_SCALAR_FIELD(mode);
2132
2133         return newnode;
2134 }
2135
2136 static ConstraintsSetStmt *
2137 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2138 {
2139         ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2140
2141         COPY_NODE_FIELD(constraints);
2142         COPY_SCALAR_FIELD(deferred);
2143
2144         return newnode;
2145 }
2146
2147 static CreateGroupStmt *
2148 _copyCreateGroupStmt(CreateGroupStmt *from)
2149 {
2150         CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2151
2152         COPY_STRING_FIELD(name);
2153         COPY_NODE_FIELD(options);
2154
2155         return newnode;
2156 }
2157
2158 static AlterGroupStmt *
2159 _copyAlterGroupStmt(AlterGroupStmt *from)
2160 {
2161         AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2162
2163         COPY_STRING_FIELD(name);
2164         COPY_SCALAR_FIELD(action);
2165         COPY_NODE_FIELD(listUsers);
2166
2167         return newnode;
2168 }
2169
2170 static DropGroupStmt *
2171 _copyDropGroupStmt(DropGroupStmt *from)
2172 {
2173         DropGroupStmt *newnode = makeNode(DropGroupStmt);
2174
2175         COPY_STRING_FIELD(name);
2176
2177         return newnode;
2178 }
2179
2180 static ReindexStmt *
2181 _copyReindexStmt(ReindexStmt *from)
2182 {
2183         ReindexStmt *newnode = makeNode(ReindexStmt);
2184
2185         COPY_SCALAR_FIELD(reindexType);
2186         COPY_NODE_FIELD(relation);
2187         COPY_STRING_FIELD(name);
2188         COPY_SCALAR_FIELD(force);
2189         COPY_SCALAR_FIELD(all);
2190
2191         return newnode;
2192 }
2193
2194 static CreateSchemaStmt *
2195 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2196 {
2197         CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2198
2199         COPY_STRING_FIELD(schemaname);
2200         COPY_STRING_FIELD(authid);
2201         COPY_NODE_FIELD(schemaElts);
2202
2203         return newnode;
2204 }
2205
2206 static CreateConversionStmt *
2207 _copyCreateConversionStmt(CreateConversionStmt *from)
2208 {
2209         CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2210
2211         COPY_NODE_FIELD(conversion_name);
2212         COPY_STRING_FIELD(for_encoding_name);
2213         COPY_STRING_FIELD(to_encoding_name);
2214         COPY_NODE_FIELD(func_name);
2215         COPY_SCALAR_FIELD(def);
2216
2217         return newnode;
2218 }
2219
2220 static CreateCastStmt *
2221 _copyCreateCastStmt(CreateCastStmt *from)
2222 {
2223         CreateCastStmt *newnode = makeNode(CreateCastStmt);
2224
2225         COPY_NODE_FIELD(sourcetype);
2226         COPY_NODE_FIELD(targettype);
2227         COPY_NODE_FIELD(func);
2228         COPY_SCALAR_FIELD(context);
2229
2230         return newnode;
2231 }
2232
2233 static DropCastStmt *
2234 _copyDropCastStmt(DropCastStmt *from)
2235 {
2236         DropCastStmt *newnode = makeNode(DropCastStmt);
2237
2238         COPY_NODE_FIELD(sourcetype);
2239         COPY_NODE_FIELD(targettype);
2240         COPY_SCALAR_FIELD(behavior);
2241
2242         return newnode;
2243 }
2244
2245 static PrepareStmt *
2246 _copyPrepareStmt(PrepareStmt *from)
2247 {
2248         PrepareStmt *newnode = makeNode(PrepareStmt);
2249
2250         COPY_STRING_FIELD(name);
2251         COPY_NODE_FIELD(argtypes);
2252         COPY_INTLIST_FIELD(argtype_oids);
2253         COPY_NODE_FIELD(query);
2254
2255         return newnode;
2256 }
2257
2258 static ExecuteStmt *
2259 _copyExecuteStmt(ExecuteStmt *from)
2260 {
2261         ExecuteStmt *newnode = makeNode(ExecuteStmt);
2262
2263         COPY_STRING_FIELD(name);
2264         COPY_NODE_FIELD(into);
2265         COPY_NODE_FIELD(params);
2266
2267         return newnode;
2268 }
2269
2270 static DeallocateStmt *
2271 _copyDeallocateStmt(DeallocateStmt *from)
2272 {
2273         DeallocateStmt *newnode = makeNode(DeallocateStmt);
2274
2275         COPY_STRING_FIELD(name);
2276
2277         return newnode;
2278 }
2279
2280
2281 /* ****************************************************************
2282  *                                      pg_list.h copy functions
2283  * ****************************************************************
2284  */
2285
2286 static Value *
2287 _copyValue(Value *from)
2288 {
2289         Value      *newnode = makeNode(Value);
2290
2291         /* See also _copyAConst when changing this code! */
2292
2293         COPY_SCALAR_FIELD(type);
2294         switch (from->type)
2295         {
2296                 case T_Integer:
2297                         COPY_SCALAR_FIELD(val.ival);
2298                         break;
2299                 case T_Float:
2300                 case T_String:
2301                 case T_BitString:
2302                         COPY_STRING_FIELD(val.str);
2303                         break;
2304                 case T_Null:
2305                         /* nothing to do */
2306                         break;
2307                 default:
2308                         elog(ERROR, "_copyValue: unknown node type %d", from->type);
2309                         break;
2310         }
2311         return newnode;
2312 }
2313
2314 /*
2315  * copyObject
2316  *
2317  * Create a copy of a Node tree or list.  This is a "deep" copy: all
2318  * substructure is copied too, recursively.
2319  */
2320 void *
2321 copyObject(void *from)
2322 {
2323         void       *retval;
2324
2325         if (from == NULL)
2326                 return NULL;
2327
2328         switch (nodeTag(from))
2329         {
2330                         /*
2331                          * PLAN NODES
2332                          */
2333                 case T_Plan:
2334                         retval = _copyPlan(from);
2335                         break;
2336                 case T_Result:
2337                         retval = _copyResult(from);
2338                         break;
2339                 case T_Append:
2340                         retval = _copyAppend(from);
2341                         break;
2342                 case T_Scan:
2343                         retval = _copyScan(from);
2344                         break;
2345                 case T_SeqScan:
2346                         retval = _copySeqScan(from);
2347                         break;
2348                 case T_IndexScan:
2349                         retval = _copyIndexScan(from);
2350                         break;
2351                 case T_TidScan:
2352                         retval = _copyTidScan(from);
2353                         break;
2354                 case T_SubqueryScan:
2355                         retval = _copySubqueryScan(from);
2356                         break;
2357                 case T_FunctionScan:
2358                         retval = _copyFunctionScan(from);
2359                         break;
2360                 case T_Join:
2361                         retval = _copyJoin(from);
2362                         break;
2363                 case T_NestLoop:
2364                         retval = _copyNestLoop(from);
2365                         break;
2366                 case T_MergeJoin:
2367                         retval = _copyMergeJoin(from);
2368                         break;
2369                 case T_HashJoin:
2370                         retval = _copyHashJoin(from);
2371                         break;
2372                 case T_Material:
2373                         retval = _copyMaterial(from);
2374                         break;
2375                 case T_Sort:
2376                         retval = _copySort(from);
2377                         break;
2378                 case T_Group:
2379                         retval = _copyGroup(from);
2380                         break;
2381                 case T_Agg:
2382                         retval = _copyAgg(from);
2383                         break;
2384                 case T_Unique:
2385                         retval = _copyUnique(from);
2386                         break;
2387                 case T_Hash:
2388                         retval = _copyHash(from);
2389                         break;
2390                 case T_SetOp:
2391                         retval = _copySetOp(from);
2392                         break;
2393                 case T_Limit:
2394                         retval = _copyLimit(from);
2395                         break;
2396
2397                         /*
2398                          * PRIMITIVE NODES
2399                          */
2400                 case T_Resdom:
2401                         retval = _copyResdom(from);
2402                         break;
2403                 case T_Alias:
2404                         retval = _copyAlias(from);
2405                         break;
2406                 case T_RangeVar:
2407                         retval = _copyRangeVar(from);
2408                         break;
2409                 case T_Var:
2410                         retval = _copyVar(from);
2411                         break;
2412                 case T_Const:
2413                         retval = _copyConst(from);
2414                         break;
2415                 case T_Param:
2416                         retval = _copyParam(from);
2417                         break;
2418                 case T_Aggref:
2419                         retval = _copyAggref(from);
2420                         break;
2421                 case T_ArrayRef:
2422                         retval = _copyArrayRef(from);
2423                         break;
2424                 case T_FuncExpr:
2425                         retval = _copyFuncExpr(from);
2426                         break;
2427                 case T_OpExpr:
2428                         retval = _copyOpExpr(from);
2429                         break;
2430                 case T_DistinctExpr:
2431                         retval = _copyDistinctExpr(from);
2432                         break;
2433                 case T_BoolExpr:
2434                         retval = _copyBoolExpr(from);
2435                         break;
2436                 case T_SubLink:
2437                         retval = _copySubLink(from);
2438                         break;
2439                 case T_SubPlan:
2440                         retval = _copySubPlan(from);
2441                         break;
2442                 case T_FieldSelect:
2443                         retval = _copyFieldSelect(from);
2444                         break;
2445                 case T_RelabelType:
2446                         retval = _copyRelabelType(from);
2447                         break;
2448                 case T_CaseExpr:
2449                         retval = _copyCaseExpr(from);
2450                         break;
2451                 case T_CaseWhen:
2452                         retval = _copyCaseWhen(from);
2453                         break;
2454                 case T_NullTest:
2455                         retval = _copyNullTest(from);
2456                         break;
2457                 case T_BooleanTest:
2458                         retval = _copyBooleanTest(from);
2459                         break;
2460                 case T_ConstraintTest:
2461                         retval = _copyConstraintTest(from);
2462                         break;
2463                 case T_ConstraintTestValue:
2464                         retval = _copyConstraintTestValue(from);
2465                         break;
2466                 case T_TargetEntry:
2467                         retval = _copyTargetEntry(from);
2468                         break;
2469                 case T_RangeTblRef:
2470                         retval = _copyRangeTblRef(from);
2471                         break;
2472                 case T_JoinExpr:
2473                         retval = _copyJoinExpr(from);
2474                         break;
2475                 case T_FromExpr:
2476                         retval = _copyFromExpr(from);
2477                         break;
2478
2479                         /*
2480                          * RELATION NODES
2481                          */
2482                 case T_PathKeyItem:
2483                         retval = _copyPathKeyItem(from);
2484                         break;
2485                 case T_RestrictInfo:
2486                         retval = _copyRestrictInfo(from);
2487                         break;
2488                 case T_JoinInfo:
2489                         retval = _copyJoinInfo(from);
2490                         break;
2491
2492                         /*
2493                          * VALUE NODES
2494                          */
2495                 case T_Integer:
2496                 case T_Float:
2497                 case T_String:
2498                 case T_BitString:
2499                 case T_Null:
2500                         retval = _copyValue(from);
2501                         break;
2502                 case T_List:
2503                         {
2504                                 List       *list = from,
2505                                                    *l,
2506                                                    *nl;
2507
2508                                 /* rather ugly coding for speed... */
2509                                 /* Note the input list cannot be NIL if we got here. */
2510                                 nl = makeList1(copyObject(lfirst(list)));
2511                                 retval = nl;
2512
2513                                 foreach(l, lnext(list))
2514                                 {
2515                                         lnext(nl) = makeList1(copyObject(lfirst(l)));
2516                                         nl = lnext(nl);
2517                                 }
2518                         }
2519                         break;
2520
2521                         /*
2522                          * PARSE NODES
2523                          */
2524                 case T_Query:
2525                         retval = _copyQuery(from);
2526                         break;
2527                 case T_InsertStmt:
2528                         retval = _copyInsertStmt(from);
2529                         break;
2530                 case T_DeleteStmt:
2531                         retval = _copyDeleteStmt(from);
2532                         break;
2533                 case T_UpdateStmt:
2534                         retval = _copyUpdateStmt(from);
2535                         break;
2536                 case T_SelectStmt:
2537                         retval = _copySelectStmt(from);
2538                         break;
2539                 case T_SetOperationStmt:
2540                         retval = _copySetOperationStmt(from);
2541                         break;
2542                 case T_AlterTableStmt:
2543                         retval = _copyAlterTableStmt(from);
2544                         break;
2545                 case T_AlterDomainStmt:
2546                         retval = _copyAlterDomainStmt(from);
2547                         break;
2548                 case T_GrantStmt:
2549                         retval = _copyGrantStmt(from);
2550                         break;
2551                 case T_ClosePortalStmt:
2552                         retval = _copyClosePortalStmt(from);
2553                         break;
2554                 case T_ClusterStmt:
2555                         retval = _copyClusterStmt(from);
2556                         break;
2557                 case T_CopyStmt:
2558                         retval = _copyCopyStmt(from);
2559                         break;
2560                 case T_CreateStmt:
2561                         retval = _copyCreateStmt(from);
2562                         break;
2563                 case T_DefineStmt:
2564                         retval = _copyDefineStmt(from);
2565                         break;
2566                 case T_DropStmt:
2567                         retval = _copyDropStmt(from);
2568                         break;
2569                 case T_TruncateStmt:
2570                         retval = _copyTruncateStmt(from);
2571                         break;
2572                 case T_CommentStmt:
2573                         retval = _copyCommentStmt(from);
2574                         break;
2575                 case T_FetchStmt:
2576                         retval = _copyFetchStmt(from);
2577                         break;
2578                 case T_IndexStmt:
2579                         retval = _copyIndexStmt(from);
2580                         break;
2581                 case T_CreateFunctionStmt:
2582                         retval = _copyCreateFunctionStmt(from);
2583                         break;
2584                 case T_RemoveAggrStmt:
2585                         retval = _copyRemoveAggrStmt(from);
2586                         break;
2587                 case T_RemoveFuncStmt:
2588                         retval = _copyRemoveFuncStmt(from);
2589                         break;
2590                 case T_RemoveOperStmt:
2591                         retval = _copyRemoveOperStmt(from);
2592                         break;
2593                 case T_RemoveOpClassStmt:
2594                         retval = _copyRemoveOpClassStmt(from);
2595                         break;
2596                 case T_RenameStmt:
2597                         retval = _copyRenameStmt(from);
2598                         break;
2599                 case T_RuleStmt:
2600                         retval = _copyRuleStmt(from);
2601                         break;
2602                 case T_NotifyStmt:
2603                         retval = _copyNotifyStmt(from);
2604                         break;
2605                 case T_ListenStmt:
2606                         retval = _copyListenStmt(from);
2607                         break;
2608                 case T_UnlistenStmt:
2609                         retval = _copyUnlistenStmt(from);
2610                         break;
2611                 case T_TransactionStmt:
2612                         retval = _copyTransactionStmt(from);
2613                         break;
2614                 case T_CompositeTypeStmt:
2615                         retval = _copyCompositeTypeStmt(from);
2616                         break;
2617                 case T_ViewStmt:
2618                         retval = _copyViewStmt(from);
2619                         break;
2620                 case T_LoadStmt:
2621                         retval = _copyLoadStmt(from);
2622                         break;
2623                 case T_CreateDomainStmt:
2624                         retval = _copyCreateDomainStmt(from);
2625                         break;
2626                 case T_CreateOpClassStmt:
2627                         retval = _copyCreateOpClassStmt(from);
2628                         break;
2629                 case T_CreateOpClassItem:
2630                         retval = _copyCreateOpClassItem(from);
2631                         break;
2632                 case T_CreatedbStmt:
2633                         retval = _copyCreatedbStmt(from);
2634                         break;
2635                 case T_AlterDatabaseSetStmt:
2636                         retval = _copyAlterDatabaseSetStmt(from);
2637                         break;
2638                 case T_DropdbStmt:
2639                         retval = _copyDropdbStmt(from);
2640                         break;
2641                 case T_VacuumStmt:
2642                         retval = _copyVacuumStmt(from);
2643                         break;
2644                 case T_ExplainStmt:
2645                         retval = _copyExplainStmt(from);
2646                         break;
2647                 case T_CreateSeqStmt:
2648                         retval = _copyCreateSeqStmt(from);
2649                         break;
2650                 case T_VariableSetStmt:
2651                         retval = _copyVariableSetStmt(from);
2652                         break;
2653                 case T_VariableShowStmt:
2654                         retval = _copyVariableShowStmt(from);
2655                         break;
2656                 case T_VariableResetStmt:
2657                         retval = _copyVariableResetStmt(from);
2658                         break;
2659                 case T_CreateTrigStmt:
2660                         retval = _copyCreateTrigStmt(from);
2661                         break;
2662                 case T_DropPropertyStmt:
2663                         retval = _copyDropPropertyStmt(from);
2664                         break;
2665                 case T_CreatePLangStmt:
2666                         retval = _copyCreatePLangStmt(from);
2667                         break;
2668                 case T_DropPLangStmt:
2669                         retval = _copyDropPLangStmt(from);
2670                         break;
2671                 case T_CreateUserStmt:
2672                         retval = _copyCreateUserStmt(from);
2673                         break;
2674                 case T_AlterUserStmt:
2675                         retval = _copyAlterUserStmt(from);
2676                         break;
2677                 case T_AlterUserSetStmt:
2678                         retval = _copyAlterUserSetStmt(from);
2679                         break;
2680                 case T_DropUserStmt:
2681                         retval = _copyDropUserStmt(from);
2682                         break;
2683                 case T_LockStmt:
2684                         retval = _copyLockStmt(from);
2685                         break;
2686                 case T_ConstraintsSetStmt:
2687                         retval = _copyConstraintsSetStmt(from);
2688                         break;
2689                 case T_CreateGroupStmt:
2690                         retval = _copyCreateGroupStmt(from);
2691                         break;
2692                 case T_AlterGroupStmt:
2693                         retval = _copyAlterGroupStmt(from);
2694                         break;
2695                 case T_DropGroupStmt:
2696                         retval = _copyDropGroupStmt(from);
2697                         break;
2698                 case T_ReindexStmt:
2699                         retval = _copyReindexStmt(from);
2700                         break;
2701                 case T_CheckPointStmt:
2702                         retval = (void *) makeNode(CheckPointStmt);
2703                         break;
2704                 case T_CreateSchemaStmt:
2705                         retval = _copyCreateSchemaStmt(from);
2706                         break;
2707                 case T_CreateConversionStmt:
2708                         retval = _copyCreateConversionStmt(from);
2709                         break;
2710                 case T_CreateCastStmt:
2711                         retval = _copyCreateCastStmt(from);
2712                         break;
2713                 case T_DropCastStmt:
2714                         retval = _copyDropCastStmt(from);
2715                         break;
2716                 case T_PrepareStmt:
2717                         retval = _copyPrepareStmt(from);
2718                         break;
2719                 case T_ExecuteStmt:
2720                         retval = _copyExecuteStmt(from);
2721                         break;
2722                 case T_DeallocateStmt:
2723                         retval = _copyDeallocateStmt(from);
2724                         break;
2725
2726                 case T_A_Expr:
2727                         retval = _copyAExpr(from);
2728                         break;
2729                 case T_ColumnRef:
2730                         retval = _copyColumnRef(from);
2731                         break;
2732                 case T_ParamRef:
2733                         retval = _copyParamRef(from);
2734                         break;
2735                 case T_A_Const:
2736                         retval = _copyAConst(from);
2737                         break;
2738                 case T_FuncCall:
2739                         retval = _copyFuncCall(from);
2740                         break;
2741                 case T_A_Indices:
2742                         retval = _copyAIndices(from);
2743                         break;
2744                 case T_ExprFieldSelect:
2745                         retval = _copyExprFieldSelect(from);
2746                         break;
2747                 case T_ResTarget:
2748                         retval = _copyResTarget(from);
2749                         break;
2750                 case T_TypeCast:
2751                         retval = _copyTypeCast(from);
2752                         break;
2753                 case T_SortGroupBy:
2754                         retval = _copySortGroupBy(from);
2755                         break;
2756                 case T_RangeSubselect:
2757                         retval = _copyRangeSubselect(from);
2758                         break;
2759                 case T_RangeFunction:
2760                         retval = _copyRangeFunction(from);
2761                         break;
2762                 case T_TypeName:
2763                         retval = _copyTypeName(from);
2764                         break;
2765                 case T_IndexElem:
2766                         retval = _copyIndexElem(from);
2767                         break;
2768                 case T_ColumnDef:
2769                         retval = _copyColumnDef(from);
2770                         break;
2771                 case T_Constraint:
2772                         retval = _copyConstraint(from);
2773                         break;
2774                 case T_DefElem:
2775                         retval = _copyDefElem(from);
2776                         break;
2777                 case T_RangeTblEntry:
2778                         retval = _copyRangeTblEntry(from);
2779                         break;
2780                 case T_SortClause:
2781                         retval = _copySortClause(from);
2782                         break;
2783                 case T_GroupClause:
2784                         retval = _copyGroupClause(from);
2785                         break;
2786                 case T_FkConstraint:
2787                         retval = _copyFkConstraint(from);
2788                         break;
2789                 case T_PrivGrantee:
2790                         retval = _copyPrivGrantee(from);
2791                         break;
2792                 case T_FuncWithArgs:
2793                         retval = _copyFuncWithArgs(from);
2794                         break;
2795                 case T_InsertDefault:
2796                         retval = _copyInsertDefault(from);
2797                         break;
2798
2799                 default:
2800                         elog(ERROR, "copyObject: don't know how to copy node type %d",
2801                                  nodeTag(from));
2802                         retval = from;          /* keep compiler quiet */
2803                         break;
2804         }
2805
2806         return retval;
2807 }