mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +03:00
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
This commit is contained in:
@ -3135,6 +3135,18 @@ CREATE FOREIGN TABLE ftable ( x int ) SERVER loopback OPTIONS ( table_name 'batc
|
||||
EXPLAIN (VERBOSE, COSTS OFF) INSERT INTO ftable VALUES (1), (2);
|
||||
INSERT INTO ftable VALUES (1), (2);
|
||||
SELECT COUNT(*) FROM ftable;
|
||||
|
||||
-- Disable batch inserting into foreign tables with BEFORE ROW INSERT triggers
|
||||
-- even if the batch_size option is enabled.
|
||||
ALTER FOREIGN TABLE ftable OPTIONS ( SET batch_size '10' );
|
||||
CREATE TRIGGER trig_row_before BEFORE INSERT ON ftable
|
||||
FOR EACH ROW EXECUTE PROCEDURE trigger_data(23,'skidoo');
|
||||
EXPLAIN (VERBOSE, COSTS OFF) INSERT INTO ftable VALUES (3), (4);
|
||||
INSERT INTO ftable VALUES (3), (4);
|
||||
SELECT COUNT(*) FROM ftable;
|
||||
|
||||
-- Clean up
|
||||
DROP TRIGGER trig_row_before ON ftable;
|
||||
DROP FOREIGN TABLE ftable;
|
||||
DROP TABLE batch_table;
|
||||
|
||||
|
Reference in New Issue
Block a user