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

Commit7f3014d

Browse files
committed
Change plpgsql's cast cache to consider source typmod as significant.
I had thought that there was no need to maintain separate cache entriesfor different source typmods, but further experimentation shows that thereis an advantage to doing so in some cases. In particular, if a domain hasa typmod (say, "CREATE DOMAIN d AS numeric(20,0)"), failing to notice thesource typmod leads to applying a length-coercion step even when thesource has the correct typmod.
1 parent45f2c2f commit7f3014d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

‎src/pl/plpgsql/src/pl_exec.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ typedef struct
5757
/* NB: we assume this struct contains no padding bytes */
5858
Oidsrctype;/* source type for cast */
5959
Oiddsttype;/* destination type for cast */
60+
int32srctypmod;/* source typmod for cast */
6061
int32dsttypmod;/* destination typmod for cast */
6162
}plpgsql_CastHashKey;
6263

@@ -231,7 +232,7 @@ static Datum exec_cast_value(PLpgSQL_execstate *estate,
231232
Oidvaltype,int32valtypmod,
232233
Oidreqtype,int32reqtypmod);
233234
staticExprState*get_cast_expression(PLpgSQL_execstate*estate,
234-
Oidsrctype,Oiddsttype,int32dsttypmod);
235+
Oidsrctype,int32srctypmod,Oiddsttype,int32dsttypmod);
235236
staticvoidexec_init_tuple_store(PLpgSQL_execstate*estate);
236237
staticvoidexec_set_found(PLpgSQL_execstate*estate,boolstate);
237238
staticvoidplpgsql_create_econtext(PLpgSQL_execstate*estate);
@@ -5733,7 +5734,9 @@ exec_cast_value(PLpgSQL_execstate *estate,
57335734
{
57345735
ExprState*cast_expr;
57355736

5736-
cast_expr=get_cast_expression(estate,valtype,reqtype,reqtypmod);
5737+
cast_expr=get_cast_expression(estate,
5738+
valtype,valtypmod,
5739+
reqtype,reqtypmod);
57375740
if (cast_expr)
57385741
{
57395742
ExprContext*econtext=estate->eval_econtext;
@@ -5769,7 +5772,7 @@ exec_cast_value(PLpgSQL_execstate *estate,
57695772
*/
57705773
staticExprState*
57715774
get_cast_expression(PLpgSQL_execstate*estate,
5772-
Oidsrctype,Oiddsttype,int32dsttypmod)
5775+
Oidsrctype,int32srctypmod,Oiddsttype,int32dsttypmod)
57735776
{
57745777
HTAB*cast_hash=estate->func->cast_hash;
57755778
plpgsql_CastHashKeycast_key;
@@ -5799,6 +5802,7 @@ get_cast_expression(PLpgSQL_execstate *estate,
57995802
/* Look for existing entry */
58005803
cast_key.srctype=srctype;
58015804
cast_key.dsttype=dsttype;
5805+
cast_key.srctypmod=srctypmod;
58025806
cast_key.dsttypmod=dsttypmod;
58035807
cast_entry= (plpgsql_CastHashEntry*)hash_search(cast_hash,
58045808
(void*)&cast_key,
@@ -5815,7 +5819,7 @@ get_cast_expression(PLpgSQL_execstate *estate,
58155819
*/
58165820
placeholder=makeNode(CaseTestExpr);
58175821
placeholder->typeId=srctype;
5818-
placeholder->typeMod=-1;
5822+
placeholder->typeMod=srctypmod;
58195823
placeholder->collation=get_typcollation(srctype);
58205824
if (OidIsValid(estate->func->fn_input_collation)&&
58215825
OidIsValid(placeholder->collation))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp