From 4def1ca696f7d73e56975caf3563734b7b7f68d2 Mon Sep 17 00:00:00 2001 From: Eren Basak Date: Wed, 18 Jan 2017 17:38:01 +0300 Subject: [PATCH] Prevent COPY to reference tables from worker nodes --- src/backend/distributed/commands/multi_copy.c | 6 ++++++ .../expected/multi_unsupported_worker_operations.out | 5 ++++- .../regress/sql/multi_unsupported_worker_operations.sql | 3 ++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/backend/distributed/commands/multi_copy.c b/src/backend/distributed/commands/multi_copy.c index b5bafb40c..7345d18f5 100644 --- a/src/backend/distributed/commands/multi_copy.c +++ b/src/backend/distributed/commands/multi_copy.c @@ -400,6 +400,12 @@ CopyToExistingShards(CopyStmt *copyStatement, char *completionTag) columnValues = palloc0(columnCount * sizeof(Datum)); columnNulls = palloc0(columnCount * sizeof(bool)); + /* we don't support copy to reference tables from workers */ + if (partitionMethod == DISTRIBUTE_BY_NONE) + { + EnsureSchemaNode(); + } + /* load the list of shards and verify that we have shards to copy into */ shardIntervalList = LoadShardIntervalList(tableId); if (shardIntervalList == NIL) diff --git a/src/test/regress/expected/multi_unsupported_worker_operations.out b/src/test/regress/expected/multi_unsupported_worker_operations.out index cdb343e7e..aea3b2b89 100644 --- a/src/test/regress/expected/multi_unsupported_worker_operations.out +++ b/src/test/regress/expected/multi_unsupported_worker_operations.out @@ -108,7 +108,7 @@ SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='mx_table'::regclass; 5 (1 row) --- INSERT/UPDATE/DELETE on reference tables +-- INSERT/UPDATE/DELETE/COPY on reference tables SELECT * FROM mx_ref_table ORDER BY col_1; col_1 | col_2 -------+-------- @@ -126,6 +126,9 @@ DETAIL: Modifications to reference tables are supported only from the schema no DELETE FROM mx_ref_table WHERE col_1 = -78; ERROR: cannot perform distributed planning for the given modification DETAIL: Modifications to reference tables are supported only from the schema node. +COPY mx_ref_table (col_1, col_2) FROM STDIN WITH (FORMAT 'csv'); +ERROR: operation is not allowed on this node +HINT: Connect to the schema node and run it again. SELECT * FROM mx_ref_table ORDER BY col_1; col_1 | col_2 -------+-------- diff --git a/src/test/regress/sql/multi_unsupported_worker_operations.sql b/src/test/regress/sql/multi_unsupported_worker_operations.sql index c171ce359..ceac8b0f4 100644 --- a/src/test/regress/sql/multi_unsupported_worker_operations.sql +++ b/src/test/regress/sql/multi_unsupported_worker_operations.sql @@ -80,11 +80,12 @@ INSERT INTO pg_dist_shard SELECT * FROM pg_dist_shard_temp; SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='mx_table'::regclass; --- INSERT/UPDATE/DELETE on reference tables +-- INSERT/UPDATE/DELETE/COPY on reference tables SELECT * FROM mx_ref_table ORDER BY col_1; INSERT INTO mx_ref_table (col_1, col_2) VALUES (-6, 'vestibulum'); UPDATE mx_ref_table SET col_2 = 'habitant' WHERE col_1 = -37; DELETE FROM mx_ref_table WHERE col_1 = -78; +COPY mx_ref_table (col_1, col_2) FROM STDIN WITH (FORMAT 'csv'); SELECT * FROM mx_ref_table ORDER BY col_1; \c - - - :master_port