copyfuncs.c 58.1 KB
Newer Older
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
B
Bruce Momjian 已提交
7
 * plan trees.	We do not support copying executor state trees; there
8 9 10 11
 * is no need for that, and no point in maintaining all the code that
 * would be needed.  We also do not support copying Path trees, mainly
 * because the circular linkages between RelOptInfo and Path nodes can't
 * be handled easily in a simple depth-first traversal.
12 13
 *
 *
B
Bruce Momjian 已提交
14
 * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
B
Add:  
Bruce Momjian 已提交
15
 * Portions Copyright (c) 1994, Regents of the University of California
16 17
 *
 * IDENTIFICATION
18
 *	  $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.293 2004/11/05 19:15:59 tgl Exp $
19 20 21 22 23 24
 *
 *-------------------------------------------------------------------------
 */

#include "postgres.h"

25 26 27
#include "nodes/parsenodes.h"
#include "nodes/plannodes.h"
#include "nodes/relation.h"
28
#include "utils/datum.h"
29 30 31


/*
32
 * Macros to simplify copying of different kinds of fields.  Use these
B
Bruce Momjian 已提交
33
 * wherever possible to reduce the chance for silly typos.	Note that these
34 35
 * hard-wire the convention that the local variables in a Copy routine are
 * named 'newnode' and 'from'.
36
 */
37 38 39 40 41 42 43 44 45

/* Copy a simple scalar field (int, float, bool, enum, etc) */
#define COPY_SCALAR_FIELD(fldname) \
	(newnode->fldname = from->fldname)

/* Copy a field that is a pointer to some kind of Node or Node tree */
#define COPY_NODE_FIELD(fldname) \
	(newnode->fldname = copyObject(from->fldname))

46 47 48 49
/* Copy a field that is a pointer to a Bitmapset */
#define COPY_BITMAPSET_FIELD(fldname) \
	(newnode->fldname = bms_copy(from->fldname))

50 51 52 53 54 55 56 57 58 59 60 61
/* Copy a field that is a pointer to a C string, or perhaps NULL */
#define COPY_STRING_FIELD(fldname) \
	(newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)

/* Copy a field that is a pointer to a simple palloc'd object of size sz */
#define COPY_POINTER_FIELD(fldname, sz) \
	do { \
		Size	_size = (sz); \
		newnode->fldname = palloc(_size); \
		memcpy(newnode->fldname, from->fldname, _size); \
	} while (0)

62 63

/* ****************************************************************
64
 *					 plannodes.h copy functions
65 66 67
 * ****************************************************************
 */

68 69
/*
 * CopyPlanFields
70
 *
71 72
 *		This function copies the fields of the Plan node.  It is used by
 *		all the copy functions for classes which inherit from Plan.
73 74
 */
static void
75
CopyPlanFields(Plan *from, Plan *newnode)
76
{
77 78 79 80 81 82 83 84
	COPY_SCALAR_FIELD(startup_cost);
	COPY_SCALAR_FIELD(total_cost);
	COPY_SCALAR_FIELD(plan_rows);
	COPY_SCALAR_FIELD(plan_width);
	COPY_NODE_FIELD(targetlist);
	COPY_NODE_FIELD(qual);
	COPY_NODE_FIELD(lefttree);
	COPY_NODE_FIELD(righttree);
85
	COPY_NODE_FIELD(initPlan);
86 87
	COPY_BITMAPSET_FIELD(extParam);
	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 103 104
	 */
	CopyPlanFields(from, newnode);

	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 120
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

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 *
B
Bruce Momjian 已提交
133
_copyAppend(Append *from)
134
{
135
	Append	   *newnode = makeNode(Append);
136

137 138
	/*
	 * copy node superclass fields
139 140 141
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

142 143
	/*
	 * copy remainder of node
144
	 */
145 146
	COPY_NODE_FIELD(appendplans);
	COPY_SCALAR_FIELD(isTarget);
147 148

	return newnode;
149 150 151
}


152 153
/*
 * CopyScanFields
154
 *
155 156
 *		This function copies the fields of the Scan node.  It is used by
 *		all the copy functions for classes which inherit from Scan.
157 158
 */
static void
159
CopyScanFields(Scan *from, Scan *newnode)
160
{
161 162 163
	CopyPlanFields((Plan *) from, (Plan *) newnode);

	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
	 */
B
Bruce Momjian 已提交
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 194 195
	 */
	CopyScanFields((Scan *) from, (Scan *) newnode);

	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 210
	 */
	CopyScanFields((Scan *) from, (Scan *) newnode);

211 212
	/*
	 * copy remainder of node
213
	 */
214
	COPY_NODE_FIELD(indxid);
215 216
	COPY_NODE_FIELD(indxqual);
	COPY_NODE_FIELD(indxqualorig);
217 218 219
	COPY_NODE_FIELD(indxstrategy);
	COPY_NODE_FIELD(indxsubtype);
	COPY_NODE_FIELD(indxlossy);
220
	COPY_SCALAR_FIELD(indxorderdir);
221 222

	return newnode;
223 224
}

225 226
/*
 * _copyTidScan
227 228 229 230
 */
static TidScan *
_copyTidScan(TidScan *from)
{
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 242
	COPY_NODE_FIELD(tideval);

243 244 245
	return newnode;
}

246 247
/*
 * _copySubqueryScan
248 249 250 251
 */
static SubqueryScan *
_copySubqueryScan(SubqueryScan *from)
{
B
Bruce Momjian 已提交
252
	SubqueryScan *newnode = makeNode(SubqueryScan);
253

254 255
	/*
	 * copy node superclass fields
256 257 258
	 */
	CopyScanFields((Scan *) from, (Scan *) newnode);

259 260
	/*
	 * copy remainder of node
261
	 */
262
	COPY_NODE_FIELD(subplan);
263 264 265 266

	return newnode;
}

267 268
/*
 * _copyFunctionScan
269 270 271 272 273 274 275 276 277 278 279 280 281
 */
static FunctionScan *
_copyFunctionScan(FunctionScan *from)
{
	FunctionScan *newnode = makeNode(FunctionScan);

	/*
	 * copy node superclass fields
	 */
	CopyScanFields((Scan *) from, (Scan *) newnode);

	return newnode;
}
282

283 284
/*
 * CopyJoinFields
285
 *
286 287
 *		This function copies the fields of the Join node.  It is used by
 *		all the copy functions for classes which inherit from Join.
288 289
 */
static void
290
CopyJoinFields(Join *from, Join *newnode)
291
{
292 293 294 295
	CopyPlanFields((Plan *) from, (Plan *) newnode);

	COPY_SCALAR_FIELD(jointype);
	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 311 312
	 */
	CopyJoinFields(from, newnode);

	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 328 329
	 */
	CopyJoinFields((Join *) from, (Join *) newnode);

	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 345
	 */
	CopyJoinFields((Join *) from, (Join *) newnode);

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 366
	 */
	CopyJoinFields((Join *) from, (Join *) newnode);

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 388 389
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

	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 407 408
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
	COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
409 410

	return newnode;
411 412
}

V
Vadim B. Mikheev 已提交
413

414 415
/*
 * _copyGroup
V
Vadim B. Mikheev 已提交
416 417 418 419 420
 */
static Group *
_copyGroup(Group *from)
{
	Group	   *newnode = makeNode(Group);
421

V
Vadim B. Mikheev 已提交
422
	CopyPlanFields((Plan *) from, (Plan *) newnode);
B
Bruce Momjian 已提交
423

424 425
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
V
Vadim B. Mikheev 已提交
426 427 428 429

	return newnode;
}

430 431
/*
 * _copyAgg
432
 */
433
static Agg *
B
Bruce Momjian 已提交
434
_copyAgg(Agg *from)
435
{
436
	Agg		   *newnode = makeNode(Agg);
437 438 439

	CopyPlanFields((Plan *) from, (Plan *) newnode);

440 441
	COPY_SCALAR_FIELD(aggstrategy);
	COPY_SCALAR_FIELD(numCols);
442
	if (from->numCols > 0)
443 444
		COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
	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 461
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

462 463
	/*
	 * copy remainder of node
464
	 */
465 466
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
467 468

	return newnode;
469 470
}

471
/*
472
 * _copyHash
473
 */
474 475
static Hash *
_copyHash(Hash *from)
476
{
477
	Hash	   *newnode = makeNode(Hash);
478

479 480
	/*
	 * copy node superclass fields
481 482 483
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

484 485
	/*
	 * copy remainder of node
486 487 488 489
	 */

	return newnode;
}
490

491
/*
492
 * _copySetOp
493
 */
494 495
static SetOp *
_copySetOp(SetOp *from)
496
{
497
	SetOp	   *newnode = makeNode(SetOp);
498

499 500
	/*
	 * copy node superclass fields
501 502 503
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

504 505
	/*
	 * copy remainder of node
506
	 */
507 508 509 510
	COPY_SCALAR_FIELD(cmd);
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
	COPY_SCALAR_FIELD(flagColIdx);
511 512 513 514

	return newnode;
}

515
/*
516
 * _copyLimit
517
 */
518 519
static Limit *
_copyLimit(Limit *from)
520
{
521
	Limit	   *newnode = makeNode(Limit);
522

523 524
	/*
	 * copy node superclass fields
525 526 527
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

528 529
	/*
	 * copy remainder of node
530
	 */
531 532
	COPY_NODE_FIELD(limitOffset);
	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 551 552 553 554
	COPY_SCALAR_FIELD(resno);
	COPY_SCALAR_FIELD(restype);
	COPY_SCALAR_FIELD(restypmod);
	COPY_STRING_FIELD(resname);
	COPY_SCALAR_FIELD(ressortgroupref);
555 556
	COPY_SCALAR_FIELD(resorigtbl);
	COPY_SCALAR_FIELD(resorigcol);
557
	COPY_SCALAR_FIELD(resjunk);
558 559

	return newnode;
560 561
}

562 563 564
/*
 * _copyAlias
 */
565 566 567 568
static Alias *
_copyAlias(Alias *from)
{
	Alias	   *newnode = makeNode(Alias);
569

570 571
	COPY_STRING_FIELD(aliasname);
	COPY_NODE_FIELD(colnames);
572

573 574
	return newnode;
}
575

576 577 578
/*
 * _copyRangeVar
 */
579 580 581 582 583 584 585 586 587 588 589
static RangeVar *
_copyRangeVar(RangeVar *from)
{
	RangeVar   *newnode = makeNode(RangeVar);

	COPY_STRING_FIELD(catalogname);
	COPY_STRING_FIELD(schemaname);
	COPY_STRING_FIELD(relname);
	COPY_SCALAR_FIELD(inhOpt);
	COPY_SCALAR_FIELD(istemp);
	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
B
Bruce Momjian 已提交
596
 * should never actually get instantiated.	Also, since it has no common
597 598
 * fields except NodeTag, there's no need for a helper routine to factor
 * 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 610 611 612 613 614 615
	COPY_SCALAR_FIELD(varno);
	COPY_SCALAR_FIELD(varattno);
	COPY_SCALAR_FIELD(vartype);
	COPY_SCALAR_FIELD(vartypmod);
	COPY_SCALAR_FIELD(varlevelsup);
	COPY_SCALAR_FIELD(varnoold);
	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 629
	COPY_SCALAR_FIELD(consttype);
	COPY_SCALAR_FIELD(constlen);
630

631
	if (from->constbyval || from->constisnull)
632
	{
633 634 635
		/*
		 * passed by value so just copy the datum. Also, don't try to copy
		 * 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 645 646
		newnode->constvalue = datumCopy(from->constvalue,
										from->constbyval,
										from->constlen);
647
	}
648

649 650
	COPY_SCALAR_FIELD(constisnull);
	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 664 665 666
	COPY_SCALAR_FIELD(paramkind);
	COPY_SCALAR_FIELD(paramid);
	COPY_STRING_FIELD(paramname);
	COPY_SCALAR_FIELD(paramtype);
667 668

	return newnode;
669 670
}

671
/*
672
 * _copyAggref
673
 */
674 675
static Aggref *
_copyAggref(Aggref *from)
676
{
677 678 679 680 681
	Aggref	   *newnode = makeNode(Aggref);

	COPY_SCALAR_FIELD(aggfnoid);
	COPY_SCALAR_FIELD(aggtype);
	COPY_NODE_FIELD(target);
682
	COPY_SCALAR_FIELD(agglevelsup);
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
	COPY_SCALAR_FIELD(aggstar);
	COPY_SCALAR_FIELD(aggdistinct);

	return newnode;
}

/*
 * _copyArrayRef
 */
static ArrayRef *
_copyArrayRef(ArrayRef *from)
{
	ArrayRef   *newnode = makeNode(ArrayRef);

	COPY_SCALAR_FIELD(refrestype);
698 699
	COPY_SCALAR_FIELD(refarraytype);
	COPY_SCALAR_FIELD(refelemtype);
700 701 702 703 704 705 706 707 708 709 710 711
	COPY_NODE_FIELD(refupperindexpr);
	COPY_NODE_FIELD(reflowerindexpr);
	COPY_NODE_FIELD(refexpr);
	COPY_NODE_FIELD(refassgnexpr);

	return newnode;
}

/*
 * _copyFuncExpr
 */
static FuncExpr *
712
_copyFuncExpr(FuncExpr *from)
713
{
B
Bruce Momjian 已提交
714
	FuncExpr   *newnode = makeNode(FuncExpr);
715

716 717 718 719
	COPY_SCALAR_FIELD(funcid);
	COPY_SCALAR_FIELD(funcresulttype);
	COPY_SCALAR_FIELD(funcretset);
	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 734 735 736 737 738 739 740 741 742
	COPY_SCALAR_FIELD(opno);
	COPY_SCALAR_FIELD(opfuncid);
	COPY_SCALAR_FIELD(opresulttype);
	COPY_SCALAR_FIELD(opretset);
	COPY_NODE_FIELD(args);

	return newnode;
}

/*
743
 * _copyDistinctExpr (same as OpExpr)
744 745
 */
static DistinctExpr *
746
_copyDistinctExpr(DistinctExpr *from)
747
{
B
Bruce Momjian 已提交
748
	DistinctExpr *newnode = makeNode(DistinctExpr);
749 750 751 752 753 754 755 756 757 758

	COPY_SCALAR_FIELD(opno);
	COPY_SCALAR_FIELD(opfuncid);
	COPY_SCALAR_FIELD(opresulttype);
	COPY_SCALAR_FIELD(opretset);
	COPY_NODE_FIELD(args);

	return newnode;
}

759 760 761 762
/*
 * _copyScalarArrayOpExpr
 */
static ScalarArrayOpExpr *
763
_copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
764
{
B
Bruce Momjian 已提交
765
	ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
766 767 768 769 770 771 772 773 774

	COPY_SCALAR_FIELD(opno);
	COPY_SCALAR_FIELD(opfuncid);
	COPY_SCALAR_FIELD(useOr);
	COPY_NODE_FIELD(args);

	return newnode;
}

775 776 777 778
/*
 * _copyBoolExpr
 */
static BoolExpr *
779
_copyBoolExpr(BoolExpr *from)
780
{
B
Bruce Momjian 已提交
781
	BoolExpr   *newnode = makeNode(BoolExpr);
782 783 784

	COPY_SCALAR_FIELD(boolop);
	COPY_NODE_FIELD(args);
785 786

	return newnode;
787 788
}

789 790
/*
 * _copySubLink
791 792 793 794
 */
static SubLink *
_copySubLink(SubLink *from)
{
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 805 806

	return newnode;
}

807
/*
808
 * _copySubPlan
809
 */
810 811
static SubPlan *
_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 820 821
	COPY_NODE_FIELD(plan);
	COPY_SCALAR_FIELD(plan_id);
	COPY_NODE_FIELD(rtable);
822 823
	COPY_SCALAR_FIELD(useHashTable);
	COPY_SCALAR_FIELD(unknownEqFalse);
824 825
	COPY_NODE_FIELD(setParam);
	COPY_NODE_FIELD(parParam);
826 827 828 829 830
	COPY_NODE_FIELD(args);

	return newnode;
}

831 832
/*
 * _copyFieldSelect
833 834 835 836 837 838
 */
static FieldSelect *
_copyFieldSelect(FieldSelect *from)
{
	FieldSelect *newnode = makeNode(FieldSelect);

839 840 841 842
	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(fieldnum);
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
843 844 845 846

	return newnode;
}

847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862
/*
 * _copyFieldStore
 */
static FieldStore *
_copyFieldStore(FieldStore *from)
{
	FieldStore *newnode = makeNode(FieldStore);

	COPY_NODE_FIELD(arg);
	COPY_NODE_FIELD(newvals);
	COPY_NODE_FIELD(fieldnums);
	COPY_SCALAR_FIELD(resulttype);

	return newnode;
}

863 864
/*
 * _copyRelabelType
865 866 867 868
 */
static RelabelType *
_copyRelabelType(RelabelType *from)
{
869
	RelabelType *newnode = makeNode(RelabelType);
870

871 872 873 874
	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
	COPY_SCALAR_FIELD(relabelformat);
875 876 877 878

	return newnode;
}

879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
/*
 * _copyCaseExpr
 */
static CaseExpr *
_copyCaseExpr(CaseExpr *from)
{
	CaseExpr   *newnode = makeNode(CaseExpr);

	COPY_SCALAR_FIELD(casetype);
	COPY_NODE_FIELD(arg);
	COPY_NODE_FIELD(args);
	COPY_NODE_FIELD(defresult);

	return newnode;
}

/*
 * _copyCaseWhen
 */
static CaseWhen *
_copyCaseWhen(CaseWhen *from)
{
	CaseWhen   *newnode = makeNode(CaseWhen);

	COPY_NODE_FIELD(expr);
	COPY_NODE_FIELD(result);

	return newnode;
}

909 910 911 912 913 914 915 916 917 918 919 920 921 922
/*
 * _copyCaseTestExpr
 */
static CaseTestExpr *
_copyCaseTestExpr(CaseTestExpr *from)
{
	CaseTestExpr *newnode = makeNode(CaseTestExpr);

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);

	return newnode;
}

923 924 925 926
/*
 * _copyArrayExpr
 */
static ArrayExpr *
927
_copyArrayExpr(ArrayExpr *from)
928
{
B
Bruce Momjian 已提交
929
	ArrayExpr  *newnode = makeNode(ArrayExpr);
930 931 932 933

	COPY_SCALAR_FIELD(array_typeid);
	COPY_SCALAR_FIELD(element_typeid);
	COPY_NODE_FIELD(elements);
934
	COPY_SCALAR_FIELD(multidims);
935 936 937 938

	return newnode;
}

939 940 941 942 943 944
/*
 * _copyRowExpr
 */
static RowExpr *
_copyRowExpr(RowExpr *from)
{
B
Bruce Momjian 已提交
945
	RowExpr    *newnode = makeNode(RowExpr);
946 947 948 949 950 951 952 953

	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(row_typeid);
	COPY_SCALAR_FIELD(row_format);

	return newnode;
}

954 955 956 957
/*
 * _copyCoalesceExpr
 */
static CoalesceExpr *
958
_copyCoalesceExpr(CoalesceExpr *from)
959 960 961 962 963 964 965 966 967 968 969 970 971
{
	CoalesceExpr *newnode = makeNode(CoalesceExpr);

	COPY_SCALAR_FIELD(coalescetype);
	COPY_NODE_FIELD(args);

	return newnode;
}

/*
 * _copyNullIfExpr (same as OpExpr)
 */
static NullIfExpr *
972
_copyNullIfExpr(NullIfExpr *from)
973
{
B
Bruce Momjian 已提交
974
	NullIfExpr *newnode = makeNode(NullIfExpr);
975 976 977 978 979 980 981 982 983 984

	COPY_SCALAR_FIELD(opno);
	COPY_SCALAR_FIELD(opfuncid);
	COPY_SCALAR_FIELD(opresulttype);
	COPY_SCALAR_FIELD(opretset);
	COPY_NODE_FIELD(args);

	return newnode;
}

985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
/*
 * _copyNullTest
 */
static NullTest *
_copyNullTest(NullTest *from)
{
	NullTest   *newnode = makeNode(NullTest);

	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(nulltesttype);

	return newnode;
}

/*
 * _copyBooleanTest
 */
static BooleanTest *
_copyBooleanTest(BooleanTest *from)
{
	BooleanTest *newnode = makeNode(BooleanTest);

	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(booltesttype);

	return newnode;
}

/*
1014
 * _copyCoerceToDomain
1015
 */
1016
static CoerceToDomain *
1017
_copyCoerceToDomain(CoerceToDomain *from)
1018
{
1019
	CoerceToDomain *newnode = makeNode(CoerceToDomain);
1020 1021

	COPY_NODE_FIELD(arg);
1022 1023 1024
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
	COPY_SCALAR_FIELD(coercionformat);
1025 1026 1027 1028 1029

	return newnode;
}

/*
1030
 * _copyCoerceToDomainValue
1031
 */
1032
static CoerceToDomainValue *
1033
_copyCoerceToDomainValue(CoerceToDomainValue *from)
1034
{
1035
	CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1036 1037 1038 1039 1040 1041 1042

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);

	return newnode;
}

1043 1044 1045 1046
/*
 * _copySetToDefault
 */
static SetToDefault *
1047
_copySetToDefault(SetToDefault *from)
1048 1049 1050 1051 1052 1053 1054 1055 1056
{
	SetToDefault *newnode = makeNode(SetToDefault);

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);

	return newnode;
}

1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
/*
 * _copyTargetEntry
 */
static TargetEntry *
_copyTargetEntry(TargetEntry *from)
{
	TargetEntry *newnode = makeNode(TargetEntry);

	COPY_NODE_FIELD(resdom);
	COPY_NODE_FIELD(expr);

	return newnode;
}

/*
 * _copyRangeTblRef
 */
1074 1075 1076 1077 1078
static RangeTblRef *
_copyRangeTblRef(RangeTblRef *from)
{
	RangeTblRef *newnode = makeNode(RangeTblRef);

1079
	COPY_SCALAR_FIELD(rtindex);
1080 1081 1082 1083

	return newnode;
}

1084 1085 1086
/*
 * _copyJoinExpr
 */
1087 1088 1089
static JoinExpr *
_copyJoinExpr(JoinExpr *from)
{
B
Bruce Momjian 已提交
1090
	JoinExpr   *newnode = makeNode(JoinExpr);
1091

1092 1093 1094 1095 1096 1097 1098 1099
	COPY_SCALAR_FIELD(jointype);
	COPY_SCALAR_FIELD(isNatural);
	COPY_NODE_FIELD(larg);
	COPY_NODE_FIELD(rarg);
	COPY_NODE_FIELD(using);
	COPY_NODE_FIELD(quals);
	COPY_NODE_FIELD(alias);
	COPY_SCALAR_FIELD(rtindex);
T
Thomas G. Lockhart 已提交
1100 1101 1102 1103

	return newnode;
}

1104 1105 1106
/*
 * _copyFromExpr
 */
1107 1108
static FromExpr *
_copyFromExpr(FromExpr *from)
B
Bruce Momjian 已提交
1109
{
1110
	FromExpr   *newnode = makeNode(FromExpr);
B
Bruce Momjian 已提交
1111

1112 1113
	COPY_NODE_FIELD(fromlist);
	COPY_NODE_FIELD(quals);
B
Bruce Momjian 已提交
1114 1115 1116 1117

	return newnode;
}

1118
/* ****************************************************************
1119
 *						relation.h copy functions
1120
 *
1121 1122
 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
 * There are some subsidiary structs that are useful to copy, though.
1123 1124 1125
 * ****************************************************************
 */

1126 1127
/*
 * _copyPathKeyItem
1128
 */
1129 1130
static PathKeyItem *
_copyPathKeyItem(PathKeyItem *from)
1131
{
1132
	PathKeyItem *newnode = makeNode(PathKeyItem);
1133

1134 1135
	COPY_NODE_FIELD(key);
	COPY_SCALAR_FIELD(sortop);
1136 1137

	return newnode;
1138 1139
}

1140 1141
/*
 * _copyRestrictInfo
1142
 */
1143
static RestrictInfo *
1144
_copyRestrictInfo(RestrictInfo *from)
1145
{
1146
	RestrictInfo *newnode = makeNode(RestrictInfo);
1147

1148
	COPY_NODE_FIELD(clause);
1149 1150 1151
	COPY_SCALAR_FIELD(is_pushed_down);
	COPY_SCALAR_FIELD(valid_everywhere);
	COPY_SCALAR_FIELD(can_join);
1152
	COPY_BITMAPSET_FIELD(clause_relids);
1153 1154
	COPY_BITMAPSET_FIELD(left_relids);
	COPY_BITMAPSET_FIELD(right_relids);
1155
	COPY_NODE_FIELD(orclause);
1156 1157 1158 1159 1160
	COPY_SCALAR_FIELD(eval_cost);
	COPY_SCALAR_FIELD(this_selec);
	COPY_SCALAR_FIELD(mergejoinoperator);
	COPY_SCALAR_FIELD(left_sortop);
	COPY_SCALAR_FIELD(right_sortop);
B
Bruce Momjian 已提交
1161 1162 1163 1164 1165

	/*
	 * Do not copy pathkeys, since they'd not be canonical in a copied
	 * query
	 */
1166 1167
	newnode->left_pathkey = NIL;
	newnode->right_pathkey = NIL;
1168 1169 1170 1171 1172 1173

	COPY_SCALAR_FIELD(left_mergescansel);
	COPY_SCALAR_FIELD(right_mergescansel);
	COPY_SCALAR_FIELD(hashjoinoperator);
	COPY_SCALAR_FIELD(left_bucketsize);
	COPY_SCALAR_FIELD(right_bucketsize);
1174 1175

	return newnode;
1176 1177
}

1178 1179
/*
 * _copyJoinInfo
1180
 */
1181
static JoinInfo *
1182
_copyJoinInfo(JoinInfo *from)
1183
{
1184
	JoinInfo   *newnode = makeNode(JoinInfo);
1185

1186
	COPY_BITMAPSET_FIELD(unjoined_relids);
1187
	COPY_NODE_FIELD(jinfo_restrictinfo);
1188 1189

	return newnode;
1190 1191
}

1192 1193 1194 1195
/*
 * _copyInClauseInfo
 */
static InClauseInfo *
1196
_copyInClauseInfo(InClauseInfo *from)
1197 1198 1199
{
	InClauseInfo *newnode = makeNode(InClauseInfo);

1200 1201
	COPY_BITMAPSET_FIELD(lefthand);
	COPY_BITMAPSET_FIELD(righthand);
1202 1203 1204 1205 1206
	COPY_NODE_FIELD(sub_targetlist);

	return newnode;
}

1207 1208 1209
/* ****************************************************************
 *					parsenodes.h copy functions
 * ****************************************************************
1210 1211 1212
 */

static RangeTblEntry *
1213
_copyRangeTblEntry(RangeTblEntry *from)
1214
{
1215
	RangeTblEntry *newnode = makeNode(RangeTblEntry);
1216

1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227
	COPY_SCALAR_FIELD(rtekind);
	COPY_SCALAR_FIELD(relid);
	COPY_NODE_FIELD(subquery);
	COPY_NODE_FIELD(funcexpr);
	COPY_NODE_FIELD(coldeflist);
	COPY_SCALAR_FIELD(jointype);
	COPY_NODE_FIELD(joinaliasvars);
	COPY_NODE_FIELD(alias);
	COPY_NODE_FIELD(eref);
	COPY_SCALAR_FIELD(inh);
	COPY_SCALAR_FIELD(inFromCl);
1228
	COPY_SCALAR_FIELD(requiredPerms);
1229
	COPY_SCALAR_FIELD(checkAsUser);
1230 1231 1232 1233

	return newnode;
}

1234 1235 1236
static FkConstraint *
_copyFkConstraint(FkConstraint *from)
{
B
Bruce Momjian 已提交
1237
	FkConstraint *newnode = makeNode(FkConstraint);
1238

1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
	COPY_STRING_FIELD(constr_name);
	COPY_NODE_FIELD(pktable);
	COPY_NODE_FIELD(fk_attrs);
	COPY_NODE_FIELD(pk_attrs);
	COPY_SCALAR_FIELD(fk_matchtype);
	COPY_SCALAR_FIELD(fk_upd_action);
	COPY_SCALAR_FIELD(fk_del_action);
	COPY_SCALAR_FIELD(deferrable);
	COPY_SCALAR_FIELD(initdeferred);
	COPY_SCALAR_FIELD(skip_validation);
B
Bruce Momjian 已提交
1249

1250 1251 1252
	return newnode;
}

1253
static SortClause *
1254
_copySortClause(SortClause *from)
1255
{
1256
	SortClause *newnode = makeNode(SortClause);
1257

1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
	COPY_SCALAR_FIELD(tleSortGroupRef);
	COPY_SCALAR_FIELD(sortop);

	return newnode;
}

static GroupClause *
_copyGroupClause(GroupClause *from)
{
	GroupClause *newnode = makeNode(GroupClause);

	COPY_SCALAR_FIELD(tleSortGroupRef);
	COPY_SCALAR_FIELD(sortop);
1271

1272
	return newnode;
1273 1274
}

1275 1276 1277
static A_Expr *
_copyAExpr(A_Expr *from)
{
B
Bruce Momjian 已提交
1278
	A_Expr	   *newnode = makeNode(A_Expr);
1279

1280
	COPY_SCALAR_FIELD(kind);
1281 1282 1283
	COPY_NODE_FIELD(name);
	COPY_NODE_FIELD(lexpr);
	COPY_NODE_FIELD(rexpr);
1284 1285 1286 1287

	return newnode;
}

1288 1289
static ColumnRef *
_copyColumnRef(ColumnRef *from)
1290
{
B
Bruce Momjian 已提交
1291
	ColumnRef  *newnode = makeNode(ColumnRef);
1292

1293
	COPY_NODE_FIELD(fields);
1294

1295
	return newnode;
1296 1297
}

1298 1299
static ParamRef *
_copyParamRef(ParamRef *from)
1300
{
B
Bruce Momjian 已提交
1301
	ParamRef   *newnode = makeNode(ParamRef);
1302

1303
	COPY_SCALAR_FIELD(number);
1304 1305 1306 1307

	return newnode;
}

1308 1309 1310 1311 1312
static A_Const *
_copyAConst(A_Const *from)
{
	A_Const    *newnode = makeNode(A_Const);

1313
	/* This part must duplicate _copyValue */
1314
	COPY_SCALAR_FIELD(val.type);
1315 1316 1317
	switch (from->val.type)
	{
		case T_Integer:
1318
			COPY_SCALAR_FIELD(val.val.ival);
1319 1320 1321 1322
			break;
		case T_Float:
		case T_String:
		case T_BitString:
1323
			COPY_STRING_FIELD(val.val.str);
1324 1325 1326 1327 1328
			break;
		case T_Null:
			/* nothing to do */
			break;
		default:
1329 1330
			elog(ERROR, "unrecognized node type: %d",
				 (int) from->val.type);
1331 1332 1333
			break;
	}

1334
	COPY_NODE_FIELD(typename);
1335 1336 1337 1338

	return newnode;
}

1339 1340 1341
static FuncCall *
_copyFuncCall(FuncCall *from)
{
B
Bruce Momjian 已提交
1342
	FuncCall   *newnode = makeNode(FuncCall);
1343

1344 1345 1346 1347
	COPY_NODE_FIELD(funcname);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(agg_star);
	COPY_SCALAR_FIELD(agg_distinct);
1348 1349 1350 1351 1352 1353 1354

	return newnode;
}

static A_Indices *
_copyAIndices(A_Indices *from)
{
B
Bruce Momjian 已提交
1355
	A_Indices  *newnode = makeNode(A_Indices);
1356

1357 1358
	COPY_NODE_FIELD(lidx);
	COPY_NODE_FIELD(uidx);
1359 1360 1361 1362

	return newnode;
}

1363 1364
static A_Indirection *
_copyA_Indirection(A_Indirection *from)
1365
{
1366
	A_Indirection *newnode = makeNode(A_Indirection);
1367

1368 1369
	COPY_NODE_FIELD(arg);
	COPY_NODE_FIELD(indirection);
1370 1371 1372 1373

	return newnode;
}

1374 1375 1376
static ResTarget *
_copyResTarget(ResTarget *from)
{
B
Bruce Momjian 已提交
1377
	ResTarget  *newnode = makeNode(ResTarget);
1378

1379 1380 1381
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(indirection);
	COPY_NODE_FIELD(val);
1382 1383 1384 1385

	return newnode;
}

1386
static TypeName *
1387
_copyTypeName(TypeName *from)
1388
{
1389
	TypeName   *newnode = makeNode(TypeName);
1390

1391 1392 1393 1394 1395 1396 1397
	COPY_NODE_FIELD(names);
	COPY_SCALAR_FIELD(typeid);
	COPY_SCALAR_FIELD(timezone);
	COPY_SCALAR_FIELD(setof);
	COPY_SCALAR_FIELD(pct_type);
	COPY_SCALAR_FIELD(typmod);
	COPY_NODE_FIELD(arrayBounds);
1398 1399

	return newnode;
1400 1401
}

1402 1403
static SortBy *
_copySortBy(SortBy *from)
1404
{
B
Bruce Momjian 已提交
1405
	SortBy	   *newnode = makeNode(SortBy);
1406

1407
	COPY_SCALAR_FIELD(sortby_kind);
1408 1409
	COPY_NODE_FIELD(useOp);
	COPY_NODE_FIELD(node);
1410 1411 1412 1413 1414 1415 1416

	return newnode;
}

static RangeSubselect *
_copyRangeSubselect(RangeSubselect *from)
{
B
Bruce Momjian 已提交
1417
	RangeSubselect *newnode = makeNode(RangeSubselect);
1418

1419 1420
	COPY_NODE_FIELD(subquery);
	COPY_NODE_FIELD(alias);
1421 1422 1423 1424

	return newnode;
}

1425 1426 1427
static RangeFunction *
_copyRangeFunction(RangeFunction *from)
{
B
Bruce Momjian 已提交
1428
	RangeFunction *newnode = makeNode(RangeFunction);
1429

1430 1431 1432
	COPY_NODE_FIELD(funccallnode);
	COPY_NODE_FIELD(alias);
	COPY_NODE_FIELD(coldeflist);
1433 1434 1435 1436

	return newnode;
}

1437 1438 1439 1440 1441
static TypeCast *
_copyTypeCast(TypeCast *from)
{
	TypeCast   *newnode = makeNode(TypeCast);

1442 1443
	COPY_NODE_FIELD(arg);
	COPY_NODE_FIELD(typename);
1444 1445 1446 1447

	return newnode;
}

1448 1449 1450
static IndexElem *
_copyIndexElem(IndexElem *from)
{
B
Bruce Momjian 已提交
1451
	IndexElem  *newnode = makeNode(IndexElem);
1452

1453
	COPY_STRING_FIELD(name);
1454
	COPY_NODE_FIELD(expr);
1455
	COPY_NODE_FIELD(opclass);
1456 1457 1458 1459 1460 1461 1462

	return newnode;
}

static ColumnDef *
_copyColumnDef(ColumnDef *from)
{
B
Bruce Momjian 已提交
1463
	ColumnDef  *newnode = makeNode(ColumnDef);
1464

1465 1466 1467 1468 1469 1470 1471 1472 1473
	COPY_STRING_FIELD(colname);
	COPY_NODE_FIELD(typename);
	COPY_SCALAR_FIELD(inhcount);
	COPY_SCALAR_FIELD(is_local);
	COPY_SCALAR_FIELD(is_not_null);
	COPY_NODE_FIELD(raw_default);
	COPY_STRING_FIELD(cooked_default);
	COPY_NODE_FIELD(constraints);
	COPY_NODE_FIELD(support);
1474 1475 1476 1477 1478 1479 1480

	return newnode;
}

static Constraint *
_copyConstraint(Constraint *from)
{
B
Bruce Momjian 已提交
1481
	Constraint *newnode = makeNode(Constraint);
1482

1483 1484 1485 1486 1487
	COPY_SCALAR_FIELD(contype);
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(raw_expr);
	COPY_STRING_FIELD(cooked_expr);
	COPY_NODE_FIELD(keys);
1488
	COPY_STRING_FIELD(indexspace);
1489 1490 1491 1492

	return newnode;
}

1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510
static DefElem *
_copyDefElem(DefElem *from)
{
	DefElem    *newnode = makeNode(DefElem);

	COPY_STRING_FIELD(defname);
	COPY_NODE_FIELD(arg);

	return newnode;
}

static Query *
_copyQuery(Query *from)
{
	Query	   *newnode = makeNode(Query);

	COPY_SCALAR_FIELD(commandType);
	COPY_SCALAR_FIELD(querySource);
1511
	COPY_SCALAR_FIELD(canSetTag);
1512 1513 1514
	COPY_NODE_FIELD(utilityStmt);
	COPY_SCALAR_FIELD(resultRelation);
	COPY_NODE_FIELD(into);
1515
	COPY_SCALAR_FIELD(intoHasOids);
1516 1517 1518 1519
	COPY_SCALAR_FIELD(hasAggs);
	COPY_SCALAR_FIELD(hasSubLinks);
	COPY_NODE_FIELD(rtable);
	COPY_NODE_FIELD(jointree);
1520
	COPY_NODE_FIELD(rowMarks);
1521 1522 1523 1524 1525 1526 1527 1528
	COPY_NODE_FIELD(targetList);
	COPY_NODE_FIELD(groupClause);
	COPY_NODE_FIELD(havingQual);
	COPY_NODE_FIELD(distinctClause);
	COPY_NODE_FIELD(sortClause);
	COPY_NODE_FIELD(limitOffset);
	COPY_NODE_FIELD(limitCount);
	COPY_NODE_FIELD(setOperations);
1529
	COPY_NODE_FIELD(resultRelations);
1530 1531
	COPY_NODE_FIELD(in_info_list);
	COPY_SCALAR_FIELD(hasJoinRTEs);
1532

1533
	/*
1534
	 * We do not copy the other planner internal fields: base_rel_list,
B
Bruce Momjian 已提交
1535 1536 1537
	 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. That
	 * would get us into copying RelOptInfo/Path trees, which we don't
	 * want to do.	It is necessary to copy in_info_list and hasJoinRTEs
1538 1539
	 * for the benefit of inheritance_planner(), which may try to copy a
	 * Query in which these are already set.
1540
	 */
1541

1542
	return newnode;
1543 1544
}

1545 1546 1547 1548
static InsertStmt *
_copyInsertStmt(InsertStmt *from)
{
	InsertStmt *newnode = makeNode(InsertStmt);
B
Bruce Momjian 已提交
1549

1550 1551 1552 1553
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(cols);
	COPY_NODE_FIELD(targetList);
	COPY_NODE_FIELD(selectStmt);
1554 1555 1556 1557 1558 1559 1560 1561

	return newnode;
}

static DeleteStmt *
_copyDeleteStmt(DeleteStmt *from)
{
	DeleteStmt *newnode = makeNode(DeleteStmt);
B
Bruce Momjian 已提交
1562

1563 1564
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(whereClause);
1565 1566 1567 1568 1569 1570 1571 1572

	return newnode;
}

static UpdateStmt *
_copyUpdateStmt(UpdateStmt *from)
{
	UpdateStmt *newnode = makeNode(UpdateStmt);
B
Bruce Momjian 已提交
1573

1574 1575 1576 1577
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(targetList);
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(fromClause);
1578 1579 1580 1581 1582 1583 1584 1585

	return newnode;
}

static SelectStmt *
_copySelectStmt(SelectStmt *from)
{
	SelectStmt *newnode = makeNode(SelectStmt);
B
Bruce Momjian 已提交
1586

1587 1588 1589
	COPY_NODE_FIELD(distinctClause);
	COPY_NODE_FIELD(into);
	COPY_NODE_FIELD(intoColNames);
1590
	COPY_SCALAR_FIELD(intoHasOids);
1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603
	COPY_NODE_FIELD(targetList);
	COPY_NODE_FIELD(fromClause);
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(groupClause);
	COPY_NODE_FIELD(havingClause);
	COPY_NODE_FIELD(sortClause);
	COPY_NODE_FIELD(limitOffset);
	COPY_NODE_FIELD(limitCount);
	COPY_NODE_FIELD(forUpdate);
	COPY_SCALAR_FIELD(op);
	COPY_SCALAR_FIELD(all);
	COPY_NODE_FIELD(larg);
	COPY_NODE_FIELD(rarg);
1604 1605 1606 1607

	return newnode;
}

1608 1609 1610 1611
static SetOperationStmt *
_copySetOperationStmt(SetOperationStmt *from)
{
	SetOperationStmt *newnode = makeNode(SetOperationStmt);
B
Bruce Momjian 已提交
1612

1613 1614 1615 1616
	COPY_SCALAR_FIELD(op);
	COPY_SCALAR_FIELD(all);
	COPY_NODE_FIELD(larg);
	COPY_NODE_FIELD(rarg);
1617
	COPY_NODE_FIELD(colTypes);
1618 1619 1620 1621

	return newnode;
}

1622 1623 1624 1625
static AlterTableStmt *
_copyAlterTableStmt(AlterTableStmt *from)
{
	AlterTableStmt *newnode = makeNode(AlterTableStmt);
B
Bruce Momjian 已提交
1626

1627
	COPY_NODE_FIELD(relation);
T
Tom Lane 已提交
1628
	COPY_NODE_FIELD(cmds);
T
Tom Lane 已提交
1629
	COPY_SCALAR_FIELD(relkind);
T
Tom Lane 已提交
1630 1631 1632 1633 1634 1635 1636 1637 1638 1639

	return newnode;
}

static AlterTableCmd *
_copyAlterTableCmd(AlterTableCmd *from)
{
	AlterTableCmd *newnode = makeNode(AlterTableCmd);

	COPY_SCALAR_FIELD(subtype);
1640 1641
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(def);
T
Tom Lane 已提交
1642
	COPY_NODE_FIELD(transform);
1643
	COPY_SCALAR_FIELD(behavior);
1644 1645 1646 1647

	return newnode;
}

B
Bruce Momjian 已提交
1648
static AlterDomainStmt *
1649
_copyAlterDomainStmt(AlterDomainStmt *from)
B
Bruce Momjian 已提交
1650 1651 1652 1653 1654 1655 1656 1657 1658 1659
{
	AlterDomainStmt *newnode = makeNode(AlterDomainStmt);

	COPY_SCALAR_FIELD(subtype);
	COPY_NODE_FIELD(typename);
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(def);
	COPY_SCALAR_FIELD(behavior);

	return newnode;
B
Bruce Momjian 已提交
1660
}
B
Bruce Momjian 已提交
1661

1662 1663
static GrantStmt *
_copyGrantStmt(GrantStmt *from)
1664
{
1665
	GrantStmt  *newnode = makeNode(GrantStmt);
B
Bruce Momjian 已提交
1666

1667 1668 1669
	COPY_SCALAR_FIELD(is_grant);
	COPY_SCALAR_FIELD(objtype);
	COPY_NODE_FIELD(objects);
1670
	COPY_NODE_FIELD(privileges);
1671
	COPY_NODE_FIELD(grantees);
1672 1673
	COPY_SCALAR_FIELD(grant_option);
	COPY_SCALAR_FIELD(behavior);
1674 1675 1676 1677 1678 1679 1680 1681 1682

	return newnode;
}

static PrivGrantee *
_copyPrivGrantee(PrivGrantee *from)
{
	PrivGrantee *newnode = makeNode(PrivGrantee);

1683 1684
	COPY_STRING_FIELD(username);
	COPY_STRING_FIELD(groupname);
1685 1686 1687 1688

	return newnode;
}

1689 1690 1691 1692 1693
static FuncWithArgs *
_copyFuncWithArgs(FuncWithArgs *from)
{
	FuncWithArgs *newnode = makeNode(FuncWithArgs);

1694 1695
	COPY_NODE_FIELD(funcname);
	COPY_NODE_FIELD(funcargs);
1696 1697 1698 1699

	return newnode;
}

1700
static DeclareCursorStmt *
1701
_copyDeclareCursorStmt(DeclareCursorStmt *from)
1702 1703 1704 1705 1706 1707 1708 1709 1710
{
	DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);

	COPY_STRING_FIELD(portalname);
	COPY_SCALAR_FIELD(options);
	COPY_NODE_FIELD(query);

	return newnode;
}
B
Bruce Momjian 已提交
1711

1712 1713 1714
static ClosePortalStmt *
_copyClosePortalStmt(ClosePortalStmt *from)
{
1715
	ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1716

1717
	COPY_STRING_FIELD(portalname);
1718 1719 1720 1721

	return newnode;
}

1722 1723 1724 1725
static ClusterStmt *
_copyClusterStmt(ClusterStmt *from)
{
	ClusterStmt *newnode = makeNode(ClusterStmt);
B
Bruce Momjian 已提交
1726

1727 1728
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(indexname);
1729 1730 1731 1732 1733 1734 1735

	return newnode;
}

static CopyStmt *
_copyCopyStmt(CopyStmt *from)
{
B
Bruce Momjian 已提交
1736 1737
	CopyStmt   *newnode = makeNode(CopyStmt);

1738 1739 1740 1741 1742
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(attlist);
	COPY_SCALAR_FIELD(is_from);
	COPY_STRING_FIELD(filename);
	COPY_NODE_FIELD(options);
1743 1744 1745 1746 1747 1748 1749 1750

	return newnode;
}

static CreateStmt *
_copyCreateStmt(CreateStmt *from)
{
	CreateStmt *newnode = makeNode(CreateStmt);
B
Bruce Momjian 已提交
1751

1752 1753 1754 1755 1756 1757
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(tableElts);
	COPY_NODE_FIELD(inhRelations);
	COPY_NODE_FIELD(constraints);
	COPY_SCALAR_FIELD(hasoids);
	COPY_SCALAR_FIELD(oncommit);
1758
	COPY_STRING_FIELD(tablespacename);
1759 1760 1761 1762

	return newnode;
}

B
Bruce Momjian 已提交
1763
static InhRelation *
1764
_copyInhRelation(InhRelation *from)
B
Bruce Momjian 已提交
1765 1766 1767 1768 1769 1770 1771 1772 1773
{
	InhRelation *newnode = makeNode(InhRelation);

	COPY_NODE_FIELD(relation);
	COPY_SCALAR_FIELD(including_defaults);

	return newnode;
}

1774 1775 1776 1777
static DefineStmt *
_copyDefineStmt(DefineStmt *from)
{
	DefineStmt *newnode = makeNode(DefineStmt);
B
Bruce Momjian 已提交
1778

1779
	COPY_SCALAR_FIELD(kind);
1780 1781
	COPY_NODE_FIELD(defnames);
	COPY_NODE_FIELD(definition);
1782 1783 1784 1785 1786 1787 1788

	return newnode;
}

static DropStmt *
_copyDropStmt(DropStmt *from)
{
B
Bruce Momjian 已提交
1789 1790
	DropStmt   *newnode = makeNode(DropStmt);

1791 1792 1793
	COPY_NODE_FIELD(objects);
	COPY_SCALAR_FIELD(removeType);
	COPY_SCALAR_FIELD(behavior);
1794 1795 1796 1797

	return newnode;
}

1798 1799 1800
static TruncateStmt *
_copyTruncateStmt(TruncateStmt *from)
{
1801
	TruncateStmt *newnode = makeNode(TruncateStmt);
1802

1803
	COPY_NODE_FIELD(relation);
1804 1805 1806 1807

	return newnode;
}

1808 1809 1810 1811
static CommentStmt *
_copyCommentStmt(CommentStmt *from)
{
	CommentStmt *newnode = makeNode(CommentStmt);
B
Bruce Momjian 已提交
1812

1813 1814 1815 1816
	COPY_SCALAR_FIELD(objtype);
	COPY_NODE_FIELD(objname);
	COPY_NODE_FIELD(objargs);
	COPY_STRING_FIELD(comment);
1817 1818 1819 1820 1821 1822 1823

	return newnode;
}

static FetchStmt *
_copyFetchStmt(FetchStmt *from)
{
B
Bruce Momjian 已提交
1824 1825
	FetchStmt  *newnode = makeNode(FetchStmt);

1826 1827 1828 1829
	COPY_SCALAR_FIELD(direction);
	COPY_SCALAR_FIELD(howMany);
	COPY_STRING_FIELD(portalname);
	COPY_SCALAR_FIELD(ismove);
1830 1831 1832 1833 1834 1835 1836

	return newnode;
}

static IndexStmt *
_copyIndexStmt(IndexStmt *from)
{
B
Bruce Momjian 已提交
1837 1838
	IndexStmt  *newnode = makeNode(IndexStmt);

1839 1840 1841
	COPY_STRING_FIELD(idxname);
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(accessMethod);
1842
	COPY_STRING_FIELD(tableSpace);
1843 1844 1845 1846 1847 1848
	COPY_NODE_FIELD(indexParams);
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(rangetable);
	COPY_SCALAR_FIELD(unique);
	COPY_SCALAR_FIELD(primary);
	COPY_SCALAR_FIELD(isconstraint);
1849 1850 1851 1852

	return newnode;
}

1853 1854
static CreateFunctionStmt *
_copyCreateFunctionStmt(CreateFunctionStmt *from)
1855
{
1856
	CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
B
Bruce Momjian 已提交
1857

1858 1859
	COPY_SCALAR_FIELD(replace);
	COPY_NODE_FIELD(funcname);
1860
	COPY_NODE_FIELD(parameters);
1861 1862 1863
	COPY_NODE_FIELD(returnType);
	COPY_NODE_FIELD(options);
	COPY_NODE_FIELD(withClause);
1864 1865 1866 1867

	return newnode;
}

1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878
static FunctionParameter *
_copyFunctionParameter(FunctionParameter *from)
{
	FunctionParameter *newnode = makeNode(FunctionParameter);

	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(argType);

	return newnode;
}

1879 1880 1881 1882
static RemoveAggrStmt *
_copyRemoveAggrStmt(RemoveAggrStmt *from)
{
	RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
B
Bruce Momjian 已提交
1883

1884 1885 1886
	COPY_NODE_FIELD(aggname);
	COPY_NODE_FIELD(aggtype);
	COPY_SCALAR_FIELD(behavior);
1887 1888 1889 1890 1891 1892 1893 1894

	return newnode;
}

static RemoveFuncStmt *
_copyRemoveFuncStmt(RemoveFuncStmt *from)
{
	RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
B
Bruce Momjian 已提交
1895

1896 1897 1898
	COPY_NODE_FIELD(funcname);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(behavior);
1899 1900 1901 1902 1903 1904 1905 1906

	return newnode;
}

static RemoveOperStmt *
_copyRemoveOperStmt(RemoveOperStmt *from)
{
	RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
B
Bruce Momjian 已提交
1907

1908 1909 1910
	COPY_NODE_FIELD(opname);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(behavior);
1911 1912 1913 1914

	return newnode;
}

1915 1916 1917 1918 1919
static RemoveOpClassStmt *
_copyRemoveOpClassStmt(RemoveOpClassStmt *from)
{
	RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);

1920 1921 1922
	COPY_NODE_FIELD(opclassname);
	COPY_STRING_FIELD(amname);
	COPY_SCALAR_FIELD(behavior);
1923 1924 1925 1926

	return newnode;
}

1927 1928 1929 1930
static RenameStmt *
_copyRenameStmt(RenameStmt *from)
{
	RenameStmt *newnode = makeNode(RenameStmt);
B
Bruce Momjian 已提交
1931

1932
	COPY_NODE_FIELD(relation);
1933 1934 1935
	COPY_NODE_FIELD(object);
	COPY_NODE_FIELD(objarg);
	COPY_STRING_FIELD(subname);
1936 1937
	COPY_STRING_FIELD(newname);
	COPY_SCALAR_FIELD(renameType);
1938 1939 1940 1941

	return newnode;
}

1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956
static AlterOwnerStmt *
_copyAlterOwnerStmt(AlterOwnerStmt *from)
{
	AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);

	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(object);
	COPY_NODE_FIELD(objarg);
	COPY_STRING_FIELD(addname);
	COPY_STRING_FIELD(newowner);
	COPY_SCALAR_FIELD(objectType);

	return newnode;
}

1957 1958 1959
static RuleStmt *
_copyRuleStmt(RuleStmt *from)
{
B
Bruce Momjian 已提交
1960 1961
	RuleStmt   *newnode = makeNode(RuleStmt);

1962 1963 1964 1965 1966 1967 1968
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(rulename);
	COPY_NODE_FIELD(whereClause);
	COPY_SCALAR_FIELD(event);
	COPY_SCALAR_FIELD(instead);
	COPY_NODE_FIELD(actions);
	COPY_SCALAR_FIELD(replace);
1969 1970 1971 1972

	return newnode;
}

1973 1974 1975
static NotifyStmt *
_copyNotifyStmt(NotifyStmt *from)
{
1976
	NotifyStmt *newnode = makeNode(NotifyStmt);
1977

1978
	COPY_NODE_FIELD(relation);
1979 1980 1981 1982 1983 1984 1985

	return newnode;
}

static ListenStmt *
_copyListenStmt(ListenStmt *from)
{
1986
	ListenStmt *newnode = makeNode(ListenStmt);
1987

1988
	COPY_NODE_FIELD(relation);
1989 1990 1991 1992 1993 1994 1995

	return newnode;
}

static UnlistenStmt *
_copyUnlistenStmt(UnlistenStmt *from)
{
1996
	UnlistenStmt *newnode = makeNode(UnlistenStmt);
1997

1998
	COPY_NODE_FIELD(relation);
1999 2000 2001 2002 2003 2004 2005

	return newnode;
}

static TransactionStmt *
_copyTransactionStmt(TransactionStmt *from)
{
2006
	TransactionStmt *newnode = makeNode(TransactionStmt);
2007

2008
	COPY_SCALAR_FIELD(kind);
2009
	COPY_NODE_FIELD(options);
2010 2011 2012 2013

	return newnode;
}

B
Bruce Momjian 已提交
2014 2015 2016
static CompositeTypeStmt *
_copyCompositeTypeStmt(CompositeTypeStmt *from)
{
B
Bruce Momjian 已提交
2017
	CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
B
Bruce Momjian 已提交
2018

2019 2020
	COPY_NODE_FIELD(typevar);
	COPY_NODE_FIELD(coldeflist);
B
Bruce Momjian 已提交
2021 2022 2023 2024

	return newnode;
}

2025 2026 2027 2028 2029
static ViewStmt *
_copyViewStmt(ViewStmt *from)
{
	ViewStmt   *newnode = makeNode(ViewStmt);

2030 2031 2032 2033
	COPY_NODE_FIELD(view);
	COPY_NODE_FIELD(aliases);
	COPY_NODE_FIELD(query);
	COPY_SCALAR_FIELD(replace);
2034 2035 2036 2037

	return newnode;
}

2038 2039 2040
static LoadStmt *
_copyLoadStmt(LoadStmt *from)
{
2041
	LoadStmt   *newnode = makeNode(LoadStmt);
2042

2043
	COPY_STRING_FIELD(filename);
2044 2045 2046 2047

	return newnode;
}

2048 2049 2050 2051 2052
static CreateDomainStmt *
_copyCreateDomainStmt(CreateDomainStmt *from)
{
	CreateDomainStmt *newnode = makeNode(CreateDomainStmt);

2053 2054 2055
	COPY_NODE_FIELD(domainname);
	COPY_NODE_FIELD(typename);
	COPY_NODE_FIELD(constraints);
2056 2057 2058 2059

	return newnode;
}

2060 2061 2062 2063 2064
static CreateOpClassStmt *
_copyCreateOpClassStmt(CreateOpClassStmt *from)
{
	CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);

2065 2066 2067 2068 2069
	COPY_NODE_FIELD(opclassname);
	COPY_STRING_FIELD(amname);
	COPY_NODE_FIELD(datatype);
	COPY_NODE_FIELD(items);
	COPY_SCALAR_FIELD(isDefault);
2070 2071 2072 2073 2074 2075 2076 2077 2078

	return newnode;
}

static CreateOpClassItem *
_copyCreateOpClassItem(CreateOpClassItem *from)
{
	CreateOpClassItem *newnode = makeNode(CreateOpClassItem);

2079 2080 2081 2082 2083 2084
	COPY_SCALAR_FIELD(itemtype);
	COPY_NODE_FIELD(name);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(number);
	COPY_SCALAR_FIELD(recheck);
	COPY_NODE_FIELD(storedtype);
2085 2086 2087 2088

	return newnode;
}

2089 2090 2091
static CreatedbStmt *
_copyCreatedbStmt(CreatedbStmt *from)
{
B
Bruce Momjian 已提交
2092
	CreatedbStmt *newnode = makeNode(CreatedbStmt);
2093

2094 2095
	COPY_STRING_FIELD(dbname);
	COPY_NODE_FIELD(options);
2096 2097 2098 2099

	return newnode;
}

2100 2101 2102 2103 2104
static AlterDatabaseSetStmt *
_copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
{
	AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);

2105 2106 2107
	COPY_STRING_FIELD(dbname);
	COPY_STRING_FIELD(variable);
	COPY_NODE_FIELD(value);
2108 2109 2110 2111

	return newnode;
}

2112 2113 2114
static DropdbStmt *
_copyDropdbStmt(DropdbStmt *from)
{
B
Bruce Momjian 已提交
2115
	DropdbStmt *newnode = makeNode(DropdbStmt);
2116

2117
	COPY_STRING_FIELD(dbname);
2118 2119 2120 2121 2122 2123 2124

	return newnode;
}

static VacuumStmt *
_copyVacuumStmt(VacuumStmt *from)
{
B
Bruce Momjian 已提交
2125
	VacuumStmt *newnode = makeNode(VacuumStmt);
2126

2127 2128 2129 2130 2131 2132 2133
	COPY_SCALAR_FIELD(vacuum);
	COPY_SCALAR_FIELD(full);
	COPY_SCALAR_FIELD(analyze);
	COPY_SCALAR_FIELD(freeze);
	COPY_SCALAR_FIELD(verbose);
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(va_cols);
2134 2135 2136 2137 2138 2139 2140

	return newnode;
}

static ExplainStmt *
_copyExplainStmt(ExplainStmt *from)
{
B
Bruce Momjian 已提交
2141
	ExplainStmt *newnode = makeNode(ExplainStmt);
2142

2143 2144 2145
	COPY_NODE_FIELD(query);
	COPY_SCALAR_FIELD(verbose);
	COPY_SCALAR_FIELD(analyze);
2146 2147 2148 2149 2150 2151 2152

	return newnode;
}

static CreateSeqStmt *
_copyCreateSeqStmt(CreateSeqStmt *from)
{
B
Bruce Momjian 已提交
2153
	CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2154

2155 2156
	COPY_NODE_FIELD(sequence);
	COPY_NODE_FIELD(options);
2157 2158 2159 2160

	return newnode;
}

B
Bruce Momjian 已提交
2161
static AlterSeqStmt *
2162
_copyAlterSeqStmt(AlterSeqStmt *from)
B
Bruce Momjian 已提交
2163 2164 2165 2166 2167 2168 2169 2170 2171
{
	AlterSeqStmt *newnode = makeNode(AlterSeqStmt);

	COPY_NODE_FIELD(sequence);
	COPY_NODE_FIELD(options);

	return newnode;
}

2172 2173 2174
static VariableSetStmt *
_copyVariableSetStmt(VariableSetStmt *from)
{
2175
	VariableSetStmt *newnode = makeNode(VariableSetStmt);
2176

2177 2178 2179
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(is_local);
2180 2181 2182 2183

	return newnode;
}

2184 2185 2186 2187 2188
static VariableShowStmt *
_copyVariableShowStmt(VariableShowStmt *from)
{
	VariableShowStmt *newnode = makeNode(VariableShowStmt);

2189
	COPY_STRING_FIELD(name);
2190 2191 2192 2193

	return newnode;
}

2194 2195 2196
static VariableResetStmt *
_copyVariableResetStmt(VariableResetStmt *from)
{
2197
	VariableResetStmt *newnode = makeNode(VariableResetStmt);
2198

2199
	COPY_STRING_FIELD(name);
2200 2201 2202 2203

	return newnode;
}

2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225
static CreateTableSpaceStmt *
_copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
{
	CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);

	COPY_STRING_FIELD(tablespacename);
	COPY_STRING_FIELD(owner);
	COPY_STRING_FIELD(location);

	return newnode;
}

static DropTableSpaceStmt *
_copyDropTableSpaceStmt(DropTableSpaceStmt *from)
{
	DropTableSpaceStmt *newnode = makeNode(DropTableSpaceStmt);

	COPY_STRING_FIELD(tablespacename);

	return newnode;
}

2226 2227 2228 2229 2230
static CreateTrigStmt *
_copyCreateTrigStmt(CreateTrigStmt *from)
{
	CreateTrigStmt *newnode = makeNode(CreateTrigStmt);

2231 2232 2233 2234 2235 2236
	COPY_STRING_FIELD(trigname);
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(funcname);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(before);
	COPY_SCALAR_FIELD(row);
B
Bruce Momjian 已提交
2237
	strcpy(newnode->actions, from->actions);	/* in-line string field */
2238 2239 2240 2241
	COPY_SCALAR_FIELD(isconstraint);
	COPY_SCALAR_FIELD(deferrable);
	COPY_SCALAR_FIELD(initdeferred);
	COPY_NODE_FIELD(constrrel);
2242 2243 2244 2245

	return newnode;
}

2246 2247
static DropPropertyStmt *
_copyDropPropertyStmt(DropPropertyStmt *from)
2248
{
2249
	DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2250

2251 2252 2253 2254
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(property);
	COPY_SCALAR_FIELD(removeType);
	COPY_SCALAR_FIELD(behavior);
2255 2256 2257 2258 2259 2260 2261 2262 2263

	return newnode;
}

static CreatePLangStmt *
_copyCreatePLangStmt(CreatePLangStmt *from)
{
	CreatePLangStmt *newnode = makeNode(CreatePLangStmt);

2264 2265 2266 2267
	COPY_STRING_FIELD(plname);
	COPY_NODE_FIELD(plhandler);
	COPY_NODE_FIELD(plvalidator);
	COPY_SCALAR_FIELD(pltrusted);
2268 2269 2270 2271 2272 2273 2274 2275 2276

	return newnode;
}

static DropPLangStmt *
_copyDropPLangStmt(DropPLangStmt *from)
{
	DropPLangStmt *newnode = makeNode(DropPLangStmt);

2277 2278
	COPY_STRING_FIELD(plname);
	COPY_SCALAR_FIELD(behavior);
2279 2280 2281 2282 2283 2284 2285 2286 2287

	return newnode;
}

static CreateUserStmt *
_copyCreateUserStmt(CreateUserStmt *from)
{
	CreateUserStmt *newnode = makeNode(CreateUserStmt);

2288 2289
	COPY_STRING_FIELD(user);
	COPY_NODE_FIELD(options);
2290 2291 2292 2293 2294 2295 2296 2297 2298

	return newnode;
}

static AlterUserStmt *
_copyAlterUserStmt(AlterUserStmt *from)
{
	AlterUserStmt *newnode = makeNode(AlterUserStmt);

2299 2300
	COPY_STRING_FIELD(user);
	COPY_NODE_FIELD(options);
2301 2302 2303 2304

	return newnode;
}

2305 2306 2307 2308 2309
static AlterUserSetStmt *
_copyAlterUserSetStmt(AlterUserSetStmt *from)
{
	AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);

2310 2311 2312
	COPY_STRING_FIELD(user);
	COPY_STRING_FIELD(variable);
	COPY_NODE_FIELD(value);
2313 2314 2315 2316

	return newnode;
}

2317 2318 2319 2320 2321
static DropUserStmt *
_copyDropUserStmt(DropUserStmt *from)
{
	DropUserStmt *newnode = makeNode(DropUserStmt);

2322
	COPY_NODE_FIELD(users);
2323 2324 2325 2326

	return newnode;
}

2327 2328 2329
static LockStmt *
_copyLockStmt(LockStmt *from)
{
2330
	LockStmt   *newnode = makeNode(LockStmt);
2331

2332 2333
	COPY_NODE_FIELD(relations);
	COPY_SCALAR_FIELD(mode);
T
Tatsuo Ishii 已提交
2334
	COPY_SCALAR_FIELD(nowait);
2335 2336 2337

	return newnode;
}
2338

2339 2340 2341
static ConstraintsSetStmt *
_copyConstraintsSetStmt(ConstraintsSetStmt *from)
{
B
Bruce Momjian 已提交
2342
	ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2343

2344 2345
	COPY_NODE_FIELD(constraints);
	COPY_SCALAR_FIELD(deferred);
2346 2347 2348 2349 2350 2351 2352

	return newnode;
}

static CreateGroupStmt *
_copyCreateGroupStmt(CreateGroupStmt *from)
{
B
Bruce Momjian 已提交
2353
	CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2354

2355 2356
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(options);
2357 2358 2359 2360 2361 2362 2363

	return newnode;
}

static AlterGroupStmt *
_copyAlterGroupStmt(AlterGroupStmt *from)
{
B
Bruce Momjian 已提交
2364
	AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2365

2366 2367 2368
	COPY_STRING_FIELD(name);
	COPY_SCALAR_FIELD(action);
	COPY_NODE_FIELD(listUsers);
2369 2370 2371 2372 2373 2374 2375

	return newnode;
}

static DropGroupStmt *
_copyDropGroupStmt(DropGroupStmt *from)
{
B
Bruce Momjian 已提交
2376
	DropGroupStmt *newnode = makeNode(DropGroupStmt);
2377

2378
	COPY_STRING_FIELD(name);
2379 2380 2381 2382 2383 2384 2385

	return newnode;
}

static ReindexStmt *
_copyReindexStmt(ReindexStmt *from)
{
B
Bruce Momjian 已提交
2386
	ReindexStmt *newnode = makeNode(ReindexStmt);
2387

2388
	COPY_SCALAR_FIELD(kind);
2389 2390 2391 2392
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(name);
	COPY_SCALAR_FIELD(force);
	COPY_SCALAR_FIELD(all);
2393 2394 2395 2396

	return newnode;
}

2397 2398 2399 2400 2401
static CreateSchemaStmt *
_copyCreateSchemaStmt(CreateSchemaStmt *from)
{
	CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);

