Re: Avoid unnecessary StringInfo allocation in tablesync COPY buffer

Álvaro Herrera <alvherre@kurilemu.de>

From: Álvaro Herrera <alvherre@kurilemu.de>
To: Chao Li <li.evan.chao@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>, David Rowley <dgrowleyml@gmail.com>, Fujii Masao <masao.fujii@gmail.com>
Date: 2026-05-09T15:35:05Z
Lists: pgsql-hackers
Hello,

On 2026-May-09, Chao Li wrote:

> I found this issue while reviewing the patch [1] and was suggested use
> a separate thread for the issue.
> 
> In tablesync.c, copy_table() currently does:
> ```
>    copybuf = makeStringInfo();
> ```
> 
> But copybuf is only used by copy_read_data(), and there it's really
> just acting as a small state holder for data, len, and cursor, rather
> than as a normal growable StringInfo.

I find this coding pattern weird and ugly and confusing.  If what we
need is three variables, shouldn't we have three variables instead of
this strange misuse of the StringInfo abstraction?

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/
"We have labored long to build a heaven, only           (Prof. Milton Glass)
 to find it populated with horrors"                   (Watchmen, Alan Moore)