Subject: Avoid unnecessary StringInfo allocation in tablesync COPY buffer

From: Chao Li <[email-masked]>
Date: Sat, 9 May 2026 14:10:50 +0800

Hi,

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. That means we do not need to allocate a StringInfo object or its backing buffer at all.

It would be cleaner to use a plain StringInfoData and simply reinitialize or zero it in copy_table(). See the attached patch for the proposed change.

David Rowley has made several cleanup changes in this area to prefer stack-allocated StringInfoData, for example a63bbc811d41b3567eb37fe2636e660a852dbbf2. This change seems consistent with that direction.

[1] https://postgr.es/m/CAOzEurQKuy3RiPkd=25PEwEzaqHuGvEOf=[email-masked]

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

---

From: Álvaro Herrera <[email-masked]>
Date: Sat, 9 May 2026 17:35:05 +0200

Hello,

On 2026-May-09, Chao Li wrote:

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

---

From: Chao Li <[email-masked]>
Date: Mon, 11 May 2026 15:09:21 +0800

> On May 9, 2026, at 23:35, Álvaro Herrera <[email-masked]> wrote:
> 
> Hello,
> 

Yep, I first considered adding a file-local structure, but decided to keep the changes minimal in the first version.

In v2, I switched to using a small file-local CopyBuf structure.

Best regards,