2402 2403 2404
	COPY_STRING_FIELD(schemaname);
	COPY_STRING_FIELD(authid);
	COPY_NODE_FIELD(schemaElts);
2405 2406 2407 2408

	return newnode;
}

2409 2410 2411 2412 2413
static CreateConversionStmt *
_copyCreateConversionStmt(CreateConversionStmt *from)
{
	CreateConversionStmt *newnode = makeNode(CreateConversionStmt);

2414 2415 2416 2417 2418
	COPY_NODE_FIELD(conversion_name);
	COPY_STRING_FIELD(for_encoding_name);
	COPY_STRING_FIELD(to_encoding_name);
	COPY_NODE_FIELD(func_name);
	COPY_SCALAR_FIELD(def);
2419 2420 2421 2422 2423 2424 2425 2426 2427

	return newnode;
}

static CreateCastStmt *
_copyCreateCastStmt(CreateCastStmt *from)
{
	CreateCastStmt *newnode = makeNode(CreateCastStmt);

2428 2429 2430 2431
	COPY_NODE_FIELD(sourcetype);
	COPY_NODE_FIELD(targettype);
	COPY_NODE_FIELD(func);
	COPY_SCALAR_FIELD(context);
2432 2433 2434 2435 2436 2437 2438 2439 2440

	return newnode;
}

static DropCastStmt *
_copyDropCastStmt(DropCastStmt *from)
{
	DropCastStmt *newnode = makeNode(DropCastStmt);

2441 2442 2443
	COPY_NODE_FIELD(sourcetype);
	COPY_NODE_FIELD(targettype);
	COPY_SCALAR_FIELD(behavior);
2444 2445 2446 2447

	return newnode;
}

2448 2449 2450 2451 2452
static PrepareStmt *
_copyPrepareStmt(PrepareStmt *from)
{
	PrepareStmt *newnode = makeNode(PrepareStmt);

2453 2454
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(argtypes);
2455
	COPY_NODE_FIELD(argtype_oids);
2456
	COPY_NODE_FIELD(query);
2457 2458 2459 2460 2461 2462 2463 2464 2465

	return newnode;
}

static ExecuteStmt *
_copyExecuteStmt(ExecuteStmt *from)
{
	ExecuteStmt *newnode = makeNode(ExecuteStmt);

2466 2467 2468
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(into);
	COPY_NODE_FIELD(params);
2469 2470 2471 2472 2473 2474 2475 2476 2477

	return newnode;
}

static DeallocateStmt *
_copyDeallocateStmt(DeallocateStmt *from)
{
	DeallocateStmt *newnode = makeNode(DeallocateStmt);

2478
	COPY_STRING_FIELD(name);
2479 2480 2481 2482

	return newnode;
}

2483 2484

/* ****************************************************************
2485
 *					pg_list.h copy functions
2486 2487 2488
 * ****************************************************************
 */

2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500
/*
 * Perform a deep copy of the specified list, using copyObject(). The
 * list MUST be of type T_List; T_IntList and T_OidList nodes don't
 * need deep copies, so they should be copied via list_copy()
 */
#define COPY_NODE_CELL(new, old)					\
	(new) = (ListCell *) palloc(sizeof(ListCell));	\
	lfirst(new) = copyObject(lfirst(old));

static List *
_copyList(List *from)
{
B
Bruce Momjian 已提交
2501 2502 2503
	List	   *new;
	ListCell   *curr_old;
	ListCell   *prev_new;
2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529

	Assert(list_length(from) >= 1);

	new = makeNode(List);
	new->length = from->length;

	COPY_NODE_CELL(new->head, from->head);
	prev_new = new->head;
	curr_old = lnext(from->head);

	while (curr_old)
	{
		COPY_NODE_CELL(prev_new->next, curr_old);
		prev_new = prev_new->next;
		curr_old = curr_old->next;
	}
	prev_new->next = NULL;
	new->tail = prev_new;

	return new;
}

/* ****************************************************************
 *					value.h copy functions
 * ****************************************************************
 */
2530
static Value *
2531
_copyValue(Value *from)
2532
{
2533
	Value	   *newnode = makeNode(Value);
2534

2535 2536
	/* See also _copyAConst when changing this code! */

2537
	COPY_SCALAR_FIELD(type);
2538 2539
	switch (from->type)
	{
2540
		case T_Integer:
2541
			COPY_SCALAR_FIELD(val.ival);
2542 2543
			break;
		case T_Float:
2544
		case T_String:
2545
		case T_BitString:
2546
			COPY_STRING_FIELD(val.str);
2547
			break;
2548 2549 2550
		case T_Null:
			/* nothing to do */
			break;
2551
		default:
2552 2553
			elog(ERROR, "unrecognized node type: %d",
				 (int) from->type);
2554
			break;
2555 2556
	}
	return newnode;
2557 2558
}

2559 2560 2561 2562 2563
/*
 * copyObject
 *
 * Create a copy of a Node tree or list.  This is a "deep" copy: all
 * substructure is copied too, recursively.
2564
 */
