agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
pgsql: Fix hangs in COPY FROM (FORMAT text).
2+ messages / 1 participants
[nested] [flat]

* pgsql: Fix hangs in COPY FROM (FORMAT text).
@ 2026-09-09 21:05 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Nathan Bossart @ 2026-09-09 21:05 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
master

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

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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Fix hangs in COPY FROM (FORMAT text).
@ 2026-09-09 21:05 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Nathan Bossart @ 2026-09-09 21:05 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-09-09 21:05 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-09-09 21:05 pgsql: Fix hangs in COPY FROM (FORMAT text). Nathan Bossart <nathan@postgresql.org>
2026-09-09 21:05 pgsql: Fix hangs in COPY FROM (FORMAT text). Nathan Bossart <nathan@postgresql.org>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox