Implement support for bulk inserts in postgres_fdw
authorTomas Vondra <tomas.vondra@postgresql.org>
Wed, 20 Jan 2021 22:05:46 +0000 (23:05 +0100)
committerTomas Vondra <tomas.vondra@postgresql.org>
Wed, 20 Jan 2021 22:57:27 +0000 (23:57 +0100)
commitb663a4136331de6c7364226e3dbf7c88bfee7145
tree3a14fac68bcfc27a42e365501ce1cdbc1ddfdc00
parentad600bba0422dde4b73fbd61049ff2a3847b068a
Implement support for bulk inserts in postgres_fdw

Extends the FDW API to allow batching inserts into foreign tables. That
is usually much more efficient than inserting individual rows, due to
high latency for each round-trip to the foreign server.

It was possible to implement something similar in the regular FDW API,
but it was inconvenient and there were issues with reporting the number
of actually inserted rows etc. This extends the FDW API with two new
functions:

* GetForeignModifyBatchSize - allows the FDW picking optimal batch size

* ExecForeignBatchInsert - inserts a batch of rows at once

Currently, only INSERT queries support batching. Support for DELETE and
UPDATE may be added in the future.

This also implements batching for postgres_fdw. The batch size may be
specified using "batch_size" option both at the server and table level.

The initial patch version was written by me, but it was rewritten and
improved in many ways by Takayuki Tsunakawa.

Author: Takayuki Tsunakawa
Reviewed-by: Tomas Vondra, Amit Langote
Discussion: https://postgr.es/m/20200628151002.7x5laxwpgvkyiu3q@development
14 files changed:
contrib/postgres_fdw/deparse.c
contrib/postgres_fdw/expected/postgres_fdw.out
contrib/postgres_fdw/option.c
contrib/postgres_fdw/postgres_fdw.c
contrib/postgres_fdw/postgres_fdw.h
contrib/postgres_fdw/sql/postgres_fdw.sql
doc/src/sgml/fdwhandler.sgml
doc/src/sgml/postgres-fdw.sgml
src/backend/executor/execPartition.c
src/backend/executor/nodeModifyTable.c
src/backend/nodes/list.c
src/include/foreign/fdwapi.h
src/include/nodes/execnodes.h
src/include/nodes/pg_list.h