copyfuncs.c 63.1 KB
Newer Older
1
/*-------------------------------------------------------------------------
2
 *
3
 * copyfuncs.c
4
 *	  Copy functions for Postgres tree nodes.
5
 *
6 7 8
 * NOTE: a general convention when copying or comparing plan nodes is
 * that we ignore the executor state subnode.  We do not need to look
 * at it because no current uses of copyObject() or equal() need to
B
Bruce Momjian 已提交
9
 * deal with already-executing plan trees.	By leaving the state subnodes
10 11 12 13
 * out, we avoid needing to write copy/compare routines for all the
 * different executor state node types.
 *
 *
B
Bruce Momjian 已提交
14
 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
B
Add:  
Bruce Momjian 已提交
15
 * Portions Copyright (c) 1994, Regents of the University of California
16 17
 *
 * IDENTIFICATION
18
 *	  $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.197 2002/07/24 19:11:10 petere Exp $
19 20 21 22 23 24
 *
 *-------------------------------------------------------------------------
 */

#include "postgres.h"

25
#include "optimizer/clauses.h"
26
#include "optimizer/planmain.h"
27 28 29 30 31 32 33 34 35


/*
 * Node_Copy
 *	  a macro to simplify calling of copyObject on the specified field
 */
#define Node_Copy(from, newnode, field) \
	((newnode)->field = copyObject((from)->field))

36 37

/*
38
 * listCopy
39 40 41 42 43 44 45 46 47
 *	  This copy function only copies the "cons-cells" of the list, not the
 *	  pointed-to objects.  (Use copyObject if you want a "deep" copy.)
 *
 *	  We also use this function for copying lists of integers, which is
 *	  grotty but unlikely to break --- it could fail if sizeof(pointer)
 *	  is less than sizeof(int), but I don't know any such machines...
 *
 *	  Note that copyObject will surely coredump if applied to a list
 *	  of integers!
48
 */
49
List *
50
listCopy(List *list)
51
{
52 53 54 55 56 57 58
	List	   *newlist,
			   *l,
			   *nl;

	/* rather ugly coding for speed... */
	if (list == NIL)
		return NIL;
59

60
	newlist = nl = makeList1(lfirst(list));
61 62

	foreach(l, lnext(list))
63
	{
64
		lnext(nl) = makeList1(lfirst(l));
65
		nl = lnext(nl);
66
	}
67
	return newlist;
68
}
69

70
/* ****************************************************************
71
 *					 plannodes.h copy functions
72 73 74 75
 * ****************************************************************
 */

/* ----------------
76
 *		CopyPlanFields
77
 *
78 79
 *		This function copies the fields of the Plan node.  It is used by
 *		all the copy functions for classes which inherit from Plan.
80 81 82
 * ----------------
 */
static void
83
CopyPlanFields(Plan *from, Plan *newnode)
84
{
85 86
	newnode->startup_cost = from->startup_cost;
	newnode->total_cost = from->total_cost;
87
	newnode->plan_rows = from->plan_rows;
88
	newnode->plan_width = from->plan_width;
89
	/* state is NOT copied */
90 91 92 93
	Node_Copy(from, newnode, targetlist);
	Node_Copy(from, newnode, qual);
	Node_Copy(from, newnode, lefttree);
	Node_Copy(from, newnode, righttree);
94 95 96
	newnode->extParam = listCopy(from->extParam);
	newnode->locParam = listCopy(from->locParam);
	newnode->chgParam = listCopy(from->chgParam);
V
Vadim B. Mikheev 已提交
97
	Node_Copy(from, newnode, initPlan);
98
	/* subPlan list must point to subplans in the new subtree, not the old */
99
	if (from->subPlan != NIL)
100 101
		newnode->subPlan = nconc(pull_subplans((Node *) newnode->targetlist),
								 pull_subplans((Node *) newnode->qual));
V
Vadim B. Mikheev 已提交
102
	else
103
		newnode->subPlan = NIL;
V
Vadim B. Mikheev 已提交
104
	newnode->nParamExec = from->nParamExec;
105 106 107
}

/* ----------------
108
 *		_copyPlan
109 110
 * ----------------
 */
111
static Plan *
112
_copyPlan(Plan *from)
113
{
114
	Plan	   *newnode = makeNode(Plan);
115

116 117
	/*
	 * copy the node superclass fields
118 119 120 121
	 */
	CopyPlanFields(from, newnode);

	return newnode;
122 123 124 125
}


/* ----------------
126
 *		_copyResult
127 128
 * ----------------
 */
129
static Result *
130
_copyResult(Result *from)
131
{
132
	Result	   *newnode = makeNode(Result);
133

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

139 140
	/*
	 * copy remainder of node
141 142 143
	 */
	Node_Copy(from, newnode, resconstantqual);

B
Bruce Momjian 已提交
144 145 146
	/*
	 * We must add subplans in resconstantqual to the new plan's subPlan
	 * list
147
	 */
148 149
	if (from->plan.subPlan != NIL)
		newnode->plan.subPlan = nconc(newnode->plan.subPlan,
150
								pull_subplans(newnode->resconstantqual));
151

152
	return newnode;
153 154 155
}

/* ----------------
156
 *		_copyAppend
157 158
 * ----------------
 */
159
static Append *
B
Bruce Momjian 已提交
160
_copyAppend(Append *from)
161
{
162
	Append	   *newnode = makeNode(Append);
163

164 165
	/*
	 * copy node superclass fields
166 167 168
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

169 170
	/*
	 * copy remainder of node
171
	 */
172
	Node_Copy(from, newnode, appendplans);
173
	newnode->isTarget = from->isTarget;
174 175

	return newnode;
176 177 178 179
}


/* ----------------
180
 *		CopyScanFields
181
 *
182 183
 *		This function copies the fields of the Scan node.  It is used by
 *		all the copy functions for classes which inherit from Scan.
184 185 186
 * ----------------
 */
static void
187
CopyScanFields(Scan *from, Scan *newnode)
188
{
189 190
	newnode->scanrelid = from->scanrelid;
	return;
191 192 193
}

/* ----------------
194
 *		_copyScan
195 196
 * ----------------
 */
