copyfuncs.c 34.6 KB
Newer Older
1
/*-------------------------------------------------------------------------
2
 *
3
 * copyfuncs.c
4
 *	  Copy functions for Postgres tree nodes.
5
 *
Bruce Momjian's avatar
Add:  
Bruce Momjian committed
6 7
 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
 * Portions Copyright (c) 1994, Regents of the University of California
8 9 10
 *
 *
 * IDENTIFICATION
11
 *	  $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.104 2000/02/07 04:40:56 tgl Exp $
12 13 14 15 16 17
 *
 *-------------------------------------------------------------------------
 */

#include "postgres.h"

18
#include "optimizer/planmain.h"
19
#include "optimizer/subselect.h"
20 21 22 23 24 25 26 27 28


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

29 30

/*
31
 * listCopy
32 33 34 35 36 37 38 39 40
 *	  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!
41
 */
42
List *
43
listCopy(List *list)
44
{
45 46 47 48 49 50 51
	List	   *newlist,
			   *l,
			   *nl;

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

53 54 55
	newlist = nl = lcons(lfirst(list), NIL);

	foreach(l, lnext(list))
56
	{
57 58
		lnext(nl) = lcons(lfirst(l), NIL);
		nl = lnext(nl);
59
	}
60
	return newlist;
61
}
62

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

/* ----------------
69
 *		CopyPlanFields
70
 *
71 72
 *		This function copies the fields of the Plan node.  It is used by
 *		all the copy functions for classes which inherit from Plan.
73 74 75
 * ----------------
 */
static void
76
CopyPlanFields(Plan *from, Plan *newnode)
77
{
78
	newnode->cost = from->cost;
79
	newnode->plan_rows = from->plan_rows;
80
	newnode->plan_width = from->plan_width;
81
	/* state is NOT copied */
82 83 84 85
	newnode->targetlist = copyObject(from->targetlist);
	newnode->qual = copyObject(from->qual);
	newnode->lefttree = copyObject(from->lefttree);
	newnode->righttree = copyObject(from->righttree);
86 87 88
	newnode->extParam = listCopy(from->extParam);
	newnode->locParam = listCopy(from->locParam);
	newnode->chgParam = listCopy(from->chgParam);
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
89
	Node_Copy(from, newnode, initPlan);
90 91 92
	if (from->subPlan != NIL)
		newnode->subPlan = nconc(SS_pull_subplan((Node *) newnode->targetlist),
								 SS_pull_subplan((Node *) newnode->qual));
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
93
	else
94
		newnode->subPlan = NIL;
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
95
	newnode->nParamExec = from->nParamExec;
96 97 98
}

/* ----------------
99
 *		_copyPlan
100 101
 * ----------------
 */
102
static Plan *
103
_copyPlan(Plan *from)
104
{
105
	Plan	   *newnode = makeNode(Plan);
106 107 108 109 110 111 112 113

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

	return newnode;
114 115 116 117
}


/* ----------------
118
 *		_copyResult
119 120
 * ----------------
 */
121
static Result *
122
_copyResult(Result *from)
123
{
124
	Result	   *newnode = makeNode(Result);
125 126 127 128 129 130 131 132 133 134 135 136 137

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

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	Node_Copy(from, newnode, resconstantqual);

Bruce Momjian's avatar
Bruce Momjian committed
138 139 140
	/*
	 * We must add subplans in resconstantqual to the new plan's subPlan
	 * list
141
	 */
142 143 144
	if (from->plan.subPlan != NIL)
		newnode->plan.subPlan = nconc(newnode->plan.subPlan,
									  SS_pull_subplan(newnode->resconstantqual));
145

146
	return newnode;
147 148 149
}

/* ----------------
150
 *		_copyAppend
151 152
 * ----------------
 */
153
static Append *
Bruce Momjian's avatar
Bruce Momjian committed
154
_copyAppend(Append *from)
155
{
156
	Append	   *newnode = makeNode(Append);
157 158 159 160 161 162 163 164 165 166 167

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

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
168 169 170 171
	Node_Copy(from, newnode, appendplans);
	Node_Copy(from, newnode, unionrtables);
	newnode->inheritrelid = from->inheritrelid;
	Node_Copy(from, newnode, inheritrtable);
172 173

	return newnode;
174 175 176 177
}


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

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

	/* ----------------
	 *	copy node superclass fields
	 * ----------------
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
Bruce Momjian's avatar
Bruce Momjian committed
205
	CopyScanFields((Scan *) from, (Scan *) newnode);
206 207

	return newnode;
208 209 210
}

/* ----------------
211
 *		_copySeqScan
212 213 214
 * ----------------
 */
static SeqScan *
215
_copySeqScan(SeqScan *from)
216
{
217
	SeqScan    *newnode = makeNode(SeqScan);
218 219 220 221 222 223 224 225 226

	/* ----------------
	 *	copy node superclass fields
	 * ----------------
	 */
	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 240 241 242 243 244 245 246 247 248 249 250

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

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	newnode->indxid = listCopy(from->indxid);
	Node_Copy(from, newnode, indxqual);
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
251
	Node_Copy(from, newnode, indxqualorig);
252
	newnode->indxorderdir = from->indxorderdir;
253 254

	return newnode;
255 256
}

257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
/* ----------------
 *              _copyTidScan
 * ----------------
 */
static TidScan *
_copyTidScan(TidScan *from)
{
	TidScan	*newnode = makeNode(TidScan);

	/* ----------------
 	 *	copy node superclass fields
	 * ----------------
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
	CopyScanFields((Scan *) from, (Scan *) newnode);
	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	newnode->needRescan = from->needRescan;
	Node_Copy(from, newnode, tideval);

	return newnode;
}

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


/* ----------------
299
 *		_copyJoin
300 301
 * ----------------
 */
302
static Join *
303
_copyJoin(Join *from)
304
{
305
	Join	   *newnode = makeNode(Join);
306 307 308 309 310 311 312 313 314

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

	return newnode;
315 316 317 318
}


/* ----------------
319
 *		_copyNestLoop
320 321 322
 * ----------------
 */
static NestLoop *
323
_copyNestLoop(NestLoop *from)
324
{
325
	NestLoop   *newnode = makeNode(NestLoop);
326 327 328 329 330 331 332 333 334

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

	return newnode;
335 336 337 338
}


/* ----------------
339
 *		_copyMergeJoin
340 341 342
 * ----------------
 */
static MergeJoin *
343
_copyMergeJoin(MergeJoin *from)
344
{
345
	MergeJoin  *newnode = makeNode(MergeJoin);
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360

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

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	Node_Copy(from, newnode, mergeclauses);

	return newnode;
361 362 363
}

/* ----------------
364
 *		_copyHashJoin
365 366 367
 * ----------------
 */
static HashJoin *
368
_copyHashJoin(HashJoin *from)
369
{
370
	HashJoin   *newnode = makeNode(HashJoin);
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387

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

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	Node_Copy(from, newnode, hashclauses);

	newnode->hashjoinop = from->hashjoinop;

	return newnode;
388 389 390 391
}


/* ----------------
392
 *		CopyNonameFields
393
 *
394 395
 *		This function copies the fields of the Noname node.  It is used by
 *		all the copy functions for classes which inherit from Noname.
396 397 398
 * ----------------
 */
static void
399
CopyNonameFields(Noname *from, Noname *newnode)
400
{
401
	newnode->nonameid = from->nonameid;
402 403
	newnode->keycount = from->keycount;
	return;
404 405 406 407
}


/* ----------------
408
 *		_copyNoname
409 410
 * ----------------
 */
411
static Noname *
412
_copyNoname(Noname *from)
413
{
414
	Noname	   *newnode = makeNode(Noname);
415 416 417 418 419 420

	/* ----------------
	 *	copy node superclass fields
	 * ----------------
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
421
	CopyNonameFields(from, newnode);
422 423

	return newnode;
424 425 426
}

/* ----------------
427
 *		_copyMaterial
428 429 430
 * ----------------
 */
static Material *
431
_copyMaterial(Material *from)
432
{
433
	Material   *newnode = makeNode(Material);
434 435 436 437 438 439

	/* ----------------
	 *	copy node superclass fields
	 * ----------------
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
440
	CopyNonameFields((Noname *) from, (Noname *) newnode);
441 442

	return newnode;
443 444 445 446
}


/* ----------------
447
 *		_copySort
448 449
 * ----------------
 */
450
static Sort *
451
_copySort(Sort *from)
452
{
453
	Sort	   *newnode = makeNode(Sort);
454 455 456 457 458 459

	/* ----------------
	 *	copy node superclass fields
	 * ----------------
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
460
	CopyNonameFields((Noname *) from, (Noname *) newnode);
461 462

	return newnode;
463 464
}

Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
465 466 467 468 469 470 471 472 473

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

Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
475
	CopyPlanFields((Plan *) from, (Plan *) newnode);
Bruce Momjian's avatar
Bruce Momjian committed
476

Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
477 478
	newnode->tuplePerGroup = from->tuplePerGroup;
	newnode->numCols = from->numCols;
479 480
	newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));
	memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
481 482 483 484

	return newnode;
}

485
/* ---------------
486
 *	_copyAgg
487 488
 * --------------
 */
489
static Agg *
Bruce Momjian's avatar
Bruce Momjian committed
490
_copyAgg(Agg *from)
491
{
492
	Agg		   *newnode = makeNode(Agg);
493 494 495 496

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

	return newnode;
497 498
}

499 500 501 502 503 504 505
/* ---------------
 *	_copyGroupClause
 * --------------
 */
static GroupClause *
_copyGroupClause(GroupClause *from)
{
506
	GroupClause *newnode = makeNode(GroupClause);
507

508 509
	newnode->tleSortGroupRef = from->tleSortGroupRef;
	newnode->sortop = from->sortop;
510

511
	return newnode;
512 513
}

514 515

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

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

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

	return newnode;
540 541 542 543
}


/* ----------------
544
 *		_copyHash
545 546
 * ----------------
 */
547
static Hash *
548
_copyHash(Hash *from)
549
{
550
	Hash	   *newnode = makeNode(Hash);
551 552 553 554 555 556 557 558 559 560 561 562 563 564

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

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	Node_Copy(from, newnode, hashkey);

	return newnode;
565 566
}

Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
567 568 569
static SubPlan *
_copySubPlan(SubPlan *from)
{
570 571
	SubPlan    *newnode = makeNode(SubPlan);

Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
572 573 574
	Node_Copy(from, newnode, plan);
	newnode->plan_id = from->plan_id;
	Node_Copy(from, newnode, rtable);
575 576
	newnode->setParam = listCopy(from->setParam);
	newnode->parParam = listCopy(from->parParam);
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
577 578
	Node_Copy(from, newnode, sublink);

579 580 581 582
	/* do not copy execution state */
	newnode->shutdown = false;
	newnode->curTuple = NULL;

Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
583 584 585
	return newnode;
}

586
/* ****************************************************************
587
 *					   primnodes.h copy functions
588 589 590 591
 * ****************************************************************
 */

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

	newnode->resno = from->resno;
	newnode->restype = from->restype;
602
	newnode->restypmod = from->restypmod;
603
	if (from->resname != NULL)
Bruce Momjian's avatar
Bruce Momjian committed
604
		newnode->resname = pstrdup(from->resname);
605
	newnode->ressortgroupref = from->ressortgroupref;
606 607 608 609 610
	newnode->reskey = from->reskey;
	newnode->reskeyop = from->reskeyop;
	newnode->resjunk = from->resjunk;

	return newnode;
611 612
}

613
static Fjoin *
614
_copyFjoin(Fjoin *from)
615
{
616
	Fjoin	   *newnode = makeNode(Fjoin);
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633

	/* ----------------
	 *	copy node superclass fields
	 * ----------------
	 */

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

Bruce Momjian's avatar
Bruce Momjian committed
634 635
	newnode->fj_alwaysDone = (BoolPtr)
		palloc((from->fj_nNodes) * sizeof(bool));
636 637 638 639 640 641
	memmove(from->fj_alwaysDone,
			newnode->fj_alwaysDone,
			(from->fj_nNodes) * sizeof(bool));


	return newnode;
642 643 644
}

/* ----------------
645
 *		_copyExpr
646 647
 * ----------------
 */
648
static Expr *
649
_copyExpr(Expr *from)
650
{
651
	Expr	   *newnode = makeNode(Expr);
652 653 654 655 656 657 658 659 660 661 662 663

	/* ----------------
	 *	copy node superclass fields
	 * ----------------
	 */
	newnode->typeOid = from->typeOid;
	newnode->opType = from->opType;

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

	return newnode;
664 665 666
}

/* ----------------
667
 *		_copyVar
668 669
 * ----------------
 */
670
static Var *
671
_copyVar(Var *from)
672
{
673
	Var		   *newnode = makeNode(Var);
674 675 676 677 678 679 680 681

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	newnode->varno = from->varno;
	newnode->varattno = from->varattno;
	newnode->vartype = from->vartype;
682
	newnode->vartypmod = from->vartypmod;
683
	newnode->varlevelsup = from->varlevelsup;
684 685 686 687 688

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

	return newnode;
689 690 691
}

/* ----------------
692
 *		_copyOper
693 694
 * ----------------
 */
695
static Oper *
696
_copyOper(Oper *from)
697
{
698
	Oper	   *newnode = makeNode(Oper);
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	newnode->opno = from->opno;
	newnode->opid = from->opid;
	newnode->opresulttype = from->opresulttype;
	newnode->opsize = from->opsize;

	/*
	 * NOTE: shall we copy the cache structure or just the pointer ?
	 * Alternatively we can set 'op_fcache' to NULL, in which case the
	 * executor will initialize it when it needs it...
	 */
	newnode->op_fcache = from->op_fcache;

	return newnode;
717 718 719
}

/* ----------------
720
 *		_copyConst
721 722
 * ----------------
 */
723
static Const *
724
_copyConst(Const *from)
725
{
726
	Const	   *newnode = makeNode(Const);
727

728
	/* ----------------
729
	 *	copy remainder of node
730 731
	 * ----------------
	 */
732 733 734
	newnode->consttype = from->consttype;
	newnode->constlen = from->constlen;

735
	if (from->constbyval || from->constisnull)
736
	{
737
		/* ----------------
738 739
		 *	passed by value so just copy the datum.
		 *	Also, don't try to copy struct when value is null!
740 741
		 * ----------------
		 */
742
		newnode->constvalue = from->constvalue;
743
	}
744
	else
745
	{
746
		/* ----------------
747
		 *	not passed by value. datum contains a pointer.
748 749
		 * ----------------
		 */
750 751 752 753 754 755 756 757
		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);
758
	}
759

760 761
	newnode->constisnull = from->constisnull;
	newnode->constbyval = from->constbyval;
Bruce Momjian's avatar
Bruce Momjian committed
762 763
	newnode->constisset = from->constisset;
	newnode->constiscast = from->constiscast;
764 765

	return newnode;
766 767 768
}

/* ----------------
769
 *		_copyParam
770 771
 * ----------------
 */
772
static Param *
773
_copyParam(Param *from)
774
{
775
	Param	   *newnode = makeNode(Param);
776 777 778 779 780 781 782 783 784 785 786 787 788 789

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	newnode->paramkind = from->paramkind;
	newnode->paramid = from->paramid;

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

	return newnode;
790 791 792
}

/* ----------------
793
 *		_copyFunc
794 795
 * ----------------
 */
796
static Func *
797
_copyFunc(Func *from)
798
{
799
	Func	   *newnode = makeNode(Func);
800 801 802 803 804 805 806 807 808 809 810 811 812 813

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	newnode->funcid = from->funcid;
	newnode->functype = from->functype;
	newnode->funcisindex = from->funcisindex;
	newnode->funcsize = from->funcsize;
	newnode->func_fcache = from->func_fcache;
	Node_Copy(from, newnode, func_tlist);
	Node_Copy(from, newnode, func_planlist);

	return newnode;
814 815 816
}

/* ----------------
Bruce Momjian's avatar
Bruce Momjian committed
817
 *		_copyAggref
818 819
 * ----------------
 */
Bruce Momjian's avatar
Bruce Momjian committed
820
static Aggref *
821
_copyAggref(Aggref *from)
822
{
Bruce Momjian's avatar
Bruce Momjian committed
823
	Aggref	   *newnode = makeNode(Aggref);
824 825 826 827 828 829 830 831 832

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	newnode->aggname = pstrdup(from->aggname);
	newnode->basetype = from->basetype;
	newnode->aggtype = from->aggtype;
	Node_Copy(from, newnode, target);
Bruce Momjian's avatar
Bruce Momjian committed
833
	newnode->usenulls = from->usenulls;
834 835
	newnode->aggstar = from->aggstar;
	newnode->aggdistinct = from->aggdistinct;
836
	newnode->aggno = from->aggno; /* probably not needed */
837 838

	return newnode;
839 840
}

841 842 843 844 845 846 847
/* ----------------
 *		_copySubLink
 * ----------------
 */
static SubLink *
_copySubLink(SubLink *from)
{
848
	SubLink    *newnode = makeNode(SubLink);
849 850 851 852 853 854 855 856

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	newnode->subLinkType = from->subLinkType;
	newnode->useor = from->useor;
	Node_Copy(from, newnode, lefthand);
Bruce Momjian's avatar
Bruce Momjian committed
857
	Node_Copy(from, newnode, oper);
858 859 860 861 862
	Node_Copy(from, newnode, subselect);

	return newnode;
}

863 864 865 866 867
/* ----------------
 *		_copyCaseExpr
 * ----------------
 */
static CaseExpr *
868
_copyCaseExpr(CaseExpr *from)
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889
{
	CaseExpr   *newnode = makeNode(CaseExpr);

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	newnode->casetype = from->casetype;

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

	return newnode;
}

/* ----------------
 *		_copyCaseWhen
 * ----------------
 */
static CaseWhen *
890
_copyCaseWhen(CaseWhen *from)
891 892 893 894 895 896 897 898 899 900 901 902 903
{
	CaseWhen   *newnode = makeNode(CaseWhen);

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	Node_Copy(from, newnode, expr);
	Node_Copy(from, newnode, result);

	return newnode;
}

904
static Array *
Bruce Momjian's avatar
Bruce Momjian committed
905
_copyArray(Array *from)
906
{
907
	Array	   *newnode = makeNode(Array);
908 909 910 911 912 913 914 915 916 917 918 919 920 921

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	newnode->arrayelemtype = from->arrayelemtype;
	newnode->arrayelemlength = from->arrayelemlength;
	newnode->arrayelembyval = from->arrayelembyval;
	newnode->arrayndim = from->arrayndim;
	newnode->arraylow = from->arraylow;
	newnode->arrayhigh = from->arrayhigh;
	newnode->arraylen = from->arraylen;

	return newnode;
922 923 924
}

static ArrayRef *
Bruce Momjian's avatar
Bruce Momjian committed
925
_copyArrayRef(ArrayRef *from)
926
{
927
	ArrayRef   *newnode = makeNode(ArrayRef);
928 929 930 931 932 933 934

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	newnode->refattrlength = from->refattrlength;
	newnode->refelemlength = from->refelemlength;
Bruce Momjian's avatar
Bruce Momjian committed
935
	newnode->refelemtype = from->refelemtype;
936 937 938 939 940 941 942 943
	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;
944 945 946
}

/* ****************************************************************
947
 *						relation.h copy functions
948 949 950 951
 * ****************************************************************
 */

/* ----------------
952
 *		_copyRelOptInfo
953 954 955
 * ----------------
 */
/*
Bruce Momjian's avatar
Bruce Momjian committed
956 957 958
 *	when you change this, also make sure to fix up xfunc_copyRelOptInfo in
 *	planner/path/xfunc.c accordingly!!!
 *		-- JMH, 8/2/93
959
 */
Bruce Momjian's avatar
Bruce Momjian committed
960
static RelOptInfo *
961
_copyRelOptInfo(RelOptInfo *from)
962
{
963
	RelOptInfo *newnode = makeNode(RelOptInfo);
964 965 966

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

967
	newnode->rows = from->rows;
968
	newnode->width = from->width;
969

970 971
	Node_Copy(from, newnode, targetlist);
	Node_Copy(from, newnode, pathlist);
972
	/* XXX cheapestpath should point to a member of pathlist? */
973 974 975
	Node_Copy(from, newnode, cheapestpath);
	newnode->pruneable = from->pruneable;

976 977 978 979
	newnode->indexed = from->indexed;
	newnode->pages = from->pages;
	newnode->tuples = from->tuples;

980
	Node_Copy(from, newnode, baserestrictinfo);
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001
	Node_Copy(from, newnode, joininfo);
	Node_Copy(from, newnode, innerjoin);

	return newnode;
}

/* ----------------
 *		_copyIndexOptInfo
 * ----------------
 */
static IndexOptInfo *
_copyIndexOptInfo(IndexOptInfo *from)
{
	IndexOptInfo *newnode = makeNode(IndexOptInfo);
	int			i,
				len;

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

1002 1003 1004 1005 1006 1007 1008 1009
	if (from->classlist)
	{
		for (len = 0; from->classlist[len] != 0; len++)
			;
		newnode->classlist = (Oid *) palloc(sizeof(Oid) * (len + 1));
		for (i = 0; i < len; i++)
			newnode->classlist[i] = from->classlist[i];
		newnode->classlist[len] = 0;
1010
	}
1011 1012 1013 1014 1015 1016 1017 1018 1019

	if (from->indexkeys)
	{
		for (len = 0; from->indexkeys[len] != 0; len++)
			;
		newnode->indexkeys = (int *) palloc(sizeof(int) * (len + 1));
		for (i = 0; i < len; i++)
			newnode->indexkeys[i] = from->indexkeys[i];
		newnode->indexkeys[len] = 0;
1020
	}
1021 1022 1023 1024 1025 1026 1027 1028 1029

	if (from->ordering)
	{
		for (len = 0; from->ordering[len] != 0; len++)
			;
		newnode->ordering = (Oid *) palloc(sizeof(Oid) * (len + 1));
		for (i = 0; i < len; i++)
			newnode->ordering[i] = from->ordering[i];
		newnode->ordering[len] = 0;
1030
	}
1031

1032
	newnode->relam = from->relam;
1033
	newnode->amcostestimate = from->amcostestimate;
1034 1035 1036
	newnode->indproc = from->indproc;
	Node_Copy(from, newnode, indpred);

1037
	return newnode;
1038 1039 1040
}

/* ----------------
1041
 *		CopyPathFields
1042
 *
1043 1044
 *		This function copies the fields of the Path node.  It is used by
 *		all the copy functions for classes which inherit from Path.
1045 1046 1047
 * ----------------
 */
static void
1048
CopyPathFields(Path *from, Path *newnode)
1049
{
1050 1051 1052 1053 1054 1055 1056 1057 1058
	/*
	 * 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;

	newnode->path_cost = from->path_cost;

1059
	newnode->pathtype = from->pathtype;
1060

1061
	Node_Copy(from, newnode, pathkeys);
1062 1063 1064
}

/* ----------------
1065
 *		_copyPath
1066 1067
 * ----------------
 */
1068
static Path *
1069
_copyPath(Path *from)
1070
{
1071
	Path	   *newnode = makeNode(Path);
1072 1073 1074 1075

	CopyPathFields(from, newnode);

	return newnode;
1076 1077 1078
}

/* ----------------
1079
 *		_copyIndexPath
1080 1081 1082
 * ----------------
 */
static IndexPath *
1083
_copyIndexPath(IndexPath *from)
1084
{
1085
	IndexPath  *newnode = makeNode(IndexPath);
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098

	/* ----------------
	 *	copy the node superclass fields
	 * ----------------
	 */
	CopyPathFields((Path *) from, (Path *) newnode);

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	newnode->indexid = listCopy(from->indexid);
	Node_Copy(from, newnode, indexqual);
1099
	newnode->joinrelids = listCopy(from->joinrelids);
1100 1101

	return newnode;
1102 1103
}

1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
/* ----------------
 *              _copyTidPath
 * ----------------
 */
static TidPath *
_copyTidPath(TidPath *from)
{
	TidPath	*newnode = makeNode(TidPath);

	/* ----------------
	 *	copy the node superclass fields
	 * ----------------
	 */
	CopyPathFields((Path *) from, (Path *) newnode);

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	Node_Copy(from, newnode, tideval);
	newnode->unjoined_relids = listCopy(from->unjoined_relids);

	return newnode;
}
1128
/* ----------------
1129
 *		CopyJoinPathFields
1130
 *
1131 1132
 *		This function copies the fields of the JoinPath node.  It is used by
 *		all the copy functions for classes which inherit from JoinPath.
1133 1134 1135
 * ----------------
 */
static void
1136
CopyJoinPathFields(JoinPath *from, JoinPath *newnode)
1137
{
1138 1139
	Node_Copy(from, newnode, outerjoinpath);
	Node_Copy(from, newnode, innerjoinpath);
1140
	Node_Copy(from, newnode, joinrestrictinfo);
1141 1142 1143
}

/* ----------------
1144
 *		_copyNestPath
1145 1146
 * ----------------
 */
1147
static NestPath *
1148
_copyNestPath(NestPath *from)
1149
{
1150
	NestPath   *newnode = makeNode(NestPath);
1151 1152 1153 1154 1155 1156

	/* ----------------
	 *	copy the node superclass fields
	 * ----------------
	 */
	CopyPathFields((Path *) from, (Path *) newnode);
1157
	CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1158 1159

	return newnode;
1160 1161 1162
}

/* ----------------
1163
 *		_copyMergePath
1164 1165 1166
 * ----------------
 */
static MergePath *
1167
_copyMergePath(MergePath *from)
1168
{
1169
	MergePath  *newnode = makeNode(MergePath);
1170 1171 1172 1173 1174 1175

	/* ----------------
	 *	copy the node superclass fields
	 * ----------------
	 */
	CopyPathFields((Path *) from, (Path *) newnode);
1176
	CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186

	/* ----------------
	 *	copy the remainder of the node
	 * ----------------
	 */
	Node_Copy(from, newnode, path_mergeclauses);
	Node_Copy(from, newnode, outersortkeys);
	Node_Copy(from, newnode, innersortkeys);

	return newnode;
1187 1188 1189
}

/* ----------------
1190
 *		_copyHashPath
1191 1192 1193
 * ----------------
 */
static HashPath *
1194
_copyHashPath(HashPath *from)
1195
{
1196
	HashPath   *newnode = makeNode(HashPath);
1197 1198 1199 1200 1201 1202

	/* ----------------
	 *	copy the node superclass fields
	 * ----------------
	 */
	CopyPathFields((Path *) from, (Path *) newnode);
1203
	CopyJoinPathFields((JoinPath *) from, (JoinPath *) newnode);
1204 1205 1206 1207 1208 1209 1210 1211

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	Node_Copy(from, newnode, path_hashclauses);

	return newnode;
1212 1213 1214
}

/* ----------------
1215
 *		_copyPathKeyItem
1216 1217
 * ----------------
 */
1218 1219
static PathKeyItem *
_copyPathKeyItem(PathKeyItem *from)
1220
{
1221
	PathKeyItem   *newnode = makeNode(PathKeyItem);
1222 1223 1224 1225 1226

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
1227 1228
	Node_Copy(from, newnode, key);
	newnode->sortop = from->sortop;
1229 1230

	return newnode;
1231 1232 1233
}

/* ----------------
1234
 *		_copyRestrictInfo
1235 1236
 * ----------------
 */
1237
static RestrictInfo *
1238
_copyRestrictInfo(RestrictInfo *from)
1239
{
1240
	RestrictInfo *newnode = makeNode(RestrictInfo);
1241 1242 1243 1244 1245 1246

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
	Node_Copy(from, newnode, clause);
1247 1248 1249 1250
	Node_Copy(from, newnode, subclauseindices);
	newnode->mergejoinoperator = from->mergejoinoperator;
	newnode->left_sortop = from->left_sortop;
	newnode->right_sortop = from->right_sortop;
1251 1252 1253
	newnode->hashjoinoperator = from->hashjoinoperator;

	return newnode;
1254 1255 1256
}

/* ----------------
1257
 *		_copyJoinInfo
1258 1259
 * ----------------
 */
1260
static JoinInfo *
1261
_copyJoinInfo(JoinInfo *from)
1262
{
1263
	JoinInfo   *newnode = makeNode(JoinInfo);
1264 1265 1266 1267 1268

	/* ----------------
	 *	copy remainder of node
	 * ----------------
	 */
Bruce Momjian's avatar
Bruce Momjian committed
1269
	newnode->unjoined_relids = listCopy(from->unjoined_relids);
1270
	Node_Copy(from, newnode, jinfo_restrictinfo);
1271 1272

	return newnode;
1273 1274
}

1275
static Iter *
1276
_copyIter(Iter *from)
1277
{
1278
	Iter	   *newnode = makeNode(Iter);
1279 1280 1281

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

1283
	return newnode;
1284 1285
}

1286
static Stream *
1287
_copyStream(Stream *from)
1288
{
1289
	Stream	   *newnode = makeNode(Stream);
1290 1291 1292 1293

	newnode->pathptr = from->pathptr;
	newnode->cinfo = from->cinfo;
	newnode->clausetype = from->clausetype;
Bruce Momjian's avatar
Bruce Momjian committed
1294

1295 1296 1297 1298 1299 1300
	newnode->upstream = (StreamPtr) NULL;		/* only copy nodes
												 * downwards! */
	Node_Copy(from, newnode, downstream);
	if (newnode->downstream)
		((Stream *) newnode->downstream)->upstream = (Stream *) newnode;

Bruce Momjian's avatar
Bruce Momjian committed
1301 1302 1303 1304
	newnode->groupup = from->groupup;
	newnode->groupcost = from->groupcost;
	newnode->groupsel = from->groupsel;

1305
	return newnode;
1306 1307
}

Bruce Momjian's avatar
Bruce Momjian committed
1308 1309
/*
 *	parsenodes.h routines have no copy functions
1310 1311 1312
 */

static TargetEntry *
1313
_copyTargetEntry(TargetEntry *from)
1314
{
1315
	TargetEntry *newnode = makeNode(TargetEntry);
1316

1317 1318 1319 1320
	Node_Copy(from, newnode, resdom);
	Node_Copy(from, newnode, fjoin);
	Node_Copy(from, newnode, expr);
	return newnode;
1321 1322 1323
}

static RangeTblEntry *
1324
_copyRangeTblEntry(RangeTblEntry *from)
1325
{
1326
	RangeTblEntry *newnode = makeNode(RangeTblEntry);
1327 1328 1329 1330 1331

	if (from->relname)
		newnode->relname = pstrdup(from->relname);
	if (from->refname)
		newnode->refname = pstrdup(from->refname);
Bruce Momjian's avatar
Bruce Momjian committed
1332 1333 1334
	newnode->relid = from->relid;
	newnode->inh = from->inh;
	newnode->inFromCl = from->inFromCl;
1335
	newnode->inJoinSet = from->inJoinSet;
1336 1337
	newnode->skipAcl = from->skipAcl;

1338
	return newnode;
1339 1340
}

1341
static RowMark *
1342
_copyRowMark(RowMark *from)
1343
{
Bruce Momjian's avatar
Bruce Momjian committed
1344
	RowMark    *newnode = makeNode(RowMark);
1345 1346 1347 1348 1349 1350 1351

	newnode->rti = from->rti;
	newnode->info = from->info;

	return newnode;
}

1352
static SortClause *
1353
_copySortClause(SortClause *from)
1354
{
1355
	SortClause *newnode = makeNode(SortClause);
1356

1357 1358
	newnode->tleSortGroupRef = from->tleSortGroupRef;
	newnode->sortop = from->sortop;
1359

1360
	return newnode;
1361 1362
}

1363
static A_Const *
Bruce Momjian's avatar
Bruce Momjian committed
1364
_copyAConst(A_Const *from)
1365
{
1366
	A_Const    *newnode = makeNode(A_Const);
1367

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

1371
	return newnode;
1372 1373 1374
}

static TypeName *
1375
_copyTypeName(TypeName *from)
1376
{
1377
	TypeName   *newnode = makeNode(TypeName);
1378 1379 1380

	if (from->name)
		newnode->name = pstrdup(from->name);
Bruce Momjian's avatar
Bruce Momjian committed
1381
	newnode->timezone = from->timezone;
1382
	newnode->setof = from->setof;
1383
	newnode->typmod = from->typmod;
1384 1385 1386
	Node_Copy(from, newnode, arrayBounds);

	return newnode;
1387 1388
}

1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399
static TypeCast *
_copyTypeCast(TypeCast *from)
{
	TypeCast   *newnode = makeNode(TypeCast);

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

	return newnode;
}

1400
static Query *
1401
_copyQuery(Query *from)
1402
{
1403
	Query	   *newnode = makeNode(Query);
1404

1405
	newnode->commandType = from->commandType;
Bruce Momjian's avatar
Bruce Momjian committed
1406 1407 1408 1409 1410
	if (from->utilityStmt && nodeTag(from->utilityStmt) == T_NotifyStmt)
	{
		NotifyStmt *from_notify = (NotifyStmt *) from->utilityStmt;
		NotifyStmt *n = makeNode(NotifyStmt);

Bruce Momjian's avatar
Bruce Momjian committed
1411
		n->relname = pstrdup(from_notify->relname);
Bruce Momjian's avatar
Bruce Momjian committed
1412 1413
		newnode->utilityStmt = (Node *) n;
	}
1414 1415 1416 1417
	newnode->resultRelation = from->resultRelation;
	if (from->into)
		newnode->into = pstrdup(from->into);
	newnode->isPortal = from->isPortal;
Bruce Momjian's avatar
Bruce Momjian committed
1418
	newnode->isBinary = from->isBinary;
1419
	newnode->isTemp = from->isTemp;
Bruce Momjian's avatar
Bruce Momjian committed
1420
	newnode->unionall = from->unionall;
1421 1422 1423
	newnode->hasAggs = from->hasAggs;
	newnode->hasSubLinks = from->hasSubLinks;

Bruce Momjian's avatar
Bruce Momjian committed
1424
	Node_Copy(from, newnode, rtable);
1425 1426
	Node_Copy(from, newnode, targetList);
	Node_Copy(from, newnode, qual);
1427
	Node_Copy(from, newnode, rowMark);
1428

1429
	Node_Copy(from, newnode, distinctClause);
1430
	Node_Copy(from, newnode, sortClause);
1431
	Node_Copy(from, newnode, groupClause);
Bruce Momjian's avatar
Bruce Momjian committed
1432
	Node_Copy(from, newnode, havingQual);
1433

1434 1435
	/* why is intersectClause missing? */
	Node_Copy(from, newnode, unionClause);
1436

Bruce Momjian's avatar
Bruce Momjian committed
1437 1438 1439
	Node_Copy(from, newnode, limitOffset);
	Node_Copy(from, newnode, limitCount);

1440 1441 1442
	/* we do not copy the planner internal fields: base_rel_list,
	 * join_rel_list, query_pathkeys.  Not entirely clear if this is right?
	 */
1443

1444
	return newnode;
1445 1446 1447
}


Bruce Momjian's avatar
Bruce Momjian committed
1448 1449
/*
 *	mnodes.h routines have no copy functions
1450 1451 1452
 */

/* ****************************************************************
1453
 *					pg_list.h copy functions
1454 1455 1456
 * ****************************************************************
 */

1457
static Value *
1458
_copyValue(Value *from)
1459
{
1460
	Value	   *newnode = makeNode(Value);
1461 1462 1463 1464

	newnode->type = from->type;
	switch (from->type)
	{
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475
		case T_String:
			newnode->val.str = pstrdup(from->val.str);
			break;
		case T_Integer:
			newnode->val.ival = from->val.ival;
			break;
		case T_Float:
			newnode->val.dval = from->val.dval;
			break;
		default:
			break;
1476 1477
	}
	return newnode;
1478 1479 1480
}

/* ----------------
1481 1482
 *		copyObject returns a copy of the node or list. If it is a list, it
 *		recursively copies its items.
1483 1484
 * ----------------
 */
1485
void *
1486 1487
copyObject(void *from)
{
1488
	void	   *retval;
1489

1490 1491 1492
	if (from == NULL)
		return NULL;
	switch (nodeTag(from))
1493
	{
1494

1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515
			/*
			 * 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;
1516 1517 1518
		case T_TidScan:
			retval = _copyTidScan(from);
			break;
1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530
		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;
1531 1532
		case T_Noname:
			retval = _copyNoname(from);
1533 1534 1535 1536 1537 1538 1539
			break;
		case T_Material:
			retval = _copyMaterial(from);
			break;
		case T_Sort:
			retval = _copySort(from);
			break;
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
1540 1541 1542
		case T_Group:
			retval = _copyGroup(from);
			break;
1543 1544 1545
		case T_Agg:
			retval = _copyAgg(from);
			break;
1546 1547 1548
		case T_GroupClause:
			retval = _copyGroupClause(from);
			break;
1549 1550 1551 1552 1553 1554
		case T_Unique:
			retval = _copyUnique(from);
			break;
		case T_Hash:
			retval = _copyHash(from);
			break;
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
1555 1556 1557
		case T_SubPlan:
			retval = _copySubPlan(from);
			break;
1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591

			/*
			 * 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;
		case T_Func:
			retval = _copyFunc(from);
			break;
		case T_Array:
			retval = _copyArray(from);
			break;
		case T_ArrayRef:
			retval = _copyArrayRef(from);
			break;
Bruce Momjian's avatar
Bruce Momjian committed
1592 1593
		case T_Aggref:
			retval = _copyAggref(from);
1594
			break;
1595 1596 1597
		case T_SubLink:
			retval = _copySubLink(from);
			break;
1598 1599 1600 1601 1602 1603
		case T_CaseExpr:
			retval = _copyCaseExpr(from);
			break;
		case T_CaseWhen:
			retval = _copyCaseWhen(from);
			break;
1604 1605 1606 1607

			/*
			 * RELATION NODES
			 */
Bruce Momjian's avatar
Bruce Momjian committed
1608
		case T_RelOptInfo:
1609
			retval = _copyRelOptInfo(from);
1610 1611 1612 1613 1614 1615 1616
			break;
		case T_Path:
			retval = _copyPath(from);
			break;
		case T_IndexPath:
			retval = _copyIndexPath(from);
			break;
1617 1618 1619
		case T_TidPath:
			retval = _copyTidPath(from);
			break;
1620 1621
		case T_NestPath:
			retval = _copyNestPath(from);
1622 1623 1624 1625 1626 1627 1628
			break;
		case T_MergePath:
			retval = _copyMergePath(from);
			break;
		case T_HashPath:
			retval = _copyHashPath(from);
			break;
1629 1630
		case T_PathKeyItem:
			retval = _copyPathKeyItem(from);
1631
			break;
1632 1633
		case T_RestrictInfo:
			retval = _copyRestrictInfo(from);
1634
			break;
1635 1636
		case T_JoinInfo:
			retval = _copyJoinInfo(from);
1637 1638 1639 1640 1641 1642 1643
			break;
		case T_Iter:
			retval = _copyIter(from);
			break;
		case T_Stream:
			retval = _copyStream(from);
			break;
1644 1645 1646
		case T_IndexOptInfo:
			retval = _copyIndexOptInfo(from);
			break;
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659

			/*
			 * PARSE NODES
			 */
		case T_Query:
			retval = _copyQuery(from);
			break;
		case T_TargetEntry:
			retval = _copyTargetEntry(from);
			break;
		case T_RangeTblEntry:
			retval = _copyRangeTblEntry(from);
			break;
1660 1661 1662
		case T_RowMark:
			retval = _copyRowMark(from);
			break;
1663 1664 1665 1666 1667 1668 1669 1670 1671
		case T_SortClause:
			retval = _copySortClause(from);
			break;
		case T_A_Const:
			retval = _copyAConst(from);
			break;
		case T_TypeName:
			retval = _copyTypeName(from);
			break;
1672 1673 1674
		case T_TypeCast:
			retval = _copyTypeCast(from);
			break;
1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686

			/*
			 * VALUE NODES
			 */
		case T_Integer:
		case T_String:
		case T_Float:
			retval = _copyValue(from);
			break;
		case T_List:
			{
				List	   *list = from,
1687 1688 1689 1690 1691 1692 1693
						   *l,
						   *nl;

				/* rather ugly coding for speed... */
				/* Note the input list cannot be NIL if we got here. */
				nl = lcons(copyObject(lfirst(list)), NIL);
				retval = nl;
1694

1695
				foreach(l, lnext(list))
1696
				{
1697 1698
					lnext(nl) = lcons(copyObject(lfirst(l)), NIL);
					nl = lnext(nl);
1699 1700
				}
			}
1701 1702
			break;
		default:
1703
			elog(ERROR, "copyObject: don't know how to copy %d", nodeTag(from));
1704 1705
			retval = from;
			break;
1706
	}
1707
	return retval;
1708
}