~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/backend/nodes/copyfuncs.c

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

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