diff --git a/src/backend/distributed/commands/multi_copy.c b/src/backend/distributed/commands/multi_copy.c index 1f0abbb56..6a93e298a 100644 --- a/src/backend/distributed/commands/multi_copy.c +++ b/src/backend/distributed/commands/multi_copy.c @@ -2060,8 +2060,12 @@ CitusCopyDestReceiverStartup(DestReceiver *dest, int operation, UseCoordinatedTransaction(); - /* all modifications use 2PC */ - Use2PCForCoordinatedTransaction(); + /* all modifications use 2PC unless we only touch a single shard */ + if (!IsCitusTableTypeCacheEntry(cacheEntry, SINGLE_SHARD_DISTRIBUTED) && + !IsCitusTableTypeCacheEntry(cacheEntry, CITUS_LOCAL_TABLE)) + { + Use2PCForCoordinatedTransaction(); + } /* define how tuples will be serialised */ CopyOutState copyOutState = (CopyOutState) palloc0(sizeof(CopyOutStateData)); diff --git a/src/test/regress/expected/foreign_tables_mx.out b/src/test/regress/expected/foreign_tables_mx.out index f9f63806b..179060b44 100644 --- a/src/test/regress/expected/foreign_tables_mx.out +++ b/src/test/regress/expected/foreign_tables_mx.out @@ -38,9 +38,16 @@ SELECT partmethod, repmodel FROM pg_dist_partition WHERE logicalrelid = 'foreign n | s (1 row) --- COPY FROM doesn't work for Citus foreign tables +-- COPY FROM for Citus foreign tables COPY foreign_table FROM stdin; -ERROR: cannot PREPARE a transaction that has operated on postgres_fdw foreign tables +SELECT * FROM foreign_table ORDER BY a; + id | data | a +--------------------------------------------------------------------- + 1 | text_test | 1 + 1 | 1foo | 2 +(2 rows) + +DELETE FROM foreign_table WHERE a = 2; CREATE TABLE parent_for_foreign_tables ( project_id integer ) PARTITION BY HASH (project_id); diff --git a/src/test/regress/sql/foreign_tables_mx.sql b/src/test/regress/sql/foreign_tables_mx.sql index bdef5a4c5..87a3618f7 100644 --- a/src/test/regress/sql/foreign_tables_mx.sql +++ b/src/test/regress/sql/foreign_tables_mx.sql @@ -37,11 +37,14 @@ CREATE FOREIGN TABLE foreign_table ( --verify SELECT partmethod, repmodel FROM pg_dist_partition WHERE logicalrelid = 'foreign_table'::regclass ORDER BY logicalrelid; --- COPY FROM doesn't work for Citus foreign tables +-- COPY FROM for Citus foreign tables COPY foreign_table FROM stdin; 1 1foo 2 \. +SELECT * FROM foreign_table ORDER BY a; +DELETE FROM foreign_table WHERE a = 2; + CREATE TABLE parent_for_foreign_tables ( project_id integer ) PARTITION BY HASH (project_id);