OSDN Git Service

Ye-old pgindent run. Same 4-space tabs.
[pg-rex/syncrep.git] / src / backend / nodes / copyfuncs.c
1 /*-------------------------------------------------------------------------
2  *
3  * copyfuncs.c
4  *        Copy functions for Postgres tree nodes.
5  *
6  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  *        $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.113 2000/04/12 17:15:16 momjian Exp $
12  *
13  *-------------------------------------------------------------------------
14  */
15
16 #include "postgres.h"
17
18 #include "optimizer/clauses.h"
19 #include "optimizer/planmain.h"
20
21
22 /*
23  * Node_Copy
24  *        a macro to simplify calling of copyObject on the specified field
25  */
26 #define Node_Copy(from, newnode, field) \
27         ((newnode)->field = copyObject((from)->field))
28
29
30 /*
31  * listCopy
32  *        This copy function only copies the "cons-cells" of the list, not the
33  *        pointed-to objects.  (Use copyObject if you want a "deep" copy.)
34  *
35  *        We also use this function for copying lists of integers, which is
36  *        grotty but unlikely to break --- it could fail if sizeof(pointer)
37  *        is less than sizeof(int), but I don't know any such machines...
38  *
39  *        Note that copyObject will surely coredump if applied to a list
40  *        of integers!
41  */
42 List *
43 listCopy(List *list)
44 {
45         List       *newlist,
46                            *l,
47                            *nl;
48
49         /* rather ugly coding for speed... */
50         if (list == NIL)
51                 return NIL;
52
53         newlist = nl = lcons(lfirst(list), NIL);
54
55         foreach(l, lnext(list))
56         {
57                 lnext(nl) = lcons(lfirst(l), NIL);
58                 nl = lnext(nl);
59         }
60         return newlist;
61 }
62
63 /* ****************************************************************
64  *                                       plannodes.h copy functions
65  * ****************************************************************
66  */
67
68 /* ----------------
69  *              CopyPlanFields
70  *
71  *              This function copies the fields of the Plan node.  It is used by
72  *              all the copy functions for classes which inherit from Plan.
73  * ----------------
74  */
75 static void
76 CopyPlanFields(Plan *from, Plan *newnode)
77 {
78         newnode->startup_cost = from->startup_cost;
79         newnode->total_cost = from->total_cost;
80         newnode->plan_rows = from->plan_rows;
81         newnode->plan_width = from->plan_width;
82         /* state is NOT copied */
83         newnode->targetlist = copyObject(from->targetlist);
84         newnode->qual = copyObject(from->qual);
85         newnode->lefttree = copyObject(from->lefttree);
86         newnode->righttree = copyObject(from->righttree);
87         newnode->extParam = listCopy(from->extParam);
88         newnode->locParam = listCopy(from->locParam);
89         newnode->chgParam = listCopy(from->chgParam);
90         Node_Copy(from, newnode, initPlan);
91         /* subPlan list must point to subplans in the new subtree, not the old */
92         if (from->subPlan != NIL)
93                 newnode->subPlan = nconc(pull_subplans((Node *) newnode->targetlist),
94                                                                  pull_subplans((Node *) newnode->qual));
95         else
96                 newnode->subPlan = NIL;
97         newnode->nParamExec = from->nParamExec;
98 }
99
100 /* ----------------
101  *              _copyPlan
102  * ----------------
103  */
104 static Plan *
105 _copyPlan(Plan *from)
106 {
107         Plan       *newnode = makeNode(Plan);
108
109         /* ----------------
110          *      copy the node superclass fields
111          * ----------------
112          */
113         CopyPlanFields(from, newnode);
114
115         return newnode;
116 }
117
118
119 /* ----------------
120  *              _copyResult
121  * ----------------
122  */
123 static Result *
124 _copyResult(Result *from)
125 {
126         Result     *newnode = makeNode(Result);
127
128         /* ----------------
129          *      copy node superclass fields
130          * ----------------
131          */
132         CopyPlanFields((Plan *) from, (Plan *) newnode);
133
134         /* ----------------
135          *      copy remainder of node
136          * ----------------
137          */
138         Node_Copy(from, newnode, resconstantqual);
139
140         /*
141          * We must add subplans in resconstantqual to the new plan's subPlan
142          * list
143          */
144         if (from->plan.subPlan != NIL)
145                 newnode->plan.subPlan = nconc(newnode->plan.subPlan,
146                                                                 pull_subplans(newnode->resconstantqual));
147
148         return newnode;
149 }
150
151 /* ----------------
152  *              _copyAppend
153  * ----------------
154  */
155 static Append *
156 _copyAppend(Append *from)
157 {
158         Append     *newnode = makeNode(Append);
159
160         /* ----------------
161          *      copy node superclass fields
162          * ----------------
163          */
164         CopyPlanFields((Plan *) from, (Plan *) newnode);
165
166         /* ----------------
167          *      copy remainder of node
168          * ----------------
169          */
170         Node_Copy(from, newnode, appendplans);
171         Node_Copy(from, newnode, unionrtables);
172         newnode->inheritrelid = from->inheritrelid;
173         Node_Copy(from, newnode, inheritrtable);
174
175         return newnode;
176 }
177
178
179 /* ----------------
180  *              CopyScanFields
181  *
182  *              This function copies the fields of the Scan node.  It is used by
183  *              all the copy functions for classes which inherit from Scan.
184  * ----------------
185  */
186 static void
187 CopyScanFields(Scan *from, Scan *newnode)
188 {
189         newnode->scanrelid = from->scanrelid;
190         return;
191 }
192
193 /* ----------------
194  *              _copyScan
195  * ----------------
196  */
197 static Scan *
198 _copyScan(Scan *from)
199 {
200         Scan       *newnode = makeNode(Scan);
201
202         /* ----------------
203          *      copy node superclass fields
204          * ----------------
205          */
206         CopyPlanFields((Plan *) from, (Plan *) newnode);
207         CopyScanFields((Scan *) from, (Scan *) newnode);
208
209         return newnode;
210 }
211
212 /* ----------------
213  *              _copySeqScan
214  * ----------------
215  */
216 static SeqScan *
217 _copySeqScan(SeqScan *from)
218 {
219         SeqScan    *newnode = makeNode(SeqScan);
220
221         /* ----------------
222          *      copy node superclass fields
223          * ----------------
224          */
225         CopyPlanFields((Plan *) from, (Plan *) newnode);
226         CopyScanFields((Scan *) from, (Scan *) newnode);
227
228         return newnode;
229 }
230
231 /* ----------------
232  *              _copyIndexScan
233  * ----------------
234  */
235 static IndexScan *
236 _copyIndexScan(IndexScan *from)
237 {
238         IndexScan  *newnode = makeNode(IndexScan);
239
240         /* ----------------
241          *      copy node superclass fields
242          * ----------------
243          */
244         CopyPlanFields((Plan *) from, (Plan *) newnode);
245         CopyScanFields((Scan *) from, (Scan *) newnode);
246
247         /* ----------------
248          *      copy remainder of node
249          * ----------------
250          */
251         newnode->indxid = listCopy(from->indxid);
252         Node_Copy(from, newnode, indxqual);
253         Node_Copy(from, newnode, indxqualorig);
254         newnode->indxorderdir = from->indxorderdir;
255
256         /*
257          * We must add subplans in index quals to the new plan's subPlan list
258          */
259         if (from->scan.plan.subPlan != NIL)
260         {
261                 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
262                                                           pull_subplans((Node *) newnode->indxqual));
263                 newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
264                                                   pull_subplans((Node *) newnode->indxqualorig));
265         }
266
267         return newnode;
268 }
269
270 /* ----------------
271  *                              _copyTidScan
272  * ----------------
273  */
274 static TidScan *
275 _copyTidScan(TidScan *from)
276 {
277         TidScan    *newnode = makeNode(TidScan);
278
279         /* ----------------
280          *      copy node superclass fields
281          * ----------------
282          */
283         CopyPlanFields((Plan *) from, (Plan *) newnode);
284         CopyScanFields((Scan *) from, (Scan *) newnode);
285         /* ----------------
286          *      copy remainder of node
287          * ----------------
288          */
289         newnode->needRescan = from->needRescan;
290         Node_Copy(from, newnode, tideval);
291
292         return newnode;
293 }
294
295
296 /* ----------------
297  *              CopyJoinFields
298  *
299  *              This function copies the fields of the Join node.  It is used by
300  *              all the copy functions for classes which inherit from Join.
301  * ----------------
302  */
303 static void
304 CopyJoinFields(Join *from, Join *newnode)
305 {
306         /* nothing extra */
307         return;
308 }
309
310
311 /* ----------------
312  *              _copyJoin
313  * ----------------
314  */
315 static Join *
316 _copyJoin(Join *from)
317 {
318         Join       *newnode = makeNode(Join);
319
320         /* ----------------
321          *      copy node superclass fields
322          * ----------------
323          */
324         CopyPlanFields((Plan *) from, (Plan *) newnode);
325         CopyJoinFields(from, newnode);
326
327         return newnode;
328 }
329
330
331 /* ----------------
332  *              _copyNestLoop
333  * ----------------
334  */
335 static NestLoop *
336 _copyNestLoop(NestLoop *from)
337 {
338         NestLoop   *newnode = makeNode(NestLoop);
339
340         /* ----------------
341          *      copy node superclass fields
342          * ----------------
343          */
344         CopyPlanFields((Plan *) from, (Plan *) newnode);
345         CopyJoinFields((Join *) from, (Join *) newnode);
346
347         return newnode;
348 }
349
350
351 /* ----------------
352  *              _copyMergeJoin
353  * ----------------
354  */
355 static MergeJoin *
356 _copyMergeJoin(MergeJoin *from)
357 {
358         MergeJoin  *newnode = makeNode(MergeJoin);
359
360         /* ----------------
361          *      copy node superclass fields
362          * ----------------
363          */
364         CopyPlanFields((Plan *) from, (Plan *) newnode);
365         CopyJoinFields((Join *) from, (Join *) newnode);
366
367         /* ----------------
368          *      copy remainder of node
369          * ----------------
370          */
371         Node_Copy(from, newnode, mergeclauses);
372
373         /*
374          * We must add subplans in mergeclauses to the new plan's subPlan list
375          */
376         if (from->join.subPlan != NIL)
377                 newnode->join.subPlan = nconc(newnode->join.subPlan,
378                                                   pull_subplans((Node *) newnode->mergeclauses));
379
380         return newnode;
381 }
382
383 /* ----------------
384  *              _copyHashJoin
385  * ----------------
386  */
387 static HashJoin *
388 _copyHashJoin(HashJoin *from)
389 {
390         HashJoin   *newnode = makeNode(HashJoin);
391
392         /* ----------------
393          *      copy node superclass fields
394          * ----------------
395          */
396         CopyPlanFields((Plan *) from, (Plan *) newnode);
397         CopyJoinFields((Join *) from, (Join *) newnode);
398
399         /* ----------------
400          *      copy remainder of node
401          * ----------------
402          */
403         Node_Copy(from, newnode, hashclauses);
404         newnode->hashjoinop = from->hashjoinop;
405
406         /*
407          * We must add subplans in hashclauses to the new plan's subPlan list
408          */
409         if (from->join.subPlan != NIL)
410                 newnode->join.subPlan = nconc(newnode->join.subPlan,
411                                                    pull_subplans((Node *) newnode->hashclauses));
412
413         return newnode;
414 }
415
416
417 /* ----------------
418  *              CopyNonameFields
419  *
420  *              This function copies the fields of the Noname node.  It is used by
421  *              all the copy functions for classes which inherit from Noname.
422  * ----------------
423  */
424 static void
425 CopyNonameFields(Noname *from, Noname *newnode)
426 {
427         newnode->nonameid = from->nonameid;
428         newnode->keycount = from->keycount;
429         return;
430 }
431
432
433 /* ----------------
434  *              _copyNoname
435  * ----------------
436  */
437 static Noname *
438 _copyNoname(Noname *from)
439 {
440         Noname     *newnode = makeNode(Noname);
441
442         /* ----------------
443          *      copy node superclass fields
444          * ----------------
445          */
446         CopyPlanFields((Plan *) from, (Plan *) newnode);
447         CopyNonameFields(from, newnode);
448
449         return newnode;
450 }
451
452 /* ----------------
453  *              _copyMaterial
454  * ----------------
455  */
456 static Material *
457 _copyMaterial(Material *from)
458 {
459         Material   *newnode = makeNode(Material);
460
461         /* ----------------
462          *      copy node superclass fields
463          * ----------------
464          */
465         CopyPlanFields((Plan *) from, (Plan *) newnode);
466         CopyNonameFields((Noname *) from, (Noname *) newnode);
467
468         return newnode;
469 }
470
471
472 /* ----------------
473  *              _copySort
474  * ----------------
475  */
476 static Sort *
477 _copySort(Sort *from)
478 {
479         Sort       *newnode = makeNode(Sort);
480
481         /* ----------------
482          *      copy node superclass fields
483          * ----------------
484          */
485         CopyPlanFields((Plan *) from, (Plan *) newnode);
486         CopyNonameFields((Noname *) from, (Noname *) newnode);
487
488         return newnode;
489 }
490
491
492 /* ----------------
493  *              _copyGroup
494  * ----------------
495  */
496 static Group *
497 _copyGroup(Group *from)
498 {
499         Group      *newnode = makeNode(Group);
500
501         CopyPlanFields((Plan *) from, (Plan *) newnode);
502
503         newnode->tuplePerGroup = from->tuplePerGroup;
504         newnode->numCols = from->numCols;
505         newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
506         memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
507
508         return newnode;
509 }
510
511 /* ---------------
512  *      _copyAgg
513  * --------------
514  */
515 static Agg *
516 _copyAgg(Agg *from)
517 {
518         Agg                *newnode = makeNode(Agg);
519
520         CopyPlanFields((Plan *) from, (Plan *) newnode);
521
522         return newnode;
523 }
524
525 /* ---------------
526  *      _copyGroupClause
527  * --------------
528  */
529 static GroupClause *
530 _copyGroupClause(GroupClause *from)
531 {
532         GroupClause *newnode = makeNode(GroupClause);
533
534         newnode->tleSortGroupRef = from->tleSortGroupRef;
535         newnode->sortop = from->sortop;
536
537         return newnode;
538 }
539
540
541 /* ----------------
542  *              _copyUnique
543  * ----------------
544  */
545 static Unique *
546 _copyUnique(Unique *from)
547 {
548         Unique     *newnode = makeNode(Unique);
549
550         /* ----------------
551          *      copy node superclass fields
552          * ----------------
553          */
554         CopyPlanFields((Plan *) from, (Plan *) newnode);
555         CopyNonameFields((Noname *) from, (Noname *) newnode);
556
557         /* ----------------
558          *      copy remainder of node
559          * ----------------
560          */
561         newnode->numCols = from->numCols;
562         newnode->uniqColIdx = palloc(from->numCols * sizeof(AttrNumber));
563         memcpy(newnode->uniqColIdx, from->uniqColIdx, from->numCols * sizeof(AttrNumber));
564
565         return newnode;
566 }
567
568
569 /* ----------------
570  *              _copyHash
571  * ----------------
572  */
573 static Hash *
574 _copyHash(Hash *from)
575 {
576         Hash       *newnode = makeNode(Hash);
577
578         /* ----------------
579          *      copy node superclass fields
580          * ----------------
581          */
582         CopyPlanFields((Plan *) from, (Plan *) newnode);
583
584         /* ----------------
585          *      copy remainder of node
586          * ----------------
587          */
588         Node_Copy(from, newnode, hashkey);
589
590         return newnode;
591 }
592
593 static SubPlan *
594 _copySubPlan(SubPlan *from)
595 {
596         SubPlan    *newnode = makeNode(SubPlan);
597
598         Node_Copy(from, newnode, plan);
599         newnode->plan_id = from->plan_id;
600         Node_Copy(from, newnode, rtable);
601         newnode->setParam = listCopy(from->setParam);
602         newnode->parParam = listCopy(from->parParam);
603         Node_Copy(from, newnode, sublink);
604
605         /* do not copy execution state */
606         newnode->shutdown = false;
607         newnode->curTuple = NULL;
608
609         return newnode;
610 }
611
612 /* ****************************************************************
613  *                                         primnodes.h copy functions
614  * ****************************************************************
615  */
616
617 /* ----------------
618  *              _copyResdom
619  * ----------------
620  */
621 static Resdom *
622 _copyResdom(Resdom *from)
623 {
624         Resdom     *newnode = makeNode(Resdom);
625
626         newnode->resno = from->resno;
627         newnode->restype = from->restype;
628         newnode->restypmod = from->restypmod;
629         if (from->resname != NULL)
630                 newnode->resname = pstrdup(from->resname);
631         newnode->ressortgroupref = from->ressortgroupref;
632         newnode->reskey = from->reskey;
633         newnode->reskeyop = from->reskeyop;
634         newnode->resjunk = from->resjunk;
635
636         return newnode;
637 }
638
639 static Fjoin *
640 _copyFjoin(Fjoin *from)
641 {
642         Fjoin      *newnode = makeNode(Fjoin);
643
644         /* ----------------
645          *      copy node superclass fields
646          * ----------------
647          */
648
649         newnode->fj_initialized = from->fj_initialized;
650         newnode->fj_nNodes = from->fj_nNodes;
651
652         Node_Copy(from, newnode, fj_innerNode);
653
654         newnode->fj_results = (DatumPtr)
655                 palloc((from->fj_nNodes) * sizeof(Datum));
656         memmove(from->fj_results,
657                         newnode->fj_results,
658                         (from->fj_nNodes) * sizeof(Datum));
659
660         newnode->fj_alwaysDone = (BoolPtr)
661                 palloc((from->fj_nNodes) * sizeof(bool));
662         memmove(from->fj_alwaysDone,
663                         newnode->fj_alwaysDone,
664                         (from->fj_nNodes) * sizeof(bool));
665
666
667         return newnode;
668 }
669
670 /* ----------------
671  *              _copyExpr
672  * ----------------
673  */
674 static Expr *
675 _copyExpr(Expr *from)
676 {
677         Expr       *newnode = makeNode(Expr);
678
679         /* ----------------
680          *      copy node superclass fields
681          * ----------------
682          */
683         newnode->typeOid = from->typeOid;
684         newnode->opType = from->opType;
685
686         Node_Copy(from, newnode, oper);
687         Node_Copy(from, newnode, args);
688
689         return newnode;
690 }
691
692 /* ----------------
693  *              _copyVar
694  * ----------------
695  */
696 static Var *
697 _copyVar(Var *from)
698 {
699         Var                *newnode = makeNode(Var);
700
701         /* ----------------
702          *      copy remainder of node
703          * ----------------
704          */
705         newnode->varno = from->varno;
706         newnode->varattno = from->varattno;
707         newnode->vartype = from->vartype;
708         newnode->vartypmod = from->vartypmod;
709         newnode->varlevelsup = from->varlevelsup;
710
711         newnode->varnoold = from->varnoold;
712         newnode->varoattno = from->varoattno;
713
714         return newnode;
715 }
716
717 static Attr *
718 _copyAttr(Attr *from)
719 {
720         Attr       *newnode = makeNode(Attr);
721
722         if (from->relname)
723                 newnode->relname = pstrdup(from->relname);
724         Node_Copy(from, newnode, attrs);
725
726         return newnode;
727 }
728
729 /* ----------------
730  *              _copyOper
731  * ----------------
732  */
733 static Oper *
734 _copyOper(Oper *from)
735 {
736         Oper       *newnode = makeNode(Oper);
737
738         /* ----------------
739          *      copy remainder of node
740          * ----------------
741          */
742         newnode->opno = from->opno;
743         newnode->opid = from->opid;
744         newnode->opresulttype = from->opresulttype;
745         newnode->opsize = from->opsize;
746
747         /*
748          * NOTE: shall we copy the cache structure or just the pointer ?
749          * Alternatively we can set 'op_fcache' to NULL, in which case the
750          * executor will initialize it when it needs it...
751          */
752         newnode->op_fcache = from->op_fcache;
753
754         return newnode;
755 }
756
757 /* ----------------
758  *              _copyConst
759  * ----------------
760  */
761 static Const *
762 _copyConst(Const *from)
763 {
764         Const      *newnode = makeNode(Const);
765
766         /* ----------------
767          *      copy remainder of node
768          * ----------------
769          */
770         newnode->consttype = from->consttype;
771         newnode->constlen = from->constlen;
772
773         if (from->constbyval || from->constisnull)
774         {
775                 /* ----------------
776                  *      passed by value so just copy the datum.
777                  *      Also, don't try to copy struct when value is null!
778                  * ----------------
779                  */
780                 newnode->constvalue = from->constvalue;
781         }
782         else
783         {
784                 /* ----------------
785                  *      not passed by value. datum contains a pointer.
786                  * ----------------
787                  */
788                 int                     length = from->constlen;
789
790                 if (length == -1)               /* variable-length type? */
791                         length = VARSIZE(from->constvalue);
792                 newnode->constvalue = PointerGetDatum(palloc(length));
793                 memcpy(DatumGetPointer(newnode->constvalue),
794                            DatumGetPointer(from->constvalue),
795                            length);
796         }
797
798         newnode->constisnull = from->constisnull;
799         newnode->constbyval = from->constbyval;
800         newnode->constisset = from->constisset;
801         newnode->constiscast = from->constiscast;
802
803         return newnode;
804 }
805
806 /* ----------------
807  *              _copyParam
808  * ----------------
809  */
810 static Param *
811 _copyParam(Param *from)
812 {
813         Param      *newnode = makeNode(Param);
814
815         /* ----------------
816          *      copy remainder of node
817          * ----------------
818          */
819         newnode->paramkind = from->paramkind;
820         newnode->paramid = from->paramid;
821
822         if (from->paramname != NULL)
823                 newnode->paramname = pstrdup(from->paramname);
824         newnode->paramtype = from->paramtype;
825         Node_Copy(from, newnode, param_tlist);
826
827         return newnode;
828 }
829
830 /* ----------------
831  *              _copyFunc
832  * ----------------
833  */
834 static Func *
835 _copyFunc(Func *from)
836 {
837         Func       *newnode = makeNode(Func);
838
839         /* ----------------
840          *      copy remainder of node
841          * ----------------
842          */
843         newnode->funcid = from->funcid;
844         newnode->functype = from->functype;
845         newnode->funcisindex = from->funcisindex;
846         newnode->funcsize = from->funcsize;
847         newnode->func_fcache = from->func_fcache;
848         Node_Copy(from, newnode, func_tlist);
849         Node_Copy(from, newnode, func_planlist);
850
851         return newnode;
852 }
853
854 /* ----------------
855  *              _copyAggref
856  * ----------------
857  */
858 static Aggref *
859 _copyAggref(Aggref *from)
860 {
861         Aggref     *newnode = makeNode(Aggref);
862
863         /* ----------------
864          *      copy remainder of node
865          * ----------------
866          */
867         newnode->aggname = pstrdup(from->aggname);
868         newnode->basetype = from->basetype;
869         newnode->aggtype = from->aggtype;
870         Node_Copy(from, newnode, target);
871         newnode->usenulls = from->usenulls;
872         newnode->aggstar = from->aggstar;
873         newnode->aggdistinct = from->aggdistinct;
874         newnode->aggno = from->aggno;           /* probably not needed */
875
876         return newnode;
877 }
878
879 /* ----------------
880  *              _copySubLink
881  * ----------------
882  */
883 static SubLink *
884 _copySubLink(SubLink *from)
885 {
886         SubLink    *newnode = makeNode(SubLink);
887
888         /* ----------------
889          *      copy remainder of node
890          * ----------------
891          */
892         newnode->subLinkType = from->subLinkType;
893         newnode->useor = from->useor;
894         Node_Copy(from, newnode, lefthand);
895         Node_Copy(from, newnode, oper);
896         Node_Copy(from, newnode, subselect);
897
898         return newnode;
899 }
900
901 /* ----------------
902  *              _copyRelabelType
903  * ----------------
904  */
905 static RelabelType *
906 _copyRelabelType(RelabelType *from)
907 {
908         RelabelType *newnode = makeNode(RelabelType);
909
910         /* ----------------
911          *      copy remainder of node
912          * ----------------
913          */
914         Node_Copy(from, newnode, arg);
915         newnode->resulttype = from->resulttype;
916         newnode->resulttypmod = from->resulttypmod;
917
918         return newnode;
919 }
920
921 /* ----------------
922  *              _copyCaseExpr
923  * ----------------
924  */
925 static CaseExpr *
926 _copyCaseExpr(CaseExpr *from)
927 {
928         CaseExpr   *newnode = makeNode(CaseExpr);
929
930         /* ----------------
931          *      copy remainder of node
932          * ----------------
933          */
934         newnode->casetype = from->casetype;
935
936         Node_Copy(from, newnode, arg);
937         Node_Copy(from, newnode, args);
938         Node_Copy(from, newnode, defresult);
939
940         return newnode;
941 }
942
943 /* ----------------
944  *              _copyCaseWhen
945  * ----------------
946  */
947 static CaseWhen *
948 _copyCaseWhen(CaseWhen *from)
949 {
950         CaseWhen   *newnode = makeNode(CaseWhen);
951
952         /* ----------------
953          *      copy remainder of node
954          * ----------------
955          */
956         Node_Copy(from, newnode, expr);
957         Node_Copy(from, newnode, result);
958
959         return newnode;
960 }
961
962 static Array *
963 _copyArray(Array *from)
964 {
965         Array      *newnode = makeNode(Array);
966
967         /* ----------------
968          *      copy remainder of node
969          * ----------------
970          */
971         newnode->arrayelemtype = from->arrayelemtype;
972         newnode->arrayelemlength = from->arrayelemlength;
973         newnode->arrayelembyval = from->arrayelembyval;
974         newnode->arrayndim = from->arrayndim;
975         newnode->arraylow = from->arraylow;
976         newnode->arrayhigh = from->arrayhigh;
977         newnode->arraylen = from->arraylen;
978
979         return newnode;
980 }
981
982 static ArrayRef *
983 _copyArrayRef(ArrayRef *from)
984 {
985         ArrayRef   *newnode = makeNode(ArrayRef);
986
987         /* ----------------
988          *      copy remainder of node
989          * ----------------
990          */
991         newnode->refattrlength = from->refattrlength;
992         newnode->refelemlength = from->refelemlength;
993         newnode->refelemtype = from->refelemtype;
994         newnode->refelembyval = from->refelembyval;
995
996         Node_Copy(from, newnode, refupperindexpr);
997         Node_Copy(from, newnode, reflowerindexpr);
998         Node_Copy(from, newnode, refexpr);
999         Node_Copy(from, newnode, refassgnexpr);
1000
1001         return newnode;
1002 }
1003
1004 /* ****************************************************************
1005  *                                              relation.h copy functions
1006  * ****************************************************************
1007  */
1008
1009 /* ----------------
1010  *              _copyRelOptInfo
1011  * ----------------
1012  */
1013 /*
1014  *      when you change this, also make sure to fix up xfunc_copyRelOptInfo in
1015  *      planner/path/xfunc.c accordingly!!!
1016  *              -- JMH, 8/2/93
1017  */
1018 static RelOptInfo *
1019 _copyRelOptInfo(RelOptInfo *from)
1020 {
1021         RelOptInfo *newnode = makeNode(RelOptInfo);
1022
1023         newnode->relids = listCopy(from->relids);
1024
1025         newnode->rows = from->rows;
1026         newnode->width = from->width;
1027
1028         Node_Copy(from, newnode, targetlist);
1029         Node_Copy(from, newnode, pathlist);
1030         /* XXX cheapest-path fields should point to members of pathlist? */
1031         Node_Copy(from, newnode, cheapest_startup_path);
1032         Node_Copy(from, newnode, cheapest_total_path);
1033         newnode->pruneable = from->pruneable;
1034
1035         newnode->indexed = from->indexed;
1036         newnode->pages = from->pages;
1037         newnode->tuples = from->tuples;
1038
1039         Node_Copy(from, newnode, baserestrictinfo);
1040         newnode->baserestrictcost = from->baserestrictcost;
1041         Node_Copy(from, newnode, joininfo);
1042         Node_Copy(from, newnode, innerjoin);
1043
1044         return newnode;
1045 }
1046
1047 /* ----------------
1048  *              _copyIndexOptInfo
1049  * ----------------
1050  */
1051 static IndexOptInfo *
1052 _copyIndexOptInfo(IndexOptInfo *from)
1053 {
1054         IndexOptInfo *newnode = makeNode(IndexOptInfo);
1055         int                     i,
1056                                 len;
1057
1058         newnode->indexoid = from->indexoid;
1059         newnode->pages = from->pages;
1060         newnode->tuples = from->tuples;
1061
1062         if (from->classlist)
1063         {
1064                 for (len = 0; from->classlist[len] != 0; len++)
1065                         ;
1066                 newnode->classlist = (Oid *) palloc(sizeof(Oid) * (len + 1));
1067                 for (i = 0; i < len; i++)
1068                         newnode->classlist[i] = from->classlist[i];
1069                 newnode->classlist[len] = 0;
1070         }
1071
1072         if (from->indexkeys)
1073         {
1074                 for (len = 0; from->indexkeys[len] != 0; len++)
1075                         ;
1076                 newnode->indexkeys = (int *) palloc(sizeof(int) * (len + 1));
1077                 for (i = 0; i < len; i++)
1078                         newnode->indexkeys[i] = from->indexkeys[i];
1079                 newnode->indexkeys[len] = 0;
1080         }
1081
1082         if (from->ordering)
1083         {
1084                 for (len = 0; from->ordering[len] != 0; len++)
1085                         ;
1086                 newnode->ordering = (Oid *) palloc(sizeof(Oid) * (len + 1));
1087                 for (i = 0; i < len; i++)
1088                         newnode->ordering[i] = from->ordering[i];
1089                 newnode->ordering[len] = 0;
1090         }
1091
1092         newnode->relam = from->relam;
1093         newnode->amcostestimate = from->amcostestimate;
1094         newnode->indproc = from->indproc;
1095         Node_Copy(from, newnode, indpred);
1096         newnode->lossy = from->lossy;
1097
1098         return newnode;
1099 }
1100
1101 /* ----------------
1102  *              CopyPathFields
1103  *
1104  *              This function copies the fields of the Path node.  It is used by
1105  *              all the copy functions for classes which inherit from Path.
1106  * ----------------
1107  */
1108 static void
1109 CopyPathFields(Path *from, Path *newnode)
1110 {
1111
1112         /*
1113          * Modify the next line, since it causes the copying to cycle (i.e.
1114          * the parent points right back here! -- JMH, 7/7/92. Old version:
1115          * Node_Copy(from, newnode, parent);
1116          */
1117         newnode->parent = from->parent;
1118
1119         newnode->startup_cost = from->startup_cost;
1120         newnode->total_cost = from->total_cost;
1121
1122         newnode->pathtype = from->pathtype;
1123
1124         Node_Copy(from, newnode, pathkeys);
1125 }
1126
1127 /* ----------------
1128  *              _copyPath
1129  * ----------------
1130  */
1131 static Path *
1132 _copyPath(Path *from)
1133 {
1134         Path       *newnode = makeNode(Path);
1135
1136         CopyPathFields(from, newnode);
1137
1138         return newnode;
1139 }
1140
1141 /* ----------------
1142  *              _copyIndexPath
1143  * ----------------
1144  */
1145 static IndexPath *
1146 _copyIndexPath(IndexPath *from)
1147 {
1148         IndexPath  *newnode = makeNode(IndexPath);
1149
1150         /* ----------------
1151          *      copy the node superclass fields
1152          * ----------------
1153          */
1154         CopyPathFields((Path *) from, (Path *) newnode);
1155
1156         /* ----------------
1157          *      copy remainder of node
1158          * ----------------
1159          */
1160         newnode->indexid = listCopy(from->indexid);
1161         Node_Copy(from, newnode, indexqual);
1162         newnode->indexscandir = from->indexscandir;
1163         newnode->joinrelids = listCopy(from->joinrelids);
1164         newnode->rows = from->rows;
1165
1166         return newnode;
1167 }
1168
1169 /* ----------------
1170  *                              _copyTidPath
1171  * ----------------
1172  */
1173 static TidPath *
1174 _copyTidPath(TidPath *from)
1175 {
1176         TidPath    *newnode = makeNode(TidPath);
1177
1178         /* ----------------
1179          *      copy the node superclass fields
1180          * ----------------
1181          */
1182         CopyPathFields((Path *) from, (Path *) newnode);
1183
1184         /* ----------------
1185          *      copy remainder of node
1186          * ----------------
1187          */
1188         Node_Copy(from, newnode, tideval);
1189         newnode->unjoined_relids = listCopy(from->unjoined_relids);
1190
1191         return newnode;
1192 }
1193
1194 /* ----------------
1195  *              CopyJoinPathFields
1196  *
1197  *              This function copies the fields of the JoinPath node.  It is used by
1198  *              all the copy functions for classes which inherit from JoinPath.
1199  * ----------------
1200  */
1201 static void
1202 CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1203 {
1204         Node_Copy(from, newnode, outerjoinpath);
1205         Node_Copy(from, newnode, innerjoinpath);
1206         Node_Copy(from, newnode, joinrestrictinfo);
1207 }
1208
1209 /* ----------------
1210  *              _copyNestPath
1211  * ----------------
1212  */
1213 static NestPath *
1214 _copyNestPath(NestPath *from)
1215 {
1216         NestPath   *newnode = makeNode(NestPath);
1217
1218         /* ----------------
1219          *      copy the node superclass fields
1220          * ----------------
1221          */
1222         CopyPathFields((Path *) from, (Path *) newnode);
1223         CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1224
1225         return newnode;
1226 }
1227
1228 /* ----------------
1229  *              _copyMergePath
1230  * ----------------
1231  */
1232 static MergePath *
1233 _copyMergePath(MergePath *from)
1234 {
1235         MergePath  *newnode = makeNode(MergePath);
1236
1237         /* ----------------
1238          *      copy the node superclass fields
1239          * ----------------
1240          */
1241         CopyPathFields((Path *) from, (Path *) newnode);
1242         CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1243
1244         /* ----------------
1245          *      copy the remainder of the node
1246          * ----------------
1247          */
1248         Node_Copy(from, newnode, path_mergeclauses);
1249         Node_Copy(from, newnode, outersortkeys);
1250         Node_Copy(from, newnode, innersortkeys);
1251
1252         return newnode;
1253 }
1254
1255 /* ----------------
1256  *              _copyHashPath
1257  * ----------------
1258  */
1259 static HashPath *
1260 _copyHashPath(HashPath *from)
1261 {
1262         HashPath   *newnode = makeNode(HashPath);
1263
1264         /* ----------------
1265          *      copy the node superclass fields
1266          * ----------------
1267          */
1268         CopyPathFields((Path *) from, (Path *) newnode);
1269         CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1270
1271         /* ----------------
1272          *      copy remainder of node
1273          * ----------------
1274          */
1275         Node_Copy(from, newnode, path_hashclauses);
1276
1277         return newnode;
1278 }
1279
1280 /* ----------------
1281  *              _copyPathKeyItem
1282  * ----------------
1283  */
1284 static PathKeyItem *
1285 _copyPathKeyItem(PathKeyItem *from)
1286 {
1287         PathKeyItem *newnode = makeNode(PathKeyItem);
1288
1289         /* ----------------
1290          *      copy remainder of node
1291          * ----------------
1292          */
1293         Node_Copy(from, newnode, key);
1294         newnode->sortop = from->sortop;
1295
1296         return newnode;
1297 }
1298
1299 /* ----------------
1300  *              _copyRestrictInfo
1301  * ----------------
1302  */
1303 static RestrictInfo *
1304 _copyRestrictInfo(RestrictInfo *from)
1305 {
1306         RestrictInfo *newnode = makeNode(RestrictInfo);
1307
1308         /* ----------------
1309          *      copy remainder of node
1310          * ----------------
1311          */
1312         Node_Copy(from, newnode, clause);
1313         Node_Copy(from, newnode, subclauseindices);
1314         newnode->mergejoinoperator = from->mergejoinoperator;
1315         newnode->left_sortop = from->left_sortop;
1316         newnode->right_sortop = from->right_sortop;
1317         newnode->hashjoinoperator = from->hashjoinoperator;
1318
1319         return newnode;
1320 }
1321
1322 /* ----------------
1323  *              _copyJoinInfo
1324  * ----------------
1325  */
1326 static JoinInfo *
1327 _copyJoinInfo(JoinInfo *from)
1328 {
1329         JoinInfo   *newnode = makeNode(JoinInfo);
1330
1331         /* ----------------
1332          *      copy remainder of node
1333          * ----------------
1334          */
1335         newnode->unjoined_relids = listCopy(from->unjoined_relids);
1336         Node_Copy(from, newnode, jinfo_restrictinfo);
1337
1338         return newnode;
1339 }
1340
1341 static Iter *
1342 _copyIter(Iter *from)
1343 {
1344         Iter       *newnode = makeNode(Iter);
1345
1346         Node_Copy(from, newnode, iterexpr);
1347         newnode->itertype = from->itertype;
1348
1349         return newnode;
1350 }
1351
1352 static Stream *
1353 _copyStream(Stream *from)
1354 {
1355         Stream     *newnode = makeNode(Stream);
1356
1357         newnode->pathptr = from->pathptr;
1358         newnode->cinfo = from->cinfo;
1359         newnode->clausetype = from->clausetype;
1360
1361         newnode->upstream = (StreamPtr) NULL;           /* only copy nodes
1362                                                                                                  * downwards! */
1363         Node_Copy(from, newnode, downstream);
1364         if (newnode->downstream)
1365                 ((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
1366
1367         newnode->groupup = from->groupup;
1368         newnode->groupcost = from->groupcost;
1369         newnode->groupsel = from->groupsel;
1370
1371         return newnode;
1372 }
1373
1374 /* ****************************************************************
1375  *                                      parsenodes.h copy functions
1376  * ****************************************************************
1377  */
1378
1379 static TargetEntry *
1380 _copyTargetEntry(TargetEntry *from)
1381 {
1382         TargetEntry *newnode = makeNode(TargetEntry);
1383
1384         Node_Copy(from, newnode, resdom);
1385         Node_Copy(from, newnode, fjoin);
1386         Node_Copy(from, newnode, expr);
1387         return newnode;
1388 }
1389
1390 static RangeTblEntry *
1391 _copyRangeTblEntry(RangeTblEntry *from)
1392 {
1393         RangeTblEntry *newnode = makeNode(RangeTblEntry);
1394
1395         if (from->relname)
1396                 newnode->relname = pstrdup(from->relname);
1397         Node_Copy(from, newnode, ref);
1398         Node_Copy(from, newnode, eref);
1399         newnode->relid = from->relid;
1400         newnode->inh = from->inh;
1401         newnode->inFromCl = from->inFromCl;
1402         newnode->inJoinSet = from->inJoinSet;
1403         newnode->skipAcl = from->skipAcl;
1404
1405         return newnode;
1406 }
1407
1408 static RowMark *
1409 _copyRowMark(RowMark *from)
1410 {
1411         RowMark    *newnode = makeNode(RowMark);
1412
1413         newnode->rti = from->rti;
1414         newnode->info = from->info;
1415
1416         return newnode;
1417 }
1418
1419 static SortClause *
1420 _copySortClause(SortClause *from)
1421 {
1422         SortClause *newnode = makeNode(SortClause);
1423
1424         newnode->tleSortGroupRef = from->tleSortGroupRef;
1425         newnode->sortop = from->sortop;
1426
1427         return newnode;
1428 }
1429
1430 static A_Const *
1431 _copyAConst(A_Const *from)
1432 {
1433         A_Const    *newnode = makeNode(A_Const);
1434
1435         newnode->val = *((Value *) (copyObject(&(from->val))));
1436         Node_Copy(from, newnode, typename);
1437
1438         return newnode;
1439 }
1440
1441 static TypeName *
1442 _copyTypeName(TypeName *from)
1443 {
1444         TypeName   *newnode = makeNode(TypeName);
1445
1446         if (from->name)
1447                 newnode->name = pstrdup(from->name);
1448         newnode->timezone = from->timezone;
1449         newnode->setof = from->setof;
1450         newnode->typmod = from->typmod;
1451         Node_Copy(from, newnode, arrayBounds);
1452
1453         return newnode;
1454 }
1455
1456 static TypeCast *
1457 _copyTypeCast(TypeCast *from)
1458 {
1459         TypeCast   *newnode = makeNode(TypeCast);
1460
1461         Node_Copy(from, newnode, arg);
1462         Node_Copy(from, newnode, typename);
1463
1464         return newnode;
1465 }
1466
1467 static Query *
1468 _copyQuery(Query *from)
1469 {
1470         Query      *newnode = makeNode(Query);
1471
1472         newnode->commandType = from->commandType;
1473         Node_Copy(from, newnode, utilityStmt);
1474         newnode->resultRelation = from->resultRelation;
1475         if (from->into)
1476                 newnode->into = pstrdup(from->into);
1477         newnode->isPortal = from->isPortal;
1478         newnode->isBinary = from->isBinary;
1479         newnode->isTemp = from->isTemp;
1480         newnode->unionall = from->unionall;
1481         newnode->hasAggs = from->hasAggs;
1482         newnode->hasSubLinks = from->hasSubLinks;
1483
1484         Node_Copy(from, newnode, rtable);
1485         Node_Copy(from, newnode, targetList);
1486         Node_Copy(from, newnode, qual);
1487         Node_Copy(from, newnode, rowMark);
1488
1489         Node_Copy(from, newnode, distinctClause);
1490         Node_Copy(from, newnode, sortClause);
1491         Node_Copy(from, newnode, groupClause);
1492         Node_Copy(from, newnode, havingQual);
1493
1494         /* why is intersectClause missing? */
1495         Node_Copy(from, newnode, unionClause);
1496
1497         Node_Copy(from, newnode, limitOffset);
1498         Node_Copy(from, newnode, limitCount);
1499
1500         /*
1501          * We do not copy the planner internal fields: base_rel_list,
1502          * join_rel_list, equi_key_list, query_pathkeys. Not entirely clear if
1503          * this is right?
1504          */
1505
1506         return newnode;
1507 }
1508
1509 static ClosePortalStmt *
1510 _copyClosePortalStmt(ClosePortalStmt *from)
1511 {
1512         ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1513
1514         if (from->portalname)
1515                 newnode->portalname = pstrdup(from->portalname);
1516
1517         return newnode;
1518 }
1519
1520 static TruncateStmt *
1521 _copyTruncateStmt(TruncateStmt *from)
1522 {
1523         TruncateStmt *newnode = makeNode(TruncateStmt);
1524
1525         newnode->relName = pstrdup(from->relName);
1526
1527         return newnode;
1528 }
1529
1530 static NotifyStmt *
1531 _copyNotifyStmt(NotifyStmt *from)
1532 {
1533         NotifyStmt *newnode = makeNode(NotifyStmt);
1534
1535         if (from->relname)
1536                 newnode->relname = pstrdup(from->relname);
1537
1538         return newnode;
1539 }
1540
1541 static ListenStmt *
1542 _copyListenStmt(ListenStmt *from)
1543 {
1544         ListenStmt *newnode = makeNode(ListenStmt);
1545
1546         if (from->relname)
1547                 newnode->relname = pstrdup(from->relname);
1548
1549         return newnode;
1550 }
1551
1552 static UnlistenStmt *
1553 _copyUnlistenStmt(UnlistenStmt *from)
1554 {
1555         UnlistenStmt *newnode = makeNode(UnlistenStmt);
1556
1557         if (from->relname)
1558                 newnode->relname = pstrdup(from->relname);
1559
1560         return newnode;
1561 }
1562
1563 static TransactionStmt *
1564 _copyTransactionStmt(TransactionStmt *from)
1565 {
1566         TransactionStmt *newnode = makeNode(TransactionStmt);
1567
1568         newnode->command = from->command;
1569
1570         return newnode;
1571 }
1572
1573 static LoadStmt *
1574 _copyLoadStmt(LoadStmt *from)
1575 {
1576         LoadStmt   *newnode = makeNode(LoadStmt);
1577
1578         if (from->filename)
1579                 newnode->filename = pstrdup(from->filename);
1580
1581         return newnode;
1582 }
1583
1584 static VariableSetStmt *
1585 _copyVariableSetStmt(VariableSetStmt *from)
1586 {
1587         VariableSetStmt *newnode = makeNode(VariableSetStmt);
1588
1589         if (from->name)
1590                 newnode->name = pstrdup(from->name);
1591         if (from->value)
1592                 newnode->value = pstrdup(from->value);
1593
1594         return newnode;
1595 }
1596
1597 static VariableResetStmt *
1598 _copyVariableResetStmt(VariableResetStmt *from)
1599 {
1600         VariableResetStmt *newnode = makeNode(VariableResetStmt);
1601
1602         if (from->name)
1603                 newnode->name = pstrdup(from->name);
1604
1605         return newnode;
1606 }
1607
1608 static LockStmt *
1609 _copyLockStmt(LockStmt *from)
1610 {
1611         LockStmt   *newnode = makeNode(LockStmt);
1612
1613         if (from->relname)
1614                 newnode->relname = pstrdup(from->relname);
1615         newnode->mode = from->mode;
1616
1617         return newnode;
1618 }
1619
1620
1621 /* ****************************************************************
1622  *                                      pg_list.h copy functions
1623  * ****************************************************************
1624  */
1625
1626 static Value *
1627 _copyValue(Value *from)
1628 {
1629         Value      *newnode = makeNode(Value);
1630
1631         newnode->type = from->type;
1632         switch (from->type)
1633         {
1634                 case T_Integer:
1635                         newnode->val.ival = from->val.ival;
1636                         break;
1637                 case T_Float:
1638                 case T_String:
1639                         newnode->val.str = pstrdup(from->val.str);
1640                         break;
1641                 default:
1642                         break;
1643         }
1644         return newnode;
1645 }
1646
1647 /* ----------------
1648  *              copyObject returns a copy of the node or list. If it is a list, it
1649  *              recursively copies its items.
1650  * ----------------
1651  */
1652 void *
1653 copyObject(void *from)
1654 {
1655         void       *retval;
1656
1657         if (from == NULL)
1658                 return NULL;
1659         switch (nodeTag(from))
1660         {
1661
1662                         /*
1663                          * PLAN NODES
1664                          */
1665                 case T_Plan:
1666                         retval = _copyPlan(from);
1667                         break;
1668                 case T_Result:
1669                         retval = _copyResult(from);
1670                         break;
1671                 case T_Append:
1672                         retval = _copyAppend(from);
1673                         break;
1674                 case T_Scan:
1675                         retval = _copyScan(from);
1676                         break;
1677                 case T_SeqScan:
1678                         retval = _copySeqScan(from);
1679                         break;
1680                 case T_IndexScan:
1681                         retval = _copyIndexScan(from);
1682                         break;
1683                 case T_TidScan:
1684                         retval = _copyTidScan(from);
1685                         break;
1686                 case T_Join:
1687                         retval = _copyJoin(from);
1688                         break;
1689                 case T_NestLoop:
1690                         retval = _copyNestLoop(from);
1691                         break;
1692                 case T_MergeJoin:
1693                         retval = _copyMergeJoin(from);
1694                         break;
1695                 case T_HashJoin:
1696                         retval = _copyHashJoin(from);
1697                         break;
1698                 case T_Noname:
1699                         retval = _copyNoname(from);
1700                         break;
1701                 case T_Material:
1702                         retval = _copyMaterial(from);
1703                         break;
1704                 case T_Sort:
1705                         retval = _copySort(from);
1706                         break;
1707                 case T_Group:
1708                         retval = _copyGroup(from);
1709                         break;
1710                 case T_Agg:
1711                         retval = _copyAgg(from);
1712                         break;
1713                 case T_GroupClause:
1714                         retval = _copyGroupClause(from);
1715                         break;
1716                 case T_Unique:
1717                         retval = _copyUnique(from);
1718                         break;
1719                 case T_Hash:
1720                         retval = _copyHash(from);
1721                         break;
1722                 case T_SubPlan:
1723                         retval = _copySubPlan(from);
1724                         break;
1725
1726                         /*
1727                          * PRIMITIVE NODES
1728                          */
1729                 case T_Resdom:
1730                         retval = _copyResdom(from);
1731                         break;
1732                 case T_Fjoin:
1733                         retval = _copyFjoin(from);
1734                         break;
1735                 case T_Expr:
1736                         retval = _copyExpr(from);
1737                         break;
1738                 case T_Var:
1739                         retval = _copyVar(from);
1740                         break;
1741                 case T_Attr:
1742                         retval = _copyAttr(from);
1743                         break;
1744                 case T_Oper:
1745                         retval = _copyOper(from);
1746                         break;
1747                 case T_Const:
1748                         retval = _copyConst(from);
1749                         break;
1750                 case T_Param:
1751                         retval = _copyParam(from);
1752                         break;
1753                 case T_Func:
1754                         retval = _copyFunc(from);
1755                         break;
1756                 case T_Array:
1757                         retval = _copyArray(from);
1758                         break;
1759                 case T_ArrayRef:
1760                         retval = _copyArrayRef(from);
1761                         break;
1762                 case T_Aggref:
1763                         retval = _copyAggref(from);
1764                         break;
1765                 case T_SubLink:
1766                         retval = _copySubLink(from);
1767                         break;
1768                 case T_RelabelType:
1769                         retval = _copyRelabelType(from);
1770                         break;
1771                 case T_CaseExpr:
1772                         retval = _copyCaseExpr(from);
1773                         break;
1774                 case T_CaseWhen:
1775                         retval = _copyCaseWhen(from);
1776                         break;
1777
1778                         /*
1779                          * RELATION NODES
1780                          */
1781                 case T_RelOptInfo:
1782                         retval = _copyRelOptInfo(from);
1783                         break;
1784                 case T_Path:
1785                         retval = _copyPath(from);
1786                         break;
1787                 case T_IndexPath:
1788                         retval = _copyIndexPath(from);
1789                         break;
1790                 case T_TidPath:
1791                         retval = _copyTidPath(from);
1792                         break;
1793                 case T_NestPath:
1794                         retval = _copyNestPath(from);
1795                         break;
1796                 case T_MergePath:
1797                         retval = _copyMergePath(from);
1798                         break;
1799                 case T_HashPath:
1800                         retval = _copyHashPath(from);
1801                         break;
1802                 case T_PathKeyItem:
1803                         retval = _copyPathKeyItem(from);
1804                         break;
1805                 case T_RestrictInfo:
1806                         retval = _copyRestrictInfo(from);
1807                         break;
1808                 case T_JoinInfo:
1809                         retval = _copyJoinInfo(from);
1810                         break;
1811                 case T_Iter:
1812                         retval = _copyIter(from);
1813                         break;
1814                 case T_Stream:
1815                         retval = _copyStream(from);
1816                         break;
1817                 case T_IndexOptInfo:
1818                         retval = _copyIndexOptInfo(from);
1819                         break;
1820
1821                         /*
1822                          * PARSE NODES
1823                          */
1824                 case T_TargetEntry:
1825                         retval = _copyTargetEntry(from);
1826                         break;
1827                 case T_RangeTblEntry:
1828                         retval = _copyRangeTblEntry(from);
1829                         break;
1830                 case T_RowMark:
1831                         retval = _copyRowMark(from);
1832                         break;
1833                 case T_SortClause:
1834                         retval = _copySortClause(from);
1835                         break;
1836                 case T_A_Const:
1837                         retval = _copyAConst(from);
1838                         break;
1839                 case T_TypeName:
1840                         retval = _copyTypeName(from);
1841                         break;
1842                 case T_TypeCast:
1843                         retval = _copyTypeCast(from);
1844                         break;
1845                 case T_Query:
1846                         retval = _copyQuery(from);
1847                         break;
1848                 case T_ClosePortalStmt:
1849                         retval = _copyClosePortalStmt(from);
1850                         break;
1851                 case T_TruncateStmt:
1852                         retval = _copyTruncateStmt(from);
1853                         break;
1854                 case T_NotifyStmt:
1855                         retval = _copyNotifyStmt(from);
1856                         break;
1857                 case T_ListenStmt:
1858                         retval = _copyListenStmt(from);
1859                         break;
1860                 case T_UnlistenStmt:
1861                         retval = _copyUnlistenStmt(from);
1862                         break;
1863                 case T_TransactionStmt:
1864                         retval = _copyTransactionStmt(from);
1865                         break;
1866                 case T_LoadStmt:
1867                         retval = _copyLoadStmt(from);
1868                         break;
1869                 case T_VariableSetStmt:
1870                         retval = _copyVariableSetStmt(from);
1871                         break;
1872                 case T_VariableResetStmt:
1873                         retval = _copyVariableResetStmt(from);
1874                         break;
1875                 case T_LockStmt:
1876                         retval = _copyLockStmt(from);
1877                         break;
1878
1879                         /*
1880                          * VALUE NODES
1881                          */
1882                 case T_Integer:
1883                 case T_Float:
1884                 case T_String:
1885                         retval = _copyValue(from);
1886                         break;
1887                 case T_List:
1888                         {
1889                                 List       *list = from,
1890                                                    *l,
1891                                                    *nl;
1892
1893                                 /* rather ugly coding for speed... */
1894                                 /* Note the input list cannot be NIL if we got here. */
1895                                 nl = lcons(copyObject(lfirst(list)), NIL);
1896                                 retval = nl;
1897
1898                                 foreach(l, lnext(list))
1899                                 {
1900                                         lnext(nl) = lcons(copyObject(lfirst(l)), NIL);
1901                                         nl = lnext(nl);
1902                                 }
1903                         }
1904                         break;
1905                 default:
1906                         elog(ERROR, "copyObject: don't know how to copy %d", nodeTag(from));
1907                         retval = from;
1908                         break;
1909         }
1910         return retval;
1911 }