agora inbox for pgsql-hackers@postgresql.org
help / color / mirror / Atom feedFrom: Nathan Bossart <nathan@postgresql.org>
Subject: [PATCH v8 1/1] Speedup COPY FROM with additional function inlining.
Date: Wed, 18 Feb 2026 14:55:39 -0600
Following the example set by commit 58a359e585, we can squeeze out
a little more performance from COPY FROM (FORMAT {text,csv}) by
forcing CopyReadLineText() to be inlined and by passing the is_csv
parameter as a constant. This allows the compiler to emit
specialized code with the known-const false comparisons and
subsequent branches removed.
Author: Nazir Bilal Yavuz <byavuz81@gmail.com>
Reviewed-by: Ayoub Kazar <ma_kazar@esi.dz>
Discussion: https://postgr.es/m/CAOzEurSW8cNr6TPKsjrstnPfhf4QyQqB4tnPXGGe8N4e_v7Jig%40mail.gmail.com
---
src/backend/commands/copyfromparse.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c
index 94d6f415a06..0aa549837b5 100644
--- a/src/backend/commands/copyfromparse.c
+++ b/src/backend/commands/copyfromparse.c
@@ -141,7 +141,8 @@ static const char BinarySignature[11] = "PGCOPY\n\377\r\n\0";
/* non-export function prototypes */
static bool CopyReadLine(CopyFromState cstate, bool is_csv);
-static bool CopyReadLineText(CopyFromState cstate, bool is_csv);
+static pg_attribute_always_inline bool CopyReadLineText(CopyFromState cstate,
+ bool is_csv);
static int CopyReadAttributesText(CopyFromState cstate);
static int CopyReadAttributesCSV(CopyFromState cstate);
static Datum CopyReadBinaryAttribute(CopyFromState cstate, FmgrInfo *flinfo,
@@ -1173,8 +1174,18 @@ CopyReadLine(CopyFromState cstate, bool is_csv)
resetStringInfo(&cstate->line_buf);
cstate->line_buf_valid = false;
- /* Parse data and transfer into line_buf */
- result = CopyReadLineText(cstate, is_csv);
+ /*
+ * Parse data and transfer into line_buf.
+ *
+ * Because this is performance critical, we inline CopyReadLineText() and
+ * pass the boolean parameters as constants to allow the compiler to emit
+ * specialized code with the known-const false comparisons and subsequent
+ * branches removed.
+ */
+ if (is_csv)
+ result = CopyReadLineText(cstate, true);
+ else
+ result = CopyReadLineText(cstate, false);
if (result)
{
@@ -1241,7 +1252,7 @@ CopyReadLine(CopyFromState cstate, bool is_csv)
/*
* CopyReadLineText - inner loop of CopyReadLine for text mode
*/
-static bool
+static pg_attribute_always_inline bool
CopyReadLineText(CopyFromState cstate, bool is_csv)
{
char *copy_input_buf;
--
2.50.1 (Apple Git-155)
--qJ6V/+kxsNWNoiKe--
Message-ID: <no-message-id-1861345@localhost>
Permalink: ../no-message-id-1861345@localhost/
Also on: postgresql.org/message-id/no-message-id-1861345@localhost
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: nathan@postgresql.org
Subject: Re: [PATCH v8 1/1] Speedup COPY FROM with additional function inlining.
In-Reply-To: <no-message-id-1861345@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox