copyfuncs.c 59.4 KB
Newer Older
1
/*-------------------------------------------------------------------------
2
 *
3
 * copyfuncs.c
4
 *	  Copy functions for Postgres tree nodes.
5
 *
6
 * NOTE: we currently support copying all node types found in parse and
B
Bruce Momjian 已提交
7
 * plan trees.	We do not support copying executor state trees; there
8 9 10 11
 * is no need for that, and no point in maintaining all the code that
 * would be needed.  We also do not support copying Path trees, mainly
 * because the circular linkages between RelOptInfo and Path nodes can't
 * be handled easily in a simple depth-first traversal.
12 13
 *
 *
P
 
PostgreSQL Daemon 已提交
14
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
B
Add:  
Bruce Momjian 已提交
15
 * Portions Copyright (c) 1994, Regents of the University of California
16 17
 *
 * IDENTIFICATION
18
 *	  $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.311 2005/07/02 23:00:39 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

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

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

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

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
 */
static void
75
CopyPlanFields(Plan *from, Plan *newnode)
76
{
77 78 79 80 81 82 83 84
	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);
85
	COPY_NODE_FIELD(initPlan);
86 87
	COPY_BITMAPSET_FIELD(extParam);
	COPY_BITMAPSET_FIELD(allParam);
88
	COPY_SCALAR_FIELD(nParamExec);
89 90
}

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

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

	return newnode;
105 106 107
}


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

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

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

	return newnode;
127 128
}

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

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

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

	return newnode;
149 150
}

151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
/*
 * _copyBitmapAnd
 */
static BitmapAnd *
_copyBitmapAnd(BitmapAnd *from)
{
	BitmapAnd	   *newnode = makeNode(BitmapAnd);

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

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

	return newnode;
}

/*
 * _copyBitmapOr
 */
static BitmapOr *
_copyBitmapOr(BitmapOr *from)
{
	BitmapOr	   *newnode = makeNode(BitmapOr);

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

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

	return newnode;
}

193

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

	COPY_SCALAR_FIELD(scanrelid);
206 207
}

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

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

	return newnode;
222 223
}

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

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

	return newnode;
238 239
}

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

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

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

	return newnode;
264 265
}

266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
/*
 * _copyBitmapIndexScan
 */
static BitmapIndexScan *
_copyBitmapIndexScan(BitmapIndexScan *from)
{
	BitmapIndexScan  *newnode = makeNode(BitmapIndexScan);

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

	/*
	 * copy remainder of node
	 */
282 283 284 285 286
	COPY_SCALAR_FIELD(indexid);
	COPY_NODE_FIELD(indexqual);
	COPY_NODE_FIELD(indexqualorig);
	COPY_NODE_FIELD(indexstrategy);
	COPY_NODE_FIELD(indexsubtype);
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311

	return newnode;
}

/*
 * _copyBitmapHeapScan
 */
static BitmapHeapScan *
_copyBitmapHeapScan(BitmapHeapScan *from)
{
	BitmapHeapScan  *newnode = makeNode(BitmapHeapScan);

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

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

	return newnode;
}

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

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

	/*
	 * copy remainder of node
327
	 */
328 329
	COPY_NODE_FIELD(tideval);

330 331 332
	return newnode;
}

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

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

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

	return newnode;
}

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

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

	return newnode;
}
369

370 371
/*
 * CopyJoinFields
372
 *
373 374
 *		This function copies the fields of the Join node.  It is used by
 *		all the copy functions for classes which inherit from Join.
375 376
 */
static void
377
CopyJoinFields(Join *from, Join *newnode)
378
{
379 380 381 382
	CopyPlanFields((Plan *) from, (Plan *) newnode);

	COPY_SCALAR_FIELD(jointype);
	COPY_NODE_FIELD(joinqual);
383 384 385
}


386 387
/*
 * _copyJoin
388
 */
389
static Join *
390
_copyJoin(Join *from)
391
{
392
	Join	   *newnode = makeNode(Join);
393

394 395
	/*
	 * copy node superclass fields
396 397 398 399
	 */
	CopyJoinFields(from, newnode);

	return newnode;
400 401 402
}


403 404
/*
 * _copyNestLoop
405 406
 */
static NestLoop *
407
_copyNestLoop(NestLoop *from)
408
{
409
	NestLoop   *newnode = makeNode(NestLoop);
410

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

	return newnode;
417 418 419
}


420 421
/*
 * _copyMergeJoin
422 423
 */
static MergeJoin *
424
_copyMergeJoin(MergeJoin *from)
425
{
426
	MergeJoin  *newnode = makeNode(MergeJoin);
427

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

433 434
	/*
	 * copy remainder of node
435
	 */
436
	COPY_NODE_FIELD(mergeclauses);
437 438

	return newnode;
439 440
}

441 442
/*
 * _copyHashJoin
443 444
 */
static HashJoin *
445
_copyHashJoin(HashJoin *from)
446
{
447
	HashJoin   *newnode = makeNode(HashJoin);
448

449 450
	/*
	 * copy node superclass fields
451 452 453
	 */
	CopyJoinFields((Join *) from, (Join *) newnode);

454 455
	/*
	 * copy remainder of node
456
	 */
457
	COPY_NODE_FIELD(hashclauses);
458 459

	return newnode;
460 461 462
}


463 464
/*
 * _copyMaterial
465 466
 */
static Material *
467
_copyMaterial(Material *from)
468
{
469
	Material   *newnode = makeNode(Material);
470

471 472
	/*
	 * copy node superclass fields
473 474 475 476
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

	return newnode;
477 478 479
}


480 481
/*
 * _copySort
482
 */
483
static Sort *
484
_copySort(Sort *from)
485
{
486
	Sort	   *newnode = makeNode(Sort);
487

488 489
	/*
	 * copy node superclass fields
490 491
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
492

493 494 495
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
	COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
496 497

	return newnode;
498 499
}

V
Vadim B. Mikheev 已提交
500

501 502
/*
 * _copyGroup
V
Vadim B. Mikheev 已提交
503 504 505 506 507
 */
static Group *
_copyGroup(Group *from)
{
	Group	   *newnode = makeNode(Group);
508

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

511 512
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
V
Vadim B. Mikheev 已提交
513 514 515 516

	return newnode;
}

517 518
/*
 * _copyAgg
519
 */
520
static Agg *
B
Bruce Momjian 已提交
521
_copyAgg(Agg *from)
522
{
523
	Agg		   *newnode = makeNode(Agg);
524 525 526

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

527 528
	COPY_SCALAR_FIELD(aggstrategy);
	COPY_SCALAR_FIELD(numCols);
529
	if (from->numCols > 0)
530 531
		COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
	COPY_SCALAR_FIELD(numGroups);
532

533
	return newnode;
534 535
}

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

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

549 550
	/*
	 * copy remainder of node
551
	 */
552 553
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
554 555

	return newnode;
556 557
}

558
/*
559
 * _copyHash
560
 */
561 562
static Hash *
_copyHash(Hash *from)
563
{
564
	Hash	   *newnode = makeNode(Hash);
565

566 567
	/*
	 * copy node superclass fields
568 569 570
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

571 572
	/*
	 * copy remainder of node
573 574 575 576
	 */

	return newnode;
}
577

578
/*
579
 * _copySetOp
580
 */
581 582
static SetOp *
_copySetOp(SetOp *from)
583
{
584
	SetOp	   *newnode = makeNode(SetOp);
585

586 587
	/*
	 * copy node superclass fields
588 589 590
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

591 592
	/*
	 * copy remainder of node
593
	 */
594 595 596 597
	COPY_SCALAR_FIELD(cmd);
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
	COPY_SCALAR_FIELD(flagColIdx);
598 599 600 601

	return newnode;
}

602
/*
603
 * _copyLimit
604
 */
605 606
static Limit *
_copyLimit(Limit *from)
607
{
608
	Limit	   *newnode = makeNode(Limit);
609

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

615 616
	/*
	 * copy remainder of node
617
	 */
618 619
	COPY_NODE_FIELD(limitOffset);
	COPY_NODE_FIELD(limitCount);
620 621

	return newnode;
622 623 624
}

/* ****************************************************************
625
 *					   primnodes.h copy functions
626 627 628
 * ****************************************************************
 */

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

637 638
	COPY_STRING_FIELD(aliasname);
	COPY_NODE_FIELD(colnames);
639

640 641
	return newnode;
}
642

643 644 645
/*
 * _copyRangeVar
 */
646 647 648 649 650 651 652 653 654 655 656
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);
657 658

	return newnode;
659 660
}

661
/*
662
 * We don't need a _copyExpr because Expr is an abstract supertype which
B
Bruce Momjian 已提交
663
 * should never actually get instantiated.	Also, since it has no common
664 665
 * fields except NodeTag, there's no need for a helper routine to factor
 * out copying the common fields...
666 667
 */

668 669
/*
 * _copyVar
670
 */
671
static Var *
672
_copyVar(Var *from)
673
{
674
	Var		   *newnode = makeNode(Var);
675

676 677 678 679 680 681 682
	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);
683 684

	return newnode;
685 686
}

687 688
/*
 * _copyConst
689
 */
