copyfuncs.c 63.7 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
 *
 *
14
 * Portions Copyright (c) 1996-2007, 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.359 2007/01/05 22:19:29 momjian Exp $
19 20 21 22 23 24
 *
 *-------------------------------------------------------------------------
 */

#include "postgres.h"

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


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

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

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

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

61 62

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

67 68
/*
 * CopyPlanFields
69
 *
70 71
 *		This function copies the fields of the Plan node.  It is used by
 *		all the copy functions for classes which inherit from Plan.
72 73
 */
static void
74
CopyPlanFields(Plan *from, Plan *newnode)
75
{
76 77 78 79 80 81 82 83
	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);
84
	COPY_NODE_FIELD(initPlan);
85 86
	COPY_BITMAPSET_FIELD(extParam);
	COPY_BITMAPSET_FIELD(allParam);
87
	COPY_SCALAR_FIELD(nParamExec);
88 89
}

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

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

	return newnode;
104 105 106
}


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

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

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

	return newnode;
126 127
}

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

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

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

	return newnode;
148 149
}

150 151 152 153 154 155
/*
 * _copyBitmapAnd
 */
static BitmapAnd *
_copyBitmapAnd(BitmapAnd *from)
{
B
Bruce Momjian 已提交
156
	BitmapAnd  *newnode = makeNode(BitmapAnd);
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176

	/*
	 * 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)
{
B
Bruce Momjian 已提交
177
	BitmapOr   *newnode = makeNode(BitmapOr);
178 179 180 181 182 183 184 185 186 187 188 189 190 191

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

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

	return newnode;
}

192

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

	COPY_SCALAR_FIELD(scanrelid);
205 206
}

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

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

	return newnode;
221 222
}

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

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

	return newnode;
237 238
}

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

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

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

	return newnode;
263 264
}

265 266 267 268 269 270
/*
 * _copyBitmapIndexScan
 */
static BitmapIndexScan *
_copyBitmapIndexScan(BitmapIndexScan *from)
{
B
Bruce Momjian 已提交
271
	BitmapIndexScan *newnode = makeNode(BitmapIndexScan);
272 273 274 275 276 277 278 279 280

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

	/*
	 * copy remainder of node
	 */
281 282 283 284 285
	COPY_SCALAR_FIELD(indexid);
	COPY_NODE_FIELD(indexqual);
	COPY_NODE_FIELD(indexqualorig);
	COPY_NODE_FIELD(indexstrategy);
	COPY_NODE_FIELD(indexsubtype);
286 287 288 289 290 291 292 293 294 295

	return newnode;
}

/*
 * _copyBitmapHeapScan
 */
static BitmapHeapScan *
_copyBitmapHeapScan(BitmapHeapScan *from)
{
B
Bruce Momjian 已提交
296
	BitmapHeapScan *newnode = makeNode(BitmapHeapScan);
297 298 299 300 301 302 303 304 305 306 307 308 309 310

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

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

	return newnode;
}

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

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

	/*
	 * copy remainder of node
326
	 */
327
	COPY_NODE_FIELD(tidquals);
328

329 330 331
	return newnode;
}

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

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

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

	return newnode;
}

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

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

	return newnode;
}
368

369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
/*
 * _copyValuesScan
 */
static ValuesScan *
_copyValuesScan(ValuesScan *from)
{
	ValuesScan *newnode = makeNode(ValuesScan);

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

	return newnode;
}

385 386
/*
 * CopyJoinFields
387
 *
388 389
 *		This function copies the fields of the Join node.  It is used by
 *		all the copy functions for classes which inherit from Join.
390 391
 */
static void
392
CopyJoinFields(Join *from, Join *newnode)
393
{
394 395 396 397
	CopyPlanFields((Plan *) from, (Plan *) newnode);

	COPY_SCALAR_FIELD(jointype);
	COPY_NODE_FIELD(joinqual);
398 399 400
}


401 402
/*
 * _copyJoin
403
 */
404
static Join *
405
_copyJoin(Join *from)
406
{
407
	Join	   *newnode = makeNode(Join);
408

409 410
	/*
	 * copy node superclass fields
411 412 413 414
	 */
	CopyJoinFields(from, newnode);

	return newnode;
415 416 417
}


418 419
/*
 * _copyNestLoop
420 421
 */
static NestLoop *
422
_copyNestLoop(NestLoop *from)
423
{
424
	NestLoop   *newnode = makeNode(NestLoop);
425

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

	return newnode;
432 433 434
}


435 436
/*
 * _copyMergeJoin
437 438
 */
static MergeJoin *
439
_copyMergeJoin(MergeJoin *from)
440
{
441
	MergeJoin  *newnode = makeNode(MergeJoin);
442

443 444
	/*
	 * copy node superclass fields
445 446 447
	 */
	CopyJoinFields((Join *) from, (Join *) newnode);

448 449
	/*
	 * copy remainder of node
450
	 */
451
	COPY_NODE_FIELD(mergeclauses);
452 453
	COPY_NODE_FIELD(mergefamilies);
	COPY_NODE_FIELD(mergestrategies);
454 455

	return newnode;
456 457
}

458 459
/*
 * _copyHashJoin
460 461
 */
static HashJoin *
462
_copyHashJoin(HashJoin *from)
463
{
464
	HashJoin   *newnode = makeNode(HashJoin);
465

466 467
	/*
	 * copy node superclass fields
468 469 470
	 */
	CopyJoinFields((Join *) from, (Join *) newnode);

471 472
	/*
	 * copy remainder of node
473
	 */
474
	COPY_NODE_FIELD(hashclauses);
475 476

	return newnode;
477 478 479
}


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

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

	return newnode;
494 495 496
}


497 498
/*
 * _copySort
499
 */
500
static Sort *
501
_copySort(Sort *from)
502
{
503
	Sort	   *newnode = makeNode(Sort);
504

505 506
	/*
	 * copy node superclass fields
507 508
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
509

510 511 512
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
	COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
513 514

	return newnode;
515 516
}

V
Vadim B. Mikheev 已提交
517

518 519
/*
 * _copyGroup
V
Vadim B. Mikheev 已提交
520 521 522 523 524
 */
static Group *
_copyGroup(Group *from)
{
	Group	   *newnode = makeNode(Group);
525

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

528 529
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
V
Vadim B. Mikheev 已提交
530 531 532 533

	return newnode;
}

534 535
/*
 * _copyAgg
536
 */
537
static Agg *
B
Bruce Momjian 已提交
538
_copyAgg(Agg *from)
539
{
540
	Agg		   *newnode = makeNode(Agg);
541 542 543

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

544 545
	COPY_SCALAR_FIELD(aggstrategy);
	COPY_SCALAR_FIELD(numCols);
546
	if (from->numCols > 0)
547 548
		COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
	COPY_SCALAR_FIELD(numGroups);
549

550
	return newnode;
551 552
}

553 554
/*
 * _copyUnique
555
 */
556
static Unique *
557
_copyUnique(Unique *from)
558
{
559
	Unique	   *newnode = makeNode(Unique);
560

561 562
	/*
	 * copy node superclass fields
563 564 565
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

566 567
	/*
	 * copy remainder of node
568
	 */
569 570
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
571 572

	return newnode;
573 574
}

575
/*
576
 * _copyHash
577
 */
578 579
static Hash *
_copyHash(Hash *from)
580
{
581
	Hash	   *newnode = makeNode(Hash);
582

583 584
	/*
	 * copy node superclass fields
585 586 587
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

588 589
	/*
	 * copy remainder of node
590 591 592 593
	 */

	return newnode;
}
594

595
/*
596
 * _copySetOp
597
 */
598 599
static SetOp *
_copySetOp(SetOp *from)
600
{
601
	SetOp	   *newnode = makeNode(SetOp);
602

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

608 609
	/*
	 * copy remainder of node
610
	 */
611 612 613 614
	COPY_SCALAR_FIELD(cmd);
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
	COPY_SCALAR_FIELD(flagColIdx);
615 616 617 618

	return newnode;
}

619
/*
620
 * _copyLimit
621
 */
622 623
static Limit *
_copyLimit(Limit *from)
624
{
625
	Limit	   *newnode = makeNode(Limit);
626

627 628
	/*
	 * copy node superclass fields
629 630 631
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

632 633
	/*
	 * copy remainder of node
634
	 */
635 636
	COPY_NODE_FIELD(limitOffset);
	COPY_NODE_FIELD(limitCount);
637 638

	return newnode;
639 640 641
}

/* ****************************************************************
642
 *					   primnodes.h copy functions
643 644 645
 * ****************************************************************
 */

646 647 648
/*
 * _copyAlias
 */
649 650 651 652
static Alias *
_copyAlias(Alias *from)
{
	Alias	   *newnode = makeNode(Alias);
653

654 655
	COPY_STRING_FIELD(aliasname);
	COPY_NODE_FIELD(colnames);
656

657 658
	return newnode;
}
659

660 661 662
/*
 * _copyRangeVar
 */
663 664 665 666 667 668 669 670 671 672 673
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);
674 675

	return newnode;
676 677
}

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

685 686
/*
 * _copyVar
687
 */
688
static Var *
689
_copyVar(Var *from)
690
{
691
	Var		   *newnode = makeNode(Var);
692

693 694 695 696 697 698 699
	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);
700 701

	return newnode;
702 703
}

704 705
/*
 * _copyConst
706
 */
707
static Const *
708
_copyConst(Const *from)
709
{
710
	Const	   *newnode = makeNode(Const);
711

712 713
	COPY_SCALAR_FIELD(consttype);
	COPY_SCALAR_FIELD(constlen);
714

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

733 734
	COPY_SCALAR_FIELD(constisnull);
	COPY_SCALAR_FIELD(constbyval);
735 736

	return newnode;
737 738
}

739 740
/*
 * _copyParam
741
 */
742
static Param *
743
_copyParam(Param *from)
744
{
745
	Param	   *newnode = makeNode(Param);
746

747 748 749
	COPY_SCALAR_FIELD(paramkind);
	COPY_SCALAR_FIELD(paramid);
	COPY_SCALAR_FIELD(paramtype);
750
	COPY_SCALAR_FIELD(paramtypmod);
751 752

	return newnode;
753 754
}

755
/*
756
 * _copyAggref
757
 */
758 759
static Aggref *
_copyAggref(Aggref *from)
760
{
761 762 763 764
	Aggref	   *newnode = makeNode(Aggref);

	COPY_SCALAR_FIELD(aggfnoid);
	COPY_SCALAR_FIELD(aggtype);
765
	COPY_NODE_FIELD(args);
766
	COPY_SCALAR_FIELD(agglevelsup);
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781
	COPY_SCALAR_FIELD(aggstar);
	COPY_SCALAR_FIELD(aggdistinct);

	return newnode;
}

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

	COPY_SCALAR_FIELD(refrestype);
782 783
	COPY_SCALAR_FIELD(refarraytype);
	COPY_SCALAR_FIELD(refelemtype);
784 785 786 787 788 789 790 791 792 793 794 795
	COPY_NODE_FIELD(refupperindexpr);
	COPY_NODE_FIELD(reflowerindexpr);
	COPY_NODE_FIELD(refexpr);
	COPY_NODE_FIELD(refassgnexpr);

	return newnode;
}

/*
 * _copyFuncExpr
 */
static FuncExpr *
796
_copyFuncExpr(FuncExpr *from)
797
{
B
Bruce Momjian 已提交
798
	FuncExpr   *newnode = makeNode(FuncExpr);
799

800 801 802 803
	COPY_SCALAR_FIELD(funcid);
	COPY_SCALAR_FIELD(funcresulttype);
	COPY_SCALAR_FIELD(funcretset);
	COPY_SCALAR_FIELD(funcformat);
804
	COPY_NODE_FIELD(args);
805

806
	return newnode;
807 808
}

809
/*
810
 * _copyOpExpr
811
 */
812
static OpExpr *
813
_copyOpExpr(OpExpr *from)
814
{
815
	OpExpr	   *newnode = makeNode(OpExpr);
816

817 818 819 820 821 822 823 824 825 826
	COPY_SCALAR_FIELD(opno);
	COPY_SCALAR_FIELD(opfuncid);
	COPY_SCALAR_FIELD(opresulttype);
	COPY_SCALAR_FIELD(opretset);
	COPY_NODE_FIELD(args);

	return newnode;
}

/*
827
 * _copyDistinctExpr (same as OpExpr)
828 829
 */
static DistinctExpr *
830
_copyDistinctExpr(DistinctExpr *from)
831
{
B
Bruce Momjian 已提交
832
	DistinctExpr *newnode = makeNode(DistinctExpr);
833 834 835 836 837 838 839 840 841 842

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

	return newnode;
}

843 844 845 846
/*
 * _copyScalarArrayOpExpr
 */
static ScalarArrayOpExpr *
847
_copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
848
{
B
Bruce Momjian 已提交
849
	ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
850 851 852 853 854 855 856 857 858

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

	return newnode;
}

859 860 861 862
/*
 * _copyBoolExpr
 */
static BoolExpr *
863
_copyBoolExpr(BoolExpr *from)
864
{
B
Bruce Momjian 已提交
865
	BoolExpr   *newnode = makeNode(BoolExpr);
866 867 868

	COPY_SCALAR_FIELD(boolop);
	COPY_NODE_FIELD(args);
869 870

	return newnode;
871 872
}

873 874
/*
 * _copySubLink
875 876 877 878
 */
static SubLink *
_copySubLink(SubLink *from)
{
879
	SubLink    *newnode = makeNode(SubLink);
880

881
	COPY_SCALAR_FIELD(subLinkType);
882
	COPY_NODE_FIELD(testexpr);
883
	COPY_NODE_FIELD(operName);
884
	COPY_NODE_FIELD(subselect);
885 886 887 888

	return newnode;
}

889
/*
890
 * _copySubPlan
891
 */
892 893
static SubPlan *
_copySubPlan(SubPlan *from)
894
{
895
	SubPlan    *newnode = makeNode(SubPlan);
896

897
	COPY_SCALAR_FIELD(subLinkType);
898
	COPY_NODE_FIELD(testexpr);
899
	COPY_NODE_FIELD(paramIds);
900 901 902
	COPY_NODE_FIELD(plan);
	COPY_SCALAR_FIELD(plan_id);
	COPY_NODE_FIELD(rtable);
903 904
	COPY_SCALAR_FIELD(useHashTable);
	COPY_SCALAR_FIELD(unknownEqFalse);
905 906
	COPY_NODE_FIELD(setParam);
	COPY_NODE_FIELD(parParam);
907 908 909 910 911
	COPY_NODE_FIELD(args);

	return newnode;
}

912 913
/*
 * _copyFieldSelect
914 915 916 917 918 919
 */
static FieldSelect *
_copyFieldSelect(FieldSelect *from)
{
	FieldSelect *newnode = makeNode(FieldSelect);

920 921 922 923
	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(fieldnum);
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
924 925 926 927

	return newnode;
}

928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
/*
 * _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;
}

944 945
/*
 * _copyRelabelType
946 947 948 949
 */
static RelabelType *
_copyRelabelType(RelabelType *from)
{
950
	RelabelType *newnode = makeNode(RelabelType);
951

952 953 954 955
	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
	COPY_SCALAR_FIELD(relabelformat);
956 957 958 959

	return newnode;
}

960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
/*
 * _copyConvertRowtypeExpr
 */
static ConvertRowtypeExpr *
_copyConvertRowtypeExpr(ConvertRowtypeExpr *from)
{
	ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);

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

	return newnode;
}

975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
/*
 * _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;
}

1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
/*
 * _copyCaseTestExpr
 */
static CaseTestExpr *
_copyCaseTestExpr(CaseTestExpr *from)
{
	CaseTestExpr *newnode = makeNode(CaseTestExpr);

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);

	return newnode;
}

1019 1020 1021 1022
/*
 * _copyArrayExpr
 */
static ArrayExpr *
1023
_copyArrayExpr(ArrayExpr *from)
1024
{
B
Bruce Momjian 已提交
1025
	ArrayExpr  *newnode = makeNode(ArrayExpr);
1026 1027 1028 1029

	COPY_SCALAR_FIELD(array_typeid);
	COPY_SCALAR_FIELD(element_typeid);
	COPY_NODE_FIELD(elements);
1030
	COPY_SCALAR_FIELD(multidims);
1031 1032 1033 1034

	return newnode;
}

1035 1036 1037 1038 1039 1040
/*
 * _copyRowExpr
 */
static RowExpr *
_copyRowExpr(RowExpr *from)
{
B
Bruce Momjian 已提交
1041
	RowExpr    *newnode = makeNode(RowExpr);
1042 1043 1044 1045 1046 1047 1048 1049

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

	return newnode;
}

1050 1051 1052 1053 1054 1055
/*
 * _copyRowCompareExpr
 */
static RowCompareExpr *
_copyRowCompareExpr(RowCompareExpr *from)
{
B
Bruce Momjian 已提交
1056
	RowCompareExpr *newnode = makeNode(RowCompareExpr);
1057 1058 1059

	COPY_SCALAR_FIELD(rctype);
	COPY_NODE_FIELD(opnos);
1060
	COPY_NODE_FIELD(opfamilies);
1061 1062 1063 1064 1065 1066
	COPY_NODE_FIELD(largs);
	COPY_NODE_FIELD(rargs);

	return newnode;
}

1067 1068 1069 1070
/*
 * _copyCoalesceExpr
 */
static CoalesceExpr *
1071
_copyCoalesceExpr(CoalesceExpr *from)
1072 1073 1074 1075 1076 1077 1078 1079 1080
{
	CoalesceExpr *newnode = makeNode(CoalesceExpr);

	COPY_SCALAR_FIELD(coalescetype);
	COPY_NODE_FIELD(args);

	return newnode;
}

1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
/*
 * _copyMinMaxExpr
 */
static MinMaxExpr *
_copyMinMaxExpr(MinMaxExpr *from)
{
	MinMaxExpr *newnode = makeNode(MinMaxExpr);

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

	return newnode;
}

1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
/*
 * _copyXmlExpr
 */
static XmlExpr *
_copyXmlExpr(XmlExpr *from)
{
	XmlExpr *newnode = makeNode(XmlExpr);

	COPY_SCALAR_FIELD(op);
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(named_args);
	COPY_NODE_FIELD(arg_names);
	COPY_NODE_FIELD(args);

	return newnode;
}

1113 1114 1115 1116
/*
 * _copyNullIfExpr (same as OpExpr)
 */
static NullIfExpr *
1117
_copyNullIfExpr(NullIfExpr *from)
1118
{
B
Bruce Momjian 已提交
1119
	NullIfExpr *newnode = makeNode(NullIfExpr);
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129

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

	return newnode;
}

1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158
/*
 * _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;
}

/*
1159
 * _copyCoerceToDomain
1160
 */
1161
static CoerceToDomain *
1162
_copyCoerceToDomain(CoerceToDomain *from)
1163
{
1164
	CoerceToDomain *newnode = makeNode(CoerceToDomain);
1165 1166

	COPY_NODE_FIELD(arg);
1167 1168 1169
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
	COPY_SCALAR_FIELD(coercionformat);
1170 1171 1172 1173 1174

	return newnode;
}

/*
1175
 * _copyCoerceToDomainValue
1176
 */
1177
static CoerceToDomainValue *
1178
_copyCoerceToDomainValue(CoerceToDomainValue *from)
1179
{
1180
	CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1181 1182 1183 1184 1185 1186 1187

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);

	return newnode;
}

1188 1189 1190 1191
/*
 * _copySetToDefault
 */
static SetToDefault *
1192
_copySetToDefault(SetToDefault *from)
1193 1194 1195 1196 1197 1198 1199 1200 1201
{
	SetToDefault *newnode = makeNode(SetToDefault);

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);

	return newnode;
}

1202 1203 1204 1205 1206 1207 1208 1209 1210
/*
 * _copyTargetEntry
 */
static TargetEntry *
_copyTargetEntry(TargetEntry *from)
{
	TargetEntry *newnode = makeNode(TargetEntry);

	COPY_NODE_FIELD(expr);
1211 1212 1213 1214 1215 1216
	COPY_SCALAR_FIELD(resno);
	COPY_STRING_FIELD(resname);
	COPY_SCALAR_FIELD(ressortgroupref);
	COPY_SCALAR_FIELD(resorigtbl);
	COPY_SCALAR_FIELD(resorigcol);
	COPY_SCALAR_FIELD(resjunk);
1217 1218 1219 1220 1221 1222 1223

	return newnode;
}

/*
 * _copyRangeTblRef
 */
1224 1225 1226 1227 1228
static RangeTblRef *
_copyRangeTblRef(RangeTblRef *from)
{
	RangeTblRef *newnode = makeNode(RangeTblRef);

1229
	COPY_SCALAR_FIELD(rtindex);
1230 1231 1232 1233

	return newnode;
}

