if (pgstat_track_functions <= flinfo->fn_stats)
{
if (flinfo->fn_strict && nargs > 0)
- scratch->opcode = EEOP_FUNCEXPR_STRICT;
+ {
+ /* Choose nargs optimized implementation if available. */
+ if (nargs == 1)
+ scratch->opcode = EEOP_FUNCEXPR_STRICT_1;
+ else if (nargs == 2)
+ scratch->opcode = EEOP_FUNCEXPR_STRICT_2;
+ else
+ scratch->opcode = EEOP_FUNCEXPR_STRICT;
+ }
else
scratch->opcode = EEOP_FUNCEXPR;
}
{
if (strictnulls)
scratch.opcode = EEOP_AGG_STRICT_INPUT_CHECK_NULLS;
+ else if (strictargs && pertrans->numTransInputs == 1)
+ scratch.opcode = EEOP_AGG_STRICT_INPUT_CHECK_ARGS_1;
else
scratch.opcode = EEOP_AGG_STRICT_INPUT_CHECK_ARGS;
scratch.d.agg_strict_input_check.nulls = strictnulls;
as->d.jump.jumpdone = state->steps_len;
}
else if (as->opcode == EEOP_AGG_STRICT_INPUT_CHECK_ARGS ||
+ as->opcode == EEOP_AGG_STRICT_INPUT_CHECK_ARGS_1 ||
as->opcode == EEOP_AGG_STRICT_INPUT_CHECK_NULLS)
{
Assert(as->d.agg_strict_input_check.jumpnull == -1);
return;
}
else if (step0 == EEOP_CASE_TESTVAL &&
- step1 == EEOP_FUNCEXPR_STRICT)
+ (step1 == EEOP_FUNCEXPR_STRICT ||
+ step1 == EEOP_FUNCEXPR_STRICT_1 ||
+ step1 == EEOP_FUNCEXPR_STRICT_2))
{
state->evalfunc_private = ExecJustApplyFuncToCase;
return;
&&CASE_EEOP_CONST,
&&CASE_EEOP_FUNCEXPR,
&&CASE_EEOP_FUNCEXPR_STRICT,
+ &&CASE_EEOP_FUNCEXPR_STRICT_1,
+ &&CASE_EEOP_FUNCEXPR_STRICT_2,
&&CASE_EEOP_FUNCEXPR_FUSAGE,
&&CASE_EEOP_FUNCEXPR_STRICT_FUSAGE,
&&CASE_EEOP_BOOL_AND_STEP_FIRST,
&&CASE_EEOP_AGG_STRICT_DESERIALIZE,
&&CASE_EEOP_AGG_DESERIALIZE,
&&CASE_EEOP_AGG_STRICT_INPUT_CHECK_ARGS,
+ &&CASE_EEOP_AGG_STRICT_INPUT_CHECK_ARGS_1,
&&CASE_EEOP_AGG_STRICT_INPUT_CHECK_NULLS,
&&CASE_EEOP_AGG_PLAIN_PERGROUP_NULLCHECK,
&&CASE_EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL,
EEO_NEXT();
}
+ /* strict function call with more than two arguments */
EEO_CASE(EEOP_FUNCEXPR_STRICT)
{
FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
int nargs = op->d.func.nargs;
Datum d;
+ Assert(nargs > 2);
+
/* strict function, so check for NULL args */
for (int argno = 0; argno < nargs; argno++)
{
EEO_NEXT();
}
+ /* strict function call with one argument */
+ EEO_CASE(EEOP_FUNCEXPR_STRICT_1)
+ {
+ FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
+ NullableDatum *args = fcinfo->args;
+
+ Assert(op->d.func.nargs == 1);
+
+ /* strict function, so check for NULL args */
+ if (args[0].isnull)
+ *op->resnull = true;
+ else
+ {
+ Datum d;
+
+ fcinfo->isnull = false;
+ d = op->d.func.fn_addr(fcinfo);
+ *op->resvalue = d;
+ *op->resnull = fcinfo->isnull;
+ }
+
+ EEO_NEXT();
+ }
+
+ /* strict function call with two arguments */
+ EEO_CASE(EEOP_FUNCEXPR_STRICT_2)
+ {
+ FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
+ NullableDatum *args = fcinfo->args;
+
+ Assert(op->d.func.nargs == 2);
+
+ /* strict function, so check for NULL args */
+ if (args[0].isnull || args[1].isnull)
+ *op->resnull = true;
+ else
+ {
+ Datum d;
+
+ fcinfo->isnull = false;
+ d = op->d.func.fn_addr(fcinfo);
+ *op->resvalue = d;
+ *op->resnull = fcinfo->isnull;
+ }
+
+ EEO_NEXT();
+ }
+
EEO_CASE(EEOP_FUNCEXPR_FUSAGE)
{
/* not common enough to inline */
* input is not NULL.
*/
+ /* when checking more than one argument */
EEO_CASE(EEOP_AGG_STRICT_INPUT_CHECK_ARGS)
{
NullableDatum *args = op->d.agg_strict_input_check.args;
int nargs = op->d.agg_strict_input_check.nargs;
+ Assert(nargs > 1);
+
for (int argno = 0; argno < nargs; argno++)
{
if (args[argno].isnull)
EEO_NEXT();
}
+ /* special case for just one argument */
+ EEO_CASE(EEOP_AGG_STRICT_INPUT_CHECK_ARGS_1)
+ {
+ NullableDatum *args = op->d.agg_strict_input_check.args;
+ PG_USED_FOR_ASSERTS_ONLY int nargs = op->d.agg_strict_input_check.nargs;
+
+ Assert(nargs == 1);
+
+ if (args[0].isnull)
+ EEO_JUMP(op->d.agg_strict_input_check.jumpnull);
+ EEO_NEXT();
+ }
+
EEO_CASE(EEOP_AGG_STRICT_INPUT_CHECK_NULLS)
{
bool *nulls = op->d.agg_strict_input_check.nulls;
case EEOP_FUNCEXPR:
case EEOP_FUNCEXPR_STRICT:
+ case EEOP_FUNCEXPR_STRICT_1:
+ case EEOP_FUNCEXPR_STRICT_2:
{
FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
LLVMValueRef v_fcinfo_isnull;
LLVMValueRef v_retval;
- if (opcode == EEOP_FUNCEXPR_STRICT)
+ if (opcode == EEOP_FUNCEXPR_STRICT ||
+ opcode == EEOP_FUNCEXPR_STRICT_1 ||
+ opcode == EEOP_FUNCEXPR_STRICT_2)
{
LLVMBasicBlockRef b_nonull;
LLVMBasicBlockRef *b_checkargnulls;
}
case EEOP_AGG_STRICT_INPUT_CHECK_ARGS:
+ case EEOP_AGG_STRICT_INPUT_CHECK_ARGS_1:
case EEOP_AGG_STRICT_INPUT_CHECK_NULLS:
{
int nargs = op->d.agg_strict_input_check.nargs;
/*
* Evaluate function call (including OpExprs etc). For speed, we
- * distinguish in the opcode whether the function is strict and/or
- * requires usage stats tracking.
+ * distinguish in the opcode whether the function is strict with 1, 2, or
+ * more arguments and/or requires usage stats tracking.
*/
EEOP_FUNCEXPR,
EEOP_FUNCEXPR_STRICT,
+ EEOP_FUNCEXPR_STRICT_1,
+ EEOP_FUNCEXPR_STRICT_2,
EEOP_FUNCEXPR_FUSAGE,
EEOP_FUNCEXPR_STRICT_FUSAGE,
EEOP_AGG_STRICT_DESERIALIZE,
EEOP_AGG_DESERIALIZE,
EEOP_AGG_STRICT_INPUT_CHECK_ARGS,
+ EEOP_AGG_STRICT_INPUT_CHECK_ARGS_1,
EEOP_AGG_STRICT_INPUT_CHECK_NULLS,
EEOP_AGG_PLAIN_PERGROUP_NULLCHECK,
EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL,