aboutsummaryrefslogtreecommitdiff
path: root/contrib/postgres_fdw/postgres_fdw.c
diff options
context:
space:
mode:
authorEtsuro Fujita <efujita@postgresql.org>2022-04-21 15:30:02 +0900
committerEtsuro Fujita <efujita@postgresql.org>2022-04-21 15:30:02 +0900
commit89d349b0a0239504325e5f63755f3bc1e1742478 (patch)
tree87c5e5d371d040625ae3b7c3f7442624377ad3fb /contrib/postgres_fdw/postgres_fdw.c
parente4521841a1ee6917633bd28b34496c1627588731 (diff)
downloadpostgresql-89d349b0a0239504325e5f63755f3bc1e1742478.tar.gz
postgresql-89d349b0a0239504325e5f63755f3bc1e1742478.zip
postgres_fdw: Disable batch insert when BEFORE ROW INSERT triggers exist.
Previously, we allowed this, but such triggers might query the table to insert into and act differently if the tuples that have already been processed and prepared for insertion are not there, so disable it in such cases. Back-patch to v14 where batch insert was added. Discussion: https://postgr.es/m/CAPmGK16_uPqsmgK0-LpLSUk54_BoK13bPrhxhfjSoSTVz414hA%40mail.gmail.com
Diffstat (limited to 'contrib/postgres_fdw/postgres_fdw.c')
-rw-r--r--contrib/postgres_fdw/postgres_fdw.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index 2193383eecb..0e24ed2a487 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -2012,8 +2012,8 @@ postgresExecForeignBatchInsert(EState *estate,
* Determine the maximum number of tuples that can be inserted in bulk
*
* Returns the batch size specified for server or table. When batching is not
- * allowed (e.g. for tables with AFTER ROW triggers or with RETURNING clause),
- * returns 1.
+ * allowed (e.g. for tables with BEFORE/AFTER ROW triggers or with RETURNING
+ * clause), returns 1.
*/
static int
postgresGetForeignModifyBatchSize(ResultRelInfo *resultRelInfo)
@@ -2042,10 +2042,19 @@ postgresGetForeignModifyBatchSize(ResultRelInfo *resultRelInfo)
else
batch_size = get_batch_size_option(resultRelInfo->ri_RelationDesc);
- /* Disable batching when we have to use RETURNING. */
+ /*
+ * Disable batching when we have to use RETURNING or there are any
+ * BEFORE/AFTER ROW INSERT triggers on the foreign table.
+ *
+ * When there are any BEFORE ROW INSERT triggers on the table, we can't
+ * support it, because such triggers might query the table we're inserting
+ * into and act differently if the tuples that have already been processed
+ * and prepared for insertion are not there.
+ */
if (resultRelInfo->ri_projectReturning != NULL ||
(resultRelInfo->ri_TrigDesc &&
- resultRelInfo->ri_TrigDesc->trig_insert_after_row))
+ (resultRelInfo->ri_TrigDesc->trig_insert_before_row ||
+ resultRelInfo->ri_TrigDesc->trig_insert_after_row)))
return 1;
/*