690
static Const *
691
_copyConst(Const *from)
692
{
693
	Const	   *newnode = makeNode(Const);
694

695 696
	COPY_SCALAR_FIELD(consttype);
	COPY_SCALAR_FIELD(constlen);
697

698
	if (from->constbyval || from->constisnull)
699
	{
700 701 702
		/*
		 * passed by value so just copy the datum. Also, don't try to copy
		 * struct when value is null!
703
		 */
704
		newnode->constvalue = from->constvalue;
705
	}
706
	else
707
	{
708
		/*
709
		 * passed by reference.  We need a palloc'd copy.
710
		 */
711 712 713
		newnode->constvalue = datumCopy(from->constvalue,
										from->constbyval,
										from->constlen);
714
	}
715

716 717
	COPY_SCALAR_FIELD(constisnull);
	COPY_SCALAR_FIELD(constbyval);
718 719

	return newnode;
720 721
}

722 723
/*
 * _copyParam
724
 */
725
static Param *
726
_copyParam(Param *from)
727
{
728
	Param	   *newnode = makeNode(Param);
729

730 731 732 733
	COPY_SCALAR_FIELD(paramkind);
	COPY_SCALAR_FIELD(paramid);
	COPY_STRING_FIELD(paramname);
	COPY_SCALAR_FIELD(paramtype);
734 735

	return newnode;
736 737
}

738
/*
739
 * _copyAggref
740
 */
741 742
static Aggref *
_copyAggref(Aggref *from)
743
{
744 745 746 747 748
	Aggref	   *newnode = makeNode(Aggref);

	COPY_SCALAR_FIELD(aggfnoid);
	COPY_SCALAR_FIELD(aggtype);
	COPY_NODE_FIELD(target);
749
	COPY_SCALAR_FIELD(agglevelsup);
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764
	COPY_SCALAR_FIELD(aggstar);
	COPY_SCALAR_FIELD(aggdistinct);

	return newnode;
}

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

	COPY_SCALAR_FIELD(refrestype);
765 766
	COPY_SCALAR_FIELD(refarraytype);
	COPY_SCALAR_FIELD(refelemtype);
767 768 769 770 771 772 773 774 775 776 777 778
	COPY_NODE_FIELD(refupperindexpr);
	COPY_NODE_FIELD(reflowerindexpr);
	COPY_NODE_FIELD(refexpr);
	COPY_NODE_FIELD(refassgnexpr);

	return newnode;
}

/*
 * _copyFuncExpr
 */
static FuncExpr *
779
_copyFuncExpr(FuncExpr *from)
780
{
B
Bruce Momjian 已提交
781
	FuncExpr   *newnode = makeNode(FuncExpr);
782

783 784 785 786
	COPY_SCALAR_FIELD(funcid);
	COPY_SCALAR_FIELD(funcresulttype);
	COPY_SCALAR_FIELD(funcretset);
	COPY_SCALAR_FIELD(funcformat);
787
	COPY_NODE_FIELD(args);
788

789
	return newnode;
790 791
}

792
/*
793
 * _copyOpExpr
794
 */
795
static OpExpr *
796
_copyOpExpr(OpExpr *from)
797
{
798
	OpExpr	   *newnode = makeNode(OpExpr);
799

800 801 802 803 804 805 806 807 808 809
	COPY_SCALAR_FIELD(opno);
	COPY_SCALAR_FIELD(opfuncid);
	COPY_SCALAR_FIELD(opresulttype);
	COPY_SCALAR_FIELD(opretset);
	COPY_NODE_FIELD(args);

	return newnode;
}

/*
810
 * _copyDistinctExpr (same as OpExpr)
811 812
 */
static DistinctExpr *
813
_copyDistinctExpr(DistinctExpr *from)
814
{
B
Bruce Momjian 已提交
815
	DistinctExpr *newnode = makeNode(DistinctExpr);
816 817 818 819 820 821 822 823 824 825

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

	return newnode;
}

826 827 828 829
/*
 * _copyScalarArrayOpExpr
 */
static ScalarArrayOpExpr *
830
_copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
831
{
B
Bruce Momjian 已提交
832
	ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
833 834 835 836 837 838 839 840 841

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

	return newnode;
}

842 843 844 845
/*
 * _copyBoolExpr
 */
static BoolExpr *
846
_copyBoolExpr(BoolExpr *from)
847
{
B
Bruce Momjian 已提交
848
	BoolExpr   *newnode = makeNode(BoolExpr);
849 850 851

	COPY_SCALAR_FIELD(boolop);
	COPY_NODE_FIELD(args);
852 853

	return newnode;
854 855
}

856 857
/*
 * _copySubLink
858 859 860 861
 */
static SubLink *
_copySubLink(SubLink *from)
{
862
	SubLink    *newnode = makeNode(SubLink);
863

864
	COPY_SCALAR_FIELD(subLinkType);
865
	COPY_SCALAR_FIELD(useOr);
866
	COPY_NODE_FIELD(lefthand);
867
	COPY_NODE_FIELD(operName);
868
	COPY_NODE_FIELD(operOids);
869
	COPY_NODE_FIELD(subselect);
870 871 872 873

	return newnode;
}

874
/*
875
 * _copySubPlan
876
 */
877 878
static SubPlan *
_copySubPlan(SubPlan *from)
879
{
880
	SubPlan    *newnode = makeNode(SubPlan);
881

882
	COPY_SCALAR_FIELD(subLinkType);
883
	COPY_SCALAR_FIELD(useOr);
884
	COPY_NODE_FIELD(exprs);
885
	COPY_NODE_FIELD(paramIds);
886 887 888
	COPY_NODE_FIELD(plan);
	COPY_SCALAR_FIELD(plan_id);
	COPY_NODE_FIELD(rtable);
889 890
	COPY_SCALAR_FIELD(useHashTable);
	COPY_SCALAR_FIELD(unknownEqFalse);
891 892
	COPY_NODE_FIELD(setParam);
	COPY_NODE_FIELD(parParam);
893 894 895 896 897
	COPY_NODE_FIELD(args);

	return newnode;
}

898 899
/*
 * _copyFieldSelect
900 901 902 903 904 905
 */
static FieldSelect *
_copyFieldSelect(FieldSelect *from)
{
	FieldSelect *newnode = makeNode(FieldSelect);

906 907 908 909
	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(fieldnum);
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
910 911 912 913

	return newnode;
}

914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
/*
 * _copyFieldStore
 */
static FieldStore *
_copyFieldStore(FieldStore *from)
{
	FieldStore *newnode = makeNode(FieldStore);

	COPY_NODE_FIELD(arg);
	COPY_NODE_FIELD(newvals);
	COPY_NODE_FIELD(fieldnums);
	COPY_SCALAR_FIELD(resulttype);

	return newnode;
}

930 931
/*
 * _copyRelabelType
932 933 934 935
 */
static RelabelType *
_copyRelabelType(RelabelType *from)
{
936
	RelabelType *newnode = makeNode(RelabelType);
937

938 939 940 941
	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
	COPY_SCALAR_FIELD(relabelformat);
942 943 944 945

	return newnode;
}

946 947 948 949 950 951 952 953 954 955 956 957 958 959 960
/*
 * _copyConvertRowtypeExpr
 */
static ConvertRowtypeExpr *
_copyConvertRowtypeExpr(ConvertRowtypeExpr *from)
{
	ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);

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

	return newnode;
}

961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990
/*
 * _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;
}

991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
/*
 * _copyCaseTestExpr
 */
static CaseTestExpr *
_copyCaseTestExpr(CaseTestExpr *from)
{
	CaseTestExpr *newnode = makeNode(CaseTestExpr);

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);

	return newnode;
}

1005 1006 1007 1008
/*
 * _copyArrayExpr
 */
static ArrayExpr *
1009
_copyArrayExpr(ArrayExpr *from)
1010
{
B
Bruce Momjian 已提交
1011
	ArrayExpr  *newnode = makeNode(ArrayExpr);
1012 1013 1014 1015

	COPY_SCALAR_FIELD(array_typeid);
	COPY_SCALAR_FIELD(element_typeid);
	COPY_NODE_FIELD(elements);
1016
	COPY_SCALAR_FIELD(multidims);
1017 1018 1019 1020

	return newnode;
}

1021 1022 1023 1024 1025 1026
/*
 * _copyRowExpr
 */
static RowExpr *
_copyRowExpr(RowExpr *from)
{
B
Bruce Momjian 已提交
1027
	RowExpr    *newnode = makeNode(RowExpr);
1028 1029 1030 1031 1032 1033 1034 1035

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

	return newnode;
}

1036 1037 1038 1039
/*
 * _copyCoalesceExpr
 */
static CoalesceExpr *
1040
_copyCoalesceExpr(CoalesceExpr *from)
1041 1042 1043 1044 1045 1046 1047 1048 1049
{
	CoalesceExpr *newnode = makeNode(CoalesceExpr);

	COPY_SCALAR_FIELD(coalescetype);
	COPY_NODE_FIELD(args);

	return newnode;
}

1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
/*
 * _copyMinMaxExpr
 */
static MinMaxExpr *
_copyMinMaxExpr(MinMaxExpr *from)
{
	MinMaxExpr *newnode = makeNode(MinMaxExpr);

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

	return newnode;
}

1065 1066 1067 1068
/*
 * _copyNullIfExpr (same as OpExpr)
 */
static NullIfExpr *
1069
_copyNullIfExpr(NullIfExpr *from)
1070
{
B
Bruce Momjian 已提交
1071
	NullIfExpr *newnode = makeNode(NullIfExpr);
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081

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

	return newnode;
}

1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
/*
 * _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;
}

/*
1111
 * _copyCoerceToDomain
1112
 */
1113
static CoerceToDomain *
1114
_copyCoerceToDomain(CoerceToDomain *from)
1115
{
1116
	CoerceToDomain *newnode = makeNode(CoerceToDomain);
1117 1118

	COPY_NODE_FIELD(arg);
1119 1120 1121
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
	COPY_SCALAR_FIELD(coercionformat);
1122 1123 1124 1125 1126

	return newnode;
}

/*
1127
 * _copyCoerceToDomainValue
1128
 */
1129
static CoerceToDomainValue *
1130
_copyCoerceToDomainValue(CoerceToDomainValue *from)
1131
{
1132
	CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1133 1134 1135 1136 1137 1138 1139

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);

	return newnode;
}

1140 1141 1142 1143
/*
 * _copySetToDefault
 */
static SetToDefault *
1144
_copySetToDefault(SetToDefault *from)
1145 1146 1147 1148 1149 1150 1151 1152 1153
{
	SetToDefault *newnode = makeNode(SetToDefault);

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);

	return newnode;
}

1154 1155 1156 1157 1158 1159 1160 1161 1162
/*
 * _copyTargetEntry
 */
static TargetEntry *
_copyTargetEntry(TargetEntry *from)
{
	TargetEntry *newnode = makeNode(TargetEntry);

	COPY_NODE_FIELD(expr);
1163 1164 1165 1166 1167 1168
	COPY_SCALAR_FIELD(resno);
	COPY_STRING_FIELD(resname);
	COPY_SCALAR_FIELD(ressortgroupref);
	COPY_SCALAR_FIELD(resorigtbl);
	COPY_SCALAR_FIELD(resorigcol);
	COPY_SCALAR_FIELD(resjunk);
1169 1170 1171 1172 1173 1174 1175

	return newnode;
}

/*
 * _copyRangeTblRef
 */
1176 1177 1178 1179 1180
static RangeTblRef *
_copyRangeTblRef(RangeTblRef *from)
{
	RangeTblRef *newnode = makeNode(RangeTblRef);

1181
	COPY_SCALAR_FIELD(rtindex);
1182 1183 1184 1185

	return newnode;
}

1186 1187 1188
/*
 * _copyJoinExpr
 */
1189 1190 1191
static JoinExpr *
_copyJoinExpr(JoinExpr *from)
{
B
Bruce Momjian 已提交
1192
	JoinExpr   *newnode = makeNode(JoinExpr);
1193

1194 1195 1196 1197 1198 1199 1200 1201
	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 已提交
1202 1203 1204 1205

	return newnode;
}

1206 1207 1208
/*
 * _copyFromExpr
 */
1209 1210
static FromExpr *
_copyFromExpr(FromExpr *from)
B
Bruce Momjian 已提交
1211
{
1212
	FromExpr   *newnode = makeNode(FromExpr);
B
Bruce Momjian 已提交
1213

1214 1215
	COPY_NODE_FIELD(fromlist);
	COPY_NODE_FIELD(quals);
B
Bruce Momjian 已提交
1216 1217 1218 1219

	return newnode;
}

1220
/* ****************************************************************
1221
 *						relation.h copy functions
1222
 *
1223 1224
 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
 * There are some subsidiary structs that are useful to copy, though.
1225 1226 1227
 * ****************************************************************
 */

1228 1229
/*
 * _copyPathKeyItem
1230
 */
1231 1232
static PathKeyItem *
_copyPathKeyItem(PathKeyItem *from)
1233
{
1234
	PathKeyItem *newnode = makeNode(PathKeyItem);
1235

1236 1237
	COPY_NODE_FIELD(key);
	COPY_SCALAR_FIELD(sortop);
1238 1239

	return newnode;
1240 1241
}

1242 1243
/*
 * _copyRestrictInfo
1244
 */
1245
static RestrictInfo *
1246
_copyRestrictInfo(RestrictInfo *from)
1247
{
1248
	RestrictInfo *newnode = makeNode(RestrictInfo);
1249

1250
	COPY_NODE_FIELD(clause);
1251 1252
	COPY_SCALAR_FIELD(is_pushed_down);
	COPY_SCALAR_FIELD(can_join);
1253
	COPY_BITMAPSET_FIELD(clause_relids);
1254
	COPY_BITMAPSET_FIELD(required_relids);
1255 1256
	COPY_BITMAPSET_FIELD(left_relids);
	COPY_BITMAPSET_FIELD(right_relids);
1257
	COPY_NODE_FIELD(orclause);
1258 1259 1260 1261 1262
	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 已提交
1263 1264 1265 1266 1267

	/*
	 * Do not copy pathkeys, since they'd not be canonical in a copied
	 * query
	 */
1268 1269
	newnode->left_pathkey = NIL;
	newnode->right_pathkey = NIL;
1270 1271 1272 1273 1274 1275

	COPY_SCALAR_FIELD(left_mergescansel);
	COPY_SCALAR_FIELD(right_mergescansel);
	COPY_SCALAR_FIELD(hashjoinoperator);
	COPY_SCALAR_FIELD(left_bucketsize);
	COPY_SCALAR_FIELD(right_bucketsize);
1276 1277

	return newnode;
1278 1279
}

1280 1281 1282 1283
/*
 * _copyInClauseInfo
 */
static InClauseInfo *
1284
_copyInClauseInfo(InClauseInfo *from)
1285 1286 1287
{
	InClauseInfo *newnode = makeNode(InClauseInfo);

1288 1289
	COPY_BITMAPSET_FIELD(lefthand);
	COPY_BITMAPSET_FIELD(righthand);
1290 1291 1292 1293 1294
	COPY_NODE_FIELD(sub_targetlist);

	return newnode;
}

1295 1296 1297
/* ****************************************************************
 *					parsenodes.h copy functions
 * ****************************************************************
1298 1299 1300
 */

static RangeTblEntry *
1301
_copyRangeTblEntry(RangeTblEntry *from)
1302
{
1303
	RangeTblEntry *newnode = makeNode(RangeTblEntry);
1304

1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315
	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);
1316
	COPY_SCALAR_FIELD(requiredPerms);
1317
	COPY_SCALAR_FIELD(checkAsUser);
1318 1319 1320 1321

	return newnode;
}

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

1327 1328 1329 1330 1331 1332 1333 1334 1335 1336
	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 已提交
1337

1338 1339 1340
	return newnode;
}

1341
static SortClause *
1342
_copySortClause(SortClause *from)
1343
{
1344
	SortClause *newnode = makeNode(SortClause);
1345

1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358
	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);
1359

1360
	return newnode;
1361 1362
}

1363 1364 1365
static A_Expr *
_copyAExpr(A_Expr *from)
{
B
Bruce Momjian 已提交
1366
	A_Expr	   *newnode = makeNode(A_Expr);
1367

1368
	COPY_SCALAR_FIELD(kind);
1369 1370 1371
	COPY_NODE_FIELD(name);
	COPY_NODE_FIELD(lexpr);
	COPY_NODE_FIELD(rexpr);
1372 1373 1374 1375

	return newnode;
}

1376 1377
static ColumnRef *
_copyColumnRef(ColumnRef *from)
1378
{
B
Bruce Momjian 已提交
1379
	ColumnRef  *newnode = makeNode(ColumnRef);
1380

1381
	COPY_NODE_FIELD(fields);
1382

1383
	return newnode;
1384 1385
}

1386 1387
static ParamRef *
_copyParamRef(ParamRef *from)
1388
{
B
Bruce Momjian 已提交
1389
	ParamRef   *newnode = makeNode(ParamRef);
1390

1391
	COPY_SCALAR_FIELD(number);
1392 1393 1394 1395

	return newnode;
}

1396 1397 1398 1399 1400
static A_Const *
_copyAConst(A_Const *from)
{
	A_Const    *newnode = makeNode(A_Const);

1401
	/* This part must duplicate _copyValue */
1402
	COPY_SCALAR_FIELD(val.type);
1403 1404 1405
	switch (from->val.type)
	{
		case T_Integer:
1406
			COPY_SCALAR_FIELD(val.val.ival);
1407 1408 1409 1410
			break;
		case T_Float:
		case T_String:
		case T_BitString:
1411
			COPY_STRING_FIELD(val.val.str);
1412 1413 1414 1415 1416
			break;
		case T_Null:
			/* nothing to do */
			break;
		default:
1417 1418
			elog(ERROR, "unrecognized node type: %d",
				 (int) from->val.type);
1419 1420 1421
			break;
	}

1422
	COPY_NODE_FIELD(typename);
1423 1424 1425 1426

	return newnode;
}

1427 1428 1429
static FuncCall *
_copyFuncCall(FuncCall *from)
{
B
Bruce Momjian 已提交
1430
	FuncCall   *newnode = makeNode(FuncCall);
1431

1432 1433 1434 1435
	COPY_NODE_FIELD(funcname);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(agg_star);
	COPY_SCALAR_FIELD(agg_distinct);
1436 1437 1438 1439 1440 1441 1442

	return newnode;
}

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

1445 1446
	COPY_NODE_FIELD(lidx);
	COPY_NODE_FIELD(uidx);
1447 1448 1449 1450

	return newnode;
}

1451 1452
static A_Indirection *
_copyA_Indirection(A_Indirection *from)
1453
{
1454
	A_Indirection *newnode = makeNode(A_Indirection);
1455

1456 1457
	COPY_NODE_FIELD(arg);
	COPY_NODE_FIELD(indirection);
1458 1459 1460 1461

	return newnode;
}

