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

Commitfe2e206

Browse files
committed
Inline the fast path of plpgsql's exec_cast_value().
In the common case where this function isn't actually asked to performany type conversion, there's nothing it has to do beyond comparing thearguments. Arrange for that part to be inlined into callers, with theslower path remaining out-of-line. This seems to be good for severalpercent speedup on simple cases, with only minimal code bloat.Amit KhandekarDiscussion:https://postgr.es/m/CAJ3gD9eBNrmUD7WBBLG8ohaZ485H9y+4eihQTgr+K8Lhka3vcQ@mail.gmail.com
1 parent90b2d8c commitfe2e206

File tree

1 file changed

+43
-22
lines changed

1 file changed

+43
-22
lines changed

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

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,14 @@ static void instantiate_empty_record_variable(PLpgSQL_execstate *estate,
417417
PLpgSQL_rec*rec);
418418
staticchar*convert_value_to_string(PLpgSQL_execstate*estate,
419419
Datumvalue,Oidvaltype);
420-
staticDatumexec_cast_value(PLpgSQL_execstate*estate,
421-
Datumvalue,bool*isnull,
422-
Oidvaltype,int32valtypmod,
423-
Oidreqtype,int32reqtypmod);
420+
staticinlineDatumexec_cast_value(PLpgSQL_execstate*estate,
421+
Datumvalue,bool*isnull,
422+
Oidvaltype,int32valtypmod,
423+
Oidreqtype,int32reqtypmod);
424+
staticDatumdo_cast_value(PLpgSQL_execstate*estate,
425+
Datumvalue,bool*isnull,
426+
Oidvaltype,int32valtypmod,
427+
Oidreqtype,int32reqtypmod);
424428
staticplpgsql_CastHashEntry*get_cast_hashentry(PLpgSQL_execstate*estate,
425429
Oidsrctype,int32srctypmod,
426430
Oiddsttype,int32dsttypmod);
@@ -7825,7 +7829,7 @@ convert_value_to_string(PLpgSQL_execstate *estate, Datum value, Oid valtype)
78257829
* done with the result.
78267830
* ----------
78277831
*/
7828-
staticDatum
7832+
staticinlineDatum
78297833
exec_cast_value(PLpgSQL_execstate*estate,
78307834
Datumvalue,bool*isnull,
78317835
Oidvaltype,int32valtypmod,
@@ -7837,30 +7841,47 @@ exec_cast_value(PLpgSQL_execstate *estate,
78377841
if (valtype!=reqtype||
78387842
(valtypmod!=reqtypmod&&reqtypmod!=-1))
78397843
{
7840-
plpgsql_CastHashEntry*cast_entry;
7844+
/* We keep the slow path out-of-line. */
7845+
value=do_cast_value(estate,value,isnull,valtype,valtypmod,
7846+
reqtype,reqtypmod);
7847+
}
78417848

7842-
cast_entry=get_cast_hashentry(estate,
7843-
valtype,valtypmod,
7844-
reqtype,reqtypmod);
7845-
if (cast_entry)
7846-
{
7847-
ExprContext*econtext=estate->eval_econtext;
7848-
MemoryContextoldcontext;
7849+
returnvalue;
7850+
}
78497851

7850-
oldcontext=MemoryContextSwitchTo(get_eval_mcontext(estate));
7852+
/* ----------
7853+
* do_cast_valueSlow path for exec_cast_value.
7854+
* ----------
7855+
*/
7856+
staticDatum
7857+
do_cast_value(PLpgSQL_execstate*estate,
7858+
Datumvalue,bool*isnull,
7859+
Oidvaltype,int32valtypmod,
7860+
Oidreqtype,int32reqtypmod)
7861+
{
7862+
plpgsql_CastHashEntry*cast_entry;
78517863

7852-
econtext->caseValue_datum=value;
7853-
econtext->caseValue_isNull=*isnull;
7864+
cast_entry=get_cast_hashentry(estate,
7865+
valtype,valtypmod,
7866+
reqtype,reqtypmod);
7867+
if (cast_entry)
7868+
{
7869+
ExprContext*econtext=estate->eval_econtext;
7870+
MemoryContextoldcontext;
78547871

7855-
cast_entry->cast_in_use=true;
7872+
oldcontext=MemoryContextSwitchTo(get_eval_mcontext(estate));
78567873

7857-
value=ExecEvalExpr(cast_entry->cast_exprstate,econtext,
7858-
isnull);
7874+
econtext->caseValue_datum=value;
7875+
econtext->caseValue_isNull=*isnull;
78597876

7860-
cast_entry->cast_in_use=false;
7877+
cast_entry->cast_in_use=true;
78617878

7862-
MemoryContextSwitchTo(oldcontext);
7863-
}
7879+
value=ExecEvalExpr(cast_entry->cast_exprstate,econtext,
7880+
isnull);
7881+
7882+
cast_entry->cast_in_use= false;
7883+
7884+
MemoryContextSwitchTo(oldcontext);
78647885
}
78657886

78667887
returnvalue;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp