copyfuncs.c 64.4 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
 *
 *
14
 * Portions Copyright (c) 1996-2007, 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.361 2007/01/10 18:06:02 tgl Exp $
19 20 21 22 23 24
 *
 *-------------------------------------------------------------------------
 */

#include "postgres.h"

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


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

/* 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))

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

49 50 51 52 53 54 55 56 57 58 59 60
/* 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)

61 62

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

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

90 91
/*
 * _copyPlan
92
 */
93
static Plan *
94
_copyPlan(Plan *from)
95
{
96
	Plan	   *newnode = makeNode(Plan);
97

98
	/*
99
	 * copy node superclass fields
100 101 102 103
	 */
	CopyPlanFields(from, newnode);

	return newnode;
104 105 106
}


107 108
/*
 * _copyResult
109
 */
110
static Result *
111
_copyResult(Result *from)
112
{
113
	Result	   *newnode = makeNode(Result);
114

115 116
	/*
	 * copy node superclass fields
117 118 119
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

120 121
	/*
	 * copy remainder of node
122
	 */
123
	COPY_NODE_FIELD(resconstantqual);
124 125

	return newnode;
126 127
}

128 129
/*
 * _copyAppend
130
 */
131
static Append *
B
Bruce Momjian 已提交
132
_copyAppend(Append *from)
133
{
134
	Append	   *newnode = makeNode(Append);
135

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

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

	return newnode;
148 149
}

150 151 152 153 154 155
/*
 * _copyBitmapAnd
 */
static BitmapAnd *
_copyBitmapAnd(BitmapAnd *from)
{
B
Bruce Momjian 已提交
156
	BitmapAnd  *newnode = makeNode(BitmapAnd);
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176

	/*
	 * copy node superclass fields
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

	/*
	 * copy remainder of node
	 */
	COPY_NODE_FIELD(bitmapplans);

	return newnode;
}

/*
 * _copyBitmapOr
 */
static BitmapOr *
_copyBitmapOr(BitmapOr *from)
{
B
Bruce Momjian 已提交
177
	BitmapOr   *newnode = makeNode(BitmapOr);
178 179 180 181 182 183 184 185 186 187 188 189 190 191

	/*
	 * copy node superclass fields
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

	/*
	 * copy remainder of node
	 */
	COPY_NODE_FIELD(bitmapplans);

	return newnode;
}

192

193 194
/*
 * CopyScanFields
195
 *
196 197
 *		This function copies the fields of the Scan node.  It is used by
 *		all the copy functions for classes which inherit from Scan.
198 199
 */
static void
200
CopyScanFields(Scan *from, Scan *newnode)
201
{
202 203 204
	CopyPlanFields((Plan *) from, (Plan *) newnode);

	COPY_SCALAR_FIELD(scanrelid);
205 206
}

207 208
/*
 * _copyScan
209
 */
210
static Scan *
211
_copyScan(Scan *from)
212
{
213
	Scan	   *newnode = makeNode(Scan);
214

215 216
	/*
	 * copy node superclass fields
217
	 */
B
Bruce Momjian 已提交
218
	CopyScanFields((Scan *) from, (Scan *) newnode);
219 220

	return newnode;
221 222
}

223 224
/*
 * _copySeqScan
225 226
 */
static SeqScan *
227
_copySeqScan(SeqScan *from)
228
{
229
	SeqScan    *newnode = makeNode(SeqScan);
230

231 232
	/*
	 * copy node superclass fields
233 234 235 236
	 */
	CopyScanFields((Scan *) from, (Scan *) newnode);

	return newnode;
237 238
}

239 240
/*
 * _copyIndexScan
241 242
 */
static IndexScan *
243
_copyIndexScan(IndexScan *from)
244
{
245
	IndexScan  *newnode = makeNode(IndexScan);
246

247 248
	/*
	 * copy node superclass fields
249 250 251
	 */
	CopyScanFields((Scan *) from, (Scan *) newnode);

252 253
	/*
	 * copy remainder of node
254
	 */
255 256 257 258 259 260
	COPY_SCALAR_FIELD(indexid);
	COPY_NODE_FIELD(indexqual);
	COPY_NODE_FIELD(indexqualorig);
	COPY_NODE_FIELD(indexstrategy);
	COPY_NODE_FIELD(indexsubtype);
	COPY_SCALAR_FIELD(indexorderdir);
261 262

	return newnode;
263 264
}

265 266 267 268 269 270
/*
 * _copyBitmapIndexScan
 */
static BitmapIndexScan *
_copyBitmapIndexScan(BitmapIndexScan *from)
{
B
Bruce Momjian 已提交
271
	BitmapIndexScan *newnode = makeNode(BitmapIndexScan);
272 273 274 275 276 277 278 279 280

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

	/*
	 * copy remainder of node
	 */
281 282 283 284 285
	COPY_SCALAR_FIELD(indexid);
	COPY_NODE_FIELD(indexqual);
	COPY_NODE_FIELD(indexqualorig);
	COPY_NODE_FIELD(indexstrategy);
	COPY_NODE_FIELD(indexsubtype);
286 287 288 289 290 291 292 293 294 295

	return newnode;
}

/*
 * _copyBitmapHeapScan
 */
static BitmapHeapScan *
_copyBitmapHeapScan(BitmapHeapScan *from)
{
B
Bruce Momjian 已提交
296
	BitmapHeapScan *newnode = makeNode(BitmapHeapScan);
297 298 299 300 301 302 303 304 305 306 307 308 309 310

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

	/*
	 * copy remainder of node
	 */
	COPY_NODE_FIELD(bitmapqualorig);

	return newnode;
}

311 312
/*
 * _copyTidScan
313 314 315 316
 */
static TidScan *
_copyTidScan(TidScan *from)
{
317
	TidScan    *newnode = makeNode(TidScan);
318

319 320
	/*
	 * copy node superclass fields
321 322
	 */
	CopyScanFields((Scan *) from, (Scan *) newnode);
323 324 325

	/*
	 * copy remainder of node
326
	 */
327
	COPY_NODE_FIELD(tidquals);
328

329 330 331
	return newnode;
}

332 333
/*
 * _copySubqueryScan
334 335 336 337
 */
static SubqueryScan *
_copySubqueryScan(SubqueryScan *from)
{
B
Bruce Momjian 已提交
338
	SubqueryScan *newnode = makeNode(SubqueryScan);
339

340 341
	/*
	 * copy node superclass fields
342 343 344
	 */
	CopyScanFields((Scan *) from, (Scan *) newnode);

345 346
	/*
	 * copy remainder of node
347
	 */
348
	COPY_NODE_FIELD(subplan);
349 350 351 352

	return newnode;
}

353 354
/*
 * _copyFunctionScan
355 356 357 358 359 360 361 362 363 364 365 366 367
 */
static FunctionScan *
_copyFunctionScan(FunctionScan *from)
{
	FunctionScan *newnode = makeNode(FunctionScan);

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

	return newnode;
}
368

369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
/*
 * _copyValuesScan
 */
static ValuesScan *
_copyValuesScan(ValuesScan *from)
{
	ValuesScan *newnode = makeNode(ValuesScan);

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

	return newnode;
}

385 386
/*
 * CopyJoinFields
387
 *
388 389
 *		This function copies the fields of the Join node.  It is used by
 *		all the copy functions for classes which inherit from Join.
390 391
 */
static void
392
CopyJoinFields(Join *from, Join *newnode)
393
{
394 395 396 397
	CopyPlanFields((Plan *) from, (Plan *) newnode);

	COPY_SCALAR_FIELD(jointype);
	COPY_NODE_FIELD(joinqual);
398 399 400
}


401 402
/*
 * _copyJoin
403
 */
404
static Join *
405
_copyJoin(Join *from)
406
{
407
	Join	   *newnode = makeNode(Join);
408

409 410
	/*
	 * copy node superclass fields
411 412 413 414
	 */
	CopyJoinFields(from, newnode);

	return newnode;
415 416 417
}


418 419
/*
 * _copyNestLoop
420 421
 */
static NestLoop *
422
_copyNestLoop(NestLoop *from)
423
{
424
	NestLoop   *newnode = makeNode(NestLoop);
425

426 427
	/*
	 * copy node superclass fields
428 429 430 431
	 */
	CopyJoinFields((Join *) from, (Join *) newnode);

	return newnode;
432 433 434
}


435 436
/*
 * _copyMergeJoin
437 438
 */
static MergeJoin *
439
_copyMergeJoin(MergeJoin *from)
440
{
441
	MergeJoin  *newnode = makeNode(MergeJoin);
442
	int			numCols;
443

444 445
	/*
	 * copy node superclass fields
446 447 448
	 */
	CopyJoinFields((Join *) from, (Join *) newnode);

449 450
	/*
	 * copy remainder of node
451
	 */
452
	COPY_NODE_FIELD(mergeclauses);
453 454 455 456
	numCols = list_length(from->mergeclauses);
	COPY_POINTER_FIELD(mergeFamilies, numCols * sizeof(Oid));
	COPY_POINTER_FIELD(mergeStrategies, numCols * sizeof(int));
	COPY_POINTER_FIELD(mergeNullsFirst, numCols * sizeof(bool));
457 458

	return newnode;
459 460
}

461 462
/*
 * _copyHashJoin
463 464
 */
static HashJoin *
465
_copyHashJoin(HashJoin *from)
466
{
467
	HashJoin   *newnode = makeNode(HashJoin);
468

469 470
	/*
	 * copy node superclass fields
471 472 473
	 */
	CopyJoinFields((Join *) from, (Join *) newnode);

474 475
	/*
	 * copy remainder of node
476
	 */
477
	COPY_NODE_FIELD(hashclauses);
478 479

	return newnode;
480 481 482
}


483 484
/*
 * _copyMaterial
485 486
 */
static Material *
487
_copyMaterial(Material *from)
488
{
489
	Material   *newnode = makeNode(Material);
490

491 492
	/*
	 * copy node superclass fields
493 494 495 496
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

	return newnode;
497 498 499
}


500 501
/*
 * _copySort
502
 */
503
static Sort *
504
_copySort(Sort *from)
505
{
506
	Sort	   *newnode = makeNode(Sort);
507

508 509
	/*
	 * copy node superclass fields
510 511
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
512

513 514 515
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
	COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
516
	COPY_POINTER_FIELD(nullsFirst, from->numCols * sizeof(bool));
517 518

	return newnode;
519 520
}

V
Vadim B. Mikheev 已提交
521

522 523
/*
 * _copyGroup
V
Vadim B. Mikheev 已提交
524 525 526 527 528
 */
static Group *
_copyGroup(Group *from)
{
	Group	   *newnode = makeNode(Group);
529

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

532 533
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
534
	COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
V
Vadim B. Mikheev 已提交
535 536 537 538

	return newnode;
}

539 540
/*
 * _copyAgg
541
 */
542
static Agg *
B
Bruce Momjian 已提交
543
_copyAgg(Agg *from)
544
{
545
	Agg		   *newnode = makeNode(Agg);
546 547 548

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

549 550
	COPY_SCALAR_FIELD(aggstrategy);
	COPY_SCALAR_FIELD(numCols);
551
	if (from->numCols > 0)
552
	{
553
		COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
554 555
		COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
	}
556
	COPY_SCALAR_FIELD(numGroups);
557

558
	return newnode;
559 560
}

561 562
/*
 * _copyUnique
563
 */
564
static Unique *
565
_copyUnique(Unique *from)
566
{
567
	Unique	   *newnode = makeNode(Unique);
568

569 570
	/*
	 * copy node superclass fields
571 572 573
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

574 575
	/*
	 * copy remainder of node
576
	 */
577 578
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
579
	COPY_POINTER_FIELD(uniqOperators, from->numCols * sizeof(Oid));
580 581

	return newnode;
582 583
}

584
/*
585
 * _copyHash
586
 */
587 588
static Hash *
_copyHash(Hash *from)
589
{
590
	Hash	   *newnode = makeNode(Hash);
591

592 593
	/*
	 * copy node superclass fields
594 595 596
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

597 598
	/*
	 * copy remainder of node
599 600 601 602
	 */

	return newnode;
}
603

604
/*
605
 * _copySetOp
606
 */
607 608
static SetOp *
_copySetOp(SetOp *from)
609
{
610
	SetOp	   *newnode = makeNode(SetOp);
611

612 613
	/*
	 * copy node superclass fields
614 615 616
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

617 618
	/*
	 * copy remainder of node
619
	 */
620 621 622
	COPY_SCALAR_FIELD(cmd);
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
623
	COPY_POINTER_FIELD(dupOperators, from->numCols * sizeof(Oid));
624
	COPY_SCALAR_FIELD(flagColIdx);
625 626 627 628

	return newnode;
}

629
/*
630
 * _copyLimit
631
 */
632 633
static Limit *
_copyLimit(Limit *from)
634
{
635
	Limit	   *newnode = makeNode(Limit);
636

637 638
	/*
	 * copy node superclass fields
639 640 641
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

642 643
	/*
	 * copy remainder of node
644
	 */
645 646
	COPY_NODE_FIELD(limitOffset);
	COPY_NODE_FIELD(limitCount);
647 648

	return newnode;
649 650 651
}

/* ****************************************************************
652
 *					   primnodes.h copy functions
653 654 655
 * ****************************************************************
 */

656 657 658
/*
 * _copyAlias
 */
659 660 661 662
static Alias *
_copyAlias(Alias *from)
{
	Alias	   *newnode = makeNode(Alias);
663

664 665
	COPY_STRING_FIELD(aliasname);
	COPY_NODE_FIELD(colnames);
666

667 668
	return newnode;
}
669

670 671 672
/*
 * _copyRangeVar
 */
673 674 675 676 677 678 679 680 681 682 683
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);
684 685

	return newnode;
686 687
}

688
/*
689
 * We don't need a _copyExpr because Expr is an abstract supertype which
B
Bruce Momjian 已提交
690
 * should never actually get instantiated.	Also, since it has no common
691 692
 * fields except NodeTag, there's no need for a helper routine to factor
 * out copying the common fields...
693 694
 */

695 696
/*
 * _copyVar
697
 */
698
static Var *
699
_copyVar(Var *from)
700
{
701
	Var		   *newnode = makeNode(Var);
702

703 704 705 706 707 708 709
	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);
710 711

	return newnode;
712 713
}

714 715
/*
 * _copyConst
716
 */
717
static Const *
718
_copyConst(Const *from)
719
{
720
	Const	   *newnode = makeNode(Const);
721

722 723
	COPY_SCALAR_FIELD(consttype);
	COPY_SCALAR_FIELD(constlen);
724

725
	if (from->constbyval || from->constisnull)
726
	{
727 728 729
		/*
		 * passed by value so just copy the datum. Also, don't try to copy
		 * struct when value is null!
730
		 */
731
		newnode->constvalue = from->constvalue;
732
	}
733
	else
734
	{
735
		/*
736
		 * passed by reference.  We need a palloc'd copy.
737
		 */
738 739 740
		newnode->constvalue = datumCopy(from->constvalue,
										from->constbyval,
										from->constlen);
741
	}
742

743 744
	COPY_SCALAR_FIELD(constisnull);
	COPY_SCALAR_FIELD(constbyval);
745 746

	return newnode;
747 748
}

749 750
/*
 * _copyParam
751
 */
752
static Param *
753
_copyParam(Param *from)
754
{
755
	Param	   *newnode = makeNode(Param);
756

757 758 759
	COPY_SCALAR_FIELD(paramkind);
	COPY_SCALAR_FIELD(paramid);
	COPY_SCALAR_FIELD(paramtype);
760
	COPY_SCALAR_FIELD(paramtypmod);
761 762

	return newnode;
763 764
}

765
/*
766
 * _copyAggref
767
 */
768 769
static Aggref *
_copyAggref(Aggref *from)
770
{
771 772 773 774
	Aggref	   *newnode = makeNode(Aggref);

	COPY_SCALAR_FIELD(aggfnoid);
	COPY_SCALAR_FIELD(aggtype);
775
	COPY_NODE_FIELD(args);
776
	COPY_SCALAR_FIELD(agglevelsup);
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
	COPY_SCALAR_FIELD(aggstar);
	COPY_SCALAR_FIELD(aggdistinct);

	return newnode;
}

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

	COPY_SCALAR_FIELD(refrestype);
792 793
	COPY_SCALAR_FIELD(refarraytype);
	COPY_SCALAR_FIELD(refelemtype);
794 795 796 797 798 799 800 801 802 803 804 805
	COPY_NODE_FIELD(refupperindexpr);
	COPY_NODE_FIELD(reflowerindexpr);
	COPY_NODE_FIELD(refexpr);
	COPY_NODE_FIELD(refassgnexpr);

	return newnode;
}

/*
 * _copyFuncExpr
 */
static FuncExpr *
806
_copyFuncExpr(FuncExpr *from)
807
{
B
Bruce Momjian 已提交
808
	FuncExpr   *newnode = makeNode(FuncExpr);
809

810 811 812 813
	COPY_SCALAR_FIELD(funcid);
	COPY_SCALAR_FIELD(funcresulttype);
	COPY_SCALAR_FIELD(funcretset);
	COPY_SCALAR_FIELD(funcformat);
814
	COPY_NODE_FIELD(args);
815

816
	return newnode;
817 818
}

819
/*
820
 * _copyOpExpr
821
 */
822
static OpExpr *
823
_copyOpExpr(OpExpr *from)
824
{
825
	OpExpr	   *newnode = makeNode(OpExpr);
826

827 828 829 830 831 832 833 834 835 836
	COPY_SCALAR_FIELD(opno);
	COPY_SCALAR_FIELD(opfuncid);
	COPY_SCALAR_FIELD(opresulttype);
	COPY_SCALAR_FIELD(opretset);
	COPY_NODE_FIELD(args);

	return newnode;
}

/*
837
 * _copyDistinctExpr (same as OpExpr)
838 839
 */
static DistinctExpr *
840
_copyDistinctExpr(DistinctExpr *from)
841
{
B
Bruce Momjian 已提交
842
	DistinctExpr *newnode = makeNode(DistinctExpr);
843 844 845 846 847 848 849 850 851 852

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

	return newnode;
}

853 854 855 856
/*
 * _copyScalarArrayOpExpr
 */
static ScalarArrayOpExpr *
857
_copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
858
{
B
Bruce Momjian 已提交
859
	ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
860 861 862 863 864 865 866 867 868

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

	return newnode;
}

869 870 871 872
/*
 * _copyBoolExpr
 */
static BoolExpr *
873
_copyBoolExpr(BoolExpr *from)
874
{
B
Bruce Momjian 已提交
875
	BoolExpr   *newnode = makeNode(BoolExpr);
876 877 878

	COPY_SCALAR_FIELD(boolop);
	COPY_NODE_FIELD(args);
879 880

	return newnode;
881 882
}

883 884
/*
 * _copySubLink
885 886 887 888
 */
static SubLink *
_copySubLink(SubLink *from)
{
889
	SubLink    *newnode = makeNode(SubLink);
890

891
	COPY_SCALAR_FIELD(subLinkType);
892
	COPY_NODE_FIELD(testexpr);
893
	COPY_NODE_FIELD(operName);
894
	COPY_NODE_FIELD(subselect);
895 896 897 898

	return newnode;
}

899
/*
900
 * _copySubPlan
901
 */
902 903
static SubPlan *
_copySubPlan(SubPlan *from)
904
{
905
	SubPlan    *newnode = makeNode(SubPlan);
906

907
	COPY_SCALAR_FIELD(subLinkType);
908
	COPY_NODE_FIELD(testexpr);
909
	COPY_NODE_FIELD(paramIds);
910 911 912
	COPY_NODE_FIELD(plan);
	COPY_SCALAR_FIELD(plan_id);
	COPY_NODE_FIELD(rtable);
913 914
	COPY_SCALAR_FIELD(useHashTable);
	COPY_SCALAR_FIELD(unknownEqFalse);
915 916
	COPY_NODE_FIELD(setParam);
	COPY_NODE_FIELD(parParam);
917 918 919 920 921
	COPY_NODE_FIELD(args);

	return newnode;
}

922 923
/*
 * _copyFieldSelect
924 925 926 927 928 929
 */
static FieldSelect *
_copyFieldSelect(FieldSelect *from)
{
	FieldSelect *newnode = makeNode(FieldSelect);

930 931 932 933
	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(fieldnum);
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
934 935 936 937

	return newnode;
}

938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953
/*
 * _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;
}

954 955
/*
 * _copyRelabelType
956 957 958 959
 */
static RelabelType *
_copyRelabelType(RelabelType *from)
{
960
	RelabelType *newnode = makeNode(RelabelType);
961

962 963 964 965
	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
	COPY_SCALAR_FIELD(relabelformat);
966 967 968 969

	return newnode;
}

970 971 972 973 974 975 976 977 978 979 980 981 982 983 984
/*
 * _copyConvertRowtypeExpr
 */
static ConvertRowtypeExpr *
_copyConvertRowtypeExpr(ConvertRowtypeExpr *from)
{
	ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);

	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(convertformat);

	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 1014
/*
 * _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;
}

1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
/*
 * _copyCaseTestExpr
 */
static CaseTestExpr *
_copyCaseTestExpr(CaseTestExpr *from)
{
	CaseTestExpr *newnode = makeNode(CaseTestExpr);

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);

	return newnode;
}

1029 1030 1031 1032
/*
 * _copyArrayExpr
 */
static ArrayExpr *
1033
_copyArrayExpr(ArrayExpr *from)
1034
{
B
Bruce Momjian 已提交
1035
	ArrayExpr  *newnode = makeNode(ArrayExpr);
1036 1037 1038 1039

	COPY_SCALAR_FIELD(array_typeid);
	COPY_SCALAR_FIELD(element_typeid);
	COPY_NODE_FIELD(elements);
1040
	COPY_SCALAR_FIELD(multidims);
1041 1042 1043 1044

	return newnode;
}

1045 1046 1047 1048 1049 1050
/*
 * _copyRowExpr
 */
static RowExpr *
_copyRowExpr(RowExpr *from)
{
B
Bruce Momjian 已提交
1051
	RowExpr    *newnode = makeNode(RowExpr);
1052 1053 1054 1055 1056 1057 1058 1059

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

	return newnode;
}

1060 1061 1062 1063 1064 1065
/*
 * _copyRowCompareExpr
 */
static RowCompareExpr *
_copyRowCompareExpr(RowCompareExpr *from)
{
B
Bruce Momjian 已提交
1066
	RowCompareExpr *newnode = makeNode(RowCompareExpr);
1067 1068 1069

	COPY_SCALAR_FIELD(rctype);
	COPY_NODE_FIELD(opnos);
1070
	COPY_NODE_FIELD(opfamilies);
1071 1072 1073 1074 1075 1076
	COPY_NODE_FIELD(largs);
	COPY_NODE_FIELD(rargs);

	return newnode;
}

1077 1078 1079 1080
/*
 * _copyCoalesceExpr
 */
static CoalesceExpr *
1081
_copyCoalesceExpr(CoalesceExpr *from)
1082 1083 1084 1085 1086 1087 1088 1089 1090
{
	CoalesceExpr *newnode = makeNode(CoalesceExpr);

	COPY_SCALAR_FIELD(coalescetype);
	COPY_NODE_FIELD(args);

	return newnode;
}

1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
/*
 * _copyMinMaxExpr
 */
static MinMaxExpr *
_copyMinMaxExpr(MinMaxExpr *from)
{
	MinMaxExpr *newnode = makeNode(MinMaxExpr);

	COPY_SCALAR_FIELD(minmaxtype);
	COPY_SCALAR_FIELD(op);
	COPY_NODE_FIELD(args);

	return newnode;
}

1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122
/*
 * _copyXmlExpr
 */
static XmlExpr *
_copyXmlExpr(XmlExpr *from)
{
	XmlExpr *newnode = makeNode(XmlExpr);

	COPY_SCALAR_FIELD(op);
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(named_args);
	COPY_NODE_FIELD(arg_names);
	COPY_NODE_FIELD(args);

	return newnode;
}

1123 1124 1125 1126
/*
 * _copyNullIfExpr (same as OpExpr)
 */
static NullIfExpr *
1127
_copyNullIfExpr(NullIfExpr *from)
1128
{
B
Bruce Momjian 已提交
1129
	NullIfExpr *newnode = makeNode(NullIfExpr);
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139

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

	return newnode;
}

1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168
/*
 * _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;
}

/*
1169
 * _copyCoerceToDomain
1170
 */
1171
static CoerceToDomain *
1172
_copyCoerceToDomain(CoerceToDomain *from)
1173
{
1174
	CoerceToDomain *newnode = makeNode(CoerceToDomain);
1175 1176

	COPY_NODE_FIELD(arg);
1177 1178 1179
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
	COPY_SCALAR_FIELD(coercionformat);
1180 1181 1182 1183 1184

	return newnode;
}

/*
1185
 * _copyCoerceToDomainValue
1186
 */
1187
static CoerceToDomainValue *
1188
_copyCoerceToDomainValue(CoerceToDomainValue *from)
1189
{
1190
	CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1191 1192 1193 1194 1195 1196 1197

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);

	return newnode;
}

1198 1199 1200 1201
/*
 * _copySetToDefault
 */
static SetToDefault *
1202
_copySetToDefault(SetToDefault *from)
1203 1204 1205 1206 1207 1208 1209 1210 1211
{
	SetToDefault *newnode = makeNode(SetToDefault);

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);

	return newnode;
}

1212 1213 1214 1215 1216 1217 1218 1219 1220
/*
 * _copyTargetEntry
 */
static TargetEntry *
_copyTargetEntry(TargetEntry *from)
{
	TargetEntry *newnode = makeNode(TargetEntry);

	COPY_NODE_FIELD(expr);
1221 1222 1223 1224 1225 1226
	COPY_SCALAR_FIELD(resno);
	COPY_STRING_FIELD(resname);
	COPY_SCALAR_FIELD(ressortgroupref);
	COPY_SCALAR_FIELD(resorigtbl);
	COPY_SCALAR_FIELD(resorigcol);
	COPY_SCALAR_FIELD(resjunk);
1227 1228 1229 1230 1231 1232 1233

	return newnode;
}

/*
 * _copyRangeTblRef
 */
1234 1235 1236 1237 1238
static RangeTblRef *
_copyRangeTblRef(RangeTblRef *from)
{
	RangeTblRef *newnode = makeNode(RangeTblRef);

1239
	COPY_SCALAR_FIELD(rtindex);
1240 1241 1242 1243

	return newnode;
}

1244 1245 1246
/*
 * _copyJoinExpr
 */
1247 1248 1249
static JoinExpr *
_copyJoinExpr(JoinExpr *from)
{
B
Bruce Momjian 已提交
1250
	JoinExpr   *newnode = makeNode(JoinExpr);
1251

1252 1253 1254 1255 1256 1257 1258 1259
	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 已提交
1260 1261 1262 1263

	return newnode;
}

1264 1265 1266
/*
 * _copyFromExpr
 */
1267 1268
static FromExpr *
_copyFromExpr(FromExpr *from)
B
Bruce Momjian 已提交
1269
{
1270
	FromExpr   *newnode = makeNode(FromExpr);
B
Bruce Momjian 已提交
1271

1272 1273
	COPY_NODE_FIELD(fromlist);
	COPY_NODE_FIELD(quals);
B
Bruce Momjian 已提交
1274 1275 1276 1277

	return newnode;
}

1278
/* ****************************************************************
1279
 *						relation.h copy functions
1280
 *
1281 1282
 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
 * There are some subsidiary structs that are useful to copy, though.
1283 1284 1285
 * ****************************************************************
 */

1286 1287
/*
 * _copyPathKeyItem
1288
 */
1289 1290
static PathKeyItem *
_copyPathKeyItem(PathKeyItem *from)
1291
{
1292
	PathKeyItem *newnode = makeNode(PathKeyItem);
1293

1294 1295
	COPY_NODE_FIELD(key);
	COPY_SCALAR_FIELD(sortop);
1296
	COPY_SCALAR_FIELD(nulls_first);
1297 1298

	return newnode;
1299 1300
}

1301 1302
/*
 * _copyRestrictInfo
1303
 */
1304
static RestrictInfo *
1305
_copyRestrictInfo(RestrictInfo *from)
1306
{
1307
	RestrictInfo *newnode = makeNode(RestrictInfo);
1308

1309
	COPY_NODE_FIELD(clause);
1310
	COPY_SCALAR_FIELD(is_pushed_down);
1311
	COPY_SCALAR_FIELD(outerjoin_delayed);
1312
	COPY_SCALAR_FIELD(can_join);
1313
	COPY_SCALAR_FIELD(pseudoconstant);
1314
	COPY_BITMAPSET_FIELD(clause_relids);
1315
	COPY_BITMAPSET_FIELD(required_relids);
1316 1317
	COPY_BITMAPSET_FIELD(left_relids);
	COPY_BITMAPSET_FIELD(right_relids);
1318
	COPY_NODE_FIELD(orclause);
1319 1320 1321 1322 1323
	COPY_SCALAR_FIELD(eval_cost);
	COPY_SCALAR_FIELD(this_selec);
	COPY_SCALAR_FIELD(mergejoinoperator);
	COPY_SCALAR_FIELD(left_sortop);
	COPY_SCALAR_FIELD(right_sortop);
1324
	COPY_SCALAR_FIELD(mergeopfamily);
B
Bruce Momjian 已提交
1325 1326

	/*
B
Bruce Momjian 已提交
1327
	 * Do not copy pathkeys, since they'd not be canonical in a copied query
B
Bruce Momjian 已提交
1328
	 */
1329 1330
	newnode->left_pathkey = NIL;
	newnode->right_pathkey = NIL;
1331 1332 1333 1334 1335 1336

	COPY_SCALAR_FIELD(left_mergescansel);
	COPY_SCALAR_FIELD(right_mergescansel);
	COPY_SCALAR_FIELD(hashjoinoperator);
	COPY_SCALAR_FIELD(left_bucketsize);
	COPY_SCALAR_FIELD(right_bucketsize);
1337 1338

	return newnode;
1339 1340
}

1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356
/*
 * _copyOuterJoinInfo
 */
static OuterJoinInfo *
_copyOuterJoinInfo(OuterJoinInfo *from)
{
	OuterJoinInfo *newnode = makeNode(OuterJoinInfo);

	COPY_BITMAPSET_FIELD(min_lefthand);
	COPY_BITMAPSET_FIELD(min_righthand);
	COPY_SCALAR_FIELD(is_full_join);
	COPY_SCALAR_FIELD(lhs_strict);

	return newnode;
}

1357 1358 1359 1360
/*
 * _copyInClauseInfo
 */
static InClauseInfo *
1361
_copyInClauseInfo(InClauseInfo *from)
1362 1363 1364
{
	InClauseInfo *newnode = makeNode(InClauseInfo);

1365 1366
	COPY_BITMAPSET_FIELD(lefthand);
	COPY_BITMAPSET_FIELD(righthand);
1367
	COPY_NODE_FIELD(sub_targetlist);
1368
	COPY_NODE_FIELD(in_operators);
1369 1370 1371 1372

	return newnode;
}

1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391
/*
 * _copyAppendRelInfo
 */
static AppendRelInfo *
_copyAppendRelInfo(AppendRelInfo *from)
{
	AppendRelInfo *newnode = makeNode(AppendRelInfo);

	COPY_SCALAR_FIELD(parent_relid);
	COPY_SCALAR_FIELD(child_relid);
	COPY_SCALAR_FIELD(parent_reltype);
	COPY_SCALAR_FIELD(child_reltype);
	COPY_NODE_FIELD(col_mappings);
	COPY_NODE_FIELD(translated_vars);
	COPY_SCALAR_FIELD(parent_reloid);

	return newnode;
}

1392 1393 1394
/* ****************************************************************
 *					parsenodes.h copy functions
 * ****************************************************************
1395 1396 1397
 */

static RangeTblEntry *
1398
_copyRangeTblEntry(RangeTblEntry *from)
1399
{
1400
	RangeTblEntry *newnode = makeNode(RangeTblEntry);
1401

1402 1403 1404 1405
	COPY_SCALAR_FIELD(rtekind);
	COPY_SCALAR_FIELD(relid);
	COPY_NODE_FIELD(subquery);
	COPY_NODE_FIELD(funcexpr);
1406 1407
	COPY_NODE_FIELD(funccoltypes);
	COPY_NODE_FIELD(funccoltypmods);
1408
	COPY_NODE_FIELD(values_lists);
1409 1410 1411 1412 1413 1414
	COPY_SCALAR_FIELD(jointype);
	COPY_NODE_FIELD(joinaliasvars);
	COPY_NODE_FIELD(alias);
	COPY_NODE_FIELD(eref);
	COPY_SCALAR_FIELD(inh);
	COPY_SCALAR_FIELD(inFromCl);
1415
	COPY_SCALAR_FIELD(requiredPerms);
1416
	COPY_SCALAR_FIELD(checkAsUser);
1417 1418 1419 1420

	return newnode;
}

1421 1422 1423
static FkConstraint *
_copyFkConstraint(FkConstraint *from)
{
B
Bruce Momjian 已提交
1424
	FkConstraint *newnode = makeNode(FkConstraint);
1425

1426 1427 1428 1429 1430 1431 1432 1433 1434 1435
	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 已提交
1436

1437 1438 1439
	return newnode;
}

1440
static SortClause *
1441
_copySortClause(SortClause *from)
1442
{
1443
	SortClause *newnode = makeNode(SortClause);
1444

1445 1446
	COPY_SCALAR_FIELD(tleSortGroupRef);
	COPY_SCALAR_FIELD(sortop);
1447
	COPY_SCALAR_FIELD(nulls_first);
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458

	return newnode;
}

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

	COPY_SCALAR_FIELD(tleSortGroupRef);
	COPY_SCALAR_FIELD(sortop);
1459
	COPY_SCALAR_FIELD(nulls_first);
1460

1461
	return newnode;
1462 1463
}

