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

Commit7c3abe3

Browse files
committed
Get rid of ParseState.p_value_substitute; use a columnref hook instead.
I noticed that p_value_substitute, which is a single-purpose kluge I addedin 2002 (commitb0422b2), could be replaced by having domainAddConstraintinstall a parser hook that looks for the name "value". The parser hookcode only dates back to 2009, so it's not surprising that we had to klugethis in 2002, but we can do it more cleanly now.
1 parent3c40594 commit7c3abe3

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

‎src/backend/commands/typecmds.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ static char *domainAddConstraint(Oid domainOid, Oid domainNamespace,
104104
OidbaseTypeOid,
105105
inttypMod,Constraint*constr,
106106
char*domainName,ObjectAddress*constrAddr);
107+
staticNode*replace_domain_constraint_value(ParseState*pstate,
108+
ColumnRef*cref);
107109

108110

109111
/*
@@ -3022,7 +3024,8 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
30223024
domVal->collation=get_typcollation(baseTypeOid);
30233025
domVal->location=-1;/* will be set when/if used */
30243026

3025-
pstate->p_value_substitute= (Node*)domVal;
3027+
pstate->p_pre_columnref_hook=replace_domain_constraint_value;
3028+
pstate->p_ref_hook_state= (void*)domVal;
30263029

30273030
expr=transformExpr(pstate,constr->raw_expr,EXPR_KIND_DOMAIN_CHECK);
30283031

@@ -3099,6 +3102,35 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
30993102
returnccbin;
31003103
}
31013104

3105+
/* Parser pre_columnref_hook for domain CHECK constraint parsing */
3106+
staticNode*
3107+
replace_domain_constraint_value(ParseState*pstate,ColumnRef*cref)
3108+
{
3109+
/*
3110+
* Check for a reference to "value", and if that's what it is, replace
3111+
* with a CoerceToDomainValue as prepared for us by domainAddConstraint.
3112+
* (We handle VALUE as a name, not a keyword, to avoid breaking a lot of
3113+
* applications that have used VALUE as a column name in the past.)
3114+
*/
3115+
if (list_length(cref->fields)==1)
3116+
{
3117+
Node*field1= (Node*)linitial(cref->fields);
3118+
char*colname;
3119+
3120+
Assert(IsA(field1,String));
3121+
colname=strVal(field1);
3122+
if (strcmp(colname,"value")==0)
3123+
{
3124+
CoerceToDomainValue*domVal=copyObject(pstate->p_ref_hook_state);
3125+
3126+
/* Propagate location knowledge, if any */
3127+
domVal->location=cref->location;
3128+
return (Node*)domVal;
3129+
}
3130+
}
3131+
returnNULL;
3132+
}
3133+
31023134

31033135
/*
31043136
* Execute ALTER TYPE RENAME

‎src/backend/parser/parse_expr.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -577,27 +577,6 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref)
577577
/*
578578
* Not known as a column of any range-table entry.
579579
*
580-
* Consider the possibility that it's VALUE in a domain
581-
* check expression. (We handle VALUE as a name, not a
582-
* keyword, to avoid breaking a lot of applications that
583-
* have used VALUE as a column name in the past.)
584-
*/
585-
if (pstate->p_value_substitute!=NULL&&
586-
strcmp(colname,"value")==0)
587-
{
588-
node= (Node*)copyObject(pstate->p_value_substitute);
589-
590-
/*
591-
* Try to propagate location knowledge. This should
592-
* be extended if p_value_substitute can ever take on
593-
* other node types.
594-
*/
595-
if (IsA(node,CoerceToDomainValue))
596-
((CoerceToDomainValue*)node)->location=cref->location;
597-
break;
598-
}
599-
600-
/*
601580
* Try to find the name as a relation. Note that only
602581
* relations already entered into the rangetable will be
603582
* recognized.

‎src/include/parser/parse_node.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ typedef Node *(*CoerceParamHook) (ParseState *pstate, Param *param,
149149
* p_locked_from_parent: true if parent query level applies FOR UPDATE/SHARE
150150
* to this subquery as a whole.
151151
*
152-
* p_value_substitute: replacement for VALUE references, if we're parsing
153-
* a domain CHECK constraint.
154-
*
155152
* p_hasAggs, p_hasWindowFuncs, etc: true if we've found any of the indicated
156153
* constructs in the query.
157154
*
@@ -184,7 +181,6 @@ struct ParseState
184181
List*p_locking_clause;/* raw FOR UPDATE/FOR SHARE info */
185182
boolp_locked_from_parent;/* parent has marked this subquery
186183
* with FOR UPDATE/FOR SHARE */
187-
Node*p_value_substitute;/* what to replace VALUE with, if any */
188184

189185
/* Flags telling about things found in the query: */
190186
boolp_hasAggs;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp