Commit fe2e206c authored by Tom Lane's avatar Tom Lane

Inline the fast path of plpgsql's exec_cast_value().

In the common case where this function isn't actually asked to perform
any type conversion, there's nothing it has to do beyond comparing the
arguments.  Arrange for that part to be inlined into callers, with the
slower path remaining out-of-line.  This seems to be good for several
percent speedup on simple cases, with only minimal code bloat.

Amit Khandekar

Discussion: https://postgr.es/m/CAJ3gD9eBNrmUD7WBBLG8ohaZ485H9y+4eihQTgr+K8Lhka3vcQ@mail.gmail.com
parent 90b2d8c1
......@@ -417,7 +417,11 @@ static void instantiate_empty_record_variable(PLpgSQL_execstate *estate,
PLpgSQL_rec *rec);
static char *convert_value_to_string(PLpgSQL_execstate *estate,
Datum value, Oid valtype);
static Datum exec_cast_value(PLpgSQL_execstate *estate,
static inline Datum exec_cast_value(PLpgSQL_execstate *estate,
Datum value, bool *isnull,
Oid valtype, int32 valtypmod,
Oid reqtype, int32 reqtypmod);
static Datum do_cast_value(PLpgSQL_execstate *estate,
Datum value, bool *isnull,
Oid valtype, int32 valtypmod,
Oid reqtype, int32 reqtypmod);
......@@ -7825,7 +7829,7 @@ convert_value_to_string(PLpgSQL_execstate *estate, Datum value, Oid valtype)
* done with the result.
* ----------
*/
static Datum
static inline Datum
exec_cast_value(PLpgSQL_execstate *estate,
Datum value, bool *isnull,
Oid valtype, int32 valtypmod,
......@@ -7837,6 +7841,24 @@ exec_cast_value(PLpgSQL_execstate *estate,
if (valtype != reqtype ||
(valtypmod != reqtypmod && reqtypmod != -1))
{
/* We keep the slow path out-of-line. */
value = do_cast_value(estate, value, isnull, valtype, valtypmod,
reqtype, reqtypmod);
}
return value;
}
/* ----------
* do_cast_value Slow path for exec_cast_value.
* ----------
*/
static Datum
do_cast_value(PLpgSQL_execstate *estate,
Datum value, bool *isnull,
Oid valtype, int32 valtypmod,
Oid reqtype, int32 reqtypmod)
{
plpgsql_CastHashEntry *cast_entry;
cast_entry = get_cast_hashentry(estate,
......@@ -7861,7 +7883,6 @@ exec_cast_value(PLpgSQL_execstate *estate,
MemoryContextSwitchTo(oldcontext);
}
}
return value;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment