Merge pull request #4545 from citusdata/alter-into-same-access-method

Adds same access method check
pull/4544/head
Halil Ozan Akgül 2021-01-20 15:50:52 +03:00 committed by GitHub
commit 082899ffa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -455,6 +455,14 @@ AlterTableSetAccessMethod(TableConversionParameters *params)
params->conversionType = ALTER_TABLE_SET_ACCESS_METHOD; params->conversionType = ALTER_TABLE_SET_ACCESS_METHOD;
params->shardCountIsNull = true; params->shardCountIsNull = true;
TableConversionState *con = CreateTableConversion(params); TableConversionState *con = CreateTableConversion(params);
if (strcmp(con->originalAccessMethod, con->accessMethod) == 0)
{
ereport(ERROR, (errmsg("the access method of %s is already %s",
generate_qualified_relation_name(con->relationId),
con->accessMethod)));
}
return ConvertTable(con); return ConvertTable(con);
} }

View File

@ -455,6 +455,10 @@ NOTICE: Renaming the new table to alter_table_set_access_method.test_fk_p1
ERROR: Foreign keys and AFTER ROW triggers are not supported for columnar tables ERROR: Foreign keys and AFTER ROW triggers are not supported for columnar tables
HINT: Consider an AFTER STATEMENT trigger instead. HINT: Consider an AFTER STATEMENT trigger instead.
CONTEXT: SQL statement "ALTER TABLE alter_table_set_access_method.test_fk_p ATTACH PARTITION alter_table_set_access_method.test_fk_p1 FOR VALUES FROM (10) TO (20);" CONTEXT: SQL statement "ALTER TABLE alter_table_set_access_method.test_fk_p ATTACH PARTITION alter_table_set_access_method.test_fk_p1 FOR VALUES FROM (10) TO (20);"
-- test changing into same access method
CREATE TABLE same_access_method (a INT);
SELECT alter_table_set_access_method('same_access_method', 'heap');
ERROR: the access method of alter_table_set_access_method.same_access_method is already heap
SET client_min_messages TO WARNING; SET client_min_messages TO WARNING;
DROP SCHEMA alter_table_set_access_method CASCADE; DROP SCHEMA alter_table_set_access_method CASCADE;
SELECT 1 FROM master_remove_node('localhost', :master_port); SELECT 1 FROM master_remove_node('localhost', :master_port);

View File

@ -139,6 +139,10 @@ create table test_fk_p0 partition of test_fk_p for values from (0) to (10);
create table test_fk_p1 partition of test_fk_p for values from (10) to (20); create table test_fk_p1 partition of test_fk_p for values from (10) to (20);
select alter_table_set_access_method('test_fk_p1', 'columnar'); select alter_table_set_access_method('test_fk_p1', 'columnar');
-- test changing into same access method
CREATE TABLE same_access_method (a INT);
SELECT alter_table_set_access_method('same_access_method', 'heap');
SET client_min_messages TO WARNING; SET client_min_messages TO WARNING;
DROP SCHEMA alter_table_set_access_method CASCADE; DROP SCHEMA alter_table_set_access_method CASCADE;
SELECT 1 FROM master_remove_node('localhost', :master_port); SELECT 1 FROM master_remove_node('localhost', :master_port);