From 4bacc6156b29b1f0fd34bc1d5a895efd9aa0d495 Mon Sep 17 00:00:00 2001 From: "dgrowley@gmail.com" Date: Wed, 10 Jun 2020 11:00:26 +1200 Subject: [PATCH 1/2] Improve performance of int8out Previously we wrote the string to a local buffer and then pstrdup'd that. However, it seems reasonable that we just palloc enough space for the largest of numbers and write the string directly to that instead. This saves us a strlen() and memcpy() call, which results in some demonstratable speedups of COPY from a table with a BIGINT column. --- src/backend/utils/adt/int8.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c index abba8f1df0..cb666b80b9 100644 --- a/src/backend/utils/adt/int8.c +++ b/src/backend/utils/adt/int8.c @@ -147,11 +147,9 @@ Datum int8out(PG_FUNCTION_ARGS) { int64 val = PG_GETARG_INT64(0); - char buf[MAXINT8LEN + 1]; - char *result; + char *result = (char *) palloc(MAXINT8LEN + 1); - pg_lltoa(val, buf); - result = pstrdup(buf); + pg_lltoa(val, result); PG_RETURN_CSTRING(result); } -- 2.25.1