Prevent undistribute_table calls for foreign tables

pull/4279/head
Hanefi Önaldı 2020-10-30 13:52:22 +03:00
parent 5fcddfa2c6
commit 5db380f33a
No known key found for this signature in database
GPG Key ID: 45A2ACB84E394FBA
4 changed files with 37 additions and 1 deletions

View File

@ -1585,6 +1585,12 @@ UndistributeTable(Oid relationId)
"because a foreign key references to it.")));
}
char relationKind = get_rel_relkind(relationId);
if (relationKind == RELKIND_FOREIGN_TABLE)
{
ereport(ERROR, (errmsg("Cannot undistribute table "
"because it is a foreign table.")));
}
List *preLoadCommands = GetPreLoadTableCreationCommands(relationId, true);
List *postLoadCommands = GetPostLoadTableCreationCommands(relationId);

View File

@ -126,6 +126,22 @@ ERROR: Cannot undistribute table because a foreign key references to it.
SELECT undistribute_table('referencing_table');
ERROR: Cannot undistribute table because it has a foreign key.
DROP TABLE referenced_table, referencing_table;
-- test distributed foreign tables
-- we expect errors
CREATE FOREIGN TABLE foreign_table (
id bigint not null,
full_name text not null default ''
) SERVER fake_fdw_server OPTIONS (encoding 'utf-8', compression 'true');
SELECT create_distributed_table('foreign_table', 'id');
NOTICE: foreign-data wrapper "fake_fdw" does not have an extension defined
create_distributed_table
---------------------------------------------------------------------
(1 row)
SELECT undistribute_table('foreign_table');
ERROR: Cannot undistribute table because it is a foreign table.
DROP FOREIGN TABLE foreign_table;
-- test partitioned tables
CREATE TABLE partitioned_table (id INT, a INT) PARTITION BY RANGE (id);
CREATE TABLE partitioned_table_1_5 PARTITION OF partitioned_table FOR VALUES FROM (1) TO (5);

View File

@ -65,6 +65,10 @@ test: ensure_no_intermediate_data_leak
# ----------
test: multi_partitioning_utils multi_partitioning replicated_partitioned_table
# ----------
# Tests for foreign data wrapper support
# ----------
test: multi_create_fdw
# ----------
# Tests for recursive subquery planning
@ -199,7 +203,6 @@ test: multi_outer_join
# Note that the order of the following tests are important. multi_complex_count_distinct
# is independent from the rest of the group, it is added to increase parallelism.
# ---
test: multi_create_fdw
test: multi_complex_count_distinct multi_select_distinct
test: multi_modifications
test: multi_distribution_metadata

View File

@ -52,6 +52,17 @@ SELECT undistribute_table('referencing_table');
DROP TABLE referenced_table, referencing_table;
-- test distributed foreign tables
-- we expect errors
CREATE FOREIGN TABLE foreign_table (
id bigint not null,
full_name text not null default ''
) SERVER fake_fdw_server OPTIONS (encoding 'utf-8', compression 'true');
SELECT create_distributed_table('foreign_table', 'id');
SELECT undistribute_table('foreign_table');
DROP FOREIGN TABLE foreign_table;
-- test partitioned tables
CREATE TABLE partitioned_table (id INT, a INT) PARTITION BY RANGE (id);
CREATE TABLE partitioned_table_1_5 PARTITION OF partitioned_table FOR VALUES FROM (1) TO (5);