1462 1463 1464
static ResTarget *
_copyResTarget(ResTarget *from)
{
B
Bruce Momjian 已提交
1465
	ResTarget  *newnode = makeNode(ResTarget);
1466

1467 1468 1469
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(indirection);
	COPY_NODE_FIELD(val);
1470 1471 1472 1473

	return newnode;
}

1474
static TypeName *
1475
_copyTypeName(TypeName *from)
1476
{
1477
	TypeName   *newnode = makeNode(TypeName);
1478

1479 1480 1481 1482 1483 1484 1485
	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);
1486 1487

	return newnode;
1488 1489
}

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

1495
	COPY_SCALAR_FIELD(sortby_kind);
1496 1497
	COPY_NODE_FIELD(useOp);
	COPY_NODE_FIELD(node);
1498 1499 1500 1501 1502 1503 1504

	return newnode;
}

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

1507 1508
	COPY_NODE_FIELD(subquery);
	COPY_NODE_FIELD(alias);
1509 1510 1511 1512

	return newnode;
}

1513 1514 1515
static RangeFunction *
_copyRangeFunction(RangeFunction *from)
{
B
Bruce Momjian 已提交
1516
	RangeFunction *newnode = makeNode(RangeFunction);
1517

1518 1519 1520
	COPY_NODE_FIELD(funccallnode);
	COPY_NODE_FIELD(alias);
	COPY_NODE_FIELD(coldeflist);
1521 1522 1523 1524

	return newnode;
}

1525 1526 1527 1528 1529
static TypeCast *
_copyTypeCast(TypeCast *from)
{
	TypeCast   *newnode = makeNode(TypeCast);

1530 1531
	COPY_NODE_FIELD(arg);
	COPY_NODE_FIELD(typename);
1532 1533 1534 1535

	return newnode;
}

1536 1537 1538
static IndexElem *
_copyIndexElem(IndexElem *from)
{
B
Bruce Momjian 已提交
1539
	IndexElem  *newnode = makeNode(IndexElem);
1540

1541
	COPY_STRING_FIELD(name);
1542
	COPY_NODE_FIELD(expr);
1543
	COPY_NODE_FIELD(opclass);
1544 1545 1546 1547 1548 1549 1550

	return newnode;
}

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

1553 1554 1555 1556 1557 1558 1559 1560 1561
	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);
1562 1563 1564 1565 1566 1567 1568

	return newnode;
}

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

1571 1572 1573 1574 1575
	COPY_SCALAR_FIELD(contype);
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(raw_expr);
	COPY_STRING_FIELD(cooked_expr);
	COPY_NODE_FIELD(keys);
1576
	COPY_STRING_FIELD(indexspace);
1577 1578 1579 1580

	return newnode;
}

1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598
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);
1599
	COPY_SCALAR_FIELD(canSetTag);
1600 1601 1602
	COPY_NODE_FIELD(utilityStmt);
	COPY_SCALAR_FIELD(resultRelation);
	COPY_NODE_FIELD(into);
1603
	COPY_SCALAR_FIELD(intoHasOids);
1604 1605 1606 1607
	COPY_SCALAR_FIELD(hasAggs);
	COPY_SCALAR_FIELD(hasSubLinks);
	COPY_NODE_FIELD(rtable);
	COPY_NODE_FIELD(jointree);
1608
	COPY_NODE_FIELD(rowMarks);
1609
	COPY_SCALAR_FIELD(forUpdate);
1610 1611 1612 1613 1614 1615 1616 1617
	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);
1618
	COPY_NODE_FIELD(resultRelations);
1619

1620
	return newnode;
1621 1622
}

1623 1624 1625 1626
static InsertStmt *
_copyInsertStmt(InsertStmt *from)
{
	InsertStmt *newnode = makeNode(InsertStmt);
B
Bruce Momjian 已提交
1627

1628 1629 1630 1631
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(cols);
	COPY_NODE_FIELD(targetList);
	COPY_NODE_FIELD(selectStmt);
1632 1633 1634 1635 1636 1637 1638 1639

	return newnode;
}

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

1641 1642
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(whereClause);
1643
	COPY_NODE_FIELD(usingClause);
1644 1645 1646 1647 1648 1649 1650 1651

	return newnode;
}

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

1653 1654 1655 1656
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(targetList);
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(fromClause);
1657 1658 1659 1660 1661 1662 1663 1664

	return newnode;
}

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

1666 1667 1668
	COPY_NODE_FIELD(distinctClause);
	COPY_NODE_FIELD(into);
	COPY_NODE_FIELD(intoColNames);
1669
	COPY_SCALAR_FIELD(intoHasOids);
1670 1671 1672 1673 1674 1675 1676 1677
	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);
1678 1679
	COPY_NODE_FIELD(lockedRels);
	COPY_SCALAR_FIELD(forUpdate);
1680 1681 1682 1683
	COPY_SCALAR_FIELD(op);
	COPY_SCALAR_FIELD(all);
	COPY_NODE_FIELD(larg);
	COPY_NODE_FIELD(rarg);
1684 1685 1686 1687

	return newnode;
}

1688 1689 1690 1691
static SetOperationStmt *
_copySetOperationStmt(SetOperationStmt *from)
{
	SetOperationStmt *newnode = makeNode(SetOperationStmt);
B
Bruce Momjian 已提交
1692

1693 1694 1695 1696
	COPY_SCALAR_FIELD(op);
	COPY_SCALAR_FIELD(all);
	COPY_NODE_FIELD(larg);
	COPY_NODE_FIELD(rarg);
1697
	COPY_NODE_FIELD(colTypes);
1698 1699 1700 1701

	return newnode;
}

1702 1703 1704 1705
static AlterTableStmt *
_copyAlterTableStmt(AlterTableStmt *from)
{
	AlterTableStmt *newnode = makeNode(AlterTableStmt);
B
Bruce Momjian 已提交
1706

1707
	COPY_NODE_FIELD(relation);
T
Tom Lane 已提交
1708
	COPY_NODE_FIELD(cmds);
T
Tom Lane 已提交
1709
	COPY_SCALAR_FIELD(relkind);
T
Tom Lane 已提交
1710 1711 1712 1713 1714 1715 1716 1717 1718 1719

	return newnode;
}

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

	COPY_SCALAR_FIELD(subtype);
1720 1721
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(def);
T
Tom Lane 已提交
1722
	COPY_NODE_FIELD(transform);
1723
	COPY_SCALAR_FIELD(behavior);
1724 1725 1726 1727

	return newnode;
}

B
Bruce Momjian 已提交
1728
static AlterDomainStmt *
1729
_copyAlterDomainStmt(AlterDomainStmt *from)
B
Bruce Momjian 已提交
1730 1731 1732 1733 1734 1735 1736 1737 1738 1739
{
	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 已提交
1740
}
B
Bruce Momjian 已提交
1741

1742 1743
static GrantStmt *
_copyGrantStmt(GrantStmt *from)
1744
{
1745
	GrantStmt  *newnode = makeNode(GrantStmt);
B
Bruce Momjian 已提交
1746

1747 1748 1749
	COPY_SCALAR_FIELD(is_grant);
	COPY_SCALAR_FIELD(objtype);
	COPY_NODE_FIELD(objects);
1750
	COPY_NODE_FIELD(privileges);
1751
	COPY_NODE_FIELD(grantees);
1752 1753
	COPY_SCALAR_FIELD(grant_option);
	COPY_SCALAR_FIELD(behavior);
1754 1755 1756 1757 1758 1759 1760 1761 1762

	return newnode;
}

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

1763
	COPY_STRING_FIELD(rolname);
1764 1765 1766 1767

	return newnode;
}

1768 1769 1770 1771 1772
static FuncWithArgs *
_copyFuncWithArgs(FuncWithArgs *from)
{
	FuncWithArgs *newnode = makeNode(FuncWithArgs);

1773 1774
	COPY_NODE_FIELD(funcname);
	COPY_NODE_FIELD(funcargs);
1775 1776 1777 1778

	return newnode;
}

1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793
static GrantRoleStmt *
_copyGrantRoleStmt(GrantRoleStmt *from)
{
	GrantRoleStmt  *newnode = makeNode(GrantRoleStmt);

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

	return newnode;
}

1794
static DeclareCursorStmt *
1795
_copyDeclareCursorStmt(DeclareCursorStmt *from)
1796 1797 1798 1799 1800 1801 1802 1803 1804
{
	DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);

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

	return newnode;
}
B
Bruce Momjian 已提交
1805

1806 1807 1808
static ClosePortalStmt *
_copyClosePortalStmt(ClosePortalStmt *from)
{
1809
	ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1810

1811
	COPY_STRING_FIELD(portalname);
1812 1813 1814 1815

	return newnode;
}

1816 1817 1818 1819
static ClusterStmt *
_copyClusterStmt(ClusterStmt *from)
{
	ClusterStmt *newnode = makeNode(ClusterStmt);
B
Bruce Momjian 已提交
1820

1821 1822
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(indexname);
1823 1824 1825 1826 1827 1828 1829

	return newnode;
}

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

1832 1833 1834 1835 1836
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(attlist);
	COPY_SCALAR_FIELD(is_from);
	COPY_STRING_FIELD(filename);
	COPY_NODE_FIELD(options);
1837 1838 1839 1840 1841 1842 1843 1844

	return newnode;
}

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

1846 1847 1848 1849 1850 1851
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(tableElts);
	COPY_NODE_FIELD(inhRelations);
	COPY_NODE_FIELD(constraints);
	COPY_SCALAR_FIELD(hasoids);
	COPY_SCALAR_FIELD(oncommit);
1852
	COPY_STRING_FIELD(tablespacename);
1853 1854 1855 1856

	return newnode;
}

B
Bruce Momjian 已提交
1857
static InhRelation *
1858
_copyInhRelation(InhRelation *from)
B
Bruce Momjian 已提交
1859 1860 1861 1862 1863 1864 1865 1866 1867
{
	InhRelation *newnode = makeNode(InhRelation);

	COPY_NODE_FIELD(relation);
	COPY_SCALAR_FIELD(including_defaults);

	return newnode;
}

1868 1869 1870 1871
static DefineStmt *
_copyDefineStmt(DefineStmt *from)
{
	DefineStmt *newnode = makeNode(DefineStmt);
B
Bruce Momjian 已提交
1872

1873
	COPY_SCALAR_FIELD(kind);
1874 1875
	COPY_NODE_FIELD(defnames);
	COPY_NODE_FIELD(definition);
1876 1877 1878 1879 1880 1881 1882

	return newnode;
}

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

1885 1886 1887
	COPY_NODE_FIELD(objects);
	COPY_SCALAR_FIELD(removeType);
	COPY_SCALAR_FIELD(behavior);
1888 1889 1890 1891

	return newnode;
}

1892 1893 1894
static TruncateStmt *
_copyTruncateStmt(TruncateStmt *from)
{
1895
	TruncateStmt *newnode = makeNode(TruncateStmt);
1896

1897
	COPY_NODE_FIELD(relations);
1898 1899 1900 1901

	return newnode;
}

1902 1903 1904 1905
static CommentStmt *
_copyCommentStmt(CommentStmt *from)
{
	CommentStmt *newnode = makeNode(CommentStmt);
B
Bruce Momjian 已提交
1906

1907 1908 1909 1910
	COPY_SCALAR_FIELD(objtype);
	COPY_NODE_FIELD(objname);
	COPY_NODE_FIELD(objargs);
	COPY_STRING_FIELD(comment);
1911 1912 1913 1914 1915 1916 1917

	return newnode;
}

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

1920 1921 1922 1923
	COPY_SCALAR_FIELD(direction);
	COPY_SCALAR_FIELD(howMany);
	COPY_STRING_FIELD(portalname);
	COPY_SCALAR_FIELD(ismove);
1924 1925 1926 1927 1928 1929 1930

	return newnode;
}

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

1933 1934 1935
	COPY_STRING_FIELD(idxname);
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(accessMethod);
1936
	COPY_STRING_FIELD(tableSpace);
1937 1938 1939 1940 1941 1942
	COPY_NODE_FIELD(indexParams);
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(rangetable);
	COPY_SCALAR_FIELD(unique);
	COPY_SCALAR_FIELD(primary);
	COPY_SCALAR_FIELD(isconstraint);
1943 1944 1945 1946

	return newnode;
}

1947 1948
static CreateFunctionStmt *
_copyCreateFunctionStmt(CreateFunctionStmt *from)
1949
{
1950
	CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
B
Bruce Momjian 已提交
1951

1952 1953
	COPY_SCALAR_FIELD(replace);
	COPY_NODE_FIELD(funcname);
1954
	COPY_NODE_FIELD(parameters);
1955 1956 1957
	COPY_NODE_FIELD(returnType);
	COPY_NODE_FIELD(options);
	COPY_NODE_FIELD(withClause);
1958 1959 1960 1961

	return newnode;
}

1962 1963 1964 1965 1966 1967 1968
static FunctionParameter *
_copyFunctionParameter(FunctionParameter *from)
{
	FunctionParameter *newnode = makeNode(FunctionParameter);

	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(argType);
1969
	COPY_SCALAR_FIELD(mode);
1970 1971 1972 1973

	return newnode;
}

1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984
static AlterFunctionStmt *
_copyAlterFunctionStmt(AlterFunctionStmt *from)
{
	AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);

	COPY_NODE_FIELD(func);
	COPY_NODE_FIELD(actions);

	return newnode;
}

1985 1986 1987 1988
static RemoveAggrStmt *
_copyRemoveAggrStmt(RemoveAggrStmt *from)
{
	RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
B
Bruce Momjian 已提交
1989

1990 1991 1992
	COPY_NODE_FIELD(aggname);
	COPY_NODE_FIELD(aggtype);
	COPY_SCALAR_FIELD(behavior);
1993 1994 1995 1996 1997 1998 1999 2000

	return newnode;
}

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

2002 2003 2004
	COPY_NODE_FIELD(funcname);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(behavior);
2005 2006 2007 2008 2009 2010 2011 2012

	return newnode;
}

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

2014 2015 2016
	COPY_NODE_FIELD(opname);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(behavior);
2017 2018 2019 2020

	return newnode;
}

2021 2022 2023 2024 2025
static RemoveOpClassStmt *
_copyRemoveOpClassStmt(RemoveOpClassStmt *from)
{
	RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);

2026 2027 2028
	COPY_NODE_FIELD(opclassname);
	COPY_STRING_FIELD(amname);
	COPY_SCALAR_FIELD(behavior);
2029 2030 2031 2032

	return newnode;
}

2033 2034 2035 2036
static RenameStmt *
_copyRenameStmt(RenameStmt *from)
{
	RenameStmt *newnode = makeNode(RenameStmt);
B
Bruce Momjian 已提交
2037

2038
	COPY_NODE_FIELD(relation);
2039 2040 2041
	COPY_NODE_FIELD(object);
	COPY_NODE_FIELD(objarg);
	COPY_STRING_FIELD(subname);
2042 2043
	COPY_STRING_FIELD(newname);
	COPY_SCALAR_FIELD(renameType);
2044 2045 2046 2047

	return newnode;
}

2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062
static AlterOwnerStmt *
_copyAlterOwnerStmt(AlterOwnerStmt *from)
{
	AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);

	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(object);
	COPY_NODE_FIELD(objarg);
	COPY_STRING_FIELD(addname);
	COPY_STRING_FIELD(newowner);
	COPY_SCALAR_FIELD(objectType);

	return newnode;
}

2063 2064 2065
static RuleStmt *
_copyRuleStmt(RuleStmt *from)
{
B
Bruce Momjian 已提交
2066 2067
	RuleStmt   *newnode = makeNode(RuleStmt);

2068 2069 2070 2071 2072 2073 2074
	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);
2075 2076 2077 2078

	return newnode;
}

2079 2080 2081
static NotifyStmt *
_copyNotifyStmt(NotifyStmt *from)
{
2082
	NotifyStmt *newnode = makeNode(NotifyStmt);
2083

2084
	COPY_NODE_FIELD(relation);
2085 2086 2087 2088 2089 2090 2091

	return newnode;
}

static ListenStmt *
_copyListenStmt(ListenStmt *from)
{
2092
	ListenStmt *newnode = makeNode(ListenStmt);
2093

2094
	COPY_NODE_FIELD(relation);
2095 2096 2097 2098 2099 2100 2101

	return newnode;
}

static UnlistenStmt *
_copyUnlistenStmt(UnlistenStmt *from)
{
2102
	UnlistenStmt *newnode = makeNode(UnlistenStmt);
2103

2104
	COPY_NODE_FIELD(relation);
2105 2106 2107 2108 2109 2110 2111

	return newnode;
}

static TransactionStmt *
_copyTransactionStmt(TransactionStmt *from)
{
2112
	TransactionStmt *newnode = makeNode(TransactionStmt);
2113

2114
	COPY_SCALAR_FIELD(kind);
2115
	COPY_NODE_FIELD(options);
2116
	COPY_STRING_FIELD(gid);
2117 2118 2119 2120

	return newnode;
}

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

2126 2127
	COPY_NODE_FIELD(typevar);
	COPY_NODE_FIELD(coldeflist);
B
Bruce Momjian 已提交
2128 2129 2130 2131

	return newnode;
}

2132 2133 2134 2135 2136
static ViewStmt *
_copyViewStmt(ViewStmt *from)
{
	ViewStmt   *newnode = makeNode(ViewStmt);

2137 2138 2139 2140
	COPY_NODE_FIELD(view);
	COPY_NODE_FIELD(aliases);
	COPY_NODE_FIELD(query);
	COPY_SCALAR_FIELD(replace);
2141 2142 2143 2144

	return newnode;
}

2145 2146 2147
static LoadStmt *
_copyLoadStmt(LoadStmt *from)
{
2148
	LoadStmt   *newnode = makeNode(LoadStmt);
2149

2150
	COPY_STRING_FIELD(filename);
2151 2152 2153 2154

	return newnode;
}

2155 2156 2157 2158 2159
static CreateDomainStmt *
_copyCreateDomainStmt(CreateDomainStmt *from)
{
	CreateDomainStmt *newnode = makeNode(CreateDomainStmt);

2160 2161 2162
	COPY_NODE_FIELD(domainname);
	COPY_NODE_FIELD(typename);
	COPY_NODE_FIELD(constraints);
2163 2164 2165 2166

	return newnode;
}

2167 2168 2169 2170 2171
static CreateOpClassStmt *
_copyCreateOpClassStmt(CreateOpClassStmt *from)
{
	CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);

2172 2173 2174 2175 2176
	COPY_NODE_FIELD(opclassname);
	COPY_STRING_FIELD(amname);
	COPY_NODE_FIELD(datatype);
	COPY_NODE_FIELD(items);
	COPY_SCALAR_FIELD(isDefault);