197
static Scan *
198
_copyScan(Scan *from)
199
{
200
	Scan	   *newnode = makeNode(Scan);
201

202 203
	/*
	 * copy node superclass fields
204 205
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
B
Bruce Momjian 已提交
206
	CopyScanFields((Scan *) from, (Scan *) newnode);
207 208

	return newnode;
209 210 211
}

/* ----------------
212
 *		_copySeqScan
213 214 215
 * ----------------
 */
static SeqScan *
216
_copySeqScan(SeqScan *from)
217
{
218
	SeqScan    *newnode = makeNode(SeqScan);
219

220 221
	/*
	 * copy node superclass fields
222 223 224 225 226
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
	CopyScanFields((Scan *) from, (Scan *) newnode);

	return newnode;
227 228 229
}

/* ----------------
230
 *		_copyIndexScan
231 232 233
 * ----------------
 */
static IndexScan *
234
_copyIndexScan(IndexScan *from)
235
{
236
	IndexScan  *newnode = makeNode(IndexScan);
237

238 239
	/*
	 * copy node superclass fields
240 241 242 243
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
	CopyScanFields((Scan *) from, (Scan *) newnode);

244 245
	/*
	 * copy remainder of node
246 247 248
	 */
	newnode->indxid = listCopy(from->indxid);
	Node_Copy(from, newnode, indxqual);
V
Vadim B. Mikheev 已提交
249
	Node_Copy(from, newnode, indxqualorig);
250
	newnode->indxorderdir = from->indxorderdir;
251

252 253 254 255 256 257
	/*
	 * We must add subplans in index quals to the new plan's subPlan list
	 */
	if (from->scan.plan.subPlan != NIL)
	{
		newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
258
							  pull_subplans((Node *) newnode->indxqual));
259
		newnode->scan.plan.subPlan = nconc(newnode->scan.plan.subPlan,
260
						  pull_subplans((Node *) newnode->indxqualorig));
261 262
	}

263
	return newnode;
264 265
}

266
/* ----------------
267
 *				_copyTidScan
268 269 270 271 272
 * ----------------
 */
static TidScan *
_copyTidScan(TidScan *from)
{
273
	TidScan    *newnode = makeNode(TidScan);
274

275 276
	/*
	 * copy node superclass fields
277 278 279
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
	CopyScanFields((Scan *) from, (Scan *) newnode);
280 281 282

	/*
	 * copy remainder of node
283 284 285 286 287 288 289
	 */
	newnode->needRescan = from->needRescan;
	Node_Copy(from, newnode, tideval);

	return newnode;
}

290 291 292 293 294 295 296
/* ----------------
 *		_copySubqueryScan
 * ----------------
 */
static SubqueryScan *
_copySubqueryScan(SubqueryScan *from)
{
B
Bruce Momjian 已提交
297
	SubqueryScan *newnode = makeNode(SubqueryScan);
298

299 300
	/*
	 * copy node superclass fields
301 302 303 304
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
	CopyScanFields((Scan *) from, (Scan *) newnode);

305 306
	/*
	 * copy remainder of node
307 308 309 310 311 312
	 */
	Node_Copy(from, newnode, subplan);

	return newnode;
}

313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
/* ----------------
 *		_copyFunctionScan
 * ----------------
 */
static FunctionScan *
_copyFunctionScan(FunctionScan *from)
{
	FunctionScan *newnode = makeNode(FunctionScan);

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

	return newnode;
}
330

331
/* ----------------
332
 *		CopyJoinFields
333
 *
334 335
 *		This function copies the fields of the Join node.  It is used by
 *		all the copy functions for classes which inherit from Join.
336 337 338
 * ----------------
 */
static void
339
CopyJoinFields(Join *from, Join *newnode)
340
{
341 342 343 344 345
	newnode->jointype = from->jointype;
	Node_Copy(from, newnode, joinqual);
	/* subPlan list must point to subplans in the new subtree, not the old */
	if (from->plan.subPlan != NIL)
		newnode->plan.subPlan = nconc(newnode->plan.subPlan,
B
Bruce Momjian 已提交
346
							  pull_subplans((Node *) newnode->joinqual));
347 348 349 350
}


/* ----------------
351
 *		_copyJoin
352 353
 * ----------------
 */
354
static Join *
355
_copyJoin(Join *from)
356
{
357
	Join	   *newnode = makeNode(Join);
358

359 360
	/*
	 * copy node superclass fields
361 362 363 364 365
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
	CopyJoinFields(from, newnode);

	return newnode;
366 367 368 369
}


/* ----------------
370
 *		_copyNestLoop
371 372 373
 * ----------------
 */
static NestLoop *
374
_copyNestLoop(NestLoop *from)
375
{
376
	NestLoop   *newnode = makeNode(NestLoop);
377

378 379
	/*
	 * copy node superclass fields
380 381 382 383 384
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
	CopyJoinFields((Join *) from, (Join *) newnode);

	return newnode;
385 386 387 388
}


/* ----------------
389
 *		_copyMergeJoin
390 391 392
 * ----------------
 */
static MergeJoin *
393
_copyMergeJoin(MergeJoin *from)
394
{
395
	MergeJoin  *newnode = makeNode(MergeJoin);
396

397 398
	/*
	 * copy node superclass fields
399 400 401 402
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
	CopyJoinFields((Join *) from, (Join *) newnode);

403 404
	/*
	 * copy remainder of node
405 406 407
	 */
	Node_Copy(from, newnode, mergeclauses);

408 409 410
	/*
	 * We must add subplans in mergeclauses to the new plan's subPlan list
	 */
411 412
	if (from->join.plan.subPlan != NIL)
		newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
413
						  pull_subplans((Node *) newnode->mergeclauses));
414

415
	return newnode;
416 417 418
}

/* ----------------
419
 *		_copyHashJoin
420 421 422
 * ----------------
 */
static HashJoin *
423
_copyHashJoin(HashJoin *from)
424
{
425
	HashJoin   *newnode = makeNode(HashJoin);
426

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

433 434
	/*
	 * copy remainder of node
435 436 437 438
	 */
	Node_Copy(from, newnode, hashclauses);
	newnode->hashjoinop = from->hashjoinop;

439 440 441
	/*
	 * We must add subplans in hashclauses to the new plan's subPlan list
	 */
442 443
	if (from->join.plan.subPlan != NIL)
		newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
444
						   pull_subplans((Node *) newnode->hashclauses));
445

446
	return newnode;
447 448 449 450
}


/* ----------------
451
 *		_copyMaterial
452 453 454
 * ----------------
 */
static Material *
455
_copyMaterial(Material *from)
456
{
457
	Material   *newnode = makeNode(Material);
458

459 460
	/*
	 * copy node superclass fields
461 462 463 464
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

	return newnode;
465 466 467 468
}


/* ----------------
469
 *		_copySort
470 471
 * ----------------
 */
472
static Sort *
473
_copySort(Sort *from)
474
{
475
	Sort	   *newnode = makeNode(Sort);
476

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

	newnode->keycount = from->keycount;
483 484

	return newnode;
485 486
}

V
Vadim B. Mikheev 已提交
487 488 489 490 491 492 493 494 495

/* ----------------
 *		_copyGroup
 * ----------------
 */
static Group *
_copyGroup(Group *from)
{
	Group	   *newnode = makeNode(Group);
496

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

V
Vadim B. Mikheev 已提交
499 500
	newnode->tuplePerGroup = from->tuplePerGroup;
	newnode->numCols = from->numCols;
501 502
	newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
	memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
V
Vadim B. Mikheev 已提交
503 504 505 506

	return newnode;
}

507
/* ---------------
508
 *	_copyAgg
509 510
 * --------------
 */
511
static Agg *
B
Bruce Momjian 已提交
512
_copyAgg(Agg *from)
513
{
514
	Agg		   *newnode = makeNode(Agg);
515 516 517 518

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

	return newnode;
519 520
}

521 522 523 524 525 526 527
/* ---------------
 *	_copyGroupClause
 * --------------
 */
static GroupClause *
_copyGroupClause(GroupClause *from)
{
528
	GroupClause *newnode = makeNode(GroupClause);
529

530 531
	newnode->tleSortGroupRef = from->tleSortGroupRef;
	newnode->sortop = from->sortop;
532

533
	return newnode;
534 535
}

536
/* ----------------
537
 *		_copyUnique
538 539
 * ----------------
 */
540
static Unique *
541
_copyUnique(Unique *from)
542
{
543
	Unique	   *newnode = makeNode(Unique);
544

545 546
	/*
	 * copy node superclass fields
547 548 549
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

550 551
	/*
	 * copy remainder of node
552
	 */
553 554 555
	newnode->numCols = from->numCols;
	newnode->uniqColIdx = palloc(from->numCols * sizeof(AttrNumber));
	memcpy(newnode->uniqColIdx, from->uniqColIdx, from->numCols * sizeof(AttrNumber));
556 557

	return newnode;
558 559
}

560 561 562 563 564 565 566 567 568
/* ----------------
 *		_copySetOp
 * ----------------
 */
static SetOp *
_copySetOp(SetOp *from)
{
	SetOp	   *newnode = makeNode(SetOp);

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

574 575
	/*
	 * copy remainder of node
576 577 578 579 580 581 582 583 584
	 */
	newnode->cmd = from->cmd;
	newnode->numCols = from->numCols;
	newnode->dupColIdx = palloc(from->numCols * sizeof(AttrNumber));
	memcpy(newnode->dupColIdx, from->dupColIdx, from->numCols * sizeof(AttrNumber));
	newnode->flagColIdx = from->flagColIdx;

	return newnode;
}
585

586 587 588 589 590 591 592 593 594
/* ----------------
 *		_copyLimit
 * ----------------
 */
static Limit *
_copyLimit(Limit *from)
{
	Limit	   *newnode = makeNode(Limit);

595 596
	/*
	 * copy node superclass fields
597 598 599
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

600 601
	/*
	 * copy remainder of node
602 603 604 605 606 607 608
	 */
	Node_Copy(from, newnode, limitOffset);
	Node_Copy(from, newnode, limitCount);

	return newnode;
}

609
/* ----------------
610
 *		_copyHash
611 612
 * ----------------
 */
613
static Hash *
614
_copyHash(Hash *from)
615
{
616
	Hash	   *newnode = makeNode(Hash);
617

618 619
	/*
	 * copy node superclass fields
620 621 622
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

623 624
	/*
	 * copy remainder of node
625 626 627 628
	 */
	Node_Copy(from, newnode, hashkey);

	return newnode;
629 630
}

V
Vadim B. Mikheev 已提交
631 632 633
static SubPlan *
_copySubPlan(SubPlan *from)
{
634 635
	SubPlan    *newnode = makeNode(SubPlan);

V
Vadim B. Mikheev 已提交
636 637 638
	Node_Copy(from, newnode, plan);
	newnode->plan_id = from->plan_id;
	Node_Copy(from, newnode, rtable);
639 640
	newnode->setParam = listCopy(from->setParam);
	newnode->parParam = listCopy(from->parParam);
V
Vadim B. Mikheev 已提交
641 642
	Node_Copy(from, newnode, sublink);

643
	/* do not copy execution state */
644
	newnode->needShutdown = false;
645 646
	newnode->curTuple = NULL;

V
Vadim B. Mikheev 已提交
647 648 649
	return newnode;
}

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

/* ----------------
656
 *		_copyResdom
657 658
 * ----------------
 */
659
static Resdom *
660
_copyResdom(Resdom *from)
661
{
662
	Resdom	   *newnode = makeNode(Resdom);
663 664 665

	newnode->resno = from->resno;
	newnode->restype = from->restype;
666
	newnode->restypmod = from->restypmod;
667
	if (from->resname != NULL)
B
Bruce Momjian 已提交
668
		newnode->resname = pstrdup(from->resname);
669
	newnode->ressortgroupref = from->ressortgroupref;
670 671 672 673 674
	newnode->reskey = from->reskey;
	newnode->reskeyop = from->reskeyop;
	newnode->resjunk = from->resjunk;

	return newnode;
675 676
}

677
static Fjoin *
678
_copyFjoin(Fjoin *from)
679
{
680
	Fjoin	   *newnode = makeNode(Fjoin);
681

682 683
	/*
	 * copy node superclass fields
684 685 686 687 688 689 690 691 692 693 694 695 696
	 */

	newnode->fj_initialized = from->fj_initialized;
	newnode->fj_nNodes = from->fj_nNodes;

	Node_Copy(from, newnode, fj_innerNode);

	newnode->fj_results = (DatumPtr)
		palloc((from->fj_nNodes) * sizeof(Datum));
	memmove(from->fj_results,
			newnode->fj_results,
			(from->fj_nNodes) * sizeof(Datum));

B
Bruce Momjian 已提交
697 698
	newnode->fj_alwaysDone = (BoolPtr)
		palloc((from->fj_nNodes) * sizeof(bool));
699 700 701 702 703 704
	memmove(from->fj_alwaysDone,
			newnode->fj_alwaysDone,
			(from->fj_nNodes) * sizeof(bool));


	return newnode;
705 706 707
}

/* ----------------
708
 *		_copyExpr
709 710
 * ----------------
 */
711
static Expr *
712
_copyExpr(Expr *from)
713
{
714
	Expr	   *newnode = makeNode(Expr);
715

716 717
	/*
	 * copy node superclass fields
718 719 720 721 722 723 724 725
	 */
	newnode->typeOid = from->typeOid;
	newnode->opType = from->opType;

	Node_Copy(from, newnode, oper);
	Node_Copy(from, newnode, args);

	return newnode;
726 727 728
}

/* ----------------
729
 *		_copyVar
730 731
 * ----------------
 */
732
static Var *
733
_copyVar(Var *from)
734
{
735
	Var		   *newnode = makeNode(Var);
736

737 738
	/*
	 * copy remainder of node
739 740 741 742
	 */
	newnode->varno = from->varno;
	newnode->varattno = from->varattno;
	newnode->vartype = from->vartype;
743
	newnode->vartypmod = from->vartypmod;
744
	newnode->varlevelsup = from->varlevelsup;
745 746 747 748 749

	newnode->varnoold = from->varnoold;
	newnode->varoattno = from->varoattno;

	return newnode;
750 751 752
}

/* ----------------
753
 *		_copyOper
754 755
 * ----------------
 */
756
static Oper *
757
_copyOper(Oper *from)
758
{
759
	Oper	   *newnode = makeNode(Oper);
760

761 762
	/*
	 * copy remainder of node
763 764 765 766
	 */
	newnode->opno = from->opno;
	newnode->opid = from->opid;
	newnode->opresulttype = from->opresulttype;
767
	newnode->opretset = from->opretset;
768 769
	/* Do not copy the run-time state, if any */
	newnode->op_fcache = NULL;
770 771

	return newnode;
772 773 774
}

/* ----------------
775
 *		_copyConst
776 777
 * ----------------
 */
778
static Const *
779
_copyConst(Const *from)
780
{
781
	Const	   *newnode = makeNode(Const);
782

783 784
	/*
	 * copy remainder of node
785
	 */
786 787 788
	newnode->consttype = from->consttype;
	newnode->constlen = from->constlen;

789
	if (from->constbyval || from->constisnull)
790
	{
791 792 793 794
		/*
		 * passed by value so just copy the datum. Also, don't try to copy
		 * struct when value is null!
		 *
795
		 */
796
		newnode->constvalue = from->constvalue;
797
	}
798
	else
799
	{
800 801
		/*
		 * not passed by value. datum contains a pointer.
802
		 */
803 804 805 806 807 808 809 810
		int			length = from->constlen;

		if (length == -1)		/* variable-length type? */
			length = VARSIZE(from->constvalue);
		newnode->constvalue = PointerGetDatum(palloc(length));
		memcpy(DatumGetPointer(newnode->constvalue),
			   DatumGetPointer(from->constvalue),
			   length);
811
	}
812

813 814
	newnode->constisnull = from->constisnull;
	newnode->constbyval = from->constbyval;
B
Bruce Momjian 已提交
815 816
	newnode->constisset = from->constisset;
	newnode->constiscast = from->constiscast;
817 818

	return newnode;
819 820 821
}

/* ----------------
822
 *		_copyParam
823 824
 * ----------------
 */
825
static Param *
826
_copyParam(Param *from)
827
{
828
	Param	   *newnode = makeNode(Param);
829

830 831
	/*
	 * copy remainder of node
832 833 834 835 836 837 838 839 840
	 */
	newnode->paramkind = from->paramkind;
	newnode->paramid = from->paramid;

	if (from->paramname != NULL)
		newnode->paramname = pstrdup(from->paramname);
	newnode->paramtype = from->paramtype;

	return newnode;
841 842 843
}

/* ----------------
844
 *		_copyFunc
845 846
 * ----------------
 */
847
static Func *
848
_copyFunc(Func *from)
849
{
850
	Func	   *newnode = makeNode(Func);
851

852 853
	/*
	 * copy remainder of node
854 855
	 */
	newnode->funcid = from->funcid;
856 857
	newnode->funcresulttype = from->funcresulttype;
	newnode->funcretset = from->funcretset;
858 859
	/* Do not copy the run-time state, if any */
	newnode->func_fcache = NULL;
860 861

	return newnode;
862 863 864
}

/* ----------------
B
Bruce Momjian 已提交
865
 *		_copyAggref
866 867
 * ----------------
 */
B
Bruce Momjian 已提交
868
static Aggref *
869
_copyAggref(Aggref *from)
870
{
B
Bruce Momjian 已提交
871
	Aggref	   *newnode = makeNode(Aggref);
872

873
	newnode->aggfnoid = from->aggfnoid;
874 875
	newnode->aggtype = from->aggtype;
	Node_Copy(from, newnode, target);
876 877
	newnode->aggstar = from->aggstar;
	newnode->aggdistinct = from->aggdistinct;
878
	newnode->aggno = from->aggno;		/* probably not needed */
879 880

	return newnode;
881 882
}

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

892 893
	/*
	 * copy remainder of node
894 895 896 897
	 */
	newnode->subLinkType = from->subLinkType;
	newnode->useor = from->useor;
	Node_Copy(from, newnode, lefthand);
B
Bruce Momjian 已提交
898
	Node_Copy(from, newnode, oper);
899 900 901 902 903
	Node_Copy(from, newnode, subselect);

	return newnode;
}

904 905 906 907 908 909 910 911 912
/* ----------------
 *		_copyFieldSelect
 * ----------------
 */
static FieldSelect *
_copyFieldSelect(FieldSelect *from)
{
	FieldSelect *newnode = makeNode(FieldSelect);

913 914
	/*
	 * copy remainder of node
915 916 917 918 919 920 921 922 923
	 */
	Node_Copy(from, newnode, arg);
	newnode->fieldnum = from->fieldnum;
	newnode->resulttype = from->resulttype;
	newnode->resulttypmod = from->resulttypmod;

	return newnode;
}

924 925 926 927 928 929 930
/* ----------------
 *		_copyRelabelType
 * ----------------
 */
static RelabelType *
_copyRelabelType(RelabelType *from)
{
931
	RelabelType *newnode = makeNode(RelabelType);
932

933 934
	/*
	 * copy remainder of node
935 936 937 938 939 940 941 942
	 */
	Node_Copy(from, newnode, arg);
	newnode->resulttype = from->resulttype;
	newnode->resulttypmod = from->resulttypmod;

	return newnode;
}

943 944 945 946 947 948 949 950 951 952
static RangeTblRef *
_copyRangeTblRef(RangeTblRef *from)
{
	RangeTblRef *newnode = makeNode(RangeTblRef);

	newnode->rtindex = from->rtindex;

	return newnode;
}

953 954 955
static FromExpr *
_copyFromExpr(FromExpr *from)
{
B
Bruce Momjian 已提交
956
	FromExpr   *newnode = makeNode(FromExpr);
957 958 959 960 961 962 963

	Node_Copy(from, newnode, fromlist);
	Node_Copy(from, newnode, quals);

	return newnode;
}

964 965 966
static JoinExpr *
_copyJoinExpr(JoinExpr *from)
{
B
Bruce Momjian 已提交
967
	JoinExpr   *newnode = makeNode(JoinExpr);
968 969 970 971 972 973 974 975

	newnode->jointype = from->jointype;
	newnode->isNatural = from->isNatural;
	Node_Copy(from, newnode, larg);
	Node_Copy(from, newnode, rarg);
	Node_Copy(from, newnode, using);
	Node_Copy(from, newnode, quals);
	Node_Copy(from, newnode, alias);
976
	newnode->rtindex = from->rtindex;
977 978 979 980

	return newnode;
}

T
Thomas G. Lockhart 已提交
981 982 983 984 985
/* ----------------
 *		_copyCaseExpr
 * ----------------
 */
static CaseExpr *
986
_copyCaseExpr(CaseExpr *from)
T
Thomas G. Lockhart 已提交
987 988 989
{
	CaseExpr   *newnode = makeNode(CaseExpr);

990 991
	/*
	 * copy remainder of node
T
Thomas G. Lockhart 已提交
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006
	 */
	newnode->casetype = from->casetype;

	Node_Copy(from, newnode, arg);
	Node_Copy(from, newnode, args);
	Node_Copy(from, newnode, defresult);

	return newnode;
}

/* ----------------
 *		_copyCaseWhen
 * ----------------
 */
static CaseWhen *
1007
_copyCaseWhen(CaseWhen *from)
T
Thomas G. Lockhart 已提交
1008 1009 1010
{
	CaseWhen   *newnode = makeNode(CaseWhen);

1011 1012
	/*
	 * copy remainder of node
T
Thomas G. Lockhart 已提交
1013 1014 1015 1016 1017 1018 1019
	 */
	Node_Copy(from, newnode, expr);
	Node_Copy(from, newnode, result);

	return newnode;
}

1020 1021 1022 1023 1024 1025 1026
/* ----------------
 *		_copyNullTest
 * ----------------
 */
static NullTest *
_copyNullTest(NullTest *from)
{
1027
	NullTest   *newnode = makeNode(NullTest);
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055

	/*
	 * copy remainder of node
	 */
	Node_Copy(from, newnode, arg);
	newnode->nulltesttype = from->nulltesttype;

	return newnode;
}

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

	/*
	 * copy remainder of node
	 */
	Node_Copy(from, newnode, arg);
	newnode->booltesttype = from->booltesttype;

	return newnode;
}

1056
static ArrayRef *
B
Bruce Momjian 已提交
1057
_copyArrayRef(ArrayRef *from)
1058
{
1059
	ArrayRef   *newnode = makeNode(ArrayRef);
1060

1061 1062
	/*
	 * copy remainder of node
1063 1064 1065
	 */
	newnode->refattrlength = from->refattrlength;
	newnode->refelemlength = from->refelemlength;
B
Bruce Momjian 已提交
1066
	newnode->refelemtype = from->refelemtype;
1067 1068 1069 1070 1071 1072 1073 1074
	newnode->refelembyval = from->refelembyval;

	Node_Copy(from, newnode, refupperindexpr);
	Node_Copy(from, newnode, reflowerindexpr);
	Node_Copy(from, newnode, refexpr);
	Node_Copy(from, newnode, refassgnexpr);

	return newnode;
1075 1076 1077
}

/* ****************************************************************
1078
 *						relation.h copy functions
1079 1080 1081 1082
 * ****************************************************************
 */

/* ----------------
B
Bruce Momjian 已提交
1083
 *		_copyRelOptInfo
1084 1085
 * ----------------
 */
B
Bruce Momjian 已提交
1086
static RelOptInfo *
1087
_copyRelOptInfo(RelOptInfo *from)
1088
{
1089
	RelOptInfo *newnode = makeNode(RelOptInfo);
1090

1091 1092
	newnode->reloptkind = from->reloptkind;

1093 1094
	newnode->relids = listCopy(from->relids);

1095
	newnode->rows = from->rows;
1096
	newnode->width = from->width;
1097

1098 1099
	Node_Copy(from, newnode, targetlist);
	Node_Copy(from, newnode, pathlist);
1100 1101 1102
	/* XXX cheapest-path fields should point to members of pathlist? */
	Node_Copy(from, newnode, cheapest_startup_path);
	Node_Copy(from, newnode, cheapest_total_path);
1103 1104
	newnode->pruneable = from->pruneable;

1105
	newnode->rtekind = from->rtekind;
1106
	Node_Copy(from, newnode, indexlist);
1107 1108
	newnode->pages = from->pages;
	newnode->tuples = from->tuples;
1109
	Node_Copy(from, newnode, subplan);
1110

1111 1112 1113
	newnode->joinrti = from->joinrti;
	newnode->joinrteids = listCopy(from->joinrteids);

1114
	Node_Copy(from, newnode, baserestrictinfo);
1115
	newnode->baserestrictcost = from->baserestrictcost;
1116
	newnode->outerjoinset = listCopy(from->outerjoinset);
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
	Node_Copy(from, newnode, joininfo);
	Node_Copy(from, newnode, innerjoin);

	return newnode;
}

/* ----------------
 *		_copyIndexOptInfo
 * ----------------
 */
static IndexOptInfo *
_copyIndexOptInfo(IndexOptInfo *from)
{
	IndexOptInfo *newnode = makeNode(IndexOptInfo);
1131
	Size		len;
1132 1133 1134 1135 1136

	newnode->indexoid = from->indexoid;
	newnode->pages = from->pages;
	newnode->tuples = from->tuples;

1137 1138 1139
	newnode->ncolumns = from->ncolumns;
	newnode->nkeys = from->nkeys;

1140 1141
	if (from->classlist)
	{
1142 1143 1144 1145
		/* copy the trailing zero too */
		len = (from->ncolumns + 1) * sizeof(Oid);
		newnode->classlist = (Oid *) palloc(len);
		memcpy(newnode->classlist, from->classlist, len);
1146
	}
1147 1148 1149

	if (from->indexkeys)
	{
1150 1151 1152 1153
		/* copy the trailing zero too */
		len = (from->nkeys + 1) * sizeof(int);
		newnode->indexkeys = (int *) palloc(len);
		memcpy(newnode->indexkeys, from->indexkeys, len);
1154
	}
1155 1156 1157

	if (from->ordering)
	{
1158 1159 1160 1161
		/* copy the trailing zero too */
		len = (from->ncolumns + 1) * sizeof(Oid);
		newnode->ordering = (Oid *) palloc(len);
		memcpy(newnode->ordering, from->ordering, len);
1162
	}
1163

1164
	newnode->relam = from->relam;
1165
	newnode->amcostestimate = from->amcostestimate;
1166 1167
	newnode->indproc = from->indproc;
	Node_Copy(from, newnode, indpred);
1168
	newnode->unique = from->unique;
1169

1170
	return newnode;
1171 1172 1173
}

/* ----------------
1174
 *		CopyPathFields
1175
 *
1176 1177
 *		This function copies the fields of the Path node.  It is used by
 *		all the copy functions for classes which inherit from Path.
1178 1179 1180
 * ----------------
 */
static void
1181
CopyPathFields(Path *from, Path *newnode)
1182
{
1183 1184 1185 1186 1187 1188 1189
	/*
	 * Modify the next line, since it causes the copying to cycle (i.e.
	 * the parent points right back here! -- JMH, 7/7/92. Old version:
	 * Node_Copy(from, newnode, parent);
	 */
	newnode->parent = from->parent;

1190 1191
	newnode->startup_cost = from->startup_cost;
	newnode->total_cost = from->total_cost;
1192

1193
	newnode->pathtype = from->pathtype;
1194

1195
	Node_Copy(from, newnode, pathkeys);
1196 1197 1198
}

/* ----------------
1199
 *		_copyPath
1200 1201
 * ----------------
 */
1202
static Path *
1203
_copyPath(Path *from)
1204
{
1205
	Path	   *newnode = makeNode(Path);
1206 1207 1208 1209

	CopyPathFields(from, newnode);

	return newnode;
1210 1211 1212
}

/* ----------------
1213
 *		_copyIndexPath
1214 1215 1216
 * ----------------
 */
static IndexPath *
1217
_copyIndexPath(IndexPath *from)
1218
{
1219
	IndexPath  *newnode = makeNode(IndexPath);
1220

1221 1222
	/*
	 * copy the node superclass fields
1223 1224 1225
	 */
	CopyPathFields((Path *) from, (Path *) newnode);

1226 1227
	/*
	 * copy remainder of node
1228
	 */
1229
	Node_Copy(from, newnode, indexinfo);
1230
	Node_Copy(from, newnode, indexqual);
1231
	newnode->indexscandir = from->indexscandir;
1232
	newnode->joinrelids = listCopy(from->joinrelids);
1233
	newnode->alljoinquals = from->alljoinquals;
1234
	newnode->rows = from->rows;
1235 1236

	return newnode;
1237 1238
}

1239
/* ----------------
1240
 *				_copyTidPath
1241 1242 1243 1244 1245
 * ----------------
 */
static TidPath *
_copyTidPath(TidPath *from)
{
1246
	TidPath    *newnode = makeNode(TidPath);
1247

1248 1249
	/*
	 * copy the node superclass fields
1250 1251 1252
	 */
	CopyPathFields((Path *) from, (Path *) newnode);

1253 1254
	/*
	 * copy remainder of node
1255 1256 1257 1258 1259 1260
	 */
	Node_Copy(from, newnode, tideval);
	newnode->unjoined_relids = listCopy(from->unjoined_relids);

	return newnode;
}
1261

1262 1263 1264 1265 1266 1267 1268
/* ----------------
 *				_copyAppendPath
 * ----------------
 */
static AppendPath *
_copyAppendPath(AppendPath *from)
{
B
Bruce Momjian 已提交
1269
	AppendPath *newnode = makeNode(AppendPath);
1270

1271 1272
	/*
	 * copy the node superclass fields
1273 1274 1275
	 */
	CopyPathFields((Path *) from, (Path *) newnode);

1276 1277
	/*
	 * copy remainder of node
1278 1279 1280 1281 1282 1283
	 */
	Node_Copy(from, newnode, subpaths);

	return newnode;
}

1284
/* ----------------
1285
 *		CopyJoinPathFields
1286
 *
1287 1288
 *		This function copies the fields of the JoinPath node.  It is used by
 *		all the copy functions for classes which inherit from JoinPath.
1289 1290 1291
 * ----------------
 */
static void
1292
CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1293
{
1294
	newnode->jointype = from->jointype;
1295 1296
	Node_Copy(from, newnode, outerjoinpath);
	Node_Copy(from, newnode, innerjoinpath);
1297
	Node_Copy(from, newnode, joinrestrictinfo);
1298 1299 1300
}

/* ----------------
1301
 *		_copyNestPath
1302 1303
 * ----------------
 */
1304
static NestPath *
1305
_copyNestPath(NestPath *from)
1306
{
1307
	NestPath   *newnode = makeNode(NestPath);
1308

1309 1310
	/*
	 * copy the node superclass fields
1311 1312
	 */
	CopyPathFields((Path *) from, (Path *) newnode);
1313
	CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1314 1315

	return newnode;
1316 1317 1318
}

/* ----------------
1319
 *		_copyMergePath
1320 1321 1322
 * ----------------
 */
static MergePath *
1323
_copyMergePath(MergePath *from)
1324
{
1325
	MergePath  *newnode = makeNode(MergePath);
1326

1327 1328
	/*
	 * copy the node superclass fields
1329 1330
	 */
	CopyPathFields((Path *) from, (Path *) newnode);
1331
	CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1332

1333 1334
	/*
	 * copy the remainder of the node
1335 1336 1337 1338 1339 1340
	 */
	Node_Copy(from, newnode, path_mergeclauses);
	Node_Copy(from, newnode, outersortkeys);
	Node_Copy(from, newnode, innersortkeys);

	return newnode;
1341 1342 1343
}

/* ----------------
1344
 *		_copyHashPath
1345 1346 1347
 * ----------------
 */
static HashPath *
1348
_copyHashPath(HashPath *from)
1349
{
1350
	HashPath   *newnode = makeNode(HashPath);
1351

1352 1353
	/*
	 * copy the node superclass fields
1354 1355
	 */
	CopyPathFields((Path *) from, (Path *) newnode);
1356
	CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1357

1358 1359
	/*
	 * copy remainder of node
1360 1361 1362 1363
	 */
	Node_Copy(from, newnode, path_hashclauses);

	return newnode;
1364 1365 1366
}

/* ----------------
1367
 *		_copyPathKeyItem
1368 1369
 * ----------------
 */
1370 1371
static PathKeyItem *
_copyPathKeyItem(PathKeyItem *from)
1372
{
1373
	PathKeyItem *newnode = makeNode(PathKeyItem);
1374

1375 1376
	/*
	 * copy remainder of node
1377
	 */
1378 1379
	Node_Copy(from, newnode, key);
	newnode->sortop = from->sortop;
1380 1381

	return newnode;
1382 1383 1384
}

/* ----------------
1385
 *		_copyRestrictInfo
1386 1387
 * ----------------
 */
1388
static RestrictInfo *
1389
_copyRestrictInfo(RestrictInfo *from)
1390
{
1391
	RestrictInfo *newnode = makeNode(RestrictInfo);
1392

1393 1394
	/*
	 * copy remainder of node
1395 1396
	 */
	Node_Copy(from, newnode, clause);
1397
	newnode->ispusheddown = from->ispusheddown;
1398
	Node_Copy(from, newnode, subclauseindices);
1399 1400
	newnode->eval_cost = from->eval_cost;
	newnode->this_selec = from->this_selec;
1401 1402 1403
	newnode->mergejoinoperator = from->mergejoinoperator;
	newnode->left_sortop = from->left_sortop;
	newnode->right_sortop = from->right_sortop;
B
Bruce Momjian 已提交
1404 1405 1406 1407 1408

	/*
	 * Do not copy pathkeys, since they'd not be canonical in a copied
	 * query
	 */
1409 1410
	newnode->left_pathkey = NIL;
	newnode->right_pathkey = NIL;
1411 1412
	newnode->left_mergescansel = from->left_mergescansel;
	newnode->right_mergescansel = from->right_mergescansel;
1413
	newnode->hashjoinoperator = from->hashjoinoperator;
1414 1415
	newnode->left_bucketsize = from->left_bucketsize;
	newnode->right_bucketsize = from->right_bucketsize;
1416 1417

	return newnode;
1418 1419 1420
}

/* ----------------
1421
 *		_copyJoinInfo
1422 1423
 * ----------------
 */
1424
static JoinInfo *
1425
_copyJoinInfo(JoinInfo *from)
1426
{
1427
	JoinInfo   *newnode = makeNode(JoinInfo);
1428

1429 1430
	/*
	 * copy remainder of node
1431
	 */
B
Bruce Momjian 已提交
1432
	newnode->unjoined_relids = listCopy(from->unjoined_relids);
1433
	Node_Copy(from, newnode, jinfo_restrictinfo);
1434 1435

	return newnode;
1436 1437
}

1438
static Stream *
1439
_copyStream(Stream *from)
1440
{
1441
	Stream	   *newnode = makeNode(Stream);
1442 1443 1444 1445

	newnode->pathptr = from->pathptr;
	newnode->cinfo = from->cinfo;
	newnode->clausetype = from->clausetype;
B
Bruce Momjian 已提交
1446

1447 1448 1449 1450 1451 1452
	newnode->upstream = (StreamPtr) NULL;		/* only copy nodes
												 * downwards! */
	Node_Copy(from, newnode, downstream);
	if (newnode->downstream)
		((Stream *) newnode->downstream)->upstream = (Stream *) newnode;

B
Bruce Momjian 已提交
1453 1454 1455 1456
	newnode->groupup = from->groupup;
	newnode->groupcost = from->groupcost;
	newnode->groupsel = from->groupsel;

1457
	return newnode;
1458 1459
}

1460 1461 1462
/* ****************************************************************
 *					parsenodes.h copy functions
 * ****************************************************************
1463 1464 1465
 */

static TargetEntry *
1466
_copyTargetEntry(TargetEntry *from)
1467
{
1468
	TargetEntry *newnode = makeNode(TargetEntry);
1469

1470 1471 1472 1473
	Node_Copy(from, newnode, resdom);
	Node_Copy(from, newnode, fjoin);
	Node_Copy(from, newnode, expr);
	return newnode;
1474 1475 1476
}

static RangeTblEntry *
1477
_copyRangeTblEntry(RangeTblEntry *from)
1478
{
1479
	RangeTblEntry *newnode = makeNode(RangeTblEntry);
1480

1481
	newnode->rtekind = from->rtekind;
B
Bruce Momjian 已提交
1482
	newnode->relid = from->relid;
1483
	Node_Copy(from, newnode, subquery);
1484
	Node_Copy(from, newnode, funcexpr);
1485
	newnode->jointype = from->jointype;
1486
	Node_Copy(from, newnode, joinaliasvars);
1487 1488
	Node_Copy(from, newnode, alias);
	Node_Copy(from, newnode, eref);
B
Bruce Momjian 已提交
1489 1490
	newnode->inh = from->inh;
	newnode->inFromCl = from->inFromCl;
1491 1492 1493
	newnode->checkForRead = from->checkForRead;
	newnode->checkForWrite = from->checkForWrite;
	newnode->checkAsUser = from->checkAsUser;
1494 1495 1496 1497

	return newnode;
}

1498 1499 1500
static FkConstraint *
_copyFkConstraint(FkConstraint *from)
{
B
Bruce Momjian 已提交
1501
	FkConstraint *newnode = makeNode(FkConstraint);
1502 1503 1504

	if (from->constr_name)
		newnode->constr_name = pstrdup(from->constr_name);
1505
	Node_Copy(from, newnode, pktable);
1506 1507
	Node_Copy(from, newnode, fk_attrs);
	Node_Copy(from, newnode, pk_attrs);
1508 1509 1510
	newnode->fk_matchtype = from->fk_matchtype;
	newnode->fk_upd_action = from->fk_upd_action;
	newnode->fk_del_action = from->fk_del_action;
1511 1512
	newnode->deferrable = from->deferrable;
	newnode->initdeferred = from->initdeferred;
1513
	newnode->skip_validation = from->skip_validation;
B
Bruce Momjian 已提交
1514

1515 1516 1517
	return newnode;
}

1518
static SortClause *
1519
_copySortClause(SortClause *from)
1520
{
1521
	SortClause *newnode = makeNode(SortClause);
1522

1523 1524
	newnode->tleSortGroupRef = from->tleSortGroupRef;
	newnode->sortop = from->sortop;
1525

1526
	return newnode;
1527 1528
}

1529 1530 1531
static A_Expr *
_copyAExpr(A_Expr *from)
{
B
Bruce Momjian 已提交
1532
	A_Expr	   *newnode = makeNode(A_Expr);
1533 1534

	newnode->oper = from->oper;
1535
	Node_Copy(from, newnode, name);
1536 1537 1538 1539 1540 1541
	Node_Copy(from, newnode, lexpr);
	Node_Copy(from, newnode, rexpr);

	return newnode;
}

1542 1543
static ColumnRef *
_copyColumnRef(ColumnRef *from)
1544
{
1545
	ColumnRef	   *newnode = makeNode(ColumnRef);
1546

1547 1548
	Node_Copy(from, newnode, fields);
	Node_Copy(from, newnode, indirection);
1549

1550
	return newnode;
1551 1552
}

1553 1554
static ParamRef *
_copyParamRef(ParamRef *from)
1555
{
1556
	ParamRef    *newnode = makeNode(ParamRef);
1557 1558

	newnode->number = from->number;
1559
	Node_Copy(from, newnode, fields);
1560 1561 1562 1563 1564
	Node_Copy(from, newnode, indirection);

	return newnode;
}

1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575
static A_Const *
_copyAConst(A_Const *from)
{
	A_Const    *newnode = makeNode(A_Const);

	newnode->val = *((Value *) (copyObject(&(from->val))));
	Node_Copy(from, newnode, typename);

	return newnode;
}

1576 1577 1578
static Ident *
_copyIdent(Ident *from)
{
B
Bruce Momjian 已提交
1579
	Ident	   *newnode = makeNode(Ident);
1580

1581
	newnode->name = pstrdup(from->name);
1582 1583 1584 1585 1586 1587 1588

	return newnode;
}

static FuncCall *
_copyFuncCall(FuncCall *from)
{
B
Bruce Momjian 已提交
1589
	FuncCall   *newnode = makeNode(FuncCall);
1590

1591
	Node_Copy(from, newnode, funcname);
1592 1593 1594 1595 1596 1597 1598 1599 1600 1601
	Node_Copy(from, newnode, args);
	newnode->agg_star = from->agg_star;
	newnode->agg_distinct = from->agg_distinct;

	return newnode;
}

static A_Indices *
_copyAIndices(A_Indices *from)
{
B
Bruce Momjian 已提交
1602
	A_Indices  *newnode = makeNode(A_Indices);
1603 1604 1605 1606 1607 1608 1609

	Node_Copy(from, newnode, lidx);
	Node_Copy(from, newnode, uidx);

	return newnode;
}

1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621
static ExprFieldSelect *
_copyExprFieldSelect(ExprFieldSelect *from)
{
	ExprFieldSelect	   *newnode = makeNode(ExprFieldSelect);

	Node_Copy(from, newnode, arg);
	Node_Copy(from, newnode, fields);
	Node_Copy(from, newnode, indirection);

	return newnode;
}

1622 1623 1624
static ResTarget *
_copyResTarget(ResTarget *from)
{
B
Bruce Momjian 已提交
1625
	ResTarget  *newnode = makeNode(ResTarget);
1626 1627 1628 1629 1630 1631 1632 1633 1634

	if (from->name)
		newnode->name = pstrdup(from->name);
	Node_Copy(from, newnode, indirection);
	Node_Copy(from, newnode, val);

	return newnode;
}

1635
static TypeName *
1636
_copyTypeName(TypeName *from)
1637
{
1638
	TypeName   *newnode = makeNode(TypeName);
1639

1640 1641
	Node_Copy(from, newnode, names);
	newnode->typeid = from->typeid;
B
Bruce Momjian 已提交
1642
	newnode->timezone = from->timezone;
1643
	newnode->setof = from->setof;
1644
	newnode->pct_type = from->pct_type;
1645
	newnode->typmod = from->typmod;
1646 1647 1648
	Node_Copy(from, newnode, arrayBounds);

	return newnode;
1649 1650
}

1651 1652 1653
static SortGroupBy *
_copySortGroupBy(SortGroupBy *from)
{
B
Bruce Momjian 已提交
1654
	SortGroupBy *newnode = makeNode(SortGroupBy);
1655

1656
	Node_Copy(from, newnode, useOp);
1657 1658 1659 1660 1661
	Node_Copy(from, newnode, node);

	return newnode;
}

1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673
static Alias *
_copyAlias(Alias *from)
{
	Alias	   *newnode = makeNode(Alias);

	if (from->aliasname)
		newnode->aliasname = pstrdup(from->aliasname);
	Node_Copy(from, newnode, colnames);

	return newnode;
}

1674 1675 1676 1677 1678
static RangeVar *
_copyRangeVar(RangeVar *from)
{
	RangeVar   *newnode = makeNode(RangeVar);

1679 1680 1681 1682
	if (from->catalogname)
		newnode->catalogname = pstrdup(from->catalogname);
	if (from->schemaname)
		newnode->schemaname = pstrdup(from->schemaname);
1683 1684
	if (from->relname)
		newnode->relname = pstrdup(from->relname);
1685
	newnode->inhOpt = from->inhOpt;
1686 1687
	newnode->istemp = from->istemp;
	Node_Copy(from, newnode, alias);
1688 1689 1690 1691 1692 1693 1694

	return newnode;
}

static RangeSubselect *
_copyRangeSubselect(RangeSubselect *from)
{
B
Bruce Momjian 已提交
1695
	RangeSubselect *newnode = makeNode(RangeSubselect);
1696 1697

	Node_Copy(from, newnode, subquery);
1698
	Node_Copy(from, newnode, alias);
1699 1700 1701 1702

	return newnode;
}

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

	Node_Copy(from, newnode, funccallnode);
	Node_Copy(from, newnode, alias);

	return newnode;
}

1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724
static TypeCast *
_copyTypeCast(TypeCast *from)
{
	TypeCast   *newnode = makeNode(TypeCast);

	Node_Copy(from, newnode, arg);
	Node_Copy(from, newnode, typename);

	return newnode;
}

1725 1726 1727
static IndexElem *
_copyIndexElem(IndexElem *from)
{
B
Bruce Momjian 已提交
1728
	IndexElem  *newnode = makeNode(IndexElem);
1729 1730 1731

	if (from->name)
		newnode->name = pstrdup(from->name);
1732
	Node_Copy(from, newnode, funcname);
1733
	Node_Copy(from, newnode, args);
1734
	Node_Copy(from, newnode, opclass);
1735 1736 1737 1738 1739 1740 1741

	return newnode;
}

static ColumnDef *
_copyColumnDef(ColumnDef *from)
{
B
Bruce Momjian 已提交
1742
	ColumnDef  *newnode = makeNode(ColumnDef);
1743 1744 1745 1746 1747 1748 1749 1750 1751

	if (from->colname)
		newnode->colname = pstrdup(from->colname);
	Node_Copy(from, newnode, typename);
	newnode->is_not_null = from->is_not_null;
	Node_Copy(from, newnode, raw_default);
	if (from->cooked_default)
		newnode->cooked_default = pstrdup(from->cooked_default);
	Node_Copy(from, newnode, constraints);
1752
	Node_Copy(from, newnode, support);
1753 1754 1755 1756 1757 1758 1759

	return newnode;
}

static Constraint *
_copyConstraint(Constraint *from)
{
B
Bruce Momjian 已提交
1760
	Constraint *newnode = makeNode(Constraint);
1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775

	newnode->contype = from->contype;
	if (from->name)
		newnode->name = pstrdup(from->name);
	Node_Copy(from, newnode, raw_expr);
	if (from->cooked_expr)
		newnode->cooked_expr = pstrdup(from->cooked_expr);
	Node_Copy(from, newnode, keys);

	return newnode;
}

static DefElem *
_copyDefElem(DefElem *from)
{
B
Bruce Momjian 已提交
1776
	DefElem    *newnode = makeNode(DefElem);
1777 1778 1779 1780 1781 1782 1783 1784

	if (from->defname)
		newnode->defname = pstrdup(from->defname);
	Node_Copy(from, newnode, arg);

	return newnode;
}

1785
static Query *
1786
_copyQuery(Query *from)
1787
{
1788
	Query	   *newnode = makeNode(Query);
1789

1790
	newnode->commandType = from->commandType;
1791
	Node_Copy(from, newnode, utilityStmt);
1792
	newnode->resultRelation = from->resultRelation;
1793
	Node_Copy(from, newnode, into);
1794
	newnode->isPortal = from->isPortal;
B
Bruce Momjian 已提交
1795
	newnode->isBinary = from->isBinary;
1796 1797
	newnode->hasAggs = from->hasAggs;
	newnode->hasSubLinks = from->hasSubLinks;
1798
	newnode->originalQuery = from->originalQuery;
1799

B
Bruce Momjian 已提交
1800
	Node_Copy(from, newnode, rtable);
1801 1802
	Node_Copy(from, newnode, jointree);

1803
	newnode->rowMarks = listCopy(from->rowMarks);
1804

1805 1806
	Node_Copy(from, newnode, targetList);

1807
	Node_Copy(from, newnode, groupClause);
B
Bruce Momjian 已提交
1808
	Node_Copy(from, newnode, havingQual);
1809 1810
	Node_Copy(from, newnode, distinctClause);
	Node_Copy(from, newnode, sortClause);
1811

B
Bruce Momjian 已提交
1812 1813 1814
	Node_Copy(from, newnode, limitOffset);
	Node_Copy(from, newnode, limitCount);

1815 1816
	Node_Copy(from, newnode, setOperations);

1817 1818
	newnode->resultRelations = listCopy(from->resultRelations);

1819 1820
	/*
	 * We do not copy the planner internal fields: base_rel_list,
1821 1822
	 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. Not
	 * entirely clear if this is right?
1823
	 */
1824

1825
	return newnode;
1826 1827
}

1828 1829 1830 1831
static InsertStmt *
_copyInsertStmt(InsertStmt *from)
{
	InsertStmt *newnode = makeNode(InsertStmt);
B
Bruce Momjian 已提交
1832

1833
	Node_Copy(from, newnode, relation);
1834 1835
	Node_Copy(from, newnode, cols);
	Node_Copy(from, newnode, targetList);
1836
	Node_Copy(from, newnode, selectStmt);
1837 1838 1839 1840 1841 1842 1843 1844

	return newnode;
}

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

1846
	Node_Copy(from, newnode, relation);
1847 1848 1849 1850 1851 1852 1853 1854 1855
	Node_Copy(from, newnode, whereClause);

	return newnode;
}

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

1857
	Node_Copy(from, newnode, relation);
1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868
	Node_Copy(from, newnode, targetList);
	Node_Copy(from, newnode, whereClause);
	Node_Copy(from, newnode, fromClause);

	return newnode;
}

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

1870
	Node_Copy(from, newnode, distinctClause);
1871
	Node_Copy(from, newnode, into);
1872
	Node_Copy(from, newnode, intoColNames);
1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884
	Node_Copy(from, newnode, targetList);
	Node_Copy(from, newnode, fromClause);
	Node_Copy(from, newnode, whereClause);
	Node_Copy(from, newnode, groupClause);
	Node_Copy(from, newnode, havingClause);
	Node_Copy(from, newnode, sortClause);
	if (from->portalname)
		newnode->portalname = pstrdup(from->portalname);
	newnode->binary = from->binary;
	Node_Copy(from, newnode, limitOffset);
	Node_Copy(from, newnode, limitCount);
	Node_Copy(from, newnode, forUpdate);
1885 1886 1887 1888
	newnode->op = from->op;
	newnode->all = from->all;
	Node_Copy(from, newnode, larg);
	Node_Copy(from, newnode, rarg);
1889 1890 1891 1892

	return newnode;
}

1893 1894 1895 1896
static SetOperationStmt *
_copySetOperationStmt(SetOperationStmt *from)
{
	SetOperationStmt *newnode = makeNode(SetOperationStmt);
B
Bruce Momjian 已提交
1897

1898 1899 1900 1901 1902 1903 1904 1905 1906
	newnode->op = from->op;
	newnode->all = from->all;
	Node_Copy(from, newnode, larg);
	Node_Copy(from, newnode, rarg);
	newnode->colTypes = listCopy(from->colTypes);

	return newnode;
}

1907 1908 1909 1910
static AlterTableStmt *
_copyAlterTableStmt(AlterTableStmt *from)
{
	AlterTableStmt *newnode = makeNode(AlterTableStmt);
B
Bruce Momjian 已提交
1911

1912
	newnode->subtype = from->subtype;
1913
	Node_Copy(from, newnode, relation);
1914 1915 1916 1917 1918 1919 1920 1921
	if (from->name)
		newnode->name = pstrdup(from->name);
	Node_Copy(from, newnode, def);
	newnode->behavior = from->behavior;

	return newnode;
}

1922 1923
static GrantStmt *
_copyGrantStmt(GrantStmt *from)
1924
{
1925
	GrantStmt  *newnode = makeNode(GrantStmt);
B
Bruce Momjian 已提交
1926

1927
	newnode->is_grant = from->is_grant;
1928 1929
	newnode->objtype = from->objtype;
	Node_Copy(from, newnode, objects);
1930
	newnode->privileges = listCopy(from->privileges);
1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944
	Node_Copy(from, newnode, grantees);

	return newnode;
}

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

	if (from->username)
		newnode->username = pstrdup(from->username);
	if (from->groupname)
		newnode->groupname = pstrdup(from->groupname);
1945 1946 1947 1948

	return newnode;
}

1949 1950 1951 1952 1953
static FuncWithArgs *
_copyFuncWithArgs(FuncWithArgs *from)
{
	FuncWithArgs *newnode = makeNode(FuncWithArgs);

1954
	Node_Copy(from, newnode, funcname);
1955 1956 1957 1958 1959
	Node_Copy(from, newnode, funcargs);

	return newnode;
}

B
Bruce Momjian 已提交
1960 1961 1962 1963 1964 1965 1966 1967 1968
static InsertDefault *
_copyInsertDefault(InsertDefault *from)
{
	InsertDefault *newnode = makeNode(InsertDefault);

	return newnode;
}


1969 1970 1971
static ClosePortalStmt *
_copyClosePortalStmt(ClosePortalStmt *from)
{
1972
	ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1973 1974 1975 1976 1977 1978 1979

	if (from->portalname)
		newnode->portalname = pstrdup(from->portalname);

	return newnode;
}

1980 1981 1982 1983
static ClusterStmt *
_copyClusterStmt(ClusterStmt *from)
{
	ClusterStmt *newnode = makeNode(ClusterStmt);
B
Bruce Momjian 已提交
1984

1985
	Node_Copy(from, newnode, relation);
1986 1987 1988 1989 1990 1991 1992 1993 1994
	if (from->indexname)
		newnode->indexname = pstrdup(from->indexname);

	return newnode;
}

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

1997
	Node_Copy(from, newnode, relation);
1998
	newnode->is_from = from->is_from;
1999 2000
	if (from->filename)
		newnode->filename = pstrdup(from->filename);
2001
	Node_Copy(from, newnode, options);
2002 2003 2004 2005 2006 2007 2008 2009

	return newnode;
}

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

2011
	Node_Copy(from, newnode, relation);
2012
	Node_Copy(from, newnode, tableElts);
2013
	Node_Copy(from, newnode, inhRelations);
2014
	Node_Copy(from, newnode, constraints);
2015
	newnode->hasoids = from->hasoids;
2016 2017 2018 2019 2020 2021 2022 2023

	return newnode;
}

static DefineStmt *
_copyDefineStmt(DefineStmt *from)
{
	DefineStmt *newnode = makeNode(DefineStmt);
B
Bruce Momjian 已提交
2024

2025
	newnode->defType = from->defType;
2026
	Node_Copy(from, newnode, defnames);
2027 2028 2029 2030 2031 2032 2033 2034
	Node_Copy(from, newnode, definition);

	return newnode;
}

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

2037
	Node_Copy(from, newnode, objects);
2038
	newnode->removeType = from->removeType;
T
Tom Lane 已提交
2039
	newnode->behavior = from->behavior;
2040 2041 2042 2043

	return newnode;
}

2044 2045 2046
static TruncateStmt *
_copyTruncateStmt(TruncateStmt *from)
{
2047
	TruncateStmt *newnode = makeNode(TruncateStmt);
2048

2049
	Node_Copy(from, newnode, relation);
2050 2051 2052 2053

	return newnode;
}

2054 2055 2056 2057
static CommentStmt *
_copyCommentStmt(CommentStmt *from)
{
	CommentStmt *newnode = makeNode(CommentStmt);
B
Bruce Momjian 已提交
2058

2059
	newnode->objtype = from->objtype;
2060 2061 2062 2063
	Node_Copy(from, newnode, objname);
	Node_Copy(from, newnode, objargs);
	if (from->comment)
		newnode->comment = pstrdup(from->comment);
2064 2065 2066 2067 2068 2069 2070

	return newnode;
}

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

2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083
	newnode->direction = from->direction;
	newnode->howMany = from->howMany;
	newnode->portalname = pstrdup(from->portalname);
	newnode->ismove = from->ismove;

	return newnode;
}

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

2086
	newnode->idxname = pstrdup(from->idxname);
2087
	Node_Copy(from, newnode, relation);
2088 2089 2090 2091 2092 2093
	newnode->accessMethod = pstrdup(from->accessMethod);
	Node_Copy(from, newnode, indexParams);
	Node_Copy(from, newnode, whereClause);
	Node_Copy(from, newnode, rangetable);
	newnode->unique = from->unique;
	newnode->primary = from->primary;
2094
	newnode->isconstraint = from->isconstraint;
2095 2096 2097 2098

	return newnode;
}

2099 2100
static CreateFunctionStmt *
_copyCreateFunctionStmt(CreateFunctionStmt *from)
2101
{
2102
	CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
B
Bruce Momjian 已提交
2103

2104
	newnode->replace = from->replace;
2105
	Node_Copy(from, newnode, funcname);
2106
	Node_Copy(from, newnode, argTypes);
2107
	Node_Copy(from, newnode, returnType);
2108
	Node_Copy(from, newnode, options);
2109 2110 2111 2112 2113 2114 2115 2116 2117
	Node_Copy(from, newnode, withClause);

	return newnode;
}

static RemoveAggrStmt *
_copyRemoveAggrStmt(RemoveAggrStmt *from)
{
	RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
B
Bruce Momjian 已提交
2118

2119
	Node_Copy(from, newnode, aggname);
2120
	Node_Copy(from, newnode, aggtype);
2121
	newnode->behavior = from->behavior;
2122 2123 2124 2125 2126 2127 2128 2129

	return newnode;
}

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

2131
	Node_Copy(from, newnode, funcname);
2132
	Node_Copy(from, newnode, args);
2133
	newnode->behavior = from->behavior;
2134 2135 2136 2137 2138 2139 2140 2141

	return newnode;
}

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

2143
	Node_Copy(from, newnode, opname);
2144
	Node_Copy(from, newnode, args);
2145
	newnode->behavior = from->behavior;
2146 2147 2148 2149 2150 2151 2152 2153

	return newnode;
}

static RenameStmt *
_copyRenameStmt(RenameStmt *from)
{
	RenameStmt *newnode = makeNode(RenameStmt);
B
Bruce Momjian 已提交
2154

2155
	Node_Copy(from, newnode, relation);
2156 2157
	if (from->oldname)
		newnode->oldname = pstrdup(from->oldname);
2158 2159
	if (from->newname)
		newnode->newname = pstrdup(from->newname);
2160
	newnode->renameType = from->renameType;
2161 2162 2163 2164 2165 2166 2167

	return newnode;
}

static RuleStmt *
_copyRuleStmt(RuleStmt *from)
{
B
Bruce Momjian 已提交
2168 2169
	RuleStmt   *newnode = makeNode(RuleStmt);

2170
	Node_Copy(from, newnode, relation);
2171 2172 2173 2174 2175 2176 2177 2178 2179
	newnode->rulename = pstrdup(from->rulename);
	Node_Copy(from, newnode, whereClause);
	newnode->event = from->event;
	newnode->instead = from->instead;
	Node_Copy(from, newnode, actions);

	return newnode;
}

2180 2181 2182
static NotifyStmt *
_copyNotifyStmt(NotifyStmt *from)
{
2183
	NotifyStmt *newnode = makeNode(NotifyStmt);
2184

2185
	Node_Copy(from, newnode, relation);
2186 2187 2188 2189 2190 2191 2192

	return newnode;
}

static ListenStmt *
_copyListenStmt(ListenStmt *from)
{
2193
	ListenStmt *newnode = makeNode(ListenStmt);
2194

2195
	Node_Copy(from, newnode, relation);
2196 2197 2198 2199 2200 2201 2202

	return newnode;
}

static UnlistenStmt *
_copyUnlistenStmt(UnlistenStmt *from)
{
2203
	UnlistenStmt *newnode = makeNode(UnlistenStmt);
2204

2205
	Node_Copy(from, newnode, relation);
2206 2207 2208 2209 2210 2211 2212

	return newnode;
}

static TransactionStmt *
_copyTransactionStmt(TransactionStmt *from)
{
2213
	TransactionStmt *newnode = makeNode(TransactionStmt);
2214 2215 2216 2217 2218 2219

	newnode->command = from->command;

	return newnode;
}

2220 2221 2222 2223 2224
static ViewStmt *
_copyViewStmt(ViewStmt *from)
{
	ViewStmt   *newnode = makeNode(ViewStmt);

2225
	Node_Copy(from, newnode, view);
2226 2227 2228 2229 2230 2231
	Node_Copy(from, newnode, aliases);
	Node_Copy(from, newnode, query);

	return newnode;
}

2232 2233 2234
static LoadStmt *
_copyLoadStmt(LoadStmt *from)
{
2235
	LoadStmt   *newnode = makeNode(LoadStmt);
2236 2237 2238 2239 2240 2241 2242

	if (from->filename)
		newnode->filename = pstrdup(from->filename);

	return newnode;
}

2243 2244 2245 2246 2247
static CreateDomainStmt *
_copyCreateDomainStmt(CreateDomainStmt *from)
{
	CreateDomainStmt *newnode = makeNode(CreateDomainStmt);

2248
	Node_Copy(from, newnode, domainname);
2249 2250 2251 2252 2253 2254
	Node_Copy(from, newnode, typename);
	Node_Copy(from, newnode, constraints);

	return newnode;
}

2255 2256 2257
static CreatedbStmt *
_copyCreatedbStmt(CreatedbStmt *from)
{
B
Bruce Momjian 已提交
2258
	CreatedbStmt *newnode = makeNode(CreatedbStmt);
2259 2260 2261

	if (from->dbname)
		newnode->dbname = pstrdup(from->dbname);
2262
	Node_Copy(from, newnode, options);
2263 2264 2265 2266

	return newnode;
}

2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280
static AlterDatabaseSetStmt *
_copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
{
	AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);

	if (from->dbname)
		newnode->dbname = pstrdup(from->dbname);
	if (from->variable)
		newnode->variable = pstrdup(from->variable);
	Node_Copy(from, newnode, value);

	return newnode;
}

2281 2282 2283
static DropdbStmt *
_copyDropdbStmt(DropdbStmt *from)
{
B
Bruce Momjian 已提交
2284
	DropdbStmt *newnode = makeNode(DropdbStmt);
2285 2286 2287 2288 2289 2290 2291 2292 2293 2294

	if (from->dbname)
		newnode->dbname = pstrdup(from->dbname);

	return newnode;
}

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

2297
	newnode->vacuum = from->vacuum;
2298
	newnode->full = from->full;
2299
	newnode->analyze = from->analyze;
2300
	newnode->freeze = from->freeze;
2301
	newnode->verbose = from->verbose;
2302
	Node_Copy(from, newnode, relation);
2303
	Node_Copy(from, newnode, va_cols);
2304 2305 2306 2307 2308 2309 2310

	return newnode;
}

static ExplainStmt *
_copyExplainStmt(ExplainStmt *from)
{
B
Bruce Momjian 已提交
2311
	ExplainStmt *newnode = makeNode(ExplainStmt);
2312 2313 2314

	Node_Copy(from, newnode, query);
	newnode->verbose = from->verbose;
2315
	newnode->analyze = from->analyze;
2316 2317 2318 2319 2320 2321 2322

	return newnode;
}

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

2325
	Node_Copy(from, newnode, sequence);
2326 2327 2328 2329 2330
	Node_Copy(from, newnode, options);

	return newnode;
}

2331 2332 2333
static VariableSetStmt *
_copyVariableSetStmt(VariableSetStmt *from)
{
2334
	VariableSetStmt *newnode = makeNode(VariableSetStmt);
2335 2336 2337

	if (from->name)
		newnode->name = pstrdup(from->name);
2338
	Node_Copy(from, newnode, args);
2339
	newnode->is_local = from->is_local;
2340 2341 2342 2343

	return newnode;
}

2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354
static VariableShowStmt *
_copyVariableShowStmt(VariableShowStmt *from)
{
	VariableShowStmt *newnode = makeNode(VariableShowStmt);

	if (from->name)
		newnode->name = pstrdup(from->name);

	return newnode;
}

2355 2356 2357
static VariableResetStmt *
_copyVariableResetStmt(VariableResetStmt *from)
{
2358
	VariableResetStmt *newnode = makeNode(VariableResetStmt);
2359 2360 2361 2362 2363 2364 2365

	if (from->name)
		newnode->name = pstrdup(from->name);

	return newnode;
}

2366 2367 2368 2369 2370 2371 2372
static CreateTrigStmt *
_copyCreateTrigStmt(CreateTrigStmt *from)
{
	CreateTrigStmt *newnode = makeNode(CreateTrigStmt);

	if (from->trigname)
		newnode->trigname = pstrdup(from->trigname);
2373
	Node_Copy(from, newnode, relation);
2374
	Node_Copy(from, newnode, funcname);
2375 2376 2377 2378 2379 2380 2381 2382
	Node_Copy(from, newnode, args);
	newnode->before = from->before;
	newnode->row = from->row;
	memcpy(newnode->actions, from->actions, sizeof(from->actions));
	if (from->lang)
		newnode->lang = pstrdup(from->lang);
	if (from->text)
		newnode->text = pstrdup(from->text);
B
Bruce Momjian 已提交
2383

2384 2385 2386 2387 2388 2389
	Node_Copy(from, newnode, attr);
	if (from->when)
		newnode->when = pstrdup(from->when);
	newnode->isconstraint = from->isconstraint;
	newnode->deferrable = from->deferrable;
	newnode->initdeferred = from->initdeferred;
2390
	Node_Copy(from, newnode, constrrel);
2391 2392 2393 2394

	return newnode;
}

2395 2396
static DropPropertyStmt *
_copyDropPropertyStmt(DropPropertyStmt *from)
2397
{
2398
	DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2399

2400
	Node_Copy(from, newnode, relation);
2401 2402 2403
	if (from->property)
		newnode->property = pstrdup(from->property);
	newnode->removeType = from->removeType;
2404
	newnode->behavior = from->behavior;
2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415

	return newnode;
}

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

	if (from->plname)
		newnode->plname = pstrdup(from->plname);
2416
	Node_Copy(from, newnode, plhandler);
2417
	Node_Copy(from, newnode, plvalidator);
2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429
	newnode->pltrusted = from->pltrusted;

	return newnode;
}

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

	if (from->plname)
		newnode->plname = pstrdup(from->plname);
2430
	newnode->behavior = from->behavior;
2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441

	return newnode;
}

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

	if (from->user)
		newnode->user = pstrdup(from->user);
2442
	Node_Copy(from, newnode, options);
2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453

	return newnode;
}

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

	if (from->user)
		newnode->user = pstrdup(from->user);
2454
	Node_Copy(from, newnode, options);
2455 2456 2457 2458

	return newnode;
}

2459 2460 2461 2462 2463 2464 2465 2466
static AlterUserSetStmt *
_copyAlterUserSetStmt(AlterUserSetStmt *from)
{
	AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);

	if (from->user)
		newnode->user = pstrdup(from->user);
	if (from->variable)
T
Tom Lane 已提交
2467
		newnode->variable = pstrdup(from->variable);
2468 2469 2470 2471 2472
	Node_Copy(from, newnode, value);

	return newnode;
}

2473 2474 2475 2476 2477 2478 2479 2480 2481 2482
static DropUserStmt *
_copyDropUserStmt(DropUserStmt *from)
{
	DropUserStmt *newnode = makeNode(DropUserStmt);

	Node_Copy(from, newnode, users);

	return newnode;
}

2483 2484 2485
static LockStmt *
_copyLockStmt(LockStmt *from)
{
2486
	LockStmt   *newnode = makeNode(LockStmt);
2487

2488
	Node_Copy(from, newnode, relations);
2489

2490 2491 2492 2493
	newnode->mode = from->mode;

	return newnode;
}
2494

2495 2496 2497
static ConstraintsSetStmt *
_copyConstraintsSetStmt(ConstraintsSetStmt *from)
{
B
Bruce Momjian 已提交
2498
	ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2499 2500 2501 2502 2503 2504 2505 2506 2507 2508

	Node_Copy(from, newnode, constraints);
	newnode->deferred = from->deferred;

	return newnode;
}

static CreateGroupStmt *
_copyCreateGroupStmt(CreateGroupStmt *from)
{
B
Bruce Momjian 已提交
2509
	CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2510 2511 2512

	if (from->name)
		newnode->name = pstrdup(from->name);
2513
	Node_Copy(from, newnode, options);
2514 2515 2516 2517 2518 2519 2520

	return newnode;
}

static AlterGroupStmt *
_copyAlterGroupStmt(AlterGroupStmt *from)
{
B
Bruce Momjian 已提交
2521
	AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533

	if (from->name)
		newnode->name = pstrdup(from->name);
	newnode->action = from->action;
	Node_Copy(from, newnode, listUsers);

	return newnode;
}

static DropGroupStmt *
_copyDropGroupStmt(DropGroupStmt *from)
{
B
Bruce Momjian 已提交
2534
	DropGroupStmt *newnode = makeNode(DropGroupStmt);
2535 2536 2537 2538 2539 2540 2541 2542 2543 2544

	if (from->name)
		newnode->name = pstrdup(from->name);

	return newnode;
}

static ReindexStmt *
_copyReindexStmt(ReindexStmt *from)
{
B
Bruce Momjian 已提交
2545
	ReindexStmt *newnode = makeNode(ReindexStmt);
2546 2547

	newnode->reindexType = from->reindexType;
2548
	Node_Copy(from, newnode, relation);
2549 2550 2551 2552 2553 2554 2555 2556
	if (from->name)
		newnode->name = pstrdup(from->name);
	newnode->force = from->force;
	newnode->all = from->all;

	return newnode;
}

2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569
static CreateSchemaStmt *
_copyCreateSchemaStmt(CreateSchemaStmt *from)
{
	CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);

	newnode->schemaname = pstrdup(from->schemaname);
	if (from->authid)
		newnode->authid = pstrdup(from->authid);
	Node_Copy(from, newnode, schemaElts);

	return newnode;
}

2570 2571

/* ****************************************************************
2572
 *					pg_list.h copy functions
2573 2574 2575
 * ****************************************************************
 */

2576
static Value *
2577
_copyValue(Value *from)
2578
{
2579
	Value	   *newnode = makeNode(Value);
2580 2581 2582 2583

	newnode->type = from->type;
	switch (from->type)
	{
2584 2585 2586 2587
		case T_Integer:
			newnode->val.ival = from->val.ival;
			break;
		case T_Float:
2588
		case T_String:
2589
		case T_BitString:
2590
			newnode->val.str = pstrdup(from->val.str);
2591 2592 2593
			break;
		default:
			break;
2594 2595
	}
	return newnode;
2596 2597 2598
}

/* ----------------
2599 2600
 *		copyObject returns a copy of the node or list. If it is a list, it
 *		recursively copies its items.
2601 2602
 * ----------------
 */
2603
void *
2604 2605
copyObject(void *from)
{
2606
	void	   *retval;
2607

2608 2609
	if (from == NULL)
		return NULL;
2610

2611
	switch (nodeTag(from))
2612
	{
2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633
			/*
			 * 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;
2634 2635 2636
		case T_TidScan:
			retval = _copyTidScan(from);
			break;
2637 2638 2639
		case T_SubqueryScan:
			retval = _copySubqueryScan(from);
			break;
2640 2641 2642
		case T_FunctionScan:
			retval = _copyFunctionScan(from);
			break;
2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660
		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 已提交
2661 2662 2663
		case T_Group:
			retval = _copyGroup(from);
			break;
2664 2665 2666 2667 2668 2669
		case T_Agg:
			retval = _copyAgg(from);
			break;
		case T_Unique:
			retval = _copyUnique(from);
			break;
2670 2671 2672
		case T_SetOp:
			retval = _copySetOp(from);
			break;
2673 2674 2675
		case T_Limit:
			retval = _copyLimit(from);
			break;
2676 2677 2678
		case T_Hash:
			retval = _copyHash(from);
			break;
V
Vadim B. Mikheev 已提交
2679 2680 2681
		case T_SubPlan:
			retval = _copySubPlan(from);
			break;
2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706

			/*
			 * PRIMITIVE NODES
			 */
		case T_Resdom:
			retval = _copyResdom(from);
			break;
		case T_Fjoin:
			retval = _copyFjoin(from);
			break;
		case T_Expr:
			retval = _copyExpr(from);
			break;
		case T_Var:
			retval = _copyVar(from);
			break;
		case T_Oper:
			retval = _copyOper(from);
			break;
		case T_Const:
			retval = _copyConst(from);
			break;
		case T_Param:
			retval = _copyParam(from);
			break;
2707 2708 2709 2710 2711 2712
		case T_Aggref:
			retval = _copyAggref(from);
			break;
		case T_SubLink:
			retval = _copySubLink(from);
			break;
2713 2714 2715 2716 2717 2718
		case T_Func:
			retval = _copyFunc(from);
			break;
		case T_ArrayRef:
			retval = _copyArrayRef(from);
			break;
2719 2720 2721
		case T_FieldSelect:
			retval = _copyFieldSelect(from);
			break;
2722 2723 2724
		case T_RelabelType:
			retval = _copyRelabelType(from);
			break;
2725 2726 2727
		case T_RangeTblRef:
			retval = _copyRangeTblRef(from);
			break;
2728 2729 2730
		case T_FromExpr:
			retval = _copyFromExpr(from);
			break;
2731 2732 2733
		case T_JoinExpr:
			retval = _copyJoinExpr(from);
			break;
2734 2735 2736 2737

			/*
			 * RELATION NODES
			 */
B
Bruce Momjian 已提交
2738
		case T_RelOptInfo:
B
Bruce Momjian 已提交
2739
			retval = _copyRelOptInfo(from);
2740 2741 2742 2743 2744 2745 2746
			break;
		case T_Path:
			retval = _copyPath(from);
			break;
		case T_IndexPath:
			retval = _copyIndexPath(from);
			break;
2747 2748 2749
		case T_TidPath:
			retval = _copyTidPath(from);
			break;
2750 2751 2752
		case T_AppendPath:
			retval = _copyAppendPath(from);
			break;
2753 2754
		case T_NestPath:
			retval = _copyNestPath(from);
2755 2756 2757 2758 2759 2760 2761
			break;
		case T_MergePath:
			retval = _copyMergePath(from);
			break;
		case T_HashPath:
			retval = _copyHashPath(from);
			break;
2762 2763
		case T_PathKeyItem:
			retval = _copyPathKeyItem(from);
2764
			break;
2765 2766
		case T_RestrictInfo:
			retval = _copyRestrictInfo(from);
2767
			break;
2768 2769
		case T_JoinInfo:
			retval = _copyJoinInfo(from);
2770 2771 2772 2773
			break;
		case T_Stream:
			retval = _copyStream(from);
			break;
2774 2775 2776
		case T_IndexOptInfo:
			retval = _copyIndexOptInfo(from);
			break;
2777 2778

			/*
2779
			 * VALUE NODES
2780
			 */
2781 2782 2783
		case T_Integer:
		case T_Float:
		case T_String:
2784
		case T_BitString:
2785
			retval = _copyValue(from);
2786
			break;
2787 2788 2789 2790 2791 2792 2793 2794
		case T_List:
			{
				List	   *list = from,
						   *l,
						   *nl;

				/* rather ugly coding for speed... */
				/* Note the input list cannot be NIL if we got here. */
2795
				nl = makeList1(copyObject(lfirst(list)));
2796 2797 2798 2799
				retval = nl;

				foreach(l, lnext(list))
				{
2800
					lnext(nl) = makeList1(copyObject(lfirst(l)));
2801 2802 2803
					nl = lnext(nl);
				}
			}
2804
			break;
2805 2806 2807 2808

			/*
			 * PARSE NODES
			 */
2809 2810 2811
		case T_Query:
			retval = _copyQuery(from);
			break;
2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823
		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;
2824 2825 2826
		case T_SetOperationStmt:
			retval = _copySetOperationStmt(from);
			break;
2827 2828 2829
		case T_AlterTableStmt:
			retval = _copyAlterTableStmt(from);
			break;
2830 2831
		case T_GrantStmt:
			retval = _copyGrantStmt(from);
2832
			break;
2833 2834 2835
		case T_ClosePortalStmt:
			retval = _copyClosePortalStmt(from);
			break;
2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850
		case T_ClusterStmt:
			retval = _copyClusterStmt(from);
			break;
		case T_CopyStmt:
			retval = _copyCopyStmt(from);
			break;
		case T_CreateStmt:
			retval = _copyCreateStmt(from);
			break;
		case T_DefineStmt:
			retval = _copyDefineStmt(from);
			break;
		case T_DropStmt:
			retval = _copyDropStmt(from);
			break;
2851 2852 2853
		case T_TruncateStmt:
			retval = _copyTruncateStmt(from);
			break;
2854 2855 2856 2857 2858 2859 2860 2861 2862
		case T_CommentStmt:
			retval = _copyCommentStmt(from);
			break;
		case T_FetchStmt:
			retval = _copyFetchStmt(from);
			break;
		case T_IndexStmt:
			retval = _copyIndexStmt(from);
			break;
2863 2864
		case T_CreateFunctionStmt:
			retval = _copyCreateFunctionStmt(from);
2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880
			break;
		case T_RemoveAggrStmt:
			retval = _copyRemoveAggrStmt(from);
			break;
		case T_RemoveFuncStmt:
			retval = _copyRemoveFuncStmt(from);
			break;
		case T_RemoveOperStmt:
			retval = _copyRemoveOperStmt(from);
			break;
		case T_RenameStmt:
			retval = _copyRenameStmt(from);
			break;
		case T_RuleStmt:
			retval = _copyRuleStmt(from);
			break;
2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892
		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;
2893 2894 2895
		case T_ViewStmt:
			retval = _copyViewStmt(from);
			break;
2896 2897 2898
		case T_LoadStmt:
			retval = _copyLoadStmt(from);
			break;
2899 2900 2901
		case T_CreateDomainStmt:
			retval = _copyCreateDomainStmt(from);
			break;
2902 2903 2904
		case T_CreatedbStmt:
			retval = _copyCreatedbStmt(from);
			break;
2905 2906 2907
		case T_AlterDatabaseSetStmt:
			retval = _copyAlterDatabaseSetStmt(from);
			break;
2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919
		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;
2920 2921 2922
		case T_VariableSetStmt:
			retval = _copyVariableSetStmt(from);
			break;
2923 2924 2925
		case T_VariableShowStmt:
			retval = _copyVariableShowStmt(from);
			break;
2926 2927 2928
		case T_VariableResetStmt:
			retval = _copyVariableResetStmt(from);
			break;
2929 2930 2931
		case T_CreateTrigStmt:
			retval = _copyCreateTrigStmt(from);
			break;
2932 2933
		case T_DropPropertyStmt:
			retval = _copyDropPropertyStmt(from);
2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946
			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;
2947 2948 2949
		case T_AlterUserSetStmt:
			retval = _copyAlterUserSetStmt(from);
			break;
2950 2951 2952
		case T_DropUserStmt:
			retval = _copyDropUserStmt(from);
			break;
2953 2954 2955
		case T_LockStmt:
			retval = _copyLockStmt(from);
			break;
2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970
		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 已提交
2971
		case T_CheckPointStmt:
B
Bruce Momjian 已提交
2972
			retval = (void *) makeNode(CheckPointStmt);
V
Vadim B. Mikheev 已提交
2973
			break;
2974 2975 2976
		case T_CreateSchemaStmt:
			retval = _copyCreateSchemaStmt(from);
			break;
2977

2978 2979 2980
		case T_A_Expr:
			retval = _copyAExpr(from);
			break;
2981 2982 2983 2984 2985
		case T_ColumnRef:
			retval = _copyColumnRef(from);
			break;
		case T_ParamRef:
			retval = _copyParamRef(from);
2986
			break;
2987 2988 2989
		case T_A_Const:
			retval = _copyAConst(from);
			break;
2990 2991 2992 2993 2994 2995 2996 2997 2998
		case T_Ident:
			retval = _copyIdent(from);
			break;
		case T_FuncCall:
			retval = _copyFuncCall(from);
			break;
		case T_A_Indices:
			retval = _copyAIndices(from);
			break;
2999 3000 3001
		case T_ExprFieldSelect:
			retval = _copyExprFieldSelect(from);
			break;
3002 3003 3004
		case T_ResTarget:
			retval = _copyResTarget(from);
			break;
3005 3006 3007
		case T_TypeCast:
			retval = _copyTypeCast(from);
			break;
3008 3009 3010
		case T_SortGroupBy:
			retval = _copySortGroupBy(from);
			break;
3011 3012 3013
		case T_Alias:
			retval = _copyAlias(from);
			break;
3014 3015 3016
		case T_RangeVar:
			retval = _copyRangeVar(from);
			break;
3017 3018 3019
		case T_RangeSubselect:
			retval = _copyRangeSubselect(from);
			break;
3020 3021 3022
		case T_RangeFunction:
			retval = _copyRangeFunction(from);
			break;
3023 3024 3025
		case T_TypeName:
			retval = _copyTypeName(from);
			break;
3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037
		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;
3038 3039 3040 3041 3042
		case T_TargetEntry:
			retval = _copyTargetEntry(from);
			break;
		case T_RangeTblEntry:
			retval = _copyRangeTblEntry(from);
3043
			break;
3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055
		case T_SortClause:
			retval = _copySortClause(from);
			break;
		case T_GroupClause:
			retval = _copyGroupClause(from);
			break;
		case T_CaseExpr:
			retval = _copyCaseExpr(from);
			break;
		case T_CaseWhen:
			retval = _copyCaseWhen(from);
			break;
3056 3057 3058 3059 3060 3061
		case T_NullTest:
			retval = _copyNullTest(from);
			break;
		case T_BooleanTest:
			retval = _copyBooleanTest(from);
			break;
3062 3063 3064
		case T_FkConstraint:
			retval = _copyFkConstraint(from);
			break;
3065 3066 3067
		case T_PrivGrantee:
			retval = _copyPrivGrantee(from);
			break;
3068 3069 3070
		case T_FuncWithArgs:
			retval = _copyFuncWithArgs(from);
			break;
B
Bruce Momjian 已提交
3071 3072 3073
		case T_InsertDefault:
			retval = _copyInsertDefault(from);
			break;
3074

3075
		default:
3076 3077 3078
			elog(ERROR, "copyObject: don't know how to copy node type %d",
				 nodeTag(from));
			retval = from;		/* keep compiler quiet */
3079
			break;
3080
	}
3081
	return retval;
3082
}