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