Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit639a86e

Browse files
committed
Remove Value node struct
The Value node struct is a weird construct. It is its own node type,but most of the time, it actually has a node type of Integer, Float,String, or BitString. As a consequence, the struct name and the nodetype don't match most of the time, and so it has to be treatedspecially a lot. There doesn't seem to be any value in the specialconstruct. There is very little code that wants to accept all Valuevariants but nothing else (and even if it did, this doesn't provideany convenient way to check it), and most code wants either just oneparticular node type (usually String), or it accepts a broader set ofnode types besides just Value.This change removes the Value struct and node type and replaces themby separate Integer, Float, String, and BitString node types that areproper node types and structs of their own and behave mostly likenormal node types.Also, this removes the T_Null node tag, which was previously also apossible variant of Value but wasn't actually used outside of theValue contained in A_Const. Replace that by an isnull field inA_Const.Reviewed-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>Discussion:https://www.postgresql.org/message-id/flat/5ba6bc5b-3f95-04f2-2419-f8ddb4c046fb@enterprisedb.com
1 parentcbdf75b commit639a86e

30 files changed

+373
-337
lines changed

‎contrib/postgres_fdw/postgres_fdw.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ enum FdwModifyPrivateIndex
101101
FdwModifyPrivateUpdateSql,
102102
/* Integer list of target attribute numbers for INSERT/UPDATE */
103103
FdwModifyPrivateTargetAttnums,
104-
/* Length till the end of VALUES clause (as aninteger Value node) */
104+
/* Length till the end of VALUES clause (as anInteger node) */
105105
FdwModifyPrivateLen,
106-
/* has-returning flag (as aninteger Value node) */
106+
/* has-returning flag (as anInteger node) */
107107
FdwModifyPrivateHasReturning,
108108
/* Integer list of attribute numbers retrieved by RETURNING */
109109
FdwModifyPrivateRetrievedAttrs
@@ -122,11 +122,11 @@ enum FdwDirectModifyPrivateIndex
122122
{
123123
/* SQL statement to execute remotely (as a String node) */
124124
FdwDirectModifyPrivateUpdateSql,
125-
/* has-returning flag (as aninteger Value node) */
125+
/* has-returning flag (as anInteger node) */
126126
FdwDirectModifyPrivateHasReturning,
127127
/* Integer list of attribute numbers retrieved by RETURNING */
128128
FdwDirectModifyPrivateRetrievedAttrs,
129-
/* set-processed flag (as aninteger Value node) */
129+
/* set-processed flag (as anInteger node) */
130130
FdwDirectModifyPrivateSetProcessed
131131
};
132132

@@ -280,9 +280,9 @@ typedef struct PgFdwAnalyzeState
280280
*/
281281
enumFdwPathPrivateIndex
282282
{
283-
/* has-final-sort flag (as aninteger Value node) */
283+
/* has-final-sort flag (as anInteger node) */
284284
FdwPathPrivateHasFinalSort,
285-
/* has-limit flag (as aninteger Value node) */
285+
/* has-limit flag (as anInteger node) */
286286
FdwPathPrivateHasLimit
287287
};
288288

‎src/backend/catalog/namespace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,7 +3026,7 @@ CheckSetNamespace(Oid oldNspOid, Oid nspOid)
30263026

30273027
/*
30283028
* QualifiedNameGetCreationNamespace
3029-
*Given a possibly-qualified name for an object (in List-of-Values
3029+
*Given a possibly-qualified name for an object (in List-of-Strings
30303030
*format), determine what namespace the object should be created in.
30313031
*Also extract and return the object name (last component of list).
30323032
*
@@ -3140,7 +3140,7 @@ makeRangeVarFromNameList(List *names)
31403140
* This is used primarily to form error messages, and so we do not quote
31413141
* the list elements, for the sake of legibility.
31423142
*
3143-
* In most scenarios the list elements should always beValue strings,
3143+
* In most scenarios the list elements should always beString values,
31443144
* but we also allow A_Star for the convenience of ColumnRef processing.
31453145
*/
31463146
char*

‎src/backend/catalog/objectaddress.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ const ObjectAddress InvalidObjectAddress =
851851
};
852852

