Re: postgres_fdw: Use COPY to speed up batch inserts - Mailing list pgsql-hackers

From Masahiko Sawada
Subject Re: postgres_fdw: Use COPY to speed up batch inserts
Date
Msg-id CAD21AoCMNawy_72g1pc2JU0fp3X1_a_ce-ZQ6P9+YmdMMg-4Rg@mail.gmail.com
Whole thread Raw
In response to Re: postgres_fdw: Use COPY to speed up batch inserts  ("Matheus Alcantara" <matheusssilv97@gmail.com>)
Responses Re: postgres_fdw: Use COPY to speed up batch inserts
List pgsql-hackers
Sorry for the late reply.

On Thu, Dec 11, 2025 at 4:03 AM Matheus Alcantara
<matheusssilv97@gmail.com> wrote:
>
> I've spent some more time on this patch cleaning up some things and
> trying to simplify some things.
>
> I've renamed "copy_for_batch_insert_threshold" to
> "batch_with_copy_threshold" and removed the boolean option
> "use_copy_for_batch_insert", so now to enable the COPY usage for batch
> inserts it only need to set batch_with_copy_threshold to a number
> greater than 0.
>
> Also the COPY can only be used if batching is also enabled (batch_size >
> 1) and it will only be used for the COPY FROM on a foreign table and for
> inserts into table partitions that are also foreign tables.

Thank you for updating the patch!

+
+   /*
+    * Set batch_with_copy_threshold from foreign server/table options. We do
+    * this outside of create_foreign_modify() because we only want to use
+    * COPY as a remote SQL when a COPY FROM on a foreign table is executed or
+    * an insert is being performed on a table partition. In both cases the
+    * BeginForeignInsert fdw routine is called.
+    */
+   fmstate->batch_with_copy_threshold = get_batch_with_copy_threshold(rel);

Does it mean that we could end up using the COPY method not only when
executing COPY FROM but also when executing INSERT with tuple
routings? If so, how does the EXPLAIN command show the remote SQL?

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com



pgsql-hackers by date:

Previous
From: Jim Jones
Date:
Subject: Re: [PATCH] psql: add \dcs to list all constraints
Next
From: "Matheus Alcantara"
Date:
Subject: Re: postgres_fdw: Use COPY to speed up batch inserts