| From: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
| Cc: | David Rowley <dgrowleyml(at)gmail(dot)com>, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> |
| Subject: | Avoid unnecessary StringInfo allocation in tablesync COPY buffer |
| Date: | 2026-05-09 06:10:50 |
| Message-ID: | 5B2C9B4C-EAE6-4F21-AF99-613A561D26DC@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
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=X7vaVzhgNjaukYzA@mail.gmail.com
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Avoid-unnecessary-StringInfo-allocation-in-tables.patch | application/octet-stream | 2.6 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Zhenwei Shang | 2026-05-09 06:30:17 | Re: Doc update proposal for the note on log_statement in the runtime config for logging page |
| Previous Message | Chao Li | 2026-05-09 05:57:10 | Re: Call EndCopyFrom() after initial table sync in logical replication |