]> granicus.if.org Git - postgresql/blob - src/backend/nodes/copyfuncs.c
Improve UPDATE/DELETE WHERE CURRENT OF so that they can be used from plpgsql
[postgresql] / src / backend / nodes / copyfuncs.c
1 /*-------------------------------------------------------------------------
2  *
3  * copyfuncs.c
4  *        Copy functions for Postgres tree nodes.
5  *
6  * NOTE: we currently support copying all node types found in parse and
7  * plan trees.  We do not support copying executor state trees; there
8  * is no need for that, and no point in maintaining all the code that
9  * would be needed.  We also do not support copying Path trees, mainly
10  * because the circular linkages between RelOptInfo and Path nodes can't
11  * be handled easily in a simple depth-first traversal.
12  *
13  *
14  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
15  * Portions Copyright (c) 1994, Regents of the University of California
16  *
17  * IDENTIFICATION
18  *        $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.379 2007/06/11 22:22:40 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_SCALAR_FIELD(nParamExec);
87
88         return newnode;
89 }
90
91 /*
92  * CopyPlanFields
93  *
94  *              This function copies the fields of the Plan node.  It is used by
95  *              all the copy functions for classes which inherit from Plan.
96  */
97 static void
98 CopyPlanFields(Plan *from, Plan *newnode)
99 {
100         COPY_SCALAR_FIELD(startup_cost);
101         COPY_SCALAR_FIELD(total_cost);
102         COPY_SCALAR_FIELD(plan_rows);
103         COPY_SCALAR_FIELD(plan_width);
104         COPY_NODE_FIELD(targetlist);
105         COPY_NODE_FIELD(qual);
106         COPY_NODE_FIELD(lefttree);
107         COPY_NODE_FIELD(righttree);
108         COPY_NODE_FIELD(initPlan);
109         COPY_BITMAPSET_FIELD(extParam);
110         COPY_BITMAPSET_FIELD(allParam);
111 }
112
113 /*
114  * _copyPlan
115  */
116 static Plan *
117 _copyPlan(Plan *from)
118 {
119         Plan       *newnode = makeNode(Plan);
120
121         /*
122          * copy node superclass fields
123          */
124         CopyPlanFields(from, newnode);
125
126         return newnode;
127 }
128
129
130 /*
131  * _copyResult
132  */
133 static Result *
134 _copyResult(Result *from)
135 {
136         Result     *newnode = makeNode(Result);
137
138         /*
139          * copy node superclass fields
140          */
141         CopyPlanFields((Plan *) from, (Plan *) newnode);
142
143         /*
144          * copy remainder of node
145          */
146         COPY_NODE_FIELD(resconstantqual);
147
148         return newnode;
149 }
150
151 /*
152  * _copyAppend
153  */
154 static Append *
155 _copyAppend(Append *from)
156 {
157         Append     *newnode = makeNode(Append);
158
159         /*
160          * copy node superclass fields
161          */
162         CopyPlanFields((Plan *) from, (Plan *) newnode);
163
164         /*
165          * copy remainder of node
166          */
167         COPY_NODE_FIELD(appendplans);
168         COPY_SCALAR_FIELD(isTarget);
169
170         return newnode;
171 }
172
173 /*
174  * _copyBitmapAnd
175  */
176 static BitmapAnd *
177 _copyBitmapAnd(BitmapAnd *from)
178 {
179         BitmapAnd  *newnode = makeNode(BitmapAnd);
180
181         /*
182          * copy node superclass fields
183          */
184         CopyPlanFields((Plan *) from, (Plan *) newnode);
185
186         /*
187          * copy remainder of node
188          */
189         COPY_NODE_FIELD(bitmapplans);
190
191         return newnode;
192 }
193
194 /*
195  * _copyBitmapOr
196  */
197 static BitmapOr *
198 _copyBitmapOr(BitmapOr *from)
199 {
200         BitmapOr   *newnode = makeNode(BitmapOr);
201
202         /*
203          * copy node superclass fields
204          */
205         CopyPlanFields((Plan *) from, (Plan *) newnode);
206
207         /*
208          * copy remainder of node
209          */
210         COPY_NODE_FIELD(bitmapplans);
211
212         return newnode;
213 }
214
215
216 /*
217  * CopyScanFields
218  *
219  *              This function copies the fields of the Scan node.  It is used by
220  *              all the copy functions for classes which inherit from Scan.
221  */
222 static void
223 CopyScanFields(Scan *from, Scan *newnode)
224 {
225         CopyPlanFields((Plan *) from, (Plan *) newnode);
226
227         COPY_SCALAR_FIELD(scanrelid);
228 }
229
230 /*
231  * _copyScan
232  */
233 static Scan *
234 _copyScan(Scan *from)
235 {
236         Scan       *newnode = makeNode(Scan);
237
238         /*
239          * copy node superclass fields
240          */
241         CopyScanFields((Scan *) from, (Scan *) newnode);
242
243         return newnode;
244 }
245
246 /*
247  * _copySeqScan
248  */
249 static SeqScan *
250 _copySeqScan(SeqScan *from)
251 {
252         SeqScan    *newnode = makeNode(SeqScan);
253
254         /*
255          * copy node superclass fields
256          */
257         CopyScanFields((Scan *) from, (Scan *) newnode);
258
259         return newnode;
260 }
261
262 /*
263  * _copyIndexScan
264  */
265 static IndexScan *
266 _copyIndexScan(IndexScan *from)
267 {
268         IndexScan  *newnode = makeNode(IndexScan);
269
270         /*
271          * copy node superclass fields
272          */
273         CopyScanFields((Scan *) from, (Scan *) newnode);
274
275         /*
276          * copy remainder of node
277          */
278         COPY_SCALAR_FIELD(indexid);
279         COPY_NODE_FIELD(indexqual);
280         COPY_NODE_FIELD(indexqualorig);
281         COPY_NODE_FIELD(indexstrategy);
282         COPY_NODE_FIELD(indexsubtype);
283         COPY_SCALAR_FIELD(indexorderdir);
284
285         return newnode;
286 }
287
288 /*
289  * _copyBitmapIndexScan
290  */
291 static BitmapIndexScan *
292 _copyBitmapIndexScan(BitmapIndexScan *from)
293 {
294         BitmapIndexScan *newnode = makeNode(BitmapIndexScan);
295
296         /*
297          * copy node superclass fields
298          */
299         CopyScanFields((Scan *) from, (Scan *) newnode);
300
301         /*
302          * copy remainder of node
303          */
304         COPY_SCALAR_FIELD(indexid);
305         COPY_NODE_FIELD(indexqual);
306         COPY_NODE_FIELD(indexqualorig);
307         COPY_NODE_FIELD(indexstrategy);
308         COPY_NODE_FIELD(indexsubtype);
309
310         return newnode;
311 }
312
313 /*
314  * _copyBitmapHeapScan
315  */
316 static BitmapHeapScan *
317 _copyBitmapHeapScan(BitmapHeapScan *from)
318 {
319         BitmapHeapScan *newnode = makeNode(BitmapHeapScan);
320
321         /*
322          * copy node superclass fields
323          */
324         CopyScanFields((Scan *) from, (Scan *) newnode);
325
326         /*
327          * copy remainder of node
328          */
329         COPY_NODE_FIELD(bitmapqualorig);
330
331         return newnode;
332 }
333
334 /*
335  * _copyTidScan
336  */
337 static TidScan *
338 _copyTidScan(TidScan *from)
339 {
340         TidScan    *newnode = makeNode(TidScan);
341
342         /*
343          * copy node superclass fields
344          */
345         CopyScanFields((Scan *) from, (Scan *) newnode);
346
347         /*
348          * copy remainder of node
349          */
350         COPY_NODE_FIELD(tidquals);
351
352         return newnode;
353 }
354
355 /*
356  * _copySubqueryScan
357  */
358 static SubqueryScan *
359 _copySubqueryScan(SubqueryScan *from)
360 {
361         SubqueryScan *newnode = makeNode(SubqueryScan);
362
363         /*
364          * copy node superclass fields
365          */
366         CopyScanFields((Scan *) from, (Scan *) newnode);
367
368         /*
369          * copy remainder of node
370          */
371         COPY_NODE_FIELD(subplan);
372         COPY_NODE_FIELD(subrtable);
373
374         return newnode;
375 }
376
377 /*
378  * _copyFunctionScan
379  */
380 static FunctionScan *
381 _copyFunctionScan(FunctionScan *from)
382 {
383         FunctionScan *newnode = makeNode(FunctionScan);
384
385         /*
386          * copy node superclass fields
387          */
388         CopyScanFields((Scan *) from, (Scan *) newnode);
389
390         /*
391          * copy remainder of node
392          */
393         COPY_NODE_FIELD(funcexpr);
394         COPY_NODE_FIELD(funccolnames);
395         COPY_NODE_FIELD(funccoltypes);
396         COPY_NODE_FIELD(funccoltypmods);
397
398         return newnode;
399 }
400
401 /*
402  * _copyValuesScan
403  */
404 static ValuesScan *
405 _copyValuesScan(ValuesScan *from)
406 {
407         ValuesScan *newnode = makeNode(ValuesScan);
408
409         /*
410          * copy node superclass fields
411          */
412         CopyScanFields((Scan *) from, (Scan *) newnode);
413
414         /*
415          * copy remainder of node
416          */
417         COPY_NODE_FIELD(values_lists);
418
419         return newnode;
420 }
421
422 /*
423  * CopyJoinFields
424  *
425  *              This function copies the fields of the Join node.  It is used by
426  *              all the copy functions for classes which inherit from Join.
427  */
428 static void
429 CopyJoinFields(Join *from, Join *newnode)
430 {
431         CopyPlanFields((Plan *) from, (Plan *) newnode);
432
433         COPY_SCALAR_FIELD(jointype);
434         COPY_NODE_FIELD(joinqual);
435 }
436
437
438 /*
439  * _copyJoin
440  */
441 static Join *
442 _copyJoin(Join *from)
443 {
444         Join       *newnode = makeNode(Join);
445
446         /*
447          * copy node superclass fields
448          */
449         CopyJoinFields(from, newnode);
450
451         return newnode;
452 }
453
454
455 /*
456  * _copyNestLoop
457  */
458 static NestLoop *
459 _copyNestLoop(NestLoop *from)
460 {
461         NestLoop   *newnode = makeNode(NestLoop);
462
463         /*
464          * copy node superclass fields
465          */
466         CopyJoinFields((Join *) from, (Join *) newnode);
467
468         return newnode;
469 }
470
471
472 /*
473  * _copyMergeJoin
474  */
475 static MergeJoin *
476 _copyMergeJoin(MergeJoin *from)
477 {
478         MergeJoin  *newnode = makeNode(MergeJoin);
479         int                     numCols;
480
481         /*
482          * copy node superclass fields
483          */
484         CopyJoinFields((Join *) from, (Join *) newnode);
485
486         /*
487          * copy remainder of node
488          */
489         COPY_NODE_FIELD(mergeclauses);
490         numCols = list_length(from->mergeclauses);
491         COPY_POINTER_FIELD(mergeFamilies, numCols * sizeof(Oid));
492         COPY_POINTER_FIELD(mergeStrategies, numCols * sizeof(int));
493         COPY_POINTER_FIELD(mergeNullsFirst, numCols * sizeof(bool));
494
495         return newnode;
496 }
497
498 /*
499  * _copyHashJoin
500  */
501 static HashJoin *
502 _copyHashJoin(HashJoin *from)
503 {
504         HashJoin   *newnode = makeNode(HashJoin);
505
506         /*
507          * copy node superclass fields
508          */
509         CopyJoinFields((Join *) from, (Join *) newnode);
510
511         /*
512          * copy remainder of node
513          */
514         COPY_NODE_FIELD(hashclauses);
515
516         return newnode;
517 }
518
519
520 /*
521  * _copyMaterial
522  */
523 static Material *
524 _copyMaterial(Material *from)
525 {
526         Material   *newnode = makeNode(Material);
527
528         /*
529          * copy node superclass fields
530          */
531         CopyPlanFields((Plan *) from, (Plan *) newnode);
532
533         return newnode;
534 }
535
536
537 /*
538  * _copySort
539  */
540 static Sort *
541 _copySort(Sort *from)
542 {
543         Sort       *newnode = makeNode(Sort);
544
545         /*
546          * copy node superclass fields
547          */
548         CopyPlanFields((Plan *) from, (Plan *) newnode);
549
550         COPY_SCALAR_FIELD(numCols);
551         COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
552         COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
553         COPY_POINTER_FIELD(nullsFirst, from->numCols * sizeof(bool));
554
555         return newnode;
556 }
557
558
559 /*
560  * _copyGroup
561  */
562 static Group *
563 _copyGroup(Group *from)
564 {
565         Group      *newnode = makeNode(Group);
566
567         CopyPlanFields((Plan *) from, (Plan *) newnode);
568
569         COPY_SCALAR_FIELD(numCols);
570         COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
571         COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
572
573         return newnode;
574 }
575
576 /*
577  * _copyAgg
578  */
579 static Agg *
580 _copyAgg(Agg *from)
581 {
582         Agg                *newnode = makeNode(Agg);
583
584         CopyPlanFields((Plan *) from, (Plan *) newnode);
585
586         COPY_SCALAR_FIELD(aggstrategy);
587         COPY_SCALAR_FIELD(numCols);
588         if (from->numCols > 0)
589         {
590                 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
591                 COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
592         }
593         COPY_SCALAR_FIELD(numGroups);
594
595         return newnode;
596 }
597
598 /*
599  * _copyUnique
600  */
601 static Unique *
602 _copyUnique(Unique *from)
603 {
604         Unique     *newnode = makeNode(Unique);
605
606         /*
607          * copy node superclass fields
608          */
609         CopyPlanFields((Plan *) from, (Plan *) newnode);
610
611         /*
612          * copy remainder of node
613          */
614         COPY_SCALAR_FIELD(numCols);
615         COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
616         COPY_POINTER_FIELD(uniqOperators, from->numCols * sizeof(Oid));
617
618         return newnode;
619 }
620
621 /*
622  * _copyHash
623  */
624 static Hash *
625 _copyHash(Hash *from)
626 {
627         Hash       *newnode = makeNode(Hash);
628
629         /*
630          * copy node superclass fields
631          */
632         CopyPlanFields((Plan *) from, (Plan *) newnode);
633
634         /*
635          * copy remainder of node
636          */
637
638         return newnode;
639 }
640
641 /*
642  * _copySetOp
643  */
644 static SetOp *
645 _copySetOp(SetOp *from)
646 {
647         SetOp      *newnode = makeNode(SetOp);
648
649         /*
650          * copy node superclass fields
651          */
652         CopyPlanFields((Plan *) from, (Plan *) newnode);
653
654         /*
655          * copy remainder of node
656          */
657         COPY_SCALAR_FIELD(cmd);
658         COPY_SCALAR_FIELD(numCols);
659         COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
660         COPY_POINTER_FIELD(dupOperators, from->numCols * sizeof(Oid));
661         COPY_SCALAR_FIELD(flagColIdx);
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  * _copyOuterJoinInfo
1448  */
1449 static OuterJoinInfo *
1450 _copyOuterJoinInfo(OuterJoinInfo *from)
1451 {
1452         OuterJoinInfo *newnode = makeNode(OuterJoinInfo);
1453
1454         COPY_BITMAPSET_FIELD(min_lefthand);
1455         COPY_BITMAPSET_FIELD(min_righthand);
1456         COPY_SCALAR_FIELD(is_full_join);
1457         COPY_SCALAR_FIELD(lhs_strict);
1458         COPY_SCALAR_FIELD(delay_upper_joins);
1459
1460         return newnode;
1461 }
1462
1463 /*
1464  * _copyInClauseInfo
1465  */
1466 static InClauseInfo *
1467 _copyInClauseInfo(InClauseInfo *from)
1468 {
1469         InClauseInfo *newnode = makeNode(InClauseInfo);
1470
1471         COPY_BITMAPSET_FIELD(lefthand);
1472         COPY_BITMAPSET_FIELD(righthand);
1473         COPY_NODE_FIELD(sub_targetlist);
1474         COPY_NODE_FIELD(in_operators);
1475
1476         return newnode;
1477 }
1478
1479 /*
1480  * _copyAppendRelInfo
1481  */
1482 static AppendRelInfo *
1483 _copyAppendRelInfo(AppendRelInfo *from)
1484 {
1485         AppendRelInfo *newnode = makeNode(AppendRelInfo);
1486
1487         COPY_SCALAR_FIELD(parent_relid);
1488         COPY_SCALAR_FIELD(child_relid);
1489         COPY_SCALAR_FIELD(parent_reltype);
1490         COPY_SCALAR_FIELD(child_reltype);
1491         COPY_NODE_FIELD(col_mappings);
1492         COPY_NODE_FIELD(translated_vars);
1493         COPY_SCALAR_FIELD(parent_reloid);
1494
1495         return newnode;
1496 }
1497
1498 /* ****************************************************************
1499  *                                      parsenodes.h copy functions
1500  * ****************************************************************
1501  */
1502
1503 static RangeTblEntry *
1504 _copyRangeTblEntry(RangeTblEntry *from)
1505 {
1506         RangeTblEntry *newnode = makeNode(RangeTblEntry);
1507
1508         COPY_SCALAR_FIELD(rtekind);
1509         COPY_SCALAR_FIELD(relid);
1510         COPY_NODE_FIELD(subquery);
1511         COPY_NODE_FIELD(funcexpr);
1512         COPY_NODE_FIELD(funccoltypes);
1513         COPY_NODE_FIELD(funccoltypmods);
1514         COPY_NODE_FIELD(values_lists);
1515         COPY_SCALAR_FIELD(jointype);
1516         COPY_NODE_FIELD(joinaliasvars);
1517         COPY_NODE_FIELD(alias);
1518         COPY_NODE_FIELD(eref);
1519         COPY_SCALAR_FIELD(inh);
1520         COPY_SCALAR_FIELD(inFromCl);
1521         COPY_SCALAR_FIELD(requiredPerms);
1522         COPY_SCALAR_FIELD(checkAsUser);
1523
1524         return newnode;
1525 }
1526
1527 static FkConstraint *
1528 _copyFkConstraint(FkConstraint *from)
1529 {
1530         FkConstraint *newnode = makeNode(FkConstraint);
1531
1532         COPY_STRING_FIELD(constr_name);
1533         COPY_NODE_FIELD(pktable);
1534         COPY_NODE_FIELD(fk_attrs);
1535         COPY_NODE_FIELD(pk_attrs);
1536         COPY_SCALAR_FIELD(fk_matchtype);
1537         COPY_SCALAR_FIELD(fk_upd_action);
1538         COPY_SCALAR_FIELD(fk_del_action);
1539         COPY_SCALAR_FIELD(deferrable);
1540         COPY_SCALAR_FIELD(initdeferred);
1541         COPY_SCALAR_FIELD(skip_validation);
1542
1543         return newnode;
1544 }
1545
1546 static SortClause *
1547 _copySortClause(SortClause *from)
1548 {
1549         SortClause *newnode = makeNode(SortClause);
1550
1551         COPY_SCALAR_FIELD(tleSortGroupRef);
1552         COPY_SCALAR_FIELD(sortop);
1553         COPY_SCALAR_FIELD(nulls_first);
1554
1555         return newnode;
1556 }
1557
1558 static GroupClause *
1559 _copyGroupClause(GroupClause *from)
1560 {
1561         GroupClause *newnode = makeNode(GroupClause);
1562
1563         COPY_SCALAR_FIELD(tleSortGroupRef);
1564         COPY_SCALAR_FIELD(sortop);
1565         COPY_SCALAR_FIELD(nulls_first);
1566
1567         return newnode;
1568 }
1569
1570 static RowMarkClause *
1571 _copyRowMarkClause(RowMarkClause *from)
1572 {
1573         RowMarkClause *newnode = makeNode(RowMarkClause);
1574
1575         COPY_SCALAR_FIELD(rti);
1576         COPY_SCALAR_FIELD(forUpdate);
1577         COPY_SCALAR_FIELD(noWait);
1578
1579         return newnode;
1580 }
1581
1582 static A_Expr *
1583 _copyAExpr(A_Expr *from)
1584 {
1585         A_Expr     *newnode = makeNode(A_Expr);
1586
1587         COPY_SCALAR_FIELD(kind);
1588         COPY_NODE_FIELD(name);
1589         COPY_NODE_FIELD(lexpr);
1590         COPY_NODE_FIELD(rexpr);
1591         COPY_SCALAR_FIELD(location);
1592
1593         return newnode;
1594 }
1595
1596 static ColumnRef *
1597 _copyColumnRef(ColumnRef *from)
1598 {
1599         ColumnRef  *newnode = makeNode(ColumnRef);
1600
1601         COPY_NODE_FIELD(fields);
1602         COPY_SCALAR_FIELD(location);
1603
1604         return newnode;
1605 }
1606
1607 static ParamRef *
1608 _copyParamRef(ParamRef *from)
1609 {
1610         ParamRef   *newnode = makeNode(ParamRef);
1611
1612         COPY_SCALAR_FIELD(number);
1613
1614         return newnode;
1615 }
1616
1617 static A_Const *
1618 _copyAConst(A_Const *from)
1619 {
1620         A_Const    *newnode = makeNode(A_Const);
1621
1622         /* This part must duplicate _copyValue */
1623         COPY_SCALAR_FIELD(val.type);
1624         switch (from->val.type)
1625         {
1626                 case T_Integer:
1627                         COPY_SCALAR_FIELD(val.val.ival);
1628                         break;
1629                 case T_Float:
1630                 case T_String:
1631                 case T_BitString:
1632                         COPY_STRING_FIELD(val.val.str);
1633                         break;
1634                 case T_Null:
1635                         /* nothing to do */
1636                         break;
1637                 default:
1638                         elog(ERROR, "unrecognized node type: %d",
1639                                  (int) from->val.type);
1640                         break;
1641         }
1642
1643         COPY_NODE_FIELD(typename);
1644
1645         return newnode;
1646 }
1647
1648 static FuncCall *
1649 _copyFuncCall(FuncCall *from)
1650 {
1651         FuncCall   *newnode = makeNode(FuncCall);
1652
1653         COPY_NODE_FIELD(funcname);
1654         COPY_NODE_FIELD(args);
1655         COPY_SCALAR_FIELD(agg_star);
1656         COPY_SCALAR_FIELD(agg_distinct);
1657         COPY_SCALAR_FIELD(location);
1658
1659         return newnode;
1660 }
1661
1662 static A_Indices *
1663 _copyAIndices(A_Indices *from)
1664 {
1665         A_Indices  *newnode = makeNode(A_Indices);
1666
1667         COPY_NODE_FIELD(lidx);
1668         COPY_NODE_FIELD(uidx);
1669
1670         return newnode;
1671 }
1672
1673 static A_Indirection *
1674 _copyA_Indirection(A_Indirection *from)
1675 {
1676         A_Indirection *newnode = makeNode(A_Indirection);
1677
1678         COPY_NODE_FIELD(arg);
1679         COPY_NODE_FIELD(indirection);
1680
1681         return newnode;
1682 }
1683
1684 static ResTarget *
1685 _copyResTarget(ResTarget *from)
1686 {
1687         ResTarget  *newnode = makeNode(ResTarget);
1688
1689         COPY_STRING_FIELD(name);
1690         COPY_NODE_FIELD(indirection);
1691         COPY_NODE_FIELD(val);
1692         COPY_SCALAR_FIELD(location);
1693
1694         return newnode;
1695 }
1696
1697 static TypeName *
1698 _copyTypeName(TypeName *from)
1699 {
1700         TypeName   *newnode = makeNode(TypeName);
1701
1702         COPY_NODE_FIELD(names);
1703         COPY_SCALAR_FIELD(typeid);
1704         COPY_SCALAR_FIELD(timezone);
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_NODE_FIELD(rtable);
1858         COPY_NODE_FIELD(jointree);
1859         COPY_NODE_FIELD(targetList);
1860         COPY_NODE_FIELD(returningList);
1861         COPY_NODE_FIELD(groupClause);
1862         COPY_NODE_FIELD(havingQual);
1863         COPY_NODE_FIELD(distinctClause);
1864         COPY_NODE_FIELD(sortClause);
1865         COPY_NODE_FIELD(limitOffset);
1866         COPY_NODE_FIELD(limitCount);
1867         COPY_NODE_FIELD(rowMarks);
1868         COPY_NODE_FIELD(setOperations);
1869
1870         return newnode;
1871 }
1872
1873 static InsertStmt *
1874 _copyInsertStmt(InsertStmt *from)
1875 {
1876         InsertStmt *newnode = makeNode(InsertStmt);
1877
1878         COPY_NODE_FIELD(relation);
1879         COPY_NODE_FIELD(cols);
1880         COPY_NODE_FIELD(selectStmt);
1881         COPY_NODE_FIELD(returningList);
1882
1883         return newnode;
1884 }
1885
1886 static DeleteStmt *
1887 _copyDeleteStmt(DeleteStmt *from)
1888 {
1889         DeleteStmt *newnode = makeNode(DeleteStmt);
1890
1891         COPY_NODE_FIELD(relation);
1892         COPY_NODE_FIELD(usingClause);
1893         COPY_NODE_FIELD(whereClause);
1894         COPY_NODE_FIELD(returningList);
1895
1896         return newnode;
1897 }
1898
1899 static UpdateStmt *
1900 _copyUpdateStmt(UpdateStmt *from)
1901 {
1902         UpdateStmt *newnode = makeNode(UpdateStmt);
1903
1904         COPY_NODE_FIELD(relation);
1905         COPY_NODE_FIELD(targetList);
1906         COPY_NODE_FIELD(whereClause);
1907         COPY_NODE_FIELD(fromClause);
1908         COPY_NODE_FIELD(returningList);
1909
1910         return newnode;
1911 }
1912
1913 static SelectStmt *
1914 _copySelectStmt(SelectStmt *from)
1915 {
1916         SelectStmt *newnode = makeNode(SelectStmt);
1917
1918         COPY_NODE_FIELD(distinctClause);
1919         COPY_NODE_FIELD(intoClause);
1920         COPY_NODE_FIELD(targetList);
1921         COPY_NODE_FIELD(fromClause);
1922         COPY_NODE_FIELD(whereClause);
1923         COPY_NODE_FIELD(groupClause);
1924         COPY_NODE_FIELD(havingClause);
1925         COPY_NODE_FIELD(valuesLists);
1926         COPY_NODE_FIELD(sortClause);
1927         COPY_NODE_FIELD(limitOffset);
1928         COPY_NODE_FIELD(limitCount);
1929         COPY_NODE_FIELD(lockingClause);
1930         COPY_SCALAR_FIELD(op);
1931         COPY_SCALAR_FIELD(all);
1932         COPY_NODE_FIELD(larg);
1933         COPY_NODE_FIELD(rarg);
1934
1935         return newnode;
1936 }
1937
1938 static SetOperationStmt *
1939 _copySetOperationStmt(SetOperationStmt *from)
1940 {
1941         SetOperationStmt *newnode = makeNode(SetOperationStmt);
1942
1943         COPY_SCALAR_FIELD(op);
1944         COPY_SCALAR_FIELD(all);
1945         COPY_NODE_FIELD(larg);
1946         COPY_NODE_FIELD(rarg);
1947         COPY_NODE_FIELD(colTypes);
1948         COPY_NODE_FIELD(colTypmods);
1949
1950         return newnode;
1951 }
1952
1953 static AlterTableStmt *
1954 _copyAlterTableStmt(AlterTableStmt *from)
1955 {
1956         AlterTableStmt *newnode = makeNode(AlterTableStmt);
1957
1958         COPY_NODE_FIELD(relation);
1959         COPY_NODE_FIELD(cmds);
1960         COPY_SCALAR_FIELD(relkind);
1961
1962         return newnode;
1963 }
1964
1965 static AlterTableCmd *
1966 _copyAlterTableCmd(AlterTableCmd *from)
1967 {
1968         AlterTableCmd *newnode = makeNode(AlterTableCmd);
1969
1970         COPY_SCALAR_FIELD(subtype);
1971         COPY_STRING_FIELD(name);
1972         COPY_NODE_FIELD(def);
1973         COPY_NODE_FIELD(transform);
1974         COPY_SCALAR_FIELD(behavior);
1975
1976         return newnode;
1977 }
1978
1979 static AlterDomainStmt *
1980 _copyAlterDomainStmt(AlterDomainStmt *from)
1981 {
1982         AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1983
1984         COPY_SCALAR_FIELD(subtype);
1985         COPY_NODE_FIELD(typename);
1986         COPY_STRING_FIELD(name);
1987         COPY_NODE_FIELD(def);
1988         COPY_SCALAR_FIELD(behavior);
1989
1990         return newnode;
1991 }
1992
1993 static GrantStmt *
1994 _copyGrantStmt(GrantStmt *from)
1995 {
1996         GrantStmt  *newnode = makeNode(GrantStmt);
1997
1998         COPY_SCALAR_FIELD(is_grant);
1999         COPY_SCALAR_FIELD(objtype);
2000         COPY_NODE_FIELD(objects);
2001         COPY_NODE_FIELD(privileges);
2002         COPY_NODE_FIELD(grantees);
2003         COPY_SCALAR_FIELD(grant_option);
2004         COPY_SCALAR_FIELD(behavior);
2005
2006         return newnode;
2007 }
2008
2009 static PrivGrantee *
2010 _copyPrivGrantee(PrivGrantee *from)
2011 {
2012         PrivGrantee *newnode = makeNode(PrivGrantee);
2013
2014         COPY_STRING_FIELD(rolname);
2015
2016         return newnode;
2017 }
2018
2019 static FuncWithArgs *
2020 _copyFuncWithArgs(FuncWithArgs *from)
2021 {
2022         FuncWithArgs *newnode = makeNode(FuncWithArgs);
2023
2024         COPY_NODE_FIELD(funcname);
2025         COPY_NODE_FIELD(funcargs);
2026
2027         return newnode;
2028 }
2029
2030 static GrantRoleStmt *
2031 _copyGrantRoleStmt(GrantRoleStmt *from)
2032 {
2033         GrantRoleStmt *newnode = makeNode(GrantRoleStmt);
2034
2035         COPY_NODE_FIELD(granted_roles);
2036         COPY_NODE_FIELD(grantee_roles);
2037         COPY_SCALAR_FIELD(is_grant);
2038         COPY_SCALAR_FIELD(admin_opt);
2039         COPY_STRING_FIELD(grantor);
2040         COPY_SCALAR_FIELD(behavior);
2041
2042         return newnode;
2043 }
2044
2045 static DeclareCursorStmt *
2046 _copyDeclareCursorStmt(DeclareCursorStmt *from)
2047 {
2048         DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
2049
2050         COPY_STRING_FIELD(portalname);
2051         COPY_SCALAR_FIELD(options);
2052         COPY_NODE_FIELD(query);
2053
2054         return newnode;
2055 }
2056
2057 static ClosePortalStmt *
2058 _copyClosePortalStmt(ClosePortalStmt *from)
2059 {
2060         ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
2061
2062         COPY_STRING_FIELD(portalname);
2063
2064         return newnode;
2065 }
2066
2067 static ClusterStmt *
2068 _copyClusterStmt(ClusterStmt *from)
2069 {
2070         ClusterStmt *newnode = makeNode(ClusterStmt);
2071
2072         COPY_NODE_FIELD(relation);
2073         COPY_STRING_FIELD(indexname);
2074
2075         return newnode;
2076 }
2077
2078 static CopyStmt *
2079 _copyCopyStmt(CopyStmt *from)
2080 {
2081         CopyStmt   *newnode = makeNode(CopyStmt);
2082
2083         COPY_NODE_FIELD(relation);
2084         COPY_NODE_FIELD(query);
2085         COPY_NODE_FIELD(attlist);
2086         COPY_SCALAR_FIELD(is_from);
2087         COPY_STRING_FIELD(filename);
2088         COPY_NODE_FIELD(options);
2089
2090         return newnode;
2091 }
2092
2093 static CreateStmt *
2094 _copyCreateStmt(CreateStmt *from)
2095 {
2096         CreateStmt *newnode = makeNode(CreateStmt);
2097
2098         COPY_NODE_FIELD(relation);
2099         COPY_NODE_FIELD(tableElts);
2100         COPY_NODE_FIELD(inhRelations);
2101         COPY_NODE_FIELD(constraints);
2102         COPY_NODE_FIELD(options);
2103         COPY_SCALAR_FIELD(oncommit);
2104         COPY_STRING_FIELD(tablespacename);
2105
2106         return newnode;
2107 }
2108
2109 static InhRelation *
2110 _copyInhRelation(InhRelation *from)
2111 {
2112         InhRelation *newnode = makeNode(InhRelation);
2113
2114         COPY_NODE_FIELD(relation);
2115         COPY_NODE_FIELD(options);
2116
2117         return newnode;
2118 }
2119
2120 static DefineStmt *
2121 _copyDefineStmt(DefineStmt *from)
2122 {
2123         DefineStmt *newnode = makeNode(DefineStmt);
2124
2125         COPY_SCALAR_FIELD(kind);
2126         COPY_SCALAR_FIELD(oldstyle);
2127         COPY_NODE_FIELD(defnames);
2128         COPY_NODE_FIELD(args);
2129         COPY_NODE_FIELD(definition);
2130
2131         return newnode;
2132 }
2133
2134 static DropStmt *
2135 _copyDropStmt(DropStmt *from)
2136 {
2137         DropStmt   *newnode = makeNode(DropStmt);
2138
2139         COPY_NODE_FIELD(objects);
2140         COPY_SCALAR_FIELD(removeType);
2141         COPY_SCALAR_FIELD(behavior);
2142         COPY_SCALAR_FIELD(missing_ok);
2143
2144         return newnode;
2145 }
2146
2147 static TruncateStmt *
2148 _copyTruncateStmt(TruncateStmt *from)
2149 {
2150         TruncateStmt *newnode = makeNode(TruncateStmt);
2151
2152         COPY_NODE_FIELD(relations);
2153         COPY_SCALAR_FIELD(behavior);
2154
2155         return newnode;
2156 }
2157
2158 static CommentStmt *
2159 _copyCommentStmt(CommentStmt *from)
2160 {
2161         CommentStmt *newnode = makeNode(CommentStmt);
2162
2163         COPY_SCALAR_FIELD(objtype);
2164         COPY_NODE_FIELD(objname);
2165         COPY_NODE_FIELD(objargs);
2166         COPY_STRING_FIELD(comment);
2167
2168         return newnode;
2169 }
2170
2171 static FetchStmt *
2172 _copyFetchStmt(FetchStmt *from)
2173 {
2174         FetchStmt  *newnode = makeNode(FetchStmt);
2175
2176         COPY_SCALAR_FIELD(direction);
2177         COPY_SCALAR_FIELD(howMany);
2178         COPY_STRING_FIELD(portalname);
2179         COPY_SCALAR_FIELD(ismove);
2180
2181         return newnode;
2182 }
2183
2184 static IndexStmt *
2185 _copyIndexStmt(IndexStmt *from)
2186 {
2187         IndexStmt  *newnode = makeNode(IndexStmt);
2188
2189         COPY_STRING_FIELD(idxname);
2190         COPY_NODE_FIELD(relation);
2191         COPY_STRING_FIELD(accessMethod);
2192         COPY_STRING_FIELD(tableSpace);
2193         COPY_NODE_FIELD(indexParams);
2194         COPY_NODE_FIELD(options);
2195         COPY_NODE_FIELD(whereClause);
2196         COPY_SCALAR_FIELD(unique);
2197         COPY_SCALAR_FIELD(primary);
2198         COPY_SCALAR_FIELD(isconstraint);
2199         COPY_SCALAR_FIELD(concurrent);
2200
2201         return newnode;
2202 }
2203
2204 static CreateFunctionStmt *
2205 _copyCreateFunctionStmt(CreateFunctionStmt *from)
2206 {
2207         CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
2208
2209         COPY_SCALAR_FIELD(replace);
2210         COPY_NODE_FIELD(funcname);
2211         COPY_NODE_FIELD(parameters);
2212         COPY_NODE_FIELD(returnType);
2213         COPY_NODE_FIELD(options);
2214         COPY_NODE_FIELD(withClause);
2215
2216         return newnode;
2217 }
2218
2219 static FunctionParameter *
2220 _copyFunctionParameter(FunctionParameter *from)
2221 {
2222         FunctionParameter *newnode = makeNode(FunctionParameter);
2223
2224         COPY_STRING_FIELD(name);
2225         COPY_NODE_FIELD(argType);
2226         COPY_SCALAR_FIELD(mode);
2227
2228         return newnode;
2229 }
2230
2231 static AlterFunctionStmt *
2232 _copyAlterFunctionStmt(AlterFunctionStmt *from)
2233 {
2234         AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);
2235
2236         COPY_NODE_FIELD(func);
2237         COPY_NODE_FIELD(actions);
2238
2239         return newnode;
2240 }
2241
2242 static RemoveFuncStmt *
2243 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2244 {
2245         RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2246
2247         COPY_SCALAR_FIELD(kind);
2248         COPY_NODE_FIELD(name);
2249         COPY_NODE_FIELD(args);
2250         COPY_SCALAR_FIELD(behavior);
2251         COPY_SCALAR_FIELD(missing_ok);
2252
2253         return newnode;
2254 }
2255
2256 static RemoveOpClassStmt *
2257 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
2258 {
2259         RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
2260
2261         COPY_NODE_FIELD(opclassname);
2262         COPY_STRING_FIELD(amname);
2263         COPY_SCALAR_FIELD(behavior);
2264         COPY_SCALAR_FIELD(missing_ok);
2265
2266         return newnode;
2267 }
2268
2269 static RemoveOpFamilyStmt *
2270 _copyRemoveOpFamilyStmt(RemoveOpFamilyStmt *from)
2271 {
2272         RemoveOpFamilyStmt *newnode = makeNode(RemoveOpFamilyStmt);
2273
2274         COPY_NODE_FIELD(opfamilyname);
2275         COPY_STRING_FIELD(amname);
2276         COPY_SCALAR_FIELD(behavior);
2277         COPY_SCALAR_FIELD(missing_ok);
2278
2279         return newnode;
2280 }
2281
2282 static RenameStmt *
2283 _copyRenameStmt(RenameStmt *from)
2284 {
2285         RenameStmt *newnode = makeNode(RenameStmt);
2286
2287         COPY_SCALAR_FIELD(renameType);
2288         COPY_NODE_FIELD(relation);
2289         COPY_NODE_FIELD(object);
2290         COPY_NODE_FIELD(objarg);
2291         COPY_STRING_FIELD(subname);
2292         COPY_STRING_FIELD(newname);
2293
2294         return newnode;
2295 }
2296
2297 static AlterObjectSchemaStmt *
2298 _copyAlterObjectSchemaStmt(AlterObjectSchemaStmt *from)
2299 {
2300         AlterObjectSchemaStmt *newnode = makeNode(AlterObjectSchemaStmt);
2301
2302         COPY_SCALAR_FIELD(objectType);
2303         COPY_NODE_FIELD(relation);
2304         COPY_NODE_FIELD(object);
2305         COPY_NODE_FIELD(objarg);
2306         COPY_STRING_FIELD(addname);
2307         COPY_STRING_FIELD(newschema);
2308
2309         return newnode;
2310 }
2311
2312 static AlterOwnerStmt *
2313 _copyAlterOwnerStmt(AlterOwnerStmt *from)
2314 {
2315         AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);
2316
2317         COPY_SCALAR_FIELD(objectType);
2318         COPY_NODE_FIELD(relation);
2319         COPY_NODE_FIELD(object);
2320         COPY_NODE_FIELD(objarg);
2321         COPY_STRING_FIELD(addname);
2322         COPY_STRING_FIELD(newowner);
2323
2324         return newnode;
2325 }
2326
2327 static RuleStmt *
2328 _copyRuleStmt(RuleStmt *from)
2329 {
2330         RuleStmt   *newnode = makeNode(RuleStmt);
2331
2332         COPY_NODE_FIELD(relation);
2333         COPY_STRING_FIELD(rulename);
2334         COPY_NODE_FIELD(whereClause);
2335         COPY_SCALAR_FIELD(event);
2336         COPY_SCALAR_FIELD(instead);
2337         COPY_NODE_FIELD(actions);
2338         COPY_SCALAR_FIELD(replace);
2339
2340         return newnode;
2341 }
2342
2343 static NotifyStmt *
2344 _copyNotifyStmt(NotifyStmt *from)
2345 {
2346         NotifyStmt *newnode = makeNode(NotifyStmt);
2347
2348         COPY_NODE_FIELD(relation);
2349
2350         return newnode;
2351 }
2352
2353 static ListenStmt *
2354 _copyListenStmt(ListenStmt *from)
2355 {
2356         ListenStmt *newnode = makeNode(ListenStmt);
2357
2358         COPY_NODE_FIELD(relation);
2359
2360         return newnode;
2361 }
2362
2363 static UnlistenStmt *
2364 _copyUnlistenStmt(UnlistenStmt *from)
2365 {
2366         UnlistenStmt *newnode = makeNode(UnlistenStmt);
2367
2368         COPY_NODE_FIELD(relation);
2369
2370         return newnode;
2371 }
2372
2373 static TransactionStmt *
2374 _copyTransactionStmt(TransactionStmt *from)
2375 {
2376         TransactionStmt *newnode = makeNode(TransactionStmt);
2377
2378         COPY_SCALAR_FIELD(kind);
2379         COPY_NODE_FIELD(options);
2380         COPY_STRING_FIELD(gid);
2381
2382         return newnode;
2383 }
2384
2385 static CompositeTypeStmt *
2386 _copyCompositeTypeStmt(CompositeTypeStmt *from)
2387 {
2388         CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
2389
2390         COPY_NODE_FIELD(typevar);
2391         COPY_NODE_FIELD(coldeflist);
2392
2393         return newnode;
2394 }
2395
2396 static CreateEnumStmt *
2397 _copyCreateEnumStmt(CreateEnumStmt *from)
2398 {
2399         CreateEnumStmt *newnode = makeNode(CreateEnumStmt);
2400
2401         COPY_NODE_FIELD(typename);
2402         COPY_NODE_FIELD(vals);
2403
2404         return newnode;
2405 }
2406
2407 static ViewStmt *
2408 _copyViewStmt(ViewStmt *from)
2409 {
2410         ViewStmt   *newnode = makeNode(ViewStmt);
2411
2412         COPY_NODE_FIELD(view);
2413         COPY_NODE_FIELD(aliases);
2414         COPY_NODE_FIELD(query);
2415         COPY_SCALAR_FIELD(replace);
2416
2417         return newnode;
2418 }
2419
2420 static LoadStmt *
2421 _copyLoadStmt(LoadStmt *from)
2422 {
2423         LoadStmt   *newnode = makeNode(LoadStmt);
2424
2425         COPY_STRING_FIELD(filename);
2426
2427         return newnode;
2428 }
2429
2430 static CreateDomainStmt *
2431 _copyCreateDomainStmt(CreateDomainStmt *from)
2432 {
2433         CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2434
2435         COPY_NODE_FIELD(domainname);
2436         COPY_NODE_FIELD(typename);
2437         COPY_NODE_FIELD(constraints);
2438
2439         return newnode;
2440 }
2441
2442 static CreateOpClassStmt *
2443 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2444 {
2445         CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2446
2447         COPY_NODE_FIELD(opclassname);
2448         COPY_NODE_FIELD(opfamilyname);
2449         COPY_STRING_FIELD(amname);
2450         COPY_NODE_FIELD(datatype);
2451         COPY_NODE_FIELD(items);
2452         COPY_SCALAR_FIELD(isDefault);
2453
2454         return newnode;
2455 }
2456
2457 static CreateOpClassItem *
2458 _copyCreateOpClassItem(CreateOpClassItem *from)
2459 {
2460         CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2461
2462         COPY_SCALAR_FIELD(itemtype);
2463         COPY_NODE_FIELD(name);
2464         COPY_NODE_FIELD(args);
2465         COPY_SCALAR_FIELD(number);
2466         COPY_SCALAR_FIELD(recheck);
2467         COPY_NODE_FIELD(class_args);
2468         COPY_NODE_FIELD(storedtype);
2469
2470         return newnode;
2471 }
2472
2473 static CreateOpFamilyStmt *
2474 _copyCreateOpFamilyStmt(CreateOpFamilyStmt *from)
2475 {
2476         CreateOpFamilyStmt *newnode = makeNode(CreateOpFamilyStmt);
2477
2478         COPY_NODE_FIELD(opfamilyname);
2479         COPY_STRING_FIELD(amname);
2480
2481         return newnode;
2482 }
2483
2484 static AlterOpFamilyStmt *
2485 _copyAlterOpFamilyStmt(AlterOpFamilyStmt *from)
2486 {
2487         AlterOpFamilyStmt *newnode = makeNode(AlterOpFamilyStmt);
2488
2489         COPY_NODE_FIELD(opfamilyname);
2490         COPY_STRING_FIELD(amname);
2491         COPY_SCALAR_FIELD(isDrop);
2492         COPY_NODE_FIELD(items);
2493
2494         return newnode;
2495 }
2496
2497 static CreatedbStmt *
2498 _copyCreatedbStmt(CreatedbStmt *from)
2499 {
2500         CreatedbStmt *newnode = makeNode(CreatedbStmt);
2501
2502         COPY_STRING_FIELD(dbname);
2503         COPY_NODE_FIELD(options);
2504
2505         return newnode;
2506 }
2507
2508 static AlterDatabaseStmt *
2509 _copyAlterDatabaseStmt(AlterDatabaseStmt *from)
2510 {
2511         AlterDatabaseStmt *newnode = makeNode(AlterDatabaseStmt);
2512
2513         COPY_STRING_FIELD(dbname);
2514         COPY_NODE_FIELD(options);
2515
2516         return newnode;
2517 }
2518
2519 static AlterDatabaseSetStmt *
2520 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2521 {
2522         AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2523
2524         COPY_STRING_FIELD(dbname);
2525         COPY_STRING_FIELD(variable);
2526         COPY_NODE_FIELD(value);
2527
2528         return newnode;
2529 }
2530
2531 static DropdbStmt *
2532 _copyDropdbStmt(DropdbStmt *from)
2533 {
2534         DropdbStmt *newnode = makeNode(DropdbStmt);
2535
2536         COPY_STRING_FIELD(dbname);
2537         COPY_SCALAR_FIELD(missing_ok);
2538
2539         return newnode;
2540 }
2541
2542 static VacuumStmt *
2543 _copyVacuumStmt(VacuumStmt *from)
2544 {
2545         VacuumStmt *newnode = makeNode(VacuumStmt);
2546
2547         COPY_SCALAR_FIELD(vacuum);
2548         COPY_SCALAR_FIELD(full);
2549         COPY_SCALAR_FIELD(analyze);
2550         COPY_SCALAR_FIELD(verbose);
2551         COPY_SCALAR_FIELD(freeze_min_age);
2552         COPY_NODE_FIELD(relation);
2553         COPY_NODE_FIELD(va_cols);
2554
2555         return newnode;
2556 }
2557
2558 static ExplainStmt *
2559 _copyExplainStmt(ExplainStmt *from)
2560 {
2561         ExplainStmt *newnode = makeNode(ExplainStmt);
2562
2563         COPY_NODE_FIELD(query);
2564         COPY_SCALAR_FIELD(verbose);
2565         COPY_SCALAR_FIELD(analyze);
2566
2567         return newnode;
2568 }
2569
2570 static CreateSeqStmt *
2571 _copyCreateSeqStmt(CreateSeqStmt *from)
2572 {
2573         CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2574
2575         COPY_NODE_FIELD(sequence);
2576         COPY_NODE_FIELD(options);
2577
2578         return newnode;
2579 }
2580
2581 static AlterSeqStmt *
2582 _copyAlterSeqStmt(AlterSeqStmt *from)
2583 {
2584         AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
2585
2586         COPY_NODE_FIELD(sequence);
2587         COPY_NODE_FIELD(options);
2588
2589         return newnode;
2590 }
2591
2592 static VariableSetStmt *
2593 _copyVariableSetStmt(VariableSetStmt *from)
2594 {
2595         VariableSetStmt *newnode = makeNode(VariableSetStmt);
2596
2597         COPY_STRING_FIELD(name);
2598         COPY_NODE_FIELD(args);
2599         COPY_SCALAR_FIELD(is_local);
2600
2601         return newnode;
2602 }
2603
2604 static VariableShowStmt *
2605 _copyVariableShowStmt(VariableShowStmt *from)
2606 {
2607         VariableShowStmt *newnode = makeNode(VariableShowStmt);
2608
2609         COPY_STRING_FIELD(name);
2610
2611         return newnode;
2612 }
2613
2614 static VariableResetStmt *
2615 _copyVariableResetStmt(VariableResetStmt *from)
2616 {
2617         VariableResetStmt *newnode = makeNode(VariableResetStmt);
2618
2619         COPY_STRING_FIELD(name);
2620
2621         return newnode;
2622 }
2623
2624 static DiscardStmt *
2625 _copyDiscardStmt(DiscardStmt *from)
2626 {
2627         DiscardStmt *newnode = makeNode(DiscardStmt);
2628
2629         COPY_SCALAR_FIELD(target);
2630
2631         return newnode;
2632 }
2633
2634 static CreateTableSpaceStmt *
2635 _copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
2636 {
2637         CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
2638
2639         COPY_STRING_FIELD(tablespacename);
2640         COPY_STRING_FIELD(owner);
2641         COPY_STRING_FIELD(location);
2642
2643         return newnode;
2644 }
2645
2646 static DropTableSpaceStmt *
2647 _copyDropTableSpaceStmt(DropTableSpaceStmt *from)
2648 {
2649         DropTableSpaceStmt *newnode = makeNode(DropTableSpaceStmt);
2650
2651         COPY_STRING_FIELD(tablespacename);
2652         COPY_SCALAR_FIELD(missing_ok);
2653
2654         return newnode;
2655 }
2656
2657 static CreateTrigStmt *
2658 _copyCreateTrigStmt(CreateTrigStmt *from)
2659 {
2660         CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2661
2662         COPY_STRING_FIELD(trigname);
2663         COPY_NODE_FIELD(relation);
2664         COPY_NODE_FIELD(funcname);
2665         COPY_NODE_FIELD(args);
2666         COPY_SCALAR_FIELD(before);
2667         COPY_SCALAR_FIELD(row);
2668         strcpy(newnode->actions, from->actions);        /* in-line string field */
2669         COPY_SCALAR_FIELD(isconstraint);
2670         COPY_SCALAR_FIELD(deferrable);
2671         COPY_SCALAR_FIELD(initdeferred);
2672         COPY_NODE_FIELD(constrrel);
2673
2674         return newnode;
2675 }
2676
2677 static DropPropertyStmt *
2678 _copyDropPropertyStmt(DropPropertyStmt *from)
2679 {
2680         DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2681
2682         COPY_NODE_FIELD(relation);
2683         COPY_STRING_FIELD(property);
2684         COPY_SCALAR_FIELD(removeType);
2685         COPY_SCALAR_FIELD(behavior);
2686         COPY_SCALAR_FIELD(missing_ok);
2687
2688         return newnode;
2689 }
2690
2691 static CreatePLangStmt *
2692 _copyCreatePLangStmt(CreatePLangStmt *from)
2693 {
2694         CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2695
2696         COPY_STRING_FIELD(plname);
2697         COPY_NODE_FIELD(plhandler);
2698         COPY_NODE_FIELD(plvalidator);
2699         COPY_SCALAR_FIELD(pltrusted);
2700
2701         return newnode;
2702 }
2703
2704 static DropPLangStmt *
2705 _copyDropPLangStmt(DropPLangStmt *from)
2706 {
2707         DropPLangStmt *newnode = makeNode(DropPLangStmt);
2708
2709         COPY_STRING_FIELD(plname);
2710         COPY_SCALAR_FIELD(behavior);
2711         COPY_SCALAR_FIELD(missing_ok);
2712
2713         return newnode;
2714 }
2715
2716 static CreateRoleStmt *
2717 _copyCreateRoleStmt(CreateRoleStmt *from)
2718 {
2719         CreateRoleStmt *newnode = makeNode(CreateRoleStmt);
2720
2721         COPY_SCALAR_FIELD(stmt_type);
2722         COPY_STRING_FIELD(role);
2723         COPY_NODE_FIELD(options);
2724
2725         return newnode;
2726 }
2727
2728 static AlterRoleStmt *
2729 _copyAlterRoleStmt(AlterRoleStmt *from)
2730 {
2731         AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
2732
2733         COPY_STRING_FIELD(role);
2734         COPY_NODE_FIELD(options);
2735         COPY_SCALAR_FIELD(action);
2736
2737         return newnode;
2738 }
2739
2740 static AlterRoleSetStmt *
2741 _copyAlterRoleSetStmt(AlterRoleSetStmt *from)
2742 {
2743         AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
2744
2745         COPY_STRING_FIELD(role);
2746         COPY_STRING_FIELD(variable);
2747         COPY_NODE_FIELD(value);
2748
2749         return newnode;
2750 }
2751
2752 static DropRoleStmt *
2753 _copyDropRoleStmt(DropRoleStmt *from)
2754 {
2755         DropRoleStmt *newnode = makeNode(DropRoleStmt);
2756
2757         COPY_NODE_FIELD(roles);
2758         COPY_SCALAR_FIELD(missing_ok);
2759
2760         return newnode;
2761 }
2762
2763 static LockStmt *
2764 _copyLockStmt(LockStmt *from)
2765 {
2766         LockStmt   *newnode = makeNode(LockStmt);
2767
2768         COPY_NODE_FIELD(relations);
2769         COPY_SCALAR_FIELD(mode);
2770         COPY_SCALAR_FIELD(nowait);
2771
2772         return newnode;
2773 }
2774
2775 static ConstraintsSetStmt *
2776 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2777 {
2778         ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2779
2780         COPY_NODE_FIELD(constraints);
2781         COPY_SCALAR_FIELD(deferred);
2782
2783         return newnode;
2784 }
2785
2786 static ReindexStmt *
2787 _copyReindexStmt(ReindexStmt *from)
2788 {
2789         ReindexStmt *newnode = makeNode(ReindexStmt);
2790
2791         COPY_SCALAR_FIELD(kind);
2792         COPY_NODE_FIELD(relation);
2793         COPY_STRING_FIELD(name);
2794         COPY_SCALAR_FIELD(do_system);
2795         COPY_SCALAR_FIELD(do_user);
2796
2797         return newnode;
2798 }
2799
2800 static CreateSchemaStmt *
2801 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2802 {
2803         CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2804
2805         COPY_STRING_FIELD(schemaname);
2806         COPY_STRING_FIELD(authid);
2807         COPY_NODE_FIELD(schemaElts);
2808
2809         return newnode;
2810 }
2811
2812 static CreateConversionStmt *
2813 _copyCreateConversionStmt(CreateConversionStmt *from)
2814 {
2815         CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2816
2817         COPY_NODE_FIELD(conversion_name);
2818         COPY_STRING_FIELD(for_encoding_name);
2819         COPY_STRING_FIELD(to_encoding_name);
2820         COPY_NODE_FIELD(func_name);
2821         COPY_SCALAR_FIELD(def);
2822
2823         return newnode;
2824 }
2825
2826 static CreateCastStmt *
2827 _copyCreateCastStmt(CreateCastStmt *from)
2828 {
2829         CreateCastStmt *newnode = makeNode(CreateCastStmt);
2830
2831         COPY_NODE_FIELD(sourcetype);
2832         COPY_NODE_FIELD(targettype);
2833         COPY_NODE_FIELD(func);
2834         COPY_SCALAR_FIELD(context);
2835
2836         return newnode;
2837 }
2838
2839 static DropCastStmt *
2840 _copyDropCastStmt(DropCastStmt *from)
2841 {
2842         DropCastStmt *newnode = makeNode(DropCastStmt);
2843
2844         COPY_NODE_FIELD(sourcetype);
2845         COPY_NODE_FIELD(targettype);
2846         COPY_SCALAR_FIELD(behavior);
2847         COPY_SCALAR_FIELD(missing_ok);
2848
2849         return newnode;
2850 }
2851
2852 static PrepareStmt *
2853 _copyPrepareStmt(PrepareStmt *from)
2854 {
2855         PrepareStmt *newnode = makeNode(PrepareStmt);
2856
2857         COPY_STRING_FIELD(name);
2858         COPY_NODE_FIELD(argtypes);
2859         COPY_NODE_FIELD(query);
2860
2861         return newnode;
2862 }
2863
2864 static ExecuteStmt *
2865 _copyExecuteStmt(ExecuteStmt *from)
2866 {
2867         ExecuteStmt *newnode = makeNode(ExecuteStmt);
2868
2869         COPY_STRING_FIELD(name);
2870         COPY_NODE_FIELD(into);
2871         COPY_NODE_FIELD(params);
2872
2873         return newnode;
2874 }
2875
2876 static DeallocateStmt *
2877 _copyDeallocateStmt(DeallocateStmt *from)
2878 {
2879         DeallocateStmt *newnode = makeNode(DeallocateStmt);
2880
2881         COPY_STRING_FIELD(name);
2882
2883         return newnode;
2884 }
2885
2886 static DropOwnedStmt *
2887 _copyDropOwnedStmt(DropOwnedStmt *from)
2888 {
2889         DropOwnedStmt *newnode = makeNode(DropOwnedStmt);
2890
2891         COPY_NODE_FIELD(roles);
2892         COPY_SCALAR_FIELD(behavior);
2893
2894         return newnode;
2895 }
2896
2897 static ReassignOwnedStmt *
2898 _copyReassignOwnedStmt(ReassignOwnedStmt *from)
2899 {
2900         ReassignOwnedStmt *newnode = makeNode(ReassignOwnedStmt);
2901
2902         COPY_NODE_FIELD(roles);
2903         COPY_SCALAR_FIELD(newrole);
2904
2905         return newnode;
2906 }
2907
2908 /* ****************************************************************
2909  *                                      pg_list.h copy functions
2910  * ****************************************************************
2911  */
2912
2913 /*
2914  * Perform a deep copy of the specified list, using copyObject(). The
2915  * list MUST be of type T_List; T_IntList and T_OidList nodes don't
2916  * need deep copies, so they should be copied via list_copy()
2917  */
2918 #define COPY_NODE_CELL(new, old)                                        \
2919         (new) = (ListCell *) palloc(sizeof(ListCell));  \
2920         lfirst(new) = copyObject(lfirst(old));
2921
2922 static List *
2923 _copyList(List *from)
2924 {
2925         List       *new;
2926         ListCell   *curr_old;
2927         ListCell   *prev_new;
2928
2929         Assert(list_length(from) >= 1);
2930
2931         new = makeNode(List);
2932         new->length = from->length;
2933
2934         COPY_NODE_CELL(new->head, from->head);
2935         prev_new = new->head;
2936         curr_old = lnext(from->head);
2937
2938         while (curr_old)
2939         {
2940                 COPY_NODE_CELL(prev_new->next, curr_old);
2941                 prev_new = prev_new->next;
2942                 curr_old = curr_old->next;
2943         }
2944         prev_new->next = NULL;
2945         new->tail = prev_new;
2946
2947         return new;
2948 }
2949
2950 /* ****************************************************************
2951  *                                      value.h copy functions
2952  * ****************************************************************
2953  */
2954 static Value *
2955 _copyValue(Value *from)
2956 {
2957         Value      *newnode = makeNode(Value);
2958
2959         /* See also _copyAConst when changing this code! */
2960
2961         COPY_SCALAR_FIELD(type);
2962         switch (from->type)
2963         {
2964                 case T_Integer:
2965                         COPY_SCALAR_FIELD(val.ival);
2966                         break;
2967                 case T_Float:
2968                 case T_String:
2969                 case T_BitString:
2970                         COPY_STRING_FIELD(val.str);
2971                         break;
2972                 case T_Null:
2973                         /* nothing to do */
2974                         break;
2975                 default:
2976                         elog(ERROR, "unrecognized node type: %d",
2977                                  (int) from->type);
2978                         break;
2979         }
2980         return newnode;
2981 }
2982
2983 /*
2984  * copyObject
2985  *
2986  * Create a copy of a Node tree or list.  This is a "deep" copy: all
2987  * substructure is copied too, recursively.
2988  */
2989 void *
2990 copyObject(void *from)
2991 {
2992         void       *retval;
2993
2994         if (from == NULL)
2995                 return NULL;
2996
2997         switch (nodeTag(from))
2998         {
2999                         /*
3000                          * PLAN NODES
3001                          */
3002                 case T_PlannedStmt:
3003                         retval = _copyPlannedStmt(from);
3004                         break;
3005                 case T_Plan:
3006                         retval = _copyPlan(from);
3007                         break;
3008                 case T_Result:
3009                         retval = _copyResult(from);
3010                         break;
3011                 case T_Append:
3012                         retval = _copyAppend(from);
3013                         break;
3014                 case T_BitmapAnd:
3015                         retval = _copyBitmapAnd(from);
3016                         break;
3017                 case T_BitmapOr:
3018                         retval = _copyBitmapOr(from);
3019                         break;
3020                 case T_Scan:
3021                         retval = _copyScan(from);
3022                         break;
3023                 case T_SeqScan:
3024                         retval = _copySeqScan(from);
3025                         break;
3026                 case T_IndexScan:
3027                         retval = _copyIndexScan(from);
3028                         break;
3029                 case T_BitmapIndexScan:
3030                         retval = _copyBitmapIndexScan(from);
3031                         break;
3032                 case T_BitmapHeapScan:
3033                         retval = _copyBitmapHeapScan(from);
3034                         break;
3035                 case T_TidScan:
3036                         retval = _copyTidScan(from);
3037                         break;
3038                 case T_SubqueryScan:
3039                         retval = _copySubqueryScan(from);
3040                         break;
3041                 case T_FunctionScan:
3042                         retval = _copyFunctionScan(from);
3043                         break;
3044                 case T_ValuesScan:
3045                         retval = _copyValuesScan(from);
3046                         break;
3047                 case T_Join:
3048                         retval = _copyJoin(from);
3049                         break;
3050                 case T_NestLoop:
3051                         retval = _copyNestLoop(from);
3052                         break;
3053                 case T_MergeJoin:
3054                         retval = _copyMergeJoin(from);
3055                         break;
3056                 case T_HashJoin:
3057                         retval = _copyHashJoin(from);
3058                         break;
3059                 case T_Material:
3060                         retval = _copyMaterial(from);
3061                         break;
3062                 case T_Sort:
3063                         retval = _copySort(from);
3064                         break;
3065                 case T_Group:
3066                         retval = _copyGroup(from);
3067                         break;
3068                 case T_Agg:
3069                         retval = _copyAgg(from);
3070                         break;
3071                 case T_Unique:
3072                         retval = _copyUnique(from);
3073                         break;
3074                 case T_Hash:
3075                         retval = _copyHash(from);
3076                         break;
3077                 case T_SetOp:
3078                         retval = _copySetOp(from);
3079                         break;
3080                 case T_Limit:
3081                         retval = _copyLimit(from);
3082                         break;
3083
3084                         /*
3085                          * PRIMITIVE NODES
3086                          */
3087                 case T_Alias:
3088                         retval = _copyAlias(from);
3089                         break;
3090                 case T_RangeVar:
3091                         retval = _copyRangeVar(from);
3092                         break;
3093                 case T_IntoClause:
3094                         retval = _copyIntoClause(from);
3095                         break;
3096                 case T_Var:
3097                         retval = _copyVar(from);
3098                         break;
3099                 case T_Const:
3100                         retval = _copyConst(from);
3101                         break;
3102                 case T_Param:
3103                         retval = _copyParam(from);
3104                         break;
3105                 case T_Aggref:
3106                         retval = _copyAggref(from);
3107                         break;
3108                 case T_ArrayRef:
3109                         retval = _copyArrayRef(from);
3110                         break;
3111                 case T_FuncExpr:
3112                         retval = _copyFuncExpr(from);
3113                         break;
3114                 case T_OpExpr:
3115                         retval = _copyOpExpr(from);
3116                         break;
3117                 case T_DistinctExpr:
3118                         retval = _copyDistinctExpr(from);
3119                         break;
3120                 case T_ScalarArrayOpExpr:
3121                         retval = _copyScalarArrayOpExpr(from);
3122                         break;
3123                 case T_BoolExpr:
3124                         retval = _copyBoolExpr(from);
3125                         break;
3126                 case T_SubLink:
3127                         retval = _copySubLink(from);
3128                         break;
3129                 case T_SubPlan:
3130                         retval = _copySubPlan(from);
3131                         break;
3132                 case T_FieldSelect:
3133                         retval = _copyFieldSelect(from);
3134                         break;
3135                 case T_FieldStore:
3136                         retval = _copyFieldStore(from);
3137                         break;
3138                 case T_RelabelType:
3139                         retval = _copyRelabelType(from);
3140                         break;
3141                 case T_CoerceViaIO:
3142                         retval = _copyCoerceViaIO(from);
3143                         break;
3144                 case T_ArrayCoerceExpr:
3145                         retval = _copyArrayCoerceExpr(from);
3146                         break;
3147                 case T_ConvertRowtypeExpr:
3148                         retval = _copyConvertRowtypeExpr(from);
3149                         break;
3150                 case T_CaseExpr:
3151                         retval = _copyCaseExpr(from);
3152                         break;
3153                 case T_CaseWhen:
3154                         retval = _copyCaseWhen(from);
3155                         break;
3156                 case T_CaseTestExpr:
3157                         retval = _copyCaseTestExpr(from);
3158                         break;
3159                 case T_ArrayExpr:
3160                         retval = _copyArrayExpr(from);
3161                         break;
3162                 case T_RowExpr:
3163                         retval = _copyRowExpr(from);
3164                         break;
3165                 case T_RowCompareExpr:
3166                         retval = _copyRowCompareExpr(from);
3167                         break;
3168                 case T_CoalesceExpr:
3169                         retval = _copyCoalesceExpr(from);
3170                         break;
3171                 case T_MinMaxExpr:
3172                         retval = _copyMinMaxExpr(from);
3173                         break;
3174                 case T_XmlExpr:
3175                         retval = _copyXmlExpr(from);
3176                         break;
3177                 case T_NullIfExpr:
3178                         retval = _copyNullIfExpr(from);
3179                         break;
3180                 case T_NullTest:
3181                         retval = _copyNullTest(from);
3182                         break;
3183                 case T_BooleanTest:
3184                         retval = _copyBooleanTest(from);
3185                         break;
3186                 case T_CoerceToDomain:
3187                         retval = _copyCoerceToDomain(from);
3188                         break;
3189                 case T_CoerceToDomainValue:
3190                         retval = _copyCoerceToDomainValue(from);
3191                         break;
3192                 case T_SetToDefault:
3193                         retval = _copySetToDefault(from);
3194                         break;
3195                 case T_CurrentOfExpr:
3196                         retval = _copyCurrentOfExpr(from);
3197                         break;
3198                 case T_TargetEntry:
3199                         retval = _copyTargetEntry(from);
3200                         break;
3201                 case T_RangeTblRef:
3202                         retval = _copyRangeTblRef(from);
3203                         break;
3204                 case T_JoinExpr:
3205                         retval = _copyJoinExpr(from);
3206                         break;
3207                 case T_FromExpr:
3208                         retval = _copyFromExpr(from);
3209                         break;
3210
3211                         /*
3212                          * RELATION NODES
3213                          */
3214                 case T_PathKey:
3215                         retval = _copyPathKey(from);
3216                         break;
3217                 case T_RestrictInfo:
3218                         retval = _copyRestrictInfo(from);
3219                         break;
3220                 case T_OuterJoinInfo:
3221                         retval = _copyOuterJoinInfo(from);
3222                         break;
3223                 case T_InClauseInfo:
3224                         retval = _copyInClauseInfo(from);
3225                         break;
3226                 case T_AppendRelInfo:
3227                         retval = _copyAppendRelInfo(from);
3228                         break;
3229
3230                         /*
3231                          * VALUE NODES
3232                          */
3233                 case T_Integer:
3234                 case T_Float:
3235                 case T_String:
3236                 case T_BitString:
3237                 case T_Null:
3238                         retval = _copyValue(from);
3239                         break;
3240
3241                         /*
3242                          * LIST NODES
3243                          */
3244                 case T_List:
3245                         retval = _copyList(from);
3246                         break;
3247
3248                         /*
3249                          * Lists of integers and OIDs don't need to be deep-copied, so we
3250                          * perform a shallow copy via list_copy()
3251                          */
3252                 case T_IntList:
3253                 case T_OidList:
3254                         retval = list_copy(from);
3255                         break;
3256
3257                         /*
3258                          * PARSE NODES
3259                          */
3260                 case T_Query:
3261                         retval = _copyQuery(from);
3262                         break;
3263                 case T_InsertStmt:
3264                         retval = _copyInsertStmt(from);
3265                         break;
3266                 case T_DeleteStmt:
3267                         retval = _copyDeleteStmt(from);
3268                         break;
3269                 case T_UpdateStmt:
3270                         retval = _copyUpdateStmt(from);
3271                         break;
3272                 case T_SelectStmt:
3273                         retval = _copySelectStmt(from);
3274                         break;
3275                 case T_SetOperationStmt:
3276                         retval = _copySetOperationStmt(from);
3277                         break;
3278                 case T_AlterTableStmt:
3279                         retval = _copyAlterTableStmt(from);
3280                         break;
3281                 case T_AlterTableCmd:
3282                         retval = _copyAlterTableCmd(from);
3283                         break;
3284                 case T_AlterDomainStmt:
3285                         retval = _copyAlterDomainStmt(from);
3286                         break;
3287                 case T_GrantStmt:
3288                         retval = _copyGrantStmt(from);
3289                         break;
3290                 case T_GrantRoleStmt:
3291                         retval = _copyGrantRoleStmt(from);
3292                         break;
3293                 case T_DeclareCursorStmt:
3294                         retval = _copyDeclareCursorStmt(from);
3295                         break;
3296                 case T_ClosePortalStmt:
3297                         retval = _copyClosePortalStmt(from);
3298                         break;
3299                 case T_ClusterStmt:
3300                         retval = _copyClusterStmt(from);
3301                         break;
3302                 case T_CopyStmt:
3303                         retval = _copyCopyStmt(from);
3304                         break;
3305                 case T_CreateStmt:
3306                         retval = _copyCreateStmt(from);
3307                         break;
3308                 case T_InhRelation:
3309                         retval = _copyInhRelation(from);
3310                         break;
3311                 case T_DefineStmt:
3312                         retval = _copyDefineStmt(from);
3313                         break;
3314                 case T_DropStmt:
3315                         retval = _copyDropStmt(from);
3316                         break;
3317                 case T_TruncateStmt:
3318                         retval = _copyTruncateStmt(from);
3319                         break;
3320                 case T_CommentStmt:
3321                         retval = _copyCommentStmt(from);
3322                         break;
3323                 case T_FetchStmt:
3324                         retval = _copyFetchStmt(from);
3325                         break;
3326                 case T_IndexStmt:
3327                         retval = _copyIndexStmt(from);
3328                         break;
3329                 case T_CreateFunctionStmt:
3330                         retval = _copyCreateFunctionStmt(from);
3331                         break;
3332                 case T_FunctionParameter:
3333                         retval = _copyFunctionParameter(from);
3334                         break;
3335                 case T_AlterFunctionStmt:
3336                         retval = _copyAlterFunctionStmt(from);
3337                         break;
3338                 case T_RemoveFuncStmt:
3339                         retval = _copyRemoveFuncStmt(from);
3340                         break;
3341                 case T_RemoveOpClassStmt:
3342                         retval = _copyRemoveOpClassStmt(from);
3343                         break;
3344                 case T_RemoveOpFamilyStmt:
3345                         retval = _copyRemoveOpFamilyStmt(from);
3346                         break;
3347                 case T_RenameStmt:
3348                         retval = _copyRenameStmt(from);
3349                         break;
3350                 case T_AlterObjectSchemaStmt:
3351                         retval = _copyAlterObjectSchemaStmt(from);
3352                         break;
3353                 case T_AlterOwnerStmt:
3354                         retval = _copyAlterOwnerStmt(from);
3355                         break;
3356                 case T_RuleStmt:
3357                         retval = _copyRuleStmt(from);
3358                         break;
3359                 case T_NotifyStmt:
3360                         retval = _copyNotifyStmt(from);
3361                         break;
3362                 case T_ListenStmt:
3363                         retval = _copyListenStmt(from);
3364                         break;
3365                 case T_UnlistenStmt:
3366                         retval = _copyUnlistenStmt(from);
3367                         break;
3368                 case T_TransactionStmt:
3369                         retval = _copyTransactionStmt(from);
3370                         break;
3371                 case T_CompositeTypeStmt:
3372                         retval = _copyCompositeTypeStmt(from);
3373                         break;
3374                 case T_CreateEnumStmt:
3375                         retval = _copyCreateEnumStmt(from);
3376                         break;
3377                 case T_ViewStmt:
3378                         retval = _copyViewStmt(from);
3379                         break;
3380                 case T_LoadStmt:
3381                         retval = _copyLoadStmt(from);
3382                         break;
3383                 case T_CreateDomainStmt:
3384                         retval = _copyCreateDomainStmt(from);
3385                         break;
3386                 case T_CreateOpClassStmt:
3387                         retval = _copyCreateOpClassStmt(from);
3388                         break;
3389                 case T_CreateOpClassItem:
3390                         retval = _copyCreateOpClassItem(from);
3391                         break;
3392                 case T_CreateOpFamilyStmt:
3393                         retval = _copyCreateOpFamilyStmt(from);
3394                         break;
3395                 case T_AlterOpFamilyStmt:
3396                         retval = _copyAlterOpFamilyStmt(from);
3397                         break;
3398                 case T_CreatedbStmt:
3399                         retval = _copyCreatedbStmt(from);
3400                         break;
3401                 case T_AlterDatabaseStmt:
3402                         retval = _copyAlterDatabaseStmt(from);
3403                         break;
3404                 case T_AlterDatabaseSetStmt:
3405                         retval = _copyAlterDatabaseSetStmt(from);
3406                         break;
3407                 case T_DropdbStmt:
3408                         retval = _copyDropdbStmt(from);
3409                         break;
3410                 case T_VacuumStmt:
3411                         retval = _copyVacuumStmt(from);
3412                         break;
3413                 case T_ExplainStmt:
3414                         retval = _copyExplainStmt(from);
3415                         break;
3416                 case T_CreateSeqStmt:
3417                         retval = _copyCreateSeqStmt(from);
3418                         break;
3419                 case T_AlterSeqStmt:
3420                         retval = _copyAlterSeqStmt(from);
3421                         break;
3422                 case T_VariableSetStmt:
3423                         retval = _copyVariableSetStmt(from);
3424                         break;
3425                 case T_VariableShowStmt:
3426                         retval = _copyVariableShowStmt(from);
3427                         break;
3428                 case T_VariableResetStmt:
3429                         retval = _copyVariableResetStmt(from);
3430                         break;
3431                 case T_DiscardStmt:
3432                         retval = _copyDiscardStmt(from);
3433                         break;
3434                 case T_CreateTableSpaceStmt:
3435                         retval = _copyCreateTableSpaceStmt(from);
3436                         break;
3437                 case T_DropTableSpaceStmt:
3438                         retval = _copyDropTableSpaceStmt(from);
3439                         break;
3440                 case T_CreateTrigStmt:
3441                         retval = _copyCreateTrigStmt(from);
3442                         break;
3443                 case T_DropPropertyStmt:
3444                         retval = _copyDropPropertyStmt(from);
3445                         break;
3446                 case T_CreatePLangStmt:
3447                         retval = _copyCreatePLangStmt(from);
3448                         break;
3449                 case T_DropPLangStmt:
3450                         retval = _copyDropPLangStmt(from);
3451                         break;
3452                 case T_CreateRoleStmt:
3453                         retval = _copyCreateRoleStmt(from);
3454                         break;
3455                 case T_AlterRoleStmt:
3456                         retval = _copyAlterRoleStmt(from);
3457                         break;
3458                 case T_AlterRoleSetStmt:
3459                         retval = _copyAlterRoleSetStmt(from);
3460                         break;
3461                 case T_DropRoleStmt:
3462                         retval = _copyDropRoleStmt(from);
3463                         break;
3464                 case T_LockStmt:
3465                         retval = _copyLockStmt(from);
3466                         break;
3467                 case T_ConstraintsSetStmt:
3468                         retval = _copyConstraintsSetStmt(from);
3469                         break;
3470                 case T_ReindexStmt:
3471                         retval = _copyReindexStmt(from);
3472                         break;
3473                 case T_CheckPointStmt:
3474                         retval = (void *) makeNode(CheckPointStmt);
3475                         break;
3476                 case T_CreateSchemaStmt:
3477                         retval = _copyCreateSchemaStmt(from);
3478                         break;
3479                 case T_CreateConversionStmt:
3480                         retval = _copyCreateConversionStmt(from);
3481                         break;
3482                 case T_CreateCastStmt:
3483                         retval = _copyCreateCastStmt(from);
3484                         break;
3485                 case T_DropCastStmt:
3486                         retval = _copyDropCastStmt(from);
3487                         break;
3488                 case T_PrepareStmt:
3489                         retval = _copyPrepareStmt(from);
3490                         break;
3491                 case T_ExecuteStmt:
3492                         retval = _copyExecuteStmt(from);
3493                         break;
3494                 case T_DeallocateStmt:
3495                         retval = _copyDeallocateStmt(from);
3496                         break;
3497                 case T_DropOwnedStmt:
3498                         retval = _copyDropOwnedStmt(from);
3499                         break;
3500                 case T_ReassignOwnedStmt:
3501                         retval = _copyReassignOwnedStmt(from);
3502                         break;
3503
3504                 case T_A_Expr:
3505                         retval = _copyAExpr(from);
3506                         break;
3507                 case T_ColumnRef:
3508                         retval = _copyColumnRef(from);
3509                         break;
3510                 case T_ParamRef:
3511                         retval = _copyParamRef(from);
3512                         break;
3513                 case T_A_Const:
3514                         retval = _copyAConst(from);
3515                         break;
3516                 case T_FuncCall:
3517                         retval = _copyFuncCall(from);
3518                         break;
3519                 case T_A_Indices:
3520                         retval = _copyAIndices(from);
3521                         break;
3522                 case T_A_Indirection:
3523                         retval = _copyA_Indirection(from);
3524                         break;
3525                 case T_ResTarget:
3526                         retval = _copyResTarget(from);
3527                         break;
3528                 case T_TypeCast:
3529                         retval = _copyTypeCast(from);
3530                         break;
3531                 case T_SortBy:
3532                         retval = _copySortBy(from);
3533                         break;
3534                 case T_RangeSubselect:
3535                         retval = _copyRangeSubselect(from);
3536                         break;
3537                 case T_RangeFunction:
3538                         retval = _copyRangeFunction(from);
3539                         break;
3540                 case T_TypeName:
3541                         retval = _copyTypeName(from);
3542                         break;
3543                 case T_IndexElem:
3544                         retval = _copyIndexElem(from);
3545                         break;
3546                 case T_ColumnDef:
3547                         retval = _copyColumnDef(from);
3548                         break;
3549                 case T_Constraint:
3550                         retval = _copyConstraint(from);
3551                         break;
3552                 case T_DefElem:
3553                         retval = _copyDefElem(from);
3554                         break;
3555                 case T_LockingClause:
3556                         retval = _copyLockingClause(from);
3557                         break;
3558                 case T_RangeTblEntry:
3559                         retval = _copyRangeTblEntry(from);
3560                         break;
3561                 case T_SortClause:
3562                         retval = _copySortClause(from);
3563                         break;
3564                 case T_GroupClause:
3565                         retval = _copyGroupClause(from);
3566                         break;
3567                 case T_RowMarkClause:
3568                         retval = _copyRowMarkClause(from);
3569                         break;
3570                 case T_FkConstraint:
3571                         retval = _copyFkConstraint(from);
3572                         break;
3573                 case T_PrivGrantee:
3574                         retval = _copyPrivGrantee(from);
3575                         break;
3576                 case T_FuncWithArgs:
3577                         retval = _copyFuncWithArgs(from);
3578                         break;
3579                 case T_XmlSerialize:
3580                         retval = _copyXmlSerialize(from);
3581                         break;
3582
3583                 default:
3584                         elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
3585                         retval = from;          /* keep compiler quiet */
3586                         break;
3587         }
3588
3589         return retval;
3590 }