copyfuncs.c 62.7 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.
 *
 *
14
 * Portions Copyright (c) 1996-2001, 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.179 2002/04/17 20:57:56 tgl 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
 *		CopyJoinFields
316
 *
317 318
 *		This function copies the fields of the Join node.  It is used by
 *		all the copy functions for classes which inherit from Join.
319 320 321
 * ----------------
 */
static void
322
CopyJoinFields(Join *from, Join *newnode)
323
{
324 325
	newnode->jointype = from->jointype;
	Node_Copy(from, newnode, joinqual);
326
	newnode->joinrti = from->joinrti;
327 328 329
	/* 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 已提交
330
							  pull_subplans((Node *) newnode->joinqual));
331 332 333 334
}


/* ----------------
335
 *		_copyJoin
336 337
 * ----------------
 */
338
static Join *
339
_copyJoin(Join *from)
340
{
341
	Join	   *newnode = makeNode(Join);
342

343 344
	/*
	 * copy node superclass fields
345 346 347 348 349
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
	CopyJoinFields(from, newnode);

	return newnode;
350 351 352 353
}


/* ----------------
354
 *		_copyNestLoop
355 356 357
 * ----------------
 */
static NestLoop *
358
_copyNestLoop(NestLoop *from)
359
{
360
	NestLoop   *newnode = makeNode(NestLoop);
361

362 363
	/*
	 * copy node superclass fields
364 365 366 367 368
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
	CopyJoinFields((Join *) from, (Join *) newnode);

	return newnode;
369 370 371 372
}


/* ----------------
373
 *		_copyMergeJoin
374 375 376
 * ----------------
 */
static MergeJoin *
377
_copyMergeJoin(MergeJoin *from)
378
{
379
	MergeJoin  *newnode = makeNode(MergeJoin);
380

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

387 388
	/*
	 * copy remainder of node
389 390 391
	 */
	Node_Copy(from, newnode, mergeclauses);

392 393 394
	/*
	 * We must add subplans in mergeclauses to the new plan's subPlan list
	 */
395 396
	if (from->join.plan.subPlan != NIL)
		newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
397
						  pull_subplans((Node *) newnode->mergeclauses));
398

399
	return newnode;
400 401 402
}

/* ----------------
403
 *		_copyHashJoin
404 405 406
 * ----------------
 */
static HashJoin *
407
_copyHashJoin(HashJoin *from)
408
{
409
	HashJoin   *newnode = makeNode(HashJoin);
410

411 412
	/*
	 * copy node superclass fields
413 414 415 416
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
	CopyJoinFields((Join *) from, (Join *) newnode);

417 418
	/*
	 * copy remainder of node
419 420 421 422
	 */
	Node_Copy(from, newnode, hashclauses);
	newnode->hashjoinop = from->hashjoinop;

423 424 425
	/*
	 * We must add subplans in hashclauses to the new plan's subPlan list
	 */
426 427
	if (from->join.plan.subPlan != NIL)
		newnode->join.plan.subPlan = nconc(newnode->join.plan.subPlan,
428
						   pull_subplans((Node *) newnode->hashclauses));
429

430
	return newnode;
431 432 433 434
}


/* ----------------
435
 *		_copyMaterial
436 437 438
 * ----------------
 */
static Material *
439
_copyMaterial(Material *from)
440
{
441
	Material   *newnode = makeNode(Material);
442

443 444
	/*
	 * copy node superclass fields
445 446 447 448
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

	return newnode;
449 450 451 452
}


/* ----------------
453
 *		_copySort
454 455
 * ----------------
 */
456
static Sort *
457
_copySort(Sort *from)
458
{
459
	Sort	   *newnode = makeNode(Sort);
460

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

	newnode->keycount = from->keycount;
467 468

	return newnode;
469 470
}

V
Vadim B. Mikheev 已提交
471 472 473 474 475 476 477 478 479

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

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

V
Vadim B. Mikheev 已提交
483 484
	newnode->tuplePerGroup = from->tuplePerGroup;
	newnode->numCols = from->numCols;
485 486
	newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
	memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
V
Vadim B. Mikheev 已提交
487 488 489 490

	return newnode;
}

491
/* ---------------
492
 *	_copyAgg
493 494
 * --------------
 */
495
static Agg *
B
Bruce Momjian 已提交
496
_copyAgg(Agg *from)
497
{
498
	Agg		   *newnode = makeNode(Agg);
499 500 501 502

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

	return newnode;
503 504
}

505 506 507 508 509 510 511
/* ---------------
 *	_copyGroupClause
 * --------------
 */
static GroupClause *
_copyGroupClause(GroupClause *from)
{
512
	GroupClause *newnode = makeNode(GroupClause);
513

514 515
	newnode->tleSortGroupRef = from->tleSortGroupRef;
	newnode->sortop = from->sortop;
516

517
	return newnode;
518 519
}

520
/* ----------------
521
 *		_copyUnique
522 523
 * ----------------
 */
524
static Unique *
525
_copyUnique(Unique *from)
526
{
527
	Unique	   *newnode = makeNode(Unique);
528

529 530
	/*
	 * copy node superclass fields
531 532 533
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

534 535
	/*
	 * copy remainder of node
536
	 */
537 538 539
	newnode->numCols = from->numCols;
	newnode->uniqColIdx = palloc(from->numCols * sizeof(AttrNumber));
	memcpy(newnode->uniqColIdx, from->uniqColIdx, from->numCols * sizeof(AttrNumber));
540 541

	return newnode;
542 543
}

544 545 546 547 548 549 550 551 552
/* ----------------
 *		_copySetOp
 * ----------------
 */
static SetOp *
_copySetOp(SetOp *from)
{
	SetOp	   *newnode = makeNode(SetOp);

553 554
	/*
	 * copy node superclass fields
555 556 557
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

558 559
	/*
	 * copy remainder of node
560 561 562 563 564 565 566 567 568
	 */
	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;
}
569

570 571 572 573 574 575 576 577 578
/* ----------------
 *		_copyLimit
 * ----------------
 */
static Limit *
_copyLimit(Limit *from)
{
	Limit	   *newnode = makeNode(Limit);

579 580
	/*
	 * copy node superclass fields
581 582 583
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

584 585
	/*
	 * copy remainder of node
586 587 588 589 590 591 592
	 */
	Node_Copy(from, newnode, limitOffset);
	Node_Copy(from, newnode, limitCount);

	return newnode;
}

593
/* ----------------
594
 *		_copyHash
595 596
 * ----------------
 */
597
static Hash *
598
_copyHash(Hash *from)
599
{
600
	Hash	   *newnode = makeNode(Hash);
601

602 603
	/*
	 * copy node superclass fields
604 605 606
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

607 608
	/*
	 * copy remainder of node
609 610 611 612
	 */
	Node_Copy(from, newnode, hashkey);

	return newnode;
613 614
}

V
Vadim B. Mikheev 已提交
615 616 617
static SubPlan *
_copySubPlan(SubPlan *from)
{
618 619
	SubPlan    *newnode = makeNode(SubPlan);

V
Vadim B. Mikheev 已提交
620 621 622
	Node_Copy(from, newnode, plan);
	newnode->plan_id = from->plan_id;
	Node_Copy(from, newnode, rtable);
623 624
	newnode->setParam = listCopy(from->setParam);
	newnode->parParam = listCopy(from->parParam);
V
Vadim B. Mikheev 已提交
625 626
	Node_Copy(from, newnode, sublink);

627
	/* do not copy execution state */
628
	newnode->needShutdown = false;
629 630
	newnode->curTuple = NULL;

V
Vadim B. Mikheev 已提交
631 632 633
	return newnode;
}

634
/* ****************************************************************
635
 *					   primnodes.h copy functions
636 637 638 639
 * ****************************************************************
 */

/* ----------------
640
 *		_copyResdom
641 642
 * ----------------
 */
643
static Resdom *
644
_copyResdom(Resdom *from)
645
{
646
	Resdom	   *newnode = makeNode(Resdom);
647 648 649

	newnode->resno = from->resno;
	newnode->restype = from->restype;
650
	newnode->restypmod = from->restypmod;
651
	if (from->resname != NULL)
B
Bruce Momjian 已提交
652
		newnode->resname = pstrdup(from->resname);
653
	newnode->ressortgroupref = from->ressortgroupref;
654 655 656 657 658
	newnode->reskey = from->reskey;
	newnode->reskeyop = from->reskeyop;
	newnode->resjunk = from->resjunk;

	return newnode;
659 660
}

661
static Fjoin *
662
_copyFjoin(Fjoin *from)
663
{
664
	Fjoin	   *newnode = makeNode(Fjoin);
665

666 667
	/*
	 * copy node superclass fields
668 669 670 671 672 673 674 675 676 677 678 679 680
	 */

	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 已提交
681 682
	newnode->fj_alwaysDone = (BoolPtr)
		palloc((from->fj_nNodes) * sizeof(bool));
683 684 685 686 687 688
	memmove(from->fj_alwaysDone,
			newnode->fj_alwaysDone,
			(from->fj_nNodes) * sizeof(bool));


	return newnode;
689 690 691
}

/* ----------------
692
 *		_copyExpr
693 694
 * ----------------
 */
695
static Expr *
696
_copyExpr(Expr *from)
697
{
698
	Expr	   *newnode = makeNode(Expr);
699

700 701
	/*
	 * copy node superclass fields
702 703 704 705 706 707 708 709
	 */
	newnode->typeOid = from->typeOid;
	newnode->opType = from->opType;

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

	return newnode;
710 711 712
}

/* ----------------
713
 *		_copyVar
714 715
 * ----------------
 */
716
static Var *
717
_copyVar(Var *from)
718
{
719
	Var		   *newnode = makeNode(Var);
720

721 722
	/*
	 * copy remainder of node
723 724 725 726
	 */
	newnode->varno = from->varno;
	newnode->varattno = from->varattno;
	newnode->vartype = from->vartype;
727
	newnode->vartypmod = from->vartypmod;
728
	newnode->varlevelsup = from->varlevelsup;
729 730 731 732 733

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

	return newnode;
734 735 736
}

/* ----------------
737
 *		_copyOper
738 739
 * ----------------
 */
740
static Oper *
741
_copyOper(Oper *from)
742
{
743
	Oper	   *newnode = makeNode(Oper);
744

745 746
	/*
	 * copy remainder of node
747 748 749 750
	 */
	newnode->opno = from->opno;
	newnode->opid = from->opid;
	newnode->opresulttype = from->opresulttype;
751 752
	/* Do not copy the run-time state, if any */
	newnode->op_fcache = NULL;
753 754

	return newnode;
755 756 757
}

/* ----------------
758
 *		_copyConst
759 760
 * ----------------
 */
761
static Const *
762
_copyConst(Const *from)
763
{
764
	Const	   *newnode = makeNode(Const);
765

766 767
	/*
	 * copy remainder of node
768
	 */
769 770 771
	newnode->consttype = from->consttype;
	newnode->constlen = from->constlen;

772
	if (from->constbyval || from->constisnull)
773
	{
774 775 776 777
		/*
		 * passed by value so just copy the datum. Also, don't try to copy
		 * struct when value is null!
		 *
778
		 */
779
		newnode->constvalue = from->constvalue;
780
	}
781
	else
782
	{
783 784
		/*
		 * not passed by value. datum contains a pointer.
785
		 */
786 787 788 789 790 791 792 793
		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);
794
	}
795

796 797
	newnode->constisnull = from->constisnull;
	newnode->constbyval = from->constbyval;
B
Bruce Momjian 已提交
798 799
	newnode->constisset = from->constisset;
	newnode->constiscast = from->constiscast;
800 801

	return newnode;
802 803 804
}

/* ----------------
805
 *		_copyParam
806 807
 * ----------------
 */
808
static Param *
809
_copyParam(Param *from)
810
{
811
	Param	   *newnode = makeNode(Param);
812

813 814
	/*
	 * copy remainder of node
815 816 817 818 819 820 821 822 823
	 */
	newnode->paramkind = from->paramkind;
	newnode->paramid = from->paramid;

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

	return newnode;
824 825 826
}

/* ----------------
827
 *		_copyFunc
828 829
 * ----------------
 */
830
static Func *
831
_copyFunc(Func *from)
832
{
833
	Func	   *newnode = makeNode(Func);
834

835 836
	/*
	 * copy remainder of node
837 838 839
	 */
	newnode->funcid = from->funcid;
	newnode->functype = from->functype;
840 841
	/* Do not copy the run-time state, if any */
	newnode->func_fcache = NULL;
842 843

	return newnode;
844 845 846
}

/* ----------------
B
Bruce Momjian 已提交
847
 *		_copyAggref
848 849
 * ----------------
 */
B
Bruce Momjian 已提交
850
static Aggref *
851
_copyAggref(Aggref *from)
852
{
B
Bruce Momjian 已提交
853
	Aggref	   *newnode = makeNode(Aggref);
854

855
	newnode->aggfnoid = from->aggfnoid;
856 857
	newnode->aggtype = from->aggtype;
	Node_Copy(from, newnode, target);
858 859
	newnode->aggstar = from->aggstar;
	newnode->aggdistinct = from->aggdistinct;
860
	newnode->aggno = from->aggno;		/* probably not needed */
861 862

	return newnode;
863 864
}

865 866 867 868 869 870 871
/* ----------------
 *		_copySubLink
 * ----------------
 */
static SubLink *
_copySubLink(SubLink *from)
{
872
	SubLink    *newnode = makeNode(SubLink);
873

874 875
	/*
	 * copy remainder of node
876 877 878 879
	 */
	newnode->subLinkType = from->subLinkType;
	newnode->useor = from->useor;
	Node_Copy(from, newnode, lefthand);
B
Bruce Momjian 已提交
880
	Node_Copy(from, newnode, oper);
881 882 883 884 885
	Node_Copy(from, newnode, subselect);

	return newnode;
}

886 887 888 889 890 891 892 893 894
/* ----------------
 *		_copyFieldSelect
 * ----------------
 */
static FieldSelect *
_copyFieldSelect(FieldSelect *from)
{
	FieldSelect *newnode = makeNode(FieldSelect);

895 896
	/*
	 * copy remainder of node
897 898 899 900 901 902 903 904 905
	 */
	Node_Copy(from, newnode, arg);
	newnode->fieldnum = from->fieldnum;
	newnode->resulttype = from->resulttype;
	newnode->resulttypmod = from->resulttypmod;

	return newnode;
}

906 907 908 909 910 911 912
/* ----------------
 *		_copyRelabelType
 * ----------------
 */
static RelabelType *
_copyRelabelType(RelabelType *from)
{
913
	RelabelType *newnode = makeNode(RelabelType);
914

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

	return newnode;
}

925 926 927 928 929 930 931 932 933 934
static RangeTblRef *
_copyRangeTblRef(RangeTblRef *from)
{
	RangeTblRef *newnode = makeNode(RangeTblRef);

	newnode->rtindex = from->rtindex;

	return newnode;
}

935 936 937
static FromExpr *
_copyFromExpr(FromExpr *from)
{
B
Bruce Momjian 已提交
938
	FromExpr   *newnode = makeNode(FromExpr);
939 940 941 942 943 944 945

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

	return newnode;
}

946 947 948
static JoinExpr *
_copyJoinExpr(JoinExpr *from)
{
B
Bruce Momjian 已提交
949
	JoinExpr   *newnode = makeNode(JoinExpr);
950 951 952 953 954 955 956 957

	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);
958
	newnode->rtindex = from->rtindex;
959 960 961 962

	return newnode;
}

T
Thomas G. Lockhart 已提交
963 964 965 966 967
/* ----------------
 *		_copyCaseExpr
 * ----------------
 */
static CaseExpr *
968
_copyCaseExpr(CaseExpr *from)
T
Thomas G. Lockhart 已提交
969 970 971
{
	CaseExpr   *newnode = makeNode(CaseExpr);

972 973
	/*
	 * copy remainder of node
T
Thomas G. Lockhart 已提交
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988
	 */
	newnode->casetype = from->casetype;

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

	return newnode;
}

/* ----------------
 *		_copyCaseWhen
 * ----------------
 */
static CaseWhen *
989
_copyCaseWhen(CaseWhen *from)
T
Thomas G. Lockhart 已提交
990 991 992
{
	CaseWhen   *newnode = makeNode(CaseWhen);

993 994
	/*
	 * copy remainder of node
T
Thomas G. Lockhart 已提交
995 996 997 998 999 1000 1001
	 */
	Node_Copy(from, newnode, expr);
	Node_Copy(from, newnode, result);

	return newnode;
}

1002 1003 1004 1005 1006 1007 1008
/* ----------------
 *		_copyNullTest
 * ----------------
 */
static NullTest *
_copyNullTest(NullTest *from)
{
1009
	NullTest   *newnode = makeNode(NullTest);
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037

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

1038
static ArrayRef *
B
Bruce Momjian 已提交
1039
_copyArrayRef(ArrayRef *from)
1040
{
1041
	ArrayRef   *newnode = makeNode(ArrayRef);
1042

1043 1044
	/*
	 * copy remainder of node
1045 1046 1047
	 */
	newnode->refattrlength = from->refattrlength;
	newnode->refelemlength = from->refelemlength;
B
Bruce Momjian 已提交
1048
	newnode->refelemtype = from->refelemtype;
1049 1050 1051 1052 1053 1054 1055 1056
	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;
1057 1058 1059
}

/* ****************************************************************
1060
 *						relation.h copy functions
1061 1062 1063 1064
 * ****************************************************************
 */

/* ----------------
B
Bruce Momjian 已提交
1065
 *		_copyRelOptInfo
1066 1067
 * ----------------
 */
B
Bruce Momjian 已提交
1068
static RelOptInfo *
1069
_copyRelOptInfo(RelOptInfo *from)
1070
{
1071
	RelOptInfo *newnode = makeNode(RelOptInfo);
1072

1073 1074
	newnode->reloptkind = from->reloptkind;

1075 1076
	newnode->relids = listCopy(from->relids);

1077
	newnode->rows = from->rows;
1078
	newnode->width = from->width;
1079

1080 1081
	Node_Copy(from, newnode, targetlist);
	Node_Copy(from, newnode, pathlist);
1082 1083 1084
	/* XXX cheapest-path fields should point to members of pathlist? */
	Node_Copy(from, newnode, cheapest_startup_path);
	Node_Copy(from, newnode, cheapest_total_path);
1085 1086
	newnode->pruneable = from->pruneable;

1087
	newnode->issubquery = from->issubquery;
1088
	Node_Copy(from, newnode, indexlist);
1089 1090
	newnode->pages = from->pages;
	newnode->tuples = from->tuples;
1091
	Node_Copy(from, newnode, subplan);
1092

1093 1094 1095
	newnode->joinrti = from->joinrti;
	newnode->joinrteids = listCopy(from->joinrteids);

1096
	Node_Copy(from, newnode, baserestrictinfo);
1097
	newnode->baserestrictcost = from->baserestrictcost;
1098
	newnode->outerjoinset = listCopy(from->outerjoinset);
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
	Node_Copy(from, newnode, joininfo);
	Node_Copy(from, newnode, innerjoin);

	return newnode;
}

/* ----------------
 *		_copyIndexOptInfo
 * ----------------
 */
static IndexOptInfo *
_copyIndexOptInfo(IndexOptInfo *from)
{
	IndexOptInfo *newnode = makeNode(IndexOptInfo);
1113
	Size		len;
1114 1115 1116 1117 1118

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

1119 1120 1121
	newnode->ncolumns = from->ncolumns;
	newnode->nkeys = from->nkeys;

1122 1123
	if (from->classlist)
	{
1124 1125 1126 1127
		/* copy the trailing zero too */
		len = (from->ncolumns + 1) * sizeof(Oid);
		newnode->classlist = (Oid *) palloc(len);
		memcpy(newnode->classlist, from->classlist, len);
1128
	}
1129 1130 1131

	if (from->indexkeys)
	{
1132 1133 1134 1135
		/* copy the trailing zero too */
		len = (from->nkeys + 1) * sizeof(int);
		newnode->indexkeys = (int *) palloc(len);
		memcpy(newnode->indexkeys, from->indexkeys, len);
1136
	}
1137 1138 1139

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

1146
	newnode->relam = from->relam;
1147
	newnode->amcostestimate = from->amcostestimate;
1148 1149
	newnode->indproc = from->indproc;
	Node_Copy(from, newnode, indpred);
1150
	newnode->unique = from->unique;
1151

1152
	return newnode;
1153 1154 1155
}

/* ----------------
1156
 *		CopyPathFields
1157
 *
1158 1159
 *		This function copies the fields of the Path node.  It is used by
 *		all the copy functions for classes which inherit from Path.
1160 1161 1162
 * ----------------
 */
static void
1163
CopyPathFields(Path *from, Path *newnode)
1164
{
1165 1166 1167 1168 1169 1170 1171
	/*
	 * 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;

1172 1173
	newnode->startup_cost = from->startup_cost;
	newnode->total_cost = from->total_cost;
1174

1175
	newnode->pathtype = from->pathtype;
1176

1177
	Node_Copy(from, newnode, pathkeys);
1178 1179 1180
}

/* ----------------
1181
 *		_copyPath
1182 1183
 * ----------------
 */
1184
static Path *
1185
_copyPath(Path *from)
1186
{
1187
	Path	   *newnode = makeNode(Path);
1188 1189 1190 1191

	CopyPathFields(from, newnode);

	return newnode;
1192 1193 1194
}

/* ----------------
1195
 *		_copyIndexPath
1196 1197 1198
 * ----------------
 */
static IndexPath *
1199
_copyIndexPath(IndexPath *from)
1200
{
1201
	IndexPath  *newnode = makeNode(IndexPath);
1202

1203 1204
	/*
	 * copy the node superclass fields
1205 1206 1207
	 */
	CopyPathFields((Path *) from, (Path *) newnode);

1208 1209
	/*
	 * copy remainder of node
1210
	 */
1211
	Node_Copy(from, newnode, indexinfo);
1212
	Node_Copy(from, newnode, indexqual);
1213
	newnode->indexscandir = from->indexscandir;
1214
	newnode->joinrelids = listCopy(from->joinrelids);
1215
	newnode->alljoinquals = from->alljoinquals;
1216
	newnode->rows = from->rows;
1217 1218

	return newnode;
1219 1220
}

1221
/* ----------------
1222
 *				_copyTidPath
1223 1224 1225 1226 1227
 * ----------------
 */
static TidPath *
_copyTidPath(TidPath *from)
{
1228
	TidPath    *newnode = makeNode(TidPath);
1229

1230 1231
	/*
	 * copy the node superclass fields
1232 1233 1234
	 */
	CopyPathFields((Path *) from, (Path *) newnode);

1235 1236
	/*
	 * copy remainder of node
1237 1238 1239 1240 1241 1242
	 */
	Node_Copy(from, newnode, tideval);
	newnode->unjoined_relids = listCopy(from->unjoined_relids);

	return newnode;
}
1243

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

1253 1254
	/*
	 * copy the node superclass fields
1255 1256 1257
	 */
	CopyPathFields((Path *) from, (Path *) newnode);

1258 1259
	/*
	 * copy remainder of node
1260 1261 1262 1263 1264 1265
	 */
	Node_Copy(from, newnode, subpaths);

	return newnode;
}

1266
/* ----------------
1267
 *		CopyJoinPathFields
1268
 *
1269 1270
 *		This function copies the fields of the JoinPath node.  It is used by
 *		all the copy functions for classes which inherit from JoinPath.
1271 1272 1273
 * ----------------
 */
static void
1274
CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1275
{
1276
	newnode->jointype = from->jointype;
1277 1278
	Node_Copy(from, newnode, outerjoinpath);
	Node_Copy(from, newnode, innerjoinpath);
1279
	Node_Copy(from, newnode, joinrestrictinfo);
1280 1281 1282
}

/* ----------------
1283
 *		_copyNestPath
1284 1285
 * ----------------
 */
1286
static NestPath *
1287
_copyNestPath(NestPath *from)
1288
{
1289
	NestPath   *newnode = makeNode(NestPath);
1290

1291 1292
	/*
	 * copy the node superclass fields
1293 1294
	 */
	CopyPathFields((Path *) from, (Path *) newnode);
1295
	CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1296 1297

	return newnode;
1298 1299 1300
}

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

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

1315 1316
	/*
	 * copy the remainder of the node
1317 1318 1319 1320 1321 1322
	 */
	Node_Copy(from, newnode, path_mergeclauses);
	Node_Copy(from, newnode, outersortkeys);
	Node_Copy(from, newnode, innersortkeys);

	return newnode;
1323 1324 1325
}

/* ----------------
1326
 *		_copyHashPath
1327 1328 1329
 * ----------------
 */
static HashPath *
1330
_copyHashPath(HashPath *from)
1331
{
1332
	HashPath   *newnode = makeNode(HashPath);
1333

1334 1335
	/*
	 * copy the node superclass fields
1336 1337
	 */
	CopyPathFields((Path *) from, (Path *) newnode);
1338
	CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1339

1340 1341
	/*
	 * copy remainder of node
1342 1343 1344 1345
	 */
	Node_Copy(from, newnode, path_hashclauses);

	return newnode;
1346 1347 1348
}

/* ----------------
1349
 *		_copyPathKeyItem
1350 1351
 * ----------------
 */
1352 1353
static PathKeyItem *
_copyPathKeyItem(PathKeyItem *from)
1354
{
1355
	PathKeyItem *newnode = makeNode(PathKeyItem);
1356

1357 1358
	/*
	 * copy remainder of node
1359
	 */
1360 1361
	Node_Copy(from, newnode, key);
	newnode->sortop = from->sortop;
1362 1363

	return newnode;
1364 1365 1366
}

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

1375 1376
	/*
	 * copy remainder of node
1377 1378
	 */
	Node_Copy(from, newnode, clause);
1379
	newnode->ispusheddown = from->ispusheddown;
1380
	Node_Copy(from, newnode, subclauseindices);
1381 1382
	newnode->eval_cost = from->eval_cost;
	newnode->this_selec = from->this_selec;
1383 1384 1385
	newnode->mergejoinoperator = from->mergejoinoperator;
	newnode->left_sortop = from->left_sortop;
	newnode->right_sortop = from->right_sortop;
B
Bruce Momjian 已提交
1386 1387 1388 1389 1390

	/*
	 * Do not copy pathkeys, since they'd not be canonical in a copied
	 * query
	 */
1391 1392
	newnode->left_pathkey = NIL;
	newnode->right_pathkey = NIL;
1393 1394
	newnode->left_mergescansel = from->left_mergescansel;
	newnode->right_mergescansel = from->right_mergescansel;
1395
	newnode->hashjoinoperator = from->hashjoinoperator;
1396 1397
	newnode->left_bucketsize = from->left_bucketsize;
	newnode->right_bucketsize = from->right_bucketsize;
1398 1399

	return newnode;
1400 1401 1402
}

/* ----------------
1403
 *		_copyJoinInfo
1404 1405
 * ----------------
 */
1406
static JoinInfo *
1407
_copyJoinInfo(JoinInfo *from)
1408
{
1409
	JoinInfo   *newnode = makeNode(JoinInfo);
1410

1411 1412
	/*
	 * copy remainder of node
1413
	 */
B
Bruce Momjian 已提交
1414
	newnode->unjoined_relids = listCopy(from->unjoined_relids);
1415
	Node_Copy(from, newnode, jinfo_restrictinfo);
1416 1417

	return newnode;
1418 1419
}

1420
static Iter *
1421
_copyIter(Iter *from)
1422
{
1423
	Iter	   *newnode = makeNode(Iter);
1424 1425 1426

	Node_Copy(from, newnode, iterexpr);
	newnode->itertype = from->itertype;
1427

1428
	return newnode;
1429 1430
}

1431
static Stream *
1432
_copyStream(Stream *from)
1433
{
1434
	Stream	   *newnode = makeNode(Stream);
1435 1436 1437 1438

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

1440 1441 1442 1443 1444 1445
	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 已提交
1446 1447 1448 1449
	newnode->groupup = from->groupup;
	newnode->groupcost = from->groupcost;
	newnode->groupsel = from->groupsel;

1450
	return newnode;
1451 1452
}

1453 1454 1455
/* ****************************************************************
 *					parsenodes.h copy functions
 * ****************************************************************
1456 1457 1458
 */

static TargetEntry *
1459
_copyTargetEntry(TargetEntry *from)
1460
{
1461
	TargetEntry *newnode = makeNode(TargetEntry);
1462

1463 1464 1465 1466
	Node_Copy(from, newnode, resdom);
	Node_Copy(from, newnode, fjoin);
	Node_Copy(from, newnode, expr);
	return newnode;
1467 1468 1469
}

static RangeTblEntry *
1470
_copyRangeTblEntry(RangeTblEntry *from)
1471
{
1472
	RangeTblEntry *newnode = makeNode(RangeTblEntry);
1473

1474
	newnode->rtekind = from->rtekind;
B
Bruce Momjian 已提交
1475
	newnode->relid = from->relid;
1476
	Node_Copy(from, newnode, subquery);
1477 1478 1479 1480 1481
	newnode->jointype = from->jointype;
	newnode->joincoltypes = listCopy(from->joincoltypes);
	newnode->joincoltypmods = listCopy(from->joincoltypmods);
	newnode->joinleftcols = listCopy(from->joinleftcols);
	newnode->joinrightcols = listCopy(from->joinrightcols);
1482 1483
	Node_Copy(from, newnode, alias);
	Node_Copy(from, newnode, eref);
B
Bruce Momjian 已提交
1484 1485
	newnode->inh = from->inh;
	newnode->inFromCl = from->inFromCl;
1486 1487 1488
	newnode->checkForRead = from->checkForRead;
	newnode->checkForWrite = from->checkForWrite;
	newnode->checkAsUser = from->checkAsUser;
1489 1490 1491 1492

	return newnode;
}

1493 1494 1495
static FkConstraint *
_copyFkConstraint(FkConstraint *from)
{
B
Bruce Momjian 已提交
1496
	FkConstraint *newnode = makeNode(FkConstraint);
1497 1498 1499

	if (from->constr_name)
		newnode->constr_name = pstrdup(from->constr_name);
1500
	Node_Copy(from, newnode, pktable);
1501 1502 1503 1504 1505 1506 1507
	Node_Copy(from, newnode, fk_attrs);
	Node_Copy(from, newnode, pk_attrs);
	if (from->match_type)
		newnode->match_type = pstrdup(from->match_type);
	newnode->actions = from->actions;
	newnode->deferrable = from->deferrable;
	newnode->initdeferred = from->initdeferred;
B
Bruce Momjian 已提交
1508

1509 1510 1511
	return newnode;
}

1512
static SortClause *
1513
_copySortClause(SortClause *from)
1514
{
1515
	SortClause *newnode = makeNode(SortClause);
1516

1517 1518
	newnode->tleSortGroupRef = from->tleSortGroupRef;
	newnode->sortop = from->sortop;
1519

1520
	return newnode;
1521 1522
}

1523 1524 1525
static A_Expr *
_copyAExpr(A_Expr *from)
{
B
Bruce Momjian 已提交
1526
	A_Expr	   *newnode = makeNode(A_Expr);
1527 1528

	newnode->oper = from->oper;
1529
	Node_Copy(from, newnode, name);
1530 1531 1532 1533 1534 1535
	Node_Copy(from, newnode, lexpr);
	Node_Copy(from, newnode, rexpr);

	return newnode;
}

1536 1537
static ColumnRef *
_copyColumnRef(ColumnRef *from)
1538
{
1539
	ColumnRef	   *newnode = makeNode(ColumnRef);
1540

1541 1542
	Node_Copy(from, newnode, fields);
	Node_Copy(from, newnode, indirection);
1543

1544
	return newnode;
1545 1546
}

1547 1548
static ParamRef *
_copyParamRef(ParamRef *from)
1549
{
1550
	ParamRef    *newnode = makeNode(ParamRef);
1551 1552

	newnode->number = from->number;
1553
	Node_Copy(from, newnode, fields);
1554 1555 1556 1557 1558
	Node_Copy(from, newnode, indirection);

	return newnode;
}

1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569
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;
}

1570 1571 1572
static Ident *
_copyIdent(Ident *from)
{
B
Bruce Momjian 已提交
1573
	Ident	   *newnode = makeNode(Ident);
1574

1575
	newnode->name = pstrdup(from->name);
1576 1577 1578 1579 1580 1581 1582

	return newnode;
}

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

1585
	Node_Copy(from, newnode, funcname);
1586 1587 1588 1589 1590 1591 1592 1593 1594 1595
	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 已提交
1596
	A_Indices  *newnode = makeNode(A_Indices);
1597 1598 1599 1600 1601 1602 1603

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

	return newnode;
}

1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615
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;
}

1616 1617 1618
static ResTarget *
_copyResTarget(ResTarget *from)
{
B
Bruce Momjian 已提交
1619
	ResTarget  *newnode = makeNode(ResTarget);
1620 1621 1622 1623 1624 1625 1626 1627 1628

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

	return newnode;
}

1629
static TypeName *
1630
_copyTypeName(TypeName *from)
1631
{
1632
	TypeName   *newnode = makeNode(TypeName);
1633

1634 1635
	Node_Copy(from, newnode, names);
	newnode->typeid = from->typeid;
B
Bruce Momjian 已提交
1636
	newnode->timezone = from->timezone;
1637
	newnode->setof = from->setof;
1638
	newnode->pct_type = from->pct_type;
1639
	newnode->typmod = from->typmod;
1640 1641 1642
	Node_Copy(from, newnode, arrayBounds);

	return newnode;
1643 1644
}

1645 1646 1647
static SortGroupBy *
_copySortGroupBy(SortGroupBy *from)
{
B
Bruce Momjian 已提交
1648
	SortGroupBy *newnode = makeNode(SortGroupBy);
1649

1650
	Node_Copy(from, newnode, useOp);
1651 1652 1653 1654 1655
	Node_Copy(from, newnode, node);

	return newnode;
}

1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667
static Alias *
_copyAlias(Alias *from)
{
	Alias	   *newnode = makeNode(Alias);

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

	return newnode;
}

1668 1669 1670 1671 1672
static RangeVar *
_copyRangeVar(RangeVar *from)
{
	RangeVar   *newnode = makeNode(RangeVar);

1673 1674 1675 1676
	if (from->catalogname)
		newnode->catalogname = pstrdup(from->catalogname);
	if (from->schemaname)
		newnode->schemaname = pstrdup(from->schemaname);
1677 1678
	if (from->relname)
		newnode->relname = pstrdup(from->relname);
1679
	newnode->inhOpt = from->inhOpt;
1680 1681
	newnode->istemp = from->istemp;
	Node_Copy(from, newnode, alias);
1682 1683 1684 1685 1686 1687 1688

	return newnode;
}

static RangeSubselect *
_copyRangeSubselect(RangeSubselect *from)
{
B
Bruce Momjian 已提交
1689
	RangeSubselect *newnode = makeNode(RangeSubselect);
1690 1691

	Node_Copy(from, newnode, subquery);
1692
	Node_Copy(from, newnode, alias);
1693 1694 1695 1696

	return newnode;
}

1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707
static TypeCast *
_copyTypeCast(TypeCast *from)
{
	TypeCast   *newnode = makeNode(TypeCast);

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

	return newnode;
}

1708 1709 1710
static IndexElem *
_copyIndexElem(IndexElem *from)
{
B
Bruce Momjian 已提交
1711
	IndexElem  *newnode = makeNode(IndexElem);
1712 1713 1714

	if (from->name)
		newnode->name = pstrdup(from->name);
1715
	Node_Copy(from, newnode, funcname);
1716
	Node_Copy(from, newnode, args);
1717
	Node_Copy(from, newnode, opclass);
1718 1719 1720 1721 1722 1723 1724

	return newnode;
}

static ColumnDef *
_copyColumnDef(ColumnDef *from)
{
B
Bruce Momjian 已提交
1725
	ColumnDef  *newnode = makeNode(ColumnDef);
1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741

	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);

	return newnode;
}

static Constraint *
_copyConstraint(Constraint *from)
{
B
Bruce Momjian 已提交
1742
	Constraint *newnode = makeNode(Constraint);
1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757

	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 已提交
1758
	DefElem    *newnode = makeNode(DefElem);
1759 1760 1761 1762 1763 1764 1765 1766

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

	return newnode;
}

1767
static Query *
1768
_copyQuery(Query *from)
1769
{
1770
	Query	   *newnode = makeNode(Query);
1771

1772
	newnode->commandType = from->commandType;
1773
	Node_Copy(from, newnode, utilityStmt);
1774
	newnode->resultRelation = from->resultRelation;
1775
	Node_Copy(from, newnode, into);
1776
	newnode->isPortal = from->isPortal;
B
Bruce Momjian 已提交
1777
	newnode->isBinary = from->isBinary;
1778 1779
	newnode->hasAggs = from->hasAggs;
	newnode->hasSubLinks = from->hasSubLinks;
1780
	newnode->originalQuery = from->originalQuery;
1781

B
Bruce Momjian 已提交
1782
	Node_Copy(from, newnode, rtable);
1783 1784
	Node_Copy(from, newnode, jointree);

1785
	newnode->rowMarks = listCopy(from->rowMarks);
1786

1787 1788
	Node_Copy(from, newnode, targetList);

1789
	Node_Copy(from, newnode, groupClause);
B
Bruce Momjian 已提交
1790
	Node_Copy(from, newnode, havingQual);
1791 1792
	Node_Copy(from, newnode, distinctClause);
	Node_Copy(from, newnode, sortClause);
1793

B
Bruce Momjian 已提交
1794 1795 1796
	Node_Copy(from, newnode, limitOffset);
	Node_Copy(from, newnode, limitCount);

1797 1798
	Node_Copy(from, newnode, setOperations);

1799 1800
	newnode->resultRelations = listCopy(from->resultRelations);

1801 1802
	/*
	 * We do not copy the planner internal fields: base_rel_list,
1803 1804
	 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. Not
	 * entirely clear if this is right?
1805
	 */
1806

1807
	return newnode;
1808 1809
}

1810 1811 1812 1813
static InsertStmt *
_copyInsertStmt(InsertStmt *from)
{
	InsertStmt *newnode = makeNode(InsertStmt);
B
Bruce Momjian 已提交
1814

1815
	Node_Copy(from, newnode, relation);
1816 1817
	Node_Copy(from, newnode, cols);
	Node_Copy(from, newnode, targetList);
1818
	Node_Copy(from, newnode, selectStmt);
1819 1820 1821 1822 1823 1824 1825 1826

	return newnode;
}

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

1828
	Node_Copy(from, newnode, relation);
1829 1830 1831 1832 1833 1834 1835 1836 1837
	Node_Copy(from, newnode, whereClause);

	return newnode;
}

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

1839
	Node_Copy(from, newnode, relation);
1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850
	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 已提交
1851

1852
	Node_Copy(from, newnode, distinctClause);
1853
	Node_Copy(from, newnode, into);
1854
	Node_Copy(from, newnode, intoColNames);
1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866
	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);
1867 1868 1869 1870
	newnode->op = from->op;
	newnode->all = from->all;
	Node_Copy(from, newnode, larg);
	Node_Copy(from, newnode, rarg);
1871 1872 1873 1874

	return newnode;
}

1875 1876 1877 1878
static SetOperationStmt *
_copySetOperationStmt(SetOperationStmt *from)
{
	SetOperationStmt *newnode = makeNode(SetOperationStmt);
B
Bruce Momjian 已提交
1879

1880 1881 1882 1883 1884 1885 1886 1887 1888
	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;
}

1889 1890 1891 1892
static AlterTableStmt *
_copyAlterTableStmt(AlterTableStmt *from)
{
	AlterTableStmt *newnode = makeNode(AlterTableStmt);
B
Bruce Momjian 已提交
1893

1894
	newnode->subtype = from->subtype;
1895
	Node_Copy(from, newnode, relation);
1896 1897 1898 1899 1900 1901 1902 1903
	if (from->name)
		newnode->name = pstrdup(from->name);
	Node_Copy(from, newnode, def);
	newnode->behavior = from->behavior;

	return newnode;
}

1904 1905
static GrantStmt *
_copyGrantStmt(GrantStmt *from)
1906
{
1907
	GrantStmt  *newnode = makeNode(GrantStmt);
B
Bruce Momjian 已提交
1908

1909
	newnode->is_grant = from->is_grant;
1910 1911
	newnode->objtype = from->objtype;
	Node_Copy(from, newnode, objects);
1912
	newnode->privileges = listCopy(from->privileges);
1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926
	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);
1927 1928 1929 1930

	return newnode;
}

1931 1932 1933 1934 1935
static FuncWithArgs *
_copyFuncWithArgs(FuncWithArgs *from)
{
	FuncWithArgs *newnode = makeNode(FuncWithArgs);

1936
	Node_Copy(from, newnode, funcname);
1937 1938 1939 1940 1941
	Node_Copy(from, newnode, funcargs);

	return newnode;
}

B
Bruce Momjian 已提交
1942 1943 1944 1945 1946 1947 1948 1949 1950
static InsertDefault *
_copyInsertDefault(InsertDefault *from)
{
	InsertDefault *newnode = makeNode(InsertDefault);

	return newnode;
}


1951 1952 1953
static ClosePortalStmt *
_copyClosePortalStmt(ClosePortalStmt *from)
{
1954
	ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1955 1956 1957 1958 1959 1960 1961

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

	return newnode;
}

1962 1963 1964 1965
static ClusterStmt *
_copyClusterStmt(ClusterStmt *from)
{
	ClusterStmt *newnode = makeNode(ClusterStmt);
B
Bruce Momjian 已提交
1966

1967
	Node_Copy(from, newnode, relation);
1968 1969 1970 1971 1972 1973 1974 1975 1976
	if (from->indexname)
		newnode->indexname = pstrdup(from->indexname);

	return newnode;
}

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

1979
	newnode->binary = from->binary;
1980
	Node_Copy(from, newnode, relation);
1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996
	newnode->oids = from->oids;
	newnode->direction = from->direction;
	if (from->filename)
		newnode->filename = pstrdup(from->filename);
	if (from->delimiter)
		newnode->delimiter = pstrdup(from->delimiter);
	if (from->null_print)
		newnode->null_print = pstrdup(from->null_print);

	return newnode;
}

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

1998
	Node_Copy(from, newnode, relation);
1999
	Node_Copy(from, newnode, tableElts);
2000
	Node_Copy(from, newnode, inhRelations);
2001
	Node_Copy(from, newnode, constraints);
2002
	newnode->hasoids = from->hasoids;
2003 2004 2005 2006 2007 2008 2009 2010

	return newnode;
}

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

2012
	newnode->defType = from->defType;
2013
	Node_Copy(from, newnode, defnames);
2014 2015 2016 2017 2018 2019 2020 2021
	Node_Copy(from, newnode, definition);

	return newnode;
}

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

2024
	Node_Copy(from, newnode, objects);
2025
	newnode->removeType = from->removeType;
T
Tom Lane 已提交
2026
	newnode->behavior = from->behavior;
2027 2028 2029 2030

	return newnode;
}

2031 2032 2033
static TruncateStmt *
_copyTruncateStmt(TruncateStmt *from)
{
2034
	TruncateStmt *newnode = makeNode(TruncateStmt);
2035

2036
	Node_Copy(from, newnode, relation);
2037 2038 2039 2040

	return newnode;
}

2041 2042 2043 2044
static CommentStmt *
_copyCommentStmt(CommentStmt *from)
{
	CommentStmt *newnode = makeNode(CommentStmt);
B
Bruce Momjian 已提交
2045

2046
	newnode->objtype = from->objtype;
2047 2048 2049 2050
	Node_Copy(from, newnode, objname);
	Node_Copy(from, newnode, objargs);
	if (from->comment)
		newnode->comment = pstrdup(from->comment);
2051 2052 2053 2054 2055 2056 2057

	return newnode;
}

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

2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070
	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 已提交
2071 2072
	IndexStmt  *newnode = makeNode(IndexStmt);

2073
	newnode->idxname = pstrdup(from->idxname);
2074
	Node_Copy(from, newnode, relation);
2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088
	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;

	return newnode;
}

static ProcedureStmt *
_copyProcedureStmt(ProcedureStmt *from)
{
	ProcedureStmt *newnode = makeNode(ProcedureStmt);
B
Bruce Momjian 已提交
2089

2090
	newnode->replace = from->replace;
2091
	Node_Copy(from, newnode, funcname);
2092
	Node_Copy(from, newnode, argTypes);
2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104
	Node_Copy(from, newnode, returnType);
	Node_Copy(from, newnode, withClause);
	Node_Copy(from, newnode, as);
	newnode->language = pstrdup(from->language);

	return newnode;
}

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

2106
	Node_Copy(from, newnode, aggname);
2107
	Node_Copy(from, newnode, aggtype);
2108 2109 2110 2111 2112 2113 2114 2115

	return newnode;
}

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

2117
	Node_Copy(from, newnode, funcname);
2118 2119 2120 2121 2122 2123 2124 2125 2126
	Node_Copy(from, newnode, args);

	return newnode;
}

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

2128
	Node_Copy(from, newnode, opname);
2129 2130 2131 2132 2133 2134 2135 2136 2137
	Node_Copy(from, newnode, args);

	return newnode;
}

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

2139
	Node_Copy(from, newnode, relation);
2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150
	if (from->column)
		newnode->column = pstrdup(from->column);
	if (from->newname)
		newnode->newname = pstrdup(from->newname);

	return newnode;
}

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

2153
	Node_Copy(from, newnode, relation);
2154 2155 2156 2157 2158 2159 2160 2161 2162
	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;
}

2163 2164 2165
static NotifyStmt *
_copyNotifyStmt(NotifyStmt *from)
{
2166
	NotifyStmt *newnode = makeNode(NotifyStmt);
2167

2168
	Node_Copy(from, newnode, relation);
2169 2170 2171 2172 2173 2174 2175

	return newnode;
}

static ListenStmt *
_copyListenStmt(ListenStmt *from)
{
2176
	ListenStmt *newnode = makeNode(ListenStmt);
2177

2178
	Node_Copy(from, newnode, relation);
2179 2180 2181 2182 2183 2184 2185

	return newnode;
}

static UnlistenStmt *
_copyUnlistenStmt(UnlistenStmt *from)
{
2186
	UnlistenStmt *newnode = makeNode(UnlistenStmt);
2187

2188
	Node_Copy(from, newnode, relation);
2189 2190 2191 2192 2193 2194 2195

	return newnode;
}

static TransactionStmt *
_copyTransactionStmt(TransactionStmt *from)
{
2196
	TransactionStmt *newnode = makeNode(TransactionStmt);
2197 2198 2199 2200 2201 2202

	newnode->command = from->command;

	return newnode;
}

2203 2204 2205 2206 2207
static ViewStmt *
_copyViewStmt(ViewStmt *from)
{
	ViewStmt   *newnode = makeNode(ViewStmt);

2208
	Node_Copy(from, newnode, view);
2209 2210 2211 2212 2213 2214
	Node_Copy(from, newnode, aliases);
	Node_Copy(from, newnode, query);

	return newnode;
}

2215 2216 2217
static LoadStmt *
_copyLoadStmt(LoadStmt *from)
{
2218
	LoadStmt   *newnode = makeNode(LoadStmt);
2219 2220 2221 2222 2223 2224 2225

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

	return newnode;
}

2226 2227 2228 2229 2230
static CreateDomainStmt *
_copyCreateDomainStmt(CreateDomainStmt *from)
{
	CreateDomainStmt *newnode = makeNode(CreateDomainStmt);

2231
	Node_Copy(from, newnode, domainname);
2232 2233 2234 2235 2236 2237
	Node_Copy(from, newnode, typename);
	Node_Copy(from, newnode, constraints);

	return newnode;
}

2238 2239 2240
static CreatedbStmt *
_copyCreatedbStmt(CreatedbStmt *from)
{
B
Bruce Momjian 已提交
2241
	CreatedbStmt *newnode = makeNode(CreatedbStmt);
2242 2243 2244

	if (from->dbname)
		newnode->dbname = pstrdup(from->dbname);
2245 2246
	if (from->dbowner)
		newnode->dbowner = pstrdup(from->dbowner);
2247 2248
	if (from->dbpath)
		newnode->dbpath = pstrdup(from->dbpath);
2249 2250
	if (from->dbtemplate)
		newnode->dbtemplate = pstrdup(from->dbtemplate);
2251 2252 2253 2254 2255
	newnode->encoding = from->encoding;

	return newnode;
}

2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269
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;
}

2270 2271 2272
static DropdbStmt *
_copyDropdbStmt(DropdbStmt *from)
{
B
Bruce Momjian 已提交
2273
	DropdbStmt *newnode = makeNode(DropdbStmt);
2274 2275 2276 2277 2278 2279 2280 2281 2282 2283

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

	return newnode;
}

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

2286
	newnode->vacuum = from->vacuum;
2287
	newnode->full = from->full;
2288
	newnode->analyze = from->analyze;
2289
	newnode->freeze = from->freeze;
2290
	newnode->verbose = from->verbose;
2291
	Node_Copy(from, newnode, relation);
2292
	Node_Copy(from, newnode, va_cols);
2293 2294 2295 2296 2297 2298 2299

	return newnode;
}

static ExplainStmt *
_copyExplainStmt(ExplainStmt *from)
{
B
Bruce Momjian 已提交
2300
	ExplainStmt *newnode = makeNode(ExplainStmt);
2301 2302 2303

	Node_Copy(from, newnode, query);
	newnode->verbose = from->verbose;
2304
	newnode->analyze = from->analyze;
2305 2306 2307 2308 2309 2310 2311

	return newnode;
}

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

2314
	Node_Copy(from, newnode, sequence);
2315 2316 2317 2318 2319
	Node_Copy(from, newnode, options);

	return newnode;
}

2320 2321 2322
static VariableSetStmt *
_copyVariableSetStmt(VariableSetStmt *from)
{
2323
	VariableSetStmt *newnode = makeNode(VariableSetStmt);
2324 2325 2326

	if (from->name)
		newnode->name = pstrdup(from->name);
2327
	Node_Copy(from, newnode, args);
2328 2329 2330 2331

	return newnode;
}

2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342
static VariableShowStmt *
_copyVariableShowStmt(VariableShowStmt *from)
{
	VariableShowStmt *newnode = makeNode(VariableShowStmt);

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

	return newnode;
}

2343 2344 2345
static VariableResetStmt *
_copyVariableResetStmt(VariableResetStmt *from)
{
2346
	VariableResetStmt *newnode = makeNode(VariableResetStmt);
2347 2348 2349 2350 2351 2352 2353

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

	return newnode;
}

2354 2355 2356 2357 2358 2359 2360
static CreateTrigStmt *
_copyCreateTrigStmt(CreateTrigStmt *from)
{
	CreateTrigStmt *newnode = makeNode(CreateTrigStmt);

	if (from->trigname)
		newnode->trigname = pstrdup(from->trigname);
2361
	Node_Copy(from, newnode, relation);
2362
	Node_Copy(from, newnode, funcname);
2363 2364 2365 2366 2367 2368 2369 2370
	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 已提交
2371

2372 2373 2374 2375 2376 2377
	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;
2378
	Node_Copy(from, newnode, constrrel);
2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389

	return newnode;
}

static DropTrigStmt *
_copyDropTrigStmt(DropTrigStmt *from)
{
	DropTrigStmt *newnode = makeNode(DropTrigStmt);

	if (from->trigname)
		newnode->trigname = pstrdup(from->trigname);
2390
	Node_Copy(from, newnode, relation);
2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401

	return newnode;
}

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

	if (from->plname)
		newnode->plname = pstrdup(from->plname);
2402
	Node_Copy(from, newnode, plhandler);
2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427
	if (from->plcompiler)
		newnode->plcompiler = pstrdup(from->plcompiler);
	newnode->pltrusted = from->pltrusted;

	return newnode;
}

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

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

	return newnode;
}

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

	if (from->user)
		newnode->user = pstrdup(from->user);
2428
	Node_Copy(from, newnode, options);
2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439

	return newnode;
}

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

	if (from->user)
		newnode->user = pstrdup(from->user);
2440
	Node_Copy(from, newnode, options);
2441 2442 2443 2444

	return newnode;
}

2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458
static AlterUserSetStmt *
_copyAlterUserSetStmt(AlterUserSetStmt *from)
{
	AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);

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

	return newnode;
}

2459 2460 2461 2462 2463 2464 2465 2466 2467 2468
static DropUserStmt *
_copyDropUserStmt(DropUserStmt *from)
{
	DropUserStmt *newnode = makeNode(DropUserStmt);

	Node_Copy(from, newnode, users);

	return newnode;
}

2469 2470 2471
static LockStmt *
_copyLockStmt(LockStmt *from)
{
2472
	LockStmt   *newnode = makeNode(LockStmt);
2473

2474
	Node_Copy(from, newnode, relations);
2475

2476 2477 2478 2479
	newnode->mode = from->mode;

	return newnode;
}
2480

2481 2482 2483
static ConstraintsSetStmt *
_copyConstraintsSetStmt(ConstraintsSetStmt *from)
{
B
Bruce Momjian 已提交
2484
	ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2485 2486 2487 2488 2489 2490 2491 2492 2493 2494

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

	return newnode;
}

static CreateGroupStmt *
_copyCreateGroupStmt(CreateGroupStmt *from)
{
B
Bruce Momjian 已提交
2495
	CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2496 2497 2498

	if (from->name)
		newnode->name = pstrdup(from->name);
2499
	Node_Copy(from, newnode, options);
2500 2501 2502 2503 2504 2505 2506

	return newnode;
}

static AlterGroupStmt *
_copyAlterGroupStmt(AlterGroupStmt *from)
{
B
Bruce Momjian 已提交
2507
	AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519

	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 已提交
2520
	DropGroupStmt *newnode = makeNode(DropGroupStmt);
2521 2522 2523 2524 2525 2526 2527 2528 2529 2530

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

	return newnode;
}

static ReindexStmt *
_copyReindexStmt(ReindexStmt *from)
{
B
Bruce Momjian 已提交
2531
	ReindexStmt *newnode = makeNode(ReindexStmt);
2532 2533

	newnode->reindexType = from->reindexType;
2534
	Node_Copy(from, newnode, relation);
2535 2536 2537 2538 2539 2540 2541 2542
	if (from->name)
		newnode->name = pstrdup(from->name);
	newnode->force = from->force;
	newnode->all = from->all;

	return newnode;
}

2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555
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;
}

2556 2557

