Re: Speed up COPY FROM text/CSV parsing using SIMD

From: Nazir Bilal Yavuz <byavuz81(at)gmail(dot)com>
To: Nathan Bossart <nathandbossart(at)gmail(dot)com>
Cc: Greg Burd <greg(at)burd(dot)me>, KAZAR Ayoub <ma_kazar(at)esi(dot)dz>, Neil Conway <neil(dot)conway(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Shinya Kato <shinya11(dot)kato(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Speed up COPY FROM text/CSV parsing using SIMD
Date: 2026-09-08 10:11:00
Message-ID: CAN55FZ3U2waD=5ZuVmju-HtZ4cO4onxHN4jXskk8Y11M6o3NOQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Mon, 7 Sept 2026 at 19:29, Nazir Bilal Yavuz <byavuz81(at)gmail(dot)com> wrote:
>
> When fewer than one SIMD vector of bytes (16 in this case) remain
> buffered, CopyReadLineTextSIMDHelper() refills the input before
> falling back to scalar parsing. If those buffered bytes already
> contain a complete '\.' (end-of-copy marker) and the source is an open
> FIFO with no more data, the refill blocks, so COPY fails to recognize
> the marker until more data arrives or the writer closes the FIFO.
> Reproducer SQL script is attached, you can see that this causes a
> hang.
>
> One potential fix is checking for an end-of-copy marker when fewer
> than one SIMD vector of bytes remains in the buffer and we decide to
> load more data into it. I haven't benchmarked this solution yet but it
> could potentially cause a slowdown when we load data in smaller
> chunks. Otherwise, I don't think this solution will cause a slowdown.
> I am planning to work on this tomorrow.
>
> Any opinions on the bug or the potential solution?

Here is an attempt to solve this problem. I ran Manni's script and saw
a 1-2% slowdown on TEXT-wide inputs. It is still faster compared to
the version without the SIMD patch; the slowdown is relative to the
current master branch (which includes the SIMD patch).

--
Regards,
Nazir Bilal Yavuz
Microsoft

Attachment Content-Type Size
v1-0001-Fix-COPY-SIMD-refill-blocking-on-buffered-end-mar.patch text/x-patch 1.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2026-09-08 10:27:19 Re: REPACK (ANALYZE) within transaction block segfaults
Previous Message Peter Eisentraut 2026-09-08 10:08:52 Use C11 alignas instead of palloc/malloc for alignment