1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475
static RowMarkClause *
_copyRowMarkClause(RowMarkClause *from)
{
	RowMarkClause *newnode = makeNode(RowMarkClause);

	COPY_SCALAR_FIELD(rti);
	COPY_SCALAR_FIELD(forUpdate);
	COPY_SCALAR_FIELD(noWait);

	return newnode;
}

1476 1477 1478
static A_Expr *
_copyAExpr(A_Expr *from)
{
B
Bruce Momjian 已提交
1479
	A_Expr	   *newnode = makeNode(A_Expr);
1480

1481
	COPY_SCALAR_FIELD(kind);
1482 1483 1484
	COPY_NODE_FIELD(name);
	COPY_NODE_FIELD(lexpr);
	COPY_NODE_FIELD(rexpr);
1485
	COPY_SCALAR_FIELD(location);
1486 1487 1488 1489

	return newnode;
}

1490 1491
static ColumnRef *
_copyColumnRef(ColumnRef *from)
1492
{
B
Bruce Momjian 已提交
1493
	ColumnRef  *newnode = makeNode(ColumnRef);
1494

1495
	COPY_NODE_FIELD(fields);
1496
	COPY_SCALAR_FIELD(location);
1497

1498
	return newnode;
1499 1500
}

1501 1502
static ParamRef *
_copyParamRef(ParamRef *from)
1503
{
B
Bruce Momjian 已提交
1504
	ParamRef   *newnode = makeNode(ParamRef);
1505

1506
	COPY_SCALAR_FIELD(number);
1507 1508 1509 1510

	return newnode;
}

1511 1512 1513 1514 1515
static A_Const *
_copyAConst(A_Const *from)
{
	A_Const    *newnode = makeNode(A_Const);

1516
	/* This part must duplicate _copyValue */
1517
	COPY_SCALAR_FIELD(val.type);
1518 1519 1520
	switch (from->val.type)
	{
		case T_Integer:
1521
			COPY_SCALAR_FIELD(val.val.ival);
1522 1523 1524 1525
			break;
		case T_Float:
		case T_String:
		case T_BitString:
1526
			COPY_STRING_FIELD(val.val.str);
1527 1528 1529 1530 1531
			break;
		case T_Null:
			/* nothing to do */
			break;
		default:
1532 1533
			elog(ERROR, "unrecognized node type: %d",
				 (int) from->val.type);
1534 1535 1536
			break;
	}

1537
	COPY_NODE_FIELD(typename);
1538 1539 1540 1541

	return newnode;
}

1542 1543 1544
static FuncCall *
_copyFuncCall(FuncCall *from)
{
B
Bruce Momjian 已提交
1545
	FuncCall   *newnode = makeNode(FuncCall);
1546

1547 1548 1549 1550
	COPY_NODE_FIELD(funcname);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(agg_star);
	COPY_SCALAR_FIELD(agg_distinct);
1551
	COPY_SCALAR_FIELD(location);
1552 1553 1554 1555 1556 1557 1558

	return newnode;
}

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

1561 1562
	COPY_NODE_FIELD(lidx);
	COPY_NODE_FIELD(uidx);
1563 1564 1565 1566

	return newnode;
}

1567 1568
static A_Indirection *
_copyA_Indirection(A_Indirection *from)
1569
{
1570
	A_Indirection *newnode = makeNode(A_Indirection);
1571

1572 1573
	COPY_NODE_FIELD(arg);
	COPY_NODE_FIELD(indirection);
1574 1575 1576 1577

	return newnode;
}

1578 1579 1580
static ResTarget *
_copyResTarget(ResTarget *from)
{
B
Bruce Momjian 已提交
1581
	ResTarget  *newnode = makeNode(ResTarget);
1582

1583 1584 1585
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(indirection);
	COPY_NODE_FIELD(val);
1586
	COPY_SCALAR_FIELD(location);
1587 1588 1589 1590

	return newnode;
}

1591
static TypeName *
1592
_copyTypeName(TypeName *from)
1593
{
1594
	TypeName   *newnode = makeNode(TypeName);
1595

1596 1597 1598 1599 1600
	COPY_NODE_FIELD(names);
	COPY_SCALAR_FIELD(typeid);
	COPY_SCALAR_FIELD(timezone);
	COPY_SCALAR_FIELD(setof);
	COPY_SCALAR_FIELD(pct_type);
1601 1602
	COPY_NODE_FIELD(typmods);
	COPY_SCALAR_FIELD(typemod);
1603
	COPY_NODE_FIELD(arrayBounds);
1604
	COPY_SCALAR_FIELD(location);
1605 1606

	return newnode;
1607 1608
}

1609 1610
static SortBy *
_copySortBy(SortBy *from)
1611
{
B
Bruce Momjian 已提交
1612
	SortBy	   *newnode = makeNode(SortBy);
1613

1614 1615
	COPY_SCALAR_FIELD(sortby_dir);
	COPY_SCALAR_FIELD(sortby_nulls);
1616 1617
	COPY_NODE_FIELD(useOp);
	COPY_NODE_FIELD(node);
1618 1619 1620 1621 1622 1623 1624

	return newnode;
}

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

1627 1628
	COPY_NODE_FIELD(subquery);
	COPY_NODE_FIELD(alias);
1629 1630 1631 1632

	return newnode;
}

1633 1634 1635
static RangeFunction *
_copyRangeFunction(RangeFunction *from)
{
B
Bruce Momjian 已提交
1636
	RangeFunction *newnode = makeNode(RangeFunction);
1637

1638 1639 1640
	COPY_NODE_FIELD(funccallnode);
	COPY_NODE_FIELD(alias);
	COPY_NODE_FIELD(coldeflist);
1641 1642 1643 1644

	return newnode;
}

1645 1646 1647 1648 1649
static TypeCast *
_copyTypeCast(TypeCast *from)
{
	TypeCast   *newnode = makeNode(TypeCast);

1650 1651
	COPY_NODE_FIELD(arg);
	COPY_NODE_FIELD(typename);
1652 1653 1654 1655

	return newnode;
}

1656 1657 1658
static IndexElem *
_copyIndexElem(IndexElem *from)
{
B
Bruce Momjian 已提交
1659
	IndexElem  *newnode = makeNode(IndexElem);
1660

1661
	COPY_STRING_FIELD(name);
1662
	COPY_NODE_FIELD(expr);
1663
	COPY_NODE_FIELD(opclass);
1664 1665
	COPY_SCALAR_FIELD(ordering);
	COPY_SCALAR_FIELD(nulls_ordering);
1666 1667 1668 1669 1670 1671 1672

	return newnode;
}

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

1675 1676 1677 1678 1679 1680 1681 1682
	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);
1683 1684 1685 1686 1687 1688 1689

	return newnode;
}

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

1692 1693 1694 1695 1696
	COPY_SCALAR_FIELD(contype);
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(raw_expr);
	COPY_STRING_FIELD(cooked_expr);
	COPY_NODE_FIELD(keys);
B
Bruce Momjian 已提交
1697
	COPY_NODE_FIELD(options);
1698
	COPY_STRING_FIELD(indexspace);
1699 1700 1701 1702

	return newnode;
}

1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713
static DefElem *
_copyDefElem(DefElem *from)
{
	DefElem    *newnode = makeNode(DefElem);

	COPY_STRING_FIELD(defname);
	COPY_NODE_FIELD(arg);

	return newnode;
}

1714 1715 1716 1717 1718 1719 1720
static LockingClause *
_copyLockingClause(LockingClause *from)
{
	LockingClause *newnode = makeNode(LockingClause);

	COPY_NODE_FIELD(lockedRels);
	COPY_SCALAR_FIELD(forUpdate);
1721
	COPY_SCALAR_FIELD(noWait);
1722 1723 1724 1725

	return newnode;
}

1726 1727 1728 1729 1730 1731 1732
static Query *
_copyQuery(Query *from)
{
	Query	   *newnode = makeNode(Query);

	COPY_SCALAR_FIELD(commandType);
	COPY_SCALAR_FIELD(querySource);
1733
	COPY_SCALAR_FIELD(canSetTag);
1734 1735 1736
	COPY_NODE_FIELD(utilityStmt);
	COPY_SCALAR_FIELD(resultRelation);
	COPY_NODE_FIELD(into);
B
Bruce Momjian 已提交
1737
	COPY_NODE_FIELD(intoOptions);
1738 1739
	COPY_SCALAR_FIELD(intoOnCommit);
	COPY_STRING_FIELD(intoTableSpaceName);
1740 1741 1742 1743 1744
	COPY_SCALAR_FIELD(hasAggs);
	COPY_SCALAR_FIELD(hasSubLinks);
	COPY_NODE_FIELD(rtable);
	COPY_NODE_FIELD(jointree);
	COPY_NODE_FIELD(targetList);
1745
	COPY_NODE_FIELD(returningList);
1746 1747 1748 1749 1750 1751
	COPY_NODE_FIELD(groupClause);
	COPY_NODE_FIELD(havingQual);
	COPY_NODE_FIELD(distinctClause);
	COPY_NODE_FIELD(sortClause);
	COPY_NODE_FIELD(limitOffset);
	COPY_NODE_FIELD(limitCount);
1752
	COPY_NODE_FIELD(rowMarks);
1753
	COPY_NODE_FIELD(setOperations);
1754
	COPY_NODE_FIELD(resultRelations);
1755
	COPY_NODE_FIELD(returningLists);
1756

1757
	return newnode;
1758 1759
}

1760 1761 1762 1763
static InsertStmt *
_copyInsertStmt(InsertStmt *from)
{
	InsertStmt *newnode = makeNode(InsertStmt);
B
Bruce Momjian 已提交
1764

1765 1766 1767
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(cols);
	COPY_NODE_FIELD(selectStmt);
1768
	COPY_NODE_FIELD(returningList);
1769 1770 1771 1772 1773 1774 1775 1776

	return newnode;
}

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

1778
	COPY_NODE_FIELD(relation);
1779
	COPY_NODE_FIELD(usingClause);
1780 1781
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(returningList);
1782 1783 1784 1785 1786 1787 1788 1789

	return newnode;
}

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

1791 1792 1793 1794
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(targetList);
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(fromClause);
1795
	COPY_NODE_FIELD(returningList);
1796 1797 1798 1799 1800 1801 1802 1803

	return newnode;
}

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

1805 1806 1807
	COPY_NODE_FIELD(distinctClause);
	COPY_NODE_FIELD(into);
	COPY_NODE_FIELD(intoColNames);
B
Bruce Momjian 已提交
1808
	COPY_NODE_FIELD(intoOptions);
1809 1810
	COPY_SCALAR_FIELD(intoOnCommit);
	COPY_STRING_FIELD(intoTableSpaceName);
1811 1812 1813 1814 1815
	COPY_NODE_FIELD(targetList);
	COPY_NODE_FIELD(fromClause);
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(groupClause);
	COPY_NODE_FIELD(havingClause);
1816
	COPY_NODE_FIELD(valuesLists);
1817 1818 1819
	COPY_NODE_FIELD(sortClause);
	COPY_NODE_FIELD(limitOffset);
	COPY_NODE_FIELD(limitCount);
1820
	COPY_NODE_FIELD(lockingClause);
1821 1822 1823 1824
	COPY_SCALAR_FIELD(op);
	COPY_SCALAR_FIELD(all);
	COPY_NODE_FIELD(larg);
	COPY_NODE_FIELD(rarg);
1825 1826 1827 1828

	return newnode;
}

1829 1830 1831 1832
static SetOperationStmt *
_copySetOperationStmt(SetOperationStmt *from)
{
	SetOperationStmt *newnode = makeNode(SetOperationStmt);
B
Bruce Momjian 已提交
1833

1834 1835 1836 1837
	COPY_SCALAR_FIELD(op);
	COPY_SCALAR_FIELD(all);
	COPY_NODE_FIELD(larg);
	COPY_NODE_FIELD(rarg);
1838
	COPY_NODE_FIELD(colTypes);
1839
	COPY_NODE_FIELD(colTypmods);
1840 1841 1842 1843

	return newnode;
}

1844 1845 1846 1847
static AlterTableStmt *
_copyAlterTableStmt(AlterTableStmt *from)
{
	AlterTableStmt *newnode = makeNode(AlterTableStmt);
B
Bruce Momjian 已提交
1848

1849
	COPY_NODE_FIELD(relation);
T
Tom Lane 已提交
1850
	COPY_NODE_FIELD(cmds);
T
Tom Lane 已提交
1851
	COPY_SCALAR_FIELD(relkind);
T
Tom Lane 已提交
1852 1853 1854 1855 1856 1857 1858 1859 1860 1861

	return newnode;
}

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

	COPY_SCALAR_FIELD(subtype);
1862
	COPY_STRING_FIELD(name);
1863
	COPY_NODE_FIELD(def);
T
Tom Lane 已提交
1864
	COPY_NODE_FIELD(transform);
1865
	COPY_SCALAR_FIELD(behavior);
1866 1867 1868 1869

	return newnode;
}

B
Bruce Momjian 已提交
1870
static AlterDomainStmt *
1871
_copyAlterDomainStmt(AlterDomainStmt *from)
B
Bruce Momjian 已提交
1872 1873 1874 1875 1876 1877 1878 1879 1880 1881
{
	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 已提交
1882
}
B
Bruce Momjian 已提交
1883

1884 1885
static GrantStmt *
_copyGrantStmt(GrantStmt *from)
1886
{
1887
	GrantStmt  *newnode = makeNode(GrantStmt);
B
Bruce Momjian 已提交
1888

1889 1890 1891
	COPY_SCALAR_FIELD(is_grant);
	COPY_SCALAR_FIELD(objtype);
	COPY_NODE_FIELD(objects);
1892
	COPY_NODE_FIELD(privileges);
1893
	COPY_NODE_FIELD(grantees);
1894 1895
	COPY_SCALAR_FIELD(grant_option);
	COPY_SCALAR_FIELD(behavior);
1896 1897 1898 1899 1900 1901 1902 1903 1904

	return newnode;
}

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

1905
	COPY_STRING_FIELD(rolname);
1906 1907 1908 1909

	return newnode;
}

1910 1911 1912 1913 1914
static FuncWithArgs *
_copyFuncWithArgs(FuncWithArgs *from)
{
	FuncWithArgs *newnode = makeNode(FuncWithArgs);

1915 1916
	COPY_NODE_FIELD(funcname);
	COPY_NODE_FIELD(funcargs);
1917 1918 1919 1920

	return newnode;
}

1921 1922 1923
static GrantRoleStmt *
_copyGrantRoleStmt(GrantRoleStmt *from)
{
B
Bruce Momjian 已提交
1924
	GrantRoleStmt *newnode = makeNode(GrantRoleStmt);
1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935

	COPY_NODE_FIELD(granted_roles);
	COPY_NODE_FIELD(grantee_roles);
	COPY_SCALAR_FIELD(is_grant);
	COPY_SCALAR_FIELD(admin_opt);
	COPY_STRING_FIELD(grantor);
	COPY_SCALAR_FIELD(behavior);

	return newnode;
}

1936
static DeclareCursorStmt *
1937
_copyDeclareCursorStmt(DeclareCursorStmt *from)
1938 1939 1940 1941 1942 1943 1944 1945 1946
{
	DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);

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

	return newnode;
}
B
Bruce Momjian 已提交
1947

1948 1949 1950
static ClosePortalStmt *
_copyClosePortalStmt(ClosePortalStmt *from)
{
1951
	ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1952

1953
	COPY_STRING_FIELD(portalname);
1954 1955 1956 1957

	return newnode;
}

1958 1959 1960 1961
static ClusterStmt *
_copyClusterStmt(ClusterStmt *from)
{
	ClusterStmt *newnode = makeNode(ClusterStmt);
B
Bruce Momjian 已提交
1962

1963 1964
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(indexname);
1965 1966 1967 1968 1969 1970 1971

	return newnode;
}

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

1974
	COPY_NODE_FIELD(relation);
1975
	COPY_NODE_FIELD(query);
1976 1977 1978 1979
	COPY_NODE_FIELD(attlist);
	COPY_SCALAR_FIELD(is_from);
	COPY_STRING_FIELD(filename);
	COPY_NODE_FIELD(options);
1980 1981 1982 1983 1984 1985 1986 1987

	return newnode;
}

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

1989 1990 1991 1992
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(tableElts);
	COPY_NODE_FIELD(inhRelations);
	COPY_NODE_FIELD(constraints);
B
Bruce Momjian 已提交
1993
	COPY_NODE_FIELD(options);
1994
	COPY_SCALAR_FIELD(oncommit);
1995
	COPY_STRING_FIELD(tablespacename);
1996 1997 1998 1999

	return newnode;
}

B
Bruce Momjian 已提交
2000
static InhRelation *
2001
_copyInhRelation(InhRelation *from)
B
Bruce Momjian 已提交
2002 2003 2004 2005
{
	InhRelation *newnode = makeNode(InhRelation);

	COPY_NODE_FIELD(relation);
2006
	COPY_NODE_FIELD(options);
B
Bruce Momjian 已提交
2007 2008 2009 2010

	return newnode;
}

2011 2012 2013 2014
static DefineStmt *
_copyDefineStmt(DefineStmt *from)
{
	DefineStmt *newnode = makeNode(DefineStmt);
B
Bruce Momjian 已提交
2015

2016
	COPY_SCALAR_FIELD(kind);
T
Tom Lane 已提交
2017
	COPY_SCALAR_FIELD(oldstyle);
2018
	COPY_NODE_FIELD(defnames);
T
Tom Lane 已提交
2019
	COPY_NODE_FIELD(args);
2020
	COPY_NODE_FIELD(definition);
2021 2022 2023 2024 2025 2026 2027

	return newnode;
}

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

2030 2031 2032
	COPY_NODE_FIELD(objects);
	COPY_SCALAR_FIELD(removeType);
	COPY_SCALAR_FIELD(behavior);
T
Tom Lane 已提交
2033
	COPY_SCALAR_FIELD(missing_ok);
2034 2035 2036 2037

	return newnode;
}

2038 2039 2040
static TruncateStmt *
_copyTruncateStmt(TruncateStmt *from)
{
2041
	TruncateStmt *newnode = makeNode(TruncateStmt);
2042

2043
	COPY_NODE_FIELD(relations);
2044
	COPY_SCALAR_FIELD(behavior);
2045 2046 2047 2048

	return newnode;
}

2049 2050 2051 2052
static CommentStmt *
_copyCommentStmt(CommentStmt *from)
{
	CommentStmt *newnode = makeNode(CommentStmt);
B
Bruce Momjian 已提交
2053

2054 2055 2056 2057
	COPY_SCALAR_FIELD(objtype);
	COPY_NODE_FIELD(objname);
	COPY_NODE_FIELD(objargs);
	COPY_STRING_FIELD(comment);
2058 2059 2060 2061 2062 2063 2064

	return newnode;
}

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

2067 2068 2069 2070
	COPY_SCALAR_FIELD(direction);
	COPY_SCALAR_FIELD(howMany);
	COPY_STRING_FIELD(portalname);
	COPY_SCALAR_FIELD(ismove);
2071 2072 2073 2074 2075 2076 2077

	return newnode;
}

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

2080 2081 2082
	COPY_STRING_FIELD(idxname);
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(accessMethod);
2083
	COPY_STRING_FIELD(tableSpace);
2084
	COPY_NODE_FIELD(indexParams);
B
Bruce Momjian 已提交
2085
	COPY_NODE_FIELD(options);
2086 2087 2088 2089 2090
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(rangetable);
	COPY_SCALAR_FIELD(unique);
	COPY_SCALAR_FIELD(primary);
	COPY_SCALAR_FIELD(isconstraint);
2091
	COPY_SCALAR_FIELD(concurrent);
2092 2093 2094 2095

	return newnode;
}

2096 2097
static CreateFunctionStmt *
_copyCreateFunctionStmt(CreateFunctionStmt *from)
2098
{
2099
	CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
B
Bruce Momjian 已提交
2100

2101 2102
	COPY_SCALAR_FIELD(replace);
	COPY_NODE_FIELD(funcname);
2103
	COPY_NODE_FIELD(parameters);
2104 2105 2106
	COPY_NODE_FIELD(returnType);
	COPY_NODE_FIELD(options);
	COPY_NODE_FIELD(withClause);
2107 2108 2109 2110

	return newnode;
}

2111 2112 2113 2114 2115 2116 2117
static FunctionParameter *
_copyFunctionParameter(FunctionParameter *from)
{
	FunctionParameter *newnode = makeNode(FunctionParameter);

	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(argType);
2118
	COPY_SCALAR_FIELD(mode);
2119 2120 2121 2122

	return newnode;
}

2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133
static AlterFunctionStmt *
_copyAlterFunctionStmt(AlterFunctionStmt *from)
{
	AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);

	COPY_NODE_FIELD(func);
	COPY_NODE_FIELD(actions);

	return newnode;
}

2134 2135 2136 2137
static RemoveFuncStmt *
_copyRemoveFuncStmt(RemoveFuncStmt *from)
{
	RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
B
Bruce Momjian 已提交
2138

T
Tom Lane 已提交
2139 2140
	COPY_SCALAR_FIELD(kind);
	COPY_NODE_FIELD(name);
2141 2142
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(behavior);
A
 
Andrew Dunstan 已提交
2143
	COPY_SCALAR_FIELD(missing_ok);
2144 2145 2146 2147

	return newnode;
}

2148 2149 2150 2151 2152
static RemoveOpClassStmt *
_copyRemoveOpClassStmt(RemoveOpClassStmt *from)
{
	RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);

2153 2154 2155
	COPY_NODE_FIELD(opclassname);
	COPY_STRING_FIELD(amname);
	COPY_SCALAR_FIELD(behavior);
A
 
Andrew Dunstan 已提交
2156
	COPY_SCALAR_FIELD(missing_ok);
2157 2158 2159 2160

	return newnode;
}

2161 2162 2163 2164
static RenameStmt *
_copyRenameStmt(RenameStmt *from)
{
	RenameStmt *newnode = makeNode(RenameStmt);
B
Bruce Momjian 已提交
2165

2166
	COPY_SCALAR_FIELD(renameType);
2167
	COPY_NODE_FIELD(relation);
2168 2169 2170
	COPY_NODE_FIELD(object);
	COPY_NODE_FIELD(objarg);
	COPY_STRING_FIELD(subname);
2171
	COPY_STRING_FIELD(newname);
2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186

	return newnode;
}

static AlterObjectSchemaStmt *
_copyAlterObjectSchemaStmt(AlterObjectSchemaStmt *from)
{
	AlterObjectSchemaStmt *newnode = makeNode(AlterObjectSchemaStmt);

	COPY_SCALAR_FIELD(objectType);
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(object);
	COPY_NODE_FIELD(objarg);
	COPY_STRING_FIELD(addname);
	COPY_STRING_FIELD(newschema);
2187 2188 2189 2190

	return newnode;
}

2191 2192 2193 2194 2195
static AlterOwnerStmt *
_copyAlterOwnerStmt(AlterOwnerStmt *from)
{
	AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);

2196
	COPY_SCALAR_FIELD(objectType);
2197 2198 2199 2200 2201 2202 2203 2204 2205
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(object);
	COPY_NODE_FIELD(objarg);
	COPY_STRING_FIELD(addname);
	COPY_STRING_FIELD(newowner);

	return newnode;
}

2206 2207 2208
static RuleStmt *
_copyRuleStmt(RuleStmt *from)
{
B
Bruce Momjian 已提交
2209 2210
	RuleStmt   *newnode = makeNode(RuleStmt);

2211 2212 2213 2214 2215 2216 2217
	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);
2218 2219 2220 2221

	return newnode;
}

2222 2223 2224
static NotifyStmt *
_copyNotifyStmt(NotifyStmt *from)
{
2225
	NotifyStmt *newnode = makeNode(NotifyStmt);
2226

2227
	COPY_NODE_FIELD(relation);
2228 2229 2230 2231 2232 2233 2234

	return newnode;
}

static ListenStmt *
_copyListenStmt(ListenStmt *from)
{
2235
	ListenStmt *newnode = makeNode(ListenStmt);
2236

2237
	COPY_NODE_FIELD(relation);
2238 2239 2240 2241 2242 2243 2244

	return newnode;
}

static UnlistenStmt *
_copyUnlistenStmt(UnlistenStmt *from)
{
2245
	UnlistenStmt *newnode = makeNode(UnlistenStmt);
2246

2247
	COPY_NODE_FIELD(relation);
2248 2249 2250 2251 2252 2253 2254

	return newnode;
}

static TransactionStmt *
_copyTransactionStmt(TransactionStmt *from)
{
2255
	TransactionStmt *newnode = makeNode(TransactionStmt);
2256

2257
	COPY_SCALAR_FIELD(kind);
2258
	COPY_NODE_FIELD(options);
2259
	COPY_STRING_FIELD(gid);
2260 2261 2262 2263

	return newnode;
}

B
Bruce Momjian 已提交
2264 2265 2266
static CompositeTypeStmt *
_copyCompositeTypeStmt(CompositeTypeStmt *from)
{
B
Bruce Momjian 已提交
2267
	CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
B
Bruce Momjian 已提交
2268

2269 2270
	COPY_NODE_FIELD(typevar);
	COPY_NODE_FIELD(coldeflist);
B
Bruce Momjian 已提交
2271 2272 2273 2274

	return newnode;
}

2275 2276 2277 2278 2279
static ViewStmt *
_copyViewStmt(ViewStmt *from)
{
	ViewStmt   *newnode = makeNode(ViewStmt);

2280 2281 2282 2283
	COPY_NODE_FIELD(view);
	COPY_NODE_FIELD(aliases);
	COPY_NODE_FIELD(query);
	COPY_SCALAR_FIELD(replace);
2284 2285 2286 2287

	return newnode;
}

2288 2289 2290
static LoadStmt *
_copyLoadStmt(LoadStmt *from)
{
2291
	LoadStmt   *newnode = makeNode(LoadStmt);
2292

2293
	COPY_STRING_FIELD(filename);
2294 2295 2296 2297

	return newnode;
}

2298 2299 2300 2301 2302
static CreateDomainStmt *
_copyCreateDomainStmt(CreateDomainStmt *from)
{
	CreateDomainStmt *newnode = makeNode(CreateDomainStmt);

2303 2304 2305
	COPY_NODE_FIELD(domainname);
	COPY_NODE_FIELD(typename);
	COPY_NODE_FIELD(constraints);
2306 2307 2308 2309

	return newnode;
}

2310 2311 2312 2313 2314
static CreateOpClassStmt *
_copyCreateOpClassStmt(CreateOpClassStmt *from)
{
	CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);

2315
	COPY_NODE_FIELD(opclassname);
2316
	COPY_NODE_FIELD(opfamilyname);
2317 2318 2319 2320
	COPY_STRING_FIELD(amname);
	COPY_NODE_FIELD(datatype);
	COPY_NODE_FIELD(items);
	COPY_SCALAR_FIELD(isDefault);
2321 2322 2323 2324 2325 2326 2327 2328 2329

	return newnode;
}

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

2330 2331 2332 2333 2334 2335
	COPY_SCALAR_FIELD(itemtype);
	COPY_NODE_FIELD(name);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(number);
	COPY_SCALAR_FIELD(recheck);
	COPY_NODE_FIELD(storedtype);
2336 2337 2338 2339

	return newnode;
}

2340 2341 2342
static CreatedbStmt *
_copyCreatedbStmt(CreatedbStmt *from)
{
B
Bruce Momjian 已提交
2343
	CreatedbStmt *newnode = makeNode(CreatedbStmt);
2344

2345 2346
	COPY_STRING_FIELD(dbname);
	COPY_NODE_FIELD(options);
2347 2348 2349 2350

	return newnode;
}

2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361
static AlterDatabaseStmt *
_copyAlterDatabaseStmt(AlterDatabaseStmt *from)
{
	AlterDatabaseStmt *newnode = makeNode(AlterDatabaseStmt);

	COPY_STRING_FIELD(dbname);
	COPY_NODE_FIELD(options);

	return newnode;
}

2362 2363 2364 2365 2366
static AlterDatabaseSetStmt *
_copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
{
	AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);

2367 2368 2369
	COPY_STRING_FIELD(dbname);
	COPY_STRING_FIELD(variable);
	COPY_NODE_FIELD(value);
2370 2371 2372 2373

	return newnode;
}

2374 2375 2376
static DropdbStmt *
_copyDropdbStmt(DropdbStmt *from)
{
B
Bruce Momjian 已提交
2377
	DropdbStmt *newnode = makeNode(DropdbStmt);
2378

2379
	COPY_STRING_FIELD(dbname);
A
 
Andrew Dunstan 已提交
2380
	COPY_SCALAR_FIELD(missing_ok);
2381 2382 2383 2384 2385 2386 2387

	return newnode;
}

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

2390 2391 2392 2393
	COPY_SCALAR_FIELD(vacuum);
	COPY_SCALAR_FIELD(full);
	COPY_SCALAR_FIELD(analyze);
	COPY_SCALAR_FIELD(verbose);
2394
	COPY_SCALAR_FIELD(freeze_min_age);
2395 2396
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(va_cols);
2397 2398 2399 2400 2401 2402 2403

	return newnode;
}

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

2406 2407 2408
	COPY_NODE_FIELD(query);
	COPY_SCALAR_FIELD(verbose);
	COPY_SCALAR_FIELD(analyze);
2409 2410 2411 2412 2413 2414 2415

	return newnode;
}

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

2418 2419
	COPY_NODE_FIELD(sequence);
	COPY_NODE_FIELD(options);
2420 2421 2422 2423

	return newnode;
}

B
Bruce Momjian 已提交
2424
static AlterSeqStmt *
2425
_copyAlterSeqStmt(AlterSeqStmt *from)
B
Bruce Momjian 已提交
2426 2427 2428 2429 2430 2431 2432 2433 2434
{
	AlterSeqStmt *newnode = makeNode(AlterSeqStmt);

	COPY_NODE_FIELD(sequence);
	COPY_NODE_FIELD(options);

	return newnode;
}

2435 2436 2437
static VariableSetStmt *
_copyVariableSetStmt(VariableSetStmt *from)
{
2438
	VariableSetStmt *newnode = makeNode(VariableSetStmt);
2439

2440 2441 2442
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(is_local);
2443 2444 2445 2446

	return newnode;
}

2447 2448 2449 2450 2451
static VariableShowStmt *
_copyVariableShowStmt(VariableShowStmt *from)
{
	VariableShowStmt *newnode = makeNode(VariableShowStmt);

2452
	COPY_STRING_FIELD(name);
2453 2454 2455 2456

	return newnode;
}

2457 2458 2459
static VariableResetStmt *
_copyVariableResetStmt(VariableResetStmt *from)
{
2460
	VariableResetStmt *newnode = makeNode(VariableResetStmt);
2461

2462
	COPY_STRING_FIELD(name);
2463 2464 2465 2466

	return newnode;
}

2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484
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);
A
 
Andrew Dunstan 已提交
2485
	COPY_SCALAR_FIELD(missing_ok);
2486 2487 2488 2489

	return newnode;
}

2490 2491 2492 2493 2494
static CreateTrigStmt *
_copyCreateTrigStmt(CreateTrigStmt *from)
{
	CreateTrigStmt *newnode = makeNode(CreateTrigStmt);

2495 2496 2497 2498 2499 2500
	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 已提交
2501
	strcpy(newnode->actions, from->actions);	/* in-line string field */
2502 2503 2504 2505
	COPY_SCALAR_FIELD(isconstraint);
	COPY_SCALAR_FIELD(deferrable);
	COPY_SCALAR_FIELD(initdeferred);
	COPY_NODE_FIELD(constrrel);
2506 2507 2508 2509

	return newnode;
}

2510 2511
static DropPropertyStmt *
_copyDropPropertyStmt(DropPropertyStmt *from)
2512
{
2513
	DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2514

2515 2516 2517 2518
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(property);
	COPY_SCALAR_FIELD(removeType);
	COPY_SCALAR_FIELD(behavior);
A
 
Andrew Dunstan 已提交
2519
	COPY_SCALAR_FIELD(missing_ok);
2520 2521 2522 2523 2524 2525 2526 2527 2528

	return newnode;
}

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

2529 2530 2531 2532
	COPY_STRING_FIELD(plname);
	COPY_NODE_FIELD(plhandler);
	COPY_NODE_FIELD(plvalidator);
	COPY_SCALAR_FIELD(pltrusted);
2533 2534 2535 2536 2537 2538 2539 2540 2541

	return newnode;
}

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

2542 2543
	COPY_STRING_FIELD(plname);
	COPY_SCALAR_FIELD(behavior);
A
 
Andrew Dunstan 已提交
2544
	COPY_SCALAR_FIELD(missing_ok);
2545 2546 2547 2548

	return newnode;
}

2549 2550
static CreateRoleStmt *
_copyCreateRoleStmt(CreateRoleStmt *from)
2551
{
2552
	CreateRoleStmt *newnode = makeNode(CreateRoleStmt);
2553

2554
	COPY_SCALAR_FIELD(stmt_type);
2555
	COPY_STRING_FIELD(role);
2556
	COPY_NODE_FIELD(options);
2557 2558 2559 2560

	return newnode;
}

2561 2562
static AlterRoleStmt *
_copyAlterRoleStmt(AlterRoleStmt *from)
2563
{
2564
	AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
2565

2566
	COPY_STRING_FIELD(role);
2567
	COPY_NODE_FIELD(options);
2568
	COPY_SCALAR_FIELD(action);
2569 2570 2571 2572

	return newnode;
}

2573 2574
static AlterRoleSetStmt *
_copyAlterRoleSetStmt(AlterRoleSetStmt *from)
2575
{
2576
	AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
2577

2578
	COPY_STRING_FIELD(role);
2579 2580
	COPY_STRING_FIELD(variable);
	COPY_NODE_FIELD(value);
2581 2582 2583 2584

	return newnode;
}

2585 2586
static DropRoleStmt *
_copyDropRoleStmt(DropRoleStmt *from)
2587
{
2588
	DropRoleStmt *newnode = makeNode(DropRoleStmt);
2589

2590
	COPY_NODE_FIELD(roles);
A
 
Andrew Dunstan 已提交
2591
	COPY_SCALAR_FIELD(missing_ok);
2592 2593 2594 2595

	return newnode;
}

2596 2597 2598
static LockStmt *
_copyLockStmt(LockStmt *from)
{
2599
	LockStmt   *newnode = makeNode(LockStmt);
2600

2601 2602
	COPY_NODE_FIELD(relations);
	COPY_SCALAR_FIELD(mode);
T
Tatsuo Ishii 已提交
2603
	COPY_SCALAR_FIELD(nowait);
2604 2605 2606

	return newnode;
}
2607

2608 2609 2610
static ConstraintsSetStmt *
_copyConstraintsSetStmt(ConstraintsSetStmt *from)
{
B
Bruce Momjian 已提交
2611
	ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2612

2613 2614
	COPY_NODE_FIELD(constraints);
	COPY_SCALAR_FIELD(deferred);
2615 2616 2617 2618 2619 2620 2621

	return newnode;
}

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

2624
	COPY_SCALAR_FIELD(kind);
2625 2626
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(name);
2627 2628
	COPY_SCALAR_FIELD(do_system);
	COPY_SCALAR_FIELD(do_user);
2629 2630 2631 2632

	return newnode;
}

2633 2634 2635 2636 2637
static CreateSchemaStmt *
_copyCreateSchemaStmt(CreateSchemaStmt *from)
{
	CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);

2638 2639 2640
	COPY_STRING_FIELD(schemaname);
	COPY_STRING_FIELD(authid);
	COPY_NODE_FIELD(schemaElts);
2641 2642 2643 2644

	return newnode;
}

2645 2646 2647 2648 2649
static CreateConversionStmt *
_copyCreateConversionStmt(CreateConversionStmt *from)
{
	CreateConversionStmt *newnode = makeNode(CreateConversionStmt);

2650 2651 2652 2653 2654
	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);
2655 2656 2657 2658 2659 2660 2661 2662 2663

	return newnode;
}

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

2664 2665 2666 2667
	COPY_NODE_FIELD(sourcetype);
	COPY_NODE_FIELD(targettype);
	COPY_NODE_FIELD(func);
	COPY_SCALAR_FIELD(context);
2668 2669 2670 2671 2672 2673 2674 2675 2676

	return newnode;
}

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

2677 2678 2679
	COPY_NODE_FIELD(sourcetype);
	COPY_NODE_FIELD(targettype);
	COPY_SCALAR_FIELD(behavior);
A
 
Andrew Dunstan 已提交
2680
	COPY_SCALAR_FIELD(missing_ok);
2681 2682 2683 2684

	return newnode;
}

2685 2686 2687 2688 2689
static PrepareStmt *
_copyPrepareStmt(PrepareStmt *from)
{
	PrepareStmt *newnode = makeNode(PrepareStmt);

2690 2691
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(argtypes);
2692
	COPY_NODE_FIELD(argtype_oids);
2693
	COPY_NODE_FIELD(query);
2694 2695 2696 2697 2698 2699 2700 2701 2702

	return newnode;
}

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

2703 2704
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(into);
B
Bruce Momjian 已提交
2705
	COPY_NODE_FIELD(intoOptions);
2706 2707
	COPY_SCALAR_FIELD(into_on_commit);
	COPY_STRING_FIELD(into_tbl_space);
2708
	COPY_NODE_FIELD(params);
2709 2710 2711 2712 2713 2714 2715 2716 2717

	return newnode;
}

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

2718
	COPY_STRING_FIELD(name);
2719 2720 2721 2722

	return newnode;
}

2723
static DropOwnedStmt *
B
Bruce Momjian 已提交
2724
_copyDropOwnedStmt(DropOwnedStmt *from)
2725 2726 2727 2728 2729
{
	DropOwnedStmt *newnode = makeNode(DropOwnedStmt);

	COPY_NODE_FIELD(roles);
	COPY_SCALAR_FIELD(behavior);
2730

2731 2732 2733 2734
	return newnode;
}

static ReassignOwnedStmt *
B
Bruce Momjian 已提交
2735
_copyReassignOwnedStmt(ReassignOwnedStmt *from)
2736 2737 2738 2739 2740 2741 2742 2743
{
	ReassignOwnedStmt *newnode = makeNode(ReassignOwnedStmt);

	COPY_NODE_FIELD(roles);
	COPY_SCALAR_FIELD(newrole);

	return newnode;
}
2744 2745

/* ****************************************************************
2746
 *					pg_list.h copy functions
2747 2748 2749
 * ****************************************************************
 */

2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761
/*
 * 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 已提交
2762 2763 2764
	List	   *new;
	ListCell   *curr_old;
	ListCell   *prev_new;
2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790

	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
 * ****************************************************************
 */
2791
static Value *
2792
_copyValue(Value *from)
2793
{
2794
	Value	   *newnode = makeNode(Value);
2795

2796 2797
	/* See also _copyAConst when changing this code! */

2798
	COPY_SCALAR_FIELD(type);
2799 2800
	switch (from->type)
	{
2801
		case T_Integer:
2802
			COPY_SCALAR_FIELD(val.ival);
2803 2804
			break;
		case T_Float:
2805
		case T_String:
2806
		case T_BitString:
2807
			COPY_STRING_FIELD(val.str);
2808
			break;
2809 2810 2811
		case T_Null:
			/* nothing to do */
			break;
2812
		default:
2813 2814
			elog(ERROR, "unrecognized node type: %d",
				 (int) from->type);
2815
			break;
2816 2817
	}
	return newnode;
2818 2819
}

2820 2821 2822 2823 2824
/*
 * copyObject
 *
 * Create a copy of a Node tree or list.  This is a "deep" copy: all
 * substructure is copied too, recursively.
2825
 */