/* ****************************************************************
2558
 *					pg_list.h copy functions
2559 2560 2561
 * ****************************************************************
 */

2562
static Value *
2563
_copyValue(Value *from)
2564
{
2565
	Value	   *newnode = makeNode(Value);
2566 2567 2568 2569

	newnode->type = from->type;
	switch (from->type)
	{
2570 2571 2572 2573
		case T_Integer:
			newnode->val.ival = from->val.ival;
			break;
		case T_Float:
2574
		case T_String:
2575
		case T_BitString:
2576
			newnode->val.str = pstrdup(from->val.str);
2577 2578 2579
			break;
		default:
			break;
2580 2581
	}
	return newnode;
2582 2583 2584
}

/* ----------------
2585 2586
 *		copyObject returns a copy of the node or list. If it is a list, it
 *		recursively copies its items.
2587 2588
 * ----------------
 */
2589
void *
2590 2591
copyObject(void *from)
{
2592
	void	   *retval;
2593

2594 2595
	if (from == NULL)
		return NULL;
2596

2597
	switch (nodeTag(from))
2598
	{
2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619
			/*
			 * 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;
2620 2621 2622
		case T_TidScan:
			retval = _copyTidScan(from);
			break;
2623 2624 2625
		case T_SubqueryScan:
			retval = _copySubqueryScan(from);
			break;
2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643
		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 已提交
2644 2645 2646
		case T_Group:
			retval = _copyGroup(from);
			break;
2647 2648 2649 2650 2651 2652
		case T_Agg:
			retval = _copyAgg(from);
			break;
		case T_Unique:
			retval = _copyUnique(from);
			break;
2653 2654 2655
		case T_SetOp:
			retval = _copySetOp(from);
			break;
2656 2657 2658
		case T_Limit:
			retval = _copyLimit(from);
			break;
2659 2660 2661
		case T_Hash:
			retval = _copyHash(from);
			break;
V
Vadim B. Mikheev 已提交
2662 2663 2664
		case T_SubPlan:
			retval = _copySubPlan(from);
			break;
2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689

			/*
			 * 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;
2690 2691 2692 2693 2694 2695
		case T_Aggref:
			retval = _copyAggref(from);
			break;
		case T_SubLink:
			retval = _copySubLink(from);
			break;
2696 2697 2698 2699 2700 2701
		case T_Func:
			retval = _copyFunc(from);
			break;
		case T_ArrayRef:
			retval = _copyArrayRef(from);
			break;
2702 2703
		case T_Iter:
			retval = _copyIter(from);
2704
			break;
2705 2706 2707
		case T_FieldSelect:
			retval = _copyFieldSelect(from);
			break;
2708 2709 2710
		case T_RelabelType:
			retval = _copyRelabelType(from);
			break;
2711 2712 2713
		case T_RangeTblRef:
			retval = _copyRangeTblRef(from);
			break;
2714 2715 2716
		case T_FromExpr:
			retval = _copyFromExpr(from);
			break;
2717 2718 2719
		case T_JoinExpr:
			retval = _copyJoinExpr(from);
			break;
2720 2721 2722 2723

			/*
			 * RELATION NODES
			 */
B
Bruce Momjian 已提交
2724
		case T_RelOptInfo:
B
Bruce Momjian 已提交
2725
			retval = _copyRelOptInfo(from);
2726 2727 2728 2729 2730 2731 2732
			break;
		case T_Path:
			retval = _copyPath(from);
			break;
		case T_IndexPath:
			retval = _copyIndexPath(from);
			break;
2733 2734 2735
		case T_TidPath:
			retval = _copyTidPath(from);
			break;
2736 2737 2738
		case T_AppendPath:
			retval = _copyAppendPath(from);
			break;
2739 2740
		case T_NestPath:
			retval = _copyNestPath(from);
2741 2742 2743 2744 2745 2746 2747
			break;
		case T_MergePath:
			retval = _copyMergePath(from);
			break;
		case T_HashPath:
			retval = _copyHashPath(from);
			break;
2748 2749
		case T_PathKeyItem:
			retval = _copyPathKeyItem(from);
2750
			break;
2751 2752
		case T_RestrictInfo:
			retval = _copyRestrictInfo(from);
2753
			break;
2754 2755
		case T_JoinInfo:
			retval = _copyJoinInfo(from);
2756 2757 2758 2759
			break;
		case T_Stream:
			retval = _copyStream(from);
			break;
2760 2761 2762
		case T_IndexOptInfo:
			retval = _copyIndexOptInfo(from);
			break;
2763 2764

			/*
2765
			 * VALUE NODES
2766
			 */
2767 2768 2769
		case T_Integer:
		case T_Float:
		case T_String:
2770
		case T_BitString:
2771
			retval = _copyValue(from);
2772
			break;
2773 2774 2775 2776 2777 2778 2779 2780
		case T_List:
			{
				List	   *list = from,
						   *l,
						   *nl;

				/* rather ugly coding for speed... */
				/* Note the input list cannot be NIL if we got here. */
2781
				nl = makeList1(copyObject(lfirst(list)));
2782 2783 2784 2785
				retval = nl;

				foreach(l, lnext(list))
				{
2786
					lnext(nl) = makeList1(copyObject(lfirst(l)));
2787 2788 2789
					nl = lnext(nl);
				}
			}
2790
			break;
2791 2792 2793 2794

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

2964 2965 2966
		case T_A_Expr:
			retval = _copyAExpr(from);
			break;
2967 2968 2969 2970 2971
		case T_ColumnRef:
			retval = _copyColumnRef(from);
			break;
		case T_ParamRef:
			retval = _copyParamRef(from);
2972
			break;
2973 2974 2975
		case T_A_Const:
			retval = _copyAConst(from);
			break;
2976 2977 2978 2979 2980 2981 2982 2983 2984
		case T_Ident:
			retval = _copyIdent(from);
			break;
		case T_FuncCall:
			retval = _copyFuncCall(from);
			break;
		case T_A_Indices:
			retval = _copyAIndices(from);
			break;
2985 2986 2987
		case T_ExprFieldSelect:
			retval = _copyExprFieldSelect(from);
			break;
2988 2989 2990
		case T_ResTarget:
			retval = _copyResTarget(from);
			break;
2991 2992 2993
		case T_TypeCast:
			retval = _copyTypeCast(from);
			break;
2994 2995 2996
		case T_SortGroupBy:
			retval = _copySortGroupBy(from);
			break;
2997 2998 2999
		case T_Alias:
			retval = _copyAlias(from);
			break;
3000 3001 3002
		case T_RangeVar:
			retval = _copyRangeVar(from);
			break;
3003 3004 3005
		case T_RangeSubselect:
			retval = _copyRangeSubselect(from);
			break;
3006 3007 3008
		case T_TypeName:
			retval = _copyTypeName(from);
			break;
3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020
		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;
3021 3022 3023 3024 3025
		case T_TargetEntry:
			retval = _copyTargetEntry(from);
			break;
		case T_RangeTblEntry:
			retval = _copyRangeTblEntry(from);
3026
			break;
3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038
		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;
3039 3040 3041 3042 3043 3044
		case T_NullTest:
			retval = _copyNullTest(from);
			break;
		case T_BooleanTest:
			retval = _copyBooleanTest(from);
			break;
3045 3046 3047
		case T_FkConstraint:
			retval = _copyFkConstraint(from);
			break;
3048 3049 3050
		case T_PrivGrantee:
			retval = _copyPrivGrantee(from);
			break;
3051 3052 3053
		case T_FuncWithArgs:
			retval = _copyFuncWithArgs(from);
			break;
B
Bruce Momjian 已提交
3054 3055 3056
		case T_InsertDefault:
			retval = _copyInsertDefault(from);
			break;
3057

3058
		default:
3059 3060 3061
			elog(ERROR, "copyObject: don't know how to copy node type %d",
				 nodeTag(from));
			retval = from;		/* keep compiler quiet */
3062
			break;
3063
	}
3064
	return retval;
3065
}