2177 2178 2179 2180 2181 2182 2183 2184 2185

	return newnode;
}

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

2186 2187 2188 2189 2190 2191
	COPY_SCALAR_FIELD(itemtype);
	COPY_NODE_FIELD(name);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(number);
	COPY_SCALAR_FIELD(recheck);
	COPY_NODE_FIELD(storedtype);
2192 2193 2194 2195

	return newnode;
}

2196 2197 2198
static CreatedbStmt *
_copyCreatedbStmt(CreatedbStmt *from)
{
B
Bruce Momjian 已提交
2199
	CreatedbStmt *newnode = makeNode(CreatedbStmt);
2200

2201 2202
	COPY_STRING_FIELD(dbname);
	COPY_NODE_FIELD(options);
2203 2204 2205 2206

	return newnode;
}

2207 2208 2209 2210 2211
static AlterDatabaseSetStmt *
_copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
{
	AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);

2212 2213 2214
	COPY_STRING_FIELD(dbname);
	COPY_STRING_FIELD(variable);
	COPY_NODE_FIELD(value);
2215 2216 2217 2218

	return newnode;
}

2219 2220 2221
static DropdbStmt *
_copyDropdbStmt(DropdbStmt *from)
{
B
Bruce Momjian 已提交
2222
	DropdbStmt *newnode = makeNode(DropdbStmt);
2223

2224
	COPY_STRING_FIELD(dbname);
2225 2226 2227 2228 2229 2230 2231

	return newnode;
}

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

2234 2235 2236 2237 2238 2239 2240
	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);
2241 2242 2243 2244 2245 2246 2247

	return newnode;
}

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

2250 2251 2252
	COPY_NODE_FIELD(query);
	COPY_SCALAR_FIELD(verbose);
	COPY_SCALAR_FIELD(analyze);
2253 2254 2255 2256 2257 2258 2259

	return newnode;
}

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

2262 2263
	COPY_NODE_FIELD(sequence);
	COPY_NODE_FIELD(options);
2264 2265 2266 2267

	return newnode;
}

B
Bruce Momjian 已提交
2268
static AlterSeqStmt *
2269
_copyAlterSeqStmt(AlterSeqStmt *from)
B
Bruce Momjian 已提交
2270 2271 2272 2273 2274 2275 2276 2277 2278
{
	AlterSeqStmt *newnode = makeNode(AlterSeqStmt);

	COPY_NODE_FIELD(sequence);
	COPY_NODE_FIELD(options);

	return newnode;
}

2279 2280 2281
static VariableSetStmt *
_copyVariableSetStmt(VariableSetStmt *from)
{
2282
	VariableSetStmt *newnode = makeNode(VariableSetStmt);
2283

2284 2285 2286
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(is_local);
2287 2288 2289 2290

	return newnode;
}

2291 2292 2293 2294 2295
static VariableShowStmt *
_copyVariableShowStmt(VariableShowStmt *from)
{
	VariableShowStmt *newnode = makeNode(VariableShowStmt);

2296
	COPY_STRING_FIELD(name);
2297 2298 2299 2300

	return newnode;
}

2301 2302 2303
static VariableResetStmt *
_copyVariableResetStmt(VariableResetStmt *from)
{
2304
	VariableResetStmt *newnode = makeNode(VariableResetStmt);
2305

2306
	COPY_STRING_FIELD(name);
2307 2308 2309 2310

	return newnode;
}

2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332
static CreateTableSpaceStmt *
_copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
{
	CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);

	COPY_STRING_FIELD(tablespacename);
	COPY_STRING_FIELD(owner);
	COPY_STRING_FIELD(location);

	return newnode;
}

static DropTableSpaceStmt *
_copyDropTableSpaceStmt(DropTableSpaceStmt *from)
{
	DropTableSpaceStmt *newnode = makeNode(DropTableSpaceStmt);

	COPY_STRING_FIELD(tablespacename);

	return newnode;
}

2333 2334 2335 2336 2337
static CreateTrigStmt *
_copyCreateTrigStmt(CreateTrigStmt *from)
{
	CreateTrigStmt *newnode = makeNode(CreateTrigStmt);

2338 2339 2340 2341 2342 2343
	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 已提交
2344
	strcpy(newnode->actions, from->actions);	/* in-line string field */
2345 2346 2347 2348
	COPY_SCALAR_FIELD(isconstraint);
	COPY_SCALAR_FIELD(deferrable);
	COPY_SCALAR_FIELD(initdeferred);
	COPY_NODE_FIELD(constrrel);
2349 2350 2351 2352

	return newnode;
}

2353 2354
static DropPropertyStmt *
_copyDropPropertyStmt(DropPropertyStmt *from)
2355
{
2356
	DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2357

2358 2359 2360 2361
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(property);
	COPY_SCALAR_FIELD(removeType);
	COPY_SCALAR_FIELD(behavior);
2362 2363 2364 2365 2366 2367 2368 2369 2370

	return newnode;
}

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

2371 2372 2373 2374
	COPY_STRING_FIELD(plname);
	COPY_NODE_FIELD(plhandler);
	COPY_NODE_FIELD(plvalidator);
	COPY_SCALAR_FIELD(pltrusted);
2375 2376 2377 2378 2379 2380 2381 2382 2383

	return newnode;
}

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

2384 2385
	COPY_STRING_FIELD(plname);
	COPY_SCALAR_FIELD(behavior);
2386 2387 2388 2389

	return newnode;
}

2390 2391
static CreateRoleStmt *
_copyCreateRoleStmt(CreateRoleStmt *from)
2392
{
2393
	CreateRoleStmt *newnode = makeNode(CreateRoleStmt);
2394

2395
	COPY_STRING_FIELD(role);
2396
	COPY_NODE_FIELD(options);
2397 2398 2399 2400

	return newnode;
}

2401 2402
static AlterRoleStmt *
_copyAlterRoleStmt(AlterRoleStmt *from)
2403
{
2404
	AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
2405

2406
	COPY_STRING_FIELD(role);
2407
	COPY_NODE_FIELD(options);
2408
	COPY_SCALAR_FIELD(action);
2409 2410 2411 2412

	return newnode;
}

2413 2414
static AlterRoleSetStmt *
_copyAlterRoleSetStmt(AlterRoleSetStmt *from)
2415
{
2416
	AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
2417

2418
	COPY_STRING_FIELD(role);
2419 2420
	COPY_STRING_FIELD(variable);
	COPY_NODE_FIELD(value);
2421 2422 2423 2424

	return newnode;
}

2425 2426
static DropRoleStmt *
_copyDropRoleStmt(DropRoleStmt *from)
2427
{
2428
	DropRoleStmt *newnode = makeNode(DropRoleStmt);
2429

2430
	COPY_NODE_FIELD(roles);
2431 2432 2433 2434

	return newnode;
}

2435 2436 2437
static LockStmt *
_copyLockStmt(LockStmt *from)
{
2438
	LockStmt   *newnode = makeNode(LockStmt);
2439

2440 2441
	COPY_NODE_FIELD(relations);
	COPY_SCALAR_FIELD(mode);
T
Tatsuo Ishii 已提交
2442
	COPY_SCALAR_FIELD(nowait);
2443 2444 2445

	return newnode;
}
2446

2447 2448 2449
static ConstraintsSetStmt *
_copyConstraintsSetStmt(ConstraintsSetStmt *from)
{
B
Bruce Momjian 已提交
2450
	ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2451

2452 2453
	COPY_NODE_FIELD(constraints);
	COPY_SCALAR_FIELD(deferred);
2454 2455 2456 2457 2458 2459 2460

	return newnode;
}

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

2463
	COPY_SCALAR_FIELD(kind);
2464 2465
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(name);
2466 2467
	COPY_SCALAR_FIELD(do_system);
	COPY_SCALAR_FIELD(do_user);
2468 2469 2470 2471

	return newnode;
}

2472 2473 2474 2475 2476
static CreateSchemaStmt *
_copyCreateSchemaStmt(CreateSchemaStmt *from)
{
	CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);

2477 2478 2479
	COPY_STRING_FIELD(schemaname);
	COPY_STRING_FIELD(authid);
	COPY_NODE_FIELD(schemaElts);
2480 2481 2482 2483

	return newnode;
}

2484 2485 2486 2487 2488
static CreateConversionStmt *
_copyCreateConversionStmt(CreateConversionStmt *from)
{
	CreateConversionStmt *newnode = makeNode(CreateConversionStmt);

2489 2490 2491 2492 2493
	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);
2494 2495 2496 2497 2498 2499 2500 2501 2502

	return newnode;
}

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

2503 2504 2505 2506
	COPY_NODE_FIELD(sourcetype);
	COPY_NODE_FIELD(targettype);
	COPY_NODE_FIELD(func);
	COPY_SCALAR_FIELD(context);
2507 2508 2509 2510 2511 2512 2513 2514 2515

	return newnode;
}

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

2516 2517 2518
	COPY_NODE_FIELD(sourcetype);
	COPY_NODE_FIELD(targettype);
	COPY_SCALAR_FIELD(behavior);
2519 2520 2521 2522

	return newnode;
}

2523 2524 2525 2526 2527
static PrepareStmt *
_copyPrepareStmt(PrepareStmt *from)
{
	PrepareStmt *newnode = makeNode(PrepareStmt);

2528 2529
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(argtypes);
2530
	COPY_NODE_FIELD(argtype_oids);
2531
	COPY_NODE_FIELD(query);
2532 2533 2534 2535 2536 2537 2538 2539 2540

	return newnode;
}

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

2541 2542 2543
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(into);
	COPY_NODE_FIELD(params);
2544 2545 2546 2547 2548 2549 2550 2551 2552

	return newnode;
}

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

2553
	COPY_STRING_FIELD(name);
2554 2555 2556 2557

	return newnode;
}

2558 2559

/* ****************************************************************
2560
 *					pg_list.h copy functions
2561 2562 2563
 * ****************************************************************
 */

2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575
/*
 * Perform a deep copy of the specified list, using copyObject(). The
 * list MUST be of type T_List; T_IntList and T_OidList nodes don't
 * need deep copies, so they should be copied via list_copy()
 */
#define COPY_NODE_CELL(new, old)					\
	(new) = (ListCell *) palloc(sizeof(ListCell));	\
	lfirst(new) = copyObject(lfirst(old));

static List *
_copyList(List *from)
{
B
Bruce Momjian 已提交
2576 2577 2578
	List	   *new;
	ListCell   *curr_old;
	ListCell   *prev_new;
2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604

	Assert(list_length(from) >= 1);

	new = makeNode(List);
	new->length = from->length;

	COPY_NODE_CELL(new->head, from->head);
	prev_new = new->head;
	curr_old = lnext(from->head);

	while (curr_old)
	{
		COPY_NODE_CELL(prev_new->next, curr_old);
		prev_new = prev_new->next;
		curr_old = curr_old->next;
	}
	prev_new->next = NULL;
	new->tail = prev_new;

	return new;
}

/* ****************************************************************
 *					value.h copy functions
 * ****************************************************************
 */
2605
static Value *
2606
_copyValue(Value *from)
2607
{
2608
	Value	   *newnode = makeNode(Value);
2609

2610 2611
	/* See also _copyAConst when changing this code! */

2612
	COPY_SCALAR_FIELD(type);
2613 2614
	switch (from->type)
	{
2615
		case T_Integer:
2616
			COPY_SCALAR_FIELD(val.ival);
2617 2618
			break;
		case T_Float:
2619
		case T_String:
2620
		case T_BitString:
2621
			COPY_STRING_FIELD(val.str);
2622
			break;
2623 2624 2625
		case T_Null:
			/* nothing to do */
			break;
2626
		default:
2627 2628
			elog(ERROR, "unrecognized node type: %d",
				 (int) from->type);
2629
			break;
2630 2631
	}
	return newnode;
2632 2633
}

2634 2635 2636 2637 2638
/*
 * copyObject
 *
 * Create a copy of a Node tree or list.  This is a "deep" copy: all
 * substructure is copied too, recursively.
2639
 */
