Don't use 2PC if COPY operates on a single shard

See discussion in:
https://github.com/citusdata/citus/pull/7160#discussion_r1314488889
naisila/single_shard_copy
naisila 2023-09-07 12:42:52 +03:00 committed by Naisila Puka
parent 8894c76ec0
commit 6e19d7ba5a
3 changed files with 19 additions and 5 deletions

View File

@ -2048,8 +2048,12 @@ CitusCopyDestReceiverStartup(DestReceiver *dest, int operation,
UseCoordinatedTransaction();
/* all modifications use 2PC */
/* 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));

View File

@ -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);

View File

@ -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);