[PATCH] Optimization: avoid repeated strlen() calls in function CreateTriggerFiringOn when parsing trigger arguments
Signed-off-by: Lucas Jeffrey <luquijeffrey@gmail.com>
---
src/backend/commands/trigger.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 1d10fb1c13c..fe447f6df68 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -899,6 +899,7 @@ CreateTriggerFiringOn(const CreateTrigStmt *stmt, const char *queryString,
char *args;
int nargs = list_length(stmt->args);
int len = 0;
+ char *d;
Assert(nargs >= 0);
if (nargs > PG_INT16_MAX)
@@ -922,10 +923,10 @@ CreateTriggerFiringOn(const CreateTrigStmt *stmt, const char *queryString,
}
args = (char *) palloc(len + 1);
args[0] = '\0';
+ d = args;
foreach(le, stmt->args)
{
char *s = strVal(lfirst(le));
- char *d = args + strlen(args);
while (*s)
{
@@ -934,6 +935,7 @@ CreateTriggerFiringOn(const CreateTrigStmt *stmt, const char *queryString,
*d++ = *s++;
}
strcpy(d, "\\000");
+ d += 4;
}
values[Anum_pg_trigger_tgnargs - 1] = Int16GetDatum(nargs);
values[Anum_pg_trigger_tgargs - 1] = DirectFunctionCall1(byteain,
--
2.43.0
On Tue, Sep 08, 2026 at 09:00:31PM -0300, Lucas Jeffrey wrote:
foreach(le, stmt->args)
{
char *s = strVal(lfirst(le));
- char *d = args + strlen(args);
While a right suggestion, trigger creation is no critical path. So
why caring?
--
Michael
On 9 Sep 2026, at 02:00, Lucas Jeffrey <luquijeffrey@gmail.com> wrote:
Signed-off-by: Lucas Jeffrey <luquijeffrey@gmail.com>
Optimization patches require a great deal more justification than just the
diff: a discussion on why it's safe and a non-synthetical benchmark which shows
the benefit.
--
Daniel Gustafsson