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