Re: postgres_fdw: Use COPY to speed up batch inserts

From: "Matheus Alcantara" <matheusssilv97(at)gmail(dot)com>
To: "Dewei Dai" <daidewei1970(at)163(dot)com>, "Matheus Alcantara" <matheusssilv97(at)gmail(dot)com>, "Masahiko Sawada" <sawada(dot)mshk(at)gmail(dot)com>
Cc: "Andrew Dunstan" <andrew(at)dunslane(dot)net>, "jian he" <jian(dot)universality(at)gmail(dot)com>, "Tomas Vondra" <tomas(at)vondra(dot)me>, "pgsql-hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: postgres_fdw: Use COPY to speed up batch inserts
Date: 2026-01-05 13:43:52
Message-ID: DFGP7WDQJ5O0.1BLQ563UVEP7H@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi, thank you for reviewing this patch!

On Sat Jan 3, 2026 at 9:45 AM -03, Dewei Dai wrote:
> 1 - in function `execute_foreign_modify_using_copy`
> The `res` object obtained from the first call to `pgfdw_get_result`
> is not freed, maybe you can use `PQclear` to release it
>
Fixed.

> 2 - in function `execute_foreign_modify_using_copy`
> After using `copy_data`,it appears it can be released by
> calling `destroyStringInfo`.
>
I'm wondering if we should call destroyStringInfo(&copy_data) or
pfree(copy_data.data). Other functions use the pfree version, so I
decided to use the same.

(I actually tried to use destroyStringInfo() but the postgres_fdw tests
kept running for longer than usual, so I think that using the pfree is
correct)

> 3 - in function `convert_slot_to_copy_text`
> The value returned by the OutputFunctionCall function can be
> freed by calling pfree
>
We have other calls to OutputFunctionCall() on postgres_fdw.c and I'm
not seeing a subsequent call to pfree. IIUC the returned valued will be
allocated on the current memory context which will be free at the end of
query execution, so I don't think that a pfree here is necessary, or I'm
missing something?

> 4 - in function `execute_foreign_modify_using_copy`
> ```Send initial COPY data if the buffer reach the limit to avoid large
> ```
> Typo: reach -> reaches
>
Fixed

--
Matheus Alcantara
EDB: https://www.enterprisedb.com

Attachment Content-Type Size
v9-0001-postgres_fdw-speed-up-batch-inserts-using-COPY.patch text/plain 14.8 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Henson Choi 2026-01-05 13:55:52 Re: SQL Property Graph Queries (SQL/PGQ)
Previous Message Peter Eisentraut 2026-01-05 13:35:43 Re: Don't cast away const where possible