Prevent undistribute_table calls for partitions

pull/4286/head
Hanefi Önaldı 2020-11-02 13:48:08 +03:00
parent feca381500
commit 85a4b61a0e
No known key found for this signature in database
GPG Key ID: 45A2ACB84E394FBA
3 changed files with 18 additions and 0 deletions

View File

@ -1592,6 +1592,16 @@ UndistributeTable(Oid relationId)
"because it is a foreign table.")));
}
if (PartitionTable(relationId))
{
Oid parentRelationId = PartitionParentOid(relationId);
char *parentRelationName = get_rel_name(parentRelationId);
ereport(ERROR, (errmsg("Cannot undistribute table "
"because it is a partition."),
errhint("Undistribute the partitioned table \"%s\" instead.",
parentRelationName)));
}
List *preLoadCommands = GetPreLoadTableCreationCommands(relationId, true);
List *postLoadCommands = GetPostLoadTableCreationCommands(relationId);

View File

@ -194,6 +194,11 @@ SELECT * FROM partitioned_table_6_10 ORDER BY 1, 2;
7 | 2
(1 row)
-- undistributing partitions are not supported
SELECT undistribute_table('partitioned_table_1_5');
ERROR: Cannot undistribute table because it is a partition.
HINT: Undistribute the partitioned table "partitioned_table" instead.
-- we can undistribute partitioned parent tables
SELECT undistribute_table('partitioned_table');
NOTICE: Undistributing the partitions of undistribute_table.partitioned_table
NOTICE: Creating a new local table for undistribute_table.partitioned_table_1_5

View File

@ -77,6 +77,9 @@ SELECT * FROM partitioned_table ORDER BY 1, 2;
SELECT * FROM partitioned_table_1_5 ORDER BY 1, 2;
SELECT * FROM partitioned_table_6_10 ORDER BY 1, 2;
-- undistributing partitions are not supported
SELECT undistribute_table('partitioned_table_1_5');
-- we can undistribute partitioned parent tables
SELECT undistribute_table('partitioned_table');
SELECT logicalrelid FROM pg_dist_partition WHERE logicalrelid::regclass::text LIKE 'partitioned\_table%' ORDER BY 1;