1234 1235 1236
/*
 * _copyJoinExpr
 */
1237 1238 1239
static JoinExpr *
_copyJoinExpr(JoinExpr *from)
{
B
Bruce Momjian 已提交
1240
	JoinExpr   *newnode = makeNode(JoinExpr);
1241

1242 1243 1244 1245 1246 1247 1248 1249
	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 已提交
1250 1251 1252 1253

	return newnode;
}

1254 1255 1256
/*
 * _copyFromExpr
 */
1257 1258
static FromExpr *
_copyFromExpr(FromExpr *from)
B
Bruce Momjian 已提交
1259
{
1260
	FromExpr   *newnode = makeNode(FromExpr);
B
Bruce Momjian 已提交
1261

1262 1263
	COPY_NODE_FIELD(fromlist);
	COPY_NODE_FIELD(quals);
B
Bruce Momjian 已提交
1264 1265 1266 1267

	return newnode;
}

1268
/* ****************************************************************
1269
 *						relation.h copy functions
1270
 *
1271 1272
 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
 * There are some subsidiary structs that are useful to copy, though.
1273 1274 1275
 * ****************************************************************
 */

1276 1277
/*
 * _copyPathKeyItem
1278
 */
1279 1280
static PathKeyItem *
_copyPathKeyItem(PathKeyItem *from)
1281
{
1282
	PathKeyItem *newnode = makeNode(PathKeyItem);
1283

1284 1285
	COPY_NODE_FIELD(key);
	COPY_SCALAR_FIELD(sortop);
1286 1287

	return newnode;
1288 1289
}

1290 1291
/*
 * _copyRestrictInfo
1292
 */
1293
static RestrictInfo *
1294
_copyRestrictInfo(RestrictInfo *from)
1295
{
1296
	RestrictInfo *newnode = makeNode(RestrictInfo);
1297

1298
	COPY_NODE_FIELD(clause);
1299
	COPY_SCALAR_FIELD(is_pushed_down);
1300
	COPY_SCALAR_FIELD(outerjoin_delayed);
1301
	COPY_SCALAR_FIELD(can_join);
1302
	COPY_SCALAR_FIELD(pseudoconstant);
1303
	COPY_BITMAPSET_FIELD(clause_relids);
1304
	COPY_BITMAPSET_FIELD(required_relids);
1305 1306
	COPY_BITMAPSET_FIELD(left_relids);
	COPY_BITMAPSET_FIELD(right_relids);
1307
	COPY_NODE_FIELD(orclause);
1308 1309 1310 1311 1312
	COPY_SCALAR_FIELD(eval_cost);
	COPY_SCALAR_FIELD(this_selec);
	COPY_SCALAR_FIELD(mergejoinoperator);
	COPY_SCALAR_FIELD(left_sortop);
	COPY_SCALAR_FIELD(right_sortop);
1313
	COPY_SCALAR_FIELD(mergeopfamily);
B
Bruce Momjian 已提交
1314 1315

	/*
B
Bruce Momjian 已提交
1316
	 * Do not copy pathkeys, since they'd not be canonical in a copied query
B
Bruce Momjian 已提交
1317
	 */
1318 1319
	newnode->left_pathkey = NIL;
	newnode->right_pathkey = NIL;
1320 1321 1322 1323 1324 1325

	COPY_SCALAR_FIELD(left_mergescansel);
	COPY_SCALAR_FIELD(right_mergescansel);
	COPY_SCALAR_FIELD(hashjoinoperator);
	COPY_SCALAR_FIELD(left_bucketsize);
	COPY_SCALAR_FIELD(right_bucketsize);
1326 1327

	return newnode;
1328 1329
}

1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345
/*
 * _copyOuterJoinInfo
 */
static OuterJoinInfo *
_copyOuterJoinInfo(OuterJoinInfo *from)
{
	OuterJoinInfo *newnode = makeNode(OuterJoinInfo);

	COPY_BITMAPSET_FIELD(min_lefthand);
	COPY_BITMAPSET_FIELD(min_righthand);
	COPY_SCALAR_FIELD(is_full_join);
	COPY_SCALAR_FIELD(lhs_strict);

	return newnode;
}

1346 1347 1348 1349
/*
 * _copyInClauseInfo
 */
static InClauseInfo *
1350
_copyInClauseInfo(InClauseInfo *from)
1351 1352 1353
{
	InClauseInfo *newnode = makeNode(InClauseInfo);

1354 1355
	COPY_BITMAPSET_FIELD(lefthand);
	COPY_BITMAPSET_FIELD(righthand);
1356 1357 1358 1359 1360
	COPY_NODE_FIELD(sub_targetlist);

	return newnode;
}

1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379
/*
 * _copyAppendRelInfo
 */
static AppendRelInfo *
_copyAppendRelInfo(AppendRelInfo *from)
{
	AppendRelInfo *newnode = makeNode(AppendRelInfo);

	COPY_SCALAR_FIELD(parent_relid);
	COPY_SCALAR_FIELD(child_relid);
	COPY_SCALAR_FIELD(parent_reltype);
	COPY_SCALAR_FIELD(child_reltype);
	COPY_NODE_FIELD(col_mappings);
	COPY_NODE_FIELD(translated_vars);
	COPY_SCALAR_FIELD(parent_reloid);

	return newnode;
}

1380 1381 1382
/* ****************************************************************
 *					parsenodes.h copy functions
 * ****************************************************************
1383 1384 1385
 */

static RangeTblEntry *
1386
_copyRangeTblEntry(RangeTblEntry *from)
1387
{
1388
	RangeTblEntry *newnode = makeNode(RangeTblEntry);
1389

1390 1391 1392 1393
	COPY_SCALAR_FIELD(rtekind);
	COPY_SCALAR_FIELD(relid);
	COPY_NODE_FIELD(subquery);
	COPY_NODE_FIELD(funcexpr);
1394 1395
	COPY_NODE_FIELD(funccoltypes);
	COPY_NODE_FIELD(funccoltypmods);
1396
	COPY_NODE_FIELD(values_lists);
1397 1398 1399 1400 1401 1402
	COPY_SCALAR_FIELD(jointype);
	COPY_NODE_FIELD(joinaliasvars);
	COPY_NODE_FIELD(alias);
	COPY_NODE_FIELD(eref);
	COPY_SCALAR_FIELD(inh);
	COPY_SCALAR_FIELD(inFromCl);
1403
	COPY_SCALAR_FIELD(requiredPerms);
1404
	COPY_SCALAR_FIELD(checkAsUser);
1405 1406 1407 1408

	return newnode;
}

1409 1410 1411
static FkConstraint *
_copyFkConstraint(FkConstraint *from)
{
B
Bruce Momjian 已提交
1412
	FkConstraint *newnode = makeNode(FkConstraint);
1413

1414 1415 1416 1417 1418 1419 1420 1421 1422 1423
	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 已提交
1424

1425 1426 1427
	return newnode;
}

1428
static SortClause *
1429
_copySortClause(SortClause *from)
1430
{
1431
	SortClause *newnode = makeNode(SortClause);
1432

1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445
	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);
1446

1447
	return newnode;
1448 1449
}

1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461
static RowMarkClause *
_copyRowMarkClause(RowMarkClause *from)
{
	RowMarkClause *newnode = makeNode(RowMarkClause);

	COPY_SCALAR_FIELD(rti);
	COPY_SCALAR_FIELD(forUpdate);
	COPY_SCALAR_FIELD(noWait);

	return newnode;
}

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

1467
	COPY_SCALAR_FIELD(kind);
1468 1469 1470
	COPY_NODE_FIELD(name);
	COPY_NODE_FIELD(lexpr);
	COPY_NODE_FIELD(rexpr);
1471
	COPY_SCALAR_FIELD(location);
1472 1473 1474 1475

	return newnode;
}

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

1481
	COPY_NODE_FIELD(fields);
1482
	COPY_SCALAR_FIELD(location);
1483

1484
	return newnode;
1485 1486
}

1487 1488
static ParamRef *
_copyParamRef(ParamRef *from)
1489
{
B
Bruce Momjian 已提交
1490
	ParamRef   *newnode = makeNode(ParamRef);
1491

1492
	COPY_SCALAR_FIELD(number);
1493 1494 1495 1496

	return newnode;
}

1497 1498 1499 1500 1501
static A_Const *
_copyAConst(A_Const *from)
{
	A_Const    *newnode = makeNode(A_Const);

1502
	/* This part must duplicate _copyValue */
1503
	COPY_SCALAR_FIELD(val.type);
1504 1505 1506
	switch (from->val.type)
	{
		case T_Integer:
1507
			COPY_SCALAR_FIELD(val.val.ival);
1508 1509 1510 1511
			break;
		case T_Float:
		case T_String:
		case T_BitString:
1512
			COPY_STRING_FIELD(val.val.str);
1513 1514 1515 1516 1517
			break;
		case T_Null:
			/* nothing to do */
			break;
		default:
1518 1519
			elog(ERROR, "unrecognized node type: %d",
				 (int) from->val.type);
1520 1521 1522
			break;
	}

1523
	COPY_NODE_FIELD(typename);
1524 1525 1526 1527

	return newnode;
}

1528 1529 1530
static FuncCall *
_copyFuncCall(FuncCall *from)
{
B
Bruce Momjian 已提交
1531
	FuncCall   *newnode = makeNode(FuncCall);
1532

1533 1534 1535 1536
	COPY_NODE_FIELD(funcname);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(agg_star);
	COPY_SCALAR_FIELD(agg_distinct);
1537
	COPY_SCALAR_FIELD(location);
1538 1539 1540 1541 1542 1543 1544

	return newnode;
}

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

1547 1548
	COPY_NODE_FIELD(lidx);
	COPY_NODE_FIELD(uidx);
1549 1550 1551 1552

	return newnode;
}

1553 1554
static A_Indirection *
_copyA_Indirection(A_Indirection *from)
1555
{
1556
	A_Indirection *newnode = makeNode(A_Indirection);
1557

1558 1559
	COPY_NODE_FIELD(arg);
	COPY_NODE_FIELD(indirection);
1560 1561 1562 1563

	return newnode;
}

1564 1565 1566
static ResTarget *
_copyResTarget(ResTarget *from)
{
B
Bruce Momjian 已提交
1567
	ResTarget  *newnode = makeNode(ResTarget);
1568

1569 1570 1571
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(indirection);
	COPY_NODE_FIELD(val);
1572
	COPY_SCALAR_FIELD(location);
1573 1574 1575 1576

	return newnode;
}

1577
static TypeName *
1578
_copyTypeName(TypeName *from)
1579
{
1580
	TypeName   *newnode = makeNode(TypeName);
1581

1582 1583 1584 1585 1586
	COPY_NODE_FIELD(names);
	COPY_SCALAR_FIELD(typeid);
	COPY_SCALAR_FIELD(timezone);
	COPY_SCALAR_FIELD(setof);
	COPY_SCALAR_FIELD(pct_type);
1587 1588
	COPY_NODE_FIELD(typmods);
	COPY_SCALAR_FIELD(typemod);
1589
	COPY_NODE_FIELD(arrayBounds);
1590
	COPY_SCALAR_FIELD(location);
1591 1592

	return newnode;
1593 1594
}

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

1600
	COPY_SCALAR_FIELD(sortby_kind);
1601 1602
	COPY_NODE_FIELD(useOp);
	COPY_NODE_FIELD(node);
1603 1604 1605 1606 1607 1608 1609

	return newnode;
}

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

1612 1613
	COPY_NODE_FIELD(subquery);
	COPY_NODE_FIELD(alias);
1614 1615 1616 1617

	return newnode;
}

1618 1619 1620
static RangeFunction *
_copyRangeFunction(RangeFunction *from)
{
B
Bruce Momjian 已提交
1621
	RangeFunction *newnode = makeNode(RangeFunction);
1622

1623 1624 1625
	COPY_NODE_FIELD(funccallnode);
	COPY_NODE_FIELD(alias);
	COPY_NODE_FIELD(coldeflist);
1626 1627 1628 1629

	return newnode;
}

1630 1631 1632 1633 1634
static TypeCast *
_copyTypeCast(TypeCast *from)
{
	TypeCast   *newnode = makeNode(TypeCast);

1635 1636
	COPY_NODE_FIELD(arg);
	COPY_NODE_FIELD(typename);
1637 1638 1639 1640

	return newnode;
}

1641 1642 1643
static IndexElem *
_copyIndexElem(IndexElem *from)
{
B
Bruce Momjian 已提交
1644
	IndexElem  *newnode = makeNode(IndexElem);
1645

1646
	COPY_STRING_FIELD(name);
1647
	COPY_NODE_FIELD(expr);
1648
	COPY_NODE_FIELD(opclass);
1649 1650 1651 1652 1653 1654 1655

	return newnode;
}

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

1658 1659 1660 1661 1662 1663 1664 1665
	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);
1666 1667 1668 1669 1670 1671 1672

	return newnode;
}

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

1675 1676 1677 1678 1679
	COPY_SCALAR_FIELD(contype);
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(raw_expr);
	COPY_STRING_FIELD(cooked_expr);
	COPY_NODE_FIELD(keys);
B
Bruce Momjian 已提交
1680
	COPY_NODE_FIELD(options);
1681
	COPY_STRING_FIELD(indexspace);
1682 1683 1684 1685

	return newnode;
}

1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696
static DefElem *
_copyDefElem(DefElem *from)
{
	DefElem    *newnode = makeNode(DefElem);

	COPY_STRING_FIELD(defname);
	COPY_NODE_FIELD(arg);

	return newnode;
}

1697 1698 1699 1700 1701 1702 1703
static LockingClause *
_copyLockingClause(LockingClause *from)
{
	LockingClause *newnode = makeNode(LockingClause);

	COPY_NODE_FIELD(lockedRels);
	COPY_SCALAR_FIELD(forUpdate);
1704
	COPY_SCALAR_FIELD(noWait);
1705 1706 1707 1708

	return newnode;
}

1709 1710 1711 1712 1713 1714 1715
static Query *
_copyQuery(Query *from)
{
	Query	   *newnode = makeNode(Query);

	COPY_SCALAR_FIELD(commandType);
	COPY_SCALAR_FIELD(querySource);
1716
	COPY_SCALAR_FIELD(canSetTag);
1717 1718 1719
	COPY_NODE_FIELD(utilityStmt);
	COPY_SCALAR_FIELD(resultRelation);
	COPY_NODE_FIELD(into);
B
Bruce Momjian 已提交
1720
	COPY_NODE_FIELD(intoOptions);
1721 1722
	COPY_SCALAR_FIELD(intoOnCommit);
	COPY_STRING_FIELD(intoTableSpaceName);
1723 1724 1725 1726 1727
	COPY_SCALAR_FIELD(hasAggs);
	COPY_SCALAR_FIELD(hasSubLinks);
	COPY_NODE_FIELD(rtable);
	COPY_NODE_FIELD(jointree);
	COPY_NODE_FIELD(targetList);
1728
	COPY_NODE_FIELD(returningList);
1729 1730 1731 1732 1733 1734
	COPY_NODE_FIELD(groupClause);
	COPY_NODE_FIELD(havingQual);
	COPY_NODE_FIELD(distinctClause);
	COPY_NODE_FIELD(sortClause);
	COPY_NODE_FIELD(limitOffset);
	COPY_NODE_FIELD(limitCount);
1735
	COPY_NODE_FIELD(rowMarks);
1736
	COPY_NODE_FIELD(setOperations);
1737
	COPY_NODE_FIELD(resultRelations);
1738
	COPY_NODE_FIELD(returningLists);
1739

1740
	return newnode;
1741 1742
}

1743 1744 1745 1746
static InsertStmt *
_copyInsertStmt(InsertStmt *from)
{
	InsertStmt *newnode = makeNode(InsertStmt);
B
Bruce Momjian 已提交
1747

1748 1749 1750
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(cols);
	COPY_NODE_FIELD(selectStmt);
1751
	COPY_NODE_FIELD(returningList);
1752 1753 1754 1755 1756 1757 1758 1759

	return newnode;
}

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

1761
	COPY_NODE_FIELD(relation);
1762
	COPY_NODE_FIELD(usingClause);
1763 1764
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(returningList);
1765 1766 1767 1768 1769 1770 1771 1772

	return newnode;
}

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

1774 1775 1776 1777
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(targetList);
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(fromClause);
1778
	COPY_NODE_FIELD(returningList);
1779 1780 1781 1782 1783 1784 1785 1786

	return newnode;
}

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

1788 1789 1790
	COPY_NODE_FIELD(distinctClause);
	COPY_NODE_FIELD(into);
	COPY_NODE_FIELD(intoColNames);
B
Bruce Momjian 已提交
1791
	COPY_NODE_FIELD(intoOptions);
1792 1793
	COPY_SCALAR_FIELD(intoOnCommit);
	COPY_STRING_FIELD(intoTableSpaceName);
1794 1795 1796 1797 1798
	COPY_NODE_FIELD(targetList);
	COPY_NODE_FIELD(fromClause);
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(groupClause);
	COPY_NODE_FIELD(havingClause);
1799
	COPY_NODE_FIELD(valuesLists);
1800 1801 1802
	COPY_NODE_FIELD(sortClause);
	COPY_NODE_FIELD(limitOffset);
	COPY_NODE_FIELD(limitCount);
1803
	COPY_NODE_FIELD(lockingClause);
1804 1805 1806 1807
	COPY_SCALAR_FIELD(op);
	COPY_SCALAR_FIELD(all);
	COPY_NODE_FIELD(larg);
	COPY_NODE_FIELD(rarg);
1808 1809 1810 1811

	return newnode;
}

1812 1813 1814 1815
static SetOperationStmt *
_copySetOperationStmt(SetOperationStmt *from)
{
	SetOperationStmt *newnode = makeNode(SetOperationStmt);
B
Bruce Momjian 已提交
1816

1817 1818 1819 1820
	COPY_SCALAR_FIELD(op);
	COPY_SCALAR_FIELD(all);
	COPY_NODE_FIELD(larg);
	COPY_NODE_FIELD(rarg);
1821
	COPY_NODE_FIELD(colTypes);
1822
	COPY_NODE_FIELD(colTypmods);
1823 1824 1825 1826

	return newnode;
}

1827 1828 1829 1830
static AlterTableStmt *
_copyAlterTableStmt(AlterTableStmt *from)
{
	AlterTableStmt *newnode = makeNode(AlterTableStmt);
B
Bruce Momjian 已提交
1831

1832
	COPY_NODE_FIELD(relation);
T
Tom Lane 已提交
1833
	COPY_NODE_FIELD(cmds);
T
Tom Lane 已提交
1834
	COPY_SCALAR_FIELD(relkind);
T
Tom Lane 已提交
1835 1836 1837 1838 1839 1840 1841 1842 1843 1844

	return newnode;
}

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

	COPY_SCALAR_FIELD(subtype);
1845
	COPY_STRING_FIELD(name);
1846
	COPY_NODE_FIELD(def);
T
Tom Lane 已提交
1847
	COPY_NODE_FIELD(transform);
1848
	COPY_SCALAR_FIELD(behavior);
1849 1850 1851 1852

	return newnode;
}

B
Bruce Momjian 已提交
1853
static AlterDomainStmt *
1854
_copyAlterDomainStmt(AlterDomainStmt *from)
B
Bruce Momjian 已提交
1855 1856 1857 1858 1859 1860 1861 1862 1863 1864
{
	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 已提交
1865
}
B
Bruce Momjian 已提交
1866

1867 1868
static GrantStmt *
_copyGrantStmt(GrantStmt *from)
1869
{
1870
	GrantStmt  *newnode = makeNode(GrantStmt);
B
Bruce Momjian 已提交
1871

1872 1873 1874
	COPY_SCALAR_FIELD(is_grant);
	COPY_SCALAR_FIELD(objtype);
	COPY_NODE_FIELD(objects);
1875
	COPY_NODE_FIELD(privileges);
1876
	COPY_NODE_FIELD(grantees);
1877 1878
	COPY_SCALAR_FIELD(grant_option);
	COPY_SCALAR_FIELD(behavior);
1879 1880 1881 1882 1883 1884 1885 1886 1887

	return newnode;
}

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

1888
	COPY_STRING_FIELD(rolname);
1889 1890 1891 1892

	return newnode;
}

1893 1894 1895 1896 1897
static FuncWithArgs *
_copyFuncWithArgs(FuncWithArgs *from)
{
	FuncWithArgs *newnode = makeNode(FuncWithArgs);

1898 1899
	COPY_NODE_FIELD(funcname);
	COPY_NODE_FIELD(funcargs);
1900 1901 1902 1903

	return newnode;
}

1904 1905 1906
static GrantRoleStmt *
_copyGrantRoleStmt(GrantRoleStmt *from)
{
B
Bruce Momjian 已提交
1907
	GrantRoleStmt *newnode = makeNode(GrantRoleStmt);
1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918

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

1919
static DeclareCursorStmt *
1920
_copyDeclareCursorStmt(DeclareCursorStmt *from)
1921 1922 1923 1924 1925 1926 1927 1928 1929
{
	DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);

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

	return newnode;
}
B
Bruce Momjian 已提交
1930

1931 1932 1933
static ClosePortalStmt *
_copyClosePortalStmt(ClosePortalStmt *from)
{
1934
	ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1935

1936
	COPY_STRING_FIELD(portalname);
1937 1938 1939 1940

	return newnode;
}

1941 1942 1943 1944
static ClusterStmt *
_copyClusterStmt(ClusterStmt *from)
{
	ClusterStmt *newnode = makeNode(ClusterStmt);
B
Bruce Momjian 已提交
1945

1946 1947
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(indexname);
1948 1949 1950 1951 1952 1953 1954

	return newnode;
}

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

1957
	COPY_NODE_FIELD(relation);
1958
	COPY_NODE_FIELD(query);
1959 1960 1961 1962
	COPY_NODE_FIELD(attlist);
	COPY_SCALAR_FIELD(is_from);
	COPY_STRING_FIELD(filename);
	COPY_NODE_FIELD(options);
1963 1964 1965 1966 1967 1968 1969 1970

	return newnode;
}

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

1972 1973 1974 1975
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(tableElts);
	COPY_NODE_FIELD(inhRelations);
	COPY_NODE_FIELD(constraints);
B
Bruce Momjian 已提交
1976
	COPY_NODE_FIELD(options);
1977
	COPY_SCALAR_FIELD(oncommit);
1978
	COPY_STRING_FIELD(tablespacename);
1979 1980 1981 1982

	return newnode;
}

B
Bruce Momjian 已提交
1983
static InhRelation *
1984
_copyInhRelation(InhRelation *from)
B
Bruce Momjian 已提交
1985 1986 1987 1988
{
	InhRelation *newnode = makeNode(InhRelation);

	COPY_NODE_FIELD(relation);
1989
	COPY_NODE_FIELD(options);
B
Bruce Momjian 已提交
1990 1991 1992 1993

	return newnode;
}

1994 1995 1996 1997
static DefineStmt *
_copyDefineStmt(DefineStmt *from)
{
	DefineStmt *newnode = makeNode(DefineStmt);
B
Bruce Momjian 已提交
1998

1999
	COPY_SCALAR_FIELD(kind);
T
Tom Lane 已提交
2000
	COPY_SCALAR_FIELD(oldstyle);
2001
	COPY_NODE_FIELD(defnames);
T
Tom Lane 已提交
2002
	COPY_NODE_FIELD(args);
2003
	COPY_NODE_FIELD(definition);
2004 2005 2006 2007 2008 2009 2010

	return newnode;
}

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

2013 2014 2015
	COPY_NODE_FIELD(objects);
	COPY_SCALAR_FIELD(removeType);
	COPY_SCALAR_FIELD(behavior);
T
Tom Lane 已提交
2016
	COPY_SCALAR_FIELD(missing_ok);
2017 2018 2019 2020

	return newnode;
}

2021 2022 2023
static TruncateStmt *
_copyTruncateStmt(TruncateStmt *from)
{
2024
	TruncateStmt *newnode = makeNode(TruncateStmt);
2025

2026
	COPY_NODE_FIELD(relations);
2027
	COPY_SCALAR_FIELD(behavior);
2028 2029 2030 2031

	return newnode;
}

2032 2033 2034 2035
static CommentStmt *
_copyCommentStmt(CommentStmt *from)
{
	CommentStmt *newnode = makeNode(CommentStmt);
B
Bruce Momjian 已提交
2036

2037 2038 2039 2040
	COPY_SCALAR_FIELD(objtype);
	COPY_NODE_FIELD(objname);
	COPY_NODE_FIELD(objargs);
	COPY_STRING_FIELD(comment);
2041 2042 2043 2044 2045 2046 2047

	return newnode;
}

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

2050 2051 2052 2053
	COPY_SCALAR_FIELD(direction);
	COPY_SCALAR_FIELD(howMany);
	COPY_STRING_FIELD(portalname);
	COPY_SCALAR_FIELD(ismove);
2054 2055 2056 2057 2058 2059 2060

	return newnode;
}

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

2063 2064 2065
	COPY_STRING_FIELD(idxname);
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(accessMethod);
2066
	COPY_STRING_FIELD(tableSpace);
2067
	COPY_NODE_FIELD(indexParams);
B
Bruce Momjian 已提交
2068
	COPY_NODE_FIELD(options);
2069 2070 2071 2072 2073
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(rangetable);
	COPY_SCALAR_FIELD(unique);
	COPY_SCALAR_FIELD(primary);
	COPY_SCALAR_FIELD(isconstraint);
2074
	COPY_SCALAR_FIELD(concurrent);
2075 2076 2077 2078

	return newnode;
}

2079 2080
static CreateFunctionStmt *
_copyCreateFunctionStmt(CreateFunctionStmt *from)
2081
{
2082
	CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
B
Bruce Momjian 已提交
2083

2084 2085
	COPY_SCALAR_FIELD(replace);
	COPY_NODE_FIELD(funcname);
2086
	COPY_NODE_FIELD(parameters);
2087 2088 2089
	COPY_NODE_FIELD(returnType);
	COPY_NODE_FIELD(options);
	COPY_NODE_FIELD(withClause);
2090 2091 2092 2093

	return newnode;
}

2094 2095 2096 2097 2098 2099 2100
static FunctionParameter *
_copyFunctionParameter(FunctionParameter *from)
{
	FunctionParameter *newnode = makeNode(FunctionParameter);

	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(argType);
2101
	COPY_SCALAR_FIELD(mode);
2102 2103 2104 2105

	return newnode;
}

2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116
static AlterFunctionStmt *
_copyAlterFunctionStmt(AlterFunctionStmt *from)
{
	AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);

	COPY_NODE_FIELD(func);
	COPY_NODE_FIELD(actions);

	return newnode;
}

2117 2118 2119 2120
static RemoveFuncStmt *
_copyRemoveFuncStmt(RemoveFuncStmt *from)
{
	RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
B
Bruce Momjian 已提交
2121

T
Tom Lane 已提交
2122 2123
	COPY_SCALAR_FIELD(kind);
	COPY_NODE_FIELD(name);
2124 2125
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(behavior);
A
 
Andrew Dunstan 已提交
2126
	COPY_SCALAR_FIELD(missing_ok);
2127 2128 2129 2130

	return newnode;
}

2131 2132 2133 2134 2135
static RemoveOpClassStmt *
_copyRemoveOpClassStmt(RemoveOpClassStmt *from)
{
	RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);

2136 2137 2138
	COPY_NODE_FIELD(opclassname);
	COPY_STRING_FIELD(amname);
	COPY_SCALAR_FIELD(behavior);
A
 
Andrew Dunstan 已提交
2139
	COPY_SCALAR_FIELD(missing_ok);
2140 2141 2142 2143

	return newnode;
}

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

2149
	COPY_SCALAR_FIELD(renameType);
2150
	COPY_NODE_FIELD(relation);
2151 2152 2153
	COPY_NODE_FIELD(object);
	COPY_NODE_FIELD(objarg);
	COPY_STRING_FIELD(subname);
2154
	COPY_STRING_FIELD(newname);
2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169

	return newnode;
}

static AlterObjectSchemaStmt *
_copyAlterObjectSchemaStmt(AlterObjectSchemaStmt *from)
{
	AlterObjectSchemaStmt *newnode = makeNode(AlterObjectSchemaStmt);

	COPY_SCALAR_FIELD(objectType);
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(object);
	COPY_NODE_FIELD(objarg);
	COPY_STRING_FIELD(addname);
	COPY_STRING_FIELD(newschema);
2170 2171 2172 2173

	return newnode;
}

2174 2175 2176 2177 2178
static AlterOwnerStmt *
_copyAlterOwnerStmt(AlterOwnerStmt *from)
{
	AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);

2179
	COPY_SCALAR_FIELD(objectType);
2180 2181 2182 2183 2184 2185 2186 2187 2188
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(object);
	COPY_NODE_FIELD(objarg);
	COPY_STRING_FIELD(addname);
	COPY_STRING_FIELD(newowner);

	return newnode;
}

2189 2190 2191
static RuleStmt *
_copyRuleStmt(RuleStmt *from)
{
B
Bruce Momjian 已提交
2192 2193
	RuleStmt   *newnode = makeNode(RuleStmt);

2194 2195 2196 2197 2198 2199 2200
	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);
2201 2202 2203 2204

	return newnode;
}

2205 2206 2207
static NotifyStmt *
_copyNotifyStmt(NotifyStmt *from)
{
2208
	NotifyStmt *newnode = makeNode(NotifyStmt);
2209

2210
	COPY_NODE_FIELD(relation);
2211 2212 2213 2214 2215 2216 2217

	return newnode;
}

static ListenStmt *
_copyListenStmt(ListenStmt *from)
{
2218
	ListenStmt *newnode = makeNode(ListenStmt);
2219

2220
	COPY_NODE_FIELD(relation);
2221 2222 2223 2224 2225 2226 2227

	return newnode;
}

static UnlistenStmt *
_copyUnlistenStmt(UnlistenStmt *from)
{
2228
	UnlistenStmt *newnode = makeNode(UnlistenStmt);
2229

2230
	COPY_NODE_FIELD(relation);
2231 2232 2233 2234 2235 2236 2237

	return newnode;
}

static TransactionStmt *
_copyTransactionStmt(TransactionStmt *from)
{
2238
	TransactionStmt *newnode = makeNode(TransactionStmt);
2239

2240
	COPY_SCALAR_FIELD(kind);
2241
	COPY_NODE_FIELD(options);
2242
	COPY_STRING_FIELD(gid);
2243 2244 2245 2246

	return newnode;
}

B
Bruce Momjian 已提交
2247 2248 2249
static CompositeTypeStmt *
_copyCompositeTypeStmt(CompositeTypeStmt *from)
{
B
Bruce Momjian 已提交
2250
	CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
B
Bruce Momjian 已提交
2251

2252 2253
	COPY_NODE_FIELD(typevar);
	COPY_NODE_FIELD(coldeflist);
B
Bruce Momjian 已提交
2254 2255 2256 2257

	return newnode;
}

2258 2259 2260 2261 2262
static ViewStmt *
_copyViewStmt(ViewStmt *from)
{
	ViewStmt   *newnode = makeNode(ViewStmt);

2263 2264 2265 2266
	COPY_NODE_FIELD(view);
	COPY_NODE_FIELD(aliases);
	COPY_NODE_FIELD(query);
	COPY_SCALAR_FIELD(replace);
2267 2268 2269 2270

	return newnode;
}

2271 2272 2273
static LoadStmt *
_copyLoadStmt(LoadStmt *from)
{
2274
	LoadStmt   *newnode = makeNode(LoadStmt);
2275

2276
	COPY_STRING_FIELD(filename);
2277 2278 2279 2280

	return newnode;
}

2281 2282 2283 2284 2285
static CreateDomainStmt *
_copyCreateDomainStmt(CreateDomainStmt *from)
{
	CreateDomainStmt *newnode = makeNode(CreateDomainStmt);

2286 2287 2288
	COPY_NODE_FIELD(domainname);
	COPY_NODE_FIELD(typename);
	COPY_NODE_FIELD(constraints);
2289 2290 2291 2292

	return newnode;
}

2293 2294 2295 2296 2297
static CreateOpClassStmt *
_copyCreateOpClassStmt(CreateOpClassStmt *from)
{
	CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);

2298
	COPY_NODE_FIELD(opclassname);
2299
	COPY_NODE_FIELD(opfamilyname);
2300 2301 2302 2303
	COPY_STRING_FIELD(amname);
	COPY_NODE_FIELD(datatype);
	COPY_NODE_FIELD(items);
	COPY_SCALAR_FIELD(isDefault);
2304 2305 2306 2307 2308 2309 2310 2311 2312

	return newnode;
}

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

2313 2314 2315 2316 2317 2318
	COPY_SCALAR_FIELD(itemtype);
	COPY_NODE_FIELD(name);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(number);
	COPY_SCALAR_FIELD(recheck);
	COPY_NODE_FIELD(storedtype);
2319 2320 2321 2322

	return newnode;
}

2323 2324 2325
static CreatedbStmt *
_copyCreatedbStmt(CreatedbStmt *from)
{
B
Bruce Momjian 已提交
2326
	CreatedbStmt *newnode = makeNode(CreatedbStmt);
2327

2328 2329
	COPY_STRING_FIELD(dbname);
	COPY_NODE_FIELD(options);
2330 2331 2332 2333

	return newnode;
}

2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344
static AlterDatabaseStmt *
_copyAlterDatabaseStmt(AlterDatabaseStmt *from)
{
	AlterDatabaseStmt *newnode = makeNode(AlterDatabaseStmt);

	COPY_STRING_FIELD(dbname);
	COPY_NODE_FIELD(options);

	return newnode;
}

2345 2346 2347 2348 2349
static AlterDatabaseSetStmt *
_copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
{
	AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);

2350 2351 2352
	COPY_STRING_FIELD(dbname);
	COPY_STRING_FIELD(variable);
	COPY_NODE_FIELD(value);
2353 2354 2355 2356

	return newnode;
}

2357 2358 2359
static DropdbStmt *
_copyDropdbStmt(DropdbStmt *from)
{
B
Bruce Momjian 已提交
2360
	DropdbStmt *newnode = makeNode(DropdbStmt);
2361

2362
	COPY_STRING_FIELD(dbname);
A
 
Andrew Dunstan 已提交
2363
	COPY_SCALAR_FIELD(missing_ok);
2364 2365 2366 2367 2368 2369 2370

	return newnode;
}

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

2373 2374 2375 2376
	COPY_SCALAR_FIELD(vacuum);
	COPY_SCALAR_FIELD(full);
	COPY_SCALAR_FIELD(analyze);
	COPY_SCALAR_FIELD(verbose);
2377
	COPY_SCALAR_FIELD(freeze_min_age);
2378 2379
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(va_cols);
2380 2381 2382 2383 2384 2385 2386

	return newnode;
}

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

2389 2390 2391
	COPY_NODE_FIELD(query);
	COPY_SCALAR_FIELD(verbose);
	COPY_SCALAR_FIELD(analyze);
2392 2393 2394 2395 2396 2397 2398

	return newnode;
}

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

2401 2402
	COPY_NODE_FIELD(sequence);
	COPY_NODE_FIELD(options);
2403 2404 2405 2406

	return newnode;
}

B
Bruce Momjian 已提交
2407
static AlterSeqStmt *
2408
_copyAlterSeqStmt(AlterSeqStmt *from)
B
Bruce Momjian 已提交
2409 2410 2411 2412 2413 2414 2415 2416 2417
{
	AlterSeqStmt *newnode = makeNode(AlterSeqStmt);

	COPY_NODE_FIELD(sequence);
	COPY_NODE_FIELD(options);

	return newnode;
}

2418 2419 2420
static VariableSetStmt *
_copyVariableSetStmt(VariableSetStmt *from)
{
2421
	VariableSetStmt *newnode = makeNode(VariableSetStmt);
2422

2423 2424 2425
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(is_local);
2426 2427 2428 2429

	return newnode;
}

2430 2431 2432 2433 2434
static VariableShowStmt *
_copyVariableShowStmt(VariableShowStmt *from)
{
	VariableShowStmt *newnode = makeNode(VariableShowStmt);

2435
	COPY_STRING_FIELD(name);
2436 2437 2438 2439

	return newnode;
}

2440 2441 2442
static VariableResetStmt *
_copyVariableResetStmt(VariableResetStmt *from)
{
2443
	VariableResetStmt *newnode = makeNode(VariableResetStmt);
2444

2445
	COPY_STRING_FIELD(name);
2446 2447 2448 2449

	return newnode;
}

2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467
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);
A
 
Andrew Dunstan 已提交
2468
	COPY_SCALAR_FIELD(missing_ok);
2469 2470 2471 2472

	return newnode;
}

2473 2474 2475 2476 2477
static CreateTrigStmt *
_copyCreateTrigStmt(CreateTrigStmt *from)
{
	CreateTrigStmt *newnode = makeNode(CreateTrigStmt);

2478 2479 2480 2481 2482 2483
	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 已提交
2484
	strcpy(newnode->actions, from->actions);	/* in-line string field */
2485 2486 2487 2488
	COPY_SCALAR_FIELD(isconstraint);
	COPY_SCALAR_FIELD(deferrable);
	COPY_SCALAR_FIELD(initdeferred);
	COPY_NODE_FIELD(constrrel);
2489 2490 2491 2492

	return newnode;
}

2493 2494
static DropPropertyStmt *
_copyDropPropertyStmt(DropPropertyStmt *from)
2495
{
2496
	DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2497

2498 2499 2500 2501
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(property);
	COPY_SCALAR_FIELD(removeType);
	COPY_SCALAR_FIELD(behavior);
A
 
Andrew Dunstan 已提交
2502
	COPY_SCALAR_FIELD(missing_ok);
2503 2504 2505 2506 2507 2508 2509 2510 2511

	return newnode;
}

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

2512 2513 2514 2515
	COPY_STRING_FIELD(plname);
	COPY_NODE_FIELD(plhandler);
	COPY_NODE_FIELD(plvalidator);
	COPY_SCALAR_FIELD(pltrusted);
2516 2517 2518 2519 2520 2521 2522 2523 2524

	return newnode;
}

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

2525 2526
	COPY_STRING_FIELD(plname);
	COPY_SCALAR_FIELD(behavior);
A
 
Andrew Dunstan 已提交
2527
	COPY_SCALAR_FIELD(missing_ok);
2528 2529 2530 2531

	return newnode;
}

2532 2533
static CreateRoleStmt *
_copyCreateRoleStmt(CreateRoleStmt *from)
2534
{
2535
	CreateRoleStmt *newnode = makeNode(CreateRoleStmt);
2536

2537
	COPY_SCALAR_FIELD(stmt_type);
2538
	COPY_STRING_FIELD(role);
2539
	COPY_NODE_FIELD(options);
2540 2541 2542 2543

	return newnode;
}

2544 2545
static AlterRoleStmt *
_copyAlterRoleStmt(AlterRoleStmt *from)
2546
{
2547
	AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
2548

2549
	COPY_STRING_FIELD(role);
2550
	COPY_NODE_FIELD(options);
2551
	COPY_SCALAR_FIELD(action);
2552 2553 2554 2555

	return newnode;
}

2556 2557
static AlterRoleSetStmt *
_copyAlterRoleSetStmt(AlterRoleSetStmt *from)
2558
{
2559
	AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
2560

2561
	COPY_STRING_FIELD(role);
2562 2563
	COPY_STRING_FIELD(variable);
	COPY_NODE_FIELD(value);
2564 2565 2566 2567

	return newnode;
}

2568 2569
static DropRoleStmt *
_copyDropRoleStmt(DropRoleStmt *from)
2570
{
2571
	DropRoleStmt *newnode = makeNode(DropRoleStmt);
2572

2573
	COPY_NODE_FIELD(roles);
A
 
Andrew Dunstan 已提交
2574
	COPY_SCALAR_FIELD(missing_ok);
2575 2576 2577 2578

	return newnode;
}

2579 2580 2581
static LockStmt *
_copyLockStmt(LockStmt *from)
{
2582
	LockStmt   *newnode = makeNode(LockStmt);
2583

2584 2585
	COPY_NODE_FIELD(relations);
	COPY_SCALAR_FIELD(mode);
T
Tatsuo Ishii 已提交
2586
	COPY_SCALAR_FIELD(nowait);
2587 2588 2589

	return newnode;
}
2590

2591 2592 2593
static ConstraintsSetStmt *
_copyConstraintsSetStmt(ConstraintsSetStmt *from)
{
B
Bruce Momjian 已提交
2594
	ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2595

2596 2597
	COPY_NODE_FIELD(constraints);
	COPY_SCALAR_FIELD(deferred);
2598 2599 2600 2601 2602 2603 2604

	return newnode;
}

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

2607
	COPY_SCALAR_FIELD(kind);
2608 2609
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(name);
2610 2611
	COPY_SCALAR_FIELD(do_system);
	COPY_SCALAR_FIELD(do_user);
2612 2613 2614 2615

	return newnode;
}

2616 2617 2618 2619 2620
static CreateSchemaStmt *
_copyCreateSchemaStmt(CreateSchemaStmt *from)
{
	CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);

2621 2622 2623
	COPY_STRING_FIELD(schemaname);
	COPY_STRING_FIELD(authid);
	COPY_NODE_FIELD(schemaElts);
2624 2625 2626 2627

	return newnode;
}

2628 2629 2630 2631 2632
static CreateConversionStmt *
_copyCreateConversionStmt(CreateConversionStmt *from)
{
	CreateConversionStmt *newnode = makeNode(CreateConversionStmt);

2633 2634 2635 2636 2637
	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);
2638 2639 2640 2641 2642 2643 2644 2645 2646

	return newnode;
}

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

2647 2648 2649 2650
	COPY_NODE_FIELD(sourcetype);
	COPY_NODE_FIELD(targettype);
	COPY_NODE_FIELD(func);
	COPY_SCALAR_FIELD(context);
2651 2652 2653 2654 2655 2656 2657 2658 2659

	return newnode;
}

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

2660 2661 2662
	COPY_NODE_FIELD(sourcetype);
	COPY_NODE_FIELD(targettype);
	COPY_SCALAR_FIELD(behavior);
A
 
Andrew Dunstan 已提交
2663
	COPY_SCALAR_FIELD(missing_ok);
2664 2665 2666 2667

	return newnode;
}

2668 2669 2670 2671 2672
static PrepareStmt *
_copyPrepareStmt(PrepareStmt *from)
{
	PrepareStmt *newnode = makeNode(PrepareStmt);

2673 2674
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(argtypes);
2675
	COPY_NODE_FIELD(argtype_oids);
2676
	COPY_NODE_FIELD(query);
2677 2678 2679 2680 2681 2682 2683 2684 2685

	return newnode;
}

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

2686 2687
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(into);
B
Bruce Momjian 已提交
2688
	COPY_NODE_FIELD(intoOptions);
2689 2690
	COPY_SCALAR_FIELD(into_on_commit);
	COPY_STRING_FIELD(into_tbl_space);
2691
	COPY_NODE_FIELD(params);
2692 2693 2694 2695 2696 2697 2698 2699 2700

	return newnode;
}

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

2701
	COPY_STRING_FIELD(name);
2702 2703 2704 2705

	return newnode;
}

2706
static DropOwnedStmt *
B
Bruce Momjian 已提交
2707
_copyDropOwnedStmt(DropOwnedStmt *from)
2708 2709 2710 2711 2712
{
	DropOwnedStmt *newnode = makeNode(DropOwnedStmt);

	COPY_NODE_FIELD(roles);
	COPY_SCALAR_FIELD(behavior);
2713

2714 2715 2716 2717
	return newnode;
}

static ReassignOwnedStmt *
B
Bruce Momjian 已提交
2718
_copyReassignOwnedStmt(ReassignOwnedStmt *from)
2719 2720 2721 2722 2723 2724 2725 2726
{
	ReassignOwnedStmt *newnode = makeNode(ReassignOwnedStmt);

	COPY_NODE_FIELD(roles);
	COPY_SCALAR_FIELD(newrole);

	return newnode;
}
2727 2728

/* ****************************************************************
2729
 *					pg_list.h copy functions
2730 2731 2732
 * ****************************************************************
 */

2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744
/*
 * 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 已提交
2745 2746 2747
	List	   *new;
	ListCell   *curr_old;
	ListCell   *prev_new;
2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773

	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
 * ****************************************************************
 */
2774
static Value *
2775
_copyValue(Value *from)
2776
{
2777
	Value	   *newnode = makeNode(Value);
2778

2779 2780
	/* See also _copyAConst when changing this code! */

2781
	COPY_SCALAR_FIELD(type);
2782 2783
	switch (from->type)
	{
2784
		case T_Integer:
2785
			COPY_SCALAR_FIELD(val.ival);
2786 2787
			break;
		case T_Float:
2788
		case T_String:
2789
		case T_BitString:
2790
			COPY_STRING_FIELD(val.str);
2791
			break;
2792 2793 2794
		case T_Null:
			/* nothing to do */
			break;
2795
		default:
2796 2797
			elog(ERROR, "unrecognized node type: %d",
				 (int) from->type);
2798
			break;
2799 2800
	}
	return newnode;
2801 2802
}

2803 2804 2805 2806 2807
/*
 * copyObject
 *
 * Create a copy of a Node tree or list.  This is a "deep" copy: all
 * substructure is copied too, recursively.
2808
 */
2809
void *
2810 2811
copyObject(void *from)
{
2812
	void	   *retval;
2813

2814 2815
	if (from == NULL)
		return NULL;
2816

2817
	switch (nodeTag(from))
2818
	{
2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830
			/*
			 * PLAN NODES
			 */
		case T_Plan:
			retval = _copyPlan(from);
			break;
		case T_Result:
			retval = _copyResult(from);
			break;
		case T_Append:
			retval = _copyAppend(from);
			break;
2831 2832 2833 2834 2835 2836
		case T_BitmapAnd:
			retval = _copyBitmapAnd(from);
			break;
		case T_BitmapOr:
			retval = _copyBitmapOr(from);
			break;
2837 2838 2839 2840 2841 2842 2843 2844 2845
		case T_Scan:
			retval = _copyScan(from);
			break;
		case T_SeqScan:
			retval = _copySeqScan(from);
			break;
		case T_IndexScan:
			retval = _copyIndexScan(from);
			break;
2846 2847 2848 2849 2850 2851
		case T_BitmapIndexScan:
			retval = _copyBitmapIndexScan(from);
			break;
		case T_BitmapHeapScan:
			retval = _copyBitmapHeapScan(from);
			break;
2852 2853 2854
		case T_TidScan:
			retval = _copyTidScan(from);
			break;
2855 2856 2857
		case T_SubqueryScan:
			retval = _copySubqueryScan(from);
			break;
2858 2859 2860
		case T_FunctionScan:
			retval = _copyFunctionScan(from);
			break;
2861 2862 2863
		case T_ValuesScan:
			retval = _copyValuesScan(from);
			break;
2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881
		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 已提交
2882 2883 2884
		case T_Group:
			retval = _copyGroup(from);
			break;
2885 2886 2887 2888 2889 2890
		case T_Agg:
			retval = _copyAgg(from);
			break;
		case T_Unique:
			retval = _copyUnique(from);
			break;
2891 2892 2893
		case T_Hash:
			retval = _copyHash(from);
			break;
2894 2895 2896
		case T_SetOp:
			retval = _copySetOp(from);
			break;
2897 2898 2899
		case T_Limit:
			retval = _copyLimit(from);
			break;
2900 2901 2902 2903

			/*
			 * PRIMITIVE NODES
			 */
2904 2905 2906 2907 2908 2909
		case T_Alias:
			retval = _copyAlias(from);
			break;
		case T_RangeVar:
			retval = _copyRangeVar(from);
			break;
2910 2911 2912 2913 2914 2915 2916 2917 2918
		case T_Var:
			retval = _copyVar(from);
			break;
		case T_Const:
			retval = _copyConst(from);
			break;
		case T_Param:
			retval = _copyParam(from);
			break;
2919 2920 2921
		case T_Aggref:
			retval = _copyAggref(from);
			break;
2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933
		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;
2934 2935 2936
		case T_ScalarArrayOpExpr:
			retval = _copyScalarArrayOpExpr(from);
			break;
2937 2938 2939
		case T_BoolExpr:
			retval = _copyBoolExpr(from);
			break;
2940 2941 2942
		case T_SubLink:
			retval = _copySubLink(from);
			break;
2943 2944
		case T_SubPlan:
			retval = _copySubPlan(from);
2945
			break;
2946 2947 2948
		case T_FieldSelect:
			retval = _copyFieldSelect(from);
			break;
2949 2950 2951
		case T_FieldStore:
			retval = _copyFieldStore(from);
			break;
2952 2953 2954
		case T_RelabelType:
			retval = _copyRelabelType(from);
			break;
2955 2956 2957
		case T_ConvertRowtypeExpr:
			retval = _copyConvertRowtypeExpr(from);
			break;
2958 2959 2960 2961 2962 2963
		case T_CaseExpr:
			retval = _copyCaseExpr(from);
			break;
		case T_CaseWhen:
			retval = _copyCaseWhen(from);
			break;
2964 2965 2966
		case T_CaseTestExpr:
			retval = _copyCaseTestExpr(from);
			break;
2967 2968 2969
		case T_ArrayExpr:
			retval = _copyArrayExpr(from);
			break;
2970 2971 2972
		case T_RowExpr:
			retval = _copyRowExpr(from);
			break;
2973 2974 2975
		case T_RowCompareExpr:
			retval = _copyRowCompareExpr(from);
			break;
2976 2977 2978
		case T_CoalesceExpr:
			retval = _copyCoalesceExpr(from);
			break;
2979 2980 2981
		case T_MinMaxExpr:
			retval = _copyMinMaxExpr(from);
			break;
2982 2983 2984
		case T_XmlExpr:
			retval = _copyXmlExpr(from);
			break;
2985 2986 2987
		case T_NullIfExpr:
			retval = _copyNullIfExpr(from);
			break;
2988 2989 2990 2991 2992 2993
		case T_NullTest:
			retval = _copyNullTest(from);
			break;
		case T_BooleanTest:
			retval = _copyBooleanTest(from);
			break;
2994 2995
		case T_CoerceToDomain:
			retval = _copyCoerceToDomain(from);
2996
			break;
2997 2998
		case T_CoerceToDomainValue:
			retval = _copyCoerceToDomainValue(from);
2999
			break;
3000 3001 3002
		case T_SetToDefault:
			retval = _copySetToDefault(from);
			break;
3003 3004 3005
		case T_TargetEntry:
			retval = _copyTargetEntry(from);
			break;
3006 3007 3008
		case T_RangeTblRef:
			retval = _copyRangeTblRef(from);
			break;
3009 3010 3011
		case T_JoinExpr:
			retval = _copyJoinExpr(from);
			break;
3012 3013 3014
		case T_FromExpr:
			retval = _copyFromExpr(from);
			break;
3015 3016 3017 3018

			/*
			 * RELATION NODES
			 */
3019 3020
		case T_PathKeyItem:
			retval = _copyPathKeyItem(from);
3021
			break;
3022 3023
		case T_RestrictInfo:
			retval = _copyRestrictInfo(from);
3024
			break;
3025 3026 3027
		case T_OuterJoinInfo:
			retval = _copyOuterJoinInfo(from);
			break;
3028 3029 3030
		case T_InClauseInfo:
			retval = _copyInClauseInfo(from);
			break;
3031 3032 3033
		case T_AppendRelInfo:
			retval = _copyAppendRelInfo(from);
			break;
3034 3035

			/*
3036
			 * VALUE NODES
3037
			 */
3038 3039 3040
		case T_Integer:
		case T_Float:
		case T_String:
3041
		case T_BitString:
3042
		case T_Null:
3043
			retval = _copyValue(from);
3044
			break;
3045 3046 3047 3048

			/*
			 * LIST NODES
			 */
3049
		case T_List:
3050 3051
			retval = _copyList(from);
			break;
B
Bruce Momjian 已提交
3052

3053
			/*
B
Bruce Momjian 已提交
3054 3055
			 * Lists of integers and OIDs don't need to be deep-copied, so we
			 * perform a shallow copy via list_copy()
3056 3057 3058 3059
			 */
		case T_IntList:
		case T_OidList:
			retval = list_copy(from);
3060
			break;
3061 3062 3063 3064

			/*
			 * PARSE NODES
			 */
3065 3066 3067
		case T_Query:
			retval = _copyQuery(from);
			break;
3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079
		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;
3080 3081 3082
		case T_SetOperationStmt:
			retval = _copySetOperationStmt(from);
			break;
3083 3084 3085
		case T_AlterTableStmt:
			retval = _copyAlterTableStmt(from);
			break;
T
Tom Lane 已提交
3086 3087 3088
		case T_AlterTableCmd:
			retval = _copyAlterTableCmd(from);
			break;
B
Bruce Momjian 已提交
3089 3090 3091
		case T_AlterDomainStmt:
			retval = _copyAlterDomainStmt(from);
			break;
3092 3093
		case T_GrantStmt:
			retval = _copyGrantStmt(from);
3094
			break;
3095 3096 3097
		case T_GrantRoleStmt:
			retval = _copyGrantRoleStmt(from);
			break;
3098 3099 3100
		case T_DeclareCursorStmt:
			retval = _copyDeclareCursorStmt(from);
			break;
3101 3102 3103
		case T_ClosePortalStmt:
			retval = _copyClosePortalStmt(from);
			break;
3104 3105 3106 3107 3108 3109 3110 3111 3112
		case T_ClusterStmt:
			retval = _copyClusterStmt(from);
			break;
		case T_CopyStmt:
			retval = _copyCopyStmt(from);
			break;
		case T_CreateStmt:
			retval = _copyCreateStmt(from);
			break;
B
Bruce Momjian 已提交
3113 3114 3115
		case T_InhRelation:
			retval = _copyInhRelation(from);
			break;
3116 3117 3118 3119 3120 3121
		case T_DefineStmt:
			retval = _copyDefineStmt(from);
			break;
		case T_DropStmt:
			retval = _copyDropStmt(from);
			break;
3122 3123 3124
		case T_TruncateStmt:
			retval = _copyTruncateStmt(from);
			break;
3125 3126 3127 3128 3129 3130 3131 3132 3133
		case T_CommentStmt:
			retval = _copyCommentStmt(from);
			break;
		case T_FetchStmt:
			retval = _copyFetchStmt(from);
			break;
		case T_IndexStmt:
			retval = _copyIndexStmt(from);
			break;
3134 3135
		case T_CreateFunctionStmt:
			retval = _copyCreateFunctionStmt(from);
3136
			break;
3137 3138 3139
		case T_FunctionParameter:
			retval = _copyFunctionParameter(from);
			break;
3140 3141 3142
		case T_AlterFunctionStmt:
			retval = _copyAlterFunctionStmt(from);
			break;
3143 3144 3145
		case T_RemoveFuncStmt:
			retval = _copyRemoveFuncStmt(from);
			break;
3146 3147 3148
		case T_RemoveOpClassStmt:
			retval = _copyRemoveOpClassStmt(from);
			break;
3149 3150 3151
		case T_RenameStmt:
			retval = _copyRenameStmt(from);
			break;
3152 3153 3154
		case T_AlterObjectSchemaStmt:
			retval = _copyAlterObjectSchemaStmt(from);
			break;
3155 3156 3157
		case T_AlterOwnerStmt:
			retval = _copyAlterOwnerStmt(from);
			break;
3158 3159 3160
		case T_RuleStmt:
			retval = _copyRuleStmt(from);
			break;
3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172
		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 已提交
3173 3174 3175
		case T_CompositeTypeStmt:
			retval = _copyCompositeTypeStmt(from);
			break;
3176 3177 3178
		case T_ViewStmt:
			retval = _copyViewStmt(from);
			break;
3179 3180 3181
		case T_LoadStmt:
			retval = _copyLoadStmt(from);
			break;
3182 3183 3184
		case T_CreateDomainStmt:
			retval = _copyCreateDomainStmt(from);
			break;
3185 3186 3187 3188 3189 3190
		case T_CreateOpClassStmt:
			retval = _copyCreateOpClassStmt(from);
			break;
		case T_CreateOpClassItem:
			retval = _copyCreateOpClassItem(from);
			break;
3191 3192 3193
		case T_CreatedbStmt:
			retval = _copyCreatedbStmt(from);
			break;
3194 3195 3196
		case T_AlterDatabaseStmt:
			retval = _copyAlterDatabaseStmt(from);
			break;
3197 3198 3199
		case T_AlterDatabaseSetStmt:
			retval = _copyAlterDatabaseSetStmt(from);
			break;
3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211
		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 已提交
3212 3213 3214
		case T_AlterSeqStmt:
			retval = _copyAlterSeqStmt(from);
			break;
3215 3216 3217
		case T_VariableSetStmt:
			retval = _copyVariableSetStmt(from);
			break;
3218 3219 3220
		case T_VariableShowStmt:
			retval = _copyVariableShowStmt(from);
			break;
3221 3222 3223
		case T_VariableResetStmt:
			retval = _copyVariableResetStmt(from);
			break;
3224 3225 3226 3227 3228 3229
		case T_CreateTableSpaceStmt:
			retval = _copyCreateTableSpaceStmt(from);
			break;
		case T_DropTableSpaceStmt:
			retval = _copyDropTableSpaceStmt(from);
			break;
3230 3231 3232
		case T_CreateTrigStmt:
			retval = _copyCreateTrigStmt(from);
			break;
3233 3234
		case T_DropPropertyStmt:
			retval = _copyDropPropertyStmt(from);
3235 3236 3237 3238 3239 3240 3241
			break;
		case T_CreatePLangStmt:
			retval = _copyCreatePLangStmt(from);
			break;
		case T_DropPLangStmt:
			retval = _copyDropPLangStmt(from);
			break;
3242 3243
		case T_CreateRoleStmt:
			retval = _copyCreateRoleStmt(from);
3244
			break;
3245 3246
		case T_AlterRoleStmt:
			retval = _copyAlterRoleStmt(from);
3247
			break;
3248 3249
		case T_AlterRoleSetStmt:
			retval = _copyAlterRoleSetStmt(from);
3250
			break;
3251 3252
		case T_DropRoleStmt:
			retval = _copyDropRoleStmt(from);
3253
			break;
3254 3255 3256
		case T_LockStmt:
			retval = _copyLockStmt(from);
			break;
3257 3258 3259 3260 3261 3262
		case T_ConstraintsSetStmt:
			retval = _copyConstraintsSetStmt(from);
			break;
		case T_ReindexStmt:
			retval = _copyReindexStmt(from);
			break;
V
Vadim B. Mikheev 已提交
3263
		case T_CheckPointStmt:
B
Bruce Momjian 已提交
3264
			retval = (void *) makeNode(CheckPointStmt);
V
Vadim B. Mikheev 已提交
3265
			break;
3266 3267 3268
		case T_CreateSchemaStmt:
			retval = _copyCreateSchemaStmt(from);
			break;
3269 3270 3271 3272 3273 3274 3275 3276 3277
		case T_CreateConversionStmt:
			retval = _copyCreateConversionStmt(from);
			break;
		case T_CreateCastStmt:
			retval = _copyCreateCastStmt(from);
			break;
		case T_DropCastStmt:
			retval = _copyDropCastStmt(from);
			break;
3278 3279 3280 3281 3282 3283 3284 3285 3286
		case T_PrepareStmt:
			retval = _copyPrepareStmt(from);
			break;
		case T_ExecuteStmt:
			retval = _copyExecuteStmt(from);
			break;
		case T_DeallocateStmt:
			retval = _copyDeallocateStmt(from);
			break;
3287 3288 3289 3290 3291 3292
		case T_DropOwnedStmt:
			retval = _copyDropOwnedStmt(from);
			break;
		case T_ReassignOwnedStmt:
			retval = _copyReassignOwnedStmt(from);
			break;
3293

3294 3295 3296
		case T_A_Expr:
			retval = _copyAExpr(from);
			break;
3297 3298 3299 3300 3301
		case T_ColumnRef:
			retval = _copyColumnRef(from);
			break;
		case T_ParamRef:
			retval = _copyParamRef(from);
3302
			break;
3303 3304 3305
		case T_A_Const:
			retval = _copyAConst(from);
			break;
3306 3307 3308 3309 3310 3311
		case T_FuncCall:
			retval = _copyFuncCall(from);
			break;
		case T_A_Indices:
			retval = _copyAIndices(from);
			break;
3312 3313
		case T_A_Indirection:
			retval = _copyA_Indirection(from);
3314
			break;
3315 3316 3317
		case T_ResTarget:
			retval = _copyResTarget(from);
			break;
3318 3319 3320
		case T_TypeCast:
			retval = _copyTypeCast(from);
			break;
3321 3322
		case T_SortBy:
			retval = _copySortBy(from);
3323
			break;
3324 3325 3326
		case T_RangeSubselect:
			retval = _copyRangeSubselect(from);
			break;
3327 3328 3329
		case T_RangeFunction:
			retval = _copyRangeFunction(from);
			break;
3330 3331 3332
		case T_TypeName:
			retval = _copyTypeName(from);
			break;
3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344
		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;
3345 3346 3347
		case T_LockingClause:
			retval = _copyLockingClause(from);
			break;
3348 3349
		case T_RangeTblEntry:
			retval = _copyRangeTblEntry(from);
3350
			break;
3351 3352 3353 3354 3355 3356
		case T_SortClause:
			retval = _copySortClause(from);
			break;
		case T_GroupClause:
			retval = _copyGroupClause(from);
			break;
3357 3358 3359
		case T_RowMarkClause:
			retval = _copyRowMarkClause(from);
			break;
3360 3361 3362
		case T_FkConstraint:
			retval = _copyFkConstraint(from);
			break;
3363 3364 3365
		case T_PrivGrantee:
			retval = _copyPrivGrantee(from);
			break;
3366 3367 3368
		case T_FuncWithArgs:
			retval = _copyFuncWithArgs(from);
			break;
3369

3370
		default:
3371
			elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
3372
			retval = from;		/* keep compiler quiet */
3373
			break;
3374
	}
3375

3376
	return retval;
3377
}