2565
void *
2566 2567
copyObject(void *from)
{
2568
	void	   *retval;
2569

2570 2571
	if (from == NULL)
		return NULL;
2572

2573
	switch (nodeTag(from))
2574
	{
2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595
			/*
			 * PLAN NODES
			 */
		case T_Plan:
			retval = _copyPlan(from);
			break;
		case T_Result:
			retval = _copyResult(from);
			break;
		case T_Append:
			retval = _copyAppend(from);
			break;
		case T_Scan:
			retval = _copyScan(from);
			break;
		case T_SeqScan:
			retval = _copySeqScan(from);
			break;
		case T_IndexScan:
			retval = _copyIndexScan(from);
			break;
2596 2597 2598
		case T_TidScan:
			retval = _copyTidScan(from);
			break;
2599 2600 2601
		case T_SubqueryScan:
			retval = _copySubqueryScan(from);
			break;
2602 2603 2604
		case T_FunctionScan:
			retval = _copyFunctionScan(from);
			break;
2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622
		case T_Join:
			retval = _copyJoin(from);
			break;
		case T_NestLoop:
			retval = _copyNestLoop(from);
			break;
		case T_MergeJoin:
			retval = _copyMergeJoin(from);
			break;
		case T_HashJoin:
			retval = _copyHashJoin(from);
			break;
		case T_Material:
			retval = _copyMaterial(from);
			break;
		case T_Sort:
			retval = _copySort(from);
			break;
V
Vadim B. Mikheev 已提交
2623 2624 2625
		case T_Group:
			retval = _copyGroup(from);
			break;
2626 2627 2628 2629 2630 2631
		case T_Agg:
			retval = _copyAgg(from);
			break;
		case T_Unique:
			retval = _copyUnique(from);
			break;
2632 2633 2634
		case T_Hash:
			retval = _copyHash(from);
			break;
2635 2636 2637
		case T_SetOp:
			retval = _copySetOp(from);
			break;
2638 2639 2640
		case T_Limit:
			retval = _copyLimit(from);
			break;
2641 2642 2643 2644 2645 2646 2647

			/*
			 * PRIMITIVE NODES
			 */
		case T_Resdom:
			retval = _copyResdom(from);
			break;
2648 2649 2650 2651 2652 2653
		case T_Alias:
			retval = _copyAlias(from);
			break;
		case T_RangeVar:
			retval = _copyRangeVar(from);
			break;
2654 2655 2656 2657 2658 2659 2660 2661 2662
		case T_Var:
			retval = _copyVar(from);
			break;
		case T_Const:
			retval = _copyConst(from);
			break;
		case T_Param:
			retval = _copyParam(from);
			break;
2663 2664 2665
		case T_Aggref:
			retval = _copyAggref(from);
			break;
2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677
		case T_ArrayRef:
			retval = _copyArrayRef(from);
			break;
		case T_FuncExpr:
			retval = _copyFuncExpr(from);
			break;
		case T_OpExpr:
			retval = _copyOpExpr(from);
			break;
		case T_DistinctExpr:
			retval = _copyDistinctExpr(from);
			break;
2678 2679 2680
		case T_ScalarArrayOpExpr:
			retval = _copyScalarArrayOpExpr(from);
			break;
2681 2682 2683
		case T_BoolExpr:
			retval = _copyBoolExpr(from);
			break;
2684 2685 2686
		case T_SubLink:
			retval = _copySubLink(from);
			break;
2687 2688
		case T_SubPlan:
			retval = _copySubPlan(from);
2689
			break;
2690 2691 2692
		case T_FieldSelect:
			retval = _copyFieldSelect(from);
			break;
2693 2694 2695
		case T_FieldStore:
			retval = _copyFieldStore(from);
			break;
2696 2697 2698
		case T_RelabelType:
			retval = _copyRelabelType(from);
			break;
2699 2700 2701 2702 2703 2704
		case T_CaseExpr:
			retval = _copyCaseExpr(from);
			break;
		case T_CaseWhen:
			retval = _copyCaseWhen(from);
			break;
2705 2706 2707
		case T_CaseTestExpr:
			retval = _copyCaseTestExpr(from);
			break;
2708 2709 2710
		case T_ArrayExpr:
			retval = _copyArrayExpr(from);
			break;
2711 2712 2713
		case T_RowExpr:
			retval = _copyRowExpr(from);
			break;
2714 2715 2716 2717 2718 2719
		case T_CoalesceExpr:
			retval = _copyCoalesceExpr(from);
			break;
		case T_NullIfExpr:
			retval = _copyNullIfExpr(from);
			break;
2720 2721 2722 2723 2724 2725
		case T_NullTest:
			retval = _copyNullTest(from);
			break;
		case T_BooleanTest:
			retval = _copyBooleanTest(from);
			break;
2726 2727
		case T_CoerceToDomain:
			retval = _copyCoerceToDomain(from);
2728
			break;
2729 2730
		case T_CoerceToDomainValue:
			retval = _copyCoerceToDomainValue(from);
2731
			break;
2732 2733 2734
		case T_SetToDefault:
			retval = _copySetToDefault(from);
			break;
2735 2736 2737
		case T_TargetEntry:
			retval = _copyTargetEntry(from);
			break;
2738 2739 2740
		case T_RangeTblRef:
			retval = _copyRangeTblRef(from);
			break;
2741 2742 2743
		case T_JoinExpr:
			retval = _copyJoinExpr(from);
			break;
2744 2745 2746
		case T_FromExpr:
			retval = _copyFromExpr(from);
			break;
2747 2748 2749 2750

			/*
			 * RELATION NODES
			 */
2751 2752
		case T_PathKeyItem:
			retval = _copyPathKeyItem(from);
2753
			break;
2754 2755
		case T_RestrictInfo:
			retval = _copyRestrictInfo(from);
2756
			break;
2757 2758
		case T_JoinInfo:
			retval = _copyJoinInfo(from);
2759
			break;
2760 2761 2762
		case T_InClauseInfo:
			retval = _copyInClauseInfo(from);
			break;
2763 2764

			/*
2765
			 * VALUE NODES
2766
			 */
2767 2768 2769
		case T_Integer:
		case T_Float:
		case T_String:
2770
		case T_BitString:
2771
		case T_Null:
2772
			retval = _copyValue(from);
2773
			break;
2774 2775 2776 2777

			/*
			 * LIST NODES
			 */
2778
		case T_List:
2779 2780
			retval = _copyList(from);
			break;
B
Bruce Momjian 已提交
2781

2782
			/*
B
Bruce Momjian 已提交
2783 2784
			 * Lists of integers and OIDs don't need to be deep-copied, so
			 * we perform a shallow copy via list_copy()
2785 2786 2787 2788
			 */
		case T_IntList:
		case T_OidList:
			retval = list_copy(from);
2789
			break;
2790 2791 2792 2793

			/*
			 * PARSE NODES
			 */
2794 2795 2796
		case T_Query:
			retval = _copyQuery(from);
			break;
2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808
		case T_InsertStmt:
			retval = _copyInsertStmt(from);
			break;
		case T_DeleteStmt:
			retval = _copyDeleteStmt(from);
			break;
		case T_UpdateStmt:
			retval = _copyUpdateStmt(from);
			break;
		case T_SelectStmt:
			retval = _copySelectStmt(from);
			break;
2809 2810 2811
		case T_SetOperationStmt:
			retval = _copySetOperationStmt(from);
			break;
2812 2813 2814
		case T_AlterTableStmt:
			retval = _copyAlterTableStmt(from);
			break;
T
Tom Lane 已提交
2815 2816 2817
		case T_AlterTableCmd:
			retval = _copyAlterTableCmd(from);
			break;
B
Bruce Momjian 已提交
2818 2819 2820
		case T_AlterDomainStmt:
			retval = _copyAlterDomainStmt(from);
			break;
2821 2822
		case T_GrantStmt:
			retval = _copyGrantStmt(from);
2823
			break;
2824 2825 2826
		case T_DeclareCursorStmt:
			retval = _copyDeclareCursorStmt(from);
			break;
2827 2828 2829
		case T_ClosePortalStmt:
			retval = _copyClosePortalStmt(from);
			break;
2830 2831 2832 2833 2834 2835 2836 2837 2838
		case T_ClusterStmt:
			retval = _copyClusterStmt(from);
			break;
		case T_CopyStmt:
			retval = _copyCopyStmt(from);
			break;
		case T_CreateStmt:
			retval = _copyCreateStmt(from);
			break;
B
Bruce Momjian 已提交
2839 2840 2841
		case T_InhRelation:
			retval = _copyInhRelation(from);
			break;
2842 2843 2844 2845 2846 2847
		case T_DefineStmt:
			retval = _copyDefineStmt(from);
			break;
		case T_DropStmt:
			retval = _copyDropStmt(from);
			break;
2848 2849 2850
		case T_TruncateStmt:
			retval = _copyTruncateStmt(from);
			break;
2851 2852 2853 2854 2855 2856 2857 2858 2859
		case T_CommentStmt:
			retval = _copyCommentStmt(from);
			break;
		case T_FetchStmt:
			retval = _copyFetchStmt(from);
			break;
		case T_IndexStmt:
			retval = _copyIndexStmt(from);
			break;
2860 2861
		case T_CreateFunctionStmt:
			retval = _copyCreateFunctionStmt(from);
2862
			break;
2863 2864 2865
		case T_FunctionParameter:
			retval = _copyFunctionParameter(from);
			break;
2866 2867 2868 2869 2870 2871 2872 2873 2874
		case T_RemoveAggrStmt:
			retval = _copyRemoveAggrStmt(from);
			break;
		case T_RemoveFuncStmt:
			retval = _copyRemoveFuncStmt(from);
			break;
		case T_RemoveOperStmt:
			retval = _copyRemoveOperStmt(from);
			break;
2875 2876 2877
		case T_RemoveOpClassStmt:
			retval = _copyRemoveOpClassStmt(from);
			break;
2878 2879 2880
		case T_RenameStmt:
			retval = _copyRenameStmt(from);
			break;
2881 2882 2883
		case T_AlterOwnerStmt:
			retval = _copyAlterOwnerStmt(from);
			break;
2884 2885 2886
		case T_RuleStmt:
			retval = _copyRuleStmt(from);
			break;
2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898
		case T_NotifyStmt:
			retval = _copyNotifyStmt(from);
			break;
		case T_ListenStmt:
			retval = _copyListenStmt(from);
			break;
		case T_UnlistenStmt:
			retval = _copyUnlistenStmt(from);
			break;
		case T_TransactionStmt:
			retval = _copyTransactionStmt(from);
			break;
B
Bruce Momjian 已提交
2899 2900 2901
		case T_CompositeTypeStmt:
			retval = _copyCompositeTypeStmt(from);
			break;
2902 2903 2904
		case T_ViewStmt:
			retval = _copyViewStmt(from);
			break;
2905 2906 2907
		case T_LoadStmt:
			retval = _copyLoadStmt(from);
			break;
2908 2909 2910
		case T_CreateDomainStmt:
			retval = _copyCreateDomainStmt(from);
			break;
2911 2912 2913 2914 2915 2916
		case T_CreateOpClassStmt:
			retval = _copyCreateOpClassStmt(from);
			break;
		case T_CreateOpClassItem:
			retval = _copyCreateOpClassItem(from);
			break;
2917 2918 2919
		case T_CreatedbStmt:
			retval = _copyCreatedbStmt(from);
			break;
2920 2921 2922
		case T_AlterDatabaseSetStmt:
			retval = _copyAlterDatabaseSetStmt(from);
			break;
2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934
		case T_DropdbStmt:
			retval = _copyDropdbStmt(from);
			break;
		case T_VacuumStmt:
			retval = _copyVacuumStmt(from);
			break;
		case T_ExplainStmt:
			retval = _copyExplainStmt(from);
			break;
		case T_CreateSeqStmt:
			retval = _copyCreateSeqStmt(from);
			break;
B
Bruce Momjian 已提交
2935 2936 2937
		case T_AlterSeqStmt:
			retval = _copyAlterSeqStmt(from);
			break;
2938 2939 2940
		case T_VariableSetStmt:
			retval = _copyVariableSetStmt(from);
			break;
2941 2942 2943
		case T_VariableShowStmt:
			retval = _copyVariableShowStmt(from);
			break;
2944 2945 2946
		case T_VariableResetStmt:
			retval = _copyVariableResetStmt(from);
			break;
2947 2948 2949 2950 2951 2952
		case T_CreateTableSpaceStmt:
			retval = _copyCreateTableSpaceStmt(from);
			break;
		case T_DropTableSpaceStmt:
			retval = _copyDropTableSpaceStmt(from);
			break;
2953 2954 2955
		case T_CreateTrigStmt:
			retval = _copyCreateTrigStmt(from);
			break;
2956 2957
		case T_DropPropertyStmt:
			retval = _copyDropPropertyStmt(from);
2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970
			break;
		case T_CreatePLangStmt:
			retval = _copyCreatePLangStmt(from);
			break;
		case T_DropPLangStmt:
			retval = _copyDropPLangStmt(from);
			break;
		case T_CreateUserStmt:
			retval = _copyCreateUserStmt(from);
			break;
		case T_AlterUserStmt:
			retval = _copyAlterUserStmt(from);
			break;
2971 2972 2973
		case T_AlterUserSetStmt:
			retval = _copyAlterUserSetStmt(from);
			break;
2974 2975 2976
		case T_DropUserStmt:
			retval = _copyDropUserStmt(from);
			break;
2977 2978 2979
		case T_LockStmt:
			retval = _copyLockStmt(from);
			break;
2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994
		case T_ConstraintsSetStmt:
			retval = _copyConstraintsSetStmt(from);
			break;
		case T_CreateGroupStmt:
			retval = _copyCreateGroupStmt(from);
			break;
		case T_AlterGroupStmt:
			retval = _copyAlterGroupStmt(from);
			break;
		case T_DropGroupStmt:
			retval = _copyDropGroupStmt(from);
			break;
		case T_ReindexStmt:
			retval = _copyReindexStmt(from);
			break;
V
Vadim B. Mikheev 已提交
2995
		case T_CheckPointStmt:
B
Bruce Momjian 已提交
2996
			retval = (void *) makeNode(CheckPointStmt);
V
Vadim B. Mikheev 已提交
2997
			break;
2998 2999 3000
		case T_CreateSchemaStmt:
			retval = _copyCreateSchemaStmt(from);
			break;
3001 3002 3003 3004 3005 3006 3007 3008 3009
		case T_CreateConversionStmt:
			retval = _copyCreateConversionStmt(from);
			break;
		case T_CreateCastStmt:
			retval = _copyCreateCastStmt(from);
			break;
		case T_DropCastStmt:
			retval = _copyDropCastStmt(from);
			break;
3010 3011 3012 3013 3014 3015 3016 3017 3018
		case T_PrepareStmt:
			retval = _copyPrepareStmt(from);
			break;
		case T_ExecuteStmt:
			retval = _copyExecuteStmt(from);
			break;
		case T_DeallocateStmt:
			retval = _copyDeallocateStmt(from);
			break;
3019

3020 3021 3022
		case T_A_Expr:
			retval = _copyAExpr(from);
			break;
3023 3024 3025 3026 3027
		case T_ColumnRef:
			retval = _copyColumnRef(from);
			break;
		case T_ParamRef:
			retval = _copyParamRef(from);
3028
			break;
3029 3030 3031
		case T_A_Const:
			retval = _copyAConst(from);
			break;
3032 3033 3034 3035 3036 3037
		case T_FuncCall:
			retval = _copyFuncCall(from);
			break;
		case T_A_Indices:
			retval = _copyAIndices(from);
			break;
3038 3039
		case T_A_Indirection:
			retval = _copyA_Indirection(from);
3040
			break;
3041 3042 3043
		case T_ResTarget:
			retval = _copyResTarget(from);
			break;
3044 3045 3046
		case T_TypeCast:
			retval = _copyTypeCast(from);
			break;
3047 3048
		case T_SortBy:
			retval = _copySortBy(from);
3049
			break;
3050 3051 3052
		case T_RangeSubselect:
			retval = _copyRangeSubselect(from);
			break;
3053 3054 3055
		case T_RangeFunction:
			retval = _copyRangeFunction(from);
			break;
3056 3057 3058
		case T_TypeName:
			retval = _copyTypeName(from);
			break;
3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070
		case T_IndexElem:
			retval = _copyIndexElem(from);
			break;
		case T_ColumnDef:
			retval = _copyColumnDef(from);
			break;
		case T_Constraint:
			retval = _copyConstraint(from);
			break;
		case T_DefElem:
			retval = _copyDefElem(from);
			break;
3071 3072
		case T_RangeTblEntry:
			retval = _copyRangeTblEntry(from);
3073
			break;
3074 3075 3076 3077 3078 3079
		case T_SortClause:
			retval = _copySortClause(from);
			break;
		case T_GroupClause:
			retval = _copyGroupClause(from);
			break;
3080 3081 3082
		case T_FkConstraint:
			retval = _copyFkConstraint(from);
			break;
3083 3084 3085
		case T_PrivGrantee:
			retval = _copyPrivGrantee(from);
			break;
3086 3087 3088
		case T_FuncWithArgs:
			retval = _copyFuncWithArgs(from);
			break;
3089

3090
		default:
3091
			elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
3092
			retval = from;		/* keep compiler quiet */
3093
			break;
3094
	}
3095

3096
	return retval;
3097
}