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
7  * plan trees.  We do not support copying executor state trees; there
8  * is no need for that, and no point in maintaining all the code that
9  * would be needed.  We also do not support copying Path trees, mainly
10  * because the circular linkages between RelOptInfo and Path nodes can't
11  * be handled easily in a simple depth-first traversal.
12  *
13  *
14  * Portions Copyright (c) 2003-2016, PgPool Global Development Group
15  * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
16  * Portions Copyright (c) 1994, Regents of the University of California
17  *
18  * IDENTIFICATION
19  *	  src/backend/nodes/copyfuncs.c
20  *
21  *-------------------------------------------------------------------------
22  */
23 
24 #include "pool.h"
25 
26 #include <string.h>
27 #include <stddef.h>
28 #include "utils/palloc.h"
29 #include "utils/elog.h"
30 #include "parsenodes.h"
31 #include "extensible.h"
32 
33 
34 /*
35  * Macros to simplify copying of different kinds of fields.  Use these
36  * wherever possible to reduce the chance for silly typos.  Note that these
37  * hard-wire the convention that the local variables in a Copy routine are
38  * named 'newnode' and 'from'.
39  */
40 
41 /* Copy a simple scalar field (int, float, bool, enum, etc) */
42 #define COPY_SCALAR_FIELD(fldname) \
43 	(newnode->fldname = from->fldname)
44 
45 /* Copy a field that is a pointer to some kind of Node or Node tree */
46 #define COPY_NODE_FIELD(fldname) \
47 	(newnode->fldname = copyObject(from->fldname))
48 
49 /* Copy a field that is a pointer to a Bitmapset */
50 #define COPY_BITMAPSET_FIELD(fldname) \
51 	(newnode->fldname = bms_copy(from->fldname))
52 
53 /* Copy a field that is a pointer to a C string, or perhaps NULL */
54 #define COPY_STRING_FIELD(fldname) \
55 	(newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)
56 
57 /* Copy a field that is a pointer to a simple palloc'd object of size sz */
58 #define COPY_POINTER_FIELD(fldname, sz) \
59 	do { \
60 		Size	_size = (sz); \
61 		newnode->fldname = palloc(_size); \
62 		memcpy(newnode->fldname, from->fldname, _size); \
63 	} while (0)
64 
65 /* Copy a parse location field (for Copy, this is same as scalar case) */
66 #define COPY_LOCATION_FIELD(fldname) \
67 	(newnode->fldname = from->fldname)
68 
69 
70 /* ****************************************************************
71  *					 plannodes.h copy functions
72  * ****************************************************************
73  */
74 
75 #ifdef NOT_USED_IN_PGPOOL
76 /*
77  * _copyPlannedStmt
78  */
79 static PlannedStmt *
_copyPlannedStmt(const PlannedStmt * from)80 _copyPlannedStmt(const PlannedStmt *from)
81 {
82 	PlannedStmt *newnode = makeNode(PlannedStmt);
83 
84 	COPY_SCALAR_FIELD(commandType);
85 	COPY_SCALAR_FIELD(queryId);
86 	COPY_SCALAR_FIELD(hasReturning);
87 	COPY_SCALAR_FIELD(hasModifyingCTE);
88 	COPY_SCALAR_FIELD(canSetTag);
89 	COPY_SCALAR_FIELD(transientPlan);
90 	COPY_SCALAR_FIELD(dependsOnRole);
91 	COPY_SCALAR_FIELD(parallelModeNeeded);
92 	COPY_NODE_FIELD(planTree);
93 	COPY_NODE_FIELD(rtable);
94 	COPY_NODE_FIELD(resultRelations);
95 	COPY_NODE_FIELD(utilityStmt);
96 	COPY_NODE_FIELD(subplans);
97 	COPY_BITMAPSET_FIELD(rewindPlanIDs);
98 	COPY_NODE_FIELD(rowMarks);
99 	COPY_NODE_FIELD(relationOids);
100 	COPY_NODE_FIELD(invalItems);
101 	COPY_SCALAR_FIELD(nParamExec);
102 
103 	return newnode;
104 }
105 
106 /*
107  * CopyPlanFields
108  *
109  *		This function copies the fields of the Plan node.  It is used by
110  *		all the copy functions for classes which inherit from Plan.
111  */
112 static void
CopyPlanFields(const Plan * from,Plan * newnode)113 CopyPlanFields(const Plan *from, Plan *newnode)
114 {
115 	COPY_SCALAR_FIELD(startup_cost);
116 	COPY_SCALAR_FIELD(total_cost);
117 	COPY_SCALAR_FIELD(plan_rows);
118 	COPY_SCALAR_FIELD(plan_width);
119 	COPY_SCALAR_FIELD(parallel_aware);
120 	COPY_SCALAR_FIELD(plan_node_id);
121 	COPY_NODE_FIELD(targetlist);
122 	COPY_NODE_FIELD(qual);
123 	COPY_NODE_FIELD(lefttree);
124 	COPY_NODE_FIELD(righttree);
125 	COPY_NODE_FIELD(initPlan);
126 	COPY_BITMAPSET_FIELD(extParam);
127 	COPY_BITMAPSET_FIELD(allParam);
128 }
129 
130 /*
131  * _copyPlan
132  */
133 static Plan *
_copyPlan(const Plan * from)134 _copyPlan(const Plan *from)
135 {
136 	Plan	   *newnode = makeNode(Plan);
137 
138 	/*
139 	 * copy node superclass fields
140 	 */
141 	CopyPlanFields(from, newnode);
142 
143 	return newnode;
144 }
145 
146 
147 /*
148  * _copyResult
149  */
150 static Result *
_copyResult(const Result * from)151 _copyResult(const Result *from)
152 {
153 	Result	   *newnode = makeNode(Result);
154 
155 	/*
156 	 * copy node superclass fields
157 	 */
158 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
159 
160 	/*
161 	 * copy remainder of node
162 	 */
163 	COPY_NODE_FIELD(resconstantqual);
164 
165 	return newnode;
166 }
167 
168 /*
169  * _copyModifyTable
170  */
171 static ModifyTable *
_copyModifyTable(const ModifyTable * from)172 _copyModifyTable(const ModifyTable *from)
173 {
174 	ModifyTable *newnode = makeNode(ModifyTable);
175 
176 	/*
177 	 * copy node superclass fields
178 	 */
179 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
180 
181 	/*
182 	 * copy remainder of node
183 	 */
184 	COPY_SCALAR_FIELD(operation);
185 	COPY_SCALAR_FIELD(canSetTag);
186 	COPY_SCALAR_FIELD(nominalRelation);
187 	COPY_NODE_FIELD(resultRelations);
188 	COPY_SCALAR_FIELD(resultRelIndex);
189 	COPY_NODE_FIELD(plans);
190 	COPY_NODE_FIELD(withCheckOptionLists);
191 	COPY_NODE_FIELD(returningLists);
192 	COPY_NODE_FIELD(fdwPrivLists);
193 	COPY_BITMAPSET_FIELD(fdwDirectModifyPlans);
194 	COPY_NODE_FIELD(rowMarks);
195 	COPY_SCALAR_FIELD(epqParam);
196 	COPY_SCALAR_FIELD(onConflictAction);
197 	COPY_NODE_FIELD(arbiterIndexes);
198 	COPY_NODE_FIELD(onConflictSet);
199 	COPY_NODE_FIELD(onConflictWhere);
200 	COPY_SCALAR_FIELD(exclRelRTI);
201 	COPY_NODE_FIELD(exclRelTlist);
202 
203 	return newnode;
204 }
205 
206 /*
207  * _copyAppend
208  */
209 static Append *
_copyAppend(const Append * from)210 _copyAppend(const Append *from)
211 {
212 	Append	   *newnode = makeNode(Append);
213 
214 	/*
215 	 * copy node superclass fields
216 	 */
217 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
218 
219 	/*
220 	 * copy remainder of node
221 	 */
222 	COPY_NODE_FIELD(appendplans);
223 
224 	return newnode;
225 }
226 
227 /*
228  * _copyMergeAppend
229  */
230 static MergeAppend *
_copyMergeAppend(const MergeAppend * from)231 _copyMergeAppend(const MergeAppend *from)
232 {
233 	MergeAppend *newnode = makeNode(MergeAppend);
234 
235 	/*
236 	 * copy node superclass fields
237 	 */
238 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
239 
240 	/*
241 	 * copy remainder of node
242 	 */
243 	COPY_NODE_FIELD(mergeplans);
244 	COPY_SCALAR_FIELD(numCols);
245 	COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
246 	COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
247 	COPY_POINTER_FIELD(collations, from->numCols * sizeof(Oid));
248 	COPY_POINTER_FIELD(nullsFirst, from->numCols * sizeof(bool));
249 
250 	return newnode;
251 }
252 
253 /*
254  * _copyRecursiveUnion
255  */
256 static RecursiveUnion *
_copyRecursiveUnion(const RecursiveUnion * from)257 _copyRecursiveUnion(const RecursiveUnion *from)
258 {
259 	RecursiveUnion *newnode = makeNode(RecursiveUnion);
260 
261 	/*
262 	 * copy node superclass fields
263 	 */
264 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
265 
266 	/*
267 	 * copy remainder of node
268 	 */
269 	COPY_SCALAR_FIELD(wtParam);
270 	COPY_SCALAR_FIELD(numCols);
271 	if (from->numCols > 0)
272 	{
273 		COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
274 		COPY_POINTER_FIELD(dupOperators, from->numCols * sizeof(Oid));
275 	}
276 	COPY_SCALAR_FIELD(numGroups);
277 
278 	return newnode;
279 }
280 
281 /*
282  * _copyBitmapAnd
283  */
284 static BitmapAnd *
_copyBitmapAnd(const BitmapAnd * from)285 _copyBitmapAnd(const BitmapAnd *from)
286 {
287 	BitmapAnd  *newnode = makeNode(BitmapAnd);
288 
289 	/*
290 	 * copy node superclass fields
291 	 */
292 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
293 
294 	/*
295 	 * copy remainder of node
296 	 */
297 	COPY_NODE_FIELD(bitmapplans);
298 
299 	return newnode;
300 }
301 
302 /*
303  * _copyBitmapOr
304  */
305 static BitmapOr *
_copyBitmapOr(const BitmapOr * from)306 _copyBitmapOr(const BitmapOr *from)
307 {
308 	BitmapOr   *newnode = makeNode(BitmapOr);
309 
310 	/*
311 	 * copy node superclass fields
312 	 */
313 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
314 
315 	/*
316 	 * copy remainder of node
317 	 */
318 	COPY_NODE_FIELD(bitmapplans);
319 
320 	return newnode;
321 }
322 
323 /*
324  * _copyGather
325  */
326 static Gather *
_copyGather(const Gather * from)327 _copyGather(const Gather *from)
328 {
329 	Gather	   *newnode = makeNode(Gather);
330 
331 	/*
332 	 * copy node superclass fields
333 	 */
334 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
335 
336 	/*
337 	 * copy remainder of node
338 	 */
339 	COPY_SCALAR_FIELD(num_workers);
340 	COPY_SCALAR_FIELD(single_copy);
341 	COPY_SCALAR_FIELD(invisible);
342 
343 	return newnode;
344 }
345 
346 /*
347  * CopyScanFields
348  *
349  *		This function copies the fields of the Scan node.  It is used by
350  *		all the copy functions for classes which inherit from Scan.
351  */
352 static void
CopyScanFields(const Scan * from,Scan * newnode)353 CopyScanFields(const Scan *from, Scan *newnode)
354 {
355 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
356 
357 	COPY_SCALAR_FIELD(scanrelid);
358 }
359 
360 /*
361  * _copyScan
362  */
363 static Scan *
_copyScan(const Scan * from)364 _copyScan(const Scan *from)
365 {
366 	Scan	   *newnode = makeNode(Scan);
367 
368 	/*
369 	 * copy node superclass fields
370 	 */
371 	CopyScanFields((const Scan *) from, (Scan *) newnode);
372 
373 	return newnode;
374 }
375 
376 /*
377  * _copySeqScan
378  */
379 static SeqScan *
_copySeqScan(const SeqScan * from)380 _copySeqScan(const SeqScan *from)
381 {
382 	SeqScan    *newnode = makeNode(SeqScan);
383 
384 	/*
385 	 * copy node superclass fields
386 	 */
387 	CopyScanFields((const Scan *) from, (Scan *) newnode);
388 
389 	return newnode;
390 }
391 
392 /*
393  * _copySampleScan
394  */
395 static SampleScan *
_copySampleScan(const SampleScan * from)396 _copySampleScan(const SampleScan *from)
397 {
398 	SampleScan *newnode = makeNode(SampleScan);
399 
400 	/*
401 	 * copy node superclass fields
402 	 */
403 	CopyScanFields((const Scan *) from, (Scan *) newnode);
404 
405 	/*
406 	 * copy remainder of node
407 	 */
408 	COPY_NODE_FIELD(tablesample);
409 
410 	return newnode;
411 }
412 
413 /*
414  * _copyIndexScan
415  */
416 static IndexScan *
_copyIndexScan(const IndexScan * from)417 _copyIndexScan(const IndexScan *from)
418 {
419 	IndexScan  *newnode = makeNode(IndexScan);
420 
421 	/*
422 	 * copy node superclass fields
423 	 */
424 	CopyScanFields((const Scan *) from, (Scan *) newnode);
425 
426 	/*
427 	 * copy remainder of node
428 	 */
429 	COPY_SCALAR_FIELD(indexid);
430 	COPY_NODE_FIELD(indexqual);
431 	COPY_NODE_FIELD(indexqualorig);
432 	COPY_NODE_FIELD(indexorderby);
433 	COPY_NODE_FIELD(indexorderbyorig);
434 	COPY_NODE_FIELD(indexorderbyops);
435 	COPY_SCALAR_FIELD(indexorderdir);
436 
437 	return newnode;
438 }
439 
440 /*
441  * _copyIndexOnlyScan
442  */
443 static IndexOnlyScan *
_copyIndexOnlyScan(const IndexOnlyScan * from)444 _copyIndexOnlyScan(const IndexOnlyScan *from)
445 {
446 	IndexOnlyScan *newnode = makeNode(IndexOnlyScan);
447 
448 	/*
449 	 * copy node superclass fields
450 	 */
451 	CopyScanFields((const Scan *) from, (Scan *) newnode);
452 
453 	/*
454 	 * copy remainder of node
455 	 */
456 	COPY_SCALAR_FIELD(indexid);
457 	COPY_NODE_FIELD(indexqual);
458 	COPY_NODE_FIELD(indexorderby);
459 	COPY_NODE_FIELD(indextlist);
460 	COPY_SCALAR_FIELD(indexorderdir);
461 
462 	return newnode;
463 }
464 
465 /*
466  * _copyBitmapIndexScan
467  */
468 static BitmapIndexScan *
_copyBitmapIndexScan(const BitmapIndexScan * from)469 _copyBitmapIndexScan(const BitmapIndexScan *from)
470 {
471 	BitmapIndexScan *newnode = makeNode(BitmapIndexScan);
472 
473 	/*
474 	 * copy node superclass fields
475 	 */
476 	CopyScanFields((const Scan *) from, (Scan *) newnode);
477 
478 	/*
479 	 * copy remainder of node
480 	 */
481 	COPY_SCALAR_FIELD(indexid);
482 	COPY_NODE_FIELD(indexqual);
483 	COPY_NODE_FIELD(indexqualorig);
484 
485 	return newnode;
486 }
487 
488 /*
489  * _copyBitmapHeapScan
490  */
491 static BitmapHeapScan *
_copyBitmapHeapScan(const BitmapHeapScan * from)492 _copyBitmapHeapScan(const BitmapHeapScan *from)
493 {
494 	BitmapHeapScan *newnode = makeNode(BitmapHeapScan);
495 
496 	/*
497 	 * copy node superclass fields
498 	 */
499 	CopyScanFields((const Scan *) from, (Scan *) newnode);
500 
501 	/*
502 	 * copy remainder of node
503 	 */
504 	COPY_NODE_FIELD(bitmapqualorig);
505 
506 	return newnode;
507 }
508 
509 /*
510  * _copyTidScan
511  */
512 static TidScan *
_copyTidScan(const TidScan * from)513 _copyTidScan(const TidScan *from)
514 {
515 	TidScan    *newnode = makeNode(TidScan);
516 
517 	/*
518 	 * copy node superclass fields
519 	 */
520 	CopyScanFields((const Scan *) from, (Scan *) newnode);
521 
522 	/*
523 	 * copy remainder of node
524 	 */
525 	COPY_NODE_FIELD(tidquals);
526 
527 	return newnode;
528 }
529 
530 /*
531  * _copySubqueryScan
532  */
533 static SubqueryScan *
_copySubqueryScan(const SubqueryScan * from)534 _copySubqueryScan(const SubqueryScan *from)
535 {
536 	SubqueryScan *newnode = makeNode(SubqueryScan);
537 
538 	/*
539 	 * copy node superclass fields
540 	 */
541 	CopyScanFields((const Scan *) from, (Scan *) newnode);
542 
543 	/*
544 	 * copy remainder of node
545 	 */
546 	COPY_NODE_FIELD(subplan);
547 
548 	return newnode;
549 }
550 
551 /*
552  * _copyFunctionScan
553  */
554 static FunctionScan *
_copyFunctionScan(const FunctionScan * from)555 _copyFunctionScan(const FunctionScan *from)
556 {
557 	FunctionScan *newnode = makeNode(FunctionScan);
558 
559 	/*
560 	 * copy node superclass fields
561 	 */
562 	CopyScanFields((const Scan *) from, (Scan *) newnode);
563 
564 	/*
565 	 * copy remainder of node
566 	 */
567 	COPY_NODE_FIELD(functions);
568 	COPY_SCALAR_FIELD(funcordinality);
569 
570 	return newnode;
571 }
572 
573 /*
574  * _copyValuesScan
575  */
576 static ValuesScan *
_copyValuesScan(const ValuesScan * from)577 _copyValuesScan(const ValuesScan *from)
578 {
579 	ValuesScan *newnode = makeNode(ValuesScan);
580 
581 	/*
582 	 * copy node superclass fields
583 	 */
584 	CopyScanFields((const Scan *) from, (Scan *) newnode);
585 
586 	/*
587 	 * copy remainder of node
588 	 */
589 	COPY_NODE_FIELD(values_lists);
590 
591 	return newnode;
592 }
593 
594 /*
595  * _copyCteScan
596  */
597 static CteScan *
_copyCteScan(const CteScan * from)598 _copyCteScan(const CteScan *from)
599 {
600 	CteScan    *newnode = makeNode(CteScan);
601 
602 	/*
603 	 * copy node superclass fields
604 	 */
605 	CopyScanFields((const Scan *) from, (Scan *) newnode);
606 
607 	/*
608 	 * copy remainder of node
609 	 */
610 	COPY_SCALAR_FIELD(ctePlanId);
611 	COPY_SCALAR_FIELD(cteParam);
612 
613 	return newnode;
614 }
615 
616 /*
617  * _copyWorkTableScan
618  */
619 static WorkTableScan *
_copyWorkTableScan(const WorkTableScan * from)620 _copyWorkTableScan(const WorkTableScan *from)
621 {
622 	WorkTableScan *newnode = makeNode(WorkTableScan);
623 
624 	/*
625 	 * copy node superclass fields
626 	 */
627 	CopyScanFields((const Scan *) from, (Scan *) newnode);
628 
629 	/*
630 	 * copy remainder of node
631 	 */
632 	COPY_SCALAR_FIELD(wtParam);
633 
634 	return newnode;
635 }
636 
637 /*
638  * _copyForeignScan
639  */
640 static ForeignScan *
_copyForeignScan(const ForeignScan * from)641 _copyForeignScan(const ForeignScan *from)
642 {
643 	ForeignScan *newnode = makeNode(ForeignScan);
644 
645 	/*
646 	 * copy node superclass fields
647 	 */
648 	CopyScanFields((const Scan *) from, (Scan *) newnode);
649 
650 	/*
651 	 * copy remainder of node
652 	 */
653 	COPY_SCALAR_FIELD(operation);
654 	COPY_SCALAR_FIELD(fs_server);
655 	COPY_NODE_FIELD(fdw_exprs);
656 	COPY_NODE_FIELD(fdw_private);
657 	COPY_NODE_FIELD(fdw_scan_tlist);
658 	COPY_NODE_FIELD(fdw_recheck_quals);
659 	COPY_BITMAPSET_FIELD(fs_relids);
660 	COPY_SCALAR_FIELD(fsSystemCol);
661 
662 	return newnode;
663 }
664 
665 /*
666  * _copyCustomScan
667  */
668 static CustomScan *
_copyCustomScan(const CustomScan * from)669 _copyCustomScan(const CustomScan *from)
670 {
671 	CustomScan *newnode = makeNode(CustomScan);
672 
673 	/*
674 	 * copy node superclass fields
675 	 */
676 	CopyScanFields((const Scan *) from, (Scan *) newnode);
677 
678 	/*
679 	 * copy remainder of node
680 	 */
681 	COPY_SCALAR_FIELD(flags);
682 	COPY_NODE_FIELD(custom_plans);
683 	COPY_NODE_FIELD(custom_exprs);
684 	COPY_NODE_FIELD(custom_private);
685 	COPY_NODE_FIELD(custom_scan_tlist);
686 	COPY_BITMAPSET_FIELD(custom_relids);
687 
688 	/*
689 	 * NOTE: The method field of CustomScan is required to be a pointer to a
690 	 * static table of callback functions.  So we don't copy the table itself,
691 	 * just reference the original one.
692 	 */
693 	COPY_SCALAR_FIELD(methods);
694 
695 	return newnode;
696 }
697 
698 /*
699  * CopyJoinFields
700  *
701  *		This function copies the fields of the Join node.  It is used by
702  *		all the copy functions for classes which inherit from Join.
703  */
704 static void
CopyJoinFields(const Join * from,Join * newnode)705 CopyJoinFields(const Join *from, Join *newnode)
706 {
707 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
708 
709 	COPY_SCALAR_FIELD(jointype);
710 	COPY_NODE_FIELD(joinqual);
711 }
712 
713 
714 /*
715  * _copyJoin
716  */
717 static Join *
_copyJoin(const Join * from)718 _copyJoin(const Join *from)
719 {
720 	Join	   *newnode = makeNode(Join);
721 
722 	/*
723 	 * copy node superclass fields
724 	 */
725 	CopyJoinFields(from, newnode);
726 
727 	return newnode;
728 }
729 
730 
731 /*
732  * _copyNestLoop
733  */
734 static NestLoop *
_copyNestLoop(const NestLoop * from)735 _copyNestLoop(const NestLoop *from)
736 {
737 	NestLoop   *newnode = makeNode(NestLoop);
738 
739 	/*
740 	 * copy node superclass fields
741 	 */
742 	CopyJoinFields((const Join *) from, (Join *) newnode);
743 
744 	/*
745 	 * copy remainder of node
746 	 */
747 	COPY_NODE_FIELD(nestParams);
748 
749 	return newnode;
750 }
751 
752 
753 /*
754  * _copyMergeJoin
755  */
756 static MergeJoin *
_copyMergeJoin(const MergeJoin * from)757 _copyMergeJoin(const MergeJoin *from)
758 {
759 	MergeJoin  *newnode = makeNode(MergeJoin);
760 	int			numCols;
761 
762 	/*
763 	 * copy node superclass fields
764 	 */
765 	CopyJoinFields((const Join *) from, (Join *) newnode);
766 
767 	/*
768 	 * copy remainder of node
769 	 */
770 	COPY_NODE_FIELD(mergeclauses);
771 	numCols = list_length(from->mergeclauses);
772 	if (numCols > 0)
773 	{
774 		COPY_POINTER_FIELD(mergeFamilies, numCols * sizeof(Oid));
775 		COPY_POINTER_FIELD(mergeCollations, numCols * sizeof(Oid));
776 		COPY_POINTER_FIELD(mergeStrategies, numCols * sizeof(int));
777 		COPY_POINTER_FIELD(mergeNullsFirst, numCols * sizeof(bool));
778 	}
779 
780 	return newnode;
781 }
782 
783 /*
784  * _copyHashJoin
785  */
786 static HashJoin *
_copyHashJoin(const HashJoin * from)787 _copyHashJoin(const HashJoin *from)
788 {
789 	HashJoin   *newnode = makeNode(HashJoin);
790 
791 	/*
792 	 * copy node superclass fields
793 	 */
794 	CopyJoinFields((const Join *) from, (Join *) newnode);
795 
796 	/*
797 	 * copy remainder of node
798 	 */
799 	COPY_NODE_FIELD(hashclauses);
800 
801 	return newnode;
802 }
803 
804 
805 /*
806  * _copyMaterial
807  */
808 static Material *
_copyMaterial(const Material * from)809 _copyMaterial(const Material *from)
810 {
811 	Material   *newnode = makeNode(Material);
812 
813 	/*
814 	 * copy node superclass fields
815 	 */
816 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
817 
818 	return newnode;
819 }
820 
821 
822 /*
823  * _copySort
824  */
825 static Sort *
_copySort(const Sort * from)826 _copySort(const Sort *from)
827 {
828 	Sort	   *newnode = makeNode(Sort);
829 
830 	/*
831 	 * copy node superclass fields
832 	 */
833 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
834 
835 	COPY_SCALAR_FIELD(numCols);
836 	COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
837 	COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
838 	COPY_POINTER_FIELD(collations, from->numCols * sizeof(Oid));
839 	COPY_POINTER_FIELD(nullsFirst, from->numCols * sizeof(bool));
840 
841 	return newnode;
842 }
843 
844 
845 /*
846  * _copyGroup
847  */
848 static Group *
_copyGroup(const Group * from)849 _copyGroup(const Group *from)
850 {
851 	Group	   *newnode = makeNode(Group);
852 
853 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
854 
855 	COPY_SCALAR_FIELD(numCols);
856 	COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
857 	COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
858 
859 	return newnode;
860 }
861 
862 /*
863  * _copyAgg
864  */
865 static Agg *
_copyAgg(const Agg * from)866 _copyAgg(const Agg *from)
867 {
868 	Agg		   *newnode = makeNode(Agg);
869 
870 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
871 
872 	COPY_SCALAR_FIELD(aggstrategy);
873 	COPY_SCALAR_FIELD(aggsplit);
874 	COPY_SCALAR_FIELD(numCols);
875 	if (from->numCols > 0)
876 	{
877 		COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
878 		COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
879 	}
880 	COPY_SCALAR_FIELD(numGroups);
881 	COPY_NODE_FIELD(groupingSets);
882 	COPY_NODE_FIELD(chain);
883 
884 	return newnode;
885 }
886 
887 /*
888  * _copyWindowAgg
889  */
890 static WindowAgg *
_copyWindowAgg(const WindowAgg * from)891 _copyWindowAgg(const WindowAgg *from)
892 {
893 	WindowAgg  *newnode = makeNode(WindowAgg);
894 
895 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
896 
897 	COPY_SCALAR_FIELD(winref);
898 	COPY_SCALAR_FIELD(partNumCols);
899 	if (from->partNumCols > 0)
900 	{
901 		COPY_POINTER_FIELD(partColIdx, from->partNumCols * sizeof(AttrNumber));
902 		COPY_POINTER_FIELD(partOperators, from->partNumCols * sizeof(Oid));
903 	}
904 	COPY_SCALAR_FIELD(ordNumCols);
905 	if (from->ordNumCols > 0)
906 	{
907 		COPY_POINTER_FIELD(ordColIdx, from->ordNumCols * sizeof(AttrNumber));
908 		COPY_POINTER_FIELD(ordOperators, from->ordNumCols * sizeof(Oid));
909 	}
910 	COPY_SCALAR_FIELD(frameOptions);
911 	COPY_NODE_FIELD(startOffset);
912 	COPY_NODE_FIELD(endOffset);
913 
914 	return newnode;
915 }
916 
917 /*
918  * _copyUnique
919  */
920 static Unique *
_copyUnique(const Unique * from)921 _copyUnique(const Unique *from)
922 {
923 	Unique	   *newnode = makeNode(Unique);
924 
925 	/*
926 	 * copy node superclass fields
927 	 */
928 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
929 
930 	/*
931 	 * copy remainder of node
932 	 */
933 	COPY_SCALAR_FIELD(numCols);
934 	COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
935 	COPY_POINTER_FIELD(uniqOperators, from->numCols * sizeof(Oid));
936 
937 	return newnode;
938 }
939 
940 /*
941  * _copyHash
942  */
943 static Hash *
_copyHash(const Hash * from)944 _copyHash(const Hash *from)
945 {
946 	Hash	   *newnode = makeNode(Hash);
947 
948 	/*
949 	 * copy node superclass fields
950 	 */
951 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
952 
953 	/*
954 	 * copy remainder of node
955 	 */
956 	COPY_SCALAR_FIELD(skewTable);
957 	COPY_SCALAR_FIELD(skewColumn);
958 	COPY_SCALAR_FIELD(skewInherit);
959 	COPY_SCALAR_FIELD(skewColType);
960 	COPY_SCALAR_FIELD(skewColTypmod);
961 
962 	return newnode;
963 }
964 
965 /*
966  * _copySetOp
967  */
968 static SetOp *
_copySetOp(const SetOp * from)969 _copySetOp(const SetOp *from)
970 {
971 	SetOp	   *newnode = makeNode(SetOp);
972 
973 	/*
974 	 * copy node superclass fields
975 	 */
976 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
977 
978 	/*
979 	 * copy remainder of node
980 	 */
981 	COPY_SCALAR_FIELD(cmd);
982 	COPY_SCALAR_FIELD(strategy);
983 	COPY_SCALAR_FIELD(numCols);
984 	COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
985 	COPY_POINTER_FIELD(dupOperators, from->numCols * sizeof(Oid));
986 	COPY_SCALAR_FIELD(flagColIdx);
987 	COPY_SCALAR_FIELD(firstFlag);
988 	COPY_SCALAR_FIELD(numGroups);
989 
990 	return newnode;
991 }
992 
993 /*
994  * _copyLockRows
995  */
996 static LockRows *
_copyLockRows(const LockRows * from)997 _copyLockRows(const LockRows *from)
998 {
999 	LockRows   *newnode = makeNode(LockRows);
1000 
1001 	/*
1002 	 * copy node superclass fields
1003 	 */
1004 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
1005 
1006 	/*
1007 	 * copy remainder of node
1008 	 */
1009 	COPY_NODE_FIELD(rowMarks);
1010 	COPY_SCALAR_FIELD(epqParam);
1011 
1012 	return newnode;
1013 }
1014 
1015 /*
1016  * _copyLimit
1017  */
1018 static Limit *
_copyLimit(const Limit * from)1019 _copyLimit(const Limit *from)
1020 {
1021 	Limit	   *newnode = makeNode(Limit);
1022 
1023 	/*
1024 	 * copy node superclass fields
1025 	 */
1026 	CopyPlanFields((const Plan *) from, (Plan *) newnode);
1027 
1028 	/*
1029 	 * copy remainder of node
1030 	 */
1031 	COPY_NODE_FIELD(limitOffset);
1032 	COPY_NODE_FIELD(limitCount);
1033 
1034 	return newnode;
1035 }
1036 
1037 /*
1038  * _copyNestLoopParam
1039  */
1040 static NestLoopParam *
_copyNestLoopParam(const NestLoopParam * from)1041 _copyNestLoopParam(const NestLoopParam *from)
1042 {
1043 	NestLoopParam *newnode = makeNode(NestLoopParam);
1044 
1045 	COPY_SCALAR_FIELD(paramno);
1046 	COPY_NODE_FIELD(paramval);
1047 
1048 	return newnode;
1049 }
1050 
1051 /*
1052  * _copyPlanRowMark
1053  */
1054 static PlanRowMark *
_copyPlanRowMark(const PlanRowMark * from)1055 _copyPlanRowMark(const PlanRowMark *from)
1056 {
1057 	PlanRowMark *newnode = makeNode(PlanRowMark);
1058 
1059 	COPY_SCALAR_FIELD(rti);
1060 	COPY_SCALAR_FIELD(prti);
1061 	COPY_SCALAR_FIELD(rowmarkId);
1062 	COPY_SCALAR_FIELD(markType);
1063 	COPY_SCALAR_FIELD(allMarkTypes);
1064 	COPY_SCALAR_FIELD(strength);
1065 	COPY_SCALAR_FIELD(waitPolicy);
1066 	COPY_SCALAR_FIELD(isParent);
1067 
1068 	return newnode;
1069 }
1070 
1071 /*
1072  * _copyPlanInvalItem
1073  */
1074 static PlanInvalItem *
_copyPlanInvalItem(const PlanInvalItem * from)1075 _copyPlanInvalItem(const PlanInvalItem *from)
1076 {
1077 	PlanInvalItem *newnode = makeNode(PlanInvalItem);
1078 
1079 	COPY_SCALAR_FIELD(cacheId);
1080 	COPY_SCALAR_FIELD(hashValue);
1081 
1082 	return newnode;
1083 }
1084 #endif
1085 
1086 /* ****************************************************************
1087  *					   primnodes.h copy functions
1088  * ****************************************************************
1089  */
1090 
1091 /*
1092  * _copyAlias
1093  */
1094 static Alias *
_copyAlias(const Alias * from)1095 _copyAlias(const Alias *from)
1096 {
1097 	Alias	   *newnode = makeNode(Alias);
1098 
1099 	COPY_STRING_FIELD(aliasname);
1100 	COPY_NODE_FIELD(colnames);
1101 
1102 	return newnode;
1103 }
1104 
1105 /*
1106  * _copyRangeVar
1107  */
1108 static RangeVar *
_copyRangeVar(const RangeVar * from)1109 _copyRangeVar(const RangeVar *from)
1110 {
1111 	RangeVar   *newnode = makeNode(RangeVar);
1112 
1113 	COPY_STRING_FIELD(catalogname);
1114 	COPY_STRING_FIELD(schemaname);
1115 	COPY_STRING_FIELD(relname);
1116 	COPY_SCALAR_FIELD(inhOpt);
1117 	COPY_SCALAR_FIELD(relpersistence);
1118 	COPY_NODE_FIELD(alias);
1119 	COPY_LOCATION_FIELD(location);
1120 
1121 	return newnode;
1122 }
1123 
1124 /*
1125  * _copyIntoClause
1126  */
1127 static IntoClause *
_copyIntoClause(const IntoClause * from)1128 _copyIntoClause(const IntoClause *from)
1129 {
1130 	IntoClause *newnode = makeNode(IntoClause);
1131 
1132 	COPY_NODE_FIELD(rel);
1133 	COPY_NODE_FIELD(colNames);
1134 	COPY_NODE_FIELD(options);
1135 	COPY_SCALAR_FIELD(onCommit);
1136 	COPY_STRING_FIELD(tableSpaceName);
1137 	COPY_NODE_FIELD(viewQuery);
1138 	COPY_SCALAR_FIELD(skipData);
1139 
1140 	return newnode;
1141 }
1142 
1143 /*
1144  * We don't need a _copyExpr because Expr is an abstract supertype which
1145  * should never actually get instantiated.  Also, since it has no common
1146  * fields except NodeTag, there's no need for a helper routine to factor
1147  * out copying the common fields...
1148  */
1149 
1150 /*
1151  * _copyVar
1152  */
1153 static Var *
_copyVar(const Var * from)1154 _copyVar(const Var *from)
1155 {
1156 	Var		   *newnode = makeNode(Var);
1157 
1158 	COPY_SCALAR_FIELD(varno);
1159 	COPY_SCALAR_FIELD(varattno);
1160 	COPY_SCALAR_FIELD(vartype);
1161 	COPY_SCALAR_FIELD(vartypmod);
1162 	COPY_SCALAR_FIELD(varcollid);
1163 	COPY_SCALAR_FIELD(varlevelsup);
1164 	COPY_SCALAR_FIELD(varnoold);
1165 	COPY_SCALAR_FIELD(varoattno);
1166 	COPY_LOCATION_FIELD(location);
1167 
1168 	return newnode;
1169 }
1170 
1171 #ifdef NOT_USED_IN_PGPOOL
1172 /*
1173  * _copyConst
1174  */
1175 static Const *
_copyConst(const Const * from)1176 _copyConst(const Const *from)
1177 {
1178 	Const	   *newnode = makeNode(Const);
1179 
1180 	COPY_SCALAR_FIELD(consttype);
1181 	COPY_SCALAR_FIELD(consttypmod);
1182 	COPY_SCALAR_FIELD(constcollid);
1183 	COPY_SCALAR_FIELD(constlen);
1184 
1185 	if (from->constbyval || from->constisnull)
1186 	{
1187 		/*
1188 		 * passed by value so just copy the datum. Also, don't try to copy
1189 		 * struct when value is null!
1190 		 */
1191 		newnode->constvalue = from->constvalue;
1192 	}
1193 	else
1194 	{
1195 		/*
1196 		 * passed by reference.  We need a palloc'd copy.
1197 		 */
1198 		newnode->constvalue = datumCopy(from->constvalue,
1199 										from->constbyval,
1200 										from->constlen);
1201 	}
1202 
1203 	COPY_SCALAR_FIELD(constisnull);
1204 	COPY_SCALAR_FIELD(constbyval);
1205 	COPY_LOCATION_FIELD(location);
1206 
1207 	return newnode;
1208 }
1209 #endif
1210 
1211 /*
1212  * _copyParam
1213  */
1214 static Param *
_copyParam(const Param * from)1215 _copyParam(const Param *from)
1216 {
1217 	Param	   *newnode = makeNode(Param);
1218 
1219 	COPY_SCALAR_FIELD(paramkind);
1220 	COPY_SCALAR_FIELD(paramid);
1221 	COPY_SCALAR_FIELD(paramtype);
1222 	COPY_SCALAR_FIELD(paramtypmod);
1223 	COPY_SCALAR_FIELD(paramcollid);
1224 	COPY_LOCATION_FIELD(location);
1225 
1226 	return newnode;
1227 }
1228 
1229 /*
1230  * _copyAggref
1231  */
1232 static Aggref *
_copyAggref(const Aggref * from)1233 _copyAggref(const Aggref *from)
1234 {
1235 	Aggref	   *newnode = makeNode(Aggref);
1236 
1237 	COPY_SCALAR_FIELD(aggfnoid);
1238 	COPY_SCALAR_FIELD(aggtype);
1239 	COPY_SCALAR_FIELD(aggcollid);
1240 	COPY_SCALAR_FIELD(inputcollid);
1241 	COPY_SCALAR_FIELD(aggtranstype);
1242 	COPY_NODE_FIELD(aggargtypes);
1243 	COPY_NODE_FIELD(aggdirectargs);
1244 	COPY_NODE_FIELD(args);
1245 	COPY_NODE_FIELD(aggorder);
1246 	COPY_NODE_FIELD(aggdistinct);
1247 	COPY_NODE_FIELD(aggfilter);
1248 	COPY_SCALAR_FIELD(aggstar);
1249 	COPY_SCALAR_FIELD(aggvariadic);
1250 	COPY_SCALAR_FIELD(aggkind);
1251 	COPY_SCALAR_FIELD(agglevelsup);
1252 	COPY_SCALAR_FIELD(aggsplit);
1253 	COPY_LOCATION_FIELD(location);
1254 
1255 	return newnode;
1256 }
1257 
1258 /*
1259  * _copyGroupingFunc
1260  */
1261 static GroupingFunc *
_copyGroupingFunc(const GroupingFunc * from)1262 _copyGroupingFunc(const GroupingFunc *from)
1263 {
1264 	GroupingFunc *newnode = makeNode(GroupingFunc);
1265 
1266 	COPY_NODE_FIELD(args);
1267 	COPY_NODE_FIELD(refs);
1268 	COPY_NODE_FIELD(cols);
1269 	COPY_SCALAR_FIELD(agglevelsup);
1270 	COPY_LOCATION_FIELD(location);
1271 
1272 	return newnode;
1273 }
1274 
1275 /*
1276  * _copyWindowFunc
1277  */
1278 static WindowFunc *
_copyWindowFunc(const WindowFunc * from)1279 _copyWindowFunc(const WindowFunc *from)
1280 {
1281 	WindowFunc *newnode = makeNode(WindowFunc);
1282 
1283 	COPY_SCALAR_FIELD(winfnoid);
1284 	COPY_SCALAR_FIELD(wintype);
1285 	COPY_SCALAR_FIELD(wincollid);
1286 	COPY_SCALAR_FIELD(inputcollid);
1287 	COPY_NODE_FIELD(args);
1288 	COPY_NODE_FIELD(aggfilter);
1289 	COPY_SCALAR_FIELD(winref);
1290 	COPY_SCALAR_FIELD(winstar);
1291 	COPY_SCALAR_FIELD(winagg);
1292 	COPY_LOCATION_FIELD(location);
1293 
1294 	return newnode;
1295 }
1296 
1297 /*
1298  * _copyArrayRef
1299  */
1300 static ArrayRef *
_copyArrayRef(const ArrayRef * from)1301 _copyArrayRef(const ArrayRef *from)
1302 {
1303 	ArrayRef   *newnode = makeNode(ArrayRef);
1304 
1305 	COPY_SCALAR_FIELD(refarraytype);
1306 	COPY_SCALAR_FIELD(refelemtype);
1307 	COPY_SCALAR_FIELD(reftypmod);
1308 	COPY_SCALAR_FIELD(refcollid);
1309 	COPY_NODE_FIELD(refupperindexpr);
1310 	COPY_NODE_FIELD(reflowerindexpr);
1311 	COPY_NODE_FIELD(refexpr);
1312 	COPY_NODE_FIELD(refassgnexpr);
1313 
1314 	return newnode;
1315 }
1316 
1317 /*
1318  * _copyFuncExpr
1319  */
1320 static FuncExpr *
_copyFuncExpr(const FuncExpr * from)1321 _copyFuncExpr(const FuncExpr *from)
1322 {
1323 	FuncExpr   *newnode = makeNode(FuncExpr);
1324 
1325 	COPY_SCALAR_FIELD(funcid);
1326 	COPY_SCALAR_FIELD(funcresulttype);
1327 	COPY_SCALAR_FIELD(funcretset);
1328 	COPY_SCALAR_FIELD(funcvariadic);
1329 	COPY_SCALAR_FIELD(funcformat);
1330 	COPY_SCALAR_FIELD(funccollid);
1331 	COPY_SCALAR_FIELD(inputcollid);
1332 	COPY_NODE_FIELD(args);
1333 	COPY_LOCATION_FIELD(location);
1334 
1335 	return newnode;
1336 }
1337 
1338 /*
1339  * _copyNamedArgExpr *
1340  */
1341 static NamedArgExpr *
_copyNamedArgExpr(const NamedArgExpr * from)1342 _copyNamedArgExpr(const NamedArgExpr *from)
1343 {
1344 	NamedArgExpr *newnode = makeNode(NamedArgExpr);
1345 
1346 	COPY_NODE_FIELD(arg);
1347 	COPY_STRING_FIELD(name);
1348 	COPY_SCALAR_FIELD(argnumber);
1349 	COPY_LOCATION_FIELD(location);
1350 
1351 	return newnode;
1352 }
1353 
1354 /*
1355  * _copyOpExpr
1356  */
1357 static OpExpr *
_copyOpExpr(const OpExpr * from)1358 _copyOpExpr(const OpExpr *from)
1359 {
1360 	OpExpr	   *newnode = makeNode(OpExpr);
1361 
1362 	COPY_SCALAR_FIELD(opno);
1363 	COPY_SCALAR_FIELD(opfuncid);
1364 	COPY_SCALAR_FIELD(opresulttype);
1365 	COPY_SCALAR_FIELD(opretset);
1366 	COPY_SCALAR_FIELD(opcollid);
1367 	COPY_SCALAR_FIELD(inputcollid);
1368 	COPY_NODE_FIELD(args);
1369 	COPY_LOCATION_FIELD(location);
1370 
1371 	return newnode;
1372 }
1373 
1374 /*
1375  * _copyDistinctExpr (same as OpExpr)
1376  */
1377 static DistinctExpr *
_copyDistinctExpr(const DistinctExpr * from)1378 _copyDistinctExpr(const DistinctExpr *from)
1379 {
1380 	DistinctExpr *newnode = makeNode(DistinctExpr);
1381 
1382 	COPY_SCALAR_FIELD(opno);
1383 	COPY_SCALAR_FIELD(opfuncid);
1384 	COPY_SCALAR_FIELD(opresulttype);
1385 	COPY_SCALAR_FIELD(opretset);
1386 	COPY_SCALAR_FIELD(opcollid);
1387 	COPY_SCALAR_FIELD(inputcollid);
1388 	COPY_NODE_FIELD(args);
1389 	COPY_LOCATION_FIELD(location);
1390 
1391 	return newnode;
1392 }
1393 
1394 /*
1395  * _copyNullIfExpr (same as OpExpr)
1396  */
1397 static NullIfExpr *
_copyNullIfExpr(const NullIfExpr * from)1398 _copyNullIfExpr(const NullIfExpr *from)
1399 {
1400 	NullIfExpr *newnode = makeNode(NullIfExpr);
1401 
1402 	COPY_SCALAR_FIELD(opno);
1403 	COPY_SCALAR_FIELD(opfuncid);
1404 	COPY_SCALAR_FIELD(opresulttype);
1405 	COPY_SCALAR_FIELD(opretset);
1406 	COPY_SCALAR_FIELD(opcollid);
1407 	COPY_SCALAR_FIELD(inputcollid);
1408 	COPY_NODE_FIELD(args);
1409 	COPY_LOCATION_FIELD(location);
1410 
1411 	return newnode;
1412 }
1413 
1414 /*
1415  * _copyScalarArrayOpExpr
1416  */
1417 static ScalarArrayOpExpr *
_copyScalarArrayOpExpr(const ScalarArrayOpExpr * from)1418 _copyScalarArrayOpExpr(const ScalarArrayOpExpr *from)
1419 {
1420 	ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
1421 
1422 	COPY_SCALAR_FIELD(opno);
1423 	COPY_SCALAR_FIELD(opfuncid);
1424 	COPY_SCALAR_FIELD(useOr);
1425 	COPY_SCALAR_FIELD(inputcollid);
1426 	COPY_NODE_FIELD(args);
1427 	COPY_LOCATION_FIELD(location);
1428 
1429 	return newnode;
1430 }
1431 
1432 /*
1433  * _copyBoolExpr
1434  */
1435 static BoolExpr *
_copyBoolExpr(const BoolExpr * from)1436 _copyBoolExpr(const BoolExpr *from)
1437 {
1438 	BoolExpr   *newnode = makeNode(BoolExpr);
1439 
1440 	COPY_SCALAR_FIELD(boolop);
1441 	COPY_NODE_FIELD(args);
1442 	COPY_LOCATION_FIELD(location);
1443 
1444 	return newnode;
1445 }
1446 
1447 /*
1448  * _copySubLink
1449  */
1450 static SubLink *
_copySubLink(const SubLink * from)1451 _copySubLink(const SubLink *from)
1452 {
1453 	SubLink    *newnode = makeNode(SubLink);
1454 
1455 	COPY_SCALAR_FIELD(subLinkType);
1456 	COPY_SCALAR_FIELD(subLinkId);
1457 	COPY_NODE_FIELD(testexpr);
1458 	COPY_NODE_FIELD(operName);
1459 	COPY_NODE_FIELD(subselect);
1460 	COPY_LOCATION_FIELD(location);
1461 
1462 	return newnode;
1463 }
1464 
1465 /*
1466  * _copySubPlan
1467  */
1468 static SubPlan *
_copySubPlan(const SubPlan * from)1469 _copySubPlan(const SubPlan *from)
1470 {
1471 	SubPlan    *newnode = makeNode(SubPlan);
1472 
1473 	COPY_SCALAR_FIELD(subLinkType);
1474 	COPY_NODE_FIELD(testexpr);
1475 	COPY_NODE_FIELD(paramIds);
1476 	COPY_SCALAR_FIELD(plan_id);
1477 	COPY_STRING_FIELD(plan_name);
1478 	COPY_SCALAR_FIELD(firstColType);
1479 	COPY_SCALAR_FIELD(firstColTypmod);
1480 	COPY_SCALAR_FIELD(firstColCollation);
1481 	COPY_SCALAR_FIELD(useHashTable);
1482 	COPY_SCALAR_FIELD(unknownEqFalse);
1483 	COPY_NODE_FIELD(setParam);
1484 	COPY_NODE_FIELD(parParam);
1485 	COPY_NODE_FIELD(args);
1486 	COPY_SCALAR_FIELD(startup_cost);
1487 	COPY_SCALAR_FIELD(per_call_cost);
1488 
1489 	return newnode;
1490 }
1491 
1492 /*
1493  * _copyAlternativeSubPlan
1494  */
1495 static AlternativeSubPlan *
_copyAlternativeSubPlan(const AlternativeSubPlan * from)1496 _copyAlternativeSubPlan(const AlternativeSubPlan *from)
1497 {
1498 	AlternativeSubPlan *newnode = makeNode(AlternativeSubPlan);
1499 
1500 	COPY_NODE_FIELD(subplans);
1501 
1502 	return newnode;
1503 }
1504 
1505 /*
1506  * _copyFieldSelect
1507  */
1508 static FieldSelect *
_copyFieldSelect(const FieldSelect * from)1509 _copyFieldSelect(const FieldSelect *from)
1510 {
1511 	FieldSelect *newnode = makeNode(FieldSelect);
1512 
1513 	COPY_NODE_FIELD(arg);
1514 	COPY_SCALAR_FIELD(fieldnum);
1515 	COPY_SCALAR_FIELD(resulttype);
1516 	COPY_SCALAR_FIELD(resulttypmod);
1517 	COPY_SCALAR_FIELD(resultcollid);
1518 
1519 	return newnode;
1520 }
1521 
1522 /*
1523  * _copyFieldStore
1524  */
1525 static FieldStore *
_copyFieldStore(const FieldStore * from)1526 _copyFieldStore(const FieldStore *from)
1527 {
1528 	FieldStore *newnode = makeNode(FieldStore);
1529 
1530 	COPY_NODE_FIELD(arg);
1531 	COPY_NODE_FIELD(newvals);
1532 	COPY_NODE_FIELD(fieldnums);
1533 	COPY_SCALAR_FIELD(resulttype);
1534 
1535 	return newnode;
1536 }
1537 
1538 /*
1539  * _copyRelabelType
1540  */
1541 static RelabelType *
_copyRelabelType(const RelabelType * from)1542 _copyRelabelType(const RelabelType *from)
1543 {
1544 	RelabelType *newnode = makeNode(RelabelType);
1545 
1546 	COPY_NODE_FIELD(arg);
1547 	COPY_SCALAR_FIELD(resulttype);
1548 	COPY_SCALAR_FIELD(resulttypmod);
1549 	COPY_SCALAR_FIELD(resultcollid);
1550 	COPY_SCALAR_FIELD(relabelformat);
1551 	COPY_LOCATION_FIELD(location);
1552 
1553 	return newnode;
1554 }
1555 
1556 /*
1557  * _copyCoerceViaIO
1558  */
1559 static CoerceViaIO *
_copyCoerceViaIO(const CoerceViaIO * from)1560 _copyCoerceViaIO(const CoerceViaIO *from)
1561 {
1562 	CoerceViaIO *newnode = makeNode(CoerceViaIO);
1563 
1564 	COPY_NODE_FIELD(arg);
1565 	COPY_SCALAR_FIELD(resulttype);
1566 	COPY_SCALAR_FIELD(resultcollid);
1567 	COPY_SCALAR_FIELD(coerceformat);
1568 	COPY_LOCATION_FIELD(location);
1569 
1570 	return newnode;
1571 }
1572 
1573 /*
1574  * _copyArrayCoerceExpr
1575  */
1576 static ArrayCoerceExpr *
_copyArrayCoerceExpr(const ArrayCoerceExpr * from)1577 _copyArrayCoerceExpr(const ArrayCoerceExpr *from)
1578 {
1579 	ArrayCoerceExpr *newnode = makeNode(ArrayCoerceExpr);
1580 
1581 	COPY_NODE_FIELD(arg);
1582 	COPY_SCALAR_FIELD(elemfuncid);
1583 	COPY_SCALAR_FIELD(resulttype);
1584 	COPY_SCALAR_FIELD(resulttypmod);
1585 	COPY_SCALAR_FIELD(resultcollid);
1586 	COPY_SCALAR_FIELD(isExplicit);
1587 	COPY_SCALAR_FIELD(coerceformat);
1588 	COPY_LOCATION_FIELD(location);
1589 
1590 	return newnode;
1591 }
1592 
1593 /*
1594  * _copyConvertRowtypeExpr
1595  */
1596 static ConvertRowtypeExpr *
_copyConvertRowtypeExpr(const ConvertRowtypeExpr * from)1597 _copyConvertRowtypeExpr(const ConvertRowtypeExpr *from)
1598 {
1599 	ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);
1600 
1601 	COPY_NODE_FIELD(arg);
1602 	COPY_SCALAR_FIELD(resulttype);
1603 	COPY_SCALAR_FIELD(convertformat);
1604 	COPY_LOCATION_FIELD(location);
1605 
1606 	return newnode;
1607 }
1608 
1609 /*
1610  * _copyCollateExpr
1611  */
1612 static CollateExpr *
_copyCollateExpr(const CollateExpr * from)1613 _copyCollateExpr(const CollateExpr *from)
1614 {
1615 	CollateExpr *newnode = makeNode(CollateExpr);
1616 
1617 	COPY_NODE_FIELD(arg);
1618 	COPY_SCALAR_FIELD(collOid);
1619 	COPY_LOCATION_FIELD(location);
1620 
1621 	return newnode;
1622 }
1623 
1624 /*
1625  * _copyCaseExpr
1626  */
1627 static CaseExpr *
_copyCaseExpr(const CaseExpr * from)1628 _copyCaseExpr(const CaseExpr *from)
1629 {
1630 	CaseExpr   *newnode = makeNode(CaseExpr);
1631 
1632 	COPY_SCALAR_FIELD(casetype);
1633 	COPY_SCALAR_FIELD(casecollid);
1634 	COPY_NODE_FIELD(arg);
1635 	COPY_NODE_FIELD(args);
1636 	COPY_NODE_FIELD(defresult);
1637 	COPY_LOCATION_FIELD(location);
1638 
1639 	return newnode;
1640 }
1641 
1642 /*
1643  * _copyCaseWhen
1644  */
1645 static CaseWhen *
_copyCaseWhen(const CaseWhen * from)1646 _copyCaseWhen(const CaseWhen *from)
1647 {
1648 	CaseWhen   *newnode = makeNode(CaseWhen);
1649 
1650 	COPY_NODE_FIELD(expr);
1651 	COPY_NODE_FIELD(result);
1652 	COPY_LOCATION_FIELD(location);
1653 
1654 	return newnode;
1655 }
1656 
1657 /*
1658  * _copyCaseTestExpr
1659  */
1660 static CaseTestExpr *
_copyCaseTestExpr(const CaseTestExpr * from)1661 _copyCaseTestExpr(const CaseTestExpr *from)
1662 {
1663 	CaseTestExpr *newnode = makeNode(CaseTestExpr);
1664 
1665 	COPY_SCALAR_FIELD(typeId);
1666 	COPY_SCALAR_FIELD(typeMod);
1667 	COPY_SCALAR_FIELD(collation);
1668 
1669 	return newnode;
1670 }
1671 
1672 /*
1673  * _copyArrayExpr
1674  */
1675 static ArrayExpr *
_copyArrayExpr(const ArrayExpr * from)1676 _copyArrayExpr(const ArrayExpr *from)
1677 {
1678 	ArrayExpr  *newnode = makeNode(ArrayExpr);
1679 
1680 	COPY_SCALAR_FIELD(array_typeid);
1681 	COPY_SCALAR_FIELD(array_collid);
1682 	COPY_SCALAR_FIELD(element_typeid);
1683 	COPY_NODE_FIELD(elements);
1684 	COPY_SCALAR_FIELD(multidims);
1685 	COPY_LOCATION_FIELD(location);
1686 
1687 	return newnode;
1688 }
1689 
1690 /*
1691  * _copyRowExpr
1692  */
1693 static RowExpr *
_copyRowExpr(const RowExpr * from)1694 _copyRowExpr(const RowExpr *from)
1695 {
1696 	RowExpr    *newnode = makeNode(RowExpr);
1697 
1698 	COPY_NODE_FIELD(args);
1699 	COPY_SCALAR_FIELD(row_typeid);
1700 	COPY_SCALAR_FIELD(row_format);
1701 	COPY_NODE_FIELD(colnames);
1702 	COPY_LOCATION_FIELD(location);
1703 
1704 	return newnode;
1705 }
1706 
1707 /*
1708  * _copyRowCompareExpr
1709  */
1710 static RowCompareExpr *
_copyRowCompareExpr(const RowCompareExpr * from)1711 _copyRowCompareExpr(const RowCompareExpr *from)
1712 {
1713 	RowCompareExpr *newnode = makeNode(RowCompareExpr);
1714 
1715 	COPY_SCALAR_FIELD(rctype);
1716 	COPY_NODE_FIELD(opnos);
1717 	COPY_NODE_FIELD(opfamilies);
1718 	COPY_NODE_FIELD(inputcollids);
1719 	COPY_NODE_FIELD(largs);
1720 	COPY_NODE_FIELD(rargs);
1721 
1722 	return newnode;
1723 }
1724 
1725 /*
1726  * _copyCoalesceExpr
1727  */
1728 static CoalesceExpr *
_copyCoalesceExpr(const CoalesceExpr * from)1729 _copyCoalesceExpr(const CoalesceExpr *from)
1730 {
1731 	CoalesceExpr *newnode = makeNode(CoalesceExpr);
1732 
1733 	COPY_SCALAR_FIELD(coalescetype);
1734 	COPY_SCALAR_FIELD(coalescecollid);
1735 	COPY_NODE_FIELD(args);
1736 	COPY_LOCATION_FIELD(location);
1737 
1738 	return newnode;
1739 }
1740 
1741 /*
1742  * _copyMinMaxExpr
1743  */
1744 static MinMaxExpr *
_copyMinMaxExpr(const MinMaxExpr * from)1745 _copyMinMaxExpr(const MinMaxExpr *from)
1746 {
1747 	MinMaxExpr *newnode = makeNode(MinMaxExpr);
1748 
1749 	COPY_SCALAR_FIELD(minmaxtype);
1750 	COPY_SCALAR_FIELD(minmaxcollid);
1751 	COPY_SCALAR_FIELD(inputcollid);
1752 	COPY_SCALAR_FIELD(op);
1753 	COPY_NODE_FIELD(args);
1754 	COPY_LOCATION_FIELD(location);
1755 
1756 	return newnode;
1757 }
1758 
1759 /*
1760  * _copyXmlExpr
1761  */
1762 static XmlExpr *
_copyXmlExpr(const XmlExpr * from)1763 _copyXmlExpr(const XmlExpr *from)
1764 {
1765 	XmlExpr    *newnode = makeNode(XmlExpr);
1766 
1767 	COPY_SCALAR_FIELD(op);
1768 	COPY_STRING_FIELD(name);
1769 	COPY_NODE_FIELD(named_args);
1770 	COPY_NODE_FIELD(arg_names);
1771 	COPY_NODE_FIELD(args);
1772 	COPY_SCALAR_FIELD(xmloption);
1773 	COPY_SCALAR_FIELD(type);
1774 	COPY_SCALAR_FIELD(typmod);
1775 	COPY_LOCATION_FIELD(location);
1776 
1777 	return newnode;
1778 }
1779 
1780 /*
1781  * _copyNullTest
1782  */
1783 static NullTest *
_copyNullTest(const NullTest * from)1784 _copyNullTest(const NullTest *from)
1785 {
1786 	NullTest   *newnode = makeNode(NullTest);
1787 
1788 	COPY_NODE_FIELD(arg);
1789 	COPY_SCALAR_FIELD(nulltesttype);
1790 	COPY_SCALAR_FIELD(argisrow);
1791 	COPY_LOCATION_FIELD(location);
1792 
1793 	return newnode;
1794 }
1795 
1796 /*
1797  * _copyBooleanTest
1798  */
1799 static BooleanTest *
_copyBooleanTest(const BooleanTest * from)1800 _copyBooleanTest(const BooleanTest *from)
1801 {
1802 	BooleanTest *newnode = makeNode(BooleanTest);
1803 
1804 	COPY_NODE_FIELD(arg);
1805 	COPY_SCALAR_FIELD(booltesttype);
1806 	COPY_LOCATION_FIELD(location);
1807 
1808 	return newnode;
1809 }
1810 
1811 /*
1812  * _copyCoerceToDomain
1813  */
1814 static CoerceToDomain *
_copyCoerceToDomain(const CoerceToDomain * from)1815 _copyCoerceToDomain(const CoerceToDomain *from)
1816 {
1817 	CoerceToDomain *newnode = makeNode(CoerceToDomain);
1818 
1819 	COPY_NODE_FIELD(arg);
1820 	COPY_SCALAR_FIELD(resulttype);
1821 	COPY_SCALAR_FIELD(resulttypmod);
1822 	COPY_SCALAR_FIELD(resultcollid);
1823 	COPY_SCALAR_FIELD(coercionformat);
1824 	COPY_LOCATION_FIELD(location);
1825 
1826 	return newnode;
1827 }
1828 
1829 /*
1830  * _copyCoerceToDomainValue
1831  */
1832 static CoerceToDomainValue *
_copyCoerceToDomainValue(const CoerceToDomainValue * from)1833 _copyCoerceToDomainValue(const CoerceToDomainValue *from)
1834 {
1835 	CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1836 
1837 	COPY_SCALAR_FIELD(typeId);
1838 	COPY_SCALAR_FIELD(typeMod);
1839 	COPY_SCALAR_FIELD(collation);
1840 	COPY_LOCATION_FIELD(location);
1841 
1842 	return newnode;
1843 }
1844 
1845 /*
1846  * _copySetToDefault
1847  */
1848 static SetToDefault *
_copySetToDefault(const SetToDefault * from)1849 _copySetToDefault(const SetToDefault *from)
1850 {
1851 	SetToDefault *newnode = makeNode(SetToDefault);
1852 
1853 	COPY_SCALAR_FIELD(typeId);
1854 	COPY_SCALAR_FIELD(typeMod);
1855 	COPY_SCALAR_FIELD(collation);
1856 	COPY_LOCATION_FIELD(location);
1857 
1858 	return newnode;
1859 }
1860 
1861 /*
1862  * _copyCurrentOfExpr
1863  */
1864 static CurrentOfExpr *
_copyCurrentOfExpr(const CurrentOfExpr * from)1865 _copyCurrentOfExpr(const CurrentOfExpr *from)
1866 {
1867 	CurrentOfExpr *newnode = makeNode(CurrentOfExpr);
1868 
1869 	COPY_SCALAR_FIELD(cvarno);
1870 	COPY_STRING_FIELD(cursor_name);
1871 	COPY_SCALAR_FIELD(cursor_param);
1872 
1873 	return newnode;
1874 }
1875 
1876 /*
1877  * _copyInferenceElem
1878  */
1879 static InferenceElem *
_copyInferenceElem(const InferenceElem * from)1880 _copyInferenceElem(const InferenceElem *from)
1881 {
1882 	InferenceElem *newnode = makeNode(InferenceElem);
1883 
1884 	COPY_NODE_FIELD(expr);
1885 	COPY_SCALAR_FIELD(infercollid);
1886 	COPY_SCALAR_FIELD(inferopclass);
1887 
1888 	return newnode;
1889 }
1890 
1891 /*
1892  * _copyTargetEntry
1893  */
1894 static TargetEntry *
_copyTargetEntry(const TargetEntry * from)1895 _copyTargetEntry(const TargetEntry *from)
1896 {
1897 	TargetEntry *newnode = makeNode(TargetEntry);
1898 
1899 	COPY_NODE_FIELD(expr);
1900 	COPY_SCALAR_FIELD(resno);
1901 	COPY_STRING_FIELD(resname);
1902 	COPY_SCALAR_FIELD(ressortgroupref);
1903 	COPY_SCALAR_FIELD(resorigtbl);
1904 	COPY_SCALAR_FIELD(resorigcol);
1905 	COPY_SCALAR_FIELD(resjunk);
1906 
1907 	return newnode;
1908 }
1909 
1910 /*
1911  * _copyRangeTblRef
1912  */
1913 static RangeTblRef *
_copyRangeTblRef(const RangeTblRef * from)1914 _copyRangeTblRef(const RangeTblRef *from)
1915 {
1916 	RangeTblRef *newnode = makeNode(RangeTblRef);
1917 
1918 	COPY_SCALAR_FIELD(rtindex);
1919 
1920 	return newnode;
1921 }
1922 
1923 /*
1924  * _copyJoinExpr
1925  */
1926 static JoinExpr *
_copyJoinExpr(const JoinExpr * from)1927 _copyJoinExpr(const JoinExpr *from)
1928 {
1929 	JoinExpr   *newnode = makeNode(JoinExpr);
1930 
1931 	COPY_SCALAR_FIELD(jointype);
1932 	COPY_SCALAR_FIELD(isNatural);
1933 	COPY_NODE_FIELD(larg);
1934 	COPY_NODE_FIELD(rarg);
1935 	COPY_NODE_FIELD(usingClause);
1936 	COPY_NODE_FIELD(quals);
1937 	COPY_NODE_FIELD(alias);
1938 	COPY_SCALAR_FIELD(rtindex);
1939 
1940 	return newnode;
1941 }
1942 
1943 /*
1944  * _copyFromExpr
1945  */
1946 static FromExpr *
_copyFromExpr(const FromExpr * from)1947 _copyFromExpr(const FromExpr *from)
1948 {
1949 	FromExpr   *newnode = makeNode(FromExpr);
1950 
1951 	COPY_NODE_FIELD(fromlist);
1952 	COPY_NODE_FIELD(quals);
1953 
1954 	return newnode;
1955 }
1956 
1957 /*
1958  * _copyOnConflictExpr
1959  */
1960 static OnConflictExpr *
_copyOnConflictExpr(const OnConflictExpr * from)1961 _copyOnConflictExpr(const OnConflictExpr *from)
1962 {
1963 	OnConflictExpr *newnode = makeNode(OnConflictExpr);
1964 
1965 	COPY_SCALAR_FIELD(action);
1966 	COPY_NODE_FIELD(arbiterElems);
1967 	COPY_NODE_FIELD(arbiterWhere);
1968 	COPY_SCALAR_FIELD(constraint);
1969 	COPY_NODE_FIELD(onConflictSet);
1970 	COPY_NODE_FIELD(onConflictWhere);
1971 	COPY_SCALAR_FIELD(exclRelIndex);
1972 	COPY_NODE_FIELD(exclRelTlist);
1973 
1974 	return newnode;
1975 }
1976 
1977 /* ****************************************************************
1978  *						relation.h copy functions
1979  *
1980  * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1981  * There are some subsidiary structs that are useful to copy, though.
1982  * ****************************************************************
1983  */
1984 
1985 #ifdef NOT_USED_IN_PGPOOL
1986 /*
1987  * _copyPathKey
1988  */
1989 static PathKey *
_copyPathKey(const PathKey * from)1990 _copyPathKey(const PathKey *from)
1991 {
1992 	PathKey    *newnode = makeNode(PathKey);
1993 
1994 	/* EquivalenceClasses are never moved, so just shallow-copy the pointer */
1995 	COPY_SCALAR_FIELD(pk_eclass);
1996 	COPY_SCALAR_FIELD(pk_opfamily);
1997 	COPY_SCALAR_FIELD(pk_strategy);
1998 	COPY_SCALAR_FIELD(pk_nulls_first);
1999 
2000 	return newnode;
2001 }
2002 
2003 /*
2004  * _copyRestrictInfo
2005  */
2006 static RestrictInfo *
_copyRestrictInfo(const RestrictInfo * from)2007 _copyRestrictInfo(const RestrictInfo *from)
2008 {
2009 	RestrictInfo *newnode = makeNode(RestrictInfo);
2010 
2011 	COPY_NODE_FIELD(clause);
2012 	COPY_SCALAR_FIELD(is_pushed_down);
2013 	COPY_SCALAR_FIELD(outerjoin_delayed);
2014 	COPY_SCALAR_FIELD(can_join);
2015 	COPY_SCALAR_FIELD(pseudoconstant);
2016 	COPY_BITMAPSET_FIELD(clause_relids);
2017 	COPY_BITMAPSET_FIELD(required_relids);
2018 	COPY_BITMAPSET_FIELD(outer_relids);
2019 	COPY_BITMAPSET_FIELD(nullable_relids);
2020 	COPY_BITMAPSET_FIELD(left_relids);
2021 	COPY_BITMAPSET_FIELD(right_relids);
2022 	COPY_NODE_FIELD(orclause);
2023 	/* EquivalenceClasses are never copied, so shallow-copy the pointers */
2024 	COPY_SCALAR_FIELD(parent_ec);
2025 	COPY_SCALAR_FIELD(eval_cost);
2026 	COPY_SCALAR_FIELD(norm_selec);
2027 	COPY_SCALAR_FIELD(outer_selec);
2028 	COPY_NODE_FIELD(mergeopfamilies);
2029 	/* EquivalenceClasses are never copied, so shallow-copy the pointers */
2030 	COPY_SCALAR_FIELD(left_ec);
2031 	COPY_SCALAR_FIELD(right_ec);
2032 	COPY_SCALAR_FIELD(left_em);
2033 	COPY_SCALAR_FIELD(right_em);
2034 	/* MergeScanSelCache isn't a Node, so hard to copy; just reset cache */
2035 	newnode->scansel_cache = NIL;
2036 	COPY_SCALAR_FIELD(outer_is_left);
2037 	COPY_SCALAR_FIELD(hashjoinoperator);
2038 	COPY_SCALAR_FIELD(left_bucketsize);
2039 	COPY_SCALAR_FIELD(right_bucketsize);
2040 
2041 	return newnode;
2042 }
2043 
2044 /*
2045  * _copyPlaceHolderVar
2046  */
2047 static PlaceHolderVar *
_copyPlaceHolderVar(const PlaceHolderVar * from)2048 _copyPlaceHolderVar(const PlaceHolderVar *from)
2049 {
2050 	PlaceHolderVar *newnode = makeNode(PlaceHolderVar);
2051 
2052 	COPY_NODE_FIELD(phexpr);
2053 	COPY_BITMAPSET_FIELD(phrels);
2054 	COPY_SCALAR_FIELD(phid);
2055 	COPY_SCALAR_FIELD(phlevelsup);
2056 
2057 	return newnode;
2058 }
2059 
2060 /*
2061  * _copySpecialJoinInfo
2062  */
2063 static SpecialJoinInfo *
_copySpecialJoinInfo(const SpecialJoinInfo * from)2064 _copySpecialJoinInfo(const SpecialJoinInfo *from)
2065 {
2066 	SpecialJoinInfo *newnode = makeNode(SpecialJoinInfo);
2067 
2068 	COPY_BITMAPSET_FIELD(min_lefthand);
2069 	COPY_BITMAPSET_FIELD(min_righthand);
2070 	COPY_BITMAPSET_FIELD(syn_lefthand);
2071 	COPY_BITMAPSET_FIELD(syn_righthand);
2072 	COPY_SCALAR_FIELD(jointype);
2073 	COPY_SCALAR_FIELD(lhs_strict);
2074 	COPY_SCALAR_FIELD(delay_upper_joins);
2075 	COPY_SCALAR_FIELD(semi_can_btree);
2076 	COPY_SCALAR_FIELD(semi_can_hash);
2077 	COPY_NODE_FIELD(semi_operators);
2078 	COPY_NODE_FIELD(semi_rhs_exprs);
2079 
2080 	return newnode;
2081 }
2082 
2083 /*
2084  * _copyAppendRelInfo
2085  */
2086 static AppendRelInfo *
_copyAppendRelInfo(const AppendRelInfo * from)2087 _copyAppendRelInfo(const AppendRelInfo *from)
2088 {
2089 	AppendRelInfo *newnode = makeNode(AppendRelInfo);
2090 
2091 	COPY_SCALAR_FIELD(parent_relid);
2092 	COPY_SCALAR_FIELD(child_relid);
2093 	COPY_SCALAR_FIELD(parent_reltype);
2094 	COPY_SCALAR_FIELD(child_reltype);
2095 	COPY_NODE_FIELD(translated_vars);
2096 	COPY_SCALAR_FIELD(parent_reloid);
2097 
2098 	return newnode;
2099 }
2100 
2101 /*
2102  * _copyPlaceHolderInfo
2103  */
2104 static PlaceHolderInfo *
_copyPlaceHolderInfo(const PlaceHolderInfo * from)2105 _copyPlaceHolderInfo(const PlaceHolderInfo *from)
2106 {
2107 	PlaceHolderInfo *newnode = makeNode(PlaceHolderInfo);
2108 
2109 	COPY_SCALAR_FIELD(phid);
2110 	COPY_NODE_FIELD(ph_var);
2111 	COPY_BITMAPSET_FIELD(ph_eval_at);
2112 	COPY_BITMAPSET_FIELD(ph_lateral);
2113 	COPY_BITMAPSET_FIELD(ph_needed);
2114 	COPY_SCALAR_FIELD(ph_width);
2115 
2116 	return newnode;
2117 }
2118 #endif
2119 
2120 /* ****************************************************************
2121  *					parsenodes.h copy functions
2122  * ****************************************************************
2123  */
2124 
2125 static RangeTblEntry *
_copyRangeTblEntry(const RangeTblEntry * from)2126 _copyRangeTblEntry(const RangeTblEntry *from)
2127 {
2128 	RangeTblEntry *newnode = makeNode(RangeTblEntry);
2129 
2130 	COPY_SCALAR_FIELD(rtekind);
2131 	COPY_SCALAR_FIELD(relid);
2132 	COPY_SCALAR_FIELD(relkind);
2133 	COPY_NODE_FIELD(tablesample);
2134 	COPY_NODE_FIELD(subquery);
2135 	COPY_SCALAR_FIELD(security_barrier);
2136 	COPY_SCALAR_FIELD(jointype);
2137 	COPY_NODE_FIELD(joinaliasvars);
2138 	COPY_NODE_FIELD(functions);
2139 	COPY_SCALAR_FIELD(funcordinality);
2140 	COPY_NODE_FIELD(values_lists);
2141 	COPY_NODE_FIELD(values_collations);
2142 	COPY_STRING_FIELD(ctename);
2143 	COPY_SCALAR_FIELD(ctelevelsup);
2144 	COPY_SCALAR_FIELD(self_reference);
2145 	COPY_NODE_FIELD(ctecoltypes);
2146 	COPY_NODE_FIELD(ctecoltypmods);
2147 	COPY_NODE_FIELD(ctecolcollations);
2148 	COPY_NODE_FIELD(alias);
2149 	COPY_NODE_FIELD(eref);
2150 	COPY_SCALAR_FIELD(lateral);
2151 	COPY_SCALAR_FIELD(inh);
2152 	COPY_SCALAR_FIELD(inFromCl);
2153 	COPY_SCALAR_FIELD(requiredPerms);
2154 	COPY_SCALAR_FIELD(checkAsUser);
2155 	COPY_BITMAPSET_FIELD(selectedCols);
2156 	COPY_BITMAPSET_FIELD(insertedCols);
2157 	COPY_BITMAPSET_FIELD(updatedCols);
2158 	COPY_NODE_FIELD(securityQuals);
2159 
2160 	return newnode;
2161 }
2162 
2163 static RangeTblFunction *
_copyRangeTblFunction(const RangeTblFunction * from)2164 _copyRangeTblFunction(const RangeTblFunction *from)
2165 {
2166 	RangeTblFunction *newnode = makeNode(RangeTblFunction);
2167 
2168 	COPY_NODE_FIELD(funcexpr);
2169 	COPY_SCALAR_FIELD(funccolcount);
2170 	COPY_NODE_FIELD(funccolnames);
2171 	COPY_NODE_FIELD(funccoltypes);
2172 	COPY_NODE_FIELD(funccoltypmods);
2173 	COPY_NODE_FIELD(funccolcollations);
2174 	COPY_BITMAPSET_FIELD(funcparams);
2175 
2176 	return newnode;
2177 }
2178 
2179 static TableSampleClause *
_copyTableSampleClause(const TableSampleClause * from)2180 _copyTableSampleClause(const TableSampleClause *from)
2181 {
2182 	TableSampleClause *newnode = makeNode(TableSampleClause);
2183 
2184 	COPY_SCALAR_FIELD(tsmhandler);
2185 	COPY_NODE_FIELD(args);
2186 	COPY_NODE_FIELD(repeatable);
2187 
2188 	return newnode;
2189 }
2190 
2191 static WithCheckOption *
_copyWithCheckOption(const WithCheckOption * from)2192 _copyWithCheckOption(const WithCheckOption *from)
2193 {
2194 	WithCheckOption *newnode = makeNode(WithCheckOption);
2195 
2196 	COPY_SCALAR_FIELD(kind);
2197 	COPY_STRING_FIELD(relname);
2198 	COPY_STRING_FIELD(polname);
2199 	COPY_NODE_FIELD(qual);
2200 	COPY_SCALAR_FIELD(cascaded);
2201 
2202 	return newnode;
2203 }
2204 
2205 static SortGroupClause *
_copySortGroupClause(const SortGroupClause * from)2206 _copySortGroupClause(const SortGroupClause *from)
2207 {
2208 	SortGroupClause *newnode = makeNode(SortGroupClause);
2209 
2210 	COPY_SCALAR_FIELD(tleSortGroupRef);
2211 	COPY_SCALAR_FIELD(eqop);
2212 	COPY_SCALAR_FIELD(sortop);
2213 	COPY_SCALAR_FIELD(nulls_first);
2214 	COPY_SCALAR_FIELD(hashable);
2215 
2216 	return newnode;
2217 }
2218 
2219 static GroupingSet *
_copyGroupingSet(const GroupingSet * from)2220 _copyGroupingSet(const GroupingSet *from)
2221 {
2222 	GroupingSet *newnode = makeNode(GroupingSet);
2223 
2224 	COPY_SCALAR_FIELD(kind);
2225 	COPY_NODE_FIELD(content);
2226 	COPY_LOCATION_FIELD(location);
2227 
2228 	return newnode;
2229 }
2230 
2231 static WindowClause *
_copyWindowClause(const WindowClause * from)2232 _copyWindowClause(const WindowClause *from)
2233 {
2234 	WindowClause *newnode = makeNode(WindowClause);
2235 
2236 	COPY_STRING_FIELD(name);
2237 	COPY_STRING_FIELD(refname);
2238 	COPY_NODE_FIELD(partitionClause);
2239 	COPY_NODE_FIELD(orderClause);
2240 	COPY_SCALAR_FIELD(frameOptions);
2241 	COPY_NODE_FIELD(startOffset);
2242 	COPY_NODE_FIELD(endOffset);
2243 	COPY_SCALAR_FIELD(winref);
2244 	COPY_SCALAR_FIELD(copiedOrder);
2245 
2246 	return newnode;
2247 }
2248 
2249 static RowMarkClause *
_copyRowMarkClause(const RowMarkClause * from)2250 _copyRowMarkClause(const RowMarkClause *from)
2251 {
2252 	RowMarkClause *newnode = makeNode(RowMarkClause);
2253 
2254 	COPY_SCALAR_FIELD(rti);
2255 	COPY_SCALAR_FIELD(strength);
2256 	COPY_SCALAR_FIELD(waitPolicy);
2257 	COPY_SCALAR_FIELD(pushedDown);
2258 
2259 	return newnode;
2260 }
2261 
2262 static WithClause *
_copyWithClause(const WithClause * from)2263 _copyWithClause(const WithClause *from)
2264 {
2265 	WithClause *newnode = makeNode(WithClause);
2266 
2267 	COPY_NODE_FIELD(ctes);
2268 	COPY_SCALAR_FIELD(recursive);
2269 	COPY_LOCATION_FIELD(location);
2270 
2271 	return newnode;
2272 }
2273 
2274 static InferClause *
_copyInferClause(const InferClause * from)2275 _copyInferClause(const InferClause *from)
2276 {
2277 	InferClause *newnode = makeNode(InferClause);
2278 
2279 	COPY_NODE_FIELD(indexElems);
2280 	COPY_NODE_FIELD(whereClause);
2281 	COPY_STRING_FIELD(conname);
2282 	COPY_LOCATION_FIELD(location);
2283 
2284 	return newnode;
2285 }
2286 
2287 static OnConflictClause *
_copyOnConflictClause(const OnConflictClause * from)2288 _copyOnConflictClause(const OnConflictClause *from)
2289 {
2290 	OnConflictClause *newnode = makeNode(OnConflictClause);
2291 
2292 	COPY_SCALAR_FIELD(action);
2293 	COPY_NODE_FIELD(infer);
2294 	COPY_NODE_FIELD(targetList);
2295 	COPY_NODE_FIELD(whereClause);
2296 	COPY_LOCATION_FIELD(location);
2297 
2298 	return newnode;
2299 }
2300 
2301 static CommonTableExpr *
_copyCommonTableExpr(const CommonTableExpr * from)2302 _copyCommonTableExpr(const CommonTableExpr *from)
2303 {
2304 	CommonTableExpr *newnode = makeNode(CommonTableExpr);
2305 
2306 	COPY_STRING_FIELD(ctename);
2307 	COPY_NODE_FIELD(aliascolnames);
2308 	COPY_NODE_FIELD(ctequery);
2309 	COPY_LOCATION_FIELD(location);
2310 	COPY_SCALAR_FIELD(cterecursive);
2311 	COPY_SCALAR_FIELD(cterefcount);
2312 	COPY_NODE_FIELD(ctecolnames);
2313 	COPY_NODE_FIELD(ctecoltypes);
2314 	COPY_NODE_FIELD(ctecoltypmods);
2315 	COPY_NODE_FIELD(ctecolcollations);
2316 
2317 	return newnode;
2318 }
2319 
2320 static A_Expr *
_copyAExpr(const A_Expr * from)2321 _copyAExpr(const A_Expr *from)
2322 {
2323 	A_Expr	   *newnode = makeNode(A_Expr);
2324 
2325 	COPY_SCALAR_FIELD(kind);
2326 	COPY_NODE_FIELD(name);
2327 	COPY_NODE_FIELD(lexpr);
2328 	COPY_NODE_FIELD(rexpr);
2329 	COPY_LOCATION_FIELD(location);
2330 
2331 	return newnode;
2332 }
2333 
2334 static ColumnRef *
_copyColumnRef(const ColumnRef * from)2335 _copyColumnRef(const ColumnRef *from)
2336 {
2337 	ColumnRef  *newnode = makeNode(ColumnRef);
2338 
2339 	COPY_NODE_FIELD(fields);
2340 	COPY_LOCATION_FIELD(location);
2341 
2342 	return newnode;
2343 }
2344 
2345 static ParamRef *
_copyParamRef(const ParamRef * from)2346 _copyParamRef(const ParamRef *from)
2347 {
2348 	ParamRef   *newnode = makeNode(ParamRef);
2349 
2350 	COPY_SCALAR_FIELD(number);
2351 	COPY_LOCATION_FIELD(location);
2352 
2353 	return newnode;
2354 }
2355 
2356 static A_Const *
_copyAConst(const A_Const * from)2357 _copyAConst(const A_Const *from)
2358 {
2359 	A_Const    *newnode = makeNode(A_Const);
2360 
2361 	/* This part must duplicate _copyValue */
2362 	COPY_SCALAR_FIELD(val.type);
2363 	switch (from->val.type)
2364 	{
2365 		case T_Integer:
2366 			COPY_SCALAR_FIELD(val.val.ival);
2367 			break;
2368 		case T_Float:
2369 		case T_String:
2370 		case T_BitString:
2371 			COPY_STRING_FIELD(val.val.str);
2372 			break;
2373 		case T_Null:
2374 			/* nothing to do */
2375 			break;
2376 		default:
2377 			elog(ERROR, "unrecognized node type: %d",
2378 				 (int) from->val.type);
2379 			break;
2380 	}
2381 
2382 	COPY_LOCATION_FIELD(location);
2383 
2384 	return newnode;
2385 }
2386 
2387 static FuncCall *
_copyFuncCall(const FuncCall * from)2388 _copyFuncCall(const FuncCall *from)
2389 {
2390 	FuncCall   *newnode = makeNode(FuncCall);
2391 
2392 	COPY_NODE_FIELD(funcname);
2393 	COPY_NODE_FIELD(args);
2394 	COPY_NODE_FIELD(agg_order);
2395 	COPY_NODE_FIELD(agg_filter);
2396 	COPY_SCALAR_FIELD(agg_within_group);
2397 	COPY_SCALAR_FIELD(agg_star);
2398 	COPY_SCALAR_FIELD(agg_distinct);
2399 	COPY_SCALAR_FIELD(func_variadic);
2400 	COPY_NODE_FIELD(over);
2401 	COPY_LOCATION_FIELD(location);
2402 
2403 	return newnode;
2404 }
2405 
2406 static A_Star *
_copyAStar(const A_Star * from)2407 _copyAStar(const A_Star *from)
2408 {
2409 	A_Star	   *newnode = makeNode(A_Star);
2410 
2411 	return newnode;
2412 }
2413 
2414 static A_Indices *
_copyAIndices(const A_Indices * from)2415 _copyAIndices(const A_Indices *from)
2416 {
2417 	A_Indices  *newnode = makeNode(A_Indices);
2418 
2419 	COPY_SCALAR_FIELD(is_slice);
2420 	COPY_NODE_FIELD(lidx);
2421 	COPY_NODE_FIELD(uidx);
2422 
2423 	return newnode;
2424 }
2425 
2426 static A_Indirection *
_copyA_Indirection(const A_Indirection * from)2427 _copyA_Indirection(const A_Indirection *from)
2428 {
2429 	A_Indirection *newnode = makeNode(A_Indirection);
2430 
2431 	COPY_NODE_FIELD(arg);
2432 	COPY_NODE_FIELD(indirection);
2433 
2434 	return newnode;
2435 }
2436 
2437 static A_ArrayExpr *
_copyA_ArrayExpr(const A_ArrayExpr * from)2438 _copyA_ArrayExpr(const A_ArrayExpr *from)
2439 {
2440 	A_ArrayExpr *newnode = makeNode(A_ArrayExpr);
2441 
2442 	COPY_NODE_FIELD(elements);
2443 	COPY_LOCATION_FIELD(location);
2444 
2445 	return newnode;
2446 }
2447 
2448 static ResTarget *
_copyResTarget(const ResTarget * from)2449 _copyResTarget(const ResTarget *from)
2450 {
2451 	ResTarget  *newnode = makeNode(ResTarget);
2452 
2453 	COPY_STRING_FIELD(name);
2454 	COPY_NODE_FIELD(indirection);
2455 	COPY_NODE_FIELD(val);
2456 	COPY_LOCATION_FIELD(location);
2457 
2458 	return newnode;
2459 }
2460 
2461 static MultiAssignRef *
_copyMultiAssignRef(const MultiAssignRef * from)2462 _copyMultiAssignRef(const MultiAssignRef *from)
2463 {
2464 	MultiAssignRef *newnode = makeNode(MultiAssignRef);
2465 
2466 	COPY_NODE_FIELD(source);
2467 	COPY_SCALAR_FIELD(colno);
2468 	COPY_SCALAR_FIELD(ncolumns);
2469 
2470 	return newnode;
2471 }
2472 
2473 static TypeName *
_copyTypeName(const TypeName * from)2474 _copyTypeName(const TypeName *from)
2475 {
2476 	TypeName   *newnode = makeNode(TypeName);
2477 
2478 	COPY_NODE_FIELD(names);
2479 	COPY_SCALAR_FIELD(typeOid);
2480 	COPY_SCALAR_FIELD(setof);
2481 	COPY_SCALAR_FIELD(pct_type);
2482 	COPY_NODE_FIELD(typmods);
2483 	COPY_SCALAR_FIELD(typemod);
2484 	COPY_NODE_FIELD(arrayBounds);
2485 	COPY_LOCATION_FIELD(location);
2486 
2487 	return newnode;
2488 }
2489 
2490 static SortBy *
_copySortBy(const SortBy * from)2491 _copySortBy(const SortBy *from)
2492 {
2493 	SortBy	   *newnode = makeNode(SortBy);
2494 
2495 	COPY_NODE_FIELD(node);
2496 	COPY_SCALAR_FIELD(sortby_dir);
2497 	COPY_SCALAR_FIELD(sortby_nulls);
2498 	COPY_NODE_FIELD(useOp);
2499 	COPY_LOCATION_FIELD(location);
2500 
2501 	return newnode;
2502 }
2503 
2504 static WindowDef *
_copyWindowDef(const WindowDef * from)2505 _copyWindowDef(const WindowDef *from)
2506 {
2507 	WindowDef  *newnode = makeNode(WindowDef);
2508 
2509 	COPY_STRING_FIELD(name);
2510 	COPY_STRING_FIELD(refname);
2511 	COPY_NODE_FIELD(partitionClause);
2512 	COPY_NODE_FIELD(orderClause);
2513 	COPY_SCALAR_FIELD(frameOptions);
2514 	COPY_NODE_FIELD(startOffset);
2515 	COPY_NODE_FIELD(endOffset);
2516 	COPY_LOCATION_FIELD(location);
2517 
2518 	return newnode;
2519 }
2520 
2521 static RangeSubselect *
_copyRangeSubselect(const RangeSubselect * from)2522 _copyRangeSubselect(const RangeSubselect *from)
2523 {
2524 	RangeSubselect *newnode = makeNode(RangeSubselect);
2525 
2526 	COPY_SCALAR_FIELD(lateral);
2527 	COPY_NODE_FIELD(subquery);
2528 	COPY_NODE_FIELD(alias);
2529 
2530 	return newnode;
2531 }
2532 
2533 static RangeFunction *
_copyRangeFunction(const RangeFunction * from)2534 _copyRangeFunction(const RangeFunction *from)
2535 {
2536 	RangeFunction *newnode = makeNode(RangeFunction);
2537 
2538 	COPY_SCALAR_FIELD(lateral);
2539 	COPY_SCALAR_FIELD(ordinality);
2540 	COPY_SCALAR_FIELD(is_rowsfrom);
2541 	COPY_NODE_FIELD(functions);
2542 	COPY_NODE_FIELD(alias);
2543 	COPY_NODE_FIELD(coldeflist);
2544 
2545 	return newnode;
2546 }
2547 
2548 static RangeTableSample *
_copyRangeTableSample(const RangeTableSample * from)2549 _copyRangeTableSample(const RangeTableSample *from)
2550 {
2551 	RangeTableSample *newnode = makeNode(RangeTableSample);
2552 
2553 	COPY_NODE_FIELD(relation);
2554 	COPY_NODE_FIELD(method);
2555 	COPY_NODE_FIELD(args);
2556 	COPY_NODE_FIELD(repeatable);
2557 	COPY_LOCATION_FIELD(location);
2558 
2559 	return newnode;
2560 }
2561 
2562 static TypeCast *
_copyTypeCast(const TypeCast * from)2563 _copyTypeCast(const TypeCast *from)
2564 {
2565 	TypeCast   *newnode = makeNode(TypeCast);
2566 
2567 	COPY_NODE_FIELD(arg);
2568 	COPY_NODE_FIELD(typeName);
2569 	COPY_LOCATION_FIELD(location);
2570 
2571 	return newnode;
2572 }
2573 
2574 static CollateClause *
_copyCollateClause(const CollateClause * from)2575 _copyCollateClause(const CollateClause *from)
2576 {
2577 	CollateClause *newnode = makeNode(CollateClause);
2578 
2579 	COPY_NODE_FIELD(arg);
2580 	COPY_NODE_FIELD(collname);
2581 	COPY_LOCATION_FIELD(location);
2582 
2583 	return newnode;
2584 }
2585 
2586 static IndexElem *
_copyIndexElem(const IndexElem * from)2587 _copyIndexElem(const IndexElem *from)
2588 {
2589 	IndexElem  *newnode = makeNode(IndexElem);
2590 
2591 	COPY_STRING_FIELD(name);
2592 	COPY_NODE_FIELD(expr);
2593 	COPY_STRING_FIELD(indexcolname);
2594 	COPY_NODE_FIELD(collation);
2595 	COPY_NODE_FIELD(opclass);
2596 	COPY_SCALAR_FIELD(ordering);
2597 	COPY_SCALAR_FIELD(nulls_ordering);
2598 
2599 	return newnode;
2600 }
2601 
2602 static ColumnDef *
_copyColumnDef(const ColumnDef * from)2603 _copyColumnDef(const ColumnDef *from)
2604 {
2605 	ColumnDef  *newnode = makeNode(ColumnDef);
2606 
2607 	COPY_STRING_FIELD(colname);
2608 	COPY_NODE_FIELD(typeName);
2609 	COPY_SCALAR_FIELD(inhcount);
2610 	COPY_SCALAR_FIELD(is_local);
2611 	COPY_SCALAR_FIELD(is_not_null);
2612 	COPY_SCALAR_FIELD(is_from_type);
2613 	COPY_SCALAR_FIELD(storage);
2614 	COPY_NODE_FIELD(raw_default);
2615 	COPY_NODE_FIELD(cooked_default);
2616 	COPY_NODE_FIELD(collClause);
2617 	COPY_SCALAR_FIELD(collOid);
2618 	COPY_NODE_FIELD(constraints);
2619 	COPY_NODE_FIELD(fdwoptions);
2620 	COPY_LOCATION_FIELD(location);
2621 
2622 	return newnode;
2623 }
2624 
2625 static Constraint *
_copyConstraint(const Constraint * from)2626 _copyConstraint(const Constraint *from)
2627 {
2628 	Constraint *newnode = makeNode(Constraint);
2629 
2630 	COPY_SCALAR_FIELD(contype);
2631 	COPY_STRING_FIELD(conname);
2632 	COPY_SCALAR_FIELD(deferrable);
2633 	COPY_SCALAR_FIELD(initdeferred);
2634 	COPY_LOCATION_FIELD(location);
2635 	COPY_SCALAR_FIELD(is_no_inherit);
2636 	COPY_NODE_FIELD(raw_expr);
2637 	COPY_STRING_FIELD(cooked_expr);
2638 	COPY_NODE_FIELD(keys);
2639 	COPY_NODE_FIELD(exclusions);
2640 	COPY_NODE_FIELD(options);
2641 	COPY_STRING_FIELD(indexname);
2642 	COPY_STRING_FIELD(indexspace);
2643 	COPY_STRING_FIELD(access_method);
2644 	COPY_NODE_FIELD(where_clause);
2645 	COPY_NODE_FIELD(pktable);
2646 	COPY_NODE_FIELD(fk_attrs);
2647 	COPY_NODE_FIELD(pk_attrs);
2648 	COPY_SCALAR_FIELD(fk_matchtype);
2649 	COPY_SCALAR_FIELD(fk_upd_action);
2650 	COPY_SCALAR_FIELD(fk_del_action);
2651 	COPY_NODE_FIELD(old_conpfeqop);
2652 	COPY_SCALAR_FIELD(old_pktable_oid);
2653 	COPY_SCALAR_FIELD(skip_validation);
2654 	COPY_SCALAR_FIELD(initially_valid);
2655 
2656 	return newnode;
2657 }
2658 
2659 static DefElem *
_copyDefElem(const DefElem * from)2660 _copyDefElem(const DefElem *from)
2661 {
2662 	DefElem    *newnode = makeNode(DefElem);
2663 
2664 	COPY_STRING_FIELD(defnamespace);
2665 	COPY_STRING_FIELD(defname);
2666 	COPY_NODE_FIELD(arg);
2667 	COPY_SCALAR_FIELD(defaction);
2668 
2669 	return newnode;
2670 }
2671 
2672 static LockingClause *
_copyLockingClause(const LockingClause * from)2673 _copyLockingClause(const LockingClause *from)
2674 {
2675 	LockingClause *newnode = makeNode(LockingClause);
2676 
2677 	COPY_NODE_FIELD(lockedRels);
2678 	COPY_SCALAR_FIELD(strength);
2679 	COPY_SCALAR_FIELD(waitPolicy);
2680 
2681 	return newnode;
2682 }
2683 
2684 static XmlSerialize *
_copyXmlSerialize(const XmlSerialize * from)2685 _copyXmlSerialize(const XmlSerialize *from)
2686 {
2687 	XmlSerialize *newnode = makeNode(XmlSerialize);
2688 
2689 	COPY_SCALAR_FIELD(xmloption);
2690 	COPY_NODE_FIELD(expr);
2691 	COPY_NODE_FIELD(typeName);
2692 	COPY_LOCATION_FIELD(location);
2693 
2694 	return newnode;
2695 }
2696 
2697 static RoleSpec *
_copyRoleSpec(const RoleSpec * from)2698 _copyRoleSpec(const RoleSpec *from)
2699 {
2700 	RoleSpec   *newnode = makeNode(RoleSpec);
2701 
2702 	COPY_SCALAR_FIELD(roletype);
2703 	COPY_STRING_FIELD(rolename);
2704 	COPY_LOCATION_FIELD(location);
2705 
2706 	return newnode;
2707 }
2708 
2709 static Query *
_copyQuery(const Query * from)2710 _copyQuery(const Query *from)
2711 {
2712 	Query	   *newnode = makeNode(Query);
2713 
2714 	COPY_SCALAR_FIELD(commandType);
2715 	COPY_SCALAR_FIELD(querySource);
2716 	COPY_SCALAR_FIELD(queryId);
2717 	COPY_SCALAR_FIELD(canSetTag);
2718 	COPY_NODE_FIELD(utilityStmt);
2719 	COPY_SCALAR_FIELD(resultRelation);
2720 	COPY_SCALAR_FIELD(hasAggs);
2721 	COPY_SCALAR_FIELD(hasWindowFuncs);
2722 	COPY_SCALAR_FIELD(hasSubLinks);
2723 	COPY_SCALAR_FIELD(hasDistinctOn);
2724 	COPY_SCALAR_FIELD(hasRecursive);
2725 	COPY_SCALAR_FIELD(hasModifyingCTE);
2726 	COPY_SCALAR_FIELD(hasForUpdate);
2727 	COPY_SCALAR_FIELD(hasRowSecurity);
2728 	COPY_NODE_FIELD(cteList);
2729 	COPY_NODE_FIELD(rtable);
2730 	COPY_NODE_FIELD(jointree);
2731 	COPY_NODE_FIELD(targetList);
2732 	COPY_NODE_FIELD(onConflict);
2733 	COPY_NODE_FIELD(returningList);
2734 	COPY_NODE_FIELD(groupClause);
2735 	COPY_NODE_FIELD(groupingSets);
2736 	COPY_NODE_FIELD(havingQual);
2737 	COPY_NODE_FIELD(windowClause);
2738 	COPY_NODE_FIELD(distinctClause);
2739 	COPY_NODE_FIELD(sortClause);
2740 	COPY_NODE_FIELD(limitOffset);
2741 	COPY_NODE_FIELD(limitCount);
2742 	COPY_NODE_FIELD(rowMarks);
2743 	COPY_NODE_FIELD(setOperations);
2744 	COPY_NODE_FIELD(constraintDeps);
2745 	COPY_NODE_FIELD(withCheckOptions);
2746 
2747 	return newnode;
2748 }
2749 
2750 static InsertStmt *
_copyInsertStmt(const InsertStmt * from)2751 _copyInsertStmt(const InsertStmt *from)
2752 {
2753 	InsertStmt *newnode = makeNode(InsertStmt);
2754 
2755 	COPY_NODE_FIELD(relation);
2756 	COPY_NODE_FIELD(cols);
2757 	COPY_NODE_FIELD(selectStmt);
2758 	COPY_NODE_FIELD(onConflictClause);
2759 	COPY_NODE_FIELD(returningList);
2760 	COPY_NODE_FIELD(withClause);
2761 
2762 	return newnode;
2763 }
2764 
2765 static DeleteStmt *
_copyDeleteStmt(const DeleteStmt * from)2766 _copyDeleteStmt(const DeleteStmt *from)
2767 {
2768 	DeleteStmt *newnode = makeNode(DeleteStmt);
2769 
2770 	COPY_NODE_FIELD(relation);
2771 	COPY_NODE_FIELD(usingClause);
2772 	COPY_NODE_FIELD(whereClause);
2773 	COPY_NODE_FIELD(returningList);
2774 	COPY_NODE_FIELD(withClause);
2775 
2776 	return newnode;
2777 }
2778 
2779 static UpdateStmt *
_copyUpdateStmt(const UpdateStmt * from)2780 _copyUpdateStmt(const UpdateStmt *from)
2781 {
2782 	UpdateStmt *newnode = makeNode(UpdateStmt);
2783 
2784 	COPY_NODE_FIELD(relation);
2785 	COPY_NODE_FIELD(targetList);
2786 	COPY_NODE_FIELD(whereClause);
2787 	COPY_NODE_FIELD(fromClause);
2788 	COPY_NODE_FIELD(returningList);
2789 	COPY_NODE_FIELD(withClause);
2790 
2791 	return newnode;
2792 }
2793 
2794 static SelectStmt *
_copySelectStmt(const SelectStmt * from)2795 _copySelectStmt(const SelectStmt *from)
2796 {
2797 	SelectStmt *newnode = makeNode(SelectStmt);
2798 
2799 	COPY_NODE_FIELD(distinctClause);
2800 	COPY_NODE_FIELD(intoClause);
2801 	COPY_NODE_FIELD(targetList);
2802 	COPY_NODE_FIELD(fromClause);
2803 	COPY_NODE_FIELD(whereClause);
2804 	COPY_NODE_FIELD(groupClause);
2805 	COPY_NODE_FIELD(havingClause);
2806 	COPY_NODE_FIELD(windowClause);
2807 	COPY_NODE_FIELD(valuesLists);
2808 	COPY_NODE_FIELD(sortClause);
2809 	COPY_NODE_FIELD(limitOffset);
2810 	COPY_NODE_FIELD(limitCount);
2811 	COPY_NODE_FIELD(lockingClause);
2812 	COPY_NODE_FIELD(withClause);
2813 	COPY_SCALAR_FIELD(op);
2814 	COPY_SCALAR_FIELD(all);
2815 	COPY_NODE_FIELD(larg);
2816 	COPY_NODE_FIELD(rarg);
2817 
2818 	return newnode;
2819 }
2820 
2821 static SetOperationStmt *
_copySetOperationStmt(const SetOperationStmt * from)2822 _copySetOperationStmt(const SetOperationStmt *from)
2823 {
2824 	SetOperationStmt *newnode = makeNode(SetOperationStmt);
2825 
2826 	COPY_SCALAR_FIELD(op);
2827 	COPY_SCALAR_FIELD(all);
2828 	COPY_NODE_FIELD(larg);
2829 	COPY_NODE_FIELD(rarg);
2830 	COPY_NODE_FIELD(colTypes);
2831 	COPY_NODE_FIELD(colTypmods);
2832 	COPY_NODE_FIELD(colCollations);
2833 	COPY_NODE_FIELD(groupClauses);
2834 
2835 	return newnode;
2836 }
2837 
2838 static AlterTableStmt *
_copyAlterTableStmt(const AlterTableStmt * from)2839 _copyAlterTableStmt(const AlterTableStmt *from)
2840 {
2841 	AlterTableStmt *newnode = makeNode(AlterTableStmt);
2842 
2843 	COPY_NODE_FIELD(relation);
2844 	COPY_NODE_FIELD(cmds);
2845 	COPY_SCALAR_FIELD(relkind);
2846 	COPY_SCALAR_FIELD(missing_ok);
2847 
2848 	return newnode;
2849 }
2850 
2851 static AlterTableCmd *
_copyAlterTableCmd(const AlterTableCmd * from)2852 _copyAlterTableCmd(const AlterTableCmd *from)
2853 {
2854 	AlterTableCmd *newnode = makeNode(AlterTableCmd);
2855 
2856 	COPY_SCALAR_FIELD(subtype);
2857 	COPY_STRING_FIELD(name);
2858 	COPY_NODE_FIELD(newowner);
2859 	COPY_NODE_FIELD(def);
2860 	COPY_SCALAR_FIELD(behavior);
2861 	COPY_SCALAR_FIELD(missing_ok);
2862 
2863 	return newnode;
2864 }
2865 
2866 static AlterDomainStmt *
_copyAlterDomainStmt(const AlterDomainStmt * from)2867 _copyAlterDomainStmt(const AlterDomainStmt *from)
2868 {
2869 	AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
2870 
2871 	COPY_SCALAR_FIELD(subtype);
2872 	COPY_NODE_FIELD(typeName);
2873 	COPY_STRING_FIELD(name);
2874 	COPY_NODE_FIELD(def);
2875 	COPY_SCALAR_FIELD(behavior);
2876 	COPY_SCALAR_FIELD(missing_ok);
2877 
2878 	return newnode;
2879 }
2880 
2881 static GrantStmt *
_copyGrantStmt(const GrantStmt * from)2882 _copyGrantStmt(const GrantStmt *from)
2883 {
2884 	GrantStmt  *newnode = makeNode(GrantStmt);
2885 
2886 	COPY_SCALAR_FIELD(is_grant);
2887 	COPY_SCALAR_FIELD(targtype);
2888 	COPY_SCALAR_FIELD(objtype);
2889 	COPY_NODE_FIELD(objects);
2890 	COPY_NODE_FIELD(privileges);
2891 	COPY_NODE_FIELD(grantees);
2892 	COPY_SCALAR_FIELD(grant_option);
2893 	COPY_SCALAR_FIELD(behavior);
2894 
2895 	return newnode;
2896 }
2897 
2898 static FuncWithArgs *
_copyFuncWithArgs(const FuncWithArgs * from)2899 _copyFuncWithArgs(const FuncWithArgs *from)
2900 {
2901 	FuncWithArgs *newnode = makeNode(FuncWithArgs);
2902 
2903 	COPY_NODE_FIELD(funcname);
2904 	COPY_NODE_FIELD(funcargs);
2905 
2906 	return newnode;
2907 }
2908 
2909 static AccessPriv *
_copyAccessPriv(const AccessPriv * from)2910 _copyAccessPriv(const AccessPriv *from)
2911 {
2912 	AccessPriv *newnode = makeNode(AccessPriv);
2913 
2914 	COPY_STRING_FIELD(priv_name);
2915 	COPY_NODE_FIELD(cols);
2916 
2917 	return newnode;
2918 }
2919 
2920 static GrantRoleStmt *
_copyGrantRoleStmt(const GrantRoleStmt * from)2921 _copyGrantRoleStmt(const GrantRoleStmt *from)
2922 {
2923 	GrantRoleStmt *newnode = makeNode(GrantRoleStmt);
2924 
2925 	COPY_NODE_FIELD(granted_roles);
2926 	COPY_NODE_FIELD(grantee_roles);
2927 	COPY_SCALAR_FIELD(is_grant);
2928 	COPY_SCALAR_FIELD(admin_opt);
2929 	COPY_NODE_FIELD(grantor);
2930 	COPY_SCALAR_FIELD(behavior);
2931 
2932 	return newnode;
2933 }
2934 
2935 static AlterDefaultPrivilegesStmt *
_copyAlterDefaultPrivilegesStmt(const AlterDefaultPrivilegesStmt * from)2936 _copyAlterDefaultPrivilegesStmt(const AlterDefaultPrivilegesStmt *from)
2937 {
2938 	AlterDefaultPrivilegesStmt *newnode = makeNode(AlterDefaultPrivilegesStmt);
2939 
2940 	COPY_NODE_FIELD(options);
2941 	COPY_NODE_FIELD(action);
2942 
2943 	return newnode;
2944 }
2945 
2946 static DeclareCursorStmt *
_copyDeclareCursorStmt(const DeclareCursorStmt * from)2947 _copyDeclareCursorStmt(const DeclareCursorStmt *from)
2948 {
2949 	DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
2950 
2951 	COPY_STRING_FIELD(portalname);
2952 	COPY_SCALAR_FIELD(options);
2953 	COPY_NODE_FIELD(query);
2954 
2955 	return newnode;
2956 }
2957 
2958 static ClosePortalStmt *
_copyClosePortalStmt(const ClosePortalStmt * from)2959 _copyClosePortalStmt(const ClosePortalStmt *from)
2960 {
2961 	ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
2962 
2963 	COPY_STRING_FIELD(portalname);
2964 
2965 	return newnode;
2966 }
2967 
2968 static ClusterStmt *
_copyClusterStmt(const ClusterStmt * from)2969 _copyClusterStmt(const ClusterStmt *from)
2970 {
2971 	ClusterStmt *newnode = makeNode(ClusterStmt);
2972 
2973 	COPY_NODE_FIELD(relation);
2974 	COPY_STRING_FIELD(indexname);
2975 	COPY_SCALAR_FIELD(verbose);
2976 
2977 	return newnode;
2978 }
2979 
2980 static CopyStmt *
_copyCopyStmt(const CopyStmt * from)2981 _copyCopyStmt(const CopyStmt *from)
2982 {
2983 	CopyStmt   *newnode = makeNode(CopyStmt);
2984 
2985 	COPY_NODE_FIELD(relation);
2986 	COPY_NODE_FIELD(query);
2987 	COPY_NODE_FIELD(attlist);
2988 	COPY_SCALAR_FIELD(is_from);
2989 	COPY_SCALAR_FIELD(is_program);
2990 	COPY_STRING_FIELD(filename);
2991 	COPY_NODE_FIELD(options);
2992 
2993 	return newnode;
2994 }
2995 
2996 /*
2997  * CopyCreateStmtFields
2998  *
2999  *		This function copies the fields of the CreateStmt node.  It is used by
3000  *		copy functions for classes which inherit from CreateStmt.
3001  */
3002 static void
CopyCreateStmtFields(const CreateStmt * from,CreateStmt * newnode)3003 CopyCreateStmtFields(const CreateStmt *from, CreateStmt *newnode)
3004 {
3005 	COPY_NODE_FIELD(relation);
3006 	COPY_NODE_FIELD(tableElts);
3007 	COPY_NODE_FIELD(inhRelations);
3008 	COPY_NODE_FIELD(ofTypename);
3009 	COPY_NODE_FIELD(constraints);
3010 	COPY_NODE_FIELD(options);
3011 	COPY_SCALAR_FIELD(oncommit);
3012 	COPY_STRING_FIELD(tablespacename);
3013 	COPY_SCALAR_FIELD(if_not_exists);
3014 }
3015 
3016 static CreateStmt *
_copyCreateStmt(const CreateStmt * from)3017 _copyCreateStmt(const CreateStmt *from)
3018 {
3019 	CreateStmt *newnode = makeNode(CreateStmt);
3020 
3021 	CopyCreateStmtFields(from, newnode);
3022 
3023 	return newnode;
3024 }
3025 
3026 static TableLikeClause *
_copyTableLikeClause(const TableLikeClause * from)3027 _copyTableLikeClause(const TableLikeClause *from)
3028 {
3029 	TableLikeClause *newnode = makeNode(TableLikeClause);
3030 
3031 	COPY_NODE_FIELD(relation);
3032 	COPY_SCALAR_FIELD(options);
3033 
3034 	return newnode;
3035 }
3036 
3037 static DefineStmt *
_copyDefineStmt(const DefineStmt * from)3038 _copyDefineStmt(const DefineStmt *from)
3039 {
3040 	DefineStmt *newnode = makeNode(DefineStmt);
3041 
3042 	COPY_SCALAR_FIELD(kind);
3043 	COPY_SCALAR_FIELD(oldstyle);
3044 	COPY_NODE_FIELD(defnames);
3045 	COPY_NODE_FIELD(args);
3046 	COPY_NODE_FIELD(definition);
3047 
3048 	return newnode;
3049 }
3050 
3051 static DropStmt *
_copyDropStmt(const DropStmt * from)3052 _copyDropStmt(const DropStmt *from)
3053 {
3054 	DropStmt   *newnode = makeNode(DropStmt);
3055 
3056 	COPY_NODE_FIELD(objects);
3057 	COPY_NODE_FIELD(arguments);
3058 	COPY_SCALAR_FIELD(removeType);
3059 	COPY_SCALAR_FIELD(behavior);
3060 	COPY_SCALAR_FIELD(missing_ok);
3061 	COPY_SCALAR_FIELD(concurrent);
3062 
3063 	return newnode;
3064 }
3065 
3066 static TruncateStmt *
_copyTruncateStmt(const TruncateStmt * from)3067 _copyTruncateStmt(const TruncateStmt *from)
3068 {
3069 	TruncateStmt *newnode = makeNode(TruncateStmt);
3070 
3071 	COPY_NODE_FIELD(relations);
3072 	COPY_SCALAR_FIELD(restart_seqs);
3073 	COPY_SCALAR_FIELD(behavior);
3074 
3075 	return newnode;
3076 }
3077 
3078 static CommentStmt *
_copyCommentStmt(const CommentStmt * from)3079 _copyCommentStmt(const CommentStmt *from)
3080 {
3081 	CommentStmt *newnode = makeNode(CommentStmt);
3082 
3083 	COPY_SCALAR_FIELD(objtype);
3084 	COPY_NODE_FIELD(objname);
3085 	COPY_NODE_FIELD(objargs);
3086 	COPY_STRING_FIELD(comment);
3087 
3088 	return newnode;
3089 }
3090 
3091 static SecLabelStmt *
_copySecLabelStmt(const SecLabelStmt * from)3092 _copySecLabelStmt(const SecLabelStmt *from)
3093 {
3094 	SecLabelStmt *newnode = makeNode(SecLabelStmt);
3095 
3096 	COPY_SCALAR_FIELD(objtype);
3097 	COPY_NODE_FIELD(objname);
3098 	COPY_NODE_FIELD(objargs);
3099 	COPY_STRING_FIELD(provider);
3100 	COPY_STRING_FIELD(label);
3101 
3102 	return newnode;
3103 }
3104 
3105 static FetchStmt *
_copyFetchStmt(const FetchStmt * from)3106 _copyFetchStmt(const FetchStmt *from)
3107 {
3108 	FetchStmt  *newnode = makeNode(FetchStmt);
3109 
3110 	COPY_SCALAR_FIELD(direction);
3111 	COPY_SCALAR_FIELD(howMany);
3112 	COPY_STRING_FIELD(portalname);
3113 	COPY_SCALAR_FIELD(ismove);
3114 
3115 	return newnode;
3116 }
3117 
3118 static IndexStmt *
_copyIndexStmt(const IndexStmt * from)3119 _copyIndexStmt(const IndexStmt *from)
3120 {
3121 	IndexStmt  *newnode = makeNode(IndexStmt);
3122 
3123 	COPY_STRING_FIELD(idxname);
3124 	COPY_NODE_FIELD(relation);
3125 	COPY_STRING_FIELD(accessMethod);
3126 	COPY_STRING_FIELD(tableSpace);
3127 	COPY_NODE_FIELD(indexParams);
3128 	COPY_NODE_FIELD(options);
3129 	COPY_NODE_FIELD(whereClause);
3130 	COPY_NODE_FIELD(excludeOpNames);
3131 	COPY_STRING_FIELD(idxcomment);
3132 	COPY_SCALAR_FIELD(indexOid);
3133 	COPY_SCALAR_FIELD(oldNode);
3134 	COPY_SCALAR_FIELD(unique);
3135 	COPY_SCALAR_FIELD(primary);
3136 	COPY_SCALAR_FIELD(isconstraint);
3137 	COPY_SCALAR_FIELD(deferrable);
3138 	COPY_SCALAR_FIELD(initdeferred);
3139 	COPY_SCALAR_FIELD(transformed);
3140 	COPY_SCALAR_FIELD(concurrent);
3141 	COPY_SCALAR_FIELD(if_not_exists);
3142 
3143 	return newnode;
3144 }
3145 
3146 static CreateFunctionStmt *
_copyCreateFunctionStmt(const CreateFunctionStmt * from)3147 _copyCreateFunctionStmt(const CreateFunctionStmt *from)
3148 {
3149 	CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
3150 
3151 	COPY_SCALAR_FIELD(replace);
3152 	COPY_NODE_FIELD(funcname);
3153 	COPY_NODE_FIELD(parameters);
3154 	COPY_NODE_FIELD(returnType);
3155 	COPY_NODE_FIELD(options);
3156 	COPY_NODE_FIELD(withClause);
3157 
3158 	return newnode;
3159 }
3160 
3161 static FunctionParameter *
_copyFunctionParameter(const FunctionParameter * from)3162 _copyFunctionParameter(const FunctionParameter *from)
3163 {
3164 	FunctionParameter *newnode = makeNode(FunctionParameter);
3165 
3166 	COPY_STRING_FIELD(name);
3167 	COPY_NODE_FIELD(argType);
3168 	COPY_SCALAR_FIELD(mode);
3169 	COPY_NODE_FIELD(defexpr);
3170 
3171 	return newnode;
3172 }
3173 
3174 static AlterFunctionStmt *
_copyAlterFunctionStmt(const AlterFunctionStmt * from)3175 _copyAlterFunctionStmt(const AlterFunctionStmt *from)
3176 {
3177 	AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);
3178 
3179 	COPY_NODE_FIELD(func);
3180 	COPY_NODE_FIELD(actions);
3181 
3182 	return newnode;
3183 }
3184 
3185 static DoStmt *
_copyDoStmt(const DoStmt * from)3186 _copyDoStmt(const DoStmt *from)
3187 {
3188 	DoStmt	   *newnode = makeNode(DoStmt);
3189 
3190 	COPY_NODE_FIELD(args);
3191 
3192 	return newnode;
3193 }
3194 
3195 static RenameStmt *
_copyRenameStmt(const RenameStmt * from)3196 _copyRenameStmt(const RenameStmt *from)
3197 {
3198 	RenameStmt *newnode = makeNode(RenameStmt);
3199 
3200 	COPY_SCALAR_FIELD(renameType);
3201 	COPY_SCALAR_FIELD(relationType);
3202 	COPY_NODE_FIELD(relation);
3203 	COPY_NODE_FIELD(object);
3204 	COPY_NODE_FIELD(objarg);
3205 	COPY_STRING_FIELD(subname);
3206 	COPY_STRING_FIELD(newname);
3207 	COPY_SCALAR_FIELD(behavior);
3208 	COPY_SCALAR_FIELD(missing_ok);
3209 
3210 	return newnode;
3211 }
3212 
3213 static AlterObjectDependsStmt *
_copyAlterObjectDependsStmt(const AlterObjectDependsStmt * from)3214 _copyAlterObjectDependsStmt(const AlterObjectDependsStmt *from)
3215 {
3216 	AlterObjectDependsStmt *newnode = makeNode(AlterObjectDependsStmt);
3217 
3218 	COPY_SCALAR_FIELD(objectType);
3219 	COPY_NODE_FIELD(relation);
3220 	COPY_NODE_FIELD(objname);
3221 	COPY_NODE_FIELD(objargs);
3222 	COPY_NODE_FIELD(extname);
3223 
3224 	return newnode;
3225 }
3226 
3227 static AlterObjectSchemaStmt *
_copyAlterObjectSchemaStmt(const AlterObjectSchemaStmt * from)3228 _copyAlterObjectSchemaStmt(const AlterObjectSchemaStmt *from)
3229 {
3230 	AlterObjectSchemaStmt *newnode = makeNode(AlterObjectSchemaStmt);
3231 
3232 	COPY_SCALAR_FIELD(objectType);
3233 	COPY_NODE_FIELD(relation);
3234 	COPY_NODE_FIELD(object);
3235 	COPY_NODE_FIELD(objarg);
3236 	COPY_STRING_FIELD(newschema);
3237 	COPY_SCALAR_FIELD(missing_ok);
3238 
3239 	return newnode;
3240 }
3241 
3242 static AlterOwnerStmt *
_copyAlterOwnerStmt(const AlterOwnerStmt * from)3243 _copyAlterOwnerStmt(const AlterOwnerStmt *from)
3244 {
3245 	AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);
3246 
3247 	COPY_SCALAR_FIELD(objectType);
3248 	COPY_NODE_FIELD(relation);
3249 	COPY_NODE_FIELD(object);
3250 	COPY_NODE_FIELD(objarg);
3251 	COPY_NODE_FIELD(newowner);
3252 
3253 	return newnode;
3254 }
3255 
3256 static AlterOperatorStmt *
_copyAlterOperatorStmt(const AlterOperatorStmt * from)3257 _copyAlterOperatorStmt(const AlterOperatorStmt *from)
3258 {
3259 	AlterOperatorStmt *newnode = makeNode(AlterOperatorStmt);
3260 
3261 	COPY_NODE_FIELD(opername);
3262 	COPY_NODE_FIELD(operargs);
3263 	COPY_NODE_FIELD(options);
3264 
3265 	return newnode;
3266 }
3267 
3268 static RuleStmt *
_copyRuleStmt(const RuleStmt * from)3269 _copyRuleStmt(const RuleStmt *from)
3270 {
3271 	RuleStmt   *newnode = makeNode(RuleStmt);
3272 
3273 	COPY_NODE_FIELD(relation);
3274 	COPY_STRING_FIELD(rulename);
3275 	COPY_NODE_FIELD(whereClause);
3276 	COPY_SCALAR_FIELD(event);
3277 	COPY_SCALAR_FIELD(instead);
3278 	COPY_NODE_FIELD(actions);
3279 	COPY_SCALAR_FIELD(replace);
3280 
3281 	return newnode;
3282 }
3283 
3284 static NotifyStmt *
_copyNotifyStmt(const NotifyStmt * from)3285 _copyNotifyStmt(const NotifyStmt *from)
3286 {
3287 	NotifyStmt *newnode = makeNode(NotifyStmt);
3288 
3289 	COPY_STRING_FIELD(conditionname);
3290 	COPY_STRING_FIELD(payload);
3291 
3292 	return newnode;
3293 }
3294 
3295 static ListenStmt *
_copyListenStmt(const ListenStmt * from)3296 _copyListenStmt(const ListenStmt *from)
3297 {
3298 	ListenStmt *newnode = makeNode(ListenStmt);
3299 
3300 	COPY_STRING_FIELD(conditionname);
3301 
3302 	return newnode;
3303 }
3304 
3305 static UnlistenStmt *
_copyUnlistenStmt(const UnlistenStmt * from)3306 _copyUnlistenStmt(const UnlistenStmt *from)
3307 {
3308 	UnlistenStmt *newnode = makeNode(UnlistenStmt);
3309 
3310 	COPY_STRING_FIELD(conditionname);
3311 
3312 	return newnode;
3313 }
3314 
3315 static TransactionStmt *
_copyTransactionStmt(const TransactionStmt * from)3316 _copyTransactionStmt(const TransactionStmt *from)
3317 {
3318 	TransactionStmt *newnode = makeNode(TransactionStmt);
3319 
3320 	COPY_SCALAR_FIELD(kind);
3321 	COPY_NODE_FIELD(options);
3322 	COPY_STRING_FIELD(gid);
3323 
3324 	return newnode;
3325 }
3326 
3327 static CompositeTypeStmt *
_copyCompositeTypeStmt(const CompositeTypeStmt * from)3328 _copyCompositeTypeStmt(const CompositeTypeStmt *from)
3329 {
3330 	CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
3331 
3332 	COPY_NODE_FIELD(typevar);
3333 	COPY_NODE_FIELD(coldeflist);
3334 
3335 	return newnode;
3336 }
3337 
3338 static CreateEnumStmt *
_copyCreateEnumStmt(const CreateEnumStmt * from)3339 _copyCreateEnumStmt(const CreateEnumStmt *from)
3340 {
3341 	CreateEnumStmt *newnode = makeNode(CreateEnumStmt);
3342 
3343 	COPY_NODE_FIELD(typeName);
3344 	COPY_NODE_FIELD(vals);
3345 
3346 	return newnode;
3347 }
3348 
3349 static CreateRangeStmt *
_copyCreateRangeStmt(const CreateRangeStmt * from)3350 _copyCreateRangeStmt(const CreateRangeStmt *from)
3351 {
3352 	CreateRangeStmt *newnode = makeNode(CreateRangeStmt);
3353 
3354 	COPY_NODE_FIELD(typeName);
3355 	COPY_NODE_FIELD(params);
3356 
3357 	return newnode;
3358 }
3359 
3360 static AlterEnumStmt *
_copyAlterEnumStmt(const AlterEnumStmt * from)3361 _copyAlterEnumStmt(const AlterEnumStmt *from)
3362 {
3363 	AlterEnumStmt *newnode = makeNode(AlterEnumStmt);
3364 
3365 	COPY_NODE_FIELD(typeName);
3366 	COPY_STRING_FIELD(newVal);
3367 	COPY_STRING_FIELD(newValNeighbor);
3368 	COPY_SCALAR_FIELD(newValIsAfter);
3369 	COPY_SCALAR_FIELD(skipIfExists);
3370 
3371 	return newnode;
3372 }
3373 
3374 static ViewStmt *
_copyViewStmt(const ViewStmt * from)3375 _copyViewStmt(const ViewStmt *from)
3376 {
3377 	ViewStmt   *newnode = makeNode(ViewStmt);
3378 
3379 	COPY_NODE_FIELD(view);
3380 	COPY_NODE_FIELD(aliases);
3381 	COPY_NODE_FIELD(query);
3382 	COPY_SCALAR_FIELD(replace);
3383 	COPY_NODE_FIELD(options);
3384 	COPY_SCALAR_FIELD(withCheckOption);
3385 
3386 	return newnode;
3387 }
3388 
3389 static LoadStmt *
_copyLoadStmt(const LoadStmt * from)3390 _copyLoadStmt(const LoadStmt *from)
3391 {
3392 	LoadStmt   *newnode = makeNode(LoadStmt);
3393 
3394 	COPY_STRING_FIELD(filename);
3395 
3396 	return newnode;
3397 }
3398 
3399 static CreateDomainStmt *
_copyCreateDomainStmt(const CreateDomainStmt * from)3400 _copyCreateDomainStmt(const CreateDomainStmt *from)
3401 {
3402 	CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
3403 
3404 	COPY_NODE_FIELD(domainname);
3405 	COPY_NODE_FIELD(typeName);
3406 	COPY_NODE_FIELD(collClause);
3407 	COPY_NODE_FIELD(constraints);
3408 
3409 	return newnode;
3410 }
3411 
3412 static CreateOpClassStmt *
_copyCreateOpClassStmt(const CreateOpClassStmt * from)3413 _copyCreateOpClassStmt(const CreateOpClassStmt *from)
3414 {
3415 	CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
3416 
3417 	COPY_NODE_FIELD(opclassname);
3418 	COPY_NODE_FIELD(opfamilyname);
3419 	COPY_STRING_FIELD(amname);
3420 	COPY_NODE_FIELD(datatype);
3421 	COPY_NODE_FIELD(items);
3422 	COPY_SCALAR_FIELD(isDefault);
3423 
3424 	return newnode;
3425 }
3426 
3427 static CreateOpClassItem *
_copyCreateOpClassItem(const CreateOpClassItem * from)3428 _copyCreateOpClassItem(const CreateOpClassItem *from)
3429 {
3430 	CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
3431 
3432 	COPY_SCALAR_FIELD(itemtype);
3433 	COPY_NODE_FIELD(name);
3434 	COPY_NODE_FIELD(args);
3435 	COPY_SCALAR_FIELD(number);
3436 	COPY_NODE_FIELD(order_family);
3437 	COPY_NODE_FIELD(class_args);
3438 	COPY_NODE_FIELD(storedtype);
3439 
3440 	return newnode;
3441 }
3442 
3443 static CreateOpFamilyStmt *
_copyCreateOpFamilyStmt(const CreateOpFamilyStmt * from)3444 _copyCreateOpFamilyStmt(const CreateOpFamilyStmt *from)
3445 {
3446 	CreateOpFamilyStmt *newnode = makeNode(CreateOpFamilyStmt);
3447 
3448 	COPY_NODE_FIELD(opfamilyname);
3449 	COPY_STRING_FIELD(amname);
3450 
3451 	return newnode;
3452 }
3453 
3454 static AlterOpFamilyStmt *
_copyAlterOpFamilyStmt(const AlterOpFamilyStmt * from)3455 _copyAlterOpFamilyStmt(const AlterOpFamilyStmt *from)
3456 {
3457 	AlterOpFamilyStmt *newnode = makeNode(AlterOpFamilyStmt);
3458 
3459 	COPY_NODE_FIELD(opfamilyname);
3460 	COPY_STRING_FIELD(amname);
3461 	COPY_SCALAR_FIELD(isDrop);
3462 	COPY_NODE_FIELD(items);
3463 
3464 	return newnode;
3465 }
3466 
3467 static CreatedbStmt *
_copyCreatedbStmt(const CreatedbStmt * from)3468 _copyCreatedbStmt(const CreatedbStmt *from)
3469 {
3470 	CreatedbStmt *newnode = makeNode(CreatedbStmt);
3471 
3472 	COPY_STRING_FIELD(dbname);
3473 	COPY_NODE_FIELD(options);
3474 
3475 	return newnode;
3476 }
3477 
3478 static AlterDatabaseStmt *
_copyAlterDatabaseStmt(const AlterDatabaseStmt * from)3479 _copyAlterDatabaseStmt(const AlterDatabaseStmt *from)
3480 {
3481 	AlterDatabaseStmt *newnode = makeNode(AlterDatabaseStmt);
3482 
3483 	COPY_STRING_FIELD(dbname);
3484 	COPY_NODE_FIELD(options);
3485 
3486 	return newnode;
3487 }
3488 
3489 static AlterDatabaseSetStmt *
_copyAlterDatabaseSetStmt(const AlterDatabaseSetStmt * from)3490 _copyAlterDatabaseSetStmt(const AlterDatabaseSetStmt *from)
3491 {
3492 	AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
3493 
3494 	COPY_STRING_FIELD(dbname);
3495 	COPY_NODE_FIELD(setstmt);
3496 
3497 	return newnode;
3498 }
3499 
3500 static DropdbStmt *
_copyDropdbStmt(const DropdbStmt * from)3501 _copyDropdbStmt(const DropdbStmt *from)
3502 {
3503 	DropdbStmt *newnode = makeNode(DropdbStmt);
3504 
3505 	COPY_STRING_FIELD(dbname);
3506 	COPY_SCALAR_FIELD(missing_ok);
3507 
3508 	return newnode;
3509 }
3510 
3511 static VacuumStmt *
_copyVacuumStmt(const VacuumStmt * from)3512 _copyVacuumStmt(const VacuumStmt *from)
3513 {
3514 	VacuumStmt *newnode = makeNode(VacuumStmt);
3515 
3516 	COPY_SCALAR_FIELD(options);
3517 	COPY_NODE_FIELD(relation);
3518 	COPY_NODE_FIELD(va_cols);
3519 
3520 	return newnode;
3521 }
3522 
3523 static ExplainStmt *
_copyExplainStmt(const ExplainStmt * from)3524 _copyExplainStmt(const ExplainStmt *from)
3525 {
3526 	ExplainStmt *newnode = makeNode(ExplainStmt);
3527 
3528 	COPY_NODE_FIELD(query);
3529 	COPY_NODE_FIELD(options);
3530 
3531 	return newnode;
3532 }
3533 
3534 static CreateTableAsStmt *
_copyCreateTableAsStmt(const CreateTableAsStmt * from)3535 _copyCreateTableAsStmt(const CreateTableAsStmt *from)
3536 {
3537 	CreateTableAsStmt *newnode = makeNode(CreateTableAsStmt);
3538 
3539 	COPY_NODE_FIELD(query);
3540 	COPY_NODE_FIELD(into);
3541 	COPY_SCALAR_FIELD(relkind);
3542 	COPY_SCALAR_FIELD(is_select_into);
3543 	COPY_SCALAR_FIELD(if_not_exists);
3544 
3545 	return newnode;
3546 }
3547 
3548 static RefreshMatViewStmt *
_copyRefreshMatViewStmt(const RefreshMatViewStmt * from)3549 _copyRefreshMatViewStmt(const RefreshMatViewStmt *from)
3550 {
3551 	RefreshMatViewStmt *newnode = makeNode(RefreshMatViewStmt);
3552 
3553 	COPY_SCALAR_FIELD(concurrent);
3554 	COPY_SCALAR_FIELD(skipData);
3555 	COPY_NODE_FIELD(relation);
3556 
3557 	return newnode;
3558 }
3559 
3560 static ReplicaIdentityStmt *
_copyReplicaIdentityStmt(const ReplicaIdentityStmt * from)3561 _copyReplicaIdentityStmt(const ReplicaIdentityStmt *from)
3562 {
3563 	ReplicaIdentityStmt *newnode = makeNode(ReplicaIdentityStmt);
3564 
3565 	COPY_SCALAR_FIELD(identity_type);
3566 	COPY_STRING_FIELD(name);
3567 
3568 	return newnode;
3569 }
3570 
3571 static AlterSystemStmt *
_copyAlterSystemStmt(const AlterSystemStmt * from)3572 _copyAlterSystemStmt(const AlterSystemStmt *from)
3573 {
3574 	AlterSystemStmt *newnode = makeNode(AlterSystemStmt);
3575 
3576 	COPY_NODE_FIELD(setstmt);
3577 
3578 	return newnode;
3579 }
3580 
3581 static CreateSeqStmt *
_copyCreateSeqStmt(const CreateSeqStmt * from)3582 _copyCreateSeqStmt(const CreateSeqStmt *from)
3583 {
3584 	CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
3585 
3586 	COPY_NODE_FIELD(sequence);
3587 	COPY_NODE_FIELD(options);
3588 	COPY_SCALAR_FIELD(ownerId);
3589 	COPY_SCALAR_FIELD(if_not_exists);
3590 
3591 	return newnode;
3592 }
3593 
3594 static AlterSeqStmt *
_copyAlterSeqStmt(const AlterSeqStmt * from)3595 _copyAlterSeqStmt(const AlterSeqStmt *from)
3596 {
3597 	AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
3598 
3599 	COPY_NODE_FIELD(sequence);
3600 	COPY_NODE_FIELD(options);
3601 	COPY_SCALAR_FIELD(missing_ok);
3602 
3603 	return newnode;
3604 }
3605 
3606 static VariableSetStmt *
_copyVariableSetStmt(const VariableSetStmt * from)3607 _copyVariableSetStmt(const VariableSetStmt *from)
3608 {
3609 	VariableSetStmt *newnode = makeNode(VariableSetStmt);
3610 
3611 	COPY_SCALAR_FIELD(kind);
3612 	COPY_STRING_FIELD(name);
3613 	COPY_NODE_FIELD(args);
3614 	COPY_SCALAR_FIELD(is_local);
3615 
3616 	return newnode;
3617 }
3618 
3619 static VariableShowStmt *
_copyVariableShowStmt(const VariableShowStmt * from)3620 _copyVariableShowStmt(const VariableShowStmt *from)
3621 {
3622 	VariableShowStmt *newnode = makeNode(VariableShowStmt);
3623 
3624 	COPY_STRING_FIELD(name);
3625 
3626 	return newnode;
3627 }
3628 
3629 static DiscardStmt *
_copyDiscardStmt(const DiscardStmt * from)3630 _copyDiscardStmt(const DiscardStmt *from)
3631 {
3632 	DiscardStmt *newnode = makeNode(DiscardStmt);
3633 
3634 	COPY_SCALAR_FIELD(target);
3635 
3636 	return newnode;
3637 }
3638 
3639 static CreateTableSpaceStmt *
_copyCreateTableSpaceStmt(const CreateTableSpaceStmt * from)3640 _copyCreateTableSpaceStmt(const CreateTableSpaceStmt *from)
3641 {
3642 	CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
3643 
3644 	COPY_STRING_FIELD(tablespacename);
3645 	COPY_NODE_FIELD(owner);
3646 	COPY_STRING_FIELD(location);
3647 	COPY_NODE_FIELD(options);
3648 
3649 	return newnode;
3650 }
3651 
3652 static DropTableSpaceStmt *
_copyDropTableSpaceStmt(const DropTableSpaceStmt * from)3653 _copyDropTableSpaceStmt(const DropTableSpaceStmt *from)
3654 {
3655 	DropTableSpaceStmt *newnode = makeNode(DropTableSpaceStmt);
3656 
3657 	COPY_STRING_FIELD(tablespacename);
3658 	COPY_SCALAR_FIELD(missing_ok);
3659 
3660 	return newnode;
3661 }
3662 
3663 static AlterTableSpaceOptionsStmt *
_copyAlterTableSpaceOptionsStmt(const AlterTableSpaceOptionsStmt * from)3664 _copyAlterTableSpaceOptionsStmt(const AlterTableSpaceOptionsStmt *from)
3665 {
3666 	AlterTableSpaceOptionsStmt *newnode = makeNode(AlterTableSpaceOptionsStmt);
3667 
3668 	COPY_STRING_FIELD(tablespacename);
3669 	COPY_NODE_FIELD(options);
3670 	COPY_SCALAR_FIELD(isReset);
3671 
3672 	return newnode;
3673 }
3674 
3675 static AlterTableMoveAllStmt *
_copyAlterTableMoveAllStmt(const AlterTableMoveAllStmt * from)3676 _copyAlterTableMoveAllStmt(const AlterTableMoveAllStmt *from)
3677 {
3678 	AlterTableMoveAllStmt *newnode = makeNode(AlterTableMoveAllStmt);
3679 
3680 	COPY_STRING_FIELD(orig_tablespacename);
3681 	COPY_SCALAR_FIELD(objtype);
3682 	COPY_NODE_FIELD(roles);
3683 	COPY_STRING_FIELD(new_tablespacename);
3684 	COPY_SCALAR_FIELD(nowait);
3685 
3686 	return newnode;
3687 }
3688 
3689 static CreateExtensionStmt *
_copyCreateExtensionStmt(const CreateExtensionStmt * from)3690 _copyCreateExtensionStmt(const CreateExtensionStmt *from)
3691 {
3692 	CreateExtensionStmt *newnode = makeNode(CreateExtensionStmt);
3693 
3694 	COPY_STRING_FIELD(extname);
3695 	COPY_SCALAR_FIELD(if_not_exists);
3696 	COPY_NODE_FIELD(options);
3697 
3698 	return newnode;
3699 }
3700 
3701 static AlterExtensionStmt *
_copyAlterExtensionStmt(const AlterExtensionStmt * from)3702 _copyAlterExtensionStmt(const AlterExtensionStmt *from)
3703 {
3704 	AlterExtensionStmt *newnode = makeNode(AlterExtensionStmt);
3705 
3706 	COPY_STRING_FIELD(extname);
3707 	COPY_NODE_FIELD(options);
3708 
3709 	return newnode;
3710 }
3711 
3712 static AlterExtensionContentsStmt *
_copyAlterExtensionContentsStmt(const AlterExtensionContentsStmt * from)3713 _copyAlterExtensionContentsStmt(const AlterExtensionContentsStmt *from)
3714 {
3715 	AlterExtensionContentsStmt *newnode = makeNode(AlterExtensionContentsStmt);
3716 
3717 	COPY_STRING_FIELD(extname);
3718 	COPY_SCALAR_FIELD(action);
3719 	COPY_SCALAR_FIELD(objtype);
3720 	COPY_NODE_FIELD(objname);
3721 	COPY_NODE_FIELD(objargs);
3722 
3723 	return newnode;
3724 }
3725 
3726 static CreateFdwStmt *
_copyCreateFdwStmt(const CreateFdwStmt * from)3727 _copyCreateFdwStmt(const CreateFdwStmt *from)
3728 {
3729 	CreateFdwStmt *newnode = makeNode(CreateFdwStmt);
3730 
3731 	COPY_STRING_FIELD(fdwname);
3732 	COPY_NODE_FIELD(func_options);
3733 	COPY_NODE_FIELD(options);
3734 
3735 	return newnode;
3736 }
3737 
3738 static AlterFdwStmt *
_copyAlterFdwStmt(const AlterFdwStmt * from)3739 _copyAlterFdwStmt(const AlterFdwStmt *from)
3740 {
3741 	AlterFdwStmt *newnode = makeNode(AlterFdwStmt);
3742 
3743 	COPY_STRING_FIELD(fdwname);
3744 	COPY_NODE_FIELD(func_options);
3745 	COPY_NODE_FIELD(options);
3746 
3747 	return newnode;
3748 }
3749 
3750 static CreateForeignServerStmt *
_copyCreateForeignServerStmt(const CreateForeignServerStmt * from)3751 _copyCreateForeignServerStmt(const CreateForeignServerStmt *from)
3752 {
3753 	CreateForeignServerStmt *newnode = makeNode(CreateForeignServerStmt);
3754 
3755 	COPY_STRING_FIELD(servername);
3756 	COPY_STRING_FIELD(servertype);
3757 	COPY_STRING_FIELD(version);
3758 	COPY_STRING_FIELD(fdwname);
3759 	COPY_NODE_FIELD(options);
3760 
3761 	return newnode;
3762 }
3763 
3764 static AlterForeignServerStmt *
_copyAlterForeignServerStmt(const AlterForeignServerStmt * from)3765 _copyAlterForeignServerStmt(const AlterForeignServerStmt *from)
3766 {
3767 	AlterForeignServerStmt *newnode = makeNode(AlterForeignServerStmt);
3768 
3769 	COPY_STRING_FIELD(servername);
3770 	COPY_STRING_FIELD(version);
3771 	COPY_NODE_FIELD(options);
3772 	COPY_SCALAR_FIELD(has_version);
3773 
3774 	return newnode;
3775 }
3776 
3777 static CreateUserMappingStmt *
_copyCreateUserMappingStmt(const CreateUserMappingStmt * from)3778 _copyCreateUserMappingStmt(const CreateUserMappingStmt *from)
3779 {
3780 	CreateUserMappingStmt *newnode = makeNode(CreateUserMappingStmt);
3781 
3782 	COPY_NODE_FIELD(user);
3783 	COPY_STRING_FIELD(servername);
3784 	COPY_NODE_FIELD(options);
3785 
3786 	return newnode;
3787 }
3788 
3789 static AlterUserMappingStmt *
_copyAlterUserMappingStmt(const AlterUserMappingStmt * from)3790 _copyAlterUserMappingStmt(const AlterUserMappingStmt *from)
3791 {
3792 	AlterUserMappingStmt *newnode = makeNode(AlterUserMappingStmt);
3793 
3794 	COPY_NODE_FIELD(user);
3795 	COPY_STRING_FIELD(servername);
3796 	COPY_NODE_FIELD(options);
3797 
3798 	return newnode;
3799 }
3800 
3801 static DropUserMappingStmt *
_copyDropUserMappingStmt(const DropUserMappingStmt * from)3802 _copyDropUserMappingStmt(const DropUserMappingStmt *from)
3803 {
3804 	DropUserMappingStmt *newnode = makeNode(DropUserMappingStmt);
3805 
3806 	COPY_NODE_FIELD(user);
3807 	COPY_STRING_FIELD(servername);
3808 	COPY_SCALAR_FIELD(missing_ok);
3809 
3810 	return newnode;
3811 }
3812 
3813 static CreateForeignTableStmt *
_copyCreateForeignTableStmt(const CreateForeignTableStmt * from)3814 _copyCreateForeignTableStmt(const CreateForeignTableStmt *from)
3815 {
3816 	CreateForeignTableStmt *newnode = makeNode(CreateForeignTableStmt);
3817 
3818 	CopyCreateStmtFields((const CreateStmt *) from, (CreateStmt *) newnode);
3819 
3820 	COPY_STRING_FIELD(servername);
3821 	COPY_NODE_FIELD(options);
3822 
3823 	return newnode;
3824 }
3825 
3826 static ImportForeignSchemaStmt *
_copyImportForeignSchemaStmt(const ImportForeignSchemaStmt * from)3827 _copyImportForeignSchemaStmt(const ImportForeignSchemaStmt *from)
3828 {
3829 	ImportForeignSchemaStmt *newnode = makeNode(ImportForeignSchemaStmt);
3830 
3831 	COPY_STRING_FIELD(server_name);
3832 	COPY_STRING_FIELD(remote_schema);
3833 	COPY_STRING_FIELD(local_schema);
3834 	COPY_SCALAR_FIELD(list_type);
3835 	COPY_NODE_FIELD(table_list);
3836 	COPY_NODE_FIELD(options);
3837 
3838 	return newnode;
3839 }
3840 
3841 static CreateTransformStmt *
_copyCreateTransformStmt(const CreateTransformStmt * from)3842 _copyCreateTransformStmt(const CreateTransformStmt *from)
3843 {
3844 	CreateTransformStmt *newnode = makeNode(CreateTransformStmt);
3845 
3846 	COPY_SCALAR_FIELD(replace);
3847 	COPY_NODE_FIELD(type_name);
3848 	COPY_STRING_FIELD(lang);
3849 	COPY_NODE_FIELD(fromsql);
3850 	COPY_NODE_FIELD(tosql);
3851 
3852 	return newnode;
3853 }
3854 
3855 static CreateAmStmt *
_copyCreateAmStmt(const CreateAmStmt * from)3856 _copyCreateAmStmt(const CreateAmStmt *from)
3857 {
3858 	CreateAmStmt *newnode = makeNode(CreateAmStmt);
3859 
3860 	COPY_STRING_FIELD(amname);
3861 	COPY_NODE_FIELD(handler_name);
3862 	COPY_SCALAR_FIELD(amtype);
3863 
3864 	return newnode;
3865 }
3866 
3867 static CreateTrigStmt *
_copyCreateTrigStmt(const CreateTrigStmt * from)3868 _copyCreateTrigStmt(const CreateTrigStmt *from)
3869 {
3870 	CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
3871 
3872 	COPY_STRING_FIELD(trigname);
3873 	COPY_NODE_FIELD(relation);
3874 	COPY_NODE_FIELD(funcname);
3875 	COPY_NODE_FIELD(args);
3876 	COPY_SCALAR_FIELD(row);
3877 	COPY_SCALAR_FIELD(timing);
3878 	COPY_SCALAR_FIELD(events);
3879 	COPY_NODE_FIELD(columns);
3880 	COPY_NODE_FIELD(whenClause);
3881 	COPY_SCALAR_FIELD(isconstraint);
3882 	COPY_SCALAR_FIELD(deferrable);
3883 	COPY_SCALAR_FIELD(initdeferred);
3884 	COPY_NODE_FIELD(constrrel);
3885 
3886 	return newnode;
3887 }
3888 
3889 static CreateEventTrigStmt *
_copyCreateEventTrigStmt(const CreateEventTrigStmt * from)3890 _copyCreateEventTrigStmt(const CreateEventTrigStmt *from)
3891 {
3892 	CreateEventTrigStmt *newnode = makeNode(CreateEventTrigStmt);
3893 
3894 	COPY_STRING_FIELD(trigname);
3895 	COPY_STRING_FIELD(eventname);
3896 	COPY_NODE_FIELD(whenclause);
3897 	COPY_NODE_FIELD(funcname);
3898 
3899 	return newnode;
3900 }
3901 
3902 static AlterEventTrigStmt *
_copyAlterEventTrigStmt(const AlterEventTrigStmt * from)3903 _copyAlterEventTrigStmt(const AlterEventTrigStmt *from)
3904 {
3905 	AlterEventTrigStmt *newnode = makeNode(AlterEventTrigStmt);
3906 
3907 	COPY_STRING_FIELD(trigname);
3908 	COPY_SCALAR_FIELD(tgenabled);
3909 
3910 	return newnode;
3911 }
3912 
3913 static CreatePLangStmt *
_copyCreatePLangStmt(const CreatePLangStmt * from)3914 _copyCreatePLangStmt(const CreatePLangStmt *from)
3915 {
3916 	CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
3917 
3918 	COPY_SCALAR_FIELD(replace);
3919 	COPY_STRING_FIELD(plname);
3920 	COPY_NODE_FIELD(plhandler);
3921 	COPY_NODE_FIELD(plinline);
3922 	COPY_NODE_FIELD(plvalidator);
3923 	COPY_SCALAR_FIELD(pltrusted);
3924 
3925 	return newnode;
3926 }
3927 
3928 static CreateRoleStmt *
_copyCreateRoleStmt(const CreateRoleStmt * from)3929 _copyCreateRoleStmt(const CreateRoleStmt *from)
3930 {
3931 	CreateRoleStmt *newnode = makeNode(CreateRoleStmt);
3932 
3933 	COPY_SCALAR_FIELD(stmt_type);
3934 	COPY_STRING_FIELD(role);
3935 	COPY_NODE_FIELD(options);
3936 
3937 	return newnode;
3938 }
3939 
3940 static AlterRoleStmt *
_copyAlterRoleStmt(const AlterRoleStmt * from)3941 _copyAlterRoleStmt(const AlterRoleStmt *from)
3942 {
3943 	AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
3944 
3945 	COPY_NODE_FIELD(role);
3946 	COPY_NODE_FIELD(options);
3947 	COPY_SCALAR_FIELD(action);
3948 
3949 	return newnode;
3950 }
3951 
3952 static AlterRoleSetStmt *
_copyAlterRoleSetStmt(const AlterRoleSetStmt * from)3953 _copyAlterRoleSetStmt(const AlterRoleSetStmt *from)
3954 {
3955 	AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
3956 
3957 	COPY_NODE_FIELD(role);
3958 	COPY_STRING_FIELD(database);
3959 	COPY_NODE_FIELD(setstmt);
3960 
3961 	return newnode;
3962 }
3963 
3964 static DropRoleStmt *
_copyDropRoleStmt(const DropRoleStmt * from)3965 _copyDropRoleStmt(const DropRoleStmt *from)
3966 {
3967 	DropRoleStmt *newnode = makeNode(DropRoleStmt);
3968 
3969 	COPY_NODE_FIELD(roles);
3970 	COPY_SCALAR_FIELD(missing_ok);
3971 
3972 	return newnode;
3973 }
3974 
3975 static LockStmt *
_copyLockStmt(const LockStmt * from)3976 _copyLockStmt(const LockStmt *from)
3977 {
3978 	LockStmt   *newnode = makeNode(LockStmt);
3979 
3980 	COPY_NODE_FIELD(relations);
3981 	COPY_SCALAR_FIELD(mode);
3982 	COPY_SCALAR_FIELD(nowait);
3983 
3984 	return newnode;
3985 }
3986 
3987 static ConstraintsSetStmt *
_copyConstraintsSetStmt(const ConstraintsSetStmt * from)3988 _copyConstraintsSetStmt(const ConstraintsSetStmt *from)
3989 {
3990 	ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
3991 
3992 	COPY_NODE_FIELD(constraints);
3993 	COPY_SCALAR_FIELD(deferred);
3994 
3995 	return newnode;
3996 }
3997 
3998 static ReindexStmt *
_copyReindexStmt(const ReindexStmt * from)3999 _copyReindexStmt(const ReindexStmt *from)
4000 {
4001 	ReindexStmt *newnode = makeNode(ReindexStmt);
4002 
4003 	COPY_SCALAR_FIELD(kind);
4004 	COPY_NODE_FIELD(relation);
4005 	COPY_STRING_FIELD(name);
4006 	COPY_SCALAR_FIELD(options);
4007 
4008 	return newnode;
4009 }
4010 
4011 static CreateSchemaStmt *
_copyCreateSchemaStmt(const CreateSchemaStmt * from)4012 _copyCreateSchemaStmt(const CreateSchemaStmt *from)
4013 {
4014 	CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
4015 
4016 	COPY_STRING_FIELD(schemaname);
4017 	COPY_NODE_FIELD(authrole);
4018 	COPY_NODE_FIELD(schemaElts);
4019 	COPY_SCALAR_FIELD(if_not_exists);
4020 
4021 	return newnode;
4022 }
4023 
4024 static CreateConversionStmt *
_copyCreateConversionStmt(const CreateConversionStmt * from)4025 _copyCreateConversionStmt(const CreateConversionStmt *from)
4026 {
4027 	CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
4028 
4029 	COPY_NODE_FIELD(conversion_name);
4030 	COPY_STRING_FIELD(for_encoding_name);
4031 	COPY_STRING_FIELD(to_encoding_name);
4032 	COPY_NODE_FIELD(func_name);
4033 	COPY_SCALAR_FIELD(def);
4034 
4035 	return newnode;
4036 }
4037 
4038 static CreateCastStmt *
_copyCreateCastStmt(const CreateCastStmt * from)4039 _copyCreateCastStmt(const CreateCastStmt *from)
4040 {
4041 	CreateCastStmt *newnode = makeNode(CreateCastStmt);
4042 
4043 	COPY_NODE_FIELD(sourcetype);
4044 	COPY_NODE_FIELD(targettype);
4045 	COPY_NODE_FIELD(func);
4046 	COPY_SCALAR_FIELD(context);
4047 	COPY_SCALAR_FIELD(inout);
4048 
4049 	return newnode;
4050 }
4051 
4052 static PrepareStmt *
_copyPrepareStmt(const PrepareStmt * from)4053 _copyPrepareStmt(const PrepareStmt *from)
4054 {
4055 	PrepareStmt *newnode = makeNode(PrepareStmt);
4056 
4057 	COPY_STRING_FIELD(name);
4058 	COPY_NODE_FIELD(argtypes);
4059 	COPY_NODE_FIELD(query);
4060 
4061 	return newnode;
4062 }
4063 
4064 static ExecuteStmt *
_copyExecuteStmt(const ExecuteStmt * from)4065 _copyExecuteStmt(const ExecuteStmt *from)
4066 {
4067 	ExecuteStmt *newnode = makeNode(ExecuteStmt);
4068 
4069 	COPY_STRING_FIELD(name);
4070 	COPY_NODE_FIELD(params);
4071 
4072 	return newnode;
4073 }
4074 
4075 static DeallocateStmt *
_copyDeallocateStmt(const DeallocateStmt * from)4076 _copyDeallocateStmt(const DeallocateStmt *from)
4077 {
4078 	DeallocateStmt *newnode = makeNode(DeallocateStmt);
4079 
4080 	COPY_STRING_FIELD(name);
4081 
4082 	return newnode;
4083 }
4084 
4085 static DropOwnedStmt *
_copyDropOwnedStmt(const DropOwnedStmt * from)4086 _copyDropOwnedStmt(const DropOwnedStmt *from)
4087 {
4088 	DropOwnedStmt *newnode = makeNode(DropOwnedStmt);
4089 
4090 	COPY_NODE_FIELD(roles);
4091 	COPY_SCALAR_FIELD(behavior);
4092 
4093 	return newnode;
4094 }
4095 
4096 static ReassignOwnedStmt *
_copyReassignOwnedStmt(const ReassignOwnedStmt * from)4097 _copyReassignOwnedStmt(const ReassignOwnedStmt *from)
4098 {
4099 	ReassignOwnedStmt *newnode = makeNode(ReassignOwnedStmt);
4100 
4101 	COPY_NODE_FIELD(roles);
4102 	COPY_NODE_FIELD(newrole);
4103 
4104 	return newnode;
4105 }
4106 
4107 static AlterTSDictionaryStmt *
_copyAlterTSDictionaryStmt(const AlterTSDictionaryStmt * from)4108 _copyAlterTSDictionaryStmt(const AlterTSDictionaryStmt *from)
4109 {
4110 	AlterTSDictionaryStmt *newnode = makeNode(AlterTSDictionaryStmt);
4111 
4112 	COPY_NODE_FIELD(dictname);
4113 	COPY_NODE_FIELD(options);
4114 
4115 	return newnode;
4116 }
4117 
4118 static AlterTSConfigurationStmt *
_copyAlterTSConfigurationStmt(const AlterTSConfigurationStmt * from)4119 _copyAlterTSConfigurationStmt(const AlterTSConfigurationStmt *from)
4120 {
4121 	AlterTSConfigurationStmt *newnode = makeNode(AlterTSConfigurationStmt);
4122 
4123 	COPY_SCALAR_FIELD(kind);
4124 	COPY_NODE_FIELD(cfgname);
4125 	COPY_NODE_FIELD(tokentype);
4126 	COPY_NODE_FIELD(dicts);
4127 	COPY_SCALAR_FIELD(override);
4128 	COPY_SCALAR_FIELD(replace);
4129 	COPY_SCALAR_FIELD(missing_ok);
4130 
4131 	return newnode;
4132 }
4133 
4134 static CreatePolicyStmt *
_copyCreatePolicyStmt(const CreatePolicyStmt * from)4135 _copyCreatePolicyStmt(const CreatePolicyStmt *from)
4136 {
4137 	CreatePolicyStmt *newnode = makeNode(CreatePolicyStmt);
4138 
4139 	COPY_STRING_FIELD(policy_name);
4140 	COPY_NODE_FIELD(table);
4141 	COPY_STRING_FIELD(cmd_name);
4142 	COPY_NODE_FIELD(roles);
4143 	COPY_NODE_FIELD(qual);
4144 	COPY_NODE_FIELD(with_check);
4145 
4146 	return newnode;
4147 }
4148 
4149 static AlterPolicyStmt *
_copyAlterPolicyStmt(const AlterPolicyStmt * from)4150 _copyAlterPolicyStmt(const AlterPolicyStmt *from)
4151 {
4152 	AlterPolicyStmt *newnode = makeNode(AlterPolicyStmt);
4153 
4154 	COPY_STRING_FIELD(policy_name);
4155 	COPY_NODE_FIELD(table);
4156 	COPY_NODE_FIELD(roles);
4157 	COPY_NODE_FIELD(qual);
4158 	COPY_NODE_FIELD(with_check);
4159 
4160 	return newnode;
4161 }
4162 
4163 /* ****************************************************************
4164  *					pg_list.h copy functions
4165  * ****************************************************************
4166  */
4167 
4168 /*
4169  * Perform a deep copy of the specified list, using copyObject(). The
4170  * list MUST be of type T_List; T_IntList and T_OidList nodes don't
4171  * need deep copies, so they should be copied via list_copy()
4172  */
4173 #define COPY_NODE_CELL(new, old)					\
4174 	(new) = (ListCell *) palloc(sizeof(ListCell));	\
4175 	lfirst(new) = copyObject(lfirst(old));
4176 
4177 static List *
_copyList(const List * from)4178 _copyList(const List *from)
4179 {
4180 	List	   *new;
4181 	ListCell   *curr_old;
4182 	ListCell   *prev_new;
4183 
4184 	Assert(list_length(from) >= 1);
4185 
4186 	new = makeNode(List);
4187 	new->length = from->length;
4188 
4189 	COPY_NODE_CELL(new->head, from->head);
4190 	prev_new = new->head;
4191 	curr_old = lnext(from->head);
4192 
4193 	while (curr_old)
4194 	{
4195 		COPY_NODE_CELL(prev_new->next, curr_old);
4196 		prev_new = prev_new->next;
4197 		curr_old = curr_old->next;
4198 	}
4199 	prev_new->next = NULL;
4200 	new->tail = prev_new;
4201 
4202 	return new;
4203 }
4204 
4205 #ifdef NOT_USED_IN_PGPOOL
4206 /* ****************************************************************
4207  *					extensible.h copy functions
4208  * ****************************************************************
4209  */
4210 static ExtensibleNode *
_copyExtensibleNode(const ExtensibleNode * from)4211 _copyExtensibleNode(const ExtensibleNode *from)
4212 {
4213 	ExtensibleNode *newnode;
4214 	const ExtensibleNodeMethods *methods;
4215 
4216 	methods = GetExtensibleNodeMethods(from->extnodename, false);
4217 	newnode = (ExtensibleNode *) newNode(methods->node_size,
4218 										 T_ExtensibleNode);
4219 	COPY_STRING_FIELD(extnodename);
4220 
4221 	/* copy the private fields */
4222 	methods->nodeCopy(newnode, from);
4223 
4224 	return newnode;
4225 }
4226 #endif
4227 
4228 /* ****************************************************************
4229  *					value.h copy functions
4230  * ****************************************************************
4231  */
4232 static Value *
_copyValue(const Value * from)4233 _copyValue(const Value *from)
4234 {
4235 	Value	   *newnode = makeNode(Value);
4236 
4237 	/* See also _copyAConst when changing this code! */
4238 
4239 	COPY_SCALAR_FIELD(type);
4240 	switch (from->type)
4241 	{
4242 		case T_Integer:
4243 			COPY_SCALAR_FIELD(val.ival);
4244 			break;
4245 		case T_Float:
4246 		case T_String:
4247 		case T_BitString:
4248 			COPY_STRING_FIELD(val.str);
4249 			break;
4250 		case T_Null:
4251 			/* nothing to do */
4252 			break;
4253 		default:
4254 			elog(ERROR, "unrecognized node type: %d",
4255 				 (int) from->type);
4256 			break;
4257 	}
4258 	return newnode;
4259 }
4260 
4261 
4262 #ifdef NOT_USED_IN_PGPOOL
4263 static ForeignKeyCacheInfo *
_copyForeignKeyCacheInfo(const ForeignKeyCacheInfo * from)4264 _copyForeignKeyCacheInfo(const ForeignKeyCacheInfo *from)
4265 {
4266 	ForeignKeyCacheInfo *newnode = makeNode(ForeignKeyCacheInfo);
4267 
4268 	COPY_SCALAR_FIELD(conrelid);
4269 	COPY_SCALAR_FIELD(confrelid);
4270 	COPY_SCALAR_FIELD(nkeys);
4271 	/* COPY_SCALAR_FIELD might work for these, but let's not assume that */
4272 	memcpy(newnode->conkey, from->conkey, sizeof(newnode->conkey));
4273 	memcpy(newnode->confkey, from->confkey, sizeof(newnode->confkey));
4274 	memcpy(newnode->conpfeqop, from->conpfeqop, sizeof(newnode->conpfeqop));
4275 
4276 	return newnode;
4277 }
4278 #endif
4279 
4280 
4281 /*
4282  * copyObject
4283  *
4284  * Create a copy of a Node tree or list.  This is a "deep" copy: all
4285  * substructure is copied too, recursively.
4286  */
4287 void *
copyObject(const void * from)4288 copyObject(const void *from)
4289 {
4290 	void	   *retval;
4291 
4292 	if (from == NULL)
4293 		return NULL;
4294 
4295 	/* Guard against stack overflow due to overly complex expressions */
4296 #ifdef NOT_USED_IN_PGPOOL
4297 	check_stack_depth();
4298 #endif
4299 
4300 	switch (nodeTag(from))
4301 	{
4302 #ifdef NOT_USED_IN_PGPOOL
4303 			/*
4304 			 * PLAN NODES
4305 			 */
4306 		case T_PlannedStmt:
4307 			retval = _copyPlannedStmt(from);
4308 			break;
4309 		case T_Plan:
4310 			retval = _copyPlan(from);
4311 			break;
4312 		case T_Result:
4313 			retval = _copyResult(from);
4314 			break;
4315 		case T_ModifyTable:
4316 			retval = _copyModifyTable(from);
4317 			break;
4318 		case T_Append:
4319 			retval = _copyAppend(from);
4320 			break;
4321 		case T_MergeAppend:
4322 			retval = _copyMergeAppend(from);
4323 			break;
4324 		case T_RecursiveUnion:
4325 			retval = _copyRecursiveUnion(from);
4326 			break;
4327 		case T_BitmapAnd:
4328 			retval = _copyBitmapAnd(from);
4329 			break;
4330 		case T_BitmapOr:
4331 			retval = _copyBitmapOr(from);
4332 			break;
4333 		case T_Scan:
4334 			retval = _copyScan(from);
4335 			break;
4336 		case T_Gather:
4337 			retval = _copyGather(from);
4338 			break;
4339 		case T_SeqScan:
4340 			retval = _copySeqScan(from);
4341 			break;
4342 		case T_SampleScan:
4343 			retval = _copySampleScan(from);
4344 			break;
4345 		case T_IndexScan:
4346 			retval = _copyIndexScan(from);
4347 			break;
4348 		case T_IndexOnlyScan:
4349 			retval = _copyIndexOnlyScan(from);
4350 			break;
4351 		case T_BitmapIndexScan:
4352 			retval = _copyBitmapIndexScan(from);
4353 			break;
4354 		case T_BitmapHeapScan:
4355 			retval = _copyBitmapHeapScan(from);
4356 			break;
4357 		case T_TidScan:
4358 			retval = _copyTidScan(from);
4359 			break;
4360 		case T_SubqueryScan:
4361 			retval = _copySubqueryScan(from);
4362 			break;
4363 		case T_FunctionScan:
4364 			retval = _copyFunctionScan(from);
4365 			break;
4366 		case T_ValuesScan:
4367 			retval = _copyValuesScan(from);
4368 			break;
4369 		case T_CteScan:
4370 			retval = _copyCteScan(from);
4371 			break;
4372 		case T_WorkTableScan:
4373 			retval = _copyWorkTableScan(from);
4374 			break;
4375 		case T_ForeignScan:
4376 			retval = _copyForeignScan(from);
4377 			break;
4378 		case T_CustomScan:
4379 			retval = _copyCustomScan(from);
4380 			break;
4381 		case T_Join:
4382 			retval = _copyJoin(from);
4383 			break;
4384 		case T_NestLoop:
4385 			retval = _copyNestLoop(from);
4386 			break;
4387 		case T_MergeJoin:
4388 			retval = _copyMergeJoin(from);
4389 			break;
4390 		case T_HashJoin:
4391 			retval = _copyHashJoin(from);
4392 			break;
4393 		case T_Material:
4394 			retval = _copyMaterial(from);
4395 			break;
4396 		case T_Sort:
4397 			retval = _copySort(from);
4398 			break;
4399 		case T_Group:
4400 			retval = _copyGroup(from);
4401 			break;
4402 		case T_Agg:
4403 			retval = _copyAgg(from);
4404 			break;
4405 		case T_WindowAgg:
4406 			retval = _copyWindowAgg(from);
4407 			break;
4408 		case T_Unique:
4409 			retval = _copyUnique(from);
4410 			break;
4411 		case T_Hash:
4412 			retval = _copyHash(from);
4413 			break;
4414 		case T_SetOp:
4415 			retval = _copySetOp(from);
4416 			break;
4417 		case T_LockRows:
4418 			retval = _copyLockRows(from);
4419 			break;
4420 		case T_Limit:
4421 			retval = _copyLimit(from);
4422 			break;
4423 		case T_NestLoopParam:
4424 			retval = _copyNestLoopParam(from);
4425 			break;
4426 		case T_PlanRowMark:
4427 			retval = _copyPlanRowMark(from);
4428 			break;
4429 		case T_PlanInvalItem:
4430 			retval = _copyPlanInvalItem(from);
4431 			break;
4432 #endif
4433 
4434 			/*
4435 			 * PRIMITIVE NODES
4436 			 */
4437 		case T_Alias:
4438 			retval = _copyAlias(from);
4439 			break;
4440 		case T_RangeVar:
4441 			retval = _copyRangeVar(from);
4442 			break;
4443 		case T_IntoClause:
4444 			retval = _copyIntoClause(from);
4445 			break;
4446 		case T_Var:
4447 			retval = _copyVar(from);
4448 			break;
4449 #ifdef NOT_USED_IN_PGPOOL
4450 		case T_Const:
4451 			retval = _copyConst(from);
4452 			break;
4453 #endif
4454 		case T_Param:
4455 			retval = _copyParam(from);
4456 			break;
4457 		case T_Aggref:
4458 			retval = _copyAggref(from);
4459 			break;
4460 		case T_GroupingFunc:
4461 			retval = _copyGroupingFunc(from);
4462 			break;
4463 		case T_WindowFunc:
4464 			retval = _copyWindowFunc(from);
4465 			break;
4466 		case T_ArrayRef:
4467 			retval = _copyArrayRef(from);
4468 			break;
4469 		case T_FuncExpr:
4470 			retval = _copyFuncExpr(from);
4471 			break;
4472 		case T_NamedArgExpr:
4473 			retval = _copyNamedArgExpr(from);
4474 			break;
4475 		case T_OpExpr:
4476 			retval = _copyOpExpr(from);
4477 			break;
4478 		case T_DistinctExpr:
4479 			retval = _copyDistinctExpr(from);
4480 			break;
4481 		case T_NullIfExpr:
4482 			retval = _copyNullIfExpr(from);
4483 			break;
4484 		case T_ScalarArrayOpExpr:
4485 			retval = _copyScalarArrayOpExpr(from);
4486 			break;
4487 		case T_BoolExpr:
4488 			retval = _copyBoolExpr(from);
4489 			break;
4490 		case T_SubLink:
4491 			retval = _copySubLink(from);
4492 			break;
4493 		case T_SubPlan:
4494 			retval = _copySubPlan(from);
4495 			break;
4496 		case T_AlternativeSubPlan:
4497 			retval = _copyAlternativeSubPlan(from);
4498 			break;
4499 		case T_FieldSelect:
4500 			retval = _copyFieldSelect(from);
4501 			break;
4502 		case T_FieldStore:
4503 			retval = _copyFieldStore(from);
4504 			break;
4505 		case T_RelabelType:
4506 			retval = _copyRelabelType(from);
4507 			break;
4508 		case T_CoerceViaIO:
4509 			retval = _copyCoerceViaIO(from);
4510 			break;
4511 		case T_ArrayCoerceExpr:
4512 			retval = _copyArrayCoerceExpr(from);
4513 			break;
4514 		case T_ConvertRowtypeExpr:
4515 			retval = _copyConvertRowtypeExpr(from);
4516 			break;
4517 		case T_CollateExpr:
4518 			retval = _copyCollateExpr(from);
4519 			break;
4520 		case T_CaseExpr:
4521 			retval = _copyCaseExpr(from);
4522 			break;
4523 		case T_CaseWhen:
4524 			retval = _copyCaseWhen(from);
4525 			break;
4526 		case T_CaseTestExpr:
4527 			retval = _copyCaseTestExpr(from);
4528 			break;
4529 		case T_ArrayExpr:
4530 			retval = _copyArrayExpr(from);
4531 			break;
4532 		case T_RowExpr:
4533 			retval = _copyRowExpr(from);
4534 			break;
4535 		case T_RowCompareExpr:
4536 			retval = _copyRowCompareExpr(from);
4537 			break;
4538 		case T_CoalesceExpr:
4539 			retval = _copyCoalesceExpr(from);
4540 			break;
4541 		case T_MinMaxExpr:
4542 			retval = _copyMinMaxExpr(from);
4543 			break;
4544 		case T_XmlExpr:
4545 			retval = _copyXmlExpr(from);
4546 			break;
4547 		case T_NullTest:
4548 			retval = _copyNullTest(from);
4549 			break;
4550 		case T_BooleanTest:
4551 			retval = _copyBooleanTest(from);
4552 			break;
4553 		case T_CoerceToDomain:
4554 			retval = _copyCoerceToDomain(from);
4555 			break;
4556 		case T_CoerceToDomainValue:
4557 			retval = _copyCoerceToDomainValue(from);
4558 			break;
4559 		case T_SetToDefault:
4560 			retval = _copySetToDefault(from);
4561 			break;
4562 		case T_CurrentOfExpr:
4563 			retval = _copyCurrentOfExpr(from);
4564 			break;
4565 		case T_InferenceElem:
4566 			retval = _copyInferenceElem(from);
4567 			break;
4568 		case T_TargetEntry:
4569 			retval = _copyTargetEntry(from);
4570 			break;
4571 		case T_RangeTblRef:
4572 			retval = _copyRangeTblRef(from);
4573 			break;
4574 		case T_JoinExpr:
4575 			retval = _copyJoinExpr(from);
4576 			break;
4577 		case T_FromExpr:
4578 			retval = _copyFromExpr(from);
4579 			break;
4580 		case T_OnConflictExpr:
4581 			retval = _copyOnConflictExpr(from);
4582 			break;
4583 
4584 #ifdef NOT_USED_IN_PGPOOL
4585 			/*
4586 			 * RELATION NODES
4587 			 */
4588 		case T_PathKey:
4589 			retval = _copyPathKey(from);
4590 			break;
4591 		case T_RestrictInfo:
4592 			retval = _copyRestrictInfo(from);
4593 			break;
4594 		case T_PlaceHolderVar:
4595 			retval = _copyPlaceHolderVar(from);
4596 			break;
4597 		case T_SpecialJoinInfo:
4598 			retval = _copySpecialJoinInfo(from);
4599 			break;
4600 		case T_AppendRelInfo:
4601 			retval = _copyAppendRelInfo(from);
4602 			break;
4603 		case T_PlaceHolderInfo:
4604 			retval = _copyPlaceHolderInfo(from);
4605 			break;
4606 
4607 #endif
4608 			/*
4609 			 * VALUE NODES
4610 			 */
4611 		case T_Integer:
4612 		case T_Float:
4613 		case T_String:
4614 		case T_BitString:
4615 		case T_Null:
4616 			retval = _copyValue(from);
4617 			break;
4618 
4619 			/*
4620 			 * LIST NODES
4621 			 */
4622 		case T_List:
4623 			retval = _copyList(from);
4624 			break;
4625 
4626 			/*
4627 			 * Lists of integers and OIDs don't need to be deep-copied, so we
4628 			 * perform a shallow copy via list_copy()
4629 			 */
4630 		case T_IntList:
4631 		case T_OidList:
4632 			retval = list_copy(from);
4633 			break;
4634 
4635 #ifdef NOT_USED_IN_PGPOOL
4636 			/*
4637 			 * EXTENSIBLE NODES
4638 			 */
4639 		case T_ExtensibleNode:
4640 			retval = _copyExtensibleNode(from);
4641 			break;
4642 #endif
4643 
4644 			/*
4645 			 * PARSE NODES
4646 			 */
4647 		case T_Query:
4648 			retval = _copyQuery(from);
4649 			break;
4650 		case T_InsertStmt:
4651 			retval = _copyInsertStmt(from);
4652 			break;
4653 		case T_DeleteStmt:
4654 			retval = _copyDeleteStmt(from);
4655 			break;
4656 		case T_UpdateStmt:
4657 			retval = _copyUpdateStmt(from);
4658 			break;
4659 		case T_SelectStmt:
4660 			retval = _copySelectStmt(from);
4661 			break;
4662 		case T_SetOperationStmt:
4663 			retval = _copySetOperationStmt(from);
4664 			break;
4665 		case T_AlterTableStmt:
4666 			retval = _copyAlterTableStmt(from);
4667 			break;
4668 		case T_AlterTableCmd:
4669 			retval = _copyAlterTableCmd(from);
4670 			break;
4671 		case T_AlterDomainStmt:
4672 			retval = _copyAlterDomainStmt(from);
4673 			break;
4674 		case T_GrantStmt:
4675 			retval = _copyGrantStmt(from);
4676 			break;
4677 		case T_GrantRoleStmt:
4678 			retval = _copyGrantRoleStmt(from);
4679 			break;
4680 		case T_AlterDefaultPrivilegesStmt:
4681 			retval = _copyAlterDefaultPrivilegesStmt(from);
4682 			break;
4683 		case T_DeclareCursorStmt:
4684 			retval = _copyDeclareCursorStmt(from);
4685 			break;
4686 		case T_ClosePortalStmt:
4687 			retval = _copyClosePortalStmt(from);
4688 			break;
4689 		case T_ClusterStmt:
4690 			retval = _copyClusterStmt(from);
4691 			break;
4692 		case T_CopyStmt:
4693 			retval = _copyCopyStmt(from);
4694 			break;
4695 		case T_CreateStmt:
4696 			retval = _copyCreateStmt(from);
4697 			break;
4698 		case T_TableLikeClause:
4699 			retval = _copyTableLikeClause(from);
4700 			break;
4701 		case T_DefineStmt:
4702 			retval = _copyDefineStmt(from);
4703 			break;
4704 		case T_DropStmt:
4705 			retval = _copyDropStmt(from);
4706 			break;
4707 		case T_TruncateStmt:
4708 			retval = _copyTruncateStmt(from);
4709 			break;
4710 		case T_CommentStmt:
4711 			retval = _copyCommentStmt(from);
4712 			break;
4713 		case T_SecLabelStmt:
4714 			retval = _copySecLabelStmt(from);
4715 			break;
4716 		case T_FetchStmt:
4717 			retval = _copyFetchStmt(from);
4718 			break;
4719 		case T_IndexStmt:
4720 			retval = _copyIndexStmt(from);
4721 			break;
4722 		case T_CreateFunctionStmt:
4723 			retval = _copyCreateFunctionStmt(from);
4724 			break;
4725 		case T_FunctionParameter:
4726 			retval = _copyFunctionParameter(from);
4727 			break;
4728 		case T_AlterFunctionStmt:
4729 			retval = _copyAlterFunctionStmt(from);
4730 			break;
4731 		case T_DoStmt:
4732 			retval = _copyDoStmt(from);
4733 			break;
4734 		case T_RenameStmt:
4735 			retval = _copyRenameStmt(from);
4736 			break;
4737 		case T_AlterObjectDependsStmt:
4738 			retval = _copyAlterObjectDependsStmt(from);
4739 			break;
4740 		case T_AlterObjectSchemaStmt:
4741 			retval = _copyAlterObjectSchemaStmt(from);
4742 			break;
4743 		case T_AlterOwnerStmt:
4744 			retval = _copyAlterOwnerStmt(from);
4745 			break;
4746 		case T_AlterOperatorStmt:
4747 			retval = _copyAlterOperatorStmt(from);
4748 			break;
4749 		case T_RuleStmt:
4750 			retval = _copyRuleStmt(from);
4751 			break;
4752 		case T_NotifyStmt:
4753 			retval = _copyNotifyStmt(from);
4754 			break;
4755 		case T_ListenStmt:
4756 			retval = _copyListenStmt(from);
4757 			break;
4758 		case T_UnlistenStmt:
4759 			retval = _copyUnlistenStmt(from);
4760 			break;
4761 		case T_TransactionStmt:
4762 			retval = _copyTransactionStmt(from);
4763 			break;
4764 		case T_CompositeTypeStmt:
4765 			retval = _copyCompositeTypeStmt(from);
4766 			break;
4767 		case T_CreateEnumStmt:
4768 			retval = _copyCreateEnumStmt(from);
4769 			break;
4770 		case T_CreateRangeStmt:
4771 			retval = _copyCreateRangeStmt(from);
4772 			break;
4773 		case T_AlterEnumStmt:
4774 			retval = _copyAlterEnumStmt(from);
4775 			break;
4776 		case T_ViewStmt:
4777 			retval = _copyViewStmt(from);
4778 			break;
4779 		case T_LoadStmt:
4780 			retval = _copyLoadStmt(from);
4781 			break;
4782 		case T_CreateDomainStmt:
4783 			retval = _copyCreateDomainStmt(from);
4784 			break;
4785 		case T_CreateOpClassStmt:
4786 			retval = _copyCreateOpClassStmt(from);
4787 			break;
4788 		case T_CreateOpClassItem:
4789 			retval = _copyCreateOpClassItem(from);
4790 			break;
4791 		case T_CreateOpFamilyStmt:
4792 			retval = _copyCreateOpFamilyStmt(from);
4793 			break;
4794 		case T_AlterOpFamilyStmt:
4795 			retval = _copyAlterOpFamilyStmt(from);
4796 			break;
4797 		case T_CreatedbStmt:
4798 			retval = _copyCreatedbStmt(from);
4799 			break;
4800 		case T_AlterDatabaseStmt:
4801 			retval = _copyAlterDatabaseStmt(from);
4802 			break;
4803 		case T_AlterDatabaseSetStmt:
4804 			retval = _copyAlterDatabaseSetStmt(from);
4805 			break;
4806 		case T_DropdbStmt:
4807 			retval = _copyDropdbStmt(from);
4808 			break;
4809 		case T_VacuumStmt:
4810 			retval = _copyVacuumStmt(from);
4811 			break;
4812 		case T_ExplainStmt:
4813 			retval = _copyExplainStmt(from);
4814 			break;
4815 		case T_CreateTableAsStmt:
4816 			retval = _copyCreateTableAsStmt(from);
4817 			break;
4818 		case T_RefreshMatViewStmt:
4819 			retval = _copyRefreshMatViewStmt(from);
4820 			break;
4821 		case T_ReplicaIdentityStmt:
4822 			retval = _copyReplicaIdentityStmt(from);
4823 			break;
4824 		case T_AlterSystemStmt:
4825 			retval = _copyAlterSystemStmt(from);
4826 			break;
4827 		case T_CreateSeqStmt:
4828 			retval = _copyCreateSeqStmt(from);
4829 			break;
4830 		case T_AlterSeqStmt:
4831 			retval = _copyAlterSeqStmt(from);
4832 			break;
4833 		case T_VariableSetStmt:
4834 			retval = _copyVariableSetStmt(from);
4835 			break;
4836 		case T_VariableShowStmt:
4837 			retval = _copyVariableShowStmt(from);
4838 			break;
4839 		case T_DiscardStmt:
4840 			retval = _copyDiscardStmt(from);
4841 			break;
4842 		case T_CreateTableSpaceStmt:
4843 			retval = _copyCreateTableSpaceStmt(from);
4844 			break;
4845 		case T_DropTableSpaceStmt:
4846 			retval = _copyDropTableSpaceStmt(from);
4847 			break;
4848 		case T_AlterTableSpaceOptionsStmt:
4849 			retval = _copyAlterTableSpaceOptionsStmt(from);
4850 			break;
4851 		case T_AlterTableMoveAllStmt:
4852 			retval = _copyAlterTableMoveAllStmt(from);
4853 			break;
4854 		case T_CreateExtensionStmt:
4855 			retval = _copyCreateExtensionStmt(from);
4856 			break;
4857 		case T_AlterExtensionStmt:
4858 			retval = _copyAlterExtensionStmt(from);
4859 			break;
4860 		case T_AlterExtensionContentsStmt:
4861 			retval = _copyAlterExtensionContentsStmt(from);
4862 			break;
4863 		case T_CreateFdwStmt:
4864 			retval = _copyCreateFdwStmt(from);
4865 			break;
4866 		case T_AlterFdwStmt:
4867 			retval = _copyAlterFdwStmt(from);
4868 			break;
4869 		case T_CreateForeignServerStmt:
4870 			retval = _copyCreateForeignServerStmt(from);
4871 			break;
4872 		case T_AlterForeignServerStmt:
4873 			retval = _copyAlterForeignServerStmt(from);
4874 			break;
4875 		case T_CreateUserMappingStmt:
4876 			retval = _copyCreateUserMappingStmt(from);
4877 			break;
4878 		case T_AlterUserMappingStmt:
4879 			retval = _copyAlterUserMappingStmt(from);
4880 			break;
4881 		case T_DropUserMappingStmt:
4882 			retval = _copyDropUserMappingStmt(from);
4883 			break;
4884 		case T_CreateForeignTableStmt:
4885 			retval = _copyCreateForeignTableStmt(from);
4886 			break;
4887 		case T_ImportForeignSchemaStmt:
4888 			retval = _copyImportForeignSchemaStmt(from);
4889 			break;
4890 		case T_CreateTransformStmt:
4891 			retval = _copyCreateTransformStmt(from);
4892 			break;
4893 		case T_CreateAmStmt:
4894 			retval = _copyCreateAmStmt(from);
4895 			break;
4896 		case T_CreateTrigStmt:
4897 			retval = _copyCreateTrigStmt(from);
4898 			break;
4899 		case T_CreateEventTrigStmt:
4900 			retval = _copyCreateEventTrigStmt(from);
4901 			break;
4902 		case T_AlterEventTrigStmt:
4903 			retval = _copyAlterEventTrigStmt(from);
4904 			break;
4905 		case T_CreatePLangStmt:
4906 			retval = _copyCreatePLangStmt(from);
4907 			break;
4908 		case T_CreateRoleStmt:
4909 			retval = _copyCreateRoleStmt(from);
4910 			break;
4911 		case T_AlterRoleStmt:
4912 			retval = _copyAlterRoleStmt(from);
4913 			break;
4914 		case T_AlterRoleSetStmt:
4915 			retval = _copyAlterRoleSetStmt(from);
4916 			break;
4917 		case T_DropRoleStmt:
4918 			retval = _copyDropRoleStmt(from);
4919 			break;
4920 		case T_LockStmt:
4921 			retval = _copyLockStmt(from);
4922 			break;
4923 		case T_ConstraintsSetStmt:
4924 			retval = _copyConstraintsSetStmt(from);
4925 			break;
4926 		case T_ReindexStmt:
4927 			retval = _copyReindexStmt(from);
4928 			break;
4929 		case T_CheckPointStmt:
4930 			retval = (void *) makeNode(CheckPointStmt);
4931 			break;
4932 		case T_CreateSchemaStmt:
4933 			retval = _copyCreateSchemaStmt(from);
4934 			break;
4935 		case T_CreateConversionStmt:
4936 			retval = _copyCreateConversionStmt(from);
4937 			break;
4938 		case T_CreateCastStmt:
4939 			retval = _copyCreateCastStmt(from);
4940 			break;
4941 		case T_PrepareStmt:
4942 			retval = _copyPrepareStmt(from);
4943 			break;
4944 		case T_ExecuteStmt:
4945 			retval = _copyExecuteStmt(from);
4946 			break;
4947 		case T_DeallocateStmt:
4948 			retval = _copyDeallocateStmt(from);
4949 			break;
4950 		case T_DropOwnedStmt:
4951 			retval = _copyDropOwnedStmt(from);
4952 			break;
4953 		case T_ReassignOwnedStmt:
4954 			retval = _copyReassignOwnedStmt(from);
4955 			break;
4956 		case T_AlterTSDictionaryStmt:
4957 			retval = _copyAlterTSDictionaryStmt(from);
4958 			break;
4959 		case T_AlterTSConfigurationStmt:
4960 			retval = _copyAlterTSConfigurationStmt(from);
4961 			break;
4962 		case T_CreatePolicyStmt:
4963 			retval = _copyCreatePolicyStmt(from);
4964 			break;
4965 		case T_AlterPolicyStmt:
4966 			retval = _copyAlterPolicyStmt(from);
4967 			break;
4968 		case T_A_Expr:
4969 			retval = _copyAExpr(from);
4970 			break;
4971 		case T_ColumnRef:
4972 			retval = _copyColumnRef(from);
4973 			break;
4974 		case T_ParamRef:
4975 			retval = _copyParamRef(from);
4976 			break;
4977 		case T_A_Const:
4978 			retval = _copyAConst(from);
4979 			break;
4980 		case T_FuncCall:
4981 			retval = _copyFuncCall(from);
4982 			break;
4983 		case T_A_Star:
4984 			retval = _copyAStar(from);
4985 			break;
4986 		case T_A_Indices:
4987 			retval = _copyAIndices(from);
4988 			break;
4989 		case T_A_Indirection:
4990 			retval = _copyA_Indirection(from);
4991 			break;
4992 		case T_A_ArrayExpr:
4993 			retval = _copyA_ArrayExpr(from);
4994 			break;
4995 		case T_ResTarget:
4996 			retval = _copyResTarget(from);
4997 			break;
4998 		case T_MultiAssignRef:
4999 			retval = _copyMultiAssignRef(from);
5000 			break;
5001 		case T_TypeCast:
5002 			retval = _copyTypeCast(from);
5003 			break;
5004 		case T_CollateClause:
5005 			retval = _copyCollateClause(from);
5006 			break;
5007 		case T_SortBy:
5008 			retval = _copySortBy(from);
5009 			break;
5010 		case T_WindowDef:
5011 			retval = _copyWindowDef(from);
5012 			break;
5013 		case T_RangeSubselect:
5014 			retval = _copyRangeSubselect(from);
5015 			break;
5016 		case T_RangeFunction:
5017 			retval = _copyRangeFunction(from);
5018 			break;
5019 		case T_RangeTableSample:
5020 			retval = _copyRangeTableSample(from);
5021 			break;
5022 		case T_TypeName:
5023 			retval = _copyTypeName(from);
5024 			break;
5025 		case T_IndexElem:
5026 			retval = _copyIndexElem(from);
5027 			break;
5028 		case T_ColumnDef:
5029 			retval = _copyColumnDef(from);
5030 			break;
5031 		case T_Constraint:
5032 			retval = _copyConstraint(from);
5033 			break;
5034 		case T_DefElem:
5035 			retval = _copyDefElem(from);
5036 			break;
5037 		case T_LockingClause:
5038 			retval = _copyLockingClause(from);
5039 			break;
5040 		case T_RangeTblEntry:
5041 			retval = _copyRangeTblEntry(from);
5042 			break;
5043 		case T_RangeTblFunction:
5044 			retval = _copyRangeTblFunction(from);
5045 			break;
5046 		case T_TableSampleClause:
5047 			retval = _copyTableSampleClause(from);
5048 			break;
5049 		case T_WithCheckOption:
5050 			retval = _copyWithCheckOption(from);
5051 			break;
5052 		case T_SortGroupClause:
5053 			retval = _copySortGroupClause(from);
5054 			break;
5055 		case T_GroupingSet:
5056 			retval = _copyGroupingSet(from);
5057 			break;
5058 		case T_WindowClause:
5059 			retval = _copyWindowClause(from);
5060 			break;
5061 		case T_RowMarkClause:
5062 			retval = _copyRowMarkClause(from);
5063 			break;
5064 		case T_WithClause:
5065 			retval = _copyWithClause(from);
5066 			break;
5067 		case T_InferClause:
5068 			retval = _copyInferClause(from);
5069 			break;
5070 		case T_OnConflictClause:
5071 			retval = _copyOnConflictClause(from);
5072 			break;
5073 		case T_CommonTableExpr:
5074 			retval = _copyCommonTableExpr(from);
5075 			break;
5076 		case T_FuncWithArgs:
5077 			retval = _copyFuncWithArgs(from);
5078 			break;
5079 		case T_AccessPriv:
5080 			retval = _copyAccessPriv(from);
5081 			break;
5082 		case T_XmlSerialize:
5083 			retval = _copyXmlSerialize(from);
5084 			break;
5085 		case T_RoleSpec:
5086 			retval = _copyRoleSpec(from);
5087 			break;
5088 
5089 #ifdef NOT_USED_IN_PGPOOL
5090 			/*
5091 			 * MISCELLANEOUS NODES
5092 			 */
5093 		case T_ForeignKeyCacheInfo:
5094 			retval = _copyForeignKeyCacheInfo(from);
5095 			break;
5096 #endif
5097 
5098 		default:
5099 			elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
5100 			retval = 0;			/* keep compiler quiet */
5101 			break;
5102 	}
5103 
5104 	return retval;
5105 }
5106 
5107 /*
5108  * from src/backend/nodes/bitmapset.c
5109  * bms_copy - make a palloc'd copy of a bitmapset
5110  */
5111 
5112 #define BITMAPSET_SIZE(nwords)  \
5113 (offsetof(Bitmapset, words) + (nwords) * sizeof(bitmapword))
5114 
5115 
5116 Bitmapset *
bms_copy(const Bitmapset * a)5117 bms_copy(const Bitmapset *a)
5118 {
5119 	Bitmapset  *result;
5120 	size_t		size;
5121 
5122 	if (a == NULL)
5123 		return NULL;
5124 	size = BITMAPSET_SIZE(a->nwords);
5125 	result = (Bitmapset *) palloc(size);
5126 	memcpy(result, a, size);
5127 	return result;
5128 }
5129