2640
void *
2641 2642
copyObject(void *from)
{
2643
	void	   *retval;
2644

2645 2646
	if (from == NULL)
		return NULL;
2647

2648
	switch (nodeTag(from))
2649
	{
2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661
			/*
			 * PLAN NODES
			 */
		case T_Plan:
			retval = _copyPlan(from);
			break;
		case T_Result:
			retval = _copyResult(from);
			break;
		case T_Append:
			retval = _copyAppend(from);
			break;
2662 2663 2664 2665 2666 2667
		case T_BitmapAnd:
			retval = _copyBitmapAnd(from);
			break;
		case T_BitmapOr:
			retval = _copyBitmapOr(from);
			break;
2668 2669 2670 2671 2672 2673 2674 2675 2676
		case T_Scan:
			retval = _copyScan(from);
			break;
		case T_SeqScan:
			retval = _copySeqScan(from);
			break;
		case T_IndexScan:
			retval = _copyIndexScan(from);
			break;
2677 2678 2679 2680 2681 2682
		case T_BitmapIndexScan:
			retval = _copyBitmapIndexScan(from);
			break;
		case T_BitmapHeapScan:
			retval = _copyBitmapHeapScan(from);
			break;
2683 2684 2685
		case T_TidScan:
			retval = _copyTidScan(from);
			break;
2686 2687 2688
		case T_SubqueryScan:
			retval = _copySubqueryScan(from);
			break;
2689 2690 2691
		case T_FunctionScan:
			retval = _copyFunctionScan(from);
			break;
2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709
		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 已提交
2710 2711 2712
		case T_Group:
			retval = _copyGroup(from);
			break;
2713 2714 2715 2716 2717 2718
		case T_Agg:
			retval = _copyAgg(from);
			break;
		case T_Unique:
			retval = _copyUnique(from);
			break;
2719 2720 2721
		case T_Hash:
			retval = _copyHash(from);
			break;
2722 2723 2724
		case T_SetOp:
			retval = _copySetOp(from);
			break;
2725 2726 2727
		case T_Limit:
			retval = _copyLimit(from);
			break;
2728 2729 2730 2731

			/*
			 * PRIMITIVE NODES
			 */
2732 2733 2734 2735 2736 2737
		case T_Alias:
			retval = _copyAlias(from);
			break;
		case T_RangeVar:
			retval = _copyRangeVar(from);
			break;
2738 2739 2740 2741 2742 2743 2744 2745 2746
		case T_Var:
			retval = _copyVar(from);
			break;
		case T_Const:
			retval = _copyConst(from);
			break;
		case T_Param:
			retval = _copyParam(from);
			break;
2747 2748 2749
		case T_Aggref:
			retval = _copyAggref(from);
			break;
2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761
		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;
2762 2763 2764
		case T_ScalarArrayOpExpr:
			retval = _copyScalarArrayOpExpr(from);
			break;
2765 2766 2767
		case T_BoolExpr:
			retval = _copyBoolExpr(from);
			break;
2768 2769 2770
		case T_SubLink:
			retval = _copySubLink(from);
			break;
2771 2772
		case T_SubPlan:
			retval = _copySubPlan(from);
2773
			break;
2774 2775 2776
		case T_FieldSelect:
			retval = _copyFieldSelect(from);
			break;
2777 2778 2779
		case T_FieldStore:
			retval = _copyFieldStore(from);
			break;
2780 2781 2782
		case T_RelabelType:
			retval = _copyRelabelType(from);
			break;
2783 2784 2785
		case T_ConvertRowtypeExpr:
			retval = _copyConvertRowtypeExpr(from);
			break;
2786 2787 2788 2789 2790 2791
		case T_CaseExpr:
			retval = _copyCaseExpr(from);
			break;
		case T_CaseWhen:
			retval = _copyCaseWhen(from);
			break;
2792 2793 2794
		case T_CaseTestExpr:
			retval = _copyCaseTestExpr(from);
			break;
2795 2796 2797
		case T_ArrayExpr:
			retval = _copyArrayExpr(from);
			break;
2798 2799 2800
		case T_RowExpr:
			retval = _copyRowExpr(from);
			break;
2801 2802 2803
		case T_CoalesceExpr:
			retval = _copyCoalesceExpr(from);
			break;
2804 2805 2806
		case T_MinMaxExpr:
			retval = _copyMinMaxExpr(from);
			break;
2807 2808 2809
		case T_NullIfExpr:
			retval = _copyNullIfExpr(from);
			break;
2810 2811 2812 2813 2814 2815
		case T_NullTest:
			retval = _copyNullTest(from);
			break;
		case T_BooleanTest:
			retval = _copyBooleanTest(from);
			break;
2816 2817
		case T_CoerceToDomain:
			retval = _copyCoerceToDomain(from);
2818
			break;
2819 2820
		case T_CoerceToDomainValue:
			retval = _copyCoerceToDomainValue(from);
2821
			break;
2822 2823 2824
		case T_SetToDefault:
			retval = _copySetToDefault(from);
			break;
2825 2826 2827
		case T_TargetEntry:
			retval = _copyTargetEntry(from);
			break;
2828 2829 2830
		case T_RangeTblRef:
			retval = _copyRangeTblRef(from);
			break;
2831 2832 2833
		case T_JoinExpr:
			retval = _copyJoinExpr(from);
			break;
2834 2835 2836
		case T_FromExpr:
			retval = _copyFromExpr(from);
			break;
2837 2838 2839 2840

			/*
			 * RELATION NODES
			 */
2841 2842
		case T_PathKeyItem:
			retval = _copyPathKeyItem(from);
2843
			break;
2844 2845
		case T_RestrictInfo:
			retval = _copyRestrictInfo(from);
2846
			break;
2847 2848 2849
		case T_InClauseInfo:
			retval = _copyInClauseInfo(from);
			break;
2850 2851

			/*
2852
			 * VALUE NODES
2853
			 */
2854 2855 2856
		case T_Integer:
		case T_Float:
		case T_String:
2857
		case T_BitString:
2858
		case T_Null:
2859
			retval = _copyValue(from);
2860
			break;
2861 2862 2863 2864

			/*
			 * LIST NODES
			 */
2865
		case T_List:
2866 2867
			retval = _copyList(from);
			break;
B
Bruce Momjian 已提交
2868

2869
			/*
B
Bruce Momjian 已提交
2870 2871
			 * Lists of integers and OIDs don't need to be deep-copied, so
			 * we perform a shallow copy via list_copy()
2872 2873 2874 2875
			 */
		case T_IntList:
		case T_OidList:
			retval = list_copy(from);
2876
			break;
2877 2878 2879 2880

			/*
			 * PARSE NODES
			 */
2881 2882 2883
		case T_Query:
			retval = _copyQuery(from);
			break;
2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895
		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;
2896 2897 2898
		case T_SetOperationStmt:
			retval = _copySetOperationStmt(from);
			break;
2899 2900 2901
		case T_AlterTableStmt:
			retval = _copyAlterTableStmt(from);
			break;
T
Tom Lane 已提交
2902 2903 2904
		case T_AlterTableCmd:
			retval = _copyAlterTableCmd(from);
			break;
B
Bruce Momjian 已提交
2905 2906 2907
		case T_AlterDomainStmt:
			retval = _copyAlterDomainStmt(from);
			break;
2908 2909
		case T_GrantStmt:
			retval = _copyGrantStmt(from);
2910
			break;
2911 2912 2913
		case T_GrantRoleStmt:
			retval = _copyGrantRoleStmt(from);
			break;
2914 2915 2916
		case T_DeclareCursorStmt:
			retval = _copyDeclareCursorStmt(from);
			break;
2917 2918 2919
		case T_ClosePortalStmt:
			retval = _copyClosePortalStmt(from);
			break;
2920 2921 2922 2923 2924 2925 2926 2927 2928
		case T_ClusterStmt:
			retval = _copyClusterStmt(from);
			break;
		case T_CopyStmt:
			retval = _copyCopyStmt(from);
			break;
		case T_CreateStmt:
			retval = _copyCreateStmt(from);
			break;
B
Bruce Momjian 已提交
2929 2930 2931
		case T_InhRelation:
			retval = _copyInhRelation(from);
			break;
2932 2933 2934 2935 2936 2937
		case T_DefineStmt:
			retval = _copyDefineStmt(from);
			break;
		case T_DropStmt:
			retval = _copyDropStmt(from);
			break;
2938 2939 2940
		case T_TruncateStmt:
			retval = _copyTruncateStmt(from);
			break;
2941 2942 2943 2944 2945 2946 2947 2948 2949
		case T_CommentStmt:
			retval = _copyCommentStmt(from);
			break;
		case T_FetchStmt:
			retval = _copyFetchStmt(from);
			break;
		case T_IndexStmt:
			retval = _copyIndexStmt(from);
			break;
2950 2951
		case T_CreateFunctionStmt:
			retval = _copyCreateFunctionStmt(from);
2952
			break;
2953 2954 2955
		case T_FunctionParameter:
			retval = _copyFunctionParameter(from);
			break;
2956 2957 2958
		case T_AlterFunctionStmt:
			retval = _copyAlterFunctionStmt(from);
			break;
2959 2960 2961 2962 2963 2964 2965 2966 2967
		case T_RemoveAggrStmt:
			retval = _copyRemoveAggrStmt(from);
			break;
		case T_RemoveFuncStmt:
			retval = _copyRemoveFuncStmt(from);
			break;
		case T_RemoveOperStmt:
			retval = _copyRemoveOperStmt(from);
			break;
2968 2969 2970
		case T_RemoveOpClassStmt:
			retval = _copyRemoveOpClassStmt(from);
			break;
2971 2972 2973
		case T_RenameStmt:
			retval = _copyRenameStmt(from);
			break;
2974 2975 2976
		case T_AlterOwnerStmt:
			retval = _copyAlterOwnerStmt(from);
			break;
2977 2978 2979
		case T_RuleStmt:
			retval = _copyRuleStmt(from);
			break;
2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991
		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 已提交
2992 2993 2994
		case T_CompositeTypeStmt:
			retval = _copyCompositeTypeStmt(from);
			break;
2995 2996 2997
		case T_ViewStmt:
			retval = _copyViewStmt(from);
			break;
2998 2999 3000
		case T_LoadStmt:
			retval = _copyLoadStmt(from);
			break;
3001 3002 3003
		case T_CreateDomainStmt:
			retval = _copyCreateDomainStmt(from);
			break;
3004 3005 3006 3007 3008 3009
		case T_CreateOpClassStmt:
			retval = _copyCreateOpClassStmt(from);
			break;
		case T_CreateOpClassItem:
			retval = _copyCreateOpClassItem(from);
			break;
3010 3011 3012
		case T_CreatedbStmt:
			retval = _copyCreatedbStmt(from);
			break;
3013 3014 3015
		case T_AlterDatabaseSetStmt:
			retval = _copyAlterDatabaseSetStmt(from);
			break;
3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027
		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 已提交
3028 3029 3030
		case T_AlterSeqStmt:
			retval = _copyAlterSeqStmt(from);
			break;
3031 3032 3033
		case T_VariableSetStmt:
			retval = _copyVariableSetStmt(from);
			break;
3034 3035 3036
		case T_VariableShowStmt:
			retval = _copyVariableShowStmt(from);
			break;
3037 3038 3039
		case T_VariableResetStmt:
			retval = _copyVariableResetStmt(from);
			break;
3040 3041 3042 3043 3044 3045
		case T_CreateTableSpaceStmt:
			retval = _copyCreateTableSpaceStmt(from);
			break;
		case T_DropTableSpaceStmt:
			retval = _copyDropTableSpaceStmt(from);
			break;
3046 3047 3048
		case T_CreateTrigStmt:
			retval = _copyCreateTrigStmt(from);
			break;
3049 3050
		case T_DropPropertyStmt:
			retval = _copyDropPropertyStmt(from);
3051 3052 3053 3054 3055 3056 3057
			break;
		case T_CreatePLangStmt:
			retval = _copyCreatePLangStmt(from);
			break;
		case T_DropPLangStmt:
			retval = _copyDropPLangStmt(from);
			break;
3058 3059
		case T_CreateRoleStmt:
			retval = _copyCreateRoleStmt(from);
3060
			break;
3061 3062
		case T_AlterRoleStmt:
			retval = _copyAlterRoleStmt(from);
3063
			break;
3064 3065
		case T_AlterRoleSetStmt:
			retval = _copyAlterRoleSetStmt(from);
3066
			break;
3067 3068
		case T_DropRoleStmt:
			retval = _copyDropRoleStmt(from);
3069
			break;
3070 3071 3072
		case T_LockStmt:
			retval = _copyLockStmt(from);
			break;
3073 3074 3075 3076 3077 3078
		case T_ConstraintsSetStmt:
			retval = _copyConstraintsSetStmt(from);
			break;
		case T_ReindexStmt:
			retval = _copyReindexStmt(from);
			break;
V
Vadim B. Mikheev 已提交
3079
		case T_CheckPointStmt:
B
Bruce Momjian 已提交
3080
			retval = (void *) makeNode(CheckPointStmt);
V
Vadim B. Mikheev 已提交
3081
			break;
3082 3083 3084
		case T_CreateSchemaStmt:
			retval = _copyCreateSchemaStmt(from);
			break;
3085 3086 3087 3088 3089 3090 3091 3092 3093
		case T_CreateConversionStmt:
			retval = _copyCreateConversionStmt(from);
			break;
		case T_CreateCastStmt:
			retval = _copyCreateCastStmt(from);
			break;
		case T_DropCastStmt:
			retval = _copyDropCastStmt(from);
			break;
3094 3095 3096 3097 3098 3099 3100 3101 3102
		case T_PrepareStmt:
			retval = _copyPrepareStmt(from);
			break;
		case T_ExecuteStmt:
			retval = _copyExecuteStmt(from);
			break;
		case T_DeallocateStmt:
			retval = _copyDeallocateStmt(from);
			break;
3103

3104 3105 3106
		case T_A_Expr:
			retval = _copyAExpr(from);
			break;
3107 3108 3109 3110 3111
		case T_ColumnRef:
			retval = _copyColumnRef(from);
			break;
		case T_ParamRef:
			retval = _copyParamRef(from);
3112
			break;
3113 3114 3115
		case T_A_Const:
			retval = _copyAConst(from);
			break;
3116 3117 3118 3119 3120 3121
		case T_FuncCall:
			retval = _copyFuncCall(from);
			break;
		case T_A_Indices:
			retval = _copyAIndices(from);
			break;
3122 3123
		case T_A_Indirection:
			retval = _copyA_Indirection(from);
3124
			break;
3125 3126 3127
		case T_ResTarget:
			retval = _copyResTarget(from);
			break;
3128 3129 3130
		case T_TypeCast:
			retval = _copyTypeCast(from);
			break;
3131 3132
		case T_SortBy:
			retval = _copySortBy(from);
3133
			break;
3134 3135 3136
		case T_RangeSubselect:
			retval = _copyRangeSubselect(from);
			break;
3137 3138 3139
		case T_RangeFunction:
			retval = _copyRangeFunction(from);
			break;
3140 3141 3142
		case T_TypeName:
			retval = _copyTypeName(from);
			break;
3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154
		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;
3155 3156
		case T_RangeTblEntry:
			retval = _copyRangeTblEntry(from);
3157
			break;
3158 3159 3160 3161 3162 3163
		case T_SortClause:
			retval = _copySortClause(from);
			break;
		case T_GroupClause:
			retval = _copyGroupClause(from);
			break;
3164 3165 3166
		case T_FkConstraint:
			retval = _copyFkConstraint(from);
			break;
3167 3168 3169
		case T_PrivGrantee:
			retval = _copyPrivGrantee(from);
			break;
3170 3171 3172
		case T_FuncWithArgs:
			retval = _copyFuncWithArgs(from);
			break;
3173

3174
		default:
3175
			elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
3176
			retval = from;		/* keep compiler quiet */
3177
			break;
3178
	}
3179

3180
	return retval;
3181
}