853853
staticObjectAddressget_object_address_unqualified(ObjectTypeobjtype,
854-
Value*strval,boolmissing_ok);
854+
String*strval,boolmissing_ok);
855855
staticObjectAddressget_relation_by_qualified_name(ObjectTypeobjtype,
856856
List*object,Relation*relp,
857857
LOCKMODElockmode,boolmissing_ok);
@@ -1011,7 +1011,7 @@ get_object_address(ObjectType objtype, Node *object,
10111011
caseOBJECT_PUBLICATION:
10121012
caseOBJECT_SUBSCRIPTION:
10131013
address=get_object_address_unqualified(objtype,
1014-
(Value*)object,missing_ok);
1014+
castNode(String,object),missing_ok);
10151015
break;
10161016
caseOBJECT_TYPE:
10171017
caseOBJECT_DOMAIN:
@@ -1244,7 +1244,7 @@ get_object_address_rv(ObjectType objtype, RangeVar *rel, List *object,
12441244
*/
12451245
staticObjectAddress
12461246
get_object_address_unqualified(ObjectTypeobjtype,
1247-
Value*strval,boolmissing_ok)
1247+
String*strval,boolmissing_ok)
12481248
{
12491249
constchar*name;
12501250
ObjectAddressaddress;

‎src/backend/catalog/pg_enum.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static intsort_order_cmp(const void *p1, const void *p2);
5555
* EnumValuesCreate
5656
*Create an entry in pg_enum for each of the supplied enum values.
5757
*
58-
* vals is a list ofValue strings.
58+
* vals is a list ofString values.
5959
*/
6060
void
6161
EnumValuesCreate(OidenumTypeOid,List*vals)

‎src/backend/commands/copy.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,8 @@ DoCopy(ParseState *pstate, const CopyStmt *stmt,
222222
{
223223
/*
224224
* Build the ColumnRef for each column. The ColumnRef
225-
* 'fields' property is a String 'Value' node (see
226-
* nodes/value.h) that corresponds to the column name
227-
* respectively.
225+
* 'fields' property is a String node that corresponds to
226+
* the column name respectively.
228227
*/
229228
cr=makeNode(ColumnRef);
230229
cr->fields=list_make1(lfirst(lc));

‎src/backend/commands/define.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,7 @@ defGetString(DefElem *def)
5858
caseT_Integer:
5959
returnpsprintf("%ld", (long)intVal(def->arg));
6060
caseT_Float:
61-
62-
/*
63-
* T_Float values are kept in string form, so this type cheat
64-
* works (and doesn't risk losing precision)
65-
*/
66-
returnstrVal(def->arg);
61+
returncastNode(Float,def->arg)->val;
6762
caseT_String:
6863
returnstrVal(def->arg);
6964
caseT_TypeName:
@@ -206,7 +201,7 @@ defGetInt64(DefElem *def)
206201
* strings.
207202
*/
208203
returnDatumGetInt64(DirectFunctionCall1(int8in,
209-
CStringGetDatum(strVal(def->arg))));
204+
CStringGetDatum(castNode(Float,def->arg)->val)));
210205
default:
211206
ereport(ERROR,
212207
(errcode(ERRCODE_SYNTAX_ERROR),

‎src/backend/commands/tsearchcmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ getTokenTypes(Oid prsId, List *tokennames)
11791179
i=0;
11801180
foreach(tn,tokennames)
11811181
{
1182-
Value*val=(Value*)lfirst(tn);
1182+
String*val=lfirst_node(String,tn);
11831183
boolfound= false;
11841184
intj;
11851185

@@ -1395,7 +1395,7 @@ DropConfigurationMapping(AlterTSConfigurationStmt *stmt,
13951395
i=0;
13961396
foreach(c,stmt->tokentype)
13971397
{
1398-
Value*val=(Value*)lfirst(c);
1398+
String*val=lfirst_node(String,c);
13991399
boolfound= false;
14001400

14011401
ScanKeyInit(&skey[0],

‎src/backend/executor/nodeTableFuncscan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ tfuncInitialize(TableFuncScanState *tstate, ExprContext *econtext, Datum doc)
364364
forboth(lc1,tstate->ns_uris,lc2,tstate->ns_names)
365365
{
366366
ExprState*expr= (ExprState*)lfirst(lc1);
367-
Value*ns_node=(Value*)lfirst(lc2);
367+
String*ns_node=lfirst_node(String,lc2);
368368
char*ns_uri;
369369
char*ns_name;
370370

‎src/backend/nodes/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ FILES IN THIS DIRECTORY (src/backend/nodes/)
2828
list.c- generic list support
2929
params.c- Param support
3030
tidbitmap.c- TIDBitmap support
31-
value.c- support forValue nodes
31+
value.c- support forvalue nodes
3232

3333
FILES IN src/include/nodes/
3434

‎src/backend/nodes/copyfuncs.c

Lines changed: 64 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,25 +2729,30 @@ _copyA_Const(const A_Const *from)
27292729
{
27302730
A_Const*newnode=makeNode(A_Const);
27312731

2732-
/* This part must duplicate _copyValue */
2733-
COPY_SCALAR_FIELD(val.type);
2734-
switch (from->val.type)
2732+
COPY_SCALAR_FIELD(isnull);
2733+
if (!from->isnull)
27352734
{
2736-
caseT_Integer:
2737-
COPY_SCALAR_FIELD(val.val.ival);
2738-
break;
2739-
caseT_Float:
2740-
caseT_String:
2741-
caseT_BitString:
2742-
COPY_STRING_FIELD(val.val.str);
2743-
break;
2744-
caseT_Null:
2745-
/* nothing to do */
2746-
break;
2747-
default:
2748-
elog(ERROR,"unrecognized node type: %d",
2749-
(int)from->val.type);
2750-
break;
2735+
/* This part must duplicate other _copy*() functions. */
2736+
COPY_SCALAR_FIELD(val.node.type);
2737+
switch (nodeTag(&from->val))
2738+
{
2739+
caseT_Integer:
2740+
COPY_SCALAR_FIELD(val.ival.val);
2741+
break;
2742+
caseT_Float:
2743+
COPY_STRING_FIELD(val.fval.val);
2744+
break;
2745+
caseT_String:
2746+
COPY_STRING_FIELD(val.sval.val);
2747+
break;
2748+
caseT_BitString:
2749+
COPY_STRING_FIELD(val.bsval.val);
2750+
break;
2751+
default:
2752+
elog(ERROR,"unrecognized node type: %d",
2753+
(int)nodeTag(&from->val));
2754+
break;
2755+
}
27512756
}
27522757

27532758
COPY_LOCATION_FIELD(location);
@@ -4892,32 +4897,43 @@ _copyExtensibleNode(const ExtensibleNode *from)
48924897
*value.h copy functions
48934898
* ****************************************************************
48944899
*/
4895-
staticValue*
4896-
_copyValue(constValue*from)
4900+
staticInteger*
4901+
_copyInteger(constInteger*from)
48974902
{
4898-
Value*newnode=makeNode(Value);
4903+
Integer*newnode=makeNode(Integer);
48994904

4900-
/* See also _copyAConst when changing this code! */
4905+
COPY_SCALAR_FIELD(val);
4906+
4907+
returnnewnode;
4908+
}
4909+
4910+
staticFloat*
4911+
_copyFloat(constFloat*from)
4912+
{
4913+
Float*newnode=makeNode(Float);
4914+
4915+
COPY_STRING_FIELD(val);
4916+
4917+
returnnewnode;
4918+
}
4919+
4920+
staticString*
4921+
_copyString(constString*from)
4922+
{
4923+
String*newnode=makeNode(String);
4924+
4925+
COPY_STRING_FIELD(val);
4926+
4927+
returnnewnode;
4928+
}
4929+
4930+
staticBitString*
4931+
_copyBitString(constBitString*from)
4932+
{
4933+
BitString*newnode=makeNode(BitString);
4934+
4935+
COPY_STRING_FIELD(val);
49014936

4902-
COPY_SCALAR_FIELD(type);
4903-
switch (from->type)
4904-
{
4905-
caseT_Integer:
4906-
COPY_SCALAR_FIELD(val.ival);
4907-
break;
4908-
caseT_Float:
4909-
caseT_String:
4910-
caseT_BitString:
4911-
COPY_STRING_FIELD(val.str);
4912-
break;
4913-
caseT_Null:
4914-
/* nothing to do */
4915-
break;
4916-
default:
4917-
elog(ERROR,"unrecognized node type: %d",
4918-
(int)from->type);
4919-
break;
4920-
}
49214937
returnnewnode;
49224938
}
49234939

@@ -5314,11 +5330,16 @@ copyObjectImpl(const void *from)
53145330
* VALUE NODES
53155331
*/
53165332
caseT_Integer:
5333+
retval=_copyInteger(from);
5334+
break;
53175335
caseT_Float:
5336+
retval=_copyFloat(from);
5337+
break;
53185338
caseT_String:
5339+
retval=_copyString(from);
5340+
break;
53195341
caseT_BitString:
5320-
caseT_Null:
5321-
retval=_copyValue(from);
5342+
retval=_copyBitString(from);
53225343
break;
53235344

53245345
/*

‎src/backend/nodes/equalfuncs.c

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,7 +2409,7 @@ _equalParamRef(const ParamRef *a, const ParamRef *b)
24092409
staticbool
24102410
_equalA_Const(constA_Const*a,constA_Const*b)
24112411
{
2412-
if (!equal(&a->val,&b->val))/* hack for in-lineValue field */
2412+
if (!equal(&a->val,&b->val))/* hack for in-lineval field */
24132413
return false;
24142414
COMPARE_LOCATION_FIELD(location);
24152415

@@ -3089,27 +3089,33 @@ _equalList(const List *a, const List *b)
30893089
*/
30903090

30913091
staticbool
3092-
_equalValue(constValue*a,constValue*b)
3092+
_equalInteger(constInteger*a,constInteger*b)
30933093
{
3094-
COMPARE_SCALAR_FIELD(type);
3094+
COMPARE_SCALAR_FIELD(val);
30953095

3096-
switch (a->type)
3097-
{
3098-
caseT_Integer:
3099-
COMPARE_SCALAR_FIELD(val.ival);
3100-
break;
3101-
caseT_Float:
3102-
caseT_String:
3103-
caseT_BitString:
3104-
COMPARE_STRING_FIELD(val.str);
3105-
break;
3106-
caseT_Null:
3107-
/* nothing to do */
3108-
break;
3109-
default:
3110-
elog(ERROR,"unrecognized node type: %d", (int)a->type);
3111-
break;
3112-
}
3096+
return true;
3097+
}
3098+
3099+
staticbool
3100+
_equalFloat(constFloat*a,constFloat*b)
3101+
{
3102+
COMPARE_STRING_FIELD(val);
3103+
3104+
return true;
3105+
}
3106+
3107+
staticbool
3108+
_equalString(constString*a,constString*b)
3109+
{
3110+
COMPARE_STRING_FIELD(val);
3111+
3112+
return true;
3113+
}
3114+
3115+
staticbool
3116+
_equalBitString(constBitString*a,constBitString*b)
3117+
{
3118+
COMPARE_STRING_FIELD(val);
31133119

31143120
return true;
31153121
}
@@ -3337,11 +3343,16 @@ equal(const void *a, const void *b)
33373343
break;
33383344

33393345
caseT_Integer:
3346+
retval=_equalInteger(a,b);
3347+
break;
33403348
caseT_Float:
3349+
retval=_equalFloat(a,b);
3350+
break;
33413351
caseT_String:
3352+
retval=_equalString(a,b);
3353+
break;
33423354
caseT_BitString:
3343-
caseT_Null:
3344-
retval=_equalValue(a,b);
3355+
retval=_equalBitString(a,b);
33453356
break;
33463357

33473358
/*

‎src/backend/nodes/nodeFuncs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3537,7 +3537,6 @@ raw_expression_tree_walker(Node *node,
35373537
caseT_Float:
35383538
caseT_String:
35393539
caseT_BitString:
3540-
caseT_Null:
35413540
caseT_ParamRef:
35423541
caseT_A_Const:
35433542
caseT_A_Star:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp