1
/*-------------------------------------------------------------------------
4
* Copy functions for Postgres tree nodes.
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.
14
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
15
* Portions Copyright (c) 1994, Regents of the University of California
18
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.295 2004-12-31 21:59:55 pgsql Exp $
20
*-------------------------------------------------------------------------
25
#include "nodes/parsenodes.h"
26
#include "nodes/plannodes.h"
27
#include "nodes/relation.h"
28
#include "utils/datum.h"
32
* Macros to simplify copying of different kinds of fields. Use these
33
* wherever possible to reduce the chance for silly typos. Note that these
34
* hard-wire the convention that the local variables in a Copy routine are
35
* named 'newnode' and 'from'.
38
/* Copy a simple scalar field (int, float, bool, enum, etc) */
39
#define COPY_SCALAR_FIELD(fldname) \
40
(newnode->fldname = from->fldname)
42
/* Copy a field that is a pointer to some kind of Node or Node tree */
43
#define COPY_NODE_FIELD(fldname) \
44
(newnode->fldname = copyObject(from->fldname))
46
/* Copy a field that is a pointer to a Bitmapset */
47
#define COPY_BITMAPSET_FIELD(fldname) \
48
(newnode->fldname = bms_copy(from->fldname))
50
/* Copy a field that is a pointer to a C string, or perhaps NULL */
51
#define COPY_STRING_FIELD(fldname) \
52
(newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)
54
/* Copy a field that is a pointer to a simple palloc'd object of size sz */
55
#define COPY_POINTER_FIELD(fldname, sz) \
58
newnode->fldname = palloc(_size); \
59
memcpy(newnode->fldname, from->fldname, _size); \
63
/* ****************************************************************
64
* plannodes.h copy functions
65
* ****************************************************************
71
* This function copies the fields of the Plan node. It is used by
72
* all the copy functions for classes which inherit from Plan.
75
CopyPlanFields(Plan *from, Plan *newnode)
77
COPY_SCALAR_FIELD(startup_cost);
78
COPY_SCALAR_FIELD(total_cost);
79
COPY_SCALAR_FIELD(plan_rows);
80
COPY_SCALAR_FIELD(plan_width);
81
COPY_NODE_FIELD(targetlist);
82
COPY_NODE_FIELD(qual);
83
COPY_NODE_FIELD(lefttree);
84
COPY_NODE_FIELD(righttree);
85
COPY_NODE_FIELD(initPlan);
86
COPY_BITMAPSET_FIELD(extParam);
87
COPY_BITMAPSET_FIELD(allParam);
88
COPY_SCALAR_FIELD(nParamExec);
97
Plan *newnode = makeNode(Plan);
100
* copy node superclass fields
102
CopyPlanFields(from, newnode);
112
_copyResult(Result *from)
114
Result *newnode = makeNode(Result);
117
* copy node superclass fields
119
CopyPlanFields((Plan *) from, (Plan *) newnode);
122
* copy remainder of node
124
COPY_NODE_FIELD(resconstantqual);
133
_copyAppend(Append *from)
135
Append *newnode = makeNode(Append);
138
* copy node superclass fields
140
CopyPlanFields((Plan *) from, (Plan *) newnode);
143
* copy remainder of node
145
COPY_NODE_FIELD(appendplans);
146
COPY_SCALAR_FIELD(isTarget);
155
* This function copies the fields of the Scan node. It is used by
156
* all the copy functions for classes which inherit from Scan.
159
CopyScanFields(Scan *from, Scan *newnode)
161
CopyPlanFields((Plan *) from, (Plan *) newnode);
163
COPY_SCALAR_FIELD(scanrelid);
170
_copyScan(Scan *from)
172
Scan *newnode = makeNode(Scan);
175
* copy node superclass fields
177
CopyScanFields((Scan *) from, (Scan *) newnode);
186
_copySeqScan(SeqScan *from)
188
SeqScan *newnode = makeNode(SeqScan);
191
* copy node superclass fields
193
CopyScanFields((Scan *) from, (Scan *) newnode);
202
_copyIndexScan(IndexScan *from)
204
IndexScan *newnode = makeNode(IndexScan);
207
* copy node superclass fields
209
CopyScanFields((Scan *) from, (Scan *) newnode);
212
* copy remainder of node
214
COPY_NODE_FIELD(indxid);
215
COPY_NODE_FIELD(indxqual);
216
COPY_NODE_FIELD(indxqualorig);
217
COPY_NODE_FIELD(indxstrategy);
218
COPY_NODE_FIELD(indxsubtype);
219
COPY_NODE_FIELD(indxlossy);
220
COPY_SCALAR_FIELD(indxorderdir);
229
_copyTidScan(TidScan *from)
231
TidScan *newnode = makeNode(TidScan);
234
* copy node superclass fields
236
CopyScanFields((Scan *) from, (Scan *) newnode);
239
* copy remainder of node
241
COPY_NODE_FIELD(tideval);
249
static SubqueryScan *
250
_copySubqueryScan(SubqueryScan *from)
252
SubqueryScan *newnode = makeNode(SubqueryScan);
255
* copy node superclass fields
257
CopyScanFields((Scan *) from, (Scan *) newnode);
260
* copy remainder of node
262
COPY_NODE_FIELD(subplan);
270
static FunctionScan *
271
_copyFunctionScan(FunctionScan *from)
273
FunctionScan *newnode = makeNode(FunctionScan);
276
* copy node superclass fields
278
CopyScanFields((Scan *) from, (Scan *) newnode);
286
* This function copies the fields of the Join node. It is used by
287
* all the copy functions for classes which inherit from Join.
290
CopyJoinFields(Join *from, Join *newnode)
292
CopyPlanFields((Plan *) from, (Plan *) newnode);
294
COPY_SCALAR_FIELD(jointype);
295
COPY_NODE_FIELD(joinqual);
303
_copyJoin(Join *from)
305
Join *newnode = makeNode(Join);
308
* copy node superclass fields
310
CopyJoinFields(from, newnode);
320
_copyNestLoop(NestLoop *from)
322
NestLoop *newnode = makeNode(NestLoop);
325
* copy node superclass fields
327
CopyJoinFields((Join *) from, (Join *) newnode);
337
_copyMergeJoin(MergeJoin *from)
339
MergeJoin *newnode = makeNode(MergeJoin);
342
* copy node superclass fields
344
CopyJoinFields((Join *) from, (Join *) newnode);
347
* copy remainder of node
349
COPY_NODE_FIELD(mergeclauses);
358
_copyHashJoin(HashJoin *from)
360
HashJoin *newnode = makeNode(HashJoin);
363
* copy node superclass fields
365
CopyJoinFields((Join *) from, (Join *) newnode);
368
* copy remainder of node
370
COPY_NODE_FIELD(hashclauses);
380
_copyMaterial(Material *from)
382
Material *newnode = makeNode(Material);
385
* copy node superclass fields
387
CopyPlanFields((Plan *) from, (Plan *) newnode);
397
_copySort(Sort *from)
399
Sort *newnode = makeNode(Sort);
402
* copy node superclass fields
404
CopyPlanFields((Plan *) from, (Plan *) newnode);
406
COPY_SCALAR_FIELD(numCols);
407
COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
408
COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
418
_copyGroup(Group *from)
420
Group *newnode = makeNode(Group);
422
CopyPlanFields((Plan *) from, (Plan *) newnode);
424
COPY_SCALAR_FIELD(numCols);
425
COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
436
Agg *newnode = makeNode(Agg);
438
CopyPlanFields((Plan *) from, (Plan *) newnode);
440
COPY_SCALAR_FIELD(aggstrategy);
441
COPY_SCALAR_FIELD(numCols);
442
if (from->numCols > 0)
443
COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
444
COPY_SCALAR_FIELD(numGroups);
453
_copyUnique(Unique *from)
455
Unique *newnode = makeNode(Unique);
458
* copy node superclass fields
460
CopyPlanFields((Plan *) from, (Plan *) newnode);
463
* copy remainder of node
465
COPY_SCALAR_FIELD(numCols);
466
COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
475
_copyHash(Hash *from)
477
Hash *newnode = makeNode(Hash);
480
* copy node superclass fields
482
CopyPlanFields((Plan *) from, (Plan *) newnode);
485
* copy remainder of node
495
_copySetOp(SetOp *from)
497
SetOp *newnode = makeNode(SetOp);
500
* copy node superclass fields
502
CopyPlanFields((Plan *) from, (Plan *) newnode);
505
* copy remainder of node
507
COPY_SCALAR_FIELD(cmd);
508
COPY_SCALAR_FIELD(numCols);
509
COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
510
COPY_SCALAR_FIELD(flagColIdx);
519
_copyLimit(Limit *from)
521
Limit *newnode = makeNode(Limit);
524
* copy node superclass fields
526
CopyPlanFields((Plan *) from, (Plan *) newnode);
529
* copy remainder of node
531
COPY_NODE_FIELD(limitOffset);
532
COPY_NODE_FIELD(limitCount);
537
/* ****************************************************************
538
* primnodes.h copy functions
539
* ****************************************************************
546
_copyResdom(Resdom *from)
548
Resdom *newnode = makeNode(Resdom);
550
COPY_SCALAR_FIELD(resno);
551
COPY_SCALAR_FIELD(restype);
552
COPY_SCALAR_FIELD(restypmod);
553
COPY_STRING_FIELD(resname);
554
COPY_SCALAR_FIELD(ressortgroupref);
555
COPY_SCALAR_FIELD(resorigtbl);
556
COPY_SCALAR_FIELD(resorigcol);
557
COPY_SCALAR_FIELD(resjunk);
566
_copyAlias(Alias *from)
568
Alias *newnode = makeNode(Alias);
570
COPY_STRING_FIELD(aliasname);
571
COPY_NODE_FIELD(colnames);
580
_copyRangeVar(RangeVar *from)
582
RangeVar *newnode = makeNode(RangeVar);
584
COPY_STRING_FIELD(catalogname);
585
COPY_STRING_FIELD(schemaname);
586
COPY_STRING_FIELD(relname);
587
COPY_SCALAR_FIELD(inhOpt);
588
COPY_SCALAR_FIELD(istemp);
589
COPY_NODE_FIELD(alias);
595
* We don't need a _copyExpr because Expr is an abstract supertype which
596
* should never actually get instantiated. Also, since it has no common
597
* fields except NodeTag, there's no need for a helper routine to factor
598
* out copying the common fields...
607
Var *newnode = makeNode(Var);
609
COPY_SCALAR_FIELD(varno);
610
COPY_SCALAR_FIELD(varattno);
611
COPY_SCALAR_FIELD(vartype);
612
COPY_SCALAR_FIELD(vartypmod);
613
COPY_SCALAR_FIELD(varlevelsup);
614
COPY_SCALAR_FIELD(varnoold);
615
COPY_SCALAR_FIELD(varoattno);
624
_copyConst(Const *from)
626
Const *newnode = makeNode(Const);
628
COPY_SCALAR_FIELD(consttype);
629
COPY_SCALAR_FIELD(constlen);
631
if (from->constbyval || from->constisnull)
634
* passed by value so just copy the datum. Also, don't try to copy
635
* struct when value is null!
637
newnode->constvalue = from->constvalue;
642
* passed by reference. We need a palloc'd copy.
644
newnode->constvalue = datumCopy(from->constvalue,
649
COPY_SCALAR_FIELD(constisnull);
650
COPY_SCALAR_FIELD(constbyval);
659
_copyParam(Param *from)
661
Param *newnode = makeNode(Param);
663
COPY_SCALAR_FIELD(paramkind);
664
COPY_SCALAR_FIELD(paramid);
665
COPY_STRING_FIELD(paramname);
666
COPY_SCALAR_FIELD(paramtype);
675
_copyAggref(Aggref *from)
677
Aggref *newnode = makeNode(Aggref);
679
COPY_SCALAR_FIELD(aggfnoid);
680
COPY_SCALAR_FIELD(aggtype);
681
COPY_NODE_FIELD(target);
682
COPY_SCALAR_FIELD(agglevelsup);
683
COPY_SCALAR_FIELD(aggstar);
684
COPY_SCALAR_FIELD(aggdistinct);
693
_copyArrayRef(ArrayRef *from)
695
ArrayRef *newnode = makeNode(ArrayRef);
697
COPY_SCALAR_FIELD(refrestype);
698
COPY_SCALAR_FIELD(refarraytype);
699
COPY_SCALAR_FIELD(refelemtype);
700
COPY_NODE_FIELD(refupperindexpr);
701
COPY_NODE_FIELD(reflowerindexpr);
702
COPY_NODE_FIELD(refexpr);
703
COPY_NODE_FIELD(refassgnexpr);
712
_copyFuncExpr(FuncExpr *from)
714
FuncExpr *newnode = makeNode(FuncExpr);
716
COPY_SCALAR_FIELD(funcid);
717
COPY_SCALAR_FIELD(funcresulttype);
718
COPY_SCALAR_FIELD(funcretset);
719
COPY_SCALAR_FIELD(funcformat);
720
COPY_NODE_FIELD(args);
729
_copyOpExpr(OpExpr *from)
731
OpExpr *newnode = makeNode(OpExpr);
733
COPY_SCALAR_FIELD(opno);
734
COPY_SCALAR_FIELD(opfuncid);
735
COPY_SCALAR_FIELD(opresulttype);
736
COPY_SCALAR_FIELD(opretset);
737
COPY_NODE_FIELD(args);
743
* _copyDistinctExpr (same as OpExpr)
745
static DistinctExpr *
746
_copyDistinctExpr(DistinctExpr *from)
748
DistinctExpr *newnode = makeNode(DistinctExpr);
750
COPY_SCALAR_FIELD(opno);
751
COPY_SCALAR_FIELD(opfuncid);
752
COPY_SCALAR_FIELD(opresulttype);
753
COPY_SCALAR_FIELD(opretset);
754
COPY_NODE_FIELD(args);
760
* _copyScalarArrayOpExpr
762
static ScalarArrayOpExpr *
763
_copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
765
ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
767
COPY_SCALAR_FIELD(opno);
768
COPY_SCALAR_FIELD(opfuncid);
769
COPY_SCALAR_FIELD(useOr);
770
COPY_NODE_FIELD(args);
779
_copyBoolExpr(BoolExpr *from)
781
BoolExpr *newnode = makeNode(BoolExpr);
783
COPY_SCALAR_FIELD(boolop);
784
COPY_NODE_FIELD(args);
793
_copySubLink(SubLink *from)
795
SubLink *newnode = makeNode(SubLink);
797
COPY_SCALAR_FIELD(subLinkType);
798
COPY_SCALAR_FIELD(useOr);
799
COPY_NODE_FIELD(lefthand);
800
COPY_NODE_FIELD(operName);
801
COPY_NODE_FIELD(operOids);
802
COPY_NODE_FIELD(subselect);
811
_copySubPlan(SubPlan *from)
813
SubPlan *newnode = makeNode(SubPlan);
815
COPY_SCALAR_FIELD(subLinkType);
816
COPY_SCALAR_FIELD(useOr);
817
COPY_NODE_FIELD(exprs);
818
COPY_NODE_FIELD(paramIds);
819
COPY_NODE_FIELD(plan);
820
COPY_SCALAR_FIELD(plan_id);
821
COPY_NODE_FIELD(rtable);
822
COPY_SCALAR_FIELD(useHashTable);
823
COPY_SCALAR_FIELD(unknownEqFalse);
824
COPY_NODE_FIELD(setParam);
825
COPY_NODE_FIELD(parParam);
826
COPY_NODE_FIELD(args);
835
_copyFieldSelect(FieldSelect *from)
837
FieldSelect *newnode = makeNode(FieldSelect);
839
COPY_NODE_FIELD(arg);
840
COPY_SCALAR_FIELD(fieldnum);
841
COPY_SCALAR_FIELD(resulttype);
842
COPY_SCALAR_FIELD(resulttypmod);
851
_copyFieldStore(FieldStore *from)
853
FieldStore *newnode = makeNode(FieldStore);
855
COPY_NODE_FIELD(arg);
856
COPY_NODE_FIELD(newvals);
857
COPY_NODE_FIELD(fieldnums);
858
COPY_SCALAR_FIELD(resulttype);
867
_copyRelabelType(RelabelType *from)
869
RelabelType *newnode = makeNode(RelabelType);
871
COPY_NODE_FIELD(arg);
872
COPY_SCALAR_FIELD(resulttype);
873
COPY_SCALAR_FIELD(resulttypmod);
874
COPY_SCALAR_FIELD(relabelformat);
880
* _copyConvertRowtypeExpr
882
static ConvertRowtypeExpr *
883
_copyConvertRowtypeExpr(ConvertRowtypeExpr *from)
885
ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);
887
COPY_NODE_FIELD(arg);
888
COPY_SCALAR_FIELD(resulttype);
889
COPY_SCALAR_FIELD(convertformat);
898
_copyCaseExpr(CaseExpr *from)
900
CaseExpr *newnode = makeNode(CaseExpr);
902
COPY_SCALAR_FIELD(casetype);
903
COPY_NODE_FIELD(arg);
904
COPY_NODE_FIELD(args);
905
COPY_NODE_FIELD(defresult);
914
_copyCaseWhen(CaseWhen *from)
916
CaseWhen *newnode = makeNode(CaseWhen);
918
COPY_NODE_FIELD(expr);
919
COPY_NODE_FIELD(result);
927
static CaseTestExpr *
928
_copyCaseTestExpr(CaseTestExpr *from)
930
CaseTestExpr *newnode = makeNode(CaseTestExpr);
932
COPY_SCALAR_FIELD(typeId);
933
COPY_SCALAR_FIELD(typeMod);
942
_copyArrayExpr(ArrayExpr *from)
944
ArrayExpr *newnode = makeNode(ArrayExpr);
946
COPY_SCALAR_FIELD(array_typeid);
947
COPY_SCALAR_FIELD(element_typeid);
948
COPY_NODE_FIELD(elements);
949
COPY_SCALAR_FIELD(multidims);
958
_copyRowExpr(RowExpr *from)
960
RowExpr *newnode = makeNode(RowExpr);
962
COPY_NODE_FIELD(args);
963
COPY_SCALAR_FIELD(row_typeid);
964
COPY_SCALAR_FIELD(row_format);
972
static CoalesceExpr *
973
_copyCoalesceExpr(CoalesceExpr *from)
975
CoalesceExpr *newnode = makeNode(CoalesceExpr);
977
COPY_SCALAR_FIELD(coalescetype);
978
COPY_NODE_FIELD(args);
984
* _copyNullIfExpr (same as OpExpr)
987
_copyNullIfExpr(NullIfExpr *from)
989
NullIfExpr *newnode = makeNode(NullIfExpr);
991
COPY_SCALAR_FIELD(opno);
992
COPY_SCALAR_FIELD(opfuncid);
993
COPY_SCALAR_FIELD(opresulttype);
994
COPY_SCALAR_FIELD(opretset);
995
COPY_NODE_FIELD(args);
1004
_copyNullTest(NullTest *from)
1006
NullTest *newnode = makeNode(NullTest);
1008
COPY_NODE_FIELD(arg);
1009
COPY_SCALAR_FIELD(nulltesttype);
1017
static BooleanTest *
1018
_copyBooleanTest(BooleanTest *from)
1020
BooleanTest *newnode = makeNode(BooleanTest);
1022
COPY_NODE_FIELD(arg);
1023
COPY_SCALAR_FIELD(booltesttype);
1029
* _copyCoerceToDomain
1031
static CoerceToDomain *
1032
_copyCoerceToDomain(CoerceToDomain *from)
1034
CoerceToDomain *newnode = makeNode(CoerceToDomain);
1036
COPY_NODE_FIELD(arg);
1037
COPY_SCALAR_FIELD(resulttype);
1038
COPY_SCALAR_FIELD(resulttypmod);
1039
COPY_SCALAR_FIELD(coercionformat);
1045
* _copyCoerceToDomainValue
1047
static CoerceToDomainValue *
1048
_copyCoerceToDomainValue(CoerceToDomainValue *from)
1050
CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1052
COPY_SCALAR_FIELD(typeId);
1053
COPY_SCALAR_FIELD(typeMod);
1061
static SetToDefault *
1062
_copySetToDefault(SetToDefault *from)
1064
SetToDefault *newnode = makeNode(SetToDefault);
1066
COPY_SCALAR_FIELD(typeId);
1067
COPY_SCALAR_FIELD(typeMod);
1075
static TargetEntry *
1076
_copyTargetEntry(TargetEntry *from)
1078
TargetEntry *newnode = makeNode(TargetEntry);
1080
COPY_NODE_FIELD(resdom);
1081
COPY_NODE_FIELD(expr);
1089
static RangeTblRef *
1090
_copyRangeTblRef(RangeTblRef *from)
1092
RangeTblRef *newnode = makeNode(RangeTblRef);
1094
COPY_SCALAR_FIELD(rtindex);
1103
_copyJoinExpr(JoinExpr *from)
1105
JoinExpr *newnode = makeNode(JoinExpr);
1107
COPY_SCALAR_FIELD(jointype);
1108
COPY_SCALAR_FIELD(isNatural);
1109
COPY_NODE_FIELD(larg);
1110
COPY_NODE_FIELD(rarg);
1111
COPY_NODE_FIELD(using);
1112
COPY_NODE_FIELD(quals);
1113
COPY_NODE_FIELD(alias);
1114
COPY_SCALAR_FIELD(rtindex);
1123
_copyFromExpr(FromExpr *from)
1125
FromExpr *newnode = makeNode(FromExpr);
1127
COPY_NODE_FIELD(fromlist);
1128
COPY_NODE_FIELD(quals);
1133
/* ****************************************************************
1134
* relation.h copy functions
1136
* We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1137
* There are some subsidiary structs that are useful to copy, though.
1138
* ****************************************************************
1144
static PathKeyItem *
1145
_copyPathKeyItem(PathKeyItem *from)
1147
PathKeyItem *newnode = makeNode(PathKeyItem);
1149
COPY_NODE_FIELD(key);
1150
COPY_SCALAR_FIELD(sortop);
1158
static RestrictInfo *
1159
_copyRestrictInfo(RestrictInfo *from)
1161
RestrictInfo *newnode = makeNode(RestrictInfo);
1163
COPY_NODE_FIELD(clause);
1164
COPY_SCALAR_FIELD(is_pushed_down);
1165
COPY_SCALAR_FIELD(valid_everywhere);
1166
COPY_SCALAR_FIELD(can_join);
1167
COPY_BITMAPSET_FIELD(clause_relids);
1168
COPY_BITMAPSET_FIELD(left_relids);
1169
COPY_BITMAPSET_FIELD(right_relids);
1170
COPY_NODE_FIELD(orclause);
1171
COPY_SCALAR_FIELD(eval_cost);
1172
COPY_SCALAR_FIELD(this_selec);
1173
COPY_SCALAR_FIELD(mergejoinoperator);
1174
COPY_SCALAR_FIELD(left_sortop);
1175
COPY_SCALAR_FIELD(right_sortop);
1178
* Do not copy pathkeys, since they'd not be canonical in a copied
1181
newnode->left_pathkey = NIL;
1182
newnode->right_pathkey = NIL;
1184
COPY_SCALAR_FIELD(left_mergescansel);
1185
COPY_SCALAR_FIELD(right_mergescansel);
1186
COPY_SCALAR_FIELD(hashjoinoperator);
1187
COPY_SCALAR_FIELD(left_bucketsize);
1188
COPY_SCALAR_FIELD(right_bucketsize);
1197
_copyJoinInfo(JoinInfo *from)
1199
JoinInfo *newnode = makeNode(JoinInfo);
1201
COPY_BITMAPSET_FIELD(unjoined_relids);
1202
COPY_NODE_FIELD(jinfo_restrictinfo);
1210
static InClauseInfo *
1211
_copyInClauseInfo(InClauseInfo *from)
1213
InClauseInfo *newnode = makeNode(InClauseInfo);
1215
COPY_BITMAPSET_FIELD(lefthand);
1216
COPY_BITMAPSET_FIELD(righthand);
1217
COPY_NODE_FIELD(sub_targetlist);
1222
/* ****************************************************************
1223
* parsenodes.h copy functions
1224
* ****************************************************************
1227
static RangeTblEntry *
1228
_copyRangeTblEntry(RangeTblEntry *from)
1230
RangeTblEntry *newnode = makeNode(RangeTblEntry);
1232
COPY_SCALAR_FIELD(rtekind);
1233
COPY_SCALAR_FIELD(relid);
1234
COPY_NODE_FIELD(subquery);
1235
COPY_NODE_FIELD(funcexpr);
1236
COPY_NODE_FIELD(coldeflist);
1237
COPY_SCALAR_FIELD(jointype);
1238
COPY_NODE_FIELD(joinaliasvars);
1239
COPY_NODE_FIELD(alias);
1240
COPY_NODE_FIELD(eref);
1241
COPY_SCALAR_FIELD(inh);
1242
COPY_SCALAR_FIELD(inFromCl);
1243
COPY_SCALAR_FIELD(requiredPerms);
1244
COPY_SCALAR_FIELD(checkAsUser);
1249
static FkConstraint *
1250
_copyFkConstraint(FkConstraint *from)
1252
FkConstraint *newnode = makeNode(FkConstraint);
1254
COPY_STRING_FIELD(constr_name);
1255
COPY_NODE_FIELD(pktable);
1256
COPY_NODE_FIELD(fk_attrs);
1257
COPY_NODE_FIELD(pk_attrs);
1258
COPY_SCALAR_FIELD(fk_matchtype);
1259
COPY_SCALAR_FIELD(fk_upd_action);
1260
COPY_SCALAR_FIELD(fk_del_action);
1261
COPY_SCALAR_FIELD(deferrable);
1262
COPY_SCALAR_FIELD(initdeferred);
1263
COPY_SCALAR_FIELD(skip_validation);
1269
_copySortClause(SortClause *from)
1271
SortClause *newnode = makeNode(SortClause);
1273
COPY_SCALAR_FIELD(tleSortGroupRef);
1274
COPY_SCALAR_FIELD(sortop);
1279
static GroupClause *
1280
_copyGroupClause(GroupClause *from)
1282
GroupClause *newnode = makeNode(GroupClause);
1284
COPY_SCALAR_FIELD(tleSortGroupRef);
1285
COPY_SCALAR_FIELD(sortop);
1291
_copyAExpr(A_Expr *from)
1293
A_Expr *newnode = makeNode(A_Expr);
1295
COPY_SCALAR_FIELD(kind);
1296
COPY_NODE_FIELD(name);
1297
COPY_NODE_FIELD(lexpr);
1298
COPY_NODE_FIELD(rexpr);
1304
_copyColumnRef(ColumnRef *from)
1306
ColumnRef *newnode = makeNode(ColumnRef);
1308
COPY_NODE_FIELD(fields);
1314
_copyParamRef(ParamRef *from)
1316
ParamRef *newnode = makeNode(ParamRef);
1318
COPY_SCALAR_FIELD(number);
1324
_copyAConst(A_Const *from)
1326
A_Const *newnode = makeNode(A_Const);
1328
/* This part must duplicate _copyValue */
1329
COPY_SCALAR_FIELD(val.type);
1330
switch (from->val.type)
1333
COPY_SCALAR_FIELD(val.val.ival);
1338
COPY_STRING_FIELD(val.val.str);
1344
elog(ERROR, "unrecognized node type: %d",
1345
(int) from->val.type);
1349
COPY_NODE_FIELD(typename);
1355
_copyFuncCall(FuncCall *from)
1357
FuncCall *newnode = makeNode(FuncCall);
1359
COPY_NODE_FIELD(funcname);
1360
COPY_NODE_FIELD(args);
1361
COPY_SCALAR_FIELD(agg_star);
1362
COPY_SCALAR_FIELD(agg_distinct);
1368
_copyAIndices(A_Indices *from)
1370
A_Indices *newnode = makeNode(A_Indices);
1372
COPY_NODE_FIELD(lidx);
1373
COPY_NODE_FIELD(uidx);
1378
static A_Indirection *
1379
_copyA_Indirection(A_Indirection *from)
1381
A_Indirection *newnode = makeNode(A_Indirection);
1383
COPY_NODE_FIELD(arg);
1384
COPY_NODE_FIELD(indirection);
1390
_copyResTarget(ResTarget *from)
1392
ResTarget *newnode = makeNode(ResTarget);
1394
COPY_STRING_FIELD(name);
1395
COPY_NODE_FIELD(indirection);
1396
COPY_NODE_FIELD(val);
1402
_copyTypeName(TypeName *from)
1404
TypeName *newnode = makeNode(TypeName);
1406
COPY_NODE_FIELD(names);
1407
COPY_SCALAR_FIELD(typeid);
1408
COPY_SCALAR_FIELD(timezone);
1409
COPY_SCALAR_FIELD(setof);
1410
COPY_SCALAR_FIELD(pct_type);
1411
COPY_SCALAR_FIELD(typmod);
1412
COPY_NODE_FIELD(arrayBounds);
1418
_copySortBy(SortBy *from)
1420
SortBy *newnode = makeNode(SortBy);
1422
COPY_SCALAR_FIELD(sortby_kind);
1423
COPY_NODE_FIELD(useOp);
1424
COPY_NODE_FIELD(node);
1429
static RangeSubselect *
1430
_copyRangeSubselect(RangeSubselect *from)
1432
RangeSubselect *newnode = makeNode(RangeSubselect);
1434
COPY_NODE_FIELD(subquery);
1435
COPY_NODE_FIELD(alias);
1440
static RangeFunction *
1441
_copyRangeFunction(RangeFunction *from)
1443
RangeFunction *newnode = makeNode(RangeFunction);
1445
COPY_NODE_FIELD(funccallnode);
1446
COPY_NODE_FIELD(alias);
1447
COPY_NODE_FIELD(coldeflist);
1453
_copyTypeCast(TypeCast *from)
1455
TypeCast *newnode = makeNode(TypeCast);
1457
COPY_NODE_FIELD(arg);
1458
COPY_NODE_FIELD(typename);
1464
_copyIndexElem(IndexElem *from)
1466
IndexElem *newnode = makeNode(IndexElem);
1468
COPY_STRING_FIELD(name);
1469
COPY_NODE_FIELD(expr);
1470
COPY_NODE_FIELD(opclass);
1476
_copyColumnDef(ColumnDef *from)
1478
ColumnDef *newnode = makeNode(ColumnDef);
1480
COPY_STRING_FIELD(colname);
1481
COPY_NODE_FIELD(typename);
1482
COPY_SCALAR_FIELD(inhcount);
1483
COPY_SCALAR_FIELD(is_local);
1484
COPY_SCALAR_FIELD(is_not_null);
1485
COPY_NODE_FIELD(raw_default);
1486
COPY_STRING_FIELD(cooked_default);
1487
COPY_NODE_FIELD(constraints);
1488
COPY_NODE_FIELD(support);
1494
_copyConstraint(Constraint *from)
1496
Constraint *newnode = makeNode(Constraint);
1498
COPY_SCALAR_FIELD(contype);
1499
COPY_STRING_FIELD(name);
1500
COPY_NODE_FIELD(raw_expr);
1501
COPY_STRING_FIELD(cooked_expr);
1502
COPY_NODE_FIELD(keys);
1503
COPY_STRING_FIELD(indexspace);
1509
_copyDefElem(DefElem *from)
1511
DefElem *newnode = makeNode(DefElem);
1513
COPY_STRING_FIELD(defname);
1514
COPY_NODE_FIELD(arg);
1520
_copyQuery(Query *from)
1522
Query *newnode = makeNode(Query);
1524
COPY_SCALAR_FIELD(commandType);
1525
COPY_SCALAR_FIELD(querySource);
1526
COPY_SCALAR_FIELD(canSetTag);
1527
COPY_NODE_FIELD(utilityStmt);
1528
COPY_SCALAR_FIELD(resultRelation);
1529
COPY_NODE_FIELD(into);
1530
COPY_SCALAR_FIELD(intoHasOids);
1531
COPY_SCALAR_FIELD(hasAggs);
1532
COPY_SCALAR_FIELD(hasSubLinks);
1533
COPY_NODE_FIELD(rtable);
1534
COPY_NODE_FIELD(jointree);
1535
COPY_NODE_FIELD(rowMarks);
1536
COPY_NODE_FIELD(targetList);
1537
COPY_NODE_FIELD(groupClause);
1538
COPY_NODE_FIELD(havingQual);
1539
COPY_NODE_FIELD(distinctClause);
1540
COPY_NODE_FIELD(sortClause);
1541
COPY_NODE_FIELD(limitOffset);
1542
COPY_NODE_FIELD(limitCount);
1543
COPY_NODE_FIELD(setOperations);
1544
COPY_NODE_FIELD(resultRelations);
1545
COPY_NODE_FIELD(in_info_list);
1546
COPY_SCALAR_FIELD(hasJoinRTEs);
1549
* We do not copy the other planner internal fields: base_rel_list,
1550
* other_rel_list, join_rel_list, equi_key_list, query_pathkeys. That
1551
* would get us into copying RelOptInfo/Path trees, which we don't
1552
* want to do. It is necessary to copy in_info_list and hasJoinRTEs
1553
* for the benefit of inheritance_planner(), which may try to copy a
1554
* Query in which these are already set.
1561
_copyInsertStmt(InsertStmt *from)
1563
InsertStmt *newnode = makeNode(InsertStmt);
1565
COPY_NODE_FIELD(relation);
1566
COPY_NODE_FIELD(cols);
1567
COPY_NODE_FIELD(targetList);
1568
COPY_NODE_FIELD(selectStmt);
1574
_copyDeleteStmt(DeleteStmt *from)
1576
DeleteStmt *newnode = makeNode(DeleteStmt);
1578
COPY_NODE_FIELD(relation);
1579
COPY_NODE_FIELD(whereClause);
1585
_copyUpdateStmt(UpdateStmt *from)
1587
UpdateStmt *newnode = makeNode(UpdateStmt);
1589
COPY_NODE_FIELD(relation);
1590
COPY_NODE_FIELD(targetList);
1591
COPY_NODE_FIELD(whereClause);
1592
COPY_NODE_FIELD(fromClause);
1598
_copySelectStmt(SelectStmt *from)
1600
SelectStmt *newnode = makeNode(SelectStmt);
1602
COPY_NODE_FIELD(distinctClause);
1603
COPY_NODE_FIELD(into);
1604
COPY_NODE_FIELD(intoColNames);
1605
COPY_SCALAR_FIELD(intoHasOids);
1606
COPY_NODE_FIELD(targetList);
1607
COPY_NODE_FIELD(fromClause);
1608
COPY_NODE_FIELD(whereClause);
1609
COPY_NODE_FIELD(groupClause);
1610
COPY_NODE_FIELD(havingClause);
1611
COPY_NODE_FIELD(sortClause);
1612
COPY_NODE_FIELD(limitOffset);
1613
COPY_NODE_FIELD(limitCount);
1614
COPY_NODE_FIELD(forUpdate);
1615
COPY_SCALAR_FIELD(op);
1616
COPY_SCALAR_FIELD(all);
1617
COPY_NODE_FIELD(larg);
1618
COPY_NODE_FIELD(rarg);
1623
static SetOperationStmt *
1624
_copySetOperationStmt(SetOperationStmt *from)
1626
SetOperationStmt *newnode = makeNode(SetOperationStmt);
1628
COPY_SCALAR_FIELD(op);
1629
COPY_SCALAR_FIELD(all);
1630
COPY_NODE_FIELD(larg);
1631
COPY_NODE_FIELD(rarg);
1632
COPY_NODE_FIELD(colTypes);
1637
static AlterTableStmt *
1638
_copyAlterTableStmt(AlterTableStmt *from)
1640
AlterTableStmt *newnode = makeNode(AlterTableStmt);
1642
COPY_NODE_FIELD(relation);
1643
COPY_NODE_FIELD(cmds);
1644
COPY_SCALAR_FIELD(relkind);
1649
static AlterTableCmd *
1650
_copyAlterTableCmd(AlterTableCmd *from)
1652
AlterTableCmd *newnode = makeNode(AlterTableCmd);
1654
COPY_SCALAR_FIELD(subtype);
1655
COPY_STRING_FIELD(name);
1656
COPY_NODE_FIELD(def);
1657
COPY_NODE_FIELD(transform);
1658
COPY_SCALAR_FIELD(behavior);
1663
static AlterDomainStmt *
1664
_copyAlterDomainStmt(AlterDomainStmt *from)
1666
AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1668
COPY_SCALAR_FIELD(subtype);
1669
COPY_NODE_FIELD(typename);
1670
COPY_STRING_FIELD(name);
1671
COPY_NODE_FIELD(def);
1672
COPY_SCALAR_FIELD(behavior);
1678
_copyGrantStmt(GrantStmt *from)
1680
GrantStmt *newnode = makeNode(GrantStmt);
1682
COPY_SCALAR_FIELD(is_grant);
1683
COPY_SCALAR_FIELD(objtype);
1684
COPY_NODE_FIELD(objects);
1685
COPY_NODE_FIELD(privileges);
1686
COPY_NODE_FIELD(grantees);
1687
COPY_SCALAR_FIELD(grant_option);
1688
COPY_SCALAR_FIELD(behavior);
1693
static PrivGrantee *
1694
_copyPrivGrantee(PrivGrantee *from)
1696
PrivGrantee *newnode = makeNode(PrivGrantee);
1698
COPY_STRING_FIELD(username);
1699
COPY_STRING_FIELD(groupname);
1704
static FuncWithArgs *
1705
_copyFuncWithArgs(FuncWithArgs *from)
1707
FuncWithArgs *newnode = makeNode(FuncWithArgs);
1709
COPY_NODE_FIELD(funcname);
1710
COPY_NODE_FIELD(funcargs);
1715
static DeclareCursorStmt *
1716
_copyDeclareCursorStmt(DeclareCursorStmt *from)
1718
DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
1720
COPY_STRING_FIELD(portalname);
1721
COPY_SCALAR_FIELD(options);
1722
COPY_NODE_FIELD(query);
1727
static ClosePortalStmt *
1728
_copyClosePortalStmt(ClosePortalStmt *from)
1730
ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1732
COPY_STRING_FIELD(portalname);
1737
static ClusterStmt *
1738
_copyClusterStmt(ClusterStmt *from)
1740
ClusterStmt *newnode = makeNode(ClusterStmt);
1742
COPY_NODE_FIELD(relation);
1743
COPY_STRING_FIELD(indexname);
1749
_copyCopyStmt(CopyStmt *from)
1751
CopyStmt *newnode = makeNode(CopyStmt);
1753
COPY_NODE_FIELD(relation);
1754
COPY_NODE_FIELD(attlist);
1755
COPY_SCALAR_FIELD(is_from);
1756
COPY_STRING_FIELD(filename);
1757
COPY_NODE_FIELD(options);
1763
_copyCreateStmt(CreateStmt *from)
1765
CreateStmt *newnode = makeNode(CreateStmt);
1767
COPY_NODE_FIELD(relation);
1768
COPY_NODE_FIELD(tableElts);
1769
COPY_NODE_FIELD(inhRelations);
1770
COPY_NODE_FIELD(constraints);
1771
COPY_SCALAR_FIELD(hasoids);
1772
COPY_SCALAR_FIELD(oncommit);
1773
COPY_STRING_FIELD(tablespacename);
1778
static InhRelation *
1779
_copyInhRelation(InhRelation *from)
1781
InhRelation *newnode = makeNode(InhRelation);
1783
COPY_NODE_FIELD(relation);
1784
COPY_SCALAR_FIELD(including_defaults);
1790
_copyDefineStmt(DefineStmt *from)
1792
DefineStmt *newnode = makeNode(DefineStmt);
1794
COPY_SCALAR_FIELD(kind);
1795
COPY_NODE_FIELD(defnames);
1796
COPY_NODE_FIELD(definition);
1802
_copyDropStmt(DropStmt *from)
1804
DropStmt *newnode = makeNode(DropStmt);
1806
COPY_NODE_FIELD(objects);
1807
COPY_SCALAR_FIELD(removeType);
1808
COPY_SCALAR_FIELD(behavior);
1813
static TruncateStmt *
1814
_copyTruncateStmt(TruncateStmt *from)
1816
TruncateStmt *newnode = makeNode(TruncateStmt);
1818
COPY_NODE_FIELD(relation);
1823
static CommentStmt *
1824
_copyCommentStmt(CommentStmt *from)
1826
CommentStmt *newnode = makeNode(CommentStmt);
1828
COPY_SCALAR_FIELD(objtype);
1829
COPY_NODE_FIELD(objname);
1830
COPY_NODE_FIELD(objargs);
1831
COPY_STRING_FIELD(comment);
1837
_copyFetchStmt(FetchStmt *from)
1839
FetchStmt *newnode = makeNode(FetchStmt);
1841
COPY_SCALAR_FIELD(direction);
1842
COPY_SCALAR_FIELD(howMany);
1843
COPY_STRING_FIELD(portalname);
1844
COPY_SCALAR_FIELD(ismove);
1850
_copyIndexStmt(IndexStmt *from)
1852
IndexStmt *newnode = makeNode(IndexStmt);
1854
COPY_STRING_FIELD(idxname);
1855
COPY_NODE_FIELD(relation);
1856
COPY_STRING_FIELD(accessMethod);
1857
COPY_STRING_FIELD(tableSpace);
1858
COPY_NODE_FIELD(indexParams);
1859
COPY_NODE_FIELD(whereClause);
1860
COPY_NODE_FIELD(rangetable);
1861
COPY_SCALAR_FIELD(unique);
1862
COPY_SCALAR_FIELD(primary);
1863
COPY_SCALAR_FIELD(isconstraint);
1868
static CreateFunctionStmt *
1869
_copyCreateFunctionStmt(CreateFunctionStmt *from)
1871
CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
1873
COPY_SCALAR_FIELD(replace);
1874
COPY_NODE_FIELD(funcname);
1875
COPY_NODE_FIELD(parameters);
1876
COPY_NODE_FIELD(returnType);
1877
COPY_NODE_FIELD(options);
1878
COPY_NODE_FIELD(withClause);
1883
static FunctionParameter *
1884
_copyFunctionParameter(FunctionParameter *from)
1886
FunctionParameter *newnode = makeNode(FunctionParameter);
1888
COPY_STRING_FIELD(name);
1889
COPY_NODE_FIELD(argType);
1894
static RemoveAggrStmt *
1895
_copyRemoveAggrStmt(RemoveAggrStmt *from)
1897
RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1899
COPY_NODE_FIELD(aggname);
1900
COPY_NODE_FIELD(aggtype);
1901
COPY_SCALAR_FIELD(behavior);
1906
static RemoveFuncStmt *
1907
_copyRemoveFuncStmt(RemoveFuncStmt *from)
1909
RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
1911
COPY_NODE_FIELD(funcname);
1912
COPY_NODE_FIELD(args);
1913
COPY_SCALAR_FIELD(behavior);
1918
static RemoveOperStmt *
1919
_copyRemoveOperStmt(RemoveOperStmt *from)
1921
RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
1923
COPY_NODE_FIELD(opname);
1924
COPY_NODE_FIELD(args);
1925
COPY_SCALAR_FIELD(behavior);
1930
static RemoveOpClassStmt *
1931
_copyRemoveOpClassStmt(RemoveOpClassStmt *from)
1933
RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
1935
COPY_NODE_FIELD(opclassname);
1936
COPY_STRING_FIELD(amname);
1937
COPY_SCALAR_FIELD(behavior);
1943
_copyRenameStmt(RenameStmt *from)
1945
RenameStmt *newnode = makeNode(RenameStmt);
1947
COPY_NODE_FIELD(relation);
1948
COPY_NODE_FIELD(object);
1949
COPY_NODE_FIELD(objarg);
1950
COPY_STRING_FIELD(subname);
1951
COPY_STRING_FIELD(newname);
1952
COPY_SCALAR_FIELD(renameType);
1957
static AlterOwnerStmt *
1958
_copyAlterOwnerStmt(AlterOwnerStmt *from)
1960
AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);
1962
COPY_NODE_FIELD(relation);
1963
COPY_NODE_FIELD(object);
1964
COPY_NODE_FIELD(objarg);
1965
COPY_STRING_FIELD(addname);
1966
COPY_STRING_FIELD(newowner);
1967
COPY_SCALAR_FIELD(objectType);
1973
_copyRuleStmt(RuleStmt *from)
1975
RuleStmt *newnode = makeNode(RuleStmt);
1977
COPY_NODE_FIELD(relation);
1978
COPY_STRING_FIELD(rulename);
1979
COPY_NODE_FIELD(whereClause);
1980
COPY_SCALAR_FIELD(event);
1981
COPY_SCALAR_FIELD(instead);
1982
COPY_NODE_FIELD(actions);
1983
COPY_SCALAR_FIELD(replace);
1989
_copyNotifyStmt(NotifyStmt *from)
1991
NotifyStmt *newnode = makeNode(NotifyStmt);
1993
COPY_NODE_FIELD(relation);
1999
_copyListenStmt(ListenStmt *from)
2001
ListenStmt *newnode = makeNode(ListenStmt);
2003
COPY_NODE_FIELD(relation);
2008
static UnlistenStmt *
2009
_copyUnlistenStmt(UnlistenStmt *from)
2011
UnlistenStmt *newnode = makeNode(UnlistenStmt);
2013
COPY_NODE_FIELD(relation);
2018
static TransactionStmt *
2019
_copyTransactionStmt(TransactionStmt *from)
2021
TransactionStmt *newnode = makeNode(TransactionStmt);
2023
COPY_SCALAR_FIELD(kind);
2024
COPY_NODE_FIELD(options);
2029
static CompositeTypeStmt *
2030
_copyCompositeTypeStmt(CompositeTypeStmt *from)
2032
CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
2034
COPY_NODE_FIELD(typevar);
2035
COPY_NODE_FIELD(coldeflist);
2041
_copyViewStmt(ViewStmt *from)
2043
ViewStmt *newnode = makeNode(ViewStmt);
2045
COPY_NODE_FIELD(view);
2046
COPY_NODE_FIELD(aliases);
2047
COPY_NODE_FIELD(query);
2048
COPY_SCALAR_FIELD(replace);
2054
_copyLoadStmt(LoadStmt *from)
2056
LoadStmt *newnode = makeNode(LoadStmt);
2058
COPY_STRING_FIELD(filename);
2063
static CreateDomainStmt *
2064
_copyCreateDomainStmt(CreateDomainStmt *from)
2066
CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2068
COPY_NODE_FIELD(domainname);
2069
COPY_NODE_FIELD(typename);
2070
COPY_NODE_FIELD(constraints);
2075
static CreateOpClassStmt *
2076
_copyCreateOpClassStmt(CreateOpClassStmt *from)
2078
CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2080
COPY_NODE_FIELD(opclassname);
2081
COPY_STRING_FIELD(amname);
2082
COPY_NODE_FIELD(datatype);
2083
COPY_NODE_FIELD(items);
2084
COPY_SCALAR_FIELD(isDefault);
2089
static CreateOpClassItem *
2090
_copyCreateOpClassItem(CreateOpClassItem *from)
2092
CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2094
COPY_SCALAR_FIELD(itemtype);
2095
COPY_NODE_FIELD(name);
2096
COPY_NODE_FIELD(args);
2097
COPY_SCALAR_FIELD(number);
2098
COPY_SCALAR_FIELD(recheck);
2099
COPY_NODE_FIELD(storedtype);
2104
static CreatedbStmt *
2105
_copyCreatedbStmt(CreatedbStmt *from)
2107
CreatedbStmt *newnode = makeNode(CreatedbStmt);
2109
COPY_STRING_FIELD(dbname);
2110
COPY_NODE_FIELD(options);
2115
static AlterDatabaseSetStmt *
2116
_copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2118
AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2120
COPY_STRING_FIELD(dbname);
2121
COPY_STRING_FIELD(variable);
2122
COPY_NODE_FIELD(value);
2128
_copyDropdbStmt(DropdbStmt *from)
2130
DropdbStmt *newnode = makeNode(DropdbStmt);
2132
COPY_STRING_FIELD(dbname);
2138
_copyVacuumStmt(VacuumStmt *from)
2140
VacuumStmt *newnode = makeNode(VacuumStmt);
2142
COPY_SCALAR_FIELD(vacuum);
2143
COPY_SCALAR_FIELD(full);
2144
COPY_SCALAR_FIELD(analyze);
2145
COPY_SCALAR_FIELD(freeze);
2146
COPY_SCALAR_FIELD(verbose);
2147
COPY_NODE_FIELD(relation);
2148
COPY_NODE_FIELD(va_cols);
2153
static ExplainStmt *
2154
_copyExplainStmt(ExplainStmt *from)
2156
ExplainStmt *newnode = makeNode(ExplainStmt);
2158
COPY_NODE_FIELD(query);
2159
COPY_SCALAR_FIELD(verbose);
2160
COPY_SCALAR_FIELD(analyze);
2165
static CreateSeqStmt *
2166
_copyCreateSeqStmt(CreateSeqStmt *from)
2168
CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2170
COPY_NODE_FIELD(sequence);
2171
COPY_NODE_FIELD(options);
2176
static AlterSeqStmt *
2177
_copyAlterSeqStmt(AlterSeqStmt *from)
2179
AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
2181
COPY_NODE_FIELD(sequence);
2182
COPY_NODE_FIELD(options);
2187
static VariableSetStmt *
2188
_copyVariableSetStmt(VariableSetStmt *from)
2190
VariableSetStmt *newnode = makeNode(VariableSetStmt);
2192
COPY_STRING_FIELD(name);
2193
COPY_NODE_FIELD(args);
2194
COPY_SCALAR_FIELD(is_local);
2199
static VariableShowStmt *
2200
_copyVariableShowStmt(VariableShowStmt *from)
2202
VariableShowStmt *newnode = makeNode(VariableShowStmt);
2204
COPY_STRING_FIELD(name);
2209
static VariableResetStmt *
2210
_copyVariableResetStmt(VariableResetStmt *from)
2212
VariableResetStmt *newnode = makeNode(VariableResetStmt);
2214
COPY_STRING_FIELD(name);
2219
static CreateTableSpaceStmt *
2220
_copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
2222
CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
2224
COPY_STRING_FIELD(tablespacename);
2225
COPY_STRING_FIELD(owner);
2226
COPY_STRING_FIELD(location);
2231
static DropTableSpaceStmt *
2232
_copyDropTableSpaceStmt(DropTableSpaceStmt *from)
2234
DropTableSpaceStmt *newnode = makeNode(DropTableSpaceStmt);
2236
COPY_STRING_FIELD(tablespacename);
2241
static CreateTrigStmt *
2242
_copyCreateTrigStmt(CreateTrigStmt *from)
2244
CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2246
COPY_STRING_FIELD(trigname);
2247
COPY_NODE_FIELD(relation);
2248
COPY_NODE_FIELD(funcname);
2249
COPY_NODE_FIELD(args);
2250
COPY_SCALAR_FIELD(before);
2251
COPY_SCALAR_FIELD(row);
2252
strcpy(newnode->actions, from->actions); /* in-line string field */
2253
COPY_SCALAR_FIELD(isconstraint);
2254
COPY_SCALAR_FIELD(deferrable);
2255
COPY_SCALAR_FIELD(initdeferred);
2256
COPY_NODE_FIELD(constrrel);
2261
static DropPropertyStmt *
2262
_copyDropPropertyStmt(DropPropertyStmt *from)
2264
DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2266
COPY_NODE_FIELD(relation);
2267
COPY_STRING_FIELD(property);
2268
COPY_SCALAR_FIELD(removeType);
2269
COPY_SCALAR_FIELD(behavior);
2274
static CreatePLangStmt *
2275
_copyCreatePLangStmt(CreatePLangStmt *from)
2277
CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2279
COPY_STRING_FIELD(plname);
2280
COPY_NODE_FIELD(plhandler);
2281
COPY_NODE_FIELD(plvalidator);
2282
COPY_SCALAR_FIELD(pltrusted);
2287
static DropPLangStmt *
2288
_copyDropPLangStmt(DropPLangStmt *from)
2290
DropPLangStmt *newnode = makeNode(DropPLangStmt);
2292
COPY_STRING_FIELD(plname);
2293
COPY_SCALAR_FIELD(behavior);
2298
static CreateUserStmt *
2299
_copyCreateUserStmt(CreateUserStmt *from)
2301
CreateUserStmt *newnode = makeNode(CreateUserStmt);
2303
COPY_STRING_FIELD(user);
2304
COPY_NODE_FIELD(options);
2309
static AlterUserStmt *
2310
_copyAlterUserStmt(AlterUserStmt *from)
2312
AlterUserStmt *newnode = makeNode(AlterUserStmt);
2314
COPY_STRING_FIELD(user);
2315
COPY_NODE_FIELD(options);
2320
static AlterUserSetStmt *
2321
_copyAlterUserSetStmt(AlterUserSetStmt *from)
2323
AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2325
COPY_STRING_FIELD(user);
2326
COPY_STRING_FIELD(variable);
2327
COPY_NODE_FIELD(value);
2332
static DropUserStmt *
2333
_copyDropUserStmt(DropUserStmt *from)
2335
DropUserStmt *newnode = makeNode(DropUserStmt);
2337
COPY_NODE_FIELD(users);
2343
_copyLockStmt(LockStmt *from)
2345
LockStmt *newnode = makeNode(LockStmt);
2347
COPY_NODE_FIELD(relations);
2348
COPY_SCALAR_FIELD(mode);
2349
COPY_SCALAR_FIELD(nowait);
2354
static ConstraintsSetStmt *
2355
_copyConstraintsSetStmt(ConstraintsSetStmt *from)
2357
ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2359
COPY_NODE_FIELD(constraints);
2360
COPY_SCALAR_FIELD(deferred);
2365
static CreateGroupStmt *
2366
_copyCreateGroupStmt(CreateGroupStmt *from)
2368
CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2370
COPY_STRING_FIELD(name);
2371
COPY_NODE_FIELD(options);
2376
static AlterGroupStmt *
2377
_copyAlterGroupStmt(AlterGroupStmt *from)
2379
AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2381
COPY_STRING_FIELD(name);
2382
COPY_SCALAR_FIELD(action);
2383
COPY_NODE_FIELD(listUsers);
2388
static DropGroupStmt *
2389
_copyDropGroupStmt(DropGroupStmt *from)
2391
DropGroupStmt *newnode = makeNode(DropGroupStmt);
2393
COPY_STRING_FIELD(name);
2398
static ReindexStmt *
2399
_copyReindexStmt(ReindexStmt *from)
2401
ReindexStmt *newnode = makeNode(ReindexStmt);
2403
COPY_SCALAR_FIELD(kind);
2404
COPY_NODE_FIELD(relation);
2405
COPY_STRING_FIELD(name);
2406
COPY_SCALAR_FIELD(force);
2407
COPY_SCALAR_FIELD(all);
2412
static CreateSchemaStmt *
2413
_copyCreateSchemaStmt(CreateSchemaStmt *from)
2415
CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2417
COPY_STRING_FIELD(schemaname);
2418
COPY_STRING_FIELD(authid);
2419
COPY_NODE_FIELD(schemaElts);
2424
static CreateConversionStmt *
2425
_copyCreateConversionStmt(CreateConversionStmt *from)
2427
CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2429
COPY_NODE_FIELD(conversion_name);
2430
COPY_STRING_FIELD(for_encoding_name);
2431
COPY_STRING_FIELD(to_encoding_name);
2432
COPY_NODE_FIELD(func_name);
2433
COPY_SCALAR_FIELD(def);
2438
static CreateCastStmt *
2439
_copyCreateCastStmt(CreateCastStmt *from)
2441
CreateCastStmt *newnode = makeNode(CreateCastStmt);
2443
COPY_NODE_FIELD(sourcetype);
2444
COPY_NODE_FIELD(targettype);
2445
COPY_NODE_FIELD(func);
2446
COPY_SCALAR_FIELD(context);
2451
static DropCastStmt *
2452
_copyDropCastStmt(DropCastStmt *from)
2454
DropCastStmt *newnode = makeNode(DropCastStmt);
2456
COPY_NODE_FIELD(sourcetype);
2457
COPY_NODE_FIELD(targettype);
2458
COPY_SCALAR_FIELD(behavior);
2463
static PrepareStmt *
2464
_copyPrepareStmt(PrepareStmt *from)
2466
PrepareStmt *newnode = makeNode(PrepareStmt);
2468
COPY_STRING_FIELD(name);
2469
COPY_NODE_FIELD(argtypes);
2470
COPY_NODE_FIELD(argtype_oids);
2471
COPY_NODE_FIELD(query);
2476
static ExecuteStmt *
2477
_copyExecuteStmt(ExecuteStmt *from)
2479
ExecuteStmt *newnode = makeNode(ExecuteStmt);
2481
COPY_STRING_FIELD(name);
2482
COPY_NODE_FIELD(into);
2483
COPY_NODE_FIELD(params);
2488
static DeallocateStmt *
2489
_copyDeallocateStmt(DeallocateStmt *from)
2491
DeallocateStmt *newnode = makeNode(DeallocateStmt);
2493
COPY_STRING_FIELD(name);
2499
/* ****************************************************************
2500
* pg_list.h copy functions
2501
* ****************************************************************
2505
* Perform a deep copy of the specified list, using copyObject(). The
2506
* list MUST be of type T_List; T_IntList and T_OidList nodes don't
2507
* need deep copies, so they should be copied via list_copy()
2509
#define COPY_NODE_CELL(new, old) \
2510
(new) = (ListCell *) palloc(sizeof(ListCell)); \
2511
lfirst(new) = copyObject(lfirst(old));
2514
_copyList(List *from)
2520
Assert(list_length(from) >= 1);
2522
new = makeNode(List);
2523
new->length = from->length;
2525
COPY_NODE_CELL(new->head, from->head);
2526
prev_new = new->head;
2527
curr_old = lnext(from->head);
2531
COPY_NODE_CELL(prev_new->next, curr_old);
2532
prev_new = prev_new->next;
2533
curr_old = curr_old->next;
2535
prev_new->next = NULL;
2536
new->tail = prev_new;
2541
/* ****************************************************************
2542
* value.h copy functions
2543
* ****************************************************************
2546
_copyValue(Value *from)
2548
Value *newnode = makeNode(Value);
2550
/* See also _copyAConst when changing this code! */
2552
COPY_SCALAR_FIELD(type);
2556
COPY_SCALAR_FIELD(val.ival);
2561
COPY_STRING_FIELD(val.str);
2567
elog(ERROR, "unrecognized node type: %d",
2577
* Create a copy of a Node tree or list. This is a "deep" copy: all
2578
* substructure is copied too, recursively.
2581
copyObject(void *from)
2588
switch (nodeTag(from))
2594
retval = _copyPlan(from);
2597
retval = _copyResult(from);
2600
retval = _copyAppend(from);
2603
retval = _copyScan(from);
2606
retval = _copySeqScan(from);
2609
retval = _copyIndexScan(from);
2612
retval = _copyTidScan(from);
2614
case T_SubqueryScan:
2615
retval = _copySubqueryScan(from);
2617
case T_FunctionScan:
2618
retval = _copyFunctionScan(from);
2621
retval = _copyJoin(from);
2624
retval = _copyNestLoop(from);
2627
retval = _copyMergeJoin(from);
2630
retval = _copyHashJoin(from);
2633
retval = _copyMaterial(from);
2636
retval = _copySort(from);
2639
retval = _copyGroup(from);
2642
retval = _copyAgg(from);
2645
retval = _copyUnique(from);
2648
retval = _copyHash(from);
2651
retval = _copySetOp(from);
2654
retval = _copyLimit(from);
2661
retval = _copyResdom(from);
2664
retval = _copyAlias(from);
2667
retval = _copyRangeVar(from);
2670
retval = _copyVar(from);
2673
retval = _copyConst(from);
2676
retval = _copyParam(from);
2679
retval = _copyAggref(from);
2682
retval = _copyArrayRef(from);
2685
retval = _copyFuncExpr(from);
2688
retval = _copyOpExpr(from);
2690
case T_DistinctExpr:
2691
retval = _copyDistinctExpr(from);
2693
case T_ScalarArrayOpExpr:
2694
retval = _copyScalarArrayOpExpr(from);
2697
retval = _copyBoolExpr(from);
2700
retval = _copySubLink(from);
2703
retval = _copySubPlan(from);
2706
retval = _copyFieldSelect(from);
2709
retval = _copyFieldStore(from);
2712
retval = _copyRelabelType(from);
2714
case T_ConvertRowtypeExpr:
2715
retval = _copyConvertRowtypeExpr(from);
2718
retval = _copyCaseExpr(from);
2721
retval = _copyCaseWhen(from);
2723
case T_CaseTestExpr:
2724
retval = _copyCaseTestExpr(from);
2727
retval = _copyArrayExpr(from);
2730
retval = _copyRowExpr(from);
2732
case T_CoalesceExpr:
2733
retval = _copyCoalesceExpr(from);
2736
retval = _copyNullIfExpr(from);
2739
retval = _copyNullTest(from);
2742
retval = _copyBooleanTest(from);
2744
case T_CoerceToDomain:
2745
retval = _copyCoerceToDomain(from);
2747
case T_CoerceToDomainValue:
2748
retval = _copyCoerceToDomainValue(from);
2750
case T_SetToDefault:
2751
retval = _copySetToDefault(from);
2754
retval = _copyTargetEntry(from);
2757
retval = _copyRangeTblRef(from);
2760
retval = _copyJoinExpr(from);
2763
retval = _copyFromExpr(from);
2770
retval = _copyPathKeyItem(from);
2772
case T_RestrictInfo:
2773
retval = _copyRestrictInfo(from);
2776
retval = _copyJoinInfo(from);
2778
case T_InClauseInfo:
2779
retval = _copyInClauseInfo(from);
2790
retval = _copyValue(from);
2797
retval = _copyList(from);
2801
* Lists of integers and OIDs don't need to be deep-copied, so
2802
* we perform a shallow copy via list_copy()
2806
retval = list_copy(from);
2813
retval = _copyQuery(from);
2816
retval = _copyInsertStmt(from);
2819
retval = _copyDeleteStmt(from);
2822
retval = _copyUpdateStmt(from);
2825
retval = _copySelectStmt(from);
2827
case T_SetOperationStmt:
2828
retval = _copySetOperationStmt(from);
2830
case T_AlterTableStmt:
2831
retval = _copyAlterTableStmt(from);
2833
case T_AlterTableCmd:
2834
retval = _copyAlterTableCmd(from);
2836
case T_AlterDomainStmt:
2837
retval = _copyAlterDomainStmt(from);
2840
retval = _copyGrantStmt(from);
2842
case T_DeclareCursorStmt:
2843
retval = _copyDeclareCursorStmt(from);
2845
case T_ClosePortalStmt:
2846
retval = _copyClosePortalStmt(from);
2849
retval = _copyClusterStmt(from);
2852
retval = _copyCopyStmt(from);
2855
retval = _copyCreateStmt(from);
2858
retval = _copyInhRelation(from);
2861
retval = _copyDefineStmt(from);
2864
retval = _copyDropStmt(from);
2866
case T_TruncateStmt:
2867
retval = _copyTruncateStmt(from);
2870
retval = _copyCommentStmt(from);
2873
retval = _copyFetchStmt(from);
2876
retval = _copyIndexStmt(from);
2878
case T_CreateFunctionStmt:
2879
retval = _copyCreateFunctionStmt(from);
2881
case T_FunctionParameter:
2882
retval = _copyFunctionParameter(from);
2884
case T_RemoveAggrStmt:
2885
retval = _copyRemoveAggrStmt(from);
2887
case T_RemoveFuncStmt:
2888
retval = _copyRemoveFuncStmt(from);
2890
case T_RemoveOperStmt:
2891
retval = _copyRemoveOperStmt(from);
2893
case T_RemoveOpClassStmt:
2894
retval = _copyRemoveOpClassStmt(from);
2897
retval = _copyRenameStmt(from);
2899
case T_AlterOwnerStmt:
2900
retval = _copyAlterOwnerStmt(from);
2903
retval = _copyRuleStmt(from);
2906
retval = _copyNotifyStmt(from);
2909
retval = _copyListenStmt(from);
2911
case T_UnlistenStmt:
2912
retval = _copyUnlistenStmt(from);
2914
case T_TransactionStmt:
2915
retval = _copyTransactionStmt(from);
2917
case T_CompositeTypeStmt:
2918
retval = _copyCompositeTypeStmt(from);
2921
retval = _copyViewStmt(from);
2924
retval = _copyLoadStmt(from);
2926
case T_CreateDomainStmt:
2927
retval = _copyCreateDomainStmt(from);
2929
case T_CreateOpClassStmt:
2930
retval = _copyCreateOpClassStmt(from);
2932
case T_CreateOpClassItem:
2933
retval = _copyCreateOpClassItem(from);
2935
case T_CreatedbStmt:
2936
retval = _copyCreatedbStmt(from);
2938
case T_AlterDatabaseSetStmt:
2939
retval = _copyAlterDatabaseSetStmt(from);
2942
retval = _copyDropdbStmt(from);
2945
retval = _copyVacuumStmt(from);
2948
retval = _copyExplainStmt(from);
2950
case T_CreateSeqStmt:
2951
retval = _copyCreateSeqStmt(from);
2953
case T_AlterSeqStmt:
2954
retval = _copyAlterSeqStmt(from);
2956
case T_VariableSetStmt:
2957
retval = _copyVariableSetStmt(from);
2959
case T_VariableShowStmt:
2960
retval = _copyVariableShowStmt(from);
2962
case T_VariableResetStmt:
2963
retval = _copyVariableResetStmt(from);
2965
case T_CreateTableSpaceStmt:
2966
retval = _copyCreateTableSpaceStmt(from);
2968
case T_DropTableSpaceStmt:
2969
retval = _copyDropTableSpaceStmt(from);
2971
case T_CreateTrigStmt:
2972
retval = _copyCreateTrigStmt(from);
2974
case T_DropPropertyStmt:
2975
retval = _copyDropPropertyStmt(from);
2977
case T_CreatePLangStmt:
2978
retval = _copyCreatePLangStmt(from);
2980
case T_DropPLangStmt:
2981
retval = _copyDropPLangStmt(from);
2983
case T_CreateUserStmt:
2984
retval = _copyCreateUserStmt(from);
2986
case T_AlterUserStmt:
2987
retval = _copyAlterUserStmt(from);
2989
case T_AlterUserSetStmt:
2990
retval = _copyAlterUserSetStmt(from);
2992
case T_DropUserStmt:
2993
retval = _copyDropUserStmt(from);
2996
retval = _copyLockStmt(from);
2998
case T_ConstraintsSetStmt:
2999
retval = _copyConstraintsSetStmt(from);
3001
case T_CreateGroupStmt:
3002
retval = _copyCreateGroupStmt(from);
3004
case T_AlterGroupStmt:
3005
retval = _copyAlterGroupStmt(from);
3007
case T_DropGroupStmt:
3008
retval = _copyDropGroupStmt(from);
3011
retval = _copyReindexStmt(from);
3013
case T_CheckPointStmt:
3014
retval = (void *) makeNode(CheckPointStmt);
3016
case T_CreateSchemaStmt:
3017
retval = _copyCreateSchemaStmt(from);
3019
case T_CreateConversionStmt:
3020
retval = _copyCreateConversionStmt(from);
3022
case T_CreateCastStmt:
3023
retval = _copyCreateCastStmt(from);
3025
case T_DropCastStmt:
3026
retval = _copyDropCastStmt(from);
3029
retval = _copyPrepareStmt(from);
3032
retval = _copyExecuteStmt(from);
3034
case T_DeallocateStmt:
3035
retval = _copyDeallocateStmt(from);
3039
retval = _copyAExpr(from);
3042
retval = _copyColumnRef(from);
3045
retval = _copyParamRef(from);
3048
retval = _copyAConst(from);
3051
retval = _copyFuncCall(from);
3054
retval = _copyAIndices(from);
3056
case T_A_Indirection:
3057
retval = _copyA_Indirection(from);
3060
retval = _copyResTarget(from);
3063
retval = _copyTypeCast(from);
3066
retval = _copySortBy(from);
3068
case T_RangeSubselect:
3069
retval = _copyRangeSubselect(from);
3071
case T_RangeFunction:
3072
retval = _copyRangeFunction(from);
3075
retval = _copyTypeName(from);
3078
retval = _copyIndexElem(from);
3081
retval = _copyColumnDef(from);
3084
retval = _copyConstraint(from);
3087
retval = _copyDefElem(from);
3089
case T_RangeTblEntry:
3090
retval = _copyRangeTblEntry(from);
3093
retval = _copySortClause(from);
3096
retval = _copyGroupClause(from);
3098
case T_FkConstraint:
3099
retval = _copyFkConstraint(from);
3102
retval = _copyPrivGrantee(from);
3104
case T_FuncWithArgs:
3105
retval = _copyFuncWithArgs(from);
3109
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
3110
retval = from; /* keep compiler quiet */