diff options
author | Daniel Gustafsson <dgustafsson@postgresql.org> | 2025-03-11 12:02:42 +0100 |
---|---|---|
committer | Daniel Gustafsson <dgustafsson@postgresql.org> | 2025-03-11 12:02:42 +0100 |
commit | d35d32d7112bc632c6a305e9dffdec0082bbdf00 (patch) | |
tree | 0e8b4c3c6b8603977cc68e59bc372764e7b489d8 /src/backend/executor/execExpr.c | |
parent | 8dd7c7cd0a2605d5301266a6b67a569d6a305106 (diff) | |
download | postgresql-d35d32d7112bc632c6a305e9dffdec0082bbdf00.tar.gz postgresql-d35d32d7112bc632c6a305e9dffdec0082bbdf00.zip |
Add special case fast-paths for strict functions
Many STRICT function calls will have one or two arguments, in which
case we can speed up checking for NULL input by avoiding setting up
a loop over the arguments. This adds EEOP_FUNCEXPR_STRICT_1 and the
corresponding EEOP_FUNCEXPR_STRICT_2 for functions with one and two
arguments respectively.
Author: Andres Freund <andres@anarazel.de>
Co-authored-by: Daniel Gustafsson <daniel@yesql.se>
Reviewed-by: Andreas Karlsson <andreas@proxel.se>
Discussion: https://postgr.es/m/415721CE-7D2E-4B74-B5D9-1950083BA03E@yesql.se
Discussion: https://postgr.es/m/20191023163849.sosqbfs5yenocez3@alap3.anarazel.de
Diffstat (limited to 'src/backend/executor/execExpr.c')
-rw-r--r-- | src/backend/executor/execExpr.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/backend/executor/execExpr.c b/src/backend/executor/execExpr.c index 0175b152980..f1569879b52 100644 --- a/src/backend/executor/execExpr.c +++ b/src/backend/executor/execExpr.c @@ -2788,7 +2788,15 @@ ExecInitFunc(ExprEvalStep *scratch, Expr *node, List *args, Oid funcid, 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; } @@ -3892,6 +3900,8 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase, { 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; @@ -3968,6 +3978,7 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase, 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); |