copyfuncs.c 105.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
 *
 *
14 15
 * Portions Copyright (c) 2005-2010, Greenplum inc
 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
B
Add:  
Bruce Momjian 已提交
16
 * Portions Copyright (c) 1994, Regents of the University of California
17 18
 *
 * IDENTIFICATION
19
 *	  $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.366 2007/02/19 02:23:11 tgl Exp $
20 21 22 23 24 25
 *
 *-------------------------------------------------------------------------
 */

#include "postgres.h"

26 27 28
#include "access/attnum.h"
#include "catalog/caqlparse.h"
#include "catalog/gp_policy.h"
29
#include "nodes/plannodes.h"
30
#include "nodes/execnodes.h" /* CdbProcess, Slice, and SliceTable. */
31
#include "nodes/relation.h"
32
#include "utils/datum.h"
33 34
#include "cdb/cdbgang.h"
#include "nodes/nodeFuncs.h"
35 36

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

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

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

55 56 57 58 59 60 61 62 63 64 65 66
/* 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)

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
#define COPY_BINARY_FIELD(fldname, sz) \
	do { \
		Size _size = (sz); \
		memcpy(&newnode->fldname, &from->fldname, _size); \
	} while (0)

/* Copy a field that is a varlena datum */
#define COPY_VARLENA_FIELD(fldname, len) \
	do { \
		if (from->fldname) \
		{ \
			newnode->fldname = DatumGetPointer( \
					datumCopy(PointerGetDatum(from->fldname), false, len)); \
		} \
	} while (0)

/* Copy a parse location field (for Copy, this is same as scalar case) */
#define COPY_LOCATION_FIELD(fldname) \
	(newnode->fldname = from->fldname)

87 88

/* ****************************************************************
89
 *					 plannodes.h copy functions
90 91 92
 * ****************************************************************
 */

93 94
/*
 * CopyPlanFields
95
 *
96 97
 *		This function copies the fields of the Plan node.  It is used by
 *		all the copy functions for classes which inherit from Plan.
98 99
 */
static void
100
CopyPlanFields(Plan *from, Plan *newnode)
101
{
102 103 104 105

	COPY_SCALAR_FIELD(plan_node_id);
	COPY_SCALAR_FIELD(plan_parent_node_id);

106 107 108 109 110 111 112 113
	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);
114
	COPY_NODE_FIELD(initPlan);
115 116
	COPY_BITMAPSET_FIELD(extParam);
	COPY_BITMAPSET_FIELD(allParam);
117
	COPY_SCALAR_FIELD(nParamExec);
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 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 193
	COPY_NODE_FIELD(flow);
	COPY_SCALAR_FIELD(dispatch);
	COPY_SCALAR_FIELD(nMotionNodes);
	COPY_SCALAR_FIELD(nInitPlans);
	COPY_NODE_FIELD(sliceTable);

	COPY_SCALAR_FIELD(directDispatch.isDirectDispatch);
	COPY_NODE_FIELD(directDispatch.contentIds);
	COPY_SCALAR_FIELD(operatorMemKB);

}

/*
 * CopyLogicalIndexInfo
 *
 *		This function copies the LogicalIndexInfo, which is part of
 *		DynamicIndexScan node.
 */
static void
CopyLogicalIndexInfo(const LogicalIndexInfo *from, LogicalIndexInfo *newnode)
{
	COPY_SCALAR_FIELD(logicalIndexOid);
	COPY_SCALAR_FIELD(nColumns);
	COPY_POINTER_FIELD(indexKeys, from->nColumns * sizeof(AttrNumber));
	COPY_NODE_FIELD(indPred);
	COPY_NODE_FIELD(indExprs);
	COPY_SCALAR_FIELD(indIsUnique);
	COPY_SCALAR_FIELD(indType);
	COPY_NODE_FIELD(partCons);
	COPY_NODE_FIELD(defaultLevels);
}

/*
 * _copyPlannedStmt 
 */
static PlannedStmt *
_copyPlannedStmt(PlannedStmt *from)
{
	PlannedStmt   *newnode = makeNode(PlannedStmt);

	COPY_SCALAR_FIELD(commandType);
	COPY_SCALAR_FIELD(planGen);
	COPY_SCALAR_FIELD(canSetTag);
	COPY_SCALAR_FIELD(transientPlan);

	COPY_NODE_FIELD(planTree);
	COPY_NODE_FIELD(rtable);
	
	COPY_NODE_FIELD(resultRelations);
	COPY_NODE_FIELD(utilityStmt);
	COPY_NODE_FIELD(intoClause);
	COPY_NODE_FIELD(subplans);
	COPY_NODE_FIELD(returningLists);
	
	COPY_NODE_FIELD(result_partitions);
	COPY_NODE_FIELD(result_aosegnos);
	COPY_NODE_FIELD(queryPartOids);
	COPY_NODE_FIELD(queryPartsMetadata);
	COPY_NODE_FIELD(numSelectorsPerScanId);
	COPY_NODE_FIELD(rowMarks);
	COPY_NODE_FIELD(relationOids);
	COPY_SCALAR_FIELD(invalItems);
	COPY_SCALAR_FIELD(nCrossLevelParams);
	COPY_SCALAR_FIELD(nMotionNodes);
	COPY_SCALAR_FIELD(nInitPlans);
	
	if (from->intoPolicy)
	{
		COPY_POINTER_FIELD(intoPolicy,sizeof(GpPolicy) + from->intoPolicy->nattrs*sizeof(from->intoPolicy->attrs[0]));
	}
	else
		newnode->intoPolicy = NULL;

	COPY_SCALAR_FIELD(query_mem);

	return newnode;
194 195
}

196 197 198 199 200 201 202 203 204 205 206 207
static QueryDispatchDesc *
_copyQueryDispatchDesc(QueryDispatchDesc *from)
{
	QueryDispatchDesc *newnode = makeNode(QueryDispatchDesc);

	COPY_NODE_FIELD(intoOidInfo);
	COPY_NODE_FIELD(intoTableSpaceName);
	COPY_NODE_FIELD(sliceTable);

	return newnode;
}

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

216
	/*
217
	 * copy node superclass fields
218 219 220 221
	 */
	CopyPlanFields(from, newnode);

	return newnode;
222 223 224
}


225 226
/*
 * _copyResult
227
 */
228
static Result *
229
_copyResult(Result *from)
230
{
231
	Result	   *newnode = makeNode(Result);
232

233 234
	/*
	 * copy node superclass fields
235 236 237
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

238 239
	/*
	 * copy remainder of node
240
	 */
241
	COPY_NODE_FIELD(resconstantqual);
242

243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
	COPY_SCALAR_FIELD(hashFilter);
	COPY_NODE_FIELD(hashList);

	return newnode;
}

/*
 * _copyRepeat
 */
static Repeat *
_copyRepeat(Repeat *from)
{
	Repeat *newnode = makeNode(Repeat);

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

	/*
	 * copy remainder of node
	 */
	COPY_NODE_FIELD(repeatCountExpr);
	COPY_SCALAR_FIELD(grouping);

268
	return newnode;
269 270
}

271 272
/*
 * _copyAppend
273
 */
274
static Append *
B
Bruce Momjian 已提交
275
_copyAppend(Append *from)
276
{
277
	Append	   *newnode = makeNode(Append);
278

279 280
	/*
	 * copy node superclass fields
281 282 283
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

284 285
	/*
	 * copy remainder of node
286
	 */
287 288
	COPY_NODE_FIELD(appendplans);
	COPY_SCALAR_FIELD(isTarget);
289 290 291 292 293 294 295 296 297 298 299 300
	COPY_SCALAR_FIELD(isZapped);
	COPY_SCALAR_FIELD(hasXslice);

	return newnode;
}

static Sequence *
_copySequence(Sequence *from)
{
	Sequence *newnode = makeNode(Sequence);
	CopyPlanFields((Plan *) from, (Plan *) newnode);
	COPY_NODE_FIELD(subplans);
301 302

	return newnode;
303 304
}

305 306 307 308 309 310
/*
 * _copyBitmapAnd
 */
static BitmapAnd *
_copyBitmapAnd(BitmapAnd *from)
{
B
Bruce Momjian 已提交
311
	BitmapAnd  *newnode = makeNode(BitmapAnd);
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331

	/*
	 * 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 已提交
332
	BitmapOr   *newnode = makeNode(BitmapOr);
333 334 335 336 337 338 339 340 341 342 343 344 345 346

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

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

	return newnode;
}

347

348 349
/*
 * CopyScanFields
350
 *
351 352
 *		This function copies the fields of the Scan node.  It is used by
 *		all the copy functions for classes which inherit from Scan.
353 354
 */
static void
355
CopyScanFields(Scan *from, Scan *newnode)
356
{
357 358 359
	CopyPlanFields((Plan *) from, (Plan *) newnode);

	COPY_SCALAR_FIELD(scanrelid);
360 361
	COPY_SCALAR_FIELD(partIndex);
	COPY_SCALAR_FIELD(partIndexPrintable);
362 363
}

364 365
/*
 * _copyScan
366
 */
367
static Scan *
368
_copyScan(Scan *from)
369
{
370
	Scan	   *newnode = makeNode(Scan);
371

372 373
	/*
	 * copy node superclass fields
374
	 */
B
Bruce Momjian 已提交
375
	CopyScanFields((Scan *) from, (Scan *) newnode);
376 377

	return newnode;
378 379
}

380 381
/*
 * _copySeqScan
382 383
 */
static SeqScan *
384
_copySeqScan(SeqScan *from)
385
{
386
	SeqScan    *newnode = makeNode(SeqScan);
387

388 389
	/*
	 * copy node superclass fields
390 391 392 393
	 */
	CopyScanFields((Scan *) from, (Scan *) newnode);

	return newnode;
394 395
}

396
/*
397
 * _copyAppendOnlyScan
398
 */
399 400
static AppendOnlyScan *
_copyAppendOnlyScan(AppendOnlyScan *from)
401
{
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
	AppendOnlyScan    *newnode = makeNode(AppendOnlyScan);

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

	return newnode;
}

/*
 * _copyAppendOnlyScan
 */
static AOCSScan *
_copyAOCSScan(AOCSScan *from)
{
	AOCSScan    *newnode = makeNode(AOCSScan);

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

	return newnode;
}

static TableScan *
_copyTableScan(TableScan *from)
{
	TableScan *newnode = makeNode(TableScan);
	CopyScanFields((Scan *) from, (Scan *) newnode);

	return newnode;
}

static DynamicTableScan *
_copyDynamicTableScan(DynamicTableScan *from)
{
	DynamicTableScan *newnode = makeNode(DynamicTableScan);
	CopyScanFields((Scan *) from, (Scan *) newnode);
	COPY_SCALAR_FIELD(partIndex);
	COPY_SCALAR_FIELD(partIndexPrintable);

	return newnode;
}

/*
 * _copyExternalScan
 */
static ExternalScan *
_copyExternalScan(ExternalScan *from)
{
	ExternalScan    *newnode = makeNode(ExternalScan);
455

456 457
	/*
	 * copy node superclass fields
458 459 460
	 */
	CopyScanFields((Scan *) from, (Scan *) newnode);

461 462
	/*
	 * copy remainder of node
463
	 */
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
	COPY_NODE_FIELD(uriList);
	COPY_NODE_FIELD(fmtOpts);
	COPY_SCALAR_FIELD(fmtType);
	COPY_SCALAR_FIELD(isMasterOnly);
	COPY_SCALAR_FIELD(rejLimit);
	COPY_SCALAR_FIELD(rejLimitInRows);
	COPY_SCALAR_FIELD(fmterrtbl);
	COPY_SCALAR_FIELD(encoding);
	COPY_SCALAR_FIELD(scancounter);

	return newnode;
}

static void
copyIndexScanFields(const IndexScan *from, IndexScan *newnode)
{
	CopyScanFields((Scan *) from, (Scan *) newnode);

482 483 484 485 486 487
	COPY_SCALAR_FIELD(indexid);
	COPY_NODE_FIELD(indexqual);
	COPY_NODE_FIELD(indexqualorig);
	COPY_NODE_FIELD(indexstrategy);
	COPY_NODE_FIELD(indexsubtype);
	COPY_SCALAR_FIELD(indexorderdir);
488

489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
	/*
	 * If we don't have a valid partIndex, we also don't have
	 * a valid logicalIndexInfo (it should be set to NULL). So,
	 * we don't copy.
	 */
	if (isDynamicScan(&from->scan))
	{
		Assert(NULL != ((IndexScan *) from)->logicalIndexInfo);
		Assert(NULL == newnode->logicalIndexInfo);
		newnode->logicalIndexInfo = palloc(sizeof(LogicalIndexInfo));

		CopyLogicalIndexInfo(((IndexScan *) from)->logicalIndexInfo, newnode->logicalIndexInfo);
	}
	else
	{
		Assert(newnode->logicalIndexInfo == NULL);
	}
}

/*
 * _copyIndexScan
 */
static IndexScan *
_copyIndexScan(IndexScan *from)
{
	IndexScan  *newnode = makeNode(IndexScan);

	copyIndexScanFields(from, newnode);

	return newnode;
}

/*
 * _copyDynamicIndexScan
 */
static DynamicIndexScan *
_copyDynamicIndexScan(const DynamicIndexScan *from)
{
	DynamicIndexScan  *newnode = makeNode(DynamicIndexScan);

	/* DynamicIndexScan has some content from IndexScan */
	copyIndexScanFields((IndexScan *)from, (IndexScan *)newnode);

532
	return newnode;
533 534
}

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

543 544 545 546 547 548 549 550 551 552 553 554 555 556
	/* DynamicIndexScan has some content from IndexScan */
	copyIndexScanFields((IndexScan *)from, (IndexScan *)newnode);

	return newnode;
}

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

557 558 559 560 561 562 563 564
	/*
	 * copy node superclass fields
	 */
	CopyScanFields((Scan *) from, (Scan *) newnode);

	/*
	 * copy remainder of node
	 */
565
	COPY_NODE_FIELD(bitmapqualorig);
566 567 568 569 570

	return newnode;
}

/*
571
 * _copyBitmapAppendOnlyScan
572
 */
573 574
static BitmapAppendOnlyScan *
_copyBitmapAppendOnlyScan(BitmapAppendOnlyScan *from)
575
{
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
	BitmapAppendOnlyScan *newnode = makeNode(BitmapAppendOnlyScan);

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

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

	return newnode;
}

/*
 * _copyBitmapTableScan
 */
static BitmapTableScan *
_copyBitmapTableScan(BitmapTableScan *from)
{
	BitmapTableScan *newnode = makeNode(BitmapTableScan);
599 600 601 602 603 604 605 606 607 608 609 610 611 612

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

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

	return newnode;
}

613 614
/*
 * _copyTidScan
615 616 617 618
 */
static TidScan *
_copyTidScan(TidScan *from)
{
619
	TidScan    *newnode = makeNode(TidScan);
620

621 622
	/*
	 * copy node superclass fields
623 624
	 */
	CopyScanFields((Scan *) from, (Scan *) newnode);
625 626 627

	/*
	 * copy remainder of node
628
	 */
629
	COPY_NODE_FIELD(tidquals);
630

631 632 633
	return newnode;
}

634 635
/*
 * _copySubqueryScan
636 637 638 639
 */
static SubqueryScan *
_copySubqueryScan(SubqueryScan *from)
{
B
Bruce Momjian 已提交
640
	SubqueryScan *newnode = makeNode(SubqueryScan);
641

642 643
	/*
	 * copy node superclass fields
644 645 646
	 */
	CopyScanFields((Scan *) from, (Scan *) newnode);

647 648
	/*
	 * copy remainder of node
649
	 */
650
	COPY_NODE_FIELD(subplan);
651

652 653
	COPY_NODE_FIELD(subrtable);
	
654 655 656
	return newnode;
}

657 658
/*
 * _copyFunctionScan
659 660 661 662 663 664 665 666 667 668 669
 */
static FunctionScan *
_copyFunctionScan(FunctionScan *from)
{
	FunctionScan *newnode = makeNode(FunctionScan);

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

670 671 672 673 674 675 676 677
	/*
	 * copy remainder of node
	 */
	COPY_NODE_FIELD(funcexpr);
	COPY_NODE_FIELD(funccolnames);
	COPY_NODE_FIELD(funccoltypes);
	COPY_NODE_FIELD(funccoltypmods);

678 679
	return newnode;
}
680

681 682 683 684 685 686 687 688 689 690 691 692 693
/*
 * _copyValuesScan
 */
static ValuesScan *
_copyValuesScan(ValuesScan *from)
{
	ValuesScan *newnode = makeNode(ValuesScan);

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

694 695 696 697 698
	/*
	 * copy remainder of node
	 */
	COPY_NODE_FIELD(values_lists);

699 700 701
	return newnode;
}

702 703
/*
 * CopyJoinFields
704
 *
705 706
 *		This function copies the fields of the Join node.  It is used by
 *		all the copy functions for classes which inherit from Join.
707 708
 */
static void
709
CopyJoinFields(Join *from, Join *newnode)
710
{
711 712
	CopyPlanFields((Plan *) from, (Plan *) newnode);

713 714
    COPY_SCALAR_FIELD(prefetch_inner);

715 716
	COPY_SCALAR_FIELD(jointype);
	COPY_NODE_FIELD(joinqual);
717 718 719
}


720 721
/*
 * _copyJoin
722
 */
723
static Join *
724
_copyJoin(Join *from)
725
{
726
	Join	   *newnode = makeNode(Join);
727

728 729
	/*
	 * copy node superclass fields
730 731 732 733
	 */
	CopyJoinFields(from, newnode);

	return newnode;
734 735 736
}


737 738
/*
 * _copyNestLoop
739 740
 */
static NestLoop *
741
_copyNestLoop(NestLoop *from)
742
{
743
	NestLoop   *newnode = makeNode(NestLoop);
744

745 746
	/*
	 * copy node superclass fields
747 748 749
	 */
	CopyJoinFields((Join *) from, (Join *) newnode);

750 751 752
    COPY_SCALAR_FIELD(outernotreferencedbyinner);   /*CDB*/
    COPY_SCALAR_FIELD(shared_outer);
    COPY_SCALAR_FIELD(singleton_outer); /*CDB-OLAP*/
753

754 755
    return newnode;
}
756

757 758
/*
 * _copyMergeJoin
759 760
 */
static MergeJoin *
761
_copyMergeJoin(MergeJoin *from)
762
{
763
	MergeJoin  *newnode = makeNode(MergeJoin);
764
	int			numCols;
765

766 767
	/*
	 * copy node superclass fields
768 769 770
	 */
	CopyJoinFields((Join *) from, (Join *) newnode);

771 772
	/*
	 * copy remainder of node
773
	 */
774
	COPY_NODE_FIELD(mergeclauses);
775 776 777 778
	numCols = list_length(from->mergeclauses);
	COPY_POINTER_FIELD(mergeFamilies, numCols * sizeof(Oid));
	COPY_POINTER_FIELD(mergeStrategies, numCols * sizeof(int));
	COPY_POINTER_FIELD(mergeNullsFirst, numCols * sizeof(bool));
779
	COPY_SCALAR_FIELD(unique_outer);
780 781

	return newnode;
782 783
}

784 785
/*
 * _copyHashJoin
786 787
 */
static HashJoin *
788
_copyHashJoin(HashJoin *from)
789
{
790
	HashJoin   *newnode = makeNode(HashJoin);
791

792 793
	/*
	 * copy node superclass fields
794 795 796
	 */
	CopyJoinFields((Join *) from, (Join *) newnode);

797 798
	/*
	 * copy remainder of node
799
	 */
800
	COPY_NODE_FIELD(hashclauses);
801 802 803 804 805 806 807 808 809 810 811 812
	COPY_NODE_FIELD(hashqualclauses);

	return newnode;
}

/*
 * _copyShareInputScan
 */
static ShareInputScan *
_copyShareInputScan(ShareInputScan *from)
{
	ShareInputScan *newnode = makeNode(ShareInputScan);
813

814 815 816 817 818
	/* copy node superclass fields */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
	COPY_SCALAR_FIELD(share_type);
	COPY_SCALAR_FIELD(share_id);
	COPY_SCALAR_FIELD(driver_slice);
819
	return newnode;
820 821 822
}


823 824
/*
 * _copyMaterial
825 826
 */
static Material *
827
_copyMaterial(Material *from)
828
{
829
	Material   *newnode = makeNode(Material);
830

831 832
	/*
	 * copy node superclass fields
833 834
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
835 836 837 838 839 840
    COPY_SCALAR_FIELD(cdb_strict);
	COPY_SCALAR_FIELD(share_type);
	COPY_SCALAR_FIELD(share_id);
	COPY_SCALAR_FIELD(driver_slice);
	COPY_SCALAR_FIELD(nsharer);
	COPY_SCALAR_FIELD(nsharer_xslice);
841

842
    return newnode;
843 844 845
}


846 847
/*
 * _copySort
848
 */
849
static Sort *
850
_copySort(Sort *from)
851
{
852
	Sort	   *newnode = makeNode(Sort);
853

854 855
	/*
	 * copy node superclass fields
856 857
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);
858

859 860 861
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
	COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
862
	COPY_POINTER_FIELD(nullsFirst, from->numCols * sizeof(bool));
863

864 865 866 867
    /* CDB */
	COPY_NODE_FIELD(limitOffset);
	COPY_NODE_FIELD(limitCount);
	COPY_SCALAR_FIELD(noduplicates);
868

869 870 871 872 873
	COPY_SCALAR_FIELD(share_type);
	COPY_SCALAR_FIELD(share_id);
	COPY_SCALAR_FIELD(driver_slice);
	COPY_SCALAR_FIELD(nsharer);
	COPY_SCALAR_FIELD(nsharer_xslice);
V
Vadim B. Mikheev 已提交
874 875 876 877

	return newnode;
}

878 879
/*
 * _copyAgg
880
 */
881
static Agg *
B
Bruce Momjian 已提交
882
_copyAgg(Agg *from)
883
{
884
	Agg		   *newnode = makeNode(Agg);
885 886 887

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

888 889
	COPY_SCALAR_FIELD(aggstrategy);
	COPY_SCALAR_FIELD(numCols);
890
	if (from->numCols > 0)
891
	{
892
		COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
893 894
		COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
	}
895
	COPY_SCALAR_FIELD(numGroups);
896 897 898 899 900 901 902 903
	COPY_SCALAR_FIELD(transSpace);
	COPY_SCALAR_FIELD(numNullCols);
	COPY_SCALAR_FIELD(inputGrouping);
	COPY_SCALAR_FIELD(grouping);
	COPY_SCALAR_FIELD(inputHasGrouping);
	COPY_SCALAR_FIELD(rollupGSTimes);
	COPY_SCALAR_FIELD(lastAgg);
	COPY_SCALAR_FIELD(streaming);
904

905
	return newnode;
906 907
}

908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938
/*
 * _copyWindowKey
 */
static WindowKey *
_copyWindowKey(WindowKey *from)
{
	WindowKey   *newnode = makeNode(WindowKey);

	COPY_SCALAR_FIELD(numSortCols);
	if (from->numSortCols > 0)
	{
		COPY_POINTER_FIELD(sortColIdx, from->numSortCols * sizeof(AttrNumber));
		COPY_POINTER_FIELD(sortOperators, from->numSortCols * sizeof(Oid));
	}
	COPY_NODE_FIELD(frame);

	return newnode;
}

/*
 * _copyWindow
 */
static Window *
_copyWindow(Window *from)
{
	Window	*newnode = makeNode(Window);

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

	COPY_SCALAR_FIELD(numPartCols);
	if (from->numPartCols > 0)
939
	{
940
		COPY_POINTER_FIELD(partColIdx, from->numPartCols * sizeof(AttrNumber));
941 942
		COPY_POINTER_FIELD(partOperators, from->numPartCols * sizeof(Oid));
	}
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961
	COPY_NODE_FIELD(windowKeys);

	return newnode;
}

/*
 * _copyTableFunctionScan
 */
static TableFunctionScan *
_copyTableFunctionScan(TableFunctionScan *from)
{
	TableFunctionScan	*newnode = makeNode(TableFunctionScan);

	CopyScanFields((Scan *) from, (Scan *) newnode);

	return newnode;
}


962 963
/*
 * _copyUnique
964
 */
965
static Unique *
966
_copyUnique(Unique *from)
967
{
968
	Unique	   *newnode = makeNode(Unique);
969

970 971
	/*
	 * copy node superclass fields
972 973 974
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

975 976
	/*
	 * copy remainder of node
977
	 */
978 979
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
980
	COPY_POINTER_FIELD(uniqOperators, from->numCols * sizeof(Oid));
981 982

	return newnode;
983 984
}

985
/*
986
 * _copyHash
987
 */
988 989
static Hash *
_copyHash(Hash *from)
990
{
991
	Hash	   *newnode = makeNode(Hash);
992

993 994
	/*
	 * copy node superclass fields
995 996 997
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

998 999
	/*
	 * copy remainder of node
1000 1001 1002 1003
	 */

	return newnode;
}
1004

1005
/*
1006
 * _copySetOp
1007
 */
1008 1009
static SetOp *
_copySetOp(SetOp *from)
1010
{
1011
	SetOp	   *newnode = makeNode(SetOp);
1012

1013 1014
	/*
	 * copy node superclass fields
1015 1016 1017
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

1018 1019
	/*
	 * copy remainder of node
1020
	 */
1021 1022 1023
	COPY_SCALAR_FIELD(cmd);
	COPY_SCALAR_FIELD(numCols);
	COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
1024
	COPY_POINTER_FIELD(dupOperators, from->numCols * sizeof(Oid));
1025
	COPY_SCALAR_FIELD(flagColIdx);
1026 1027 1028 1029

	return newnode;
}

1030
/*
1031
 * _copyLimit
1032
 */
1033 1034
static Limit *
_copyLimit(Limit *from)
1035
{
1036
	Limit	   *newnode = makeNode(Limit);
1037

1038 1039
	/*
	 * copy node superclass fields
1040 1041 1042
	 */
	CopyPlanFields((Plan *) from, (Plan *) newnode);

1043 1044
	/*
	 * copy remainder of node
1045
	 */
1046 1047
	COPY_NODE_FIELD(limitOffset);
	COPY_NODE_FIELD(limitCount);
1048 1049

	return newnode;
1050 1051
}

1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
/*
 * _copyMotion
 */
static Motion *
_copyMotion(Motion *from)
{
	Motion	   *newnode = makeNode(Motion);

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

	COPY_SCALAR_FIELD(sendSorted);
	COPY_SCALAR_FIELD(motionID);

	COPY_SCALAR_FIELD(motionType);

	COPY_NODE_FIELD(hashExpr);
	COPY_NODE_FIELD(hashDataTypes);

	COPY_SCALAR_FIELD(numOutputSegs);
	COPY_POINTER_FIELD(outputSegIdx, from->numOutputSegs * sizeof(int));

	COPY_SCALAR_FIELD(numSortCols);
	COPY_POINTER_FIELD(sortColIdx, from->numSortCols * sizeof(AttrNumber));
	COPY_POINTER_FIELD(sortOperators, from->numSortCols * sizeof(Oid));
1079
	COPY_POINTER_FIELD(nullsFirst, from->numSortCols * sizeof(bool));
1080 1081 1082 1083 1084 1085
	
	COPY_SCALAR_FIELD(segidColIdx);
	
	return newnode;
}

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 1111 1112 1113 1114 1115 1116 1117 1118
/*
* _copyCoerceViaIO
*/
static CoerceViaIO *
_copyCoerceViaIO(CoerceViaIO *from)
{
	CoerceViaIO   *newnode = makeNode(CoerceViaIO);

	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(coerceformat);

	return newnode;
}

/*
 * _copyArrayCoerceExpr
 */
static ArrayCoerceExpr *
_copyArrayCoerceExpr(ArrayCoerceExpr *from)
{
	ArrayCoerceExpr   *newnode = makeNode(ArrayCoerceExpr);

	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(elemfuncid);
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
	COPY_SCALAR_FIELD(isExplicit);
	COPY_SCALAR_FIELD(coerceformat);

	return newnode;
}

1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 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 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231
/*
 * _copyDML
 */
static DML *
_copyDML(const DML *from)
{
	DML *newnode = makeNode(DML);

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

	COPY_SCALAR_FIELD(scanrelid);
	COPY_SCALAR_FIELD(oidColIdx);
	COPY_SCALAR_FIELD(actionColIdx);
	COPY_SCALAR_FIELD(ctidColIdx);
	COPY_SCALAR_FIELD(tupleoidColIdx);

	return newnode;
}

/*
 * _copySplitUpdate
 */
static SplitUpdate *
_copySplitUpdate(const SplitUpdate *from)
{
	SplitUpdate *newnode = makeNode(SplitUpdate);

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

	COPY_SCALAR_FIELD(actionColIdx);
	COPY_SCALAR_FIELD(ctidColIdx);
	COPY_SCALAR_FIELD(tupleoidColIdx);
	COPY_NODE_FIELD(insertColIdx);
	COPY_NODE_FIELD(deleteColIdx);

	return newnode;
}

/*
 * _copyRowTrigger
 */
static RowTrigger *
_copyRowTrigger(const RowTrigger *from)
{
	RowTrigger *newnode = makeNode(RowTrigger);

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

	COPY_SCALAR_FIELD(relid);
	COPY_SCALAR_FIELD(eventFlags);
	COPY_NODE_FIELD(oldValuesColIdx);
	COPY_NODE_FIELD(newValuesColIdx);

	return newnode;
}

/*
 * _copyAssertOp
 */
static AssertOp *
_copyAssertOp(const AssertOp *from)
{
	AssertOp *newnode = makeNode(AssertOp);

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

	COPY_SCALAR_FIELD(errcode);
	COPY_NODE_FIELD(errmessage);
	
	return newnode;
}

/*
 * _copyPartitionSelector
 */
static PartitionSelector *
_copyPartitionSelector(const PartitionSelector *from)
{
	PartitionSelector *newnode = makeNode(PartitionSelector);

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

	COPY_SCALAR_FIELD(relid);
	COPY_SCALAR_FIELD(nLevels);
	COPY_SCALAR_FIELD(scanId);
	COPY_SCALAR_FIELD(selectorId);
	COPY_NODE_FIELD(levelEqExpressions);
	COPY_NODE_FIELD(levelExpressions);
	COPY_NODE_FIELD(residualPredicate);
	COPY_NODE_FIELD(propagationExpression);
	COPY_NODE_FIELD(printablePredicate);
	COPY_SCALAR_FIELD(staticSelection);
	COPY_NODE_FIELD(staticPartOids);
	COPY_NODE_FIELD(staticScanIds);

	return newnode;
}

1232
/* ****************************************************************
1233
 *					   primnodes.h copy functions
1234 1235 1236
 * ****************************************************************
 */

1237 1238 1239
/*
 * _copyAlias
 */
1240 1241 1242 1243
static Alias *
_copyAlias(Alias *from)
{
	Alias	   *newnode = makeNode(Alias);
1244

1245 1246
	COPY_STRING_FIELD(aliasname);
	COPY_NODE_FIELD(colnames);
1247

1248 1249
	return newnode;
}
1250

1251 1252 1253
/*
 * _copyRangeVar
 */
1254 1255 1256 1257 1258
static RangeVar *
_copyRangeVar(RangeVar *from)
{
	RangeVar   *newnode = makeNode(RangeVar);

1259
	Assert(from->schemaname == NULL || strlen(from->schemaname)>0);
1260 1261 1262 1263 1264 1265
	COPY_STRING_FIELD(catalogname);
	COPY_STRING_FIELD(schemaname);
	COPY_STRING_FIELD(relname);
	COPY_SCALAR_FIELD(inhOpt);
	COPY_SCALAR_FIELD(istemp);
	COPY_NODE_FIELD(alias);
1266
	COPY_LOCATION_FIELD(location);
1267 1268

	return newnode;
1269 1270
}

1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283
/*
 * _copyIntoClause
 */
static IntoClause *
_copyIntoClause(IntoClause *from)
{
	IntoClause *newnode = makeNode(IntoClause);
	
	COPY_NODE_FIELD(rel);
	COPY_NODE_FIELD(colNames);
	COPY_NODE_FIELD(options);
	COPY_SCALAR_FIELD(onCommit);
	COPY_STRING_FIELD(tableSpaceName);
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308

	return newnode;
}

static TableOidInfo *
_copyTableOidInfo(TableOidInfo *from)
{
	TableOidInfo *newnode = makeNode(TableOidInfo);

	COPY_SCALAR_FIELD(relOid);
	COPY_SCALAR_FIELD(comptypeOid);
	COPY_SCALAR_FIELD(comptypeArrayOid);
	COPY_SCALAR_FIELD(toastOid);
	COPY_SCALAR_FIELD(toastIndexOid);
	COPY_SCALAR_FIELD(toastComptypeOid);
	COPY_SCALAR_FIELD(aosegOid);
	COPY_SCALAR_FIELD(aosegIndexOid);
	COPY_SCALAR_FIELD(aosegComptypeOid);
	COPY_SCALAR_FIELD(aovisimapOid);
	COPY_SCALAR_FIELD(aovisimapIndexOid);
	COPY_SCALAR_FIELD(aovisimapComptypeOid);
	COPY_SCALAR_FIELD(aoblkdirOid);
	COPY_SCALAR_FIELD(aoblkdirIndexOid);
	COPY_SCALAR_FIELD(aoblkdirComptypeOid);

1309 1310 1311
	return newnode;
}

1312
/*
1313
 * We don't need a _copyExpr because Expr is an abstract supertype which
B
Bruce Momjian 已提交
1314
 * should never actually get instantiated.	Also, since it has no common
1315 1316
 * fields except NodeTag, there's no need for a helper routine to factor
 * out copying the common fields...
1317 1318
 */

1319 1320
/*
 * _copyVar
1321
 */
1322
static Var *
1323
_copyVar(Var *from)
1324
{
1325
	Var		   *newnode = makeNode(Var);
1326

1327 1328 1329 1330 1331 1332 1333
	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);
1334
	COPY_LOCATION_FIELD(location);
1335 1336

	return newnode;
1337 1338
}

1339 1340
/*
 * _copyConst
1341
 */
1342
static Const *
1343
_copyConst(Const *from)
1344
{
1345
	Const	   *newnode = makeNode(Const);
1346

1347 1348
	COPY_SCALAR_FIELD(consttype);
	COPY_SCALAR_FIELD(constlen);
1349

1350
	if (from->constbyval || from->constisnull)
1351
	{
1352 1353 1354
		/*
		 * passed by value so just copy the datum. Also, don't try to copy
		 * struct when value is null!
1355
		 */
1356
		newnode->constvalue = from->constvalue;
1357
	}
1358
	else
1359
	{
1360
		/*
1361
		 * passed by reference.  We need a palloc'd copy.
1362
		 */
1363 1364 1365
		newnode->constvalue = datumCopy(from->constvalue,
										from->constbyval,
										from->constlen);
1366
	}
1367

1368 1369
	COPY_SCALAR_FIELD(constisnull);
	COPY_SCALAR_FIELD(constbyval);
1370
	COPY_LOCATION_FIELD(location);
1371 1372

	return newnode;
1373 1374
}

1375 1376
/*
 * _copyParam
1377
 */
1378
static Param *
1379
_copyParam(Param *from)
1380
{
1381
	Param	   *newnode = makeNode(Param);
1382

1383 1384 1385
	COPY_SCALAR_FIELD(paramkind);
	COPY_SCALAR_FIELD(paramid);
	COPY_SCALAR_FIELD(paramtype);
1386
	COPY_SCALAR_FIELD(paramtypmod);
1387
	COPY_LOCATION_FIELD(location);
1388 1389

	return newnode;
1390 1391
}

1392
/*
1393
 * _copyAggref
1394
 */
1395 1396
static Aggref *
_copyAggref(Aggref *from)
1397
{
1398 1399 1400 1401
	Aggref	   *newnode = makeNode(Aggref);

	COPY_SCALAR_FIELD(aggfnoid);
	COPY_SCALAR_FIELD(aggtype);
1402
	COPY_NODE_FIELD(args);
1403
	COPY_SCALAR_FIELD(agglevelsup);
1404 1405
	COPY_SCALAR_FIELD(aggstar);
	COPY_SCALAR_FIELD(aggdistinct);
1406 1407
	COPY_SCALAR_FIELD(aggstage);
    COPY_NODE_FIELD(aggorder);
1408
	COPY_LOCATION_FIELD(location);
1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444

	return newnode;
}

/*
 * _copyAggOrder
 */
static AggOrder *
_copyAggOrder(AggOrder *from)
{
	AggOrder   *newnode = makeNode(AggOrder);

    COPY_SCALAR_FIELD(sortImplicit);
	COPY_NODE_FIELD(sortTargets);
    COPY_NODE_FIELD(sortClause);

	return newnode;
}

/*
 * _copyWindowRef
 */
static WindowRef *
_copyWindowRef(WindowRef *from)
{
	WindowRef	   *newnode = makeNode(WindowRef);

	COPY_SCALAR_FIELD(winfnoid);
	COPY_SCALAR_FIELD(restype);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(winlevelsup);
	COPY_SCALAR_FIELD(windistinct);
	COPY_SCALAR_FIELD(winspec);
	COPY_SCALAR_FIELD(winindex);
	COPY_SCALAR_FIELD(winstage);
	COPY_SCALAR_FIELD(winlevel);
1445
	COPY_LOCATION_FIELD(location);
1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458

	return newnode;
}

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

	COPY_SCALAR_FIELD(refrestype);
1459 1460
	COPY_SCALAR_FIELD(refarraytype);
	COPY_SCALAR_FIELD(refelemtype);
1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472
	COPY_NODE_FIELD(refupperindexpr);
	COPY_NODE_FIELD(reflowerindexpr);
	COPY_NODE_FIELD(refexpr);
	COPY_NODE_FIELD(refassgnexpr);

	return newnode;
}

/*
 * _copyFuncExpr
 */
static FuncExpr *
1473
_copyFuncExpr(FuncExpr *from)
1474
{
B
Bruce Momjian 已提交
1475
	FuncExpr   *newnode = makeNode(FuncExpr);
1476

1477 1478 1479 1480
	COPY_SCALAR_FIELD(funcid);
	COPY_SCALAR_FIELD(funcresulttype);
	COPY_SCALAR_FIELD(funcretset);
	COPY_SCALAR_FIELD(funcformat);
1481
	COPY_NODE_FIELD(args);
1482
	COPY_LOCATION_FIELD(location);
1483
	COPY_SCALAR_FIELD(is_tablefunc);
1484

1485
	return newnode;
1486 1487
}

1488
/*
1489
 * _copyOpExpr
1490
 */
1491
static OpExpr *
1492
_copyOpExpr(OpExpr *from)
1493
{
1494
	OpExpr	   *newnode = makeNode(OpExpr);
1495

1496 1497 1498 1499 1500
	COPY_SCALAR_FIELD(opno);
	COPY_SCALAR_FIELD(opfuncid);
	COPY_SCALAR_FIELD(opresulttype);
	COPY_SCALAR_FIELD(opretset);
	COPY_NODE_FIELD(args);
1501
	COPY_LOCATION_FIELD(location);
1502 1503 1504 1505 1506

	return newnode;
}

/*
1507
 * _copyDistinctExpr (same as OpExpr)
1508 1509
 */
static DistinctExpr *
1510
_copyDistinctExpr(DistinctExpr *from)
1511
{
B
Bruce Momjian 已提交
1512
	DistinctExpr *newnode = makeNode(DistinctExpr);
1513 1514 1515 1516 1517 1518

	COPY_SCALAR_FIELD(opno);
	COPY_SCALAR_FIELD(opfuncid);
	COPY_SCALAR_FIELD(opresulttype);
	COPY_SCALAR_FIELD(opretset);
	COPY_NODE_FIELD(args);
1519
	COPY_LOCATION_FIELD(location);
1520 1521 1522 1523

	return newnode;
}

1524 1525 1526 1527
/*
 * _copyScalarArrayOpExpr
 */
static ScalarArrayOpExpr *
1528
_copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
1529
{
B
Bruce Momjian 已提交
1530
	ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
1531 1532 1533 1534 1535

	COPY_SCALAR_FIELD(opno);
	COPY_SCALAR_FIELD(opfuncid);
	COPY_SCALAR_FIELD(useOr);
	COPY_NODE_FIELD(args);
1536
	COPY_LOCATION_FIELD(location);
1537 1538 1539 1540

	return newnode;
}

1541 1542 1543 1544
/*
 * _copyBoolExpr
 */
static BoolExpr *
1545
_copyBoolExpr(BoolExpr *from)
1546
{
B
Bruce Momjian 已提交
1547
	BoolExpr   *newnode = makeNode(BoolExpr);
1548 1549 1550

	COPY_SCALAR_FIELD(boolop);
	COPY_NODE_FIELD(args);
1551
	COPY_LOCATION_FIELD(location);
1552 1553

	return newnode;
1554 1555
}

1556 1557
/*
 * _copySubLink
1558 1559 1560 1561
 */
static SubLink *
_copySubLink(SubLink *from)
{
1562
	SubLink    *newnode = makeNode(SubLink);
1563

1564
	COPY_SCALAR_FIELD(subLinkType);
1565
	COPY_NODE_FIELD(testexpr);
1566
	COPY_NODE_FIELD(operName);
1567
	COPY_NODE_FIELD(subselect);
1568
	COPY_LOCATION_FIELD(location);
1569 1570 1571 1572

	return newnode;
}

1573
/*
1574
 * _copySubPlan
1575
 */
1576 1577
static SubPlan *
_copySubPlan(SubPlan *from)
1578
{
1579
	SubPlan    *newnode = makeNode(SubPlan);
1580

1581
	COPY_SCALAR_FIELD(subLinkType);
1582
	COPY_SCALAR_FIELD(qDispSliceId);    /*CDB*/
1583
	COPY_NODE_FIELD(testexpr);
1584
	COPY_NODE_FIELD(paramIds);
1585
	COPY_SCALAR_FIELD(plan_id);
1586 1587 1588
	COPY_STRING_FIELD(plan_name);
	COPY_SCALAR_FIELD(firstColType);
	COPY_SCALAR_FIELD(firstColTypmod);
1589 1590
	COPY_SCALAR_FIELD(useHashTable);
	COPY_SCALAR_FIELD(unknownEqFalse);
1591 1592
	COPY_SCALAR_FIELD(is_initplan);	/*CDB*/
	COPY_SCALAR_FIELD(is_multirow);	/*CDB*/
1593 1594
	COPY_NODE_FIELD(setParam);
	COPY_NODE_FIELD(parParam);
1595
	COPY_NODE_FIELD(args);
1596
	COPY_NODE_FIELD(extParam);
1597 1598 1599 1600

	return newnode;
}

1601 1602
/*
 * _copyFieldSelect
1603 1604 1605 1606 1607 1608
 */
static FieldSelect *
_copyFieldSelect(FieldSelect *from)
{
	FieldSelect *newnode = makeNode(FieldSelect);

1609 1610 1611 1612
	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(fieldnum);
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
1613 1614 1615 1616

	return newnode;
}

1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632
/*
 * _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;
}

1633 1634
/*
 * _copyRelabelType
1635 1636 1637 1638
 */
static RelabelType *
_copyRelabelType(RelabelType *from)
{
1639
	RelabelType *newnode = makeNode(RelabelType);
1640

1641 1642 1643 1644
	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
	COPY_SCALAR_FIELD(relabelformat);
1645
	COPY_LOCATION_FIELD(location);
1646 1647 1648 1649

	return newnode;
}

1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660
/*
 * _copyConvertRowtypeExpr
 */
static ConvertRowtypeExpr *
_copyConvertRowtypeExpr(ConvertRowtypeExpr *from)
{
	ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);

	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(convertformat);
1661
	COPY_LOCATION_FIELD(location);
1662 1663 1664 1665

	return newnode;
}

1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677
/*
 * _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);
1678
	COPY_LOCATION_FIELD(location);
1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692

	return newnode;
}

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

	COPY_NODE_FIELD(expr);
	COPY_NODE_FIELD(result);
1693
	COPY_LOCATION_FIELD(location);
1694 1695 1696 1697

	return newnode;
}

1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
/*
 * _copyCaseTestExpr
 */
static CaseTestExpr *
_copyCaseTestExpr(CaseTestExpr *from)
{
	CaseTestExpr *newnode = makeNode(CaseTestExpr);

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);

	return newnode;
}

1712 1713 1714 1715
/*
 * _copyArrayExpr
 */
static ArrayExpr *
1716
_copyArrayExpr(ArrayExpr *from)
1717
{
B
Bruce Momjian 已提交
1718
	ArrayExpr  *newnode = makeNode(ArrayExpr);
1719 1720 1721 1722

	COPY_SCALAR_FIELD(array_typeid);
	COPY_SCALAR_FIELD(element_typeid);
	COPY_NODE_FIELD(elements);
1723
	COPY_SCALAR_FIELD(multidims);
1724
	COPY_LOCATION_FIELD(location);
1725 1726 1727 1728

	return newnode;
}

1729 1730 1731 1732 1733 1734
/*
 * _copyRowExpr
 */
static RowExpr *
_copyRowExpr(RowExpr *from)
{
B
Bruce Momjian 已提交
1735
	RowExpr    *newnode = makeNode(RowExpr);
1736 1737 1738 1739

	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(row_typeid);
	COPY_SCALAR_FIELD(row_format);
1740
	COPY_LOCATION_FIELD(location);
1741 1742 1743 1744

	return newnode;
}

1745 1746 1747 1748 1749 1750
/*
 * _copyRowCompareExpr
 */
static RowCompareExpr *
_copyRowCompareExpr(RowCompareExpr *from)
{
B
Bruce Momjian 已提交
1751
	RowCompareExpr *newnode = makeNode(RowCompareExpr);
1752 1753 1754

	COPY_SCALAR_FIELD(rctype);
	COPY_NODE_FIELD(opnos);
1755
	COPY_NODE_FIELD(opfamilies);
1756 1757 1758 1759 1760 1761
	COPY_NODE_FIELD(largs);
	COPY_NODE_FIELD(rargs);

	return newnode;
}

1762 1763 1764 1765
/*
 * _copyCoalesceExpr
 */
static CoalesceExpr *
1766
_copyCoalesceExpr(CoalesceExpr *from)
1767 1768 1769 1770 1771
{
	CoalesceExpr *newnode = makeNode(CoalesceExpr);

	COPY_SCALAR_FIELD(coalescetype);
	COPY_NODE_FIELD(args);
1772
	COPY_LOCATION_FIELD(location);
1773 1774 1775 1776

	return newnode;
}

1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787
/*
 * _copyMinMaxExpr
 */
static MinMaxExpr *
_copyMinMaxExpr(MinMaxExpr *from)
{
	MinMaxExpr *newnode = makeNode(MinMaxExpr);

	COPY_SCALAR_FIELD(minmaxtype);
	COPY_SCALAR_FIELD(op);
	COPY_NODE_FIELD(args);
1788
	COPY_LOCATION_FIELD(location);
1789 1790 1791 1792

	return newnode;
}

1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805
/*
 * _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);
1806 1807 1808 1809
	COPY_SCALAR_FIELD(xmloption);
	COPY_SCALAR_FIELD(type);
	COPY_SCALAR_FIELD(typmod);
	COPY_LOCATION_FIELD(location);
1810 1811 1812 1813

	return newnode;
}

1814 1815 1816 1817
/*
 * _copyNullIfExpr (same as OpExpr)
 */
static NullIfExpr *
1818
_copyNullIfExpr(NullIfExpr *from)
1819
{
B
Bruce Momjian 已提交
1820
	NullIfExpr *newnode = makeNode(NullIfExpr);
1821 1822 1823 1824 1825 1826

	COPY_SCALAR_FIELD(opno);
	COPY_SCALAR_FIELD(opfuncid);
	COPY_SCALAR_FIELD(opresulttype);
	COPY_SCALAR_FIELD(opretset);
	COPY_NODE_FIELD(args);
1827
	COPY_LOCATION_FIELD(location);
1828 1829 1830 1831

	return newnode;
}

1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860
/*
 * _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;
}

/*
1861
 * _copyCoerceToDomain
1862
 */
1863
static CoerceToDomain *
1864
_copyCoerceToDomain(CoerceToDomain *from)
1865
{
1866
	CoerceToDomain *newnode = makeNode(CoerceToDomain);
1867 1868

	COPY_NODE_FIELD(arg);
1869 1870 1871
	COPY_SCALAR_FIELD(resulttype);
	COPY_SCALAR_FIELD(resulttypmod);
	COPY_SCALAR_FIELD(coercionformat);
1872
	COPY_LOCATION_FIELD(location);
1873 1874 1875 1876 1877

	return newnode;
}

/*
1878
 * _copyCoerceToDomainValue
1879
 */
1880
static CoerceToDomainValue *
1881
_copyCoerceToDomainValue(CoerceToDomainValue *from)
1882
{
1883
	CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1884 1885 1886

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);
1887
	COPY_LOCATION_FIELD(location);
1888 1889 1890 1891

	return newnode;
}

1892 1893 1894 1895
/*
 * _copySetToDefault
 */
static SetToDefault *
1896
_copySetToDefault(SetToDefault *from)
1897 1898 1899 1900 1901
{
	SetToDefault *newnode = makeNode(SetToDefault);

	COPY_SCALAR_FIELD(typeId);
	COPY_SCALAR_FIELD(typeMod);
1902
	COPY_LOCATION_FIELD(location);
1903 1904 1905 1906

	return newnode;
}

1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924
/*
 * _copyCurrentOfExpr
 */
static CurrentOfExpr *
_copyCurrentOfExpr(CurrentOfExpr *from)
{
	CurrentOfExpr *newnode = makeNode(CurrentOfExpr);

	COPY_STRING_FIELD(cursor_name);
	COPY_SCALAR_FIELD(cvarno);
	COPY_SCALAR_FIELD(target_relid);
	COPY_SCALAR_FIELD(gp_segment_id);
	COPY_BINARY_FIELD(ctid, sizeof(ItemPointerData));
	COPY_SCALAR_FIELD(tableoid);

	return newnode;
}

1925 1926 1927 1928 1929 1930 1931 1932 1933
/*
 * _copyTargetEntry
 */
static TargetEntry *
_copyTargetEntry(TargetEntry *from)
{
	TargetEntry *newnode = makeNode(TargetEntry);

	COPY_NODE_FIELD(expr);
1934 1935 1936 1937 1938 1939
	COPY_SCALAR_FIELD(resno);
	COPY_STRING_FIELD(resname);
	COPY_SCALAR_FIELD(ressortgroupref);
	COPY_SCALAR_FIELD(resorigtbl);
	COPY_SCALAR_FIELD(resorigcol);
	COPY_SCALAR_FIELD(resjunk);
1940 1941 1942 1943 1944 1945 1946

	return newnode;
}

/*
 * _copyRangeTblRef
 */
1947 1948 1949 1950 1951
static RangeTblRef *
_copyRangeTblRef(RangeTblRef *from)
{
	RangeTblRef *newnode = makeNode(RangeTblRef);

1952
	COPY_SCALAR_FIELD(rtindex);
1953 1954 1955 1956

	return newnode;
}

1957 1958 1959
/*
 * _copyJoinExpr
 */
1960 1961 1962
static JoinExpr *
_copyJoinExpr(JoinExpr *from)
{
B
Bruce Momjian 已提交
1963
	JoinExpr   *newnode = makeNode(JoinExpr);
1964

1965 1966 1967 1968
	COPY_SCALAR_FIELD(jointype);
	COPY_SCALAR_FIELD(isNatural);
	COPY_NODE_FIELD(larg);
	COPY_NODE_FIELD(rarg);
1969
	COPY_NODE_FIELD(usingClause);
1970 1971 1972
	COPY_NODE_FIELD(quals);
	COPY_NODE_FIELD(alias);
	COPY_SCALAR_FIELD(rtindex);
1973
	COPY_NODE_FIELD(subqfromlist);          /*CDB*/
T
Thomas G. Lockhart 已提交
1974 1975 1976 1977

	return newnode;
}

1978 1979 1980
/*
 * _copyFromExpr
 */
1981 1982
static FromExpr *
_copyFromExpr(FromExpr *from)
B
Bruce Momjian 已提交
1983
{
1984
	FromExpr   *newnode = makeNode(FromExpr);
B
Bruce Momjian 已提交
1985

1986 1987
	COPY_NODE_FIELD(fromlist);
	COPY_NODE_FIELD(quals);
B
Bruce Momjian 已提交
1988 1989 1990 1991

	return newnode;
}

1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006
/*
 * _copyFlow
 */
static Flow *
_copyFlow(Flow *from)
{
	Flow   *newnode = makeNode(Flow);

	COPY_SCALAR_FIELD(flotype);
	COPY_SCALAR_FIELD(req_move);
	COPY_SCALAR_FIELD(locustype);
	COPY_SCALAR_FIELD(segindex);
	COPY_SCALAR_FIELD(numSortCols);
	COPY_POINTER_FIELD(sortColIdx, from->numSortCols*sizeof(AttrNumber));
	COPY_POINTER_FIELD(sortOperators, from->numSortCols*sizeof(Oid));
2007
	COPY_POINTER_FIELD(nullsFirst, from->numSortCols*sizeof(bool));
2008
	COPY_SCALAR_FIELD(numOrderbyCols);
2009 2010 2011 2012 2013 2014 2015
	COPY_NODE_FIELD(hashExpr);
	COPY_NODE_FIELD(flow_before_req_move);

	return newnode;
}


2016
/* ****************************************************************
2017
 *						relation.h copy functions
2018
 *
2019 2020
 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
 * There are some subsidiary structs that are useful to copy, though.
2021 2022 2023
 * ****************************************************************
 */

2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041
/*
 * _copyCdbRelColumnInfo
 */
static CdbRelColumnInfo *
_copyCdbRelColumnInfo(CdbRelColumnInfo *from)
{
	CdbRelColumnInfo *newnode = makeNode(CdbRelColumnInfo);

	COPY_SCALAR_FIELD(pseudoattno);
    COPY_SCALAR_FIELD(targetresno);
	COPY_NODE_FIELD(defexpr);
	COPY_BITMAPSET_FIELD(where_needed);
	COPY_SCALAR_FIELD(attr_width);
    COPY_BINARY_FIELD(colname, sizeof(from->colname));

	return newnode;
}

2042
/*
2043
 * _copyPathKey
2044
 */
2045 2046
static PathKey *
_copyPathKey(PathKey *from)
2047
{
2048
	PathKey *newnode = makeNode(PathKey);
2049

2050 2051 2052 2053 2054
	/* EquivalenceClasses are never moved, so just shallow-copy the pointer */
	COPY_SCALAR_FIELD(pk_eclass);
	COPY_SCALAR_FIELD(pk_opfamily);
	COPY_SCALAR_FIELD(pk_strategy);
	COPY_SCALAR_FIELD(pk_nulls_first);
2055 2056

	return newnode;
2057 2058
}

2059 2060
/*
 * _copyRestrictInfo
2061
 */
2062
static RestrictInfo *
2063
_copyRestrictInfo(RestrictInfo *from)
2064
{
2065
	RestrictInfo *newnode = makeNode(RestrictInfo);
2066

2067
	COPY_NODE_FIELD(clause);
2068
	COPY_SCALAR_FIELD(is_pushed_down);
2069
	COPY_SCALAR_FIELD(outerjoin_delayed);
2070
	COPY_SCALAR_FIELD(can_join);
2071
	COPY_SCALAR_FIELD(pseudoconstant);
2072
	COPY_BITMAPSET_FIELD(clause_relids);
2073
	COPY_BITMAPSET_FIELD(required_relids);
2074 2075
	COPY_BITMAPSET_FIELD(left_relids);
	COPY_BITMAPSET_FIELD(right_relids);
2076
	COPY_NODE_FIELD(orclause);
2077 2078
	/* EquivalenceClasses are never copied, so shallow-copy the pointers */
	COPY_SCALAR_FIELD(parent_ec);
2079 2080
	COPY_SCALAR_FIELD(eval_cost);
	COPY_SCALAR_FIELD(this_selec);
2081 2082 2083 2084
	COPY_NODE_FIELD(mergeopfamilies);
	/* EquivalenceClasses are never copied, so shallow-copy the pointers */
	COPY_SCALAR_FIELD(left_ec);
	COPY_SCALAR_FIELD(right_ec);
2085 2086 2087 2088
	COPY_SCALAR_FIELD(left_em);
	COPY_SCALAR_FIELD(right_em);
	/* MergeScanSelCache isn't a Node, so hard to copy; just reset cache */
	newnode->scansel_cache = NIL;
2089
	COPY_SCALAR_FIELD(outer_is_left);
2090 2091 2092
	COPY_SCALAR_FIELD(hashjoinoperator);
	COPY_SCALAR_FIELD(left_bucketsize);
	COPY_SCALAR_FIELD(right_bucketsize);
2093 2094

	return newnode;
2095 2096
}

2097 2098 2099 2100 2101 2102 2103 2104 2105 2106
/*
 * _copyOuterJoinInfo
 */
static OuterJoinInfo *
_copyOuterJoinInfo(OuterJoinInfo *from)
{
	OuterJoinInfo *newnode = makeNode(OuterJoinInfo);

	COPY_BITMAPSET_FIELD(min_lefthand);
	COPY_BITMAPSET_FIELD(min_righthand);
2107 2108 2109
	COPY_BITMAPSET_FIELD(syn_lefthand);
	COPY_BITMAPSET_FIELD(syn_righthand);
	COPY_SCALAR_FIELD(join_type);
2110
	COPY_SCALAR_FIELD(lhs_strict);
2111
	COPY_SCALAR_FIELD(delay_upper_joins);
2112 2113 2114 2115

	return newnode;
}

2116 2117 2118 2119
/*
 * _copyInClauseInfo
 */
static InClauseInfo *
2120
_copyInClauseInfo(InClauseInfo *from)
2121 2122 2123
{
	InClauseInfo *newnode = makeNode(InClauseInfo);

2124
	COPY_BITMAPSET_FIELD(righthand);
2125
	COPY_NODE_FIELD(sub_targetlist);
2126
	COPY_NODE_FIELD(in_operators);
2127

2128 2129
    COPY_SCALAR_FIELD(try_join_unique);                 /*CDB*/

2130 2131 2132
	return newnode;
}

