Re: Avoid unnecessary StringInfo allocation in tablesync COPY buffer

From: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
To: Aleksander Alekseev <aleksander(at)tigerdata(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, ZizhuanLiu X-MAN <44973863(at)qq(dot)com>, Denis Smirnov <darthunix(at)gmail(dot)com>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, David Rowley <dgrowleyml(at)gmail(dot)com>, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Subject: Re: Avoid unnecessary StringInfo allocation in tablesync COPY buffer
Date: 2026-11-23 12:26:53
Message-ID: awQqxeejbPAlo6ph@alvherre.pgsql
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2026-Nov-23, Aleksander Alekseev wrote:

> Hi,
>
> > I revised the patch based on the discussion. Instead of introducing
> > a separate CopyBuf abstraction, v3 reuses the existing
> > StringInfoData mechanism.
>
> I fail to understand the value of v3 except the fact that it saves 3
> lines of code. Arguably right now we have much larger problems e.g.
> actual bugs to fix and we better spend the time of the reviewers on
> these problems.

I agree that there are more important things to fix. I thought using a
read-only StringInfo and getting rid of the global wasn't a completely
bad idea. I was reading this patch thinking it could be a quick push,
but I realized that it's not trivial to see from eyeballing alone that
we don't call walrcv_receive() one more time before consuming the whole
buffer (which libpqrcv_receive warns against). Admittedly, the same can
be said of the original code, so this is not a new concern. Maybe a few
extra comments would make this business clearer.

Another thing I noticed is that minread is always 1 in current callers
of CopyGetData(). We used to have callers passing other values, but
that code's gone. Not sure this insight buys us anything, as I don't
see changing it to hardcode a 1, although we could remove the parameter
in all the callers that pass a copy_data_source_cb to BeginCopyFrom ...
which is only the one being patched here, curiously.

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dean Rasheed 2026-11-23 12:32:08 Re: Fix stale source values in MERGE RETURNING after a cross-partition update
Previous Message Shlok Kyal 2026-11-23 12:22:58 Re: Initial table sync copies the whole table when it is no longer published