pgsql: Fix hangs in COPY FROM (FORMAT text).

From: Nathan Bossart <nathan(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix hangs in COPY FROM (FORMAT text).
Date: 2026-09-09 21:05:29
Message-ID: E1x4PU0-00000004BAD-1f6G@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)gmail(dot)com>
Reviewed-by: Greg Burd <greg(at)burd(dot)me>
Discussion: https://postgr.es/m/CAN55FZ1qFb4Yo3-MWeQfGQnu1_Ksx4xcFC2m3hyw8a--%2BeHQYQ%40mail.gmail.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d1895a11c8f1b19b3fe0db45cc10a9d26c56bc8c

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

Browse pgsql-committers by date

  From Date Subject
Next Message Nathan Bossart 2026-09-09 21:30:50 pgsql: Add pg_nodiscard decorations to some Bitmapset functions.
Previous Message Masahiko Sawada 2026-09-09 20:46:17 pgsql: Unify REPACK (CONCURRENTLY) error messages.