2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151
/*
 * _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;
}

2152 2153 2154
/* ****************************************************************
 *					parsenodes.h copy functions
 * ****************************************************************
2155 2156 2157
 */

static RangeTblEntry *
2158
_copyRangeTblEntry(RangeTblEntry *from)
2159
{
2160
	RangeTblEntry *newnode = makeNode(RangeTblEntry);
2161

2162 2163 2164 2165
	COPY_SCALAR_FIELD(rtekind);
	COPY_SCALAR_FIELD(relid);
	COPY_NODE_FIELD(subquery);
	COPY_NODE_FIELD(funcexpr);
2166 2167
	COPY_NODE_FIELD(funccoltypes);
	COPY_NODE_FIELD(funccoltypmods);
2168
	COPY_VARLENA_FIELD(funcuserdata, -1);
2169
	COPY_NODE_FIELD(values_lists);
2170 2171 2172 2173 2174 2175
	COPY_SCALAR_FIELD(jointype);
	COPY_NODE_FIELD(joinaliasvars);
	COPY_NODE_FIELD(alias);
	COPY_NODE_FIELD(eref);
	COPY_SCALAR_FIELD(inh);
	COPY_SCALAR_FIELD(inFromCl);
2176
	COPY_SCALAR_FIELD(requiredPerms);
2177
	COPY_SCALAR_FIELD(checkAsUser);
2178

2179 2180 2181 2182 2183 2184 2185 2186 2187
	COPY_STRING_FIELD(ctename);
	COPY_SCALAR_FIELD(ctelevelsup);
	COPY_SCALAR_FIELD(self_reference);
	COPY_NODE_FIELD(ctecoltypes);
	COPY_NODE_FIELD(ctecoltypmods);

	COPY_SCALAR_FIELD(forceDistRandom);
    COPY_NODE_FIELD(pseudocols);                /*CDB*/

2188 2189 2190
	return newnode;
}

2191 2192 2193
static FkConstraint *
_copyFkConstraint(FkConstraint *from)
{
B
Bruce Momjian 已提交
2194
	FkConstraint *newnode = makeNode(FkConstraint);
2195

2196
	COPY_STRING_FIELD(constr_name);
2197
	COPY_SCALAR_FIELD(constrOid);
2198 2199 2200 2201 2202 2203 2204 2205 2206
	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);
2207 2208 2209 2210
	COPY_SCALAR_FIELD(trig1Oid);
	COPY_SCALAR_FIELD(trig2Oid);
	COPY_SCALAR_FIELD(trig3Oid);
	COPY_SCALAR_FIELD(trig4Oid);
B
Bruce Momjian 已提交
2211

2212 2213 2214
	return newnode;
}

2215
static SortClause *
2216
_copySortClause(SortClause *from)
2217
{
2218
	SortClause *newnode = makeNode(SortClause);
2219

2220 2221
	COPY_SCALAR_FIELD(tleSortGroupRef);
	COPY_SCALAR_FIELD(sortop);
2222
	COPY_SCALAR_FIELD(nulls_first);
2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233

	return newnode;
}

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

	COPY_SCALAR_FIELD(tleSortGroupRef);
	COPY_SCALAR_FIELD(sortop);
2234
	COPY_SCALAR_FIELD(nulls_first);
2235

2236
	return newnode;
2237 2238
}

2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343
static GroupingClause *
_copyGroupingClause(GroupingClause *from)
{
	GroupingClause *newnode = makeNode(GroupingClause);
	COPY_SCALAR_FIELD(groupType);
	COPY_NODE_FIELD(groupsets);

	return newnode;
}

static GroupingFunc *
_copyGroupingFunc(GroupingFunc *from)
{
	GroupingFunc *newnode = makeNode(GroupingFunc);

	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(ngrpcols);

	return newnode;
}

static Grouping *
_copyGrouping(Grouping *from)
{
	Grouping *newnode = makeNode(Grouping);

	return newnode;
}

static GroupId *
_copyGroupId(GroupId *from)
{
	GroupId *newnode = makeNode(GroupId);

	return newnode;
}

static WindowSpecParse *
_copyWindowSpecParse(WindowSpecParse *from)
{
	WindowSpecParse *newnode = makeNode(WindowSpecParse);

	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(elems);

	return newnode;
}

static WindowSpec *
_copyWindowSpec(WindowSpec *from)
{
	WindowSpec *newnode = makeNode(WindowSpec);

	COPY_STRING_FIELD(name);
	COPY_STRING_FIELD(parent);
	COPY_NODE_FIELD(partition);
	COPY_NODE_FIELD(order);
	COPY_NODE_FIELD(frame);
	COPY_SCALAR_FIELD(location);

	return newnode;
}

static WindowFrame *
_copyWindowFrame(WindowFrame *from)
{
	WindowFrame *newnode = makeNode(WindowFrame);

	COPY_SCALAR_FIELD(is_rows);
	COPY_SCALAR_FIELD(is_between);
	COPY_NODE_FIELD(trail);
	COPY_NODE_FIELD(lead);
	COPY_SCALAR_FIELD(exclude);

	return newnode;
}

static WindowFrameEdge *
_copyWindowFrameEdge(WindowFrameEdge *from)
{
	WindowFrameEdge *newnode = makeNode(WindowFrameEdge);

	COPY_SCALAR_FIELD(kind);
	COPY_NODE_FIELD(val);

	return newnode;
}

static PercentileExpr *
_copyPercentileExpr(PercentileExpr *from)
{
	PercentileExpr *newnode = makeNode(PercentileExpr);

	COPY_SCALAR_FIELD(perctype);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(perckind);
	COPY_NODE_FIELD(sortClause);
	COPY_NODE_FIELD(sortTargets);
	COPY_NODE_FIELD(pcExpr);
	COPY_NODE_FIELD(tcExpr);
	COPY_SCALAR_FIELD(location);

	return newnode;
}

2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355
static RowMarkClause *
_copyRowMarkClause(RowMarkClause *from)
{
	RowMarkClause *newnode = makeNode(RowMarkClause);

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

	return newnode;
}

2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385
static WithClause *
_copyWithClause(WithClause *from)
{
	WithClause *newnode = makeNode(WithClause);
	
	COPY_NODE_FIELD(ctes);
	COPY_SCALAR_FIELD(recursive);
	COPY_SCALAR_FIELD(location);
	
	return newnode;
}

static CommonTableExpr *
_copyCommonTableExpr(CommonTableExpr *from)
{
	CommonTableExpr *newnode = makeNode(CommonTableExpr);
	
	COPY_STRING_FIELD(ctename);
	COPY_NODE_FIELD(aliascolnames);
	COPY_NODE_FIELD(ctequery);
	COPY_SCALAR_FIELD(location);
	COPY_SCALAR_FIELD(cterecursive);
	COPY_SCALAR_FIELD(cterefcount);
	COPY_NODE_FIELD(ctecolnames);
	COPY_NODE_FIELD(ctecoltypes);
	COPY_NODE_FIELD(ctecoltypmods);

	return newnode;
}

2386 2387 2388
static A_Expr *
_copyAExpr(A_Expr *from)
{
B
Bruce Momjian 已提交
2389
	A_Expr	   *newnode = makeNode(A_Expr);
2390

2391
	COPY_SCALAR_FIELD(kind);
2392 2393 2394
	COPY_NODE_FIELD(name);
	COPY_NODE_FIELD(lexpr);
	COPY_NODE_FIELD(rexpr);
2395
	COPY_SCALAR_FIELD(location);
2396 2397 2398 2399

	return newnode;
}

2400 2401
static ColumnRef *
_copyColumnRef(ColumnRef *from)
2402
{
B
Bruce Momjian 已提交
2403
	ColumnRef  *newnode = makeNode(ColumnRef);
2404

2405
	COPY_NODE_FIELD(fields);
2406
	COPY_SCALAR_FIELD(location);
2407

2408
	return newnode;
2409 2410
}

2411 2412
static ParamRef *
_copyParamRef(ParamRef *from)
2413
{
B
Bruce Momjian 已提交
2414
	ParamRef   *newnode = makeNode(ParamRef);
2415

2416
	COPY_SCALAR_FIELD(number);
2417
	COPY_SCALAR_FIELD(location);    /*CDB*/
2418 2419 2420 2421

	return newnode;
}

2422 2423 2424 2425 2426
static A_Const *
_copyAConst(A_Const *from)
{
	A_Const    *newnode = makeNode(A_Const);

2427
	/* This part must duplicate _copyValue */
2428
	COPY_SCALAR_FIELD(val.type);
2429 2430 2431
	switch (from->val.type)
	{
		case T_Integer:
2432
			COPY_SCALAR_FIELD(val.val.ival);
2433 2434 2435 2436
			break;
		case T_Float:
		case T_String:
		case T_BitString:
2437
			COPY_STRING_FIELD(val.val.str);
2438 2439 2440 2441 2442
			break;
		case T_Null:
			/* nothing to do */
			break;
		default:
2443 2444
			elog(ERROR, "unrecognized node type: %d",
				 (int) from->val.type);
2445 2446 2447
			break;
	}

2448 2449
	COPY_NODE_FIELD(typname);
	COPY_SCALAR_FIELD(location);    /*CDB*/
2450 2451 2452 2453

	return newnode;
}

2454 2455 2456
static FuncCall *
_copyFuncCall(FuncCall *from)
{
B
Bruce Momjian 已提交
2457
	FuncCall   *newnode = makeNode(FuncCall);
2458

2459 2460
	COPY_NODE_FIELD(funcname);
	COPY_NODE_FIELD(args);
2461
    COPY_NODE_FIELD(agg_order);
2462 2463
	COPY_SCALAR_FIELD(agg_star);
	COPY_SCALAR_FIELD(agg_distinct);
2464
	COPY_SCALAR_FIELD(func_variadic);
2465
	COPY_NODE_FIELD(over);
2466
	COPY_SCALAR_FIELD(location);
2467
	COPY_NODE_FIELD(agg_filter);
2468 2469 2470 2471 2472 2473 2474

	return newnode;
}

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

2477 2478
	COPY_NODE_FIELD(lidx);
	COPY_NODE_FIELD(uidx);
2479 2480 2481 2482

	return newnode;
}

2483 2484
static A_Indirection *
_copyA_Indirection(A_Indirection *from)
2485
{
2486
	A_Indirection *newnode = makeNode(A_Indirection);
2487

2488 2489
	COPY_NODE_FIELD(arg);
	COPY_NODE_FIELD(indirection);
2490 2491 2492 2493

	return newnode;
}

2494 2495 2496 2497 2498 2499 2500 2501 2502 2503
static A_ArrayExpr *
_copyA_ArrayExpr(A_ArrayExpr *from)
{
	A_ArrayExpr *newnode = makeNode(A_ArrayExpr);
	COPY_NODE_FIELD(elements);
	COPY_LOCATION_FIELD(location);

	return newnode;
}

2504 2505 2506
static ResTarget *
_copyResTarget(ResTarget *from)
{
B
Bruce Momjian 已提交
2507
	ResTarget  *newnode = makeNode(ResTarget);
2508

2509 2510 2511
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(indirection);
	COPY_NODE_FIELD(val);
2512
	COPY_SCALAR_FIELD(location);
2513 2514 2515 2516

	return newnode;
}

2517
static TypeName *
2518
_copyTypeName(TypeName *from)
2519
{
2520
	TypeName   *newnode = makeNode(TypeName);
2521

2522
	COPY_NODE_FIELD(names);
2523
	COPY_SCALAR_FIELD(typid);
2524 2525 2526
	COPY_SCALAR_FIELD(timezone);
	COPY_SCALAR_FIELD(setof);
	COPY_SCALAR_FIELD(pct_type);
2527 2528
	COPY_NODE_FIELD(typmods);
	COPY_SCALAR_FIELD(typemod);
2529
	COPY_NODE_FIELD(arrayBounds);
2530
	COPY_SCALAR_FIELD(location);
2531 2532

	return newnode;
2533 2534
}

2535 2536
static SortBy *
_copySortBy(SortBy *from)
2537
{
B
Bruce Momjian 已提交
2538
	SortBy	   *newnode = makeNode(SortBy);
2539

2540 2541
	COPY_SCALAR_FIELD(sortby_dir);
	COPY_SCALAR_FIELD(sortby_nulls);
2542 2543
	COPY_NODE_FIELD(useOp);
	COPY_NODE_FIELD(node);
2544
	COPY_SCALAR_FIELD(location);
2545 2546 2547 2548 2549 2550 2551

	return newnode;
}

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

2554 2555
	COPY_NODE_FIELD(subquery);
	COPY_NODE_FIELD(alias);
2556 2557 2558 2559

	return newnode;
}

2560 2561 2562
static RangeFunction *
_copyRangeFunction(RangeFunction *from)
{
B
Bruce Momjian 已提交
2563
	RangeFunction *newnode = makeNode(RangeFunction);
2564

2565 2566 2567
	COPY_NODE_FIELD(funccallnode);
	COPY_NODE_FIELD(alias);
	COPY_NODE_FIELD(coldeflist);
2568 2569 2570 2571

	return newnode;
}

2572 2573 2574 2575 2576
static TypeCast *
_copyTypeCast(TypeCast *from)
{
	TypeCast   *newnode = makeNode(TypeCast);

2577
	COPY_NODE_FIELD(arg);
2578
	COPY_NODE_FIELD(typname);
2579 2580 2581 2582

	return newnode;
}

2583 2584 2585
static IndexElem *
_copyIndexElem(IndexElem *from)
{
B
Bruce Momjian 已提交
2586
	IndexElem  *newnode = makeNode(IndexElem);
2587

2588
	COPY_STRING_FIELD(name);
2589
	COPY_NODE_FIELD(expr);
2590
	COPY_NODE_FIELD(opclass);
2591 2592
	COPY_SCALAR_FIELD(ordering);
	COPY_SCALAR_FIELD(nulls_ordering);
2593 2594 2595 2596 2597 2598 2599

	return newnode;
}

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

2602
	COPY_STRING_FIELD(colname);
2603
	COPY_NODE_FIELD(typname);
2604 2605 2606
	COPY_SCALAR_FIELD(inhcount);
	COPY_SCALAR_FIELD(is_local);
	COPY_SCALAR_FIELD(is_not_null);
2607 2608
	COPY_SCALAR_FIELD(attnum);
	COPY_SCALAR_FIELD(default_oid);
2609 2610 2611
	COPY_NODE_FIELD(raw_default);
	COPY_STRING_FIELD(cooked_default);
	COPY_NODE_FIELD(constraints);
2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622
	COPY_NODE_FIELD(encoding);

	return newnode;
}

static ColumnReferenceStorageDirective *
_copyColumnReferenceStorageDirective(ColumnReferenceStorageDirective *from)
{
	ColumnReferenceStorageDirective *newnode =
		makeNode(ColumnReferenceStorageDirective);

2623
	COPY_STRING_FIELD(column);
2624 2625
	COPY_SCALAR_FIELD(deflt);
	COPY_NODE_FIELD(encoding);
2626 2627 2628 2629 2630 2631 2632

	return newnode;
}

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

2635
	COPY_SCALAR_FIELD(contype);
2636
	COPY_SCALAR_FIELD(conoid);
2637 2638 2639 2640
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(raw_expr);
	COPY_STRING_FIELD(cooked_expr);
	COPY_NODE_FIELD(keys);
B
Bruce Momjian 已提交
2641
	COPY_NODE_FIELD(options);
2642
	COPY_STRING_FIELD(indexspace);
2643 2644 2645 2646

	return newnode;
}

2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670
static DefElem *
_copyDefElem(DefElem *from)
{
	DefElem    *newnode = makeNode(DefElem);

	COPY_STRING_FIELD(defname);
	COPY_NODE_FIELD(arg);
	COPY_SCALAR_FIELD(defaction);

	return newnode;
}

static LockingClause *
_copyLockingClause(LockingClause *from)
{
	LockingClause *newnode = makeNode(LockingClause);

	COPY_NODE_FIELD(lockedRels);
	COPY_SCALAR_FIELD(forUpdate);
	COPY_SCALAR_FIELD(noWait);

	return newnode;
}

2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683
static XmlSerialize *
_copyXmlSerialize(XmlSerialize *from)
{
	XmlSerialize *newnode = makeNode(XmlSerialize);

	COPY_SCALAR_FIELD(xmloption);
	COPY_NODE_FIELD(expr);
	COPY_NODE_FIELD(typeName);
	COPY_LOCATION_FIELD(location);

	return newnode;
}

2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722
static DMLActionExpr *
_copyDMLActionExpr(const DMLActionExpr *from)
{
	DMLActionExpr *newnode = makeNode(DMLActionExpr);

	return newnode;
}

static PartOidExpr *
_copyPartOidExpr(const PartOidExpr *from)
{
	PartOidExpr *newnode = makeNode(PartOidExpr);
	COPY_SCALAR_FIELD(level);

	return newnode;
}

static PartDefaultExpr *
_copyPartDefaultExpr(const PartDefaultExpr *from)
{
	PartDefaultExpr *newnode = makeNode(PartDefaultExpr);
	COPY_SCALAR_FIELD(level);

	return newnode;
}

static PartBoundExpr *
_copyPartBoundExpr(const PartBoundExpr *from)
{
	PartBoundExpr *newnode = makeNode(PartBoundExpr);
	COPY_SCALAR_FIELD(level);
	COPY_SCALAR_FIELD(boundType);
	COPY_SCALAR_FIELD(isLowerBound);

	return newnode;
}

static PartBoundInclusionExpr *
_copyPartBoundInclusionExpr(const PartBoundInclusionExpr *from)
2723
{
2724 2725 2726
	PartBoundInclusionExpr *newnode = makeNode(PartBoundInclusionExpr);
	COPY_SCALAR_FIELD(level);
	COPY_SCALAR_FIELD(isLowerBound);
2727 2728 2729 2730

	return newnode;
}

2731 2732
static PartBoundOpenExpr *
_copyPartBoundOpenExpr(const PartBoundOpenExpr *from)
2733
{
2734 2735 2736
	PartBoundOpenExpr *newnode = makeNode(PartBoundOpenExpr);
	COPY_SCALAR_FIELD(level);
	COPY_SCALAR_FIELD(isLowerBound);
2737 2738 2739 2740

	return newnode;
}

2741 2742 2743 2744 2745 2746 2747
static Query *
_copyQuery(Query *from)
{
	Query	   *newnode = makeNode(Query);

	COPY_SCALAR_FIELD(commandType);
	COPY_SCALAR_FIELD(querySource);
2748
	COPY_SCALAR_FIELD(canSetTag);
2749 2750
	COPY_NODE_FIELD(utilityStmt);
	COPY_SCALAR_FIELD(resultRelation);
2751
	COPY_NODE_FIELD(intoClause);
2752
	COPY_SCALAR_FIELD(hasAggs);
2753
	COPY_SCALAR_FIELD(hasWindFuncs);
2754 2755 2756 2757
	COPY_SCALAR_FIELD(hasSubLinks);
	COPY_NODE_FIELD(rtable);
	COPY_NODE_FIELD(jointree);
	COPY_NODE_FIELD(targetList);
2758
	COPY_NODE_FIELD(returningList);
2759 2760
	COPY_NODE_FIELD(groupClause);
	COPY_NODE_FIELD(havingQual);
2761
	COPY_NODE_FIELD(windowClause);
2762 2763
	COPY_NODE_FIELD(distinctClause);
	COPY_NODE_FIELD(sortClause);
2764 2765 2766 2767
	COPY_NODE_FIELD(scatterClause);
	COPY_NODE_FIELD(cteList);
	COPY_SCALAR_FIELD(hasRecursive);
	COPY_SCALAR_FIELD(hasModifyingCTE);
2768 2769
	COPY_NODE_FIELD(limitOffset);
	COPY_NODE_FIELD(limitCount);
2770
	COPY_NODE_FIELD(rowMarks);
2771
	COPY_NODE_FIELD(setOperations);
2772
	COPY_NODE_FIELD(resultRelations);
2773
	COPY_NODE_FIELD(returningLists);
2774 2775 2776 2777 2778 2779
	if (from->intoPolicy)
	{
		COPY_POINTER_FIELD(intoPolicy,sizeof(GpPolicy) + from->intoPolicy->nattrs*sizeof(from->intoPolicy->attrs[0]));
	}
	else
		newnode->intoPolicy = NULL;
2780

2781
	return newnode;
2782 2783
}

2784 2785 2786 2787
static InsertStmt *
_copyInsertStmt(InsertStmt *from)
{
	InsertStmt *newnode = makeNode(InsertStmt);
B
Bruce Momjian 已提交
2788

2789 2790 2791
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(cols);
	COPY_NODE_FIELD(selectStmt);
2792
	COPY_NODE_FIELD(returningList);
2793 2794 2795 2796 2797 2798 2799 2800

	return newnode;
}

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

2802
	COPY_NODE_FIELD(relation);
2803
	COPY_NODE_FIELD(usingClause);
2804 2805
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(returningList);
2806 2807 2808 2809 2810 2811 2812 2813

	return newnode;
}

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

2815 2816 2817 2818
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(targetList);
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(fromClause);
2819
	COPY_NODE_FIELD(returningList);
2820 2821 2822 2823 2824 2825 2826 2827

	return newnode;
}

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

2829
	COPY_NODE_FIELD(distinctClause);
2830
	COPY_NODE_FIELD(intoClause);
2831 2832 2833 2834 2835
	COPY_NODE_FIELD(targetList);
	COPY_NODE_FIELD(fromClause);
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(groupClause);
	COPY_NODE_FIELD(havingClause);
2836
	COPY_NODE_FIELD(windowClause);
2837
	COPY_NODE_FIELD(valuesLists);
2838
	COPY_NODE_FIELD(sortClause);
2839 2840
	COPY_NODE_FIELD(scatterClause);
	COPY_NODE_FIELD(withClause);
2841 2842
	COPY_NODE_FIELD(limitOffset);
	COPY_NODE_FIELD(limitCount);
2843
	COPY_NODE_FIELD(lockingClause);
2844 2845 2846 2847
	COPY_SCALAR_FIELD(op);
	COPY_SCALAR_FIELD(all);
	COPY_NODE_FIELD(larg);
	COPY_NODE_FIELD(rarg);
2848
	COPY_NODE_FIELD(distributedBy);
2849 2850 2851 2852

	return newnode;
}

2853 2854 2855 2856
static SetOperationStmt *
_copySetOperationStmt(SetOperationStmt *from)
{
	SetOperationStmt *newnode = makeNode(SetOperationStmt);
B
Bruce Momjian 已提交
2857

2858 2859 2860 2861
	COPY_SCALAR_FIELD(op);
	COPY_SCALAR_FIELD(all);
	COPY_NODE_FIELD(larg);
	COPY_NODE_FIELD(rarg);
2862
	COPY_NODE_FIELD(colTypes);
2863
	COPY_NODE_FIELD(colTypmods);
2864 2865 2866
	return newnode;
}

2867 2868 2869 2870
static AlterTableStmt *
_copyAlterTableStmt(AlterTableStmt *from)
{
	AlterTableStmt *newnode = makeNode(AlterTableStmt);
B
Bruce Momjian 已提交
2871

2872
	COPY_NODE_FIELD(relation);
T
Tom Lane 已提交
2873
	COPY_NODE_FIELD(cmds);
T
Tom Lane 已提交
2874
	COPY_SCALAR_FIELD(relkind);
2875 2876
	
	/* No need to copy AT workspace fields. */
T
Tom Lane 已提交
2877 2878 2879 2880 2881 2882 2883 2884 2885 2886

	return newnode;
}

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

	COPY_SCALAR_FIELD(subtype);
2887
	COPY_STRING_FIELD(name);
2888
	COPY_NODE_FIELD(def);
T
Tom Lane 已提交
2889
	COPY_NODE_FIELD(transform);
2890
	COPY_SCALAR_FIELD(behavior);
2891 2892 2893 2894 2895 2896 2897 2898
	COPY_SCALAR_FIELD(part_expanded);
	
	/* Need to copy AT workspace since process uses copy internally. */
	COPY_NODE_FIELD(partoids);

	return newnode;
}

2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911
static SetDistributionCmd*
_copySetDistributionCmd(SetDistributionCmd *from)
{
	SetDistributionCmd *newnode = makeNode(SetDistributionCmd);

	COPY_SCALAR_FIELD(backendId);
	COPY_NODE_FIELD(relids);
	COPY_NODE_FIELD(indexOidMap);
	COPY_NODE_FIELD(hiddenTypes);

	return newnode;
}

2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929
static InheritPartitionCmd *
_copyInheritPartitionCmd(InheritPartitionCmd *from)
{
	InheritPartitionCmd *newnode = makeNode(InheritPartitionCmd);

	COPY_NODE_FIELD(parent);

	return newnode;
}

static AlterPartitionCmd *
_copyAlterPartitionCmd(AlterPartitionCmd *from)
{
	AlterPartitionCmd *newnode = makeNode(AlterPartitionCmd);

	COPY_NODE_FIELD(partid);
	COPY_NODE_FIELD(arg1);
	COPY_NODE_FIELD(arg2);
2930 2931 2932 2933

	return newnode;
}

2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945
static AlterPartitionId *
_copyAlterPartitionId(AlterPartitionId *from)
{
	AlterPartitionId *newnode = makeNode(AlterPartitionId);

	COPY_SCALAR_FIELD(idtype);
	COPY_NODE_FIELD(partiddef);

	return newnode;
}


B
Bruce Momjian 已提交
2946
static AlterDomainStmt *
2947
_copyAlterDomainStmt(AlterDomainStmt *from)
B
Bruce Momjian 已提交
2948 2949 2950 2951
{
	AlterDomainStmt *newnode = makeNode(AlterDomainStmt);

	COPY_SCALAR_FIELD(subtype);
2952
	COPY_NODE_FIELD(typname);
B
Bruce Momjian 已提交
2953 2954 2955 2956 2957
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(def);
	COPY_SCALAR_FIELD(behavior);

	return newnode;
B
Bruce Momjian 已提交
2958
}
B
Bruce Momjian 已提交
2959

2960 2961
static GrantStmt *
_copyGrantStmt(GrantStmt *from)
2962
{
2963
	GrantStmt  *newnode = makeNode(GrantStmt);
B
Bruce Momjian 已提交
2964

2965 2966 2967
	COPY_SCALAR_FIELD(is_grant);
	COPY_SCALAR_FIELD(objtype);
	COPY_NODE_FIELD(objects);
2968
	COPY_NODE_FIELD(privileges);
2969
	COPY_NODE_FIELD(grantees);
2970 2971
	COPY_SCALAR_FIELD(grant_option);
	COPY_SCALAR_FIELD(behavior);
2972
	COPY_NODE_FIELD(cooked_privs);
2973 2974 2975 2976 2977 2978 2979 2980 2981

	return newnode;
}

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

2982
	COPY_STRING_FIELD(rolname);
2983 2984 2985 2986

	return newnode;
}

2987 2988 2989 2990 2991
static FuncWithArgs *
_copyFuncWithArgs(FuncWithArgs *from)
{
	FuncWithArgs *newnode = makeNode(FuncWithArgs);

2992 2993
	COPY_NODE_FIELD(funcname);
	COPY_NODE_FIELD(funcargs);
2994 2995 2996 2997

	return newnode;
}

2998 2999 3000
static GrantRoleStmt *
_copyGrantRoleStmt(GrantRoleStmt *from)
{
B
Bruce Momjian 已提交
3001
	GrantRoleStmt *newnode = makeNode(GrantRoleStmt);
3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012

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

3013
static DeclareCursorStmt *
3014
_copyDeclareCursorStmt(DeclareCursorStmt *from)
3015 3016 3017 3018 3019 3020
{
	DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);

	COPY_STRING_FIELD(portalname);
	COPY_SCALAR_FIELD(options);
	COPY_NODE_FIELD(query);
3021
	COPY_SCALAR_FIELD(is_simply_updatable);
3022 3023 3024

	return newnode;
}
B
Bruce Momjian 已提交
3025

3026 3027 3028
static ClosePortalStmt *
_copyClosePortalStmt(ClosePortalStmt *from)
{
3029
	ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
3030

3031
	COPY_STRING_FIELD(portalname);
3032 3033 3034 3035

	return newnode;
}

3036 3037 3038 3039
static ClusterStmt *
_copyClusterStmt(ClusterStmt *from)
{
	ClusterStmt *newnode = makeNode(ClusterStmt);
B
Bruce Momjian 已提交
3040

3041 3042
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(indexname);
3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060
	COPY_SCALAR_FIELD(oidInfo.relOid);
	COPY_SCALAR_FIELD(oidInfo.comptypeOid);
	COPY_SCALAR_FIELD(oidInfo.toastOid);
	COPY_SCALAR_FIELD(oidInfo.toastIndexOid);
	COPY_SCALAR_FIELD(oidInfo.toastComptypeOid);
	COPY_NODE_FIELD(new_ind_oids);

	return newnode;
}

static SingleRowErrorDesc *
_copySingleRowErrorDesc(SingleRowErrorDesc *from)
{
	SingleRowErrorDesc *newnode = makeNode(SingleRowErrorDesc);

	COPY_SCALAR_FIELD(rejectlimit);
	COPY_SCALAR_FIELD(is_limit_in_rows);
	COPY_SCALAR_FIELD(into_file);
3061 3062 3063 3064 3065 3066 3067

	return newnode;
}

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

3070
	COPY_NODE_FIELD(relation);
3071
	COPY_NODE_FIELD(query);
3072 3073
	COPY_NODE_FIELD(attlist);
	COPY_SCALAR_FIELD(is_from);
3074
	COPY_SCALAR_FIELD(skip_ext_partition);
3075 3076
	COPY_STRING_FIELD(filename);
	COPY_NODE_FIELD(options);
3077
	COPY_NODE_FIELD(sreh);
3078 3079 3080 3081 3082 3083 3084 3085

	return newnode;
}

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

3087 3088 3089
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(tableElts);
	COPY_NODE_FIELD(inhRelations);
3090 3091
	COPY_NODE_FIELD(inhOids);
	COPY_SCALAR_FIELD(parentOidCount);
3092
	COPY_NODE_FIELD(constraints);
B
Bruce Momjian 已提交
3093
	COPY_NODE_FIELD(options);
3094
	COPY_SCALAR_FIELD(oncommit);
3095
	COPY_STRING_FIELD(tablespacename);
3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169
	COPY_NODE_FIELD(distributedBy);
	COPY_SCALAR_FIELD(oidInfo.relOid);
	COPY_SCALAR_FIELD(oidInfo.comptypeOid);
	COPY_SCALAR_FIELD(oidInfo.toastOid);
	COPY_SCALAR_FIELD(oidInfo.toastIndexOid);
	COPY_SCALAR_FIELD(oidInfo.toastComptypeOid);
	COPY_SCALAR_FIELD(relKind);
	COPY_SCALAR_FIELD(relStorage);
	if (from->policy)
	{
		COPY_POINTER_FIELD(policy,sizeof(GpPolicy) + from->policy->nattrs*sizeof(from->policy->attrs[0]));
	}
	else
		newnode->policy = NULL;
	/* postCreate omitted (why?) */
	COPY_NODE_FIELD(deferredStmts);
	COPY_SCALAR_FIELD(is_part_child);
	COPY_SCALAR_FIELD(is_add_part);
	COPY_SCALAR_FIELD(ownerid);
	COPY_SCALAR_FIELD(buildAoBlkdir);
	COPY_NODE_FIELD(attr_encodings);

	return newnode;
}

static PartitionBy *
_copyPartitionBy(PartitionBy *from)
{
	PartitionBy *newnode = makeNode(PartitionBy);

	COPY_SCALAR_FIELD(partType);
	COPY_NODE_FIELD(keys);
	COPY_NODE_FIELD(keyopclass);
	COPY_NODE_FIELD(partNum);
	COPY_NODE_FIELD(subPart);
	COPY_NODE_FIELD(partSpec);
	COPY_SCALAR_FIELD(partDepth);
	COPY_NODE_FIELD(parentRel);
	COPY_SCALAR_FIELD(partQuiet);
	COPY_SCALAR_FIELD(location);

	return newnode;
}

static PartitionSpec *
_copyPartitionSpec(PartitionSpec *from)
{
	PartitionSpec *newnode = makeNode(PartitionSpec);

	COPY_NODE_FIELD(partElem);
	COPY_NODE_FIELD(subSpec);
	COPY_SCALAR_FIELD(istemplate);
	COPY_NODE_FIELD(enc_clauses);
	COPY_SCALAR_FIELD(location);

	return newnode;
}

static PartitionValuesSpec *
_copyPartitionValuesSpec(PartitionValuesSpec *from)
{
	PartitionValuesSpec *newnode = makeNode(PartitionValuesSpec);

	COPY_NODE_FIELD(partValues);
	COPY_SCALAR_FIELD(location);

	return newnode;
}

static PartitionElem *
_copyPartitionElem(PartitionElem *from)
{
	PartitionElem *newnode = makeNode(PartitionElem);

3170
	COPY_STRING_FIELD(partName);
3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314
	COPY_NODE_FIELD(boundSpec);
	COPY_NODE_FIELD(subSpec);
	COPY_SCALAR_FIELD(isDefault);
	COPY_NODE_FIELD(storeAttr);
	COPY_SCALAR_FIELD(partno);
	COPY_SCALAR_FIELD(rrand);
	COPY_NODE_FIELD(colencs);
	COPY_SCALAR_FIELD(location);

	return newnode;
}

static PartitionRangeItem *
_copyPartitionRangeItem(PartitionRangeItem *from)
{
	PartitionRangeItem *newnode = makeNode(PartitionRangeItem);

	COPY_NODE_FIELD(partRangeVal);
	COPY_SCALAR_FIELD(partedge);
	COPY_SCALAR_FIELD(location);

	return newnode;
}

static PartitionBoundSpec *
_copyPartitionBoundSpec(PartitionBoundSpec *from)
{
	PartitionBoundSpec *newnode = makeNode(PartitionBoundSpec);

	COPY_NODE_FIELD(partStart);
	COPY_NODE_FIELD(partEnd);
	COPY_NODE_FIELD(partEvery);
	COPY_SCALAR_FIELD(location);

	return newnode;
}

static PgPartRule *
_copyPgPartRule(PgPartRule *from)
{
	PgPartRule *newnode = makeNode(PgPartRule);

	COPY_NODE_FIELD(pNode);
	COPY_NODE_FIELD(topRule);
	COPY_STRING_FIELD(partIdStr);
	COPY_SCALAR_FIELD(isName);
	COPY_SCALAR_FIELD(topRuleRank);
	COPY_STRING_FIELD(relname);

	return newnode;
}

static Partition *
_copyPartition(Partition *from)
{
	Partition *newnode = makeNode(Partition);

	COPY_SCALAR_FIELD(partid);
	COPY_SCALAR_FIELD(parrelid);
	COPY_SCALAR_FIELD(parkind);
	COPY_SCALAR_FIELD(parlevel);
	COPY_SCALAR_FIELD(paristemplate);
	COPY_SCALAR_FIELD(parnatts);
	COPY_POINTER_FIELD(paratts, from->parnatts * sizeof(AttrNumber));
	COPY_POINTER_FIELD(parclass, from->parnatts * sizeof(Oid));

	return newnode;
}

static PartitionRule *
_copyPartitionRule(PartitionRule *from)
{
	PartitionRule *newnode = makeNode(PartitionRule);

	COPY_SCALAR_FIELD(parruleid);
	COPY_SCALAR_FIELD(paroid);
	COPY_SCALAR_FIELD(parchildrelid);
	COPY_SCALAR_FIELD(parparentoid);
	COPY_SCALAR_FIELD(parisdefault);
	COPY_STRING_FIELD(parname);
	COPY_NODE_FIELD(parrangestart);
	COPY_SCALAR_FIELD(parrangestartincl);
	COPY_NODE_FIELD(parrangeend);
	COPY_SCALAR_FIELD(parrangeendincl);
	COPY_NODE_FIELD(parrangeevery);
	COPY_NODE_FIELD(parlistvalues);
	COPY_SCALAR_FIELD(parruleord);
	COPY_NODE_FIELD(parreloptions);
	COPY_SCALAR_FIELD(partemplatespaceId);
	COPY_NODE_FIELD(children); /* sub partition */

	return newnode;
}

static PartitionNode *
_copyPartitionNode(PartitionNode *from)
{
	PartitionNode *newnode = makeNode(PartitionNode);

	COPY_NODE_FIELD(part);
	COPY_NODE_FIELD(default_part);
	COPY_NODE_FIELD(rules);

	return newnode;
}

static ExtTableTypeDesc *
_copyExtTableTypeDesc(ExtTableTypeDesc *from)
{
	ExtTableTypeDesc *newnode = makeNode(ExtTableTypeDesc);

	COPY_SCALAR_FIELD(exttabletype);
	COPY_NODE_FIELD(location_list);
	COPY_NODE_FIELD(on_clause);
	COPY_STRING_FIELD(command_string);

	return newnode;
}

static CreateExternalStmt *
_copyCreateExternalStmt(CreateExternalStmt *from)
{
	CreateExternalStmt *newnode = makeNode(CreateExternalStmt);

	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(tableElts);
	COPY_NODE_FIELD(exttypedesc);
	COPY_STRING_FIELD(format);
	COPY_NODE_FIELD(formatOpts);
	COPY_SCALAR_FIELD(isweb);
	COPY_SCALAR_FIELD(iswritable);
	COPY_NODE_FIELD(sreh);
	COPY_NODE_FIELD(encoding);
	COPY_NODE_FIELD(distributedBy);	
	if (from->policy)
	{
		COPY_POINTER_FIELD(policy,sizeof(GpPolicy) + from->policy->nattrs*sizeof(from->policy->attrs[0]));
	}
	else
		newnode->policy = NULL;

	return newnode;
}

B
Bruce Momjian 已提交
3315
static InhRelation *
3316
_copyInhRelation(InhRelation *from)
B
Bruce Momjian 已提交
3317 3318 3319 3320
{
	InhRelation *newnode = makeNode(InhRelation);

	COPY_NODE_FIELD(relation);
3321
	COPY_NODE_FIELD(options);
B
Bruce Momjian 已提交
3322 3323 3324 3325

	return newnode;
}

3326 3327 3328 3329
static DefineStmt *
_copyDefineStmt(DefineStmt *from)
{
	DefineStmt *newnode = makeNode(DefineStmt);
B
Bruce Momjian 已提交
3330

3331
	COPY_SCALAR_FIELD(kind);
T
Tom Lane 已提交
3332
	COPY_SCALAR_FIELD(oldstyle);
3333
	COPY_NODE_FIELD(defnames);
T
Tom Lane 已提交
3334
	COPY_NODE_FIELD(args);
3335
	COPY_NODE_FIELD(definition);
3336 3337
	COPY_SCALAR_FIELD(ordered);  /* CDB */
	COPY_SCALAR_FIELD(trusted);  /* CDB */
3338 3339 3340 3341
	COPY_SCALAR_FIELD(newOid);
	COPY_SCALAR_FIELD(arrayOid);
	COPY_SCALAR_FIELD(commutatorOid);
	COPY_SCALAR_FIELD(negatorOid);
3342 3343 3344 3345 3346 3347 3348

	return newnode;
}

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

3351
	COPY_SCALAR_FIELD(removeType);
3352
	COPY_NODE_FIELD(objects);
3353
	COPY_SCALAR_FIELD(behavior);
T
Tom Lane 已提交
3354
	COPY_SCALAR_FIELD(missing_ok);
3355
	COPY_SCALAR_FIELD(bAllowPartn);
3356 3357 3358 3359

	return newnode;
}

3360 3361 3362
static TruncateStmt *
_copyTruncateStmt(TruncateStmt *from)
{
3363
	TruncateStmt *newnode = makeNode(TruncateStmt);
3364

3365
	COPY_NODE_FIELD(relations);
3366
	COPY_SCALAR_FIELD(behavior);
3367 3368 3369 3370

	return newnode;
}

3371 3372 3373 3374
static CommentStmt *
_copyCommentStmt(CommentStmt *from)
{
	CommentStmt *newnode = makeNode(CommentStmt);
B
Bruce Momjian 已提交
3375

3376 3377 3378 3379
	COPY_SCALAR_FIELD(objtype);
	COPY_NODE_FIELD(objname);
	COPY_NODE_FIELD(objargs);
	COPY_STRING_FIELD(comment);
3380 3381 3382 3383 3384 3385 3386

	return newnode;
}

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

3389 3390 3391 3392
	COPY_SCALAR_FIELD(direction);
	COPY_SCALAR_FIELD(howMany);
	COPY_STRING_FIELD(portalname);
	COPY_SCALAR_FIELD(ismove);
3393 3394 3395 3396 3397 3398 3399

	return newnode;
}

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

3402 3403 3404
	COPY_STRING_FIELD(idxname);
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(accessMethod);
3405
	COPY_STRING_FIELD(tableSpace);
3406
	COPY_NODE_FIELD(indexParams);
B
Bruce Momjian 已提交
3407
	COPY_NODE_FIELD(options);
3408 3409
	COPY_NODE_FIELD(whereClause);
	COPY_NODE_FIELD(rangetable);
3410
	COPY_SCALAR_FIELD(is_part_child);
3411 3412 3413
	COPY_SCALAR_FIELD(unique);
	COPY_SCALAR_FIELD(primary);
	COPY_SCALAR_FIELD(isconstraint);
3414 3415
	COPY_STRING_FIELD(altconname);
	COPY_SCALAR_FIELD(constrOid);
3416
	COPY_SCALAR_FIELD(concurrent);
3417 3418
	COPY_NODE_FIELD(idxOids);
	COPY_SCALAR_FIELD(do_part);
3419 3420 3421 3422

	return newnode;
}

3423 3424
static CreateFunctionStmt *
_copyCreateFunctionStmt(CreateFunctionStmt *from)
3425
{
3426
	CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
B
Bruce Momjian 已提交
3427

3428 3429
	COPY_SCALAR_FIELD(replace);
	COPY_NODE_FIELD(funcname);
3430
	COPY_NODE_FIELD(parameters);
3431 3432 3433
	COPY_NODE_FIELD(returnType);
	COPY_NODE_FIELD(options);
	COPY_NODE_FIELD(withClause);
3434 3435
	COPY_SCALAR_FIELD(funcOid);
	COPY_SCALAR_FIELD(shelltypeOid);
3436 3437 3438 3439

	return newnode;
}

3440 3441 3442 3443 3444 3445 3446
static FunctionParameter *
_copyFunctionParameter(FunctionParameter *from)
{
	FunctionParameter *newnode = makeNode(FunctionParameter);

	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(argType);
3447
	COPY_SCALAR_FIELD(mode);
3448
	COPY_NODE_FIELD(defexpr);
3449 3450 3451 3452

	return newnode;
}

3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463
static AlterFunctionStmt *
_copyAlterFunctionStmt(AlterFunctionStmt *from)
{
	AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);

	COPY_NODE_FIELD(func);
	COPY_NODE_FIELD(actions);

	return newnode;
}

3464 3465 3466 3467
static RemoveFuncStmt *
_copyRemoveFuncStmt(RemoveFuncStmt *from)
{
	RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
B
Bruce Momjian 已提交
3468

T
Tom Lane 已提交
3469 3470
	COPY_SCALAR_FIELD(kind);
	COPY_NODE_FIELD(name);
3471 3472
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(behavior);
A
 
Andrew Dunstan 已提交
3473
	COPY_SCALAR_FIELD(missing_ok);
3474 3475 3476 3477

	return newnode;
}

3478 3479 3480 3481 3482 3483 3484 3485 3486 3487
static DoStmt *
_copyDoStmt(DoStmt *from)
{
	DoStmt	   *newnode = makeNode(DoStmt);

	COPY_NODE_FIELD(args);

	return newnode;
}

3488 3489 3490 3491 3492
static RemoveOpClassStmt *
_copyRemoveOpClassStmt(RemoveOpClassStmt *from)
{
	RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);

3493 3494 3495
	COPY_NODE_FIELD(opclassname);
	COPY_STRING_FIELD(amname);
	COPY_SCALAR_FIELD(behavior);
A
 
Andrew Dunstan 已提交
3496
	COPY_SCALAR_FIELD(missing_ok);
3497 3498 3499 3500

	return newnode;
}

3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513
static RemoveOpFamilyStmt *
_copyRemoveOpFamilyStmt(RemoveOpFamilyStmt *from)
{
	RemoveOpFamilyStmt *newnode = makeNode(RemoveOpFamilyStmt);

	COPY_NODE_FIELD(opfamilyname);
	COPY_STRING_FIELD(amname);
	COPY_SCALAR_FIELD(behavior);
	COPY_SCALAR_FIELD(missing_ok);

	return newnode;
}

3514 3515 3516 3517
static RenameStmt *
_copyRenameStmt(RenameStmt *from)
{
	RenameStmt *newnode = makeNode(RenameStmt);
B
Bruce Momjian 已提交
3518

3519
	COPY_SCALAR_FIELD(renameType);
3520
	COPY_NODE_FIELD(relation);
3521
	COPY_SCALAR_FIELD(objid);
3522 3523 3524
	COPY_NODE_FIELD(object);
	COPY_NODE_FIELD(objarg);
	COPY_STRING_FIELD(subname);
3525
	COPY_STRING_FIELD(newname);
3526
	COPY_SCALAR_FIELD(bAllowPartn);
3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541

	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);
3542 3543 3544 3545

	return newnode;
}

3546 3547 3548 3549 3550
static AlterOwnerStmt *
_copyAlterOwnerStmt(AlterOwnerStmt *from)
{
	AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);

3551
	COPY_SCALAR_FIELD(objectType);
3552 3553 3554 3555 3556 3557 3558 3559 3560
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(object);
	COPY_NODE_FIELD(objarg);
	COPY_STRING_FIELD(addname);
	COPY_STRING_FIELD(newowner);

	return newnode;
}

3561 3562 3563
static RuleStmt *
_copyRuleStmt(RuleStmt *from)
{
B
Bruce Momjian 已提交
3564 3565
	RuleStmt   *newnode = makeNode(RuleStmt);

3566 3567 3568 3569 3570 3571 3572
	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);
3573
	COPY_SCALAR_FIELD(ruleOid);
3574 3575 3576 3577

	return newnode;
}

3578 3579 3580
static NotifyStmt *
_copyNotifyStmt(NotifyStmt *from)
{
3581
	NotifyStmt *newnode = makeNode(NotifyStmt);
3582

3583
	COPY_NODE_FIELD(relation);
3584 3585 3586 3587 3588 3589 3590

	return newnode;
}

static ListenStmt *
_copyListenStmt(ListenStmt *from)
{
3591
	ListenStmt *newnode = makeNode(ListenStmt);
3592

3593
	COPY_NODE_FIELD(relation);
3594 3595 3596 3597 3598 3599 3600

	return newnode;
}

static UnlistenStmt *
_copyUnlistenStmt(UnlistenStmt *from)
{
3601
	UnlistenStmt *newnode = makeNode(UnlistenStmt);
3602

3603
	COPY_NODE_FIELD(relation);
3604 3605 3606 3607 3608 3609 3610

	return newnode;
}

static TransactionStmt *
_copyTransactionStmt(TransactionStmt *from)
{
3611
	TransactionStmt *newnode = makeNode(TransactionStmt);
3612

3613
	COPY_SCALAR_FIELD(kind);
3614
	COPY_NODE_FIELD(options);
3615
	COPY_STRING_FIELD(gid);
3616 3617 3618 3619

	return newnode;
}

B
Bruce Momjian 已提交
3620 3621 3622
static CompositeTypeStmt *
_copyCompositeTypeStmt(CompositeTypeStmt *from)
{
B
Bruce Momjian 已提交
3623
	CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
B
Bruce Momjian 已提交
3624

3625 3626
	COPY_NODE_FIELD(typevar);
	COPY_NODE_FIELD(coldeflist);
3627 3628
	COPY_SCALAR_FIELD(relOid);
	COPY_SCALAR_FIELD(comptypeOid);
B
Bruce Momjian 已提交
3629 3630 3631 3632

	return newnode;
}

3633 3634 3635 3636 3637
static ViewStmt *
_copyViewStmt(ViewStmt *from)
{
	ViewStmt   *newnode = makeNode(ViewStmt);

3638 3639 3640 3641
	COPY_NODE_FIELD(view);
	COPY_NODE_FIELD(aliases);
	COPY_NODE_FIELD(query);
	COPY_SCALAR_FIELD(replace);
3642 3643 3644
	COPY_SCALAR_FIELD(relOid);
	COPY_SCALAR_FIELD(comptypeOid);
	COPY_SCALAR_FIELD(rewriteOid);
3645 3646 3647 3648

	return newnode;
}

3649 3650 3651
static LoadStmt *
_copyLoadStmt(LoadStmt *from)
{
3652
	LoadStmt   *newnode = makeNode(LoadStmt);
3653

3654
	COPY_STRING_FIELD(filename);
3655 3656 3657 3658

	return newnode;
}

3659 3660 3661 3662 3663
static CreateDomainStmt *
_copyCreateDomainStmt(CreateDomainStmt *from)
{
	CreateDomainStmt *newnode = makeNode(CreateDomainStmt);

3664
	COPY_NODE_FIELD(domainname);
3665
	COPY_NODE_FIELD(typname);
3666
	COPY_NODE_FIELD(constraints);
3667
	COPY_SCALAR_FIELD(domainOid);
3668 3669 3670 3671

	return newnode;
}

3672 3673 3674 3675 3676
static CreateOpClassStmt *
_copyCreateOpClassStmt(CreateOpClassStmt *from)
{
	CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);

3677
	COPY_NODE_FIELD(opclassname);
3678
	COPY_NODE_FIELD(opfamilyname);
3679 3680 3681 3682
	COPY_STRING_FIELD(amname);
	COPY_NODE_FIELD(datatype);
	COPY_NODE_FIELD(items);
	COPY_SCALAR_FIELD(isDefault);
3683

3684 3685 3686
	COPY_SCALAR_FIELD(opclassOid);
	COPY_SCALAR_FIELD(opfamilyOid);

3687 3688 3689 3690 3691 3692 3693 3694
	return newnode;
}

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

3695 3696 3697 3698 3699
	COPY_SCALAR_FIELD(itemtype);
	COPY_NODE_FIELD(name);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(number);
	COPY_SCALAR_FIELD(recheck);
3700
	COPY_NODE_FIELD(class_args);
3701
	COPY_NODE_FIELD(storedtype);
3702 3703 3704 3705

	return newnode;
}

3706 3707 3708 3709 3710 3711 3712
static CreateOpFamilyStmt *
_copyCreateOpFamilyStmt(CreateOpFamilyStmt *from)
{
	CreateOpFamilyStmt *newnode = makeNode(CreateOpFamilyStmt);

	COPY_NODE_FIELD(opfamilyname);
	COPY_STRING_FIELD(amname);
3713
	COPY_SCALAR_FIELD(newOid);
3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730

	return newnode;
}

static AlterOpFamilyStmt *
_copyAlterOpFamilyStmt(AlterOpFamilyStmt *from)
{
	AlterOpFamilyStmt *newnode = makeNode(AlterOpFamilyStmt);

	COPY_NODE_FIELD(opfamilyname);
	COPY_STRING_FIELD(amname);
	COPY_SCALAR_FIELD(isDrop);
	COPY_NODE_FIELD(items);

	return newnode;
}

3731 3732 3733
static CreatedbStmt *
_copyCreatedbStmt(CreatedbStmt *from)
{
B
Bruce Momjian 已提交
3734
	CreatedbStmt *newnode = makeNode(CreatedbStmt);
3735

3736 3737
	COPY_STRING_FIELD(dbname);
	COPY_NODE_FIELD(options);
3738
	COPY_SCALAR_FIELD(dbOid);
3739 3740 3741 3742

	return newnode;
}

3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753
static AlterDatabaseStmt *
_copyAlterDatabaseStmt(AlterDatabaseStmt *from)
{
	AlterDatabaseStmt *newnode = makeNode(AlterDatabaseStmt);

	COPY_STRING_FIELD(dbname);
	COPY_NODE_FIELD(options);

	return newnode;
}

3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789
static AlterDatabaseSetStmt *
_copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
{
	AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);

	COPY_STRING_FIELD(dbname);
	COPY_STRING_FIELD(variable);
	COPY_NODE_FIELD(value);

	return newnode;
}

static DropdbStmt *
_copyDropdbStmt(DropdbStmt *from)
{
	DropdbStmt *newnode = makeNode(DropdbStmt);

	COPY_STRING_FIELD(dbname);
	COPY_SCALAR_FIELD(missing_ok);

	return newnode;
}

static VacuumStmt *
_copyVacuumStmt(VacuumStmt *from)
{
	VacuumStmt *newnode = makeNode(VacuumStmt);

	COPY_SCALAR_FIELD(vacuum);
	COPY_SCALAR_FIELD(full);
	COPY_SCALAR_FIELD(analyze);
	COPY_SCALAR_FIELD(verbose);
	COPY_SCALAR_FIELD(rootonly);
	COPY_SCALAR_FIELD(freeze_min_age);
	COPY_NODE_FIELD(relation);
	COPY_NODE_FIELD(va_cols);
3790

3791 3792
	COPY_NODE_FIELD(expanded_relids);
	COPY_NODE_FIELD(extra_oids);
3793 3794 3795 3796 3797 3798
	COPY_NODE_FIELD(appendonly_compaction_segno);
	COPY_NODE_FIELD(appendonly_compaction_insert_segno);
	COPY_SCALAR_FIELD(appendonly_compaction_vacuum_cleanup);
	COPY_SCALAR_FIELD(appendonly_compaction_vacuum_prepare);
	COPY_SCALAR_FIELD(appendonly_relation_empty);
	COPY_SCALAR_FIELD(heap_truncate);
3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885

	return newnode;
}

static ExplainStmt *
_copyExplainStmt(ExplainStmt *from)
{
	ExplainStmt *newnode = makeNode(ExplainStmt);

	COPY_NODE_FIELD(query);
	COPY_SCALAR_FIELD(verbose);
	COPY_SCALAR_FIELD(analyze);

	return newnode;
}

static CreateSeqStmt *
_copyCreateSeqStmt(CreateSeqStmt *from)
{
	CreateSeqStmt *newnode = makeNode(CreateSeqStmt);

	COPY_NODE_FIELD(sequence);
	COPY_NODE_FIELD(options);
	COPY_SCALAR_FIELD(relOid);
	COPY_SCALAR_FIELD(comptypeOid);

	return newnode;
}

static AlterSeqStmt *
_copyAlterSeqStmt(AlterSeqStmt *from)
{
	AlterSeqStmt *newnode = makeNode(AlterSeqStmt);

	COPY_NODE_FIELD(sequence);
	COPY_NODE_FIELD(options);

	return newnode;
}

static VariableSetStmt *
_copyVariableSetStmt(VariableSetStmt *from)
{
	VariableSetStmt *newnode = makeNode(VariableSetStmt);

	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(args);
	COPY_SCALAR_FIELD(is_local);

	return newnode;
}

static VariableShowStmt *
_copyVariableShowStmt(VariableShowStmt *from)
{
	VariableShowStmt *newnode = makeNode(VariableShowStmt);

	COPY_STRING_FIELD(name);

	return newnode;
}

static VariableResetStmt *
_copyVariableResetStmt(VariableResetStmt *from)
{
	VariableResetStmt *newnode = makeNode(VariableResetStmt);

	COPY_STRING_FIELD(name);

	return newnode;
}

static CreateFileSpaceStmt *
_copyCreateFileSpaceStmt(CreateFileSpaceStmt *from)
{
	CreateFileSpaceStmt *newnode = makeNode(CreateFileSpaceStmt);

	COPY_STRING_FIELD(filespacename);
	COPY_STRING_FIELD(owner);
	COPY_NODE_FIELD(locations);
	COPY_SCALAR_FIELD(fsoid);

	return newnode;
}

static FileSpaceEntry *
_copyFileSpaceEntry(FileSpaceEntry *from)
3886
{
3887
	FileSpaceEntry *newnode = makeNode(FileSpaceEntry);
3888

3889 3890 3891 3892
	COPY_SCALAR_FIELD(dbid);
	COPY_SCALAR_FIELD(contentid);	
	COPY_STRING_FIELD(location);
	COPY_STRING_FIELD(hostname);
3893 3894 3895 3896

	return newnode;
}

3897 3898
static CreateTableSpaceStmt *
_copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
3899
{
3900
	CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
3901

3902 3903 3904 3905
	COPY_STRING_FIELD(tablespacename);
	COPY_STRING_FIELD(owner);
	COPY_STRING_FIELD(filespacename);
	COPY_SCALAR_FIELD(tsoid);
3906 3907 3908 3909 3910 3911 3912 3913 3914

	return newnode;
}

static CreateTrigStmt *
_copyCreateTrigStmt(CreateTrigStmt *from)
{
	CreateTrigStmt *newnode = makeNode(CreateTrigStmt);

3915 3916 3917 3918 3919 3920
	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 已提交
3921
	strcpy(newnode->actions, from->actions);	/* in-line string field */
3922 3923 3924 3925
	COPY_SCALAR_FIELD(isconstraint);
	COPY_SCALAR_FIELD(deferrable);
	COPY_SCALAR_FIELD(initdeferred);
	COPY_NODE_FIELD(constrrel);
3926 3927 3928 3929

	return newnode;
}

3930 3931
static DropPropertyStmt *
_copyDropPropertyStmt(DropPropertyStmt *from)
3932
{
3933
	DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
3934

3935 3936 3937 3938
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(property);
	COPY_SCALAR_FIELD(removeType);
	COPY_SCALAR_FIELD(behavior);
A
 
Andrew Dunstan 已提交
3939
	COPY_SCALAR_FIELD(missing_ok);
3940 3941 3942 3943 3944 3945 3946 3947 3948

	return newnode;
}

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

3949 3950
	COPY_STRING_FIELD(plname);
	COPY_NODE_FIELD(plhandler);
3951
	COPY_NODE_FIELD(plinline);
3952 3953
	COPY_NODE_FIELD(plvalidator);
	COPY_SCALAR_FIELD(pltrusted);
3954 3955
	COPY_SCALAR_FIELD(plangOid);
	COPY_SCALAR_FIELD(plhandlerOid);
3956
	COPY_SCALAR_FIELD(plinlineOid);
3957
	COPY_SCALAR_FIELD(plvalidatorOid);
3958 3959 3960 3961 3962 3963 3964 3965 3966

	return newnode;
}

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

3967 3968
	COPY_STRING_FIELD(plname);
	COPY_SCALAR_FIELD(behavior);
A
 
Andrew Dunstan 已提交
3969
	COPY_SCALAR_FIELD(missing_ok);
3970 3971 3972 3973

	return newnode;
}

3974 3975
static CreateRoleStmt *
_copyCreateRoleStmt(CreateRoleStmt *from)
3976
{
3977
	CreateRoleStmt *newnode = makeNode(CreateRoleStmt);
3978

3979
	COPY_SCALAR_FIELD(stmt_type);
3980
	COPY_STRING_FIELD(role);
3981
	COPY_NODE_FIELD(options);
3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004
	COPY_SCALAR_FIELD(roleOid);

	return newnode;
}

static DenyLoginInterval *
_copyDenyLoginInterval(DenyLoginInterval *from)
{
	DenyLoginInterval *newnode = makeNode(DenyLoginInterval);

	COPY_NODE_FIELD(start);
	COPY_NODE_FIELD(end);

	return newnode;
}

static DenyLoginPoint *
_copyDenyLoginPoint(DenyLoginPoint *from)
{
	DenyLoginPoint *newnode = makeNode(DenyLoginPoint);

	COPY_NODE_FIELD(day);
	COPY_NODE_FIELD(time);
4005 4006 4007 4008

	return newnode;
}

4009 4010
static AlterRoleStmt *
_copyAlterRoleStmt(AlterRoleStmt *from)
4011
{
4012
	AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
4013

4014
	COPY_STRING_FIELD(role);
4015
	COPY_NODE_FIELD(options);
4016
	COPY_SCALAR_FIELD(action);
4017 4018 4019 4020

	return newnode;
}

4021 4022
static AlterRoleSetStmt *
_copyAlterRoleSetStmt(AlterRoleSetStmt *from)
4023
{
4024
	AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
4025

4026
	COPY_STRING_FIELD(role);
4027 4028
	COPY_STRING_FIELD(variable);
	COPY_NODE_FIELD(value);
4029 4030 4031 4032

	return newnode;
}

4033 4034
static DropRoleStmt *
_copyDropRoleStmt(DropRoleStmt *from)
4035
{
4036
	DropRoleStmt *newnode = makeNode(DropRoleStmt);
4037

4038
	COPY_NODE_FIELD(roles);
A
 
Andrew Dunstan 已提交
4039
	COPY_SCALAR_FIELD(missing_ok);
4040 4041 4042 4043

	return newnode;
}

4044 4045 4046
static LockStmt *
_copyLockStmt(LockStmt *from)
{
4047
	LockStmt   *newnode = makeNode(LockStmt);
4048

4049 4050
	COPY_NODE_FIELD(relations);
	COPY_SCALAR_FIELD(mode);
T
Tatsuo Ishii 已提交
4051
	COPY_SCALAR_FIELD(nowait);
4052 4053 4054

	return newnode;
}
4055

4056 4057 4058
static ConstraintsSetStmt *
_copyConstraintsSetStmt(ConstraintsSetStmt *from)
{
B
Bruce Momjian 已提交
4059
	ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
4060

4061 4062
	COPY_NODE_FIELD(constraints);
	COPY_SCALAR_FIELD(deferred);
4063 4064 4065 4066 4067 4068 4069

	return newnode;
}

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

4072
	COPY_SCALAR_FIELD(kind);
4073 4074
	COPY_NODE_FIELD(relation);
	COPY_STRING_FIELD(name);
4075 4076
	COPY_SCALAR_FIELD(do_system);
	COPY_SCALAR_FIELD(do_user);
4077 4078
	COPY_NODE_FIELD(new_ind_oids);
	COPY_SCALAR_FIELD(relid);
4079 4080 4081 4082

	return newnode;
}

4083 4084 4085 4086 4087
static CreateSchemaStmt *
_copyCreateSchemaStmt(CreateSchemaStmt *from)
{
	CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);

4088 4089 4090
	COPY_STRING_FIELD(schemaname);
	COPY_STRING_FIELD(authid);
	COPY_NODE_FIELD(schemaElts);
4091 4092
	COPY_SCALAR_FIELD(istemp);
	COPY_SCALAR_FIELD(schemaOid);
4093 4094 4095 4096

	return newnode;
}

4097 4098 4099 4100 4101
static CreateConversionStmt *
_copyCreateConversionStmt(CreateConversionStmt *from)
{
	CreateConversionStmt *newnode = makeNode(CreateConversionStmt);

4102 4103 4104 4105 4106
	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);
4107 4108 4109 4110 4111 4112 4113 4114 4115

	return newnode;
}

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

4116 4117 4118 4119
	COPY_NODE_FIELD(sourcetype);
	COPY_NODE_FIELD(targettype);
	COPY_NODE_FIELD(func);
	COPY_SCALAR_FIELD(context);
4120 4121 4122 4123 4124 4125 4126 4127 4128

	return newnode;
}

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

4129 4130 4131
	COPY_NODE_FIELD(sourcetype);
	COPY_NODE_FIELD(targettype);
	COPY_SCALAR_FIELD(behavior);
A
 
Andrew Dunstan 已提交
4132
	COPY_SCALAR_FIELD(missing_ok);
4133 4134 4135 4136

	return newnode;
}

4137 4138 4139 4140 4141
static PrepareStmt *
_copyPrepareStmt(PrepareStmt *from)
{
	PrepareStmt *newnode = makeNode(PrepareStmt);

4142 4143
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(argtypes);
4144
	COPY_NODE_FIELD(argtype_oids);
4145
	COPY_NODE_FIELD(query);
4146 4147 4148 4149 4150 4151 4152 4153 4154

	return newnode;
}

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

4155 4156 4157
	COPY_STRING_FIELD(name);
	COPY_NODE_FIELD(into);
	COPY_NODE_FIELD(params);
4158 4159 4160 4161 4162 4163 4164 4165 4166

	return newnode;
}

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

4167
	COPY_STRING_FIELD(name);
4168 4169 4170 4171

	return newnode;
}

4172
static DropOwnedStmt *
B
Bruce Momjian 已提交
4173
_copyDropOwnedStmt(DropOwnedStmt *from)
4174 4175 4176 4177 4178
{
	DropOwnedStmt *newnode = makeNode(DropOwnedStmt);

	COPY_NODE_FIELD(roles);
	COPY_SCALAR_FIELD(behavior);
4179

4180 4181 4182 4183
	return newnode;
}

static ReassignOwnedStmt *
B
Bruce Momjian 已提交
4184
_copyReassignOwnedStmt(ReassignOwnedStmt *from)
4185 4186 4187 4188 4189 4190 4191 4192
{
	ReassignOwnedStmt *newnode = makeNode(ReassignOwnedStmt);

	COPY_NODE_FIELD(roles);
	COPY_SCALAR_FIELD(newrole);

	return newnode;
}
4193

4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352


static CdbProcess *
_copyCdbProcess(CdbProcess *from)
{
	CdbProcess *newnode = makeNode(CdbProcess);

	COPY_STRING_FIELD(listenerAddr);
	COPY_SCALAR_FIELD(listenerPort);
	COPY_SCALAR_FIELD(pid);
	COPY_SCALAR_FIELD(contentid);

	return newnode;
}

static Slice *
_copySlice(Slice *from)
{
	Slice *newnode = makeNode(Slice);

	COPY_SCALAR_FIELD(sliceIndex);
	COPY_SCALAR_FIELD(rootIndex);
	COPY_SCALAR_FIELD(gangType);
	COPY_SCALAR_FIELD(gangSize);
	COPY_SCALAR_FIELD(numGangMembersToBeActive);
	COPY_SCALAR_FIELD(directDispatch.isDirectDispatch);
	COPY_NODE_FIELD(directDispatch.contentIds);

	newnode->primaryGang = from->primaryGang;
	COPY_SCALAR_FIELD(primary_gang_id);
	COPY_SCALAR_FIELD(parentIndex);
	COPY_NODE_FIELD(children);
	COPY_NODE_FIELD(primaryProcesses);

	return newnode;
}

static SliceTable *
_copySliceTable(SliceTable *from)
{
	SliceTable *newnode = makeNode(SliceTable);

	COPY_SCALAR_FIELD(nMotions);
	COPY_SCALAR_FIELD(nInitPlans);
	COPY_SCALAR_FIELD(localSlice);
	COPY_NODE_FIELD(slices);
    COPY_SCALAR_FIELD(doInstrument);
    COPY_SCALAR_FIELD(ic_instance_id);

	return newnode;
}



static CreateQueueStmt *
_copyCreateQueueStmt(CreateQueueStmt *from)
{
	CreateQueueStmt *newnode = makeNode(CreateQueueStmt);

	COPY_STRING_FIELD(queue);
	COPY_NODE_FIELD(options);

	return newnode;
}

static AlterQueueStmt *
_copyAlterQueueStmt(AlterQueueStmt *from)
{
	AlterQueueStmt *newnode = makeNode(AlterQueueStmt);

	COPY_STRING_FIELD(queue);
	COPY_NODE_FIELD(options);

	return newnode;
}

static DropQueueStmt *
_copyDropQueueStmt(DropQueueStmt *from)
{
	DropQueueStmt *newnode = makeNode(DropQueueStmt);

	COPY_STRING_FIELD(queue);

	return newnode;
}

static TableValueExpr *
_copyTableValueExpr(TableValueExpr *from)
{
	TableValueExpr *newnode = makeNode(TableValueExpr);

	COPY_NODE_FIELD(subquery);

	return newnode;
}

static AlterTypeStmt *
_copyAlterTypeStmt(AlterTypeStmt *from)
{
	AlterTypeStmt *newnode = makeNode(AlterTypeStmt);

	COPY_NODE_FIELD(typname);
	COPY_NODE_FIELD(encoding);

	return newnode;
}

static CaQLSelect *
_copyCaQLSelect(const CaQLSelect *from)
{
	CaQLSelect *newnode = makeNode(CaQLSelect);

	COPY_NODE_FIELD(targetlist);
	COPY_STRING_FIELD(from);
	COPY_NODE_FIELD(where);
	COPY_NODE_FIELD(orderby);
	COPY_SCALAR_FIELD(forupdate);
	COPY_SCALAR_FIELD(count);

	return newnode;
}

static CaQLInsert *
_copyCaQLInsert(const CaQLInsert *from)
{
	CaQLInsert *newnode = makeNode(CaQLInsert);

	COPY_STRING_FIELD(into);

	return newnode;
}

static CaQLDelete *
_copyCaQLDelete(const CaQLDelete *from)
{
	CaQLDelete *newnode = makeNode(CaQLDelete);

	COPY_STRING_FIELD(from);
	COPY_NODE_FIELD(where);

	return newnode;
}

static CaQLExpr *
_copyCaQLExpr(const CaQLExpr *from)
{
	CaQLExpr *newnode = makeNode(CaQLExpr);

	COPY_STRING_FIELD(left);
	COPY_STRING_FIELD(op);
	COPY_SCALAR_FIELD(right);
	COPY_SCALAR_FIELD(attnum);
	COPY_SCALAR_FIELD(strategy);
	COPY_SCALAR_FIELD(fnoid);
	COPY_SCALAR_FIELD(typid);

	return newnode;
}

4353
/* ****************************************************************
4354
 *					pg_list.h copy functions
4355 4356 4357
 * ****************************************************************
 */

4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369
/*
 * 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 已提交
4370 4371 4372
	List	   *new;
	ListCell   *curr_old;
	ListCell   *prev_new;
4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398

	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
 * ****************************************************************
 */
4399
static Value *
4400
_copyValue(Value *from)
4401
{
4402
	Value	   *newnode = makeNode(Value);
4403

4404 4405
	/* See also _copyAConst when changing this code! */

4406
	COPY_SCALAR_FIELD(type);
4407 4408
	switch (from->type)
	{
4409
		case T_Integer:
4410
			COPY_SCALAR_FIELD(val.ival);
4411 4412
			break;
		case T_Float:
4413
		case T_String:
4414
		case T_BitString:
4415
			COPY_STRING_FIELD(val.str);
4416
			break;
4417 4418 4419
		case T_Null:
			/* nothing to do */
			break;
4420
		default:
4421 4422
			elog(ERROR, "unrecognized node type: %d",
				 (int) from->type);
4423
			break;
4424 4425
	}
	return newnode;
4426 4427
}

4428 4429 4430 4431 4432
/*
 * copyObject
 *
 * Create a copy of a Node tree or list.  This is a "deep" copy: all
 * substructure is copied too, recursively.
4433
 */
4434
void *
4435 4436
copyObject(void *from)
{
4437
	void	   *retval;
4438

4439 4440
	if (from == NULL)
		return NULL;
4441

4442
	switch (nodeTag(from))
4443
	{
4444 4445 4446
			/*
			 * PLAN NODES
			 */
4447 4448 4449
		case T_PlannedStmt:
			retval = _copyPlannedStmt(from);
			break;
4450 4451 4452
		case T_QueryDispatchDesc:
			retval = _copyQueryDispatchDesc(from);
			break;
4453 4454 4455 4456 4457 4458
		case T_Plan:
			retval = _copyPlan(from);
			break;
		case T_Result:
			retval = _copyResult(from);
			break;
4459 4460 4461
		case T_Repeat:
			retval = _copyRepeat(from);
			break;
4462 4463 4464
		case T_Append:
			retval = _copyAppend(from);
			break;
4465 4466 4467
		case T_Sequence:
			retval = _copySequence(from);
			break;
4468 4469 4470 4471 4472 4473
		case T_BitmapAnd:
			retval = _copyBitmapAnd(from);
			break;
		case T_BitmapOr:
			retval = _copyBitmapOr(from);
			break;
4474 4475 4476 4477 4478 4479
		case T_Scan:
			retval = _copyScan(from);
			break;
		case T_SeqScan:
			retval = _copySeqScan(from);
			break;
4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494
		case T_AppendOnlyScan:
			retval = _copyAppendOnlyScan(from);
			break;
		case T_AOCSScan:
			retval = _copyAOCSScan(from);
			break;
		case T_TableScan:
			retval = _copyTableScan(from);
			break;
		case T_DynamicTableScan:
			retval = _copyDynamicTableScan(from);
			break;
		case T_ExternalScan:
			retval = _copyExternalScan(from);
			break;
4495 4496 4497
		case T_IndexScan:
			retval = _copyIndexScan(from);
			break;
4498 4499 4500
		case T_DynamicIndexScan:
			retval = _copyDynamicIndexScan(from);
			break;
4501 4502 4503 4504 4505 4506
		case T_BitmapIndexScan:
			retval = _copyBitmapIndexScan(from);
			break;
		case T_BitmapHeapScan:
			retval = _copyBitmapHeapScan(from);
			break;
4507 4508 4509 4510 4511 4512
		case T_BitmapAppendOnlyScan:
			retval = _copyBitmapAppendOnlyScan(from);
			break;
		case T_BitmapTableScan:
			retval = _copyBitmapTableScan(from);
			break;
4513 4514 4515
		case T_TidScan:
			retval = _copyTidScan(from);
			break;
4516 4517 4518
		case T_SubqueryScan:
			retval = _copySubqueryScan(from);
			break;
4519 4520 4521
		case T_FunctionScan:
			retval = _copyFunctionScan(from);
			break;
4522 4523 4524
		case T_ValuesScan:
			retval = _copyValuesScan(from);
			break;
4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536
		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;
4537 4538 4539
		case T_ShareInputScan:
			retval = _copyShareInputScan(from);
			break;
4540 4541 4542 4543 4544 4545 4546 4547 4548
		case T_Material:
			retval = _copyMaterial(from);
			break;
		case T_Sort:
			retval = _copySort(from);
			break;
		case T_Agg:
			retval = _copyAgg(from);
			break;
4549 4550 4551 4552 4553 4554 4555 4556 4557
		case T_WindowKey:
			retval = _copyWindowKey(from);
			break;
		case T_Window:
			retval = _copyWindow(from);
			break;
		case T_TableFunctionScan:
			retval = _copyTableFunctionScan(from);
			break;
4558 4559 4560
		case T_Unique:
			retval = _copyUnique(from);
			break;
4561 4562 4563
		case T_Hash:
			retval = _copyHash(from);
			break;
4564 4565 4566
		case T_SetOp:
			retval = _copySetOp(from);
			break;
4567 4568 4569
		case T_Limit:
			retval = _copyLimit(from);
			break;
4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587
		case T_Motion:
			retval = _copyMotion(from);
			break;
		case T_DML:
			retval = _copyDML(from);
			break;
		case T_SplitUpdate:
			retval = _copySplitUpdate(from);
			break;
		case T_RowTrigger:
			retval = _copyRowTrigger(from);
			break;
		case T_AssertOp:
			retval = _copyAssertOp(from);
			break;
		case T_PartitionSelector:
			retval = _copyPartitionSelector(from);
			break;
4588 4589 4590 4591

			/*
			 * PRIMITIVE NODES
			 */
4592 4593 4594 4595 4596 4597
		case T_Alias:
			retval = _copyAlias(from);
			break;
		case T_RangeVar:
			retval = _copyRangeVar(from);
			break;
4598 4599 4600
		case T_IntoClause:
			retval = _copyIntoClause(from);
			break;
4601 4602 4603
		case T_TableOidInfo:
			retval = _copyTableOidInfo(from);
			break;
4604 4605 4606 4607 4608 4609 4610 4611 4612
		case T_Var:
			retval = _copyVar(from);
			break;
		case T_Const:
			retval = _copyConst(from);
			break;
		case T_Param:
			retval = _copyParam(from);
			break;
4613 4614 4615
		case T_Aggref:
			retval = _copyAggref(from);
			break;
4616 4617 4618 4619 4620 4621
		case T_AggOrder:
			retval = _copyAggOrder(from);
			break;
		case T_WindowRef:
			retval = _copyWindowRef(from);
			break;
4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633
		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;
4634 4635 4636
		case T_ScalarArrayOpExpr:
			retval = _copyScalarArrayOpExpr(from);
			break;
4637 4638 4639
		case T_BoolExpr:
			retval = _copyBoolExpr(from);
			break;
4640 4641 4642
		case T_SubLink:
			retval = _copySubLink(from);
			break;
4643 4644
		case T_SubPlan:
			retval = _copySubPlan(from);
4645
			break;
4646 4647 4648
		case T_FieldSelect:
			retval = _copyFieldSelect(from);
			break;
4649 4650 4651
		case T_FieldStore:
			retval = _copyFieldStore(from);
			break;
4652 4653 4654
		case T_RelabelType:
			retval = _copyRelabelType(from);
			break;
4655 4656 4657 4658 4659 4660
		case T_CoerceViaIO:
			retval = _copyCoerceViaIO(from);
			break;
		case T_ArrayCoerceExpr:
			retval = _copyArrayCoerceExpr(from);
			break;
4661 4662 4663
		case T_ConvertRowtypeExpr:
			retval = _copyConvertRowtypeExpr(from);
			break;
4664 4665 4666 4667 4668 4669
		case T_CaseExpr:
			retval = _copyCaseExpr(from);
			break;
		case T_CaseWhen:
			retval = _copyCaseWhen(from);
			break;
4670 4671 4672
		case T_CaseTestExpr:
			retval = _copyCaseTestExpr(from);
			break;
4673 4674 4675
		case T_ArrayExpr:
			retval = _copyArrayExpr(from);
			break;
4676 4677 4678
		case T_RowExpr:
			retval = _copyRowExpr(from);
			break;
4679 4680 4681
		case T_RowCompareExpr:
			retval = _copyRowCompareExpr(from);
			break;
4682 4683 4684
		case T_CoalesceExpr:
			retval = _copyCoalesceExpr(from);
			break;
4685 4686 4687
		case T_MinMaxExpr:
			retval = _copyMinMaxExpr(from);
			break;
4688 4689 4690
		case T_XmlExpr:
			retval = _copyXmlExpr(from);
			break;
4691 4692 4693
		case T_NullIfExpr:
			retval = _copyNullIfExpr(from);
			break;
4694 4695 4696 4697 4698 4699
		case T_NullTest:
			retval = _copyNullTest(from);
			break;
		case T_BooleanTest:
			retval = _copyBooleanTest(from);
			break;
4700 4701
		case T_CoerceToDomain:
			retval = _copyCoerceToDomain(from);
4702
			break;
4703 4704
		case T_CoerceToDomainValue:
			retval = _copyCoerceToDomainValue(from);
4705
			break;
4706 4707 4708
		case T_SetToDefault:
			retval = _copySetToDefault(from);
			break;
4709 4710 4711
		case T_CurrentOfExpr:
			retval = _copyCurrentOfExpr(from);
			break;
4712 4713 4714
		case T_TargetEntry:
			retval = _copyTargetEntry(from);
			break;
4715 4716 4717
		case T_RangeTblRef:
			retval = _copyRangeTblRef(from);
			break;
4718 4719 4720
		case T_JoinExpr:
			retval = _copyJoinExpr(from);
			break;
4721 4722 4723
		case T_FromExpr:
			retval = _copyFromExpr(from);
			break;
4724 4725 4726
		case T_Flow:
			retval = _copyFlow(from);
			break;
4727 4728 4729 4730

			/*
			 * RELATION NODES
			 */
4731 4732 4733
		case T_CdbRelColumnInfo:
			retval = _copyCdbRelColumnInfo(from);
			break;
4734 4735
		case T_PathKey:
			retval = _copyPathKey(from);
4736
			break;
4737 4738
		case T_RestrictInfo:
			retval = _copyRestrictInfo(from);
4739
			break;
4740 4741 4742
		case T_OuterJoinInfo:
			retval = _copyOuterJoinInfo(from);
			break;
4743 4744 4745
		case T_InClauseInfo:
			retval = _copyInClauseInfo(from);
			break;
4746 4747 4748
		case T_AppendRelInfo:
			retval = _copyAppendRelInfo(from);
			break;
4749 4750

			/*
4751
			 * VALUE NODES
4752
			 */
4753 4754 4755
		case T_Integer:
		case T_Float:
		case T_String:
4756
		case T_BitString:
4757
		case T_Null:
4758
			retval = _copyValue(from);
4759
			break;
4760 4761 4762 4763

			/*
			 * LIST NODES
			 */
4764
		case T_List:
4765 4766
			retval = _copyList(from);
			break;
B
Bruce Momjian 已提交
4767

4768
			/*
B
Bruce Momjian 已提交
4769 4770
			 * Lists of integers and OIDs don't need to be deep-copied, so we
			 * perform a shallow copy via list_copy()
4771 4772 4773 4774
			 */
		case T_IntList:
		case T_OidList:
			retval = list_copy(from);
4775
			break;
4776 4777 4778 4779

			/*
			 * PARSE NODES
			 */
4780 4781 4782
		case T_Query:
			retval = _copyQuery(from);
			break;
4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794
		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;
4795 4796 4797
		case T_SetOperationStmt:
			retval = _copySetOperationStmt(from);
			break;
4798 4799 4800
		case T_AlterTableStmt:
			retval = _copyAlterTableStmt(from);
			break;
T
Tom Lane 已提交
4801 4802 4803
		case T_AlterTableCmd:
			retval = _copyAlterTableCmd(from);
			break;
4804 4805 4806
		case T_SetDistributionCmd:
			retval = _copySetDistributionCmd(from);
			break;
4807 4808 4809 4810 4811 4812 4813 4814 4815
		case T_InheritPartitionCmd:
			retval = _copyInheritPartitionCmd(from);
			break;
		case T_AlterPartitionCmd:
			retval = _copyAlterPartitionCmd(from);
			break;
		case T_AlterPartitionId:
			retval = _copyAlterPartitionId(from);
			break;
B
Bruce Momjian 已提交
4816 4817 4818
		case T_AlterDomainStmt:
			retval = _copyAlterDomainStmt(from);
			break;
4819 4820
		case T_GrantStmt:
			retval = _copyGrantStmt(from);
4821
			break;
4822 4823 4824
		case T_GrantRoleStmt:
			retval = _copyGrantRoleStmt(from);
			break;
4825 4826 4827
		case T_DeclareCursorStmt:
			retval = _copyDeclareCursorStmt(from);
			break;
4828 4829 4830
		case T_ClosePortalStmt:
			retval = _copyClosePortalStmt(from);
			break;
4831 4832 4833
		case T_ClusterStmt:
			retval = _copyClusterStmt(from);
			break;
4834 4835 4836
		case T_SingleRowErrorDesc:
			retval = _copySingleRowErrorDesc(from);
			break;
4837 4838 4839 4840 4841 4842
		case T_CopyStmt:
			retval = _copyCopyStmt(from);
			break;
		case T_CreateStmt:
			retval = _copyCreateStmt(from);
			break;
4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878
		case T_PartitionBy:
			retval = _copyPartitionBy(from);
			break;
		case T_PartitionSpec:
			retval = _copyPartitionSpec(from);
			break;
		case T_PartitionValuesSpec:
			retval = _copyPartitionValuesSpec(from);
			break;
		case T_PartitionElem:
			retval = _copyPartitionElem(from);
			break;
		case T_PartitionRangeItem:
			retval = _copyPartitionRangeItem(from);
			break;
		case T_PartitionBoundSpec:
			retval = _copyPartitionBoundSpec(from);
			break;
		case T_PgPartRule:
			retval = _copyPgPartRule(from);
			break;
		case T_PartitionNode:
			retval = _copyPartitionNode(from);
			break;
		case T_Partition:
			retval = _copyPartition(from);
			break;
		case T_PartitionRule:
			retval = _copyPartitionRule(from);
			break;
		case T_ExtTableTypeDesc:
			retval = _copyExtTableTypeDesc(from);
			break;
		case T_CreateExternalStmt:
			retval = _copyCreateExternalStmt(from);
			break;
B
Bruce Momjian 已提交
4879 4880 4881
		case T_InhRelation:
			retval = _copyInhRelation(from);
			break;
4882 4883 4884 4885 4886 4887
		case T_DefineStmt:
			retval = _copyDefineStmt(from);
			break;
		case T_DropStmt:
			retval = _copyDropStmt(from);
			break;
4888 4889 4890
		case T_TruncateStmt:
			retval = _copyTruncateStmt(from);
			break;
4891 4892 4893 4894 4895 4896 4897 4898 4899
		case T_CommentStmt:
			retval = _copyCommentStmt(from);
			break;
		case T_FetchStmt:
			retval = _copyFetchStmt(from);
			break;
		case T_IndexStmt:
			retval = _copyIndexStmt(from);
			break;
4900 4901
		case T_CreateFunctionStmt:
			retval = _copyCreateFunctionStmt(from);
4902
			break;
4903 4904 4905
		case T_FunctionParameter:
			retval = _copyFunctionParameter(from);
			break;
4906 4907 4908
		case T_AlterFunctionStmt:
			retval = _copyAlterFunctionStmt(from);
			break;
4909 4910 4911
		case T_RemoveFuncStmt:
			retval = _copyRemoveFuncStmt(from);
			break;
4912 4913 4914
		case T_DoStmt:
			retval = _copyDoStmt(from);
			break;
4915 4916 4917
		case T_RemoveOpClassStmt:
			retval = _copyRemoveOpClassStmt(from);
			break;
4918 4919 4920
		case T_RemoveOpFamilyStmt:
			retval = _copyRemoveOpFamilyStmt(from);
			break;
4921 4922 4923
		case T_RenameStmt:
			retval = _copyRenameStmt(from);
			break;
4924 4925 4926
		case T_AlterObjectSchemaStmt:
			retval = _copyAlterObjectSchemaStmt(from);
			break;
4927 4928 4929
		case T_AlterOwnerStmt:
			retval = _copyAlterOwnerStmt(from);
			break;
4930 4931 4932
		case T_RuleStmt:
			retval = _copyRuleStmt(from);
			break;
4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944
		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 已提交
4945 4946 4947
		case T_CompositeTypeStmt:
			retval = _copyCompositeTypeStmt(from);
			break;
4948 4949 4950
		case T_ViewStmt:
			retval = _copyViewStmt(from);
			break;
4951 4952 4953
		case T_LoadStmt:
			retval = _copyLoadStmt(from);
			break;
4954 4955 4956
		case T_CreateDomainStmt:
			retval = _copyCreateDomainStmt(from);
			break;
4957 4958 4959 4960 4961 4962
		case T_CreateOpClassStmt:
			retval = _copyCreateOpClassStmt(from);
			break;
		case T_CreateOpClassItem:
			retval = _copyCreateOpClassItem(from);
			break;
4963 4964 4965 4966 4967 4968
		case T_CreateOpFamilyStmt:
			retval = _copyCreateOpFamilyStmt(from);
			break;
		case T_AlterOpFamilyStmt:
			retval = _copyAlterOpFamilyStmt(from);
			break;
4969 4970 4971
		case T_CreatedbStmt:
			retval = _copyCreatedbStmt(from);
			break;
4972 4973 4974
		case T_AlterDatabaseStmt:
			retval = _copyAlterDatabaseStmt(from);
			break;
4975 4976 4977
		case T_AlterDatabaseSetStmt:
			retval = _copyAlterDatabaseSetStmt(from);
			break;
4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989
		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 已提交
4990 4991 4992
		case T_AlterSeqStmt:
			retval = _copyAlterSeqStmt(from);
			break;
4993 4994 4995
		case T_VariableSetStmt:
			retval = _copyVariableSetStmt(from);
			break;
4996 4997 4998
		case T_VariableShowStmt:
			retval = _copyVariableShowStmt(from);
			break;
4999 5000 5001
		case T_VariableResetStmt:
			retval = _copyVariableResetStmt(from);
			break;
5002 5003 5004 5005 5006 5007
		case T_CreateFileSpaceStmt:
			retval = _copyCreateFileSpaceStmt(from);
			break;
		case T_FileSpaceEntry:
			retval = _copyFileSpaceEntry(from);
			break;
5008 5009 5010
		case T_CreateTableSpaceStmt:
			retval = _copyCreateTableSpaceStmt(from);
			break;
5011 5012 5013
		case T_CreateTrigStmt:
			retval = _copyCreateTrigStmt(from);
			break;
5014 5015
		case T_DropPropertyStmt:
			retval = _copyDropPropertyStmt(from);
5016 5017 5018 5019 5020 5021 5022
			break;
		case T_CreatePLangStmt:
			retval = _copyCreatePLangStmt(from);
			break;
		case T_DropPLangStmt:
			retval = _copyDropPLangStmt(from);
			break;
5023 5024
		case T_CreateRoleStmt:
			retval = _copyCreateRoleStmt(from);
5025
			break;
5026 5027
		case T_AlterRoleStmt:
			retval = _copyAlterRoleStmt(from);
5028
			break;
5029 5030
		case T_AlterRoleSetStmt:
			retval = _copyAlterRoleSetStmt(from);
5031
			break;
5032 5033
		case T_DropRoleStmt:
			retval = _copyDropRoleStmt(from);
5034
			break;
5035 5036 5037
		case T_LockStmt:
			retval = _copyLockStmt(from);
			break;
5038 5039 5040 5041 5042 5043
		case T_ConstraintsSetStmt:
			retval = _copyConstraintsSetStmt(from);
			break;
		case T_ReindexStmt:
			retval = _copyReindexStmt(from);
			break;
V
Vadim B. Mikheev 已提交
5044
		case T_CheckPointStmt:
B
Bruce Momjian 已提交
5045
			retval = (void *) makeNode(CheckPointStmt);
V
Vadim B. Mikheev 已提交
5046
			break;
5047 5048 5049
		case T_CreateSchemaStmt:
			retval = _copyCreateSchemaStmt(from);
			break;
5050 5051 5052 5053 5054 5055 5056 5057 5058
		case T_CreateConversionStmt:
			retval = _copyCreateConversionStmt(from);
			break;
		case T_CreateCastStmt:
			retval = _copyCreateCastStmt(from);
			break;
		case T_DropCastStmt:
			retval = _copyDropCastStmt(from);
			break;
5059 5060 5061 5062 5063 5064 5065 5066 5067
		case T_PrepareStmt:
			retval = _copyPrepareStmt(from);
			break;
		case T_ExecuteStmt:
			retval = _copyExecuteStmt(from);
			break;
		case T_DeallocateStmt:
			retval = _copyDeallocateStmt(from);
			break;
5068 5069 5070 5071 5072 5073
		case T_DropOwnedStmt:
			retval = _copyDropOwnedStmt(from);
			break;
		case T_ReassignOwnedStmt:
			retval = _copyReassignOwnedStmt(from);
			break;
5074

5075 5076 5077 5078 5079 5080 5081 5082 5083
		case T_CreateQueueStmt:
			retval = _copyCreateQueueStmt(from);
			break;
		case T_AlterQueueStmt:
			retval = _copyAlterQueueStmt(from);
			break;
		case T_DropQueueStmt:
			retval = _copyDropQueueStmt(from);
			break;
5084 5085 5086
		case T_A_Expr:
			retval = _copyAExpr(from);
			break;
5087 5088 5089 5090 5091
		case T_ColumnRef:
			retval = _copyColumnRef(from);
			break;
		case T_ParamRef:
			retval = _copyParamRef(from);
5092
			break;
5093 5094 5095
		case T_A_Const:
			retval = _copyAConst(from);
			break;
5096 5097 5098 5099 5100 5101
		case T_FuncCall:
			retval = _copyFuncCall(from);
			break;
		case T_A_Indices:
			retval = _copyAIndices(from);
			break;
5102 5103
		case T_A_Indirection:
			retval = _copyA_Indirection(from);
5104
			break;
5105 5106 5107
		case T_A_ArrayExpr:
			retval = _copyA_ArrayExpr(from);
			break;
5108 5109 5110
		case T_ResTarget:
			retval = _copyResTarget(from);
			break;
5111 5112 5113
		case T_TypeCast:
			retval = _copyTypeCast(from);
			break;
5114 5115
		case T_SortBy:
			retval = _copySortBy(from);
5116
			break;
5117 5118 5119
		case T_RangeSubselect:
			retval = _copyRangeSubselect(from);
			break;
5120 5121 5122
		case T_RangeFunction:
			retval = _copyRangeFunction(from);
			break;
5123 5124 5125
		case T_TypeName:
			retval = _copyTypeName(from);
			break;
5126 5127 5128 5129 5130 5131
		case T_IndexElem:
			retval = _copyIndexElem(from);
			break;
		case T_ColumnDef:
			retval = _copyColumnDef(from);
			break;
5132 5133 5134
		case T_ColumnReferenceStorageDirective:
			retval = _copyColumnReferenceStorageDirective(from);
			break;
5135 5136 5137 5138 5139 5140
		case T_Constraint:
			retval = _copyConstraint(from);
			break;
		case T_DefElem:
			retval = _copyDefElem(from);
			break;
5141 5142 5143
		case T_LockingClause:
			retval = _copyLockingClause(from);
			break;
5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161
		case T_DMLActionExpr:
			retval = _copyDMLActionExpr(from);
			break;
		case T_PartOidExpr:
			retval = _copyPartOidExpr(from);
			break;
		case T_PartDefaultExpr:
			retval = _copyPartDefaultExpr(from);
			break;
		case T_PartBoundExpr:
			retval = _copyPartBoundExpr(from);
			break;
		case T_PartBoundInclusionExpr:
			retval = _copyPartBoundInclusionExpr(from);
			break;
		case T_PartBoundOpenExpr:
			retval = _copyPartBoundOpenExpr(from);
			break;
5162 5163
		case T_RangeTblEntry:
			retval = _copyRangeTblEntry(from);
5164
			break;
5165 5166 5167 5168 5169 5170
		case T_SortClause:
			retval = _copySortClause(from);
			break;
		case T_GroupClause:
			retval = _copyGroupClause(from);
			break;
5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197
		case T_GroupingClause:
			retval = _copyGroupingClause(from);
			break;
		case T_GroupingFunc:
			retval = _copyGroupingFunc(from);
			break;
		case T_Grouping:
			retval = _copyGrouping(from);
			break;
		case T_GroupId:
			retval = _copyGroupId(from);
			break;
		case T_WindowSpecParse:
			retval = _copyWindowSpecParse(from);
			break;
		case T_WindowSpec:
			retval = _copyWindowSpec(from);
			break;
		case T_WindowFrame:
			retval = _copyWindowFrame(from);
			break;
		case T_WindowFrameEdge:
			retval = _copyWindowFrameEdge(from);
			break;
		case T_PercentileExpr:
			retval = _copyPercentileExpr(from);
			break;
5198 5199 5200
		case T_RowMarkClause:
			retval = _copyRowMarkClause(from);
			break;
5201 5202 5203 5204 5205 5206
		case T_WithClause:
			retval = _copyWithClause(from);
			break;
		case T_CommonTableExpr:
			retval = _copyCommonTableExpr(from);
			break;
5207 5208 5209
		case T_FkConstraint:
			retval = _copyFkConstraint(from);
			break;
5210 5211 5212
		case T_PrivGrantee:
			retval = _copyPrivGrantee(from);
			break;
5213 5214 5215
		case T_FuncWithArgs:
			retval = _copyFuncWithArgs(from);
			break;
5216 5217 5218 5219
		case T_XmlSerialize:
			retval = _copyXmlSerialize(from);
			break;

5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254
		case T_CdbProcess:
			retval = _copyCdbProcess(from);
			break;
		case T_Slice:
			retval = _copySlice(from);
			break;
		case T_SliceTable:
			retval = _copySliceTable(from);
			break;
		case T_TableValueExpr:
			retval = _copyTableValueExpr(from);
			break;
		case T_AlterTypeStmt:
			retval = _copyAlterTypeStmt(from);
			break;

		case T_DenyLoginInterval:
			retval = _copyDenyLoginInterval(from);
			break;
		case T_DenyLoginPoint:
			retval = _copyDenyLoginPoint(from);
			break;

		case T_CaQLSelect:
			retval = _copyCaQLSelect(from);
			break;
		case T_CaQLInsert:
			retval = _copyCaQLInsert(from);
			break;
		case T_CaQLDelete:
			retval = _copyCaQLDelete(from);
			break;
		case T_CaQLExpr:
			retval = _copyCaQLExpr(from);
			break;
5255

5256
		default:
5257
			elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
5258
			retval = from;		/* keep compiler quiet */
5259
			break;
5260
	}
5261

5262
	return retval;
5263
}