agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Nathan Bossart <nathan@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix hangs in COPY FROM (FORMAT text).
Date: Wed, 09 Sep 2026 21:05:29 +0000
Message-ID: <E1x4PU0-00000004BAF-1mOg@gemulon.postgresql.org> (raw)

Fix hangs in COPY FROM (FORMAT text).

The SIMD path for this command reads ahead via CopyLoadInputBuf()
whenever fewer than sizeof(Vector8) bytes remain in the input
buffer, even if those bytes hold a complete end-of-copy marker.
If the input is a pipe whose writer has sent the marker but not
closed the pipe, that read blocks, and COPY waits for data it will
never use.  The scalar loop asks only for the bytes it needs, so
it stops at the marker without reading any further.

To fix, teach CopyLoadInputBuf() to decline a speculative load
when the caller's remaining bytes contain a backslash, which in
text mode might begin such a marker.  (CSV mode doesn't treat
\. as special, so it is unaffected.)  The SIMD path then hands
those bytes to the scalar loop, as it already does when a load
comes up short.  Checking for the marker in the SIMD helper itself
would be more direct, but a call there costs the compiler
registers on every line, which measurably slowed COPY of short
lines in testing.

Oversight in commit e0a3a3fd53.

Author: Nazir Bilal Yavuz <byavuz81@gmail.com>
Reviewed-by: Greg Burd <greg@burd.me>
Discussion: https://postgr.es/m/CAN55FZ1qFb4Yo3-MWeQfGQnu1_Ksx4xcFC2m3hyw8a--%2BeHQYQ%40mail.gmail.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/50ba390a4f81536aac13c1b8cf75c646a1156527

Modified Files
--------------
src/backend/commands/copyfromparse.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)



view thread (2+ messages)

Message-ID: <E1x4PU0-00000004BAF-1mOg@gemulon.postgresql.org>
Permalink:  ../E1x4PU0-00000004BAF-1mOg@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1x4PU0-00000004BAF-1mOg@gemulon.postgresql.org

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-committers@postgresql.org
  Cc: nathan@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix hangs in COPY FROM (FORMAT text).
  In-Reply-To: <E1x4PU0-00000004BAF-1mOg@gemulon.postgresql.org>

* 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