copyfuncs.c 57.5 KB
Newer Older
1
/*-------------------------------------------------------------------------
2
 *
3
 * copyfuncs.c
4
 *	  Copy functions for Postgres tree nodes.
5
 *
6
 * NOTE: we currently support copying all node types found in parse and
B
Bruce Momjian 已提交
7
 * plan trees.	We do not support copying executor state trees; there
8 9 10 11
 * is no need for that, and no point in maintaining all the code that
 * would be needed.  We also do not support copying Path trees, mainly
 * because the circular linkages between RelOptInfo and Path nodes can't
 * be handled easily in a simple depth-first traversal.
12 13
 *
 *
B
Bruce Momjian 已提交
14
 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
B
Add:  
Bruce Momjian 已提交
15
 * Portions Copyright (c) 1994, Regents of the University of California
16 17
 *
 * IDENTIFICATION
T
Tom Lane 已提交
18
 *	  $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.280 2004/05/05 04:48:45 tgl Exp $
19 20 21 22 23 24
 *
 *-------------------------------------------------------------------------
 */

#include "postgres.h"

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


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

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

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

/* Copy a field that is a pointer to a list of integers */
#define COPY_INTLIST_FIELD(fldname) \
	(newnode->fldname = listCopy(from->fldname))

50 51 52 53
/* Copy a field that is a pointer to a list of Oids */
#define COPY_OIDLIST_FIELD(fldname) \
	(newnode->fldname = listCopy(from->fldname))

54 55 56 57
/* Copy a field that is a pointer to a Bitmapset */
#define COPY_BITMAPSET_FIELD(fldname) \
	(newnode->fldname = bms_copy(from->fldname))

58 59 60 61 62 63 64 65 66 67 68 69
/* Copy a field that is a pointer to a C string, or perhaps NULL */
#define COPY_STRING_FIELD(fldname) \
	(newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)

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

70 71

/*
72
 * listCopy
73 74 75
 *	  This copy function only copies the "cons-cells" of the list, not the
 *	  pointed-to objects.  (Use copyObject if you want a "deep" copy.)
 *
76 77
 *	  We also use this function for copying lists of integers and Oids,
 *	  which is notationally a bit ugly, but perfectly safe.
78 79
 *
 *	  Note that copyObject will surely coredump if applied to a list
80
 *	  of integers or Oids!
81
 */
82
List *
83
listCopy(List *list)
84
{
85
	List	   *newlist,
86 87 88
			   *oldl,
			   *newcell,
			   *prev;
89 90 91 92

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

94 95 96 97
	newcell = makeNode(List);
	newcell->elem = list->elem;

	newlist = prev = newcell;
98

99
	foreach(oldl, lnext(list))
100
	{
101 102 103 104
		newcell = makeNode(List);
		newcell->elem = oldl->elem;
		prev->next = newcell;
		prev = newcell;
105
	}
106 107
	prev->next = NIL;

108
	return newlist;
109
}
110

111
/* ****************************************************************
112
 *					 plannodes.h copy functions
113 114 115
 * ****************************************************************
 */

116 117
/*
 * CopyPlanFields
118
 *
119 120
 *		This function copies the fields of the Plan node.  It is used by
 *		all the copy functions for classes which inherit from Plan.
121 122
 */
static void
123
CopyPlanFields(Plan *from, Plan *newnode)
124
{
125 126 127 128 129 130 131 132
	COPY_SCALAR_FIELD(startup_cost);
	COPY_SCALAR_FIELD(total_cost);
	COPY_SCALAR_FIELD(plan_rows);
	COPY_SCALAR_FIELD(plan_width);
	COPY_NODE_FIELD(targetlist);
	COPY_NODE_FIELD(qual);
	COPY_NODE_FIELD(lefttree);
	COPY_NODE_FIELD(righttree);
133
	COPY_NODE_FIELD(initPlan);
134 135
	COPY_BITMAPSET_FIELD(extParam);
	COPY_BITMAPSET_FIELD(allParam);
136
	COPY_SCALAR_FIELD(nParamExec);
137 138
}

139 140
/*
 * _copyPlan
141
 */
142
static Plan *
143
_copyPlan(Plan *from)
144
{
145
	Plan	   *newnode = makeNode(Plan);
146

147
	/*
148
	 * copy node superclass fields
149 150 151 152
	 */
	CopyPlanFields(from, newnode);

	return newnode;
153 154 155
}


156 157
/*
 * _copyResult
158
 */
159
static Result *
160
_copyResult(Result *from)
161
{
162
	Result	   *newnode = makeNode(Result);
163

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

169 170
	/*
	 * copy remainder of node
171
	 */
172
	COPY_NODE_FIELD(resconstantqual);
173 174

	return newnode;
175 176
}

177 178
/*
 * _copyAppend
179
 */
180
static Append *
B
Bruce Momjian 已提交
181
_copyAppend(Append *from)
182
{
183
	Append	   *newnode = makeNode(Append);
184

185 186
	/*
	 * copy node superclass fields
187 188 189
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

190 191
	/*
	 * copy remainder of node
192
	 */
193 194
	COPY_NODE_FIELD(appendplans);
	COPY_SCALAR_FIELD(isTarget);
195 196

	return newnode;
197 198 199
}


200 201
/*
 * CopyScanFields
202
 *
203 204
 *		This function copies the fields of the Scan node.  It is used by
 *		all the copy functions for classes which inherit from Scan.
205 206
 */
static void
207
CopyScanFields(Scan *from, Scan *newnode)
208
{
209 210 211
	CopyPlanFields((Plan *) from, (Plan *) newnode);

	COPY_SCALAR_FIELD(scanrelid);
212 213
}

214 215
/*
 * _copyScan
216
 */
217
static Scan *
218
_copyScan(Scan *from)
219
{
220
	Scan	   *newnode = makeNode(Scan);
221

222 223
	/*
	 * copy node superclass fields
224
	 */
B
Bruce Momjian 已提交
225
	CopyScanFields((Scan *) from, (Scan *) newnode);
226 227

	return newnode;
228 229
}

230 231
/*
 * _copySeqScan
232 233
 */
static SeqScan *
234
_copySeqScan(SeqScan *from)
235
{
236
	SeqScan    *newnode = makeNode(SeqScan);
237

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

	return newnode;
244 245
}

246 247
/*
 * _copyIndexScan
248 249
 */
static IndexScan *
250
_copyIndexScan(IndexScan *from)
251
{
252
	IndexScan  *newnode = makeNode(IndexScan);
253

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

259 260
	/*
	 * copy remainder of node
261
	 */
262
	COPY_OIDLIST_FIELD(indxid);
263 264
	COPY_NODE_FIELD(indxqual);
	COPY_NODE_FIELD(indxqualorig);
265 266 267 268 269 270 271 272 273 274 275
	/* this can become COPY_NODE_FIELD when intlists are normal objects: */
	{
		List	*newstrat = NIL;
		List    *tmp;

		foreach(tmp, from->indxstrategy)
		{
			newstrat = lappend(newstrat, listCopy(lfirst(tmp)));
		}
		newnode->indxstrategy = newstrat;
	}
276 277 278 279 280 281 282 283 284 285 286
	/* this can become COPY_NODE_FIELD when OID lists are normal objects: */
	{
		List	*newsubtype = NIL;
		List    *tmp;

		foreach(tmp, from->indxsubtype)
		{
			newsubtype = lappend(newsubtype, listCopy(lfirst(tmp)));
		}
		newnode->indxsubtype = newsubtype;
	}
287 288 289 290 291 292 293 294 295 296 297
	/* this can become COPY_NODE_FIELD when intlists are normal objects: */
	{
		List	*newstrat = NIL;
		List    *tmp;

		foreach(tmp, from->indxlossy)
		{
			newstrat = lappend(newstrat, listCopy(lfirst(tmp)));
		}
		newnode->indxlossy = newstrat;
	}
298
	COPY_SCALAR_FIELD(indxorderdir);
299 300

	return newnode;
301 302
}

303 304
/*
 * _copyTidScan
305 306 307 308
 */
static TidScan *
_copyTidScan(TidScan *from)
{
309
	TidScan    *newnode = makeNode(TidScan);
310

311 312
	/*
	 * copy node superclass fields
313 314
	 */
	CopyScanFields((Scan *) from, (Scan *) newnode);
315 316 317

	/*
	 * copy remainder of node
318
	 */
319 320
	COPY_NODE_FIELD(tideval);

321 322 323
	return newnode;
}

324 325
/*
 * _copySubqueryScan
326 327 328 329
 */
static SubqueryScan *
_copySubqueryScan(SubqueryScan *from)
{
B
Bruce Momjian 已提交
330
	SubqueryScan *newnode = makeNode(SubqueryScan);
331

332 333
	/*
	 * copy node superclass fields
334 335 336
	 */
	CopyScanFields((Scan *) from, (Scan *) newnode);

337 338
	/*
	 * copy remainder of node
339
	 */
340
	COPY_NODE_FIELD(subplan);
341 342 343 344

	return newnode;
}

345 346
/*
 * _copyFunctionScan
347 348 349 350 351 352 353 354 355 356 357 358 359
 */
static FunctionScan *
_copyFunctionScan(FunctionScan *from)
{
	FunctionScan *newnode = makeNode(FunctionScan);

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

	return newnode;
}
360

361 362
/*
 * CopyJoinFields
363
 *
364 365
 *		This function copies the fields of the Join node.  It is used by
 *		all the copy functions for classes which inherit from Join.
366 367
 */
static void
368
CopyJoinFields(Join *from, Join *newnode)
369
{
370 371 372 373
	CopyPlanFields((Plan *) from, (Plan *) newnode);

	COPY_SCALAR_FIELD(jointype);
	COPY_NODE_FIELD(joinqual);
374 375 376
}


377 378
/*
 * _copyJoin
379
 */
380
static Join *
381
_copyJoin(Join *from)
382
{
383
	Join	   *newnode = makeNode(Join);
384

385 386
	/*
	 * copy node superclass fields
387 388 389 390
	 */
	CopyJoinFields(from, newnode);

	return newnode;
391 392 393
}


394 395
/*
 * _copyNestLoop
396 397
 */
static NestLoop *
398
_copyNestLoop(NestLoop *from)
399
{
400
	NestLoop   *newnode = makeNode(NestLoop);
401

402 403
	/*
	 * copy node superclass fields
404 405 406 407
	 */
	CopyJoinFields((Join *) from, (Join *) newnode);

	return newnode;
408 409 410
}


411 412
/*
 * _copyMergeJoin
413 414
 */
static MergeJoin *
415
_copyMergeJoin(MergeJoin *from)
416
{
417
	MergeJoin  *newnode = makeNode(MergeJoin);
418

419 420
	/*
	 * copy node superclass fields
421 422 423
	 */
	CopyJoinFields((Join *) from, (Join *) newnode);

424 425
	/*
	 * copy remainder of node
426
	 */
427
	COPY_NODE_FIELD(mergeclauses);
428 429

	return newnode;
430 431
}

432 433
/*
 * _copyHashJoin
434 435
 */
static HashJoin *
436
_copyHashJoin(HashJoin *from)
437
{
438
	HashJoin   *newnode = makeNode(HashJoin);
439

440 441
	/*
	 * copy node superclass fields
442 443 444
	 */
	CopyJoinFields((Join *) from, (Join *) newnode);

445 446
	/*
	 * copy remainder of node
447
	 */
448
	COPY_NODE_FIELD(hashclauses);
449 450

	return newnode;
451 452 453
}


454 455
/*
 * _copyMaterial
456 457
 */
static Material *
458
_copyMaterial(Material *from)
459
{
460
	Material   *newnode = makeNode(Material);
461

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

	return newnode;
468 469 470
}


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

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

484 485 486
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
	COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
487 488

	return newnode;
489 490
}

V
Vadim B. Mikheev 已提交
491

492 493
/*
 * _copyGroup
V
Vadim B. Mikheev 已提交
494 495 496 497 498
 */
static Group *
_copyGroup(Group *from)
{
	Group	   *newnode = makeNode(Group);
499

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

502 503
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
V
Vadim B. Mikheev 已提交
504 505 506 507

	return newnode;
}

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

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

518 519
	COPY_SCALAR_FIELD(aggstrategy);
	COPY_SCALAR_FIELD(numCols);
520
	if (from->numCols > 0)
521 522
		COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
	COPY_SCALAR_FIELD(numGroups);
523

524
	return newnode;
525 526
}

527 528
/*
 * _copyUnique
529
 */
530
static Unique *
531
_copyUnique(Unique *from)
532
{
533
	Unique	   *newnode = makeNode(Unique);
534

535 536
	/*
	 * copy node superclass fields
537 538 539
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

540 541
	/*
	 * copy remainder of node
542
	 */
543 544
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
545 546

	return newnode;
547 548
}

549
/*
550
 * _copyHash
551
 */
552 553
static Hash *
_copyHash(Hash *from)
554
{
555
	Hash	   *newnode = makeNode(Hash);
556

557 558
	/*
	 * copy node superclass fields
559 560 561
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

562 563
	/*
	 * copy remainder of node
564 565 566 567
	 */

	return newnode;
}
568

569
/*
570
 * _copySetOp
571
 */
572 573
static SetOp *
_copySetOp(SetOp *from)
574
{
575
	SetOp	   *newnode = makeNode(SetOp);
576

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

582 583
	/*
	 * copy remainder of node
584
	 */
585 586 587 588
	COPY_SCALAR_FIELD(cmd);
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
	COPY_SCALAR_FIELD(flagColIdx);
589 590 591 592

	return newnode;
}

593
/*
594
 * _copyLimit
595
 */
596 597
static Limit *
_copyLimit(Limit *from)
598
{
599
	Limit	   *newnode = makeNode(Limit);
600

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

606 607
	/*
	 * copy remainder of node
608
	 */
609 610
	COPY_NODE_FIELD(limitOffset);
	COPY_NODE_FIELD(limitCount);
611 612

	return newnode;
613 614 615
}

/* ****************************************************************
616
 *					   primnodes.h copy functions
617 618 619
 * ****************************************************************
 */

620 621
/*
 * _copyResdom
622
 */
623
static Resdom *
624
_copyResdom(Resdom *from)
625
{
626
	Resdom	   *newnode = makeNode(Resdom);
627

628 629 630 631 632
	COPY_SCALAR_FIELD(resno);
	COPY_SCALAR_FIELD(restype);
	COPY_SCALAR_FIELD(restypmod);
	COPY_STRING_FIELD(resname);
	COPY_SCALAR_FIELD(ressortgroupref);
633 634
	COPY_SCALAR_FIELD(resorigtbl);
	COPY_SCALAR_FIELD(resorigcol);
635
	COPY_SCALAR_FIELD(resjunk);
636 637

	return newnode;
638 639
}

640 641 642
/*
 * _copyAlias
 */
643 644 645 646
static Alias *
_copyAlias(Alias *from)
{
	Alias	   *newnode = makeNode(Alias);
647

648 649
	COPY_STRING_FIELD(aliasname);
	COPY_NODE_FIELD(colnames);
650

651 652
	return newnode;
}
653

654 655 656
/*
 * _copyRangeVar
 */
657 658 659 660 661 662 663 664 665 666 667
static RangeVar *
_copyRangeVar(RangeVar *from)
{
	RangeVar   *newnode = makeNode(RangeVar);

	COPY_STRING_FIELD(catalogname);
	COPY_STRING_FIELD(schemaname);
	COPY_STRING_FIELD(relname);
	COPY_SCALAR_FIELD(inhOpt);
	COPY_SCALAR_FIELD(istemp);
	COPY_NODE_FIELD(alias);
668 669

	return newnode;
670 671
}

672
/*
673
 * We don't need a _copyExpr because Expr is an abstract supertype which
B
Bruce Momjian 已提交
674
 * should never actually get instantiated.	Also, since it has no common
675 676
 * fields except NodeTag, there's no need for a helper routine to factor
 * out copying the common fields...
677 678
 */

679 680
/*
 * _copyVar
681
 */
682
static Var *
683
_copyVar(Var *from)
684
{
685
	Var		   *newnode = makeNode(Var);
686

687 688 689 690 691 692 693
	COPY_SCALAR_FIELD(varno);
	COPY_SCALAR_FIELD(varattno);
	COPY_SCALAR_FIELD(vartype);
	COPY_SCALAR_FIELD(vartypmod);
	COPY_SCALAR_FIELD(varlevelsup);
	COPY_SCALAR_FIELD(varnoold);
	COPY_SCALAR_FIELD(varoattno);
694 695

	return newnode;
696 697
}

698 699
/*
 * _copyConst
700
 */
701
static Const *
702
_copyConst(Const *from)
703
{
704
	Const	   *newnode = makeNode(Const);
705

706 707
	COPY_SCALAR_FIELD(consttype);
	COPY_SCALAR_FIELD(constlen);
708

709
	if (from->constbyval || from->constisnull)
710
	{
711 712 713
		/*
		 * passed by value so just copy the datum. Also, don't try to copy
		 * struct when value is null!
714
		 */
715
		newnode->constvalue = from->constvalue;
716
	}
717
	else
718
	{
719
		/*
720
		 * passed by reference.  We need a palloc'd copy.
721
		 */
722 723 724
		newnode->constvalue = datumCopy(from->constvalue,
										from->constbyval,
										from->constlen);
725
	}
726

727 728
	COPY_SCALAR_FIELD(constisnull);
	COPY_SCALAR_FIELD(constbyval);
729 730

	return newnode;
731 732
}

733 734
/*
 * _copyParam
735
 */
736
static Param *
737
_copyParam(Param *from)
738
{
739
	Param	   *newnode = makeNode(Param);
740

741 742 743 744
	COPY_SCALAR_FIELD(paramkind);
	COPY_SCALAR_FIELD(paramid);
	COPY_STRING_FIELD(paramname);
	COPY_SCALAR_FIELD(paramtype);
745 746

	return newnode;
747 748
}

749
/*
750
 * _copyAggref
751
 */
752 753
static Aggref *
_copyAggref(Aggref *from)
754
{
755 756 757 758 759
	Aggref	   *newnode = makeNode(Aggref);

	COPY_SCALAR_FIELD(aggfnoid);
	COPY_SCALAR_FIELD(aggtype);
	COPY_NODE_FIELD(target);
760
	COPY_SCALAR_FIELD(agglevelsup);
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
	COPY_SCALAR_FIELD(aggstar);
	COPY_SCALAR_FIELD(aggdistinct);

	return newnode;
}

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

	COPY_SCALAR_FIELD(refrestype);
776 777
	COPY_SCALAR_FIELD(refarraytype);
	COPY_SCALAR_FIELD(refelemtype);
778 779 780 781 782 783 784 785 786 787 788 789
	COPY_NODE_FIELD(refupperindexpr);
	COPY_NODE_FIELD(reflowerindexpr);
	COPY_NODE_FIELD(refexpr);
	COPY_NODE_FIELD(refassgnexpr);

	return newnode;
}

/*
 * _copyFuncExpr
 */
static FuncExpr *
790
_copyFuncExpr(FuncExpr *from)
791
{
B
Bruce Momjian 已提交
792
	FuncExpr   *newnode = makeNode(FuncExpr);
793

794 795 796 797
	COPY_SCALAR_FIELD(funcid);
	COPY_SCALAR_FIELD(funcresulttype);
	COPY_SCALAR_FIELD(funcretset);
	COPY_SCALAR_FIELD(funcformat);
798
	COPY_NODE_FIELD(args);
799

800
	return newnode;
801 802
}

803
/*
804
 * _copyOpExpr
805
 */
806
static OpExpr *
807
_copyOpExpr(OpExpr *from)
808
{
809
	OpExpr	   *newnode = makeNode(OpExpr);
810

811 812 813 814 815 816 817 818 819 820
	COPY_SCALAR_FIELD(opno);
	COPY_SCALAR_FIELD(opfuncid);
	COPY_SCALAR_FIELD(opresulttype);
	COPY_SCALAR_FIELD(opretset);
	COPY_NODE_FIELD(args);

	return newnode;
}

/*
821
 * _copyDistinctExpr (same as OpExpr)
822 823
 */
static DistinctExpr *
824
_copyDistinctExpr(DistinctExpr *from)
825
{
B
Bruce Momjian 已提交
826
	DistinctExpr *newnode = makeNode(DistinctExpr);
827 828 829 830 831 832 833 834 835 836

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

	return newnode;
}

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

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

	return newnode;
}

853 854 855 856
/*
 * _copyBoolExpr
 */
static BoolExpr *
857
_copyBoolExpr(BoolExpr *from)
858
{
B
Bruce Momjian 已提交
859
	BoolExpr   *newnode = makeNode(BoolExpr);
860 861 862

	COPY_SCALAR_FIELD(boolop);
	COPY_NODE_FIELD(args);
863 864

	return newnode;
865 866
}

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

875
	COPY_SCALAR_FIELD(subLinkType);
876
	COPY_SCALAR_FIELD(useOr);
877
	COPY_NODE_FIELD(lefthand);
878
	COPY_NODE_FIELD(operName);
879
	COPY_OIDLIST_FIELD(operOids);
880
	COPY_NODE_FIELD(subselect);
881 882 883 884

	return newnode;
}

885
/*
886
 * _copySubPlan
887
 */
888 889
static SubPlan *
_copySubPlan(SubPlan *from)
890
{
891
	SubPlan    *newnode = makeNode(SubPlan);
892

893
	COPY_SCALAR_FIELD(subLinkType);
894
	COPY_SCALAR_FIELD(useOr);
895 896
	COPY_NODE_FIELD(exprs);
	COPY_INTLIST_FIELD(paramIds);
897 898 899
	COPY_NODE_FIELD(plan);
	COPY_SCALAR_FIELD(plan_id);
	COPY_NODE_FIELD(rtable);
900 901
	COPY_SCALAR_FIELD(useHashTable);
	COPY_SCALAR_FIELD(unknownEqFalse);
902 903 904 905 906 907 908
	COPY_INTLIST_FIELD(setParam);
	COPY_INTLIST_FIELD(parParam);
	COPY_NODE_FIELD(args);

	return newnode;
}

909 910
/*
 * _copyFieldSelect
911 912 913 914 915 916
 */
static FieldSelect *
_copyFieldSelect(FieldSelect *from)
{
	FieldSelect *newnode = makeNode(FieldSelect);

917 918 919 920
	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(fieldnum);
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
921 922 923 924

	return newnode;
}

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

933 934 935 936
	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
	COPY_SCALAR_FIELD(relabelformat);
937 938 939 940

	return newnode;
}

941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
/*
 * _copyCaseExpr
 */
static CaseExpr *
_copyCaseExpr(CaseExpr *from)
{
	CaseExpr   *newnode = makeNode(CaseExpr);

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

	return newnode;
}

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

	COPY_NODE_FIELD(expr);
	COPY_NODE_FIELD(result);

	return newnode;
}

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

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);

	return newnode;
}

985 986 987 988
/*
 * _copyArrayExpr
 */
static ArrayExpr *
989
_copyArrayExpr(ArrayExpr *from)
990
{
B
Bruce Momjian 已提交
991
	ArrayExpr  *newnode = makeNode(ArrayExpr);
992 993 994 995

	COPY_SCALAR_FIELD(array_typeid);
	COPY_SCALAR_FIELD(element_typeid);
	COPY_NODE_FIELD(elements);
996
	COPY_SCALAR_FIELD(multidims);
997 998 999 1000

	return newnode;
}

1001 1002 1003 1004
/*
 * _copyCoalesceExpr
 */
static CoalesceExpr *
1005
_copyCoalesceExpr(CoalesceExpr *from)
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
{
	CoalesceExpr *newnode = makeNode(CoalesceExpr);

	COPY_SCALAR_FIELD(coalescetype);
	COPY_NODE_FIELD(args);

	return newnode;
}

/*
 * _copyNullIfExpr (same as OpExpr)
 */
static NullIfExpr *
1019
_copyNullIfExpr(NullIfExpr *from)
1020
{
B
Bruce Momjian 已提交
1021
	NullIfExpr *newnode = makeNode(NullIfExpr);
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031

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

	return newnode;
}

1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
/*
 * _copyNullTest
 */
static NullTest *
_copyNullTest(NullTest *from)
{
	NullTest   *newnode = makeNode(NullTest);

	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(nulltesttype);

	return newnode;
}

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

	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(booltesttype);

	return newnode;
}

/*
1061
 * _copyCoerceToDomain
1062
 */
1063
static CoerceToDomain *
1064
_copyCoerceToDomain(CoerceToDomain *from)
1065
{
1066
	CoerceToDomain *newnode = makeNode(CoerceToDomain);
1067 1068

	COPY_NODE_FIELD(arg);
1069 1070 1071
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
	COPY_SCALAR_FIELD(coercionformat);
1072 1073 1074 1075 1076

	return newnode;
}

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

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);

	return newnode;
}

1090 1091 1092 1093
/*
 * _copySetToDefault
 */
static SetToDefault *
1094
_copySetToDefault(SetToDefault *from)
1095 1096 1097 1098 1099 1100 1101 1102 1103
{
	SetToDefault *newnode = makeNode(SetToDefault);

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);

	return newnode;
}

1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
/*
 * _copyTargetEntry
 */
static TargetEntry *
_copyTargetEntry(TargetEntry *from)
{
	TargetEntry *newnode = makeNode(TargetEntry);

	COPY_NODE_FIELD(resdom);
	COPY_NODE_FIELD(expr);

	return newnode;
}

/*
 * _copyRangeTblRef
 */
1121 1122 1123 1124 1125
static RangeTblRef *
_copyRangeTblRef(RangeTblRef *from)
{
	RangeTblRef *newnode = makeNode(RangeTblRef);

1126
	COPY_SCALAR_FIELD(rtindex);
1127 1128 1129 1130

	return newnode;
}

1131 1132 1133
/*
 * _copyJoinExpr
 */
1134 1135 1136
static JoinExpr *
_copyJoinExpr(JoinExpr *from)
{
B
Bruce Momjian 已提交
1137
	JoinExpr   *newnode = makeNode(JoinExpr);
1138

1139 1140 1141 1142 1143 1144 1145 1146
	COPY_SCALAR_FIELD(jointype);
	COPY_SCALAR_FIELD(isNatural);
	COPY_NODE_FIELD(larg);
	COPY_NODE_FIELD(rarg);
	COPY_NODE_FIELD(using);
	COPY_NODE_FIELD(quals);
	COPY_NODE_FIELD(alias);
	COPY_SCALAR_FIELD(rtindex);
T
Thomas G. Lockhart 已提交
1147 1148 1149 1150

	return newnode;
}

1151 1152 1153
/*
 * _copyFromExpr
 */
1154 1155
static FromExpr *
_copyFromExpr(FromExpr *from)
B
Bruce Momjian 已提交
1156
{
1157
	FromExpr   *newnode = makeNode(FromExpr);
B
Bruce Momjian 已提交
1158

1159 1160
	COPY_NODE_FIELD(fromlist);
	COPY_NODE_FIELD(quals);
B
Bruce Momjian 已提交
1161 1162 1163 1164

	return newnode;
}

1165
/* ****************************************************************
1166
 *						relation.h copy functions
1167
 *
1168 1169
 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
 * There are some subsidiary structs that are useful to copy, though.
1170 1171 1172
 * ****************************************************************
 */

1173 1174
/*
 * _copyPathKeyItem
1175
 */
1176 1177
static PathKeyItem *
_copyPathKeyItem(PathKeyItem *from)
1178
{
1179
	PathKeyItem *newnode = makeNode(PathKeyItem);
1180

1181 1182
	COPY_NODE_FIELD(key);
	COPY_SCALAR_FIELD(sortop);
1183 1184

	return newnode;
1185 1186
}

1187 1188
/*
 * _copyRestrictInfo
1189
 */
1190
static RestrictInfo *
1191
_copyRestrictInfo(RestrictInfo *from)
1192
{
1193
	RestrictInfo *newnode = makeNode(RestrictInfo);
1194

1195
	COPY_NODE_FIELD(clause);
1196 1197 1198
	COPY_SCALAR_FIELD(is_pushed_down);
	COPY_SCALAR_FIELD(valid_everywhere);
	COPY_SCALAR_FIELD(can_join);
1199
	COPY_BITMAPSET_FIELD(clause_relids);
1200 1201
	COPY_BITMAPSET_FIELD(left_relids);
	COPY_BITMAPSET_FIELD(right_relids);
1202
	COPY_NODE_FIELD(orclause);
1203 1204 1205 1206 1207
	COPY_SCALAR_FIELD(eval_cost);
	COPY_SCALAR_FIELD(this_selec);
	COPY_SCALAR_FIELD(mergejoinoperator);
	COPY_SCALAR_FIELD(left_sortop);
	COPY_SCALAR_FIELD(right_sortop);
B
Bruce Momjian 已提交
1208 1209 1210 1211 1212

	/*
	 * Do not copy pathkeys, since they'd not be canonical in a copied
	 * query
	 */
1213 1214
	newnode->left_pathkey = NIL;
	newnode->right_pathkey = NIL;
1215 1216 1217 1218 1219 1220

	COPY_SCALAR_FIELD(left_mergescansel);
	COPY_SCALAR_FIELD(right_mergescansel);
	COPY_SCALAR_FIELD(hashjoinoperator);
	COPY_SCALAR_FIELD(left_bucketsize);
	COPY_SCALAR_FIELD(right_bucketsize);
1221 1222

	return newnode;
1223 1224
}

1225 1226
/*
 * _copyJoinInfo
1227
 */
1228
static JoinInfo *
1229
_copyJoinInfo(JoinInfo *from)
1230
{
1231
	JoinInfo   *newnode = makeNode(JoinInfo);
1232

1233
	COPY_BITMAPSET_FIELD(unjoined_relids);
1234
	COPY_NODE_FIELD(jinfo_restrictinfo);
1235 1236

	return newnode;
1237 1238
}

1239 1240 1241 1242
/*
 * _copyInClauseInfo
 */
static InClauseInfo *
1243
_copyInClauseInfo(InClauseInfo *from)
1244 1245 1246
{
	InClauseInfo *newnode = makeNode(InClauseInfo);

1247 1248
	COPY_BITMAPSET_FIELD(lefthand);
	COPY_BITMAPSET_FIELD(righthand);
1249 1250 1251 1252 1253
	COPY_NODE_FIELD(sub_targetlist);

	return newnode;
}

1254 1255 1256
/* ****************************************************************
 *					parsenodes.h copy functions
 * ****************************************************************
1257 1258 1259
 */

static RangeTblEntry *
1260
_copyRangeTblEntry(RangeTblEntry *from)
1261
{
1262
	RangeTblEntry *newnode = makeNode(RangeTblEntry);
1263

1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274
	COPY_SCALAR_FIELD(rtekind);
	COPY_SCALAR_FIELD(relid);
	COPY_NODE_FIELD(subquery);
	COPY_NODE_FIELD(funcexpr);
	COPY_NODE_FIELD(coldeflist);
	COPY_SCALAR_FIELD(jointype);
	COPY_NODE_FIELD(joinaliasvars);
	COPY_NODE_FIELD(alias);
	COPY_NODE_FIELD(eref);
	COPY_SCALAR_FIELD(inh);
	COPY_SCALAR_FIELD(inFromCl);
1275
	COPY_SCALAR_FIELD(requiredPerms);
1276
	COPY_SCALAR_FIELD(checkAsUser);
1277 1278 1279 1280

	return newnode;
}

1281 1282 1283
static FkConstraint *
_copyFkConstraint(FkConstraint *from)
{
B
Bruce Momjian 已提交
1284
	FkConstraint *newnode = makeNode(FkConstraint);
1285

1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
	COPY_STRING_FIELD(constr_name);
	COPY_NODE_FIELD(pktable);
	COPY_NODE_FIELD(fk_attrs);
	COPY_NODE_FIELD(pk_attrs);
	COPY_SCALAR_FIELD(fk_matchtype);
	COPY_SCALAR_FIELD(fk_upd_action);
	COPY_SCALAR_FIELD(fk_del_action);
	COPY_SCALAR_FIELD(deferrable);
	COPY_SCALAR_FIELD(initdeferred);
	COPY_SCALAR_FIELD(skip_validation);
B
Bruce Momjian 已提交
1296

1297 1298 1299
	return newnode;
}

1300
static SortClause *
1301
_copySortClause(SortClause *from)
1302
{
1303
	SortClause *newnode = makeNode(SortClause);
1304

1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317
	COPY_SCALAR_FIELD(tleSortGroupRef);
	COPY_SCALAR_FIELD(sortop);

	return newnode;
}

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

	COPY_SCALAR_FIELD(tleSortGroupRef);
	COPY_SCALAR_FIELD(sortop);
1318

1319
	return newnode;
1320 1321
}

1322 1323 1324
static A_Expr *
_copyAExpr(A_Expr *from)
{
B
Bruce Momjian 已提交
1325
	A_Expr	   *newnode = makeNode(A_Expr);
1326

1327
	COPY_SCALAR_FIELD(kind);
1328 1329 1330
	COPY_NODE_FIELD(name);
	COPY_NODE_FIELD(lexpr);
	COPY_NODE_FIELD(rexpr);
1331 1332 1333 1334

	return newnode;
}

1335 1336
static ColumnRef *
_copyColumnRef(ColumnRef *from)
1337
{
B
Bruce Momjian 已提交
1338
	ColumnRef  *newnode = makeNode(ColumnRef);
1339

1340 1341
	COPY_NODE_FIELD(fields);
	COPY_NODE_FIELD(indirection);
1342

1343
	return newnode;
1344 1345
}

1346 1347
static ParamRef *
_copyParamRef(ParamRef *from)
1348
{
B
Bruce Momjian 已提交
1349
	ParamRef   *newnode = makeNode(ParamRef);
1350

1351 1352 1353
	COPY_SCALAR_FIELD(number);
	COPY_NODE_FIELD(fields);
	COPY_NODE_FIELD(indirection);
1354 1355 1356 1357

	return newnode;
}

1358 1359 1360 1361 1362
static A_Const *
_copyAConst(A_Const *from)
{
	A_Const    *newnode = makeNode(A_Const);

1363
	/* This part must duplicate _copyValue */
1364
	COPY_SCALAR_FIELD(val.type);
1365 1366 1367
	switch (from->val.type)
	{
		case T_Integer:
1368
			COPY_SCALAR_FIELD(val.val.ival);
1369 1370 1371 1372
			break;
		case T_Float:
		case T_String:
		case T_BitString:
1373
			COPY_STRING_FIELD(val.val.str);
1374 1375 1376 1377 1378
			break;
		case T_Null:
			/* nothing to do */
			break;
		default:
1379 1380
			elog(ERROR, "unrecognized node type: %d",
				 (int) from->val.type);
1381 1382 1383
			break;
	}

1384
	COPY_NODE_FIELD(typename);
1385 1386 1387 1388

	return newnode;
}

1389 1390 1391
static FuncCall *
_copyFuncCall(FuncCall *from)
{
B
Bruce Momjian 已提交
1392
	FuncCall   *newnode = makeNode(FuncCall);
1393

1394 1395 1396 1397
	COPY_NODE_FIELD(funcname);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(agg_star);
	COPY_SCALAR_FIELD(agg_distinct);
1398 1399 1400 1401 1402 1403 1404

	return newnode;
}

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

1407 1408
	COPY_NODE_FIELD(lidx);
	COPY_NODE_FIELD(uidx);
1409 1410 1411 1412

	return newnode;
}

1413 1414 1415
static ExprFieldSelect *
_copyExprFieldSelect(ExprFieldSelect *from)
{
B
Bruce Momjian 已提交
1416
	ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
1417

1418 1419 1420
	COPY_NODE_FIELD(arg);
	COPY_NODE_FIELD(fields);
	COPY_NODE_FIELD(indirection);
1421 1422 1423 1424

	return newnode;
}

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

1430 1431 1432
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(indirection);
	COPY_NODE_FIELD(val);
1433 1434 1435 1436

	return newnode;
}

1437
static TypeName *
1438
_copyTypeName(TypeName *from)
1439
{
1440
	TypeName   *newnode = makeNode(TypeName);
1441

1442 1443 1444 1445 1446 1447 1448
	COPY_NODE_FIELD(names);
	COPY_SCALAR_FIELD(typeid);
	COPY_SCALAR_FIELD(timezone);
	COPY_SCALAR_FIELD(setof);
	COPY_SCALAR_FIELD(pct_type);
	COPY_SCALAR_FIELD(typmod);
	COPY_NODE_FIELD(arrayBounds);
1449 1450

	return newnode;
1451 1452
}

1453 1454
static SortBy *
_copySortBy(SortBy *from)
1455
{
1456
	SortBy *newnode = makeNode(SortBy);
1457

1458
	COPY_SCALAR_FIELD(sortby_kind);
1459 1460
	COPY_NODE_FIELD(useOp);
	COPY_NODE_FIELD(node);
1461 1462 1463 1464 1465 1466 1467

	return newnode;
}

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

1470 1471
	COPY_NODE_FIELD(subquery);
	COPY_NODE_FIELD(alias);
1472 1473 1474 1475

	return newnode;
}

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

1481 1482 1483
	COPY_NODE_FIELD(funccallnode);
	COPY_NODE_FIELD(alias);
	COPY_NODE_FIELD(coldeflist);
1484 1485 1486 1487

	return newnode;
}

1488 1489 1490 1491 1492
static TypeCast *
_copyTypeCast(TypeCast *from)
{
	TypeCast   *newnode = makeNode(TypeCast);

1493 1494
	COPY_NODE_FIELD(arg);
	COPY_NODE_FIELD(typename);
1495 1496 1497 1498

	return newnode;
}

1499 1500 1501
static IndexElem *
_copyIndexElem(IndexElem *from)
{
B
Bruce Momjian 已提交
1502
	IndexElem  *newnode = makeNode(IndexElem);
1503

1504
	COPY_STRING_FIELD(name);
1505
	COPY_NODE_FIELD(expr);
1506
	COPY_NODE_FIELD(opclass);
1507 1508 1509 1510 1511 1512 1513

	return newnode;
}

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

1516 1517 1518 1519 1520 1521 1522 1523 1524
	COPY_STRING_FIELD(colname);
	COPY_NODE_FIELD(typename);
	COPY_SCALAR_FIELD(inhcount);
	COPY_SCALAR_FIELD(is_local);
	COPY_SCALAR_FIELD(is_not_null);
	COPY_NODE_FIELD(raw_default);
	COPY_STRING_FIELD(cooked_default);
	COPY_NODE_FIELD(constraints);
	COPY_NODE_FIELD(support);
1525 1526 1527 1528 1529 1530 1531

	return newnode;
}

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

1534 1535 1536 1537 1538
	COPY_SCALAR_FIELD(contype);
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(raw_expr);
	COPY_STRING_FIELD(cooked_expr);
	COPY_NODE_FIELD(keys);
1539 1540 1541 1542

	return newnode;
}

1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560
static DefElem *
_copyDefElem(DefElem *from)
{
	DefElem    *newnode = makeNode(DefElem);

	COPY_STRING_FIELD(defname);
	COPY_NODE_FIELD(arg);

	return newnode;
}

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

	COPY_SCALAR_FIELD(commandType);
	COPY_SCALAR_FIELD(querySource);
1561
	COPY_SCALAR_FIELD(canSetTag);
1562 1563 1564
	COPY_NODE_FIELD(utilityStmt);
	COPY_SCALAR_FIELD(resultRelation);
	COPY_NODE_FIELD(into);
1565
	COPY_SCALAR_FIELD(intoHasOids);
1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579
	COPY_SCALAR_FIELD(hasAggs);
	COPY_SCALAR_FIELD(hasSubLinks);
	COPY_NODE_FIELD(rtable);
	COPY_NODE_FIELD(jointree);
	COPY_INTLIST_FIELD(rowMarks);
	COPY_NODE_FIELD(targetList);
	COPY_NODE_FIELD(groupClause);
	COPY_NODE_FIELD(havingQual);
	COPY_NODE_FIELD(distinctClause);
	COPY_NODE_FIELD(sortClause);
	COPY_NODE_FIELD(limitOffset);
	COPY_NODE_FIELD(limitCount);
	COPY_NODE_FIELD(setOperations);
	COPY_INTLIST_FIELD(resultRelations);
1580 1581
	COPY_NODE_FIELD(in_info_list);
	COPY_SCALAR_FIELD(hasJoinRTEs);
1582

1583
	/*
1584
	 * We do not copy the other planner internal fields: base_rel_list,
B
Bruce Momjian 已提交
1585 1586 1587
	 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. That
	 * would get us into copying RelOptInfo/Path trees, which we don't
	 * want to do.	It is necessary to copy in_info_list and hasJoinRTEs
1588 1589
	 * for the benefit of inheritance_planner(), which may try to copy a
	 * Query in which these are already set.
1590
	 */
1591

1592
	return newnode;
1593 1594
}

1595 1596 1597 1598
static InsertStmt *
_copyInsertStmt(InsertStmt *from)
{
	InsertStmt *newnode = makeNode(InsertStmt);
B
Bruce Momjian 已提交
1599

1600 1601 1602 1603
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(cols);
	COPY_NODE_FIELD(targetList);
	COPY_NODE_FIELD(selectStmt);
1604 1605 1606 1607 1608 1609 1610 1611

	return newnode;
}

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

1613 1614
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(whereClause);
1615 1616 1617 1618 1619 1620 1621 1622

	return newnode;
}

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

1624 1625 1626 1627
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(targetList);
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(fromClause);
1628 1629 1630 1631 1632 1633 1634 1635

	return newnode;
}

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

1637 1638 1639
	COPY_NODE_FIELD(distinctClause);
	COPY_NODE_FIELD(into);
	COPY_NODE_FIELD(intoColNames);
1640
	COPY_SCALAR_FIELD(intoHasOids);
1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653
	COPY_NODE_FIELD(targetList);
	COPY_NODE_FIELD(fromClause);
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(groupClause);
	COPY_NODE_FIELD(havingClause);
	COPY_NODE_FIELD(sortClause);
	COPY_NODE_FIELD(limitOffset);
	COPY_NODE_FIELD(limitCount);
	COPY_NODE_FIELD(forUpdate);
	COPY_SCALAR_FIELD(op);
	COPY_SCALAR_FIELD(all);
	COPY_NODE_FIELD(larg);
	COPY_NODE_FIELD(rarg);
1654 1655 1656 1657

	return newnode;
}

1658 1659 1660 1661
static SetOperationStmt *
_copySetOperationStmt(SetOperationStmt *from)
{
	SetOperationStmt *newnode = makeNode(SetOperationStmt);
B
Bruce Momjian 已提交
1662

1663 1664 1665 1666
	COPY_SCALAR_FIELD(op);
	COPY_SCALAR_FIELD(all);
	COPY_NODE_FIELD(larg);
	COPY_NODE_FIELD(rarg);
1667
	COPY_OIDLIST_FIELD(colTypes);
1668 1669 1670 1671

	return newnode;
}

1672 1673 1674 1675
static AlterTableStmt *
_copyAlterTableStmt(AlterTableStmt *from)
{
	AlterTableStmt *newnode = makeNode(AlterTableStmt);
B
Bruce Momjian 已提交
1676

1677
	COPY_NODE_FIELD(relation);
T
Tom Lane 已提交
1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688
	COPY_NODE_FIELD(cmds);

	return newnode;
}

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

	COPY_SCALAR_FIELD(subtype);
1689 1690
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(def);
T
Tom Lane 已提交
1691
	COPY_NODE_FIELD(transform);
1692
	COPY_SCALAR_FIELD(behavior);
1693 1694 1695 1696

	return newnode;
}

B
Bruce Momjian 已提交
1697
static AlterDomainStmt *
1698
_copyAlterDomainStmt(AlterDomainStmt *from)
B
Bruce Momjian 已提交
1699 1700 1701 1702 1703 1704 1705 1706 1707 1708
{
	AlterDomainStmt *newnode = makeNode(AlterDomainStmt);

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

	return newnode;
B
Bruce Momjian 已提交
1709
}
B
Bruce Momjian 已提交
1710

1711 1712
static GrantStmt *
_copyGrantStmt(GrantStmt *from)
1713
{
1714
	GrantStmt  *newnode = makeNode(GrantStmt);
B
Bruce Momjian 已提交
1715

1716 1717 1718 1719 1720
	COPY_SCALAR_FIELD(is_grant);
	COPY_SCALAR_FIELD(objtype);
	COPY_NODE_FIELD(objects);
	COPY_INTLIST_FIELD(privileges);
	COPY_NODE_FIELD(grantees);
1721 1722
	COPY_SCALAR_FIELD(grant_option);
	COPY_SCALAR_FIELD(behavior);
1723 1724 1725 1726 1727 1728 1729 1730 1731

	return newnode;
}

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

1732 1733
	COPY_STRING_FIELD(username);
	COPY_STRING_FIELD(groupname);
1734 1735 1736 1737

	return newnode;
}

1738 1739 1740 1741 1742
static FuncWithArgs *
_copyFuncWithArgs(FuncWithArgs *from)
{
	FuncWithArgs *newnode = makeNode(FuncWithArgs);

1743 1744
	COPY_NODE_FIELD(funcname);
	COPY_NODE_FIELD(funcargs);
1745 1746 1747 1748

	return newnode;
}

1749
static DeclareCursorStmt *
1750
_copyDeclareCursorStmt(DeclareCursorStmt *from)
1751 1752 1753 1754 1755 1756 1757 1758 1759
{
	DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);

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

	return newnode;
}
B
Bruce Momjian 已提交
1760

1761 1762 1763
static ClosePortalStmt *
_copyClosePortalStmt(ClosePortalStmt *from)
{
1764
	ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1765

1766
	COPY_STRING_FIELD(portalname);
1767 1768 1769 1770

	return newnode;
}

1771 1772 1773 1774
static ClusterStmt *
_copyClusterStmt(ClusterStmt *from)
{
	ClusterStmt *newnode = makeNode(ClusterStmt);
B
Bruce Momjian 已提交
1775

1776 1777
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(indexname);
1778 1779 1780 1781 1782 1783 1784

	return newnode;
}

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

1787 1788 1789 1790 1791
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(attlist);
	COPY_SCALAR_FIELD(is_from);
	COPY_STRING_FIELD(filename);
	COPY_NODE_FIELD(options);
1792 1793 1794 1795 1796 1797 1798 1799

	return newnode;
}

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

1801 1802 1803 1804 1805 1806
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(tableElts);
	COPY_NODE_FIELD(inhRelations);
	COPY_NODE_FIELD(constraints);
	COPY_SCALAR_FIELD(hasoids);
	COPY_SCALAR_FIELD(oncommit);
1807 1808 1809 1810

	return newnode;
}

B
Bruce Momjian 已提交
1811
static InhRelation *
1812
_copyInhRelation(InhRelation *from)
B
Bruce Momjian 已提交
1813 1814 1815 1816 1817 1818 1819 1820 1821
{
	InhRelation *newnode = makeNode(InhRelation);

	COPY_NODE_FIELD(relation);
	COPY_SCALAR_FIELD(including_defaults);

	return newnode;
}

1822 1823 1824 1825
static DefineStmt *
_copyDefineStmt(DefineStmt *from)
{
	DefineStmt *newnode = makeNode(DefineStmt);
B
Bruce Momjian 已提交
1826

1827
	COPY_SCALAR_FIELD(kind);
1828 1829
	COPY_NODE_FIELD(defnames);
	COPY_NODE_FIELD(definition);
1830 1831 1832 1833 1834 1835 1836

	return newnode;
}

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

1839 1840 1841
	COPY_NODE_FIELD(objects);
	COPY_SCALAR_FIELD(removeType);
	COPY_SCALAR_FIELD(behavior);
1842 1843 1844 1845

	return newnode;
}

1846 1847 1848
static TruncateStmt *
_copyTruncateStmt(TruncateStmt *from)
{
1849
	TruncateStmt *newnode = makeNode(TruncateStmt);
1850

1851
	COPY_NODE_FIELD(relation);
1852 1853 1854 1855

	return newnode;
}

1856 1857 1858 1859
static CommentStmt *
_copyCommentStmt(CommentStmt *from)
{
	CommentStmt *newnode = makeNode(CommentStmt);
B
Bruce Momjian 已提交
1860

1861 1862 1863 1864
	COPY_SCALAR_FIELD(objtype);
	COPY_NODE_FIELD(objname);
	COPY_NODE_FIELD(objargs);
	COPY_STRING_FIELD(comment);
1865 1866 1867 1868 1869 1870 1871

	return newnode;
}

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

1874 1875 1876 1877
	COPY_SCALAR_FIELD(direction);
	COPY_SCALAR_FIELD(howMany);
	COPY_STRING_FIELD(portalname);
	COPY_SCALAR_FIELD(ismove);
1878 1879 1880 1881 1882 1883 1884

	return newnode;
}

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

1887 1888 1889 1890 1891 1892 1893 1894 1895
	COPY_STRING_FIELD(idxname);
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(accessMethod);
	COPY_NODE_FIELD(indexParams);
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(rangetable);
	COPY_SCALAR_FIELD(unique);
	COPY_SCALAR_FIELD(primary);
	COPY_SCALAR_FIELD(isconstraint);
1896 1897 1898 1899

	return newnode;
}

1900 1901
static CreateFunctionStmt *
_copyCreateFunctionStmt(CreateFunctionStmt *from)
1902
{
1903
	CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
B
Bruce Momjian 已提交
1904

1905 1906
	COPY_SCALAR_FIELD(replace);
	COPY_NODE_FIELD(funcname);
1907
	COPY_NODE_FIELD(parameters);
1908 1909 1910
	COPY_NODE_FIELD(returnType);
	COPY_NODE_FIELD(options);
	COPY_NODE_FIELD(withClause);
1911 1912 1913 1914

	return newnode;
}

1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925
static FunctionParameter *
_copyFunctionParameter(FunctionParameter *from)
{
	FunctionParameter *newnode = makeNode(FunctionParameter);

	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(argType);

	return newnode;
}

1926 1927 1928 1929
static RemoveAggrStmt *
_copyRemoveAggrStmt(RemoveAggrStmt *from)
{
	RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
B
Bruce Momjian 已提交
1930

1931 1932 1933
	COPY_NODE_FIELD(aggname);
	COPY_NODE_FIELD(aggtype);
	COPY_SCALAR_FIELD(behavior);
1934 1935 1936 1937 1938 1939 1940 1941

	return newnode;
}

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

1943 1944 1945
	COPY_NODE_FIELD(funcname);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(behavior);
1946 1947 1948 1949 1950 1951 1952 1953

	return newnode;
}

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

1955 1956 1957
	COPY_NODE_FIELD(opname);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(behavior);
1958 1959 1960 1961

	return newnode;
}

1962 1963 1964 1965 1966
static RemoveOpClassStmt *
_copyRemoveOpClassStmt(RemoveOpClassStmt *from)
{
	RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);

1967 1968 1969
	COPY_NODE_FIELD(opclassname);
	COPY_STRING_FIELD(amname);
	COPY_SCALAR_FIELD(behavior);
1970 1971 1972 1973

	return newnode;
}

1974 1975 1976 1977
static RenameStmt *
_copyRenameStmt(RenameStmt *from)
{
	RenameStmt *newnode = makeNode(RenameStmt);
B
Bruce Momjian 已提交
1978

1979
	COPY_NODE_FIELD(relation);
1980 1981 1982
	COPY_NODE_FIELD(object);
	COPY_NODE_FIELD(objarg);
	COPY_STRING_FIELD(subname);
1983 1984
	COPY_STRING_FIELD(newname);
	COPY_SCALAR_FIELD(renameType);
1985 1986 1987 1988 1989 1990 1991

	return newnode;
}

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

1994 1995 1996 1997 1998 1999 2000
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(rulename);
	COPY_NODE_FIELD(whereClause);
	COPY_SCALAR_FIELD(event);
	COPY_SCALAR_FIELD(instead);
	COPY_NODE_FIELD(actions);
	COPY_SCALAR_FIELD(replace);
2001 2002 2003 2004

	return newnode;
}

2005 2006 2007
static NotifyStmt *
_copyNotifyStmt(NotifyStmt *from)
{
2008
	NotifyStmt *newnode = makeNode(NotifyStmt);
2009

2010
	COPY_NODE_FIELD(relation);
2011 2012 2013 2014 2015 2016 2017

	return newnode;
}

static ListenStmt *
_copyListenStmt(ListenStmt *from)
{
2018
	ListenStmt *newnode = makeNode(ListenStmt);
2019

2020
	COPY_NODE_FIELD(relation);
2021 2022 2023 2024 2025 2026 2027

	return newnode;
}

static UnlistenStmt *
_copyUnlistenStmt(UnlistenStmt *from)
{
2028
	UnlistenStmt *newnode = makeNode(UnlistenStmt);
2029

2030
	COPY_NODE_FIELD(relation);
2031 2032 2033 2034 2035 2036 2037

	return newnode;
}

static TransactionStmt *
_copyTransactionStmt(TransactionStmt *from)
{
2038
	TransactionStmt *newnode = makeNode(TransactionStmt);
2039

2040
	COPY_SCALAR_FIELD(kind);
2041
	COPY_NODE_FIELD(options);
2042 2043 2044 2045

	return newnode;
}

B
Bruce Momjian 已提交
2046 2047 2048
static CompositeTypeStmt *
_copyCompositeTypeStmt(CompositeTypeStmt *from)
{
B
Bruce Momjian 已提交
2049
	CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
B
Bruce Momjian 已提交
2050

2051 2052
	COPY_NODE_FIELD(typevar);
	COPY_NODE_FIELD(coldeflist);
B
Bruce Momjian 已提交
2053 2054 2055 2056

	return newnode;
}

2057 2058 2059 2060 2061
static ViewStmt *
_copyViewStmt(ViewStmt *from)
{
	ViewStmt   *newnode = makeNode(ViewStmt);

2062 2063 2064 2065
	COPY_NODE_FIELD(view);
	COPY_NODE_FIELD(aliases);
	COPY_NODE_FIELD(query);
	COPY_SCALAR_FIELD(replace);
2066 2067 2068 2069

	return newnode;
}

2070 2071 2072
static LoadStmt *
_copyLoadStmt(LoadStmt *from)
{
2073
	LoadStmt   *newnode = makeNode(LoadStmt);
2074

2075
	COPY_STRING_FIELD(filename);
2076 2077 2078 2079

	return newnode;
}

2080 2081 2082 2083 2084
static CreateDomainStmt *
_copyCreateDomainStmt(CreateDomainStmt *from)
{
	CreateDomainStmt *newnode = makeNode(CreateDomainStmt);

2085 2086 2087
	COPY_NODE_FIELD(domainname);
	COPY_NODE_FIELD(typename);
	COPY_NODE_FIELD(constraints);
2088 2089 2090 2091

	return newnode;
}

2092 2093 2094 2095 2096
static CreateOpClassStmt *
_copyCreateOpClassStmt(CreateOpClassStmt *from)
{
	CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);

2097 2098 2099 2100 2101
	COPY_NODE_FIELD(opclassname);
	COPY_STRING_FIELD(amname);
	COPY_NODE_FIELD(datatype);
	COPY_NODE_FIELD(items);
	COPY_SCALAR_FIELD(isDefault);
2102 2103 2104 2105 2106 2107 2108 2109 2110

	return newnode;
}

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

2111 2112 2113 2114 2115 2116
	COPY_SCALAR_FIELD(itemtype);
	COPY_NODE_FIELD(name);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(number);
	COPY_SCALAR_FIELD(recheck);
	COPY_NODE_FIELD(storedtype);
2117 2118 2119 2120

	return newnode;
}

2121 2122 2123
static CreatedbStmt *
_copyCreatedbStmt(CreatedbStmt *from)
{
B
Bruce Momjian 已提交
2124
	CreatedbStmt *newnode = makeNode(CreatedbStmt);
2125

2126 2127
	COPY_STRING_FIELD(dbname);
	COPY_NODE_FIELD(options);
2128 2129 2130 2131

	return newnode;
}

2132 2133 2134 2135 2136
static AlterDatabaseSetStmt *
_copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
{
	AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);

2137 2138 2139
	COPY_STRING_FIELD(dbname);
	COPY_STRING_FIELD(variable);
	COPY_NODE_FIELD(value);
2140 2141 2142 2143

	return newnode;
}

2144 2145 2146
static DropdbStmt *
_copyDropdbStmt(DropdbStmt *from)
{
B
Bruce Momjian 已提交
2147
	DropdbStmt *newnode = makeNode(DropdbStmt);
2148

2149
	COPY_STRING_FIELD(dbname);
2150 2151 2152 2153 2154 2155 2156

	return newnode;
}

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

2159 2160 2161 2162 2163 2164 2165
	COPY_SCALAR_FIELD(vacuum);
	COPY_SCALAR_FIELD(full);
	COPY_SCALAR_FIELD(analyze);
	COPY_SCALAR_FIELD(freeze);
	COPY_SCALAR_FIELD(verbose);
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(va_cols);
2166 2167 2168 2169 2170 2171 2172

	return newnode;
}

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

2175 2176 2177
	COPY_NODE_FIELD(query);
	COPY_SCALAR_FIELD(verbose);
	COPY_SCALAR_FIELD(analyze);
2178 2179 2180 2181 2182 2183 2184

	return newnode;
}

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

2187 2188
	COPY_NODE_FIELD(sequence);
	COPY_NODE_FIELD(options);
2189 2190 2191 2192

	return newnode;
}

B
Bruce Momjian 已提交
2193
static AlterSeqStmt *
2194
_copyAlterSeqStmt(AlterSeqStmt *from)
B
Bruce Momjian 已提交
2195 2196 2197 2198 2199 2200 2201 2202 2203
{
	AlterSeqStmt *newnode = makeNode(AlterSeqStmt);

	COPY_NODE_FIELD(sequence);
	COPY_NODE_FIELD(options);

	return newnode;
}

2204 2205 2206
static VariableSetStmt *
_copyVariableSetStmt(VariableSetStmt *from)
{
2207
	VariableSetStmt *newnode = makeNode(VariableSetStmt);
2208

2209 2210 2211
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(is_local);
2212 2213 2214 2215

	return newnode;
}

2216 2217 2218 2219 2220
static VariableShowStmt *
_copyVariableShowStmt(VariableShowStmt *from)
{
	VariableShowStmt *newnode = makeNode(VariableShowStmt);

2221
	COPY_STRING_FIELD(name);
2222 2223 2224 2225

	return newnode;
}

2226 2227 2228
static VariableResetStmt *
_copyVariableResetStmt(VariableResetStmt *from)
{
2229
	VariableResetStmt *newnode = makeNode(VariableResetStmt);
2230

2231
	COPY_STRING_FIELD(name);
2232 2233 2234 2235

	return newnode;
}

2236 2237 2238 2239 2240
static CreateTrigStmt *
_copyCreateTrigStmt(CreateTrigStmt *from)
{
	CreateTrigStmt *newnode = makeNode(CreateTrigStmt);

2241 2242 2243 2244 2245 2246
	COPY_STRING_FIELD(trigname);
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(funcname);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(before);
	COPY_SCALAR_FIELD(row);
B
Bruce Momjian 已提交
2247
	strcpy(newnode->actions, from->actions);	/* in-line string field */
2248 2249 2250 2251
	COPY_SCALAR_FIELD(isconstraint);
	COPY_SCALAR_FIELD(deferrable);
	COPY_SCALAR_FIELD(initdeferred);
	COPY_NODE_FIELD(constrrel);
2252 2253 2254 2255

	return newnode;
}

2256 2257
static DropPropertyStmt *
_copyDropPropertyStmt(DropPropertyStmt *from)
2258
{
2259
	DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2260

2261 2262 2263 2264
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(property);
	COPY_SCALAR_FIELD(removeType);
	COPY_SCALAR_FIELD(behavior);
2265 2266 2267 2268 2269 2270 2271 2272 2273

	return newnode;
}

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

2274 2275 2276 2277
	COPY_STRING_FIELD(plname);
	COPY_NODE_FIELD(plhandler);
	COPY_NODE_FIELD(plvalidator);
	COPY_SCALAR_FIELD(pltrusted);
2278 2279 2280 2281 2282 2283 2284 2285 2286

	return newnode;
}

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

2287 2288
	COPY_STRING_FIELD(plname);
	COPY_SCALAR_FIELD(behavior);
2289 2290 2291 2292 2293 2294 2295 2296 2297

	return newnode;
}

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

2298 2299
	COPY_STRING_FIELD(user);
	COPY_NODE_FIELD(options);
2300 2301 2302 2303 2304 2305 2306 2307 2308

	return newnode;
}

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