2826
void *
2827 2828
copyObject(void *from)
{
2829
	void	   *retval;
2830

2831 2832
	if (from == NULL)
		return NULL;
2833

2834
	switch (nodeTag(from))
2835
	{
2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847
			/*
			 * PLAN NODES
			 */
		case T_Plan:
			retval = _copyPlan(from);
			break;
		case T_Result:
			retval = _copyResult(from);
			break;
		case T_Append:
			retval = _copyAppend(from);
			break;
2848 2849 2850 2851 2852 2853
		case T_BitmapAnd:
			retval = _copyBitmapAnd(from);
			break;
		case T_BitmapOr:
			retval = _copyBitmapOr(from);
			break;
2854 2855 2856 2857 2858 2859 2860 2861 2862
		case T_Scan:
			retval = _copyScan(from);
			break;
		case T_SeqScan:
			retval = _copySeqScan(from);
			break;
		case T_IndexScan:
			retval = _copyIndexScan(from);
			break;
2863 2864 2865 2866 2867 2868
		case T_BitmapIndexScan:
			retval = _copyBitmapIndexScan(from);
			break;
		case T_BitmapHeapScan:
			retval = _copyBitmapHeapScan(from);
			break;
2869 2870 2871
		case T_TidScan:
			retval = _copyTidScan(from);
			break;
2872 2873 2874
		case T_SubqueryScan:
			retval = _copySubqueryScan(from);
			break;
2875 2876 2877
		case T_FunctionScan:
			retval = _copyFunctionScan(from);
			break;
2878 2879 2880
		case T_ValuesScan:
			retval = _copyValuesScan(from);
			break;
2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898
		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 已提交
2899 2900 2901
		case T_Group:
			retval = _copyGroup(from);
			break;
2902 2903 2904 2905 2906 2907
		case T_Agg:
			retval = _copyAgg(from);
			break;
		case T_Unique:
			retval = _copyUnique(from);
			break;
2908 2909 2910
		case T_Hash:
			retval = _copyHash(from);
			break;
2911 2912 2913
		case T_SetOp:
			retval = _copySetOp(from);
			break;
2914 2915 2916
		case T_Limit:
			retval = _copyLimit(from);
			break;
2917 2918 2919 2920

			/*
			 * PRIMITIVE NODES
			 */
2921 2922 2923 2924 2925 2926
		case T_Alias:
			retval = _copyAlias(from);
			break;
		case T_RangeVar:
			retval = _copyRangeVar(from);
			break;
2927 2928 2929 2930 2931 2932 2933 2934 2935
		case T_Var:
			retval = _copyVar(from);
			break;
		case T_Const:
			retval = _copyConst(from);
			break;
		case T_Param:
			retval = _copyParam(from);
			break;
2936 2937 2938
		case T_Aggref:
			retval = _copyAggref(from);
			break;
2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950
		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;
2951 2952 2953
		case T_ScalarArrayOpExpr:
			retval = _copyScalarArrayOpExpr(from);
			break;
2954 2955 2956
		case T_BoolExpr:
			retval = _copyBoolExpr(from);
			break;
2957 2958 2959
		case T_SubLink:
			retval = _copySubLink(from);
			break;
2960 2961
		case T_SubPlan:
			retval = _copySubPlan(from);
2962
			break;
2963 2964 2965
		case T_FieldSelect:
			retval = _copyFieldSelect(from);
			break;
2966 2967 2968
		case T_FieldStore:
			retval = _copyFieldStore(from);
			break;
2969 2970 2971
		case T_RelabelType:
			retval = _copyRelabelType(from);
			break;
2972 2973 2974
		case T_ConvertRowtypeExpr:
			retval = _copyConvertRowtypeExpr(from);
			break;
2975 2976 2977 2978 2979 2980
		case T_CaseExpr:
			retval = _copyCaseExpr(from);
			break;
		case T_CaseWhen:
			retval = _copyCaseWhen(from);
			break;
2981 2982 2983
		case T_CaseTestExpr:
			retval = _copyCaseTestExpr(from);
			break;
2984 2985 2986
		case T_ArrayExpr:
			retval = _copyArrayExpr(from);
			break;
2987 2988 2989
		case T_RowExpr:
			retval = _copyRowExpr(from);
			break;
2990 2991 2992
		case T_RowCompareExpr:
			retval = _copyRowCompareExpr(from);
			break;
2993 2994 2995
		case T_CoalesceExpr:
			retval = _copyCoalesceExpr(from);
			break;
2996 2997 2998
		case T_MinMaxExpr:
			retval = _copyMinMaxExpr(from);
			break;
2999 3000 3001
		case T_XmlExpr:
			retval = _copyXmlExpr(from);
			break;
3002 3003 3004
		case T_NullIfExpr:
			retval = _copyNullIfExpr(from);
			break;
3005 3006 3007 3008 3009 3010
		case T_NullTest:
			retval = _copyNullTest(from);
			break;
		case T_BooleanTest:
			retval = _copyBooleanTest(from);
			break;
3011 3012
		case T_CoerceToDomain:
			retval = _copyCoerceToDomain(from);
3013
			break;
3014 3015
		case T_CoerceToDomainValue:
			retval = _copyCoerceToDomainValue(from);
3016
			break;
3017 3018 3019
		case T_SetToDefault:
			retval = _copySetToDefault(from);
			break;
3020 3021 3022
		case T_TargetEntry:
			retval = _copyTargetEntry(from);
			break;
3023 3024 3025
		case T_RangeTblRef:
			retval = _copyRangeTblRef(from);
			break;
3026 3027 3028
		case T_JoinExpr:
			retval = _copyJoinExpr(from);
			break;
3029 3030 3031
		case T_FromExpr:
			retval = _copyFromExpr(from);
			break;
3032 3033 3034 3035

			/*
			 * RELATION NODES
			 */
3036 3037
		case T_PathKeyItem:
			retval = _copyPathKeyItem(from);
3038
			break;
3039 3040
		case T_RestrictInfo:
			retval = _copyRestrictInfo(from);
3041
			break;
3042 3043 3044
		case T_OuterJoinInfo:
			retval = _copyOuterJoinInfo(from);
			break;
3045 3046 3047
		case T_InClauseInfo:
			retval = _copyInClauseInfo(from);
			break;
3048 3049 3050
		case T_AppendRelInfo:
			retval = _copyAppendRelInfo(from);
			break;
3051 3052

			/*
3053
			 * VALUE NODES
3054
			 */
3055 3056 3057
		case T_Integer:
		case T_Float:
		case T_String:
3058
		case T_BitString:
3059
		case T_Null:
3060
			retval = _copyValue(from);
3061
			break;
3062 3063 3064 3065

			/*
			 * LIST NODES
			 */
3066
		case T_List:
3067 3068
			retval = _copyList(from);
			break;
B
Bruce Momjian 已提交
3069

3070
			/*
B
Bruce Momjian 已提交
3071 3072
			 * Lists of integers and OIDs don't need to be deep-copied, so we
			 * perform a shallow copy via list_copy()
3073 3074 3075 3076
			 */
		case T_IntList:
		case T_OidList:
			retval = list_copy(from);
3077
			break;
3078 3079 3080 3081

			/*
			 * PARSE NODES
			 */
3082 3083 3084
		case T_Query:
			retval = _copyQuery(from);
			break;
3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096
		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;
3097 3098 3099
		case T_SetOperationStmt:
			retval = _copySetOperationStmt(from);
			break;
3100 3101 3102
		case T_AlterTableStmt:
			retval = _copyAlterTableStmt(from);
			break;
T
Tom Lane 已提交
3103 3104 3105
		case T_AlterTableCmd:
			retval = _copyAlterTableCmd(from);
			break;
B
Bruce Momjian 已提交
3106 3107 3108
		case T_AlterDomainStmt:
			retval = _copyAlterDomainStmt(from);
			break;
3109 3110
		case T_GrantStmt:
			retval = _copyGrantStmt(from);
3111
			break;
3112 3113 3114
		case T_GrantRoleStmt:
			retval = _copyGrantRoleStmt(from);
			break;
3115 3116 3117
		case T_DeclareCursorStmt:
			retval = _copyDeclareCursorStmt(from);
			break;
3118 3119 3120
		case T_ClosePortalStmt:
			retval = _copyClosePortalStmt(from);
			break;
3121 3122 3123 3124 3125 3126 3127 3128 3129
		case T_ClusterStmt:
			retval = _copyClusterStmt(from);
			break;
		case T_CopyStmt:
			retval = _copyCopyStmt(from);
			break;
		case T_CreateStmt:
			retval = _copyCreateStmt(from);
			break;
B
Bruce Momjian 已提交
3130 3131 3132
		case T_InhRelation:
			retval = _copyInhRelation(from);
			break;
3133 3134 3135 3136 3137 3138
		case T_DefineStmt:
			retval = _copyDefineStmt(from);
			break;
		case T_DropStmt:
			retval = _copyDropStmt(from);
			break;
3139 3140 3141
		case T_TruncateStmt:
			retval = _copyTruncateStmt(from);
			break;
3142 3143 3144 3145 3146 3147 3148 3149 3150
		case T_CommentStmt:
			retval = _copyCommentStmt(from);
			break;
		case T_FetchStmt:
			retval = _copyFetchStmt(from);
			break;
		case T_IndexStmt:
			retval = _copyIndexStmt(from);
			break;
3151 3152
		case T_CreateFunctionStmt:
			retval = _copyCreateFunctionStmt(from);
3153
			break;
3154 3155 3156
		case T_FunctionParameter:
			retval = _copyFunctionParameter(from);
			break;
3157 3158 3159
		case T_AlterFunctionStmt:
			retval = _copyAlterFunctionStmt(from);
			break;
3160 3161 3162
		case T_RemoveFuncStmt:
			retval = _copyRemoveFuncStmt(from);
			break;
3163 3164 3165
		case T_RemoveOpClassStmt:
			retval = _copyRemoveOpClassStmt(from);
			break;
3166 3167 3168
		case T_RenameStmt:
			retval = _copyRenameStmt(from);
			break;
3169 3170 3171
		case T_AlterObjectSchemaStmt:
			retval = _copyAlterObjectSchemaStmt(from);
			break;
3172 3173 3174
		case T_AlterOwnerStmt:
			retval = _copyAlterOwnerStmt(from);
			break;
3175 3176 3177
		case T_RuleStmt:
			retval = _copyRuleStmt(from);
			break;
3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189
		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 已提交
3190 3191 3192
		case T_CompositeTypeStmt:
			retval = _copyCompositeTypeStmt(from);
			break;
3193 3194 3195
		case T_ViewStmt:
			retval = _copyViewStmt(from);
			break;
3196 3197 3198
		case T_LoadStmt:
			retval = _copyLoadStmt(from);
			break;
3199 3200 3201
		case T_CreateDomainStmt:
			retval = _copyCreateDomainStmt(from);
			break;
3202 3203 3204 3205 3206 3207
		case T_CreateOpClassStmt:
			retval = _copyCreateOpClassStmt(from);
			break;
		case T_CreateOpClassItem:
			retval = _copyCreateOpClassItem(from);
			break;
3208 3209 3210
		case T_CreatedbStmt:
			retval = _copyCreatedbStmt(from);
			break;
3211 3212 3213
		case T_AlterDatabaseStmt:
			retval = _copyAlterDatabaseStmt(from);
			break;
3214 3215 3216
		case T_AlterDatabaseSetStmt:
			retval = _copyAlterDatabaseSetStmt(from);
			break;
3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228
		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 已提交
3229 3230 3231
		case T_AlterSeqStmt:
			retval = _copyAlterSeqStmt(from);
			break;
3232 3233 3234
		case T_VariableSetStmt:
			retval = _copyVariableSetStmt(from);
			break;
3235 3236 3237
		case T_VariableShowStmt:
			retval = _copyVariableShowStmt(from);
			break;
3238 3239 3240
		case T_VariableResetStmt:
			retval = _copyVariableResetStmt(from);
			break;
3241 3242 3243 3244 3245 3246
		case T_CreateTableSpaceStmt:
			retval = _copyCreateTableSpaceStmt(from);
			break;
		case T_DropTableSpaceStmt:
			retval = _copyDropTableSpaceStmt(from);
			break;
3247 3248 3249
		case T_CreateTrigStmt:
			retval = _copyCreateTrigStmt(from);
			break;
3250 3251
		case T_DropPropertyStmt:
			retval = _copyDropPropertyStmt(from);
3252 3253 3254 3255 3256 3257 3258
			break;
		case T_CreatePLangStmt:
			retval = _copyCreatePLangStmt(from);
			break;
		case T_DropPLangStmt:
			retval = _copyDropPLangStmt(from);
			break;
3259 3260
		case T_CreateRoleStmt:
			retval = _copyCreateRoleStmt(from);
3261
			break;
3262 3263
		case T_AlterRoleStmt:
			retval = _copyAlterRoleStmt(from);
3264
			break;
3265 3266
		case T_AlterRoleSetStmt:
			retval = _copyAlterRoleSetStmt(from);
3267
			break;
3268 3269
		case T_DropRoleStmt:
			retval = _copyDropRoleStmt(from);
3270
			break;
3271 3272 3273
		case T_LockStmt:
			retval = _copyLockStmt(from);
			break;
3274 3275 3276 3277 3278 3279
		case T_ConstraintsSetStmt:
			retval = _copyConstraintsSetStmt(from);
			break;
		case T_ReindexStmt:
			retval = _copyReindexStmt(from);
			break;
V
Vadim B. Mikheev 已提交
3280
		case T_CheckPointStmt:
B
Bruce Momjian 已提交
3281
			retval = (void *) makeNode(CheckPointStmt);
V
Vadim B. Mikheev 已提交
3282
			break;
3283 3284 3285
		case T_CreateSchemaStmt:
			retval = _copyCreateSchemaStmt(from);
			break;
3286 3287 3288 3289 3290 3291 3292 3293 3294
		case T_CreateConversionStmt:
			retval = _copyCreateConversionStmt(from);
			break;
		case T_CreateCastStmt:
			retval = _copyCreateCastStmt(from);
			break;
		case T_DropCastStmt:
			retval = _copyDropCastStmt(from);
			break;
3295 3296 3297 3298 3299 3300 3301 3302 3303
		case T_PrepareStmt:
			retval = _copyPrepareStmt(from);
			break;
		case T_ExecuteStmt:
			retval = _copyExecuteStmt(from);
			break;
		case T_DeallocateStmt:
			retval = _copyDeallocateStmt(from);
			break;
3304 3305 3306 3307 3308 3309
		case T_DropOwnedStmt:
			retval = _copyDropOwnedStmt(from);
			break;
		case T_ReassignOwnedStmt:
			retval = _copyReassignOwnedStmt(from);
			break;
3310

3311 3312 3313
		case T_A_Expr:
			retval = _copyAExpr(from);
			break;
3314 3315 3316 3317 3318
		case T_ColumnRef:
			retval = _copyColumnRef(from);
			break;
		case T_ParamRef:
			retval = _copyParamRef(from);
3319
			break;
3320 3321 3322
		case T_A_Const:
			retval = _copyAConst(from);
			break;
3323 3324 3325 3326 3327 3328
		case T_FuncCall:
			retval = _copyFuncCall(from);
			break;
		case T_A_Indices:
			retval = _copyAIndices(from);
			break;
3329 3330
		case T_A_Indirection:
			retval = _copyA_Indirection(from);
3331
			break;
3332 3333 3334
		case T_ResTarget:
			retval = _copyResTarget(from);
			break;
3335 3336 3337
		case T_TypeCast:
			retval = _copyTypeCast(from);
			break;
3338 3339
		case T_SortBy:
			retval = _copySortBy(from);
3340
			break;
3341 3342 3343
		case T_RangeSubselect:
			retval = _copyRangeSubselect(from);
			break;
3344 3345 3346
		case T_RangeFunction:
			retval = _copyRangeFunction(from);
			break;
3347 3348 3349
		case T_TypeName:
			retval = _copyTypeName(from);
			break;
3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361
		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;
3362 3363 3364
		case T_LockingClause:
			retval = _copyLockingClause(from);
			break;
3365 3366
		case T_RangeTblEntry:
			retval = _copyRangeTblEntry(from);
3367
			break;
3368 3369 3370 3371 3372 3373
		case T_SortClause:
			retval = _copySortClause(from);
			break;
		case T_GroupClause:
			retval = _copyGroupClause(from);
			break;
3374 3375 3376
		case T_RowMarkClause:
			retval = _copyRowMarkClause(from);
			break;
3377 3378 3379
		case T_FkConstraint:
			retval = _copyFkConstraint(from);
			break;
3380 3381 3382
		case T_PrivGrantee:
			retval = _copyPrivGrantee(from);
			break;
3383 3384 3385
		case T_FuncWithArgs:
			retval = _copyFuncWithArgs(from);
			break;
3386

3387
		default:
3388
			elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
3389
			retval = from;		/* keep compiler quiet */
3390
			break;
3391
	}
3392

3393
	return retval;
3394
}