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