2309 2310
	COPY_STRING_FIELD(user);
	COPY_NODE_FIELD(options);
2311 2312 2313 2314

	return newnode;
}

2315 2316 2317 2318 2319
static AlterUserSetStmt *
_copyAlterUserSetStmt(AlterUserSetStmt *from)
{
	AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);

2320 2321 2322
	COPY_STRING_FIELD(user);
	COPY_STRING_FIELD(variable);
	COPY_NODE_FIELD(value);
2323 2324 2325 2326

	return newnode;
}

2327 2328 2329 2330 2331
static DropUserStmt *
_copyDropUserStmt(DropUserStmt *from)
{
	DropUserStmt *newnode = makeNode(DropUserStmt);

2332
	COPY_NODE_FIELD(users);
2333 2334 2335 2336

	return newnode;
}

2337 2338 2339
static LockStmt *
_copyLockStmt(LockStmt *from)
{
2340
	LockStmt   *newnode = makeNode(LockStmt);
2341

2342 2343
	COPY_NODE_FIELD(relations);
	COPY_SCALAR_FIELD(mode);
T
Tatsuo Ishii 已提交
2344
	COPY_SCALAR_FIELD(nowait);
2345 2346 2347

	return newnode;
}
2348

2349 2350 2351
static ConstraintsSetStmt *
_copyConstraintsSetStmt(ConstraintsSetStmt *from)
{
B
Bruce Momjian 已提交
2352
	ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2353

2354 2355
	COPY_NODE_FIELD(constraints);
	COPY_SCALAR_FIELD(deferred);
2356 2357 2358 2359 2360 2361 2362

	return newnode;
}

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

2365 2366
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(options);
2367 2368 2369 2370 2371 2372 2373

	return newnode;
}

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

2376 2377 2378
	COPY_STRING_FIELD(name);
	COPY_SCALAR_FIELD(action);
	COPY_NODE_FIELD(listUsers);
2379 2380 2381 2382 2383 2384 2385

	return newnode;
}

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

2388
	COPY_STRING_FIELD(name);
2389 2390 2391 2392 2393 2394 2395

	return newnode;
}

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

2398
	COPY_SCALAR_FIELD(kind);
2399 2400 2401 2402
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(name);
	COPY_SCALAR_FIELD(force);
	COPY_SCALAR_FIELD(all);
2403 2404 2405 2406

	return newnode;
}

2407 2408 2409 2410 2411
static CreateSchemaStmt *
_copyCreateSchemaStmt(CreateSchemaStmt *from)
{
	CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);

2412 2413 2414
	COPY_STRING_FIELD(schemaname);
	COPY_STRING_FIELD(authid);
	COPY_NODE_FIELD(schemaElts);
2415 2416 2417 2418

	return newnode;
}

2419 2420 2421 2422 2423
static CreateConversionStmt *
_copyCreateConversionStmt(CreateConversionStmt *from)
{
	CreateConversionStmt *newnode = makeNode(CreateConversionStmt);

2424 2425 2426 2427 2428
	COPY_NODE_FIELD(conversion_name);
	COPY_STRING_FIELD(for_encoding_name);
	COPY_STRING_FIELD(to_encoding_name);
	COPY_NODE_FIELD(func_name);
	COPY_SCALAR_FIELD(def);
2429 2430 2431 2432 2433 2434 2435 2436 2437

	return newnode;
}

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

2438 2439 2440 2441
	COPY_NODE_FIELD(sourcetype);
	COPY_NODE_FIELD(targettype);
	COPY_NODE_FIELD(func);
	COPY_SCALAR_FIELD(context);
2442 2443 2444 2445 2446 2447 2448 2449 2450

	return newnode;
}

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

2451 2452 2453
	COPY_NODE_FIELD(sourcetype);
	COPY_NODE_FIELD(targettype);
	COPY_SCALAR_FIELD(behavior);
2454 2455 2456 2457

	return newnode;
}

2458 2459 2460 2461 2462
static PrepareStmt *
_copyPrepareStmt(PrepareStmt *from)
{
	PrepareStmt *newnode = makeNode(PrepareStmt);

2463 2464
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(argtypes);
2465
	COPY_OIDLIST_FIELD(argtype_oids);
2466
	COPY_NODE_FIELD(query);
2467 2468 2469 2470 2471 2472 2473 2474 2475

	return newnode;
}

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

2476 2477 2478
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(into);
	COPY_NODE_FIELD(params);
2479 2480 2481 2482 2483 2484 2485 2486 2487

	return newnode;
}

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

2488
	COPY_STRING_FIELD(name);
2489 2490 2491 2492

	return newnode;
}

2493 2494

/* ****************************************************************
2495
 *					pg_list.h copy functions
2496 2497 2498
 * ****************************************************************
 */

2499
static Value *
2500
_copyValue(Value *from)
2501
{
2502
	Value	   *newnode = makeNode(Value);
2503

2504 2505
	/* See also _copyAConst when changing this code! */

2506
	COPY_SCALAR_FIELD(type);
2507 2508
	switch (from->type)
	{
2509
		case T_Integer:
2510
			COPY_SCALAR_FIELD(val.ival);
2511 2512
			break;
		case T_Float:
2513
		case T_String:
2514
		case T_BitString:
2515
			COPY_STRING_FIELD(val.str);
2516
			break;
2517 2518 2519
		case T_Null:
			/* nothing to do */
			break;
2520
		default:
2521 2522
			elog(ERROR, "unrecognized node type: %d",
				 (int) from->type);
2523
			break;
2524 2525
	}
	return newnode;
2526 2527
}

2528 2529 2530 2531 2532
/*
 * copyObject
 *
 * Create a copy of a Node tree or list.  This is a "deep" copy: all
 * substructure is copied too, recursively.
2533
 */
2534
void *
2535 2536
copyObject(void *from)
{
2537
	void	   *retval;
2538

2539 2540
	if (from == NULL)
		return NULL;
2541

2542
	switch (nodeTag(from))
2543
	{
2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564
			/*
			 * 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;
2565 2566 2567
		case T_TidScan:
			retval = _copyTidScan(from);
			break;
2568 2569 2570
		case T_SubqueryScan:
			retval = _copySubqueryScan(from);
			break;
2571 2572 2573
		case T_FunctionScan:
			retval = _copyFunctionScan(from);
			break;
2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591
		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 已提交
2592 2593 2594
		case T_Group:
			retval = _copyGroup(from);
			break;
2595 2596 2597 2598 2599 2600
		case T_Agg:
			retval = _copyAgg(from);
			break;
		case T_Unique:
			retval = _copyUnique(from);
			break;
2601 2602 2603
		case T_Hash:
			retval = _copyHash(from);
			break;
2604 2605 2606
		case T_SetOp:
			retval = _copySetOp(from);
			break;
2607 2608 2609
		case T_Limit:
			retval = _copyLimit(from);
			break;
2610 2611 2612 2613 2614 2615 2616

			/*
			 * PRIMITIVE NODES
			 */
		case T_Resdom:
			retval = _copyResdom(from);
			break;
2617 2618 2619 2620 2621 2622
		case T_Alias:
			retval = _copyAlias(from);
			break;
		case T_RangeVar:
			retval = _copyRangeVar(from);
			break;
2623 2624 2625 2626 2627 2628 2629 2630 2631
		case T_Var:
			retval = _copyVar(from);
			break;
		case T_Const:
			retval = _copyConst(from);
			break;
		case T_Param:
			retval = _copyParam(from);
			break;
2632 2633 2634
		case T_Aggref:
			retval = _copyAggref(from);
			break;
2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646
		case T_ArrayRef:
			retval = _copyArrayRef(from);
			break;
		case T_FuncExpr:
			retval = _copyFuncExpr(from);
			break;
		case T_OpExpr:
			retval = _copyOpExpr(from);
			break;
		case T_DistinctExpr:
			retval = _copyDistinctExpr(from);
			break;
2647 2648 2649
		case T_ScalarArrayOpExpr:
			retval = _copyScalarArrayOpExpr(from);
			break;
2650 2651 2652
		case T_BoolExpr:
			retval = _copyBoolExpr(from);
			break;
2653 2654 2655
		case T_SubLink:
			retval = _copySubLink(from);
			break;
2656 2657
		case T_SubPlan:
			retval = _copySubPlan(from);
2658
			break;
2659 2660 2661
		case T_FieldSelect:
			retval = _copyFieldSelect(from);
			break;
2662 2663 2664
		case T_RelabelType:
			retval = _copyRelabelType(from);
			break;
2665 2666 2667 2668 2669 2670
		case T_CaseExpr:
			retval = _copyCaseExpr(from);
			break;
		case T_CaseWhen:
			retval = _copyCaseWhen(from);
			break;
2671 2672 2673
		case T_CaseTestExpr:
			retval = _copyCaseTestExpr(from);
			break;
2674 2675 2676
		case T_ArrayExpr:
			retval = _copyArrayExpr(from);
			break;
2677 2678 2679 2680 2681 2682
		case T_CoalesceExpr:
			retval = _copyCoalesceExpr(from);
			break;
		case T_NullIfExpr:
			retval = _copyNullIfExpr(from);
			break;
2683 2684 2685 2686 2687 2688
		case T_NullTest:
			retval = _copyNullTest(from);
			break;
		case T_BooleanTest:
			retval = _copyBooleanTest(from);
			break;
2689 2690
		case T_CoerceToDomain:
			retval = _copyCoerceToDomain(from);
2691
			break;
2692 2693
		case T_CoerceToDomainValue:
			retval = _copyCoerceToDomainValue(from);
2694
			break;
2695 2696 2697
		case T_SetToDefault:
			retval = _copySetToDefault(from);
			break;
2698 2699 2700
		case T_TargetEntry:
			retval = _copyTargetEntry(from);
			break;
2701 2702 2703
		case T_RangeTblRef:
			retval = _copyRangeTblRef(from);
			break;
2704 2705 2706
		case T_JoinExpr:
			retval = _copyJoinExpr(from);
			break;
2707 2708 2709
		case T_FromExpr:
			retval = _copyFromExpr(from);
			break;
2710 2711 2712 2713

			/*
			 * RELATION NODES
			 */
2714 2715
		case T_PathKeyItem:
			retval = _copyPathKeyItem(from);
2716
			break;
2717 2718
		case T_RestrictInfo:
			retval = _copyRestrictInfo(from);
2719
			break;
2720 2721
		case T_JoinInfo:
			retval = _copyJoinInfo(from);
2722
			break;
2723 2724 2725
		case T_InClauseInfo:
			retval = _copyInClauseInfo(from);
			break;
2726 2727

			/*
2728
			 * VALUE NODES
2729
			 */
2730 2731 2732
		case T_Integer:
		case T_Float:
		case T_String:
2733
		case T_BitString:
2734
		case T_Null:
2735
			retval = _copyValue(from);
2736
			break;
2737 2738 2739
		case T_List:
			{
				List	   *list = from,
2740 2741 2742
						   *oldl,
						   *newcell,
						   *prev;
2743 2744 2745

				/* rather ugly coding for speed... */
				/* Note the input list cannot be NIL if we got here. */
2746 2747 2748 2749 2750
				newcell = makeNode(List);
				lfirst(newcell) = copyObject(lfirst(list));

				retval = (void *) newcell;
				prev = newcell;
2751

2752
				foreach(oldl, lnext(list))
2753
				{
2754 2755 2756 2757
					newcell = makeNode(List);
					lfirst(newcell) = copyObject(lfirst(oldl));
					prev->next = newcell;
					prev = newcell;
2758
				}
2759
				prev->next = NIL;
2760
			}
2761
			break;
2762 2763 2764 2765

			/*
			 * PARSE NODES
			 */
2766 2767 2768
		case T_Query:
			retval = _copyQuery(from);
			break;
2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780
		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;
2781 2782 2783
		case T_SetOperationStmt:
			retval = _copySetOperationStmt(from);
			break;
2784 2785 2786
		case T_AlterTableStmt:
			retval = _copyAlterTableStmt(from);
			break;
T
Tom Lane 已提交
2787 2788 2789
		case T_AlterTableCmd:
			retval = _copyAlterTableCmd(from);
			break;
B
Bruce Momjian 已提交
2790 2791 2792
		case T_AlterDomainStmt:
			retval = _copyAlterDomainStmt(from);
			break;
2793 2794
		case T_GrantStmt:
			retval = _copyGrantStmt(from);
2795
			break;
2796 2797 2798
		case T_DeclareCursorStmt:
			retval = _copyDeclareCursorStmt(from);
			break;
2799 2800 2801
		case T_ClosePortalStmt:
			retval = _copyClosePortalStmt(from);
			break;
2802 2803 2804 2805 2806 2807 2808 2809 2810
		case T_ClusterStmt:
			retval = _copyClusterStmt(from);
			break;
		case T_CopyStmt:
			retval = _copyCopyStmt(from);
			break;
		case T_CreateStmt:
			retval = _copyCreateStmt(from);
			break;
B
Bruce Momjian 已提交
2811 2812 2813
		case T_InhRelation:
			retval = _copyInhRelation(from);
			break;
2814 2815 2816 2817 2818 2819
		case T_DefineStmt:
			retval = _copyDefineStmt(from);
			break;
		case T_DropStmt:
			retval = _copyDropStmt(from);
			break;
2820 2821 2822
		case T_TruncateStmt:
			retval = _copyTruncateStmt(from);
			break;
2823 2824 2825 2826 2827 2828 2829 2830 2831
		case T_CommentStmt:
			retval = _copyCommentStmt(from);
			break;
		case T_FetchStmt:
			retval = _copyFetchStmt(from);
			break;
		case T_IndexStmt:
			retval = _copyIndexStmt(from);
			break;
2832 2833
		case T_CreateFunctionStmt:
			retval = _copyCreateFunctionStmt(from);
2834
			break;
2835 2836 2837
		case T_FunctionParameter:
			retval = _copyFunctionParameter(from);
			break;
2838 2839 2840 2841 2842 2843 2844 2845 2846
		case T_RemoveAggrStmt:
			retval = _copyRemoveAggrStmt(from);
			break;
		case T_RemoveFuncStmt:
			retval = _copyRemoveFuncStmt(from);
			break;
		case T_RemoveOperStmt:
			retval = _copyRemoveOperStmt(from);
			break;
2847 2848 2849
		case T_RemoveOpClassStmt:
			retval = _copyRemoveOpClassStmt(from);
			break;
2850 2851 2852 2853 2854 2855
		case T_RenameStmt:
			retval = _copyRenameStmt(from);
			break;
		case T_RuleStmt:
			retval = _copyRuleStmt(from);
			break;
2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867
		case T_NotifyStmt:
			retval = _copyNotifyStmt(from);
			break;
		case T_ListenStmt:
			retval = _copyListenStmt(from);
			break;
		case T_UnlistenStmt:
			retval = _copyUnlistenStmt(from);
			break;
		case T_TransactionStmt:
			retval = _copyTransactionStmt(from);
			break;
B
Bruce Momjian 已提交
2868 2869 2870
		case T_CompositeTypeStmt:
			retval = _copyCompositeTypeStmt(from);
			break;
2871 2872 2873
		case T_ViewStmt:
			retval = _copyViewStmt(from);
			break;
2874 2875 2876
		case T_LoadStmt:
			retval = _copyLoadStmt(from);
			break;
2877 2878 2879
		case T_CreateDomainStmt:
			retval = _copyCreateDomainStmt(from);
			break;
2880 2881 2882 2883 2884 2885
		case T_CreateOpClassStmt:
			retval = _copyCreateOpClassStmt(from);
			break;
		case T_CreateOpClassItem:
			retval = _copyCreateOpClassItem(from);
			break;
2886 2887 2888
		case T_CreatedbStmt:
			retval = _copyCreatedbStmt(from);
			break;
2889 2890 2891
		case T_AlterDatabaseSetStmt:
			retval = _copyAlterDatabaseSetStmt(from);
			break;
2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903
		case T_DropdbStmt:
			retval = _copyDropdbStmt(from);
			break;
		case T_VacuumStmt:
			retval = _copyVacuumStmt(from);
			break;
		case T_ExplainStmt:
			retval = _copyExplainStmt(from);
			break;
		case T_CreateSeqStmt:
			retval = _copyCreateSeqStmt(from);
			break;
B
Bruce Momjian 已提交
2904 2905 2906
		case T_AlterSeqStmt:
			retval = _copyAlterSeqStmt(from);
			break;
2907 2908 2909
		case T_VariableSetStmt:
			retval = _copyVariableSetStmt(from);
			break;
2910 2911 2912
		case T_VariableShowStmt:
			retval = _copyVariableShowStmt(from);
			break;
2913 2914 2915
		case T_VariableResetStmt:
			retval = _copyVariableResetStmt(from);
			break;
2916 2917 2918
		case T_CreateTrigStmt:
			retval = _copyCreateTrigStmt(from);
			break;
2919 2920
		case T_DropPropertyStmt:
			retval = _copyDropPropertyStmt(from);
2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933
			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;
2934 2935 2936
		case T_AlterUserSetStmt:
			retval = _copyAlterUserSetStmt(from);
			break;
2937 2938 2939
		case T_DropUserStmt:
			retval = _copyDropUserStmt(from);
			break;
2940 2941 2942
		case T_LockStmt:
			retval = _copyLockStmt(from);
			break;
2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957
		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 已提交
2958
		case T_CheckPointStmt:
B
Bruce Momjian 已提交
2959
			retval = (void *) makeNode(CheckPointStmt);
V
Vadim B. Mikheev 已提交
2960
			break;
2961 2962 2963
		case T_CreateSchemaStmt:
			retval = _copyCreateSchemaStmt(from);
			break;
2964 2965 2966 2967 2968 2969 2970 2971 2972
		case T_CreateConversionStmt:
			retval = _copyCreateConversionStmt(from);
			break;
		case T_CreateCastStmt:
			retval = _copyCreateCastStmt(from);
			break;
		case T_DropCastStmt:
			retval = _copyDropCastStmt(from);
			break;
2973 2974 2975 2976 2977 2978 2979 2980 2981
		case T_PrepareStmt:
			retval = _copyPrepareStmt(from);
			break;
		case T_ExecuteStmt:
			retval = _copyExecuteStmt(from);
			break;
		case T_DeallocateStmt:
			retval = _copyDeallocateStmt(from);
			break;
2982

2983 2984 2985
		case T_A_Expr:
			retval = _copyAExpr(from);
			break;
2986 2987 2988 2989 2990
		case T_ColumnRef:
			retval = _copyColumnRef(from);
			break;
		case T_ParamRef:
			retval = _copyParamRef(from);
2991
			break;
2992 2993 2994
		case T_A_Const:
			retval = _copyAConst(from);
			break;
2995 2996 2997 2998 2999 3000
		case T_FuncCall:
			retval = _copyFuncCall(from);
			break;
		case T_A_Indices:
			retval = _copyAIndices(from);
			break;
3001 3002 3003
		case T_ExprFieldSelect:
			retval = _copyExprFieldSelect(from);
			break;
3004 3005 3006
		case T_ResTarget:
			retval = _copyResTarget(from);
			break;
3007 3008 3009
		case T_TypeCast:
			retval = _copyTypeCast(from);
			break;
3010 3011
		case T_SortBy:
			retval = _copySortBy(from);
3012
			break;
3013 3014 3015
		case T_RangeSubselect:
			retval = _copyRangeSubselect(from);
			break;
3016 3017 3018
		case T_RangeFunction:
			retval = _copyRangeFunction(from);
			break;
3019 3020 3021
		case T_TypeName:
			retval = _copyTypeName(from);
			break;
3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033
		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;
3034 3035
		case T_RangeTblEntry:
			retval = _copyRangeTblEntry(from);
3036
			break;
3037 3038 3039 3040 3041 3042
		case T_SortClause:
			retval = _copySortClause(from);
			break;
		case T_GroupClause:
			retval = _copyGroupClause(from);
			break;
3043 3044 3045
		case T_FkConstraint:
			retval = _copyFkConstraint(from);
			break;
3046 3047 3048
		case T_PrivGrantee:
			retval = _copyPrivGrantee(from);
			break;
3049 3050 3051
		case T_FuncWithArgs:
			retval = _copyFuncWithArgs(from);
			break;
3052

3053
		default:
3054
			elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
3055
			retval = from;		/* keep compiler quiet */
3056
			break;
3057
	}
3058

3059
	return retval;
3060
}