diff --git a/src/backend/distributed/commands/alter_table.c b/src/backend/distributed/commands/alter_table.c index 8ff77bdc6..b7e7c5f7a 100644 --- a/src/backend/distributed/commands/alter_table.c +++ b/src/backend/distributed/commands/alter_table.c @@ -399,11 +399,12 @@ UndistributeTable(TableConversionParameters *params) ErrorIfUnsupportedCascadeObjects(params->relationId); - ErrorIfTableHasIdentityColumn(params->relationId); - params->conversionType = UNDISTRIBUTE_TABLE; params->shardCountIsNull = true; TableConversionState *con = CreateTableConversion(params); + + ErrorIfTableHasIdentityColumn(params->relationId); + return ConvertTable(con); } diff --git a/src/backend/distributed/commands/create_distributed_table.c b/src/backend/distributed/commands/create_distributed_table.c index 1229f1592..f14567f97 100644 --- a/src/backend/distributed/commands/create_distributed_table.c +++ b/src/backend/distributed/commands/create_distributed_table.c @@ -304,8 +304,6 @@ create_distributed_table_concurrently(PG_FUNCTION_ARGS) shardCountIsStrict = true; } - ErrorIfTableHasUnsupportedIdentityColumn(relationId); - CreateDistributedTableConcurrently(relationId, distributionColumnName, distributionMethod, colocateWithTableName, @@ -434,6 +432,8 @@ CreateDistributedTableConcurrently(Oid relationId, char *distributionColumnName, WarnIfTableHaveNoReplicaIdentity(relationId); + ErrorIfTableHasUnsupportedIdentityColumn(relationId); + List *shardList = LoadShardIntervalList(relationId); /* diff --git a/src/backend/distributed/commands/table.c b/src/backend/distributed/commands/table.c index 8ecdbdd69..5f6467765 100644 --- a/src/backend/distributed/commands/table.c +++ b/src/backend/distributed/commands/table.c @@ -3981,7 +3981,7 @@ ErrorIfTableHasUnsupportedIdentityColumn(Oid relationId) { Relation relation = relation_open(relationId, AccessShareLock); TupleDesc tupleDescriptor = RelationGetDescr(relation); - relation_close(relation, NoLock); + relation_close(relation, AccessShareLock); for (int attributeIndex = 0; attributeIndex < tupleDescriptor->natts; attributeIndex++) diff --git a/src/test/regress/expected/generated_identity.out b/src/test/regress/expected/generated_identity.out index 9f3d478ae..4d21d3e68 100644 --- a/src/test/regress/expected/generated_identity.out +++ b/src/test/regress/expected/generated_identity.out @@ -1,6 +1,7 @@ CREATE SCHEMA generated_identities; SET search_path TO generated_identities; SET client_min_messages to ERROR; +SET citus.shard_replication_factor TO 1; SELECT 1 from citus_add_node('localhost', :master_port, groupId=>0); ?column? --------------------------------------------------------------------- @@ -13,6 +14,8 @@ CREATE TABLE smallint_identity_column ( ); SELECT create_distributed_table('smallint_identity_column', 'a'); ERROR: cannot complete operation on a table with smallint/int identity column +SELECT create_distributed_table_concurrently('smallint_identity_column', 'a'); +ERROR: cannot complete operation on a table with smallint/int identity column SELECT create_reference_table('smallint_identity_column'); ERROR: cannot complete operation on a table with smallint/int identity column SELECT citus_add_local_table_to_metadata('smallint_identity_column'); @@ -28,6 +31,8 @@ CREATE TABLE int_identity_column ( ); SELECT create_distributed_table('int_identity_column', 'a'); ERROR: cannot complete operation on a table with smallint/int identity column +SELECT create_distributed_table_concurrently('int_identity_column', 'a'); +ERROR: cannot complete operation on a table with smallint/int identity column SELECT create_reference_table('int_identity_column'); ERROR: cannot complete operation on a table with smallint/int identity column SELECT citus_add_local_table_to_metadata('int_identity_column'); @@ -37,6 +42,7 @@ SELECT citus_add_local_table_to_metadata('int_identity_column'); (1 row) DROP TABLE int_identity_column; +RESET citus.shard_replication_factor; CREATE TABLE bigint_identity_column ( a bigint GENERATED BY DEFAULT AS IDENTITY, b int @@ -161,10 +167,6 @@ SET search_path TO generated_identities; SET client_min_messages to ERROR; INSERT INTO partitioned_table (c) SELECT s FROM generate_series(10,20) s; -INSERT INTO partitioned_table (a,b,c) VALUES (997,997,997); -ERROR: cannot insert a non-DEFAULT value into column "b" -DETAIL: Column "b" is an identity column defined as GENERATED ALWAYS. -HINT: Use OVERRIDING SYSTEM VALUE to override. INSERT INTO partitioned_table (a,c) VALUES (998,998); INSERT INTO partitioned_table (a,b,c) OVERRIDING SYSTEM VALUE VALUES (999,999,999); SELECT * FROM partitioned_table ORDER BY c ASC; @@ -283,17 +285,19 @@ SELECT * FROM reference_table ORDER BY c ASC; (20 rows) DROP TABLE reference_table; --- https://github.com/citusdata/citus/issues/6694 CREATE TABLE color ( color_id BIGINT GENERATED ALWAYS AS IDENTITY UNIQUE, color_name VARCHAR NOT NULL ); -SELECT create_distributed_table('color', 'color_id'); - create_distributed_table +SET citus.shard_replication_factor TO 1; +SELECT create_distributed_table_concurrently('color', 'color_id'); + create_distributed_table_concurrently --------------------------------------------------------------------- (1 row) +RESET citus.shard_replication_factor; +-- https://github.com/citusdata/citus/issues/6694 CREATE USER identity_test_user; GRANT INSERT ON color TO identity_test_user; GRANT USAGE ON SCHEMA generated_identities TO identity_test_user; diff --git a/src/test/regress/expected/multi_extension.out b/src/test/regress/expected/multi_extension.out index 092ec9e5c..9c8e3e270 100644 --- a/src/test/regress/expected/multi_extension.out +++ b/src/test/regress/expected/multi_extension.out @@ -1323,9 +1323,10 @@ SELECT * FROM multi_extension.print_extension_changes(); -- Snapshot of state at 11.3-1 ALTER EXTENSION citus UPDATE TO '11.3-1'; SELECT * FROM multi_extension.print_extension_changes(); - previous_object | current_object + previous_object | current_object --------------------------------------------------------------------- -(0 rows) + | function worker_modify_identity_columns(regclass) void +(1 row) DROP TABLE multi_extension.prev_objects, multi_extension.extension_diff; -- show running version diff --git a/src/test/regress/sql/generated_identity.sql b/src/test/regress/sql/generated_identity.sql index c731ad30c..e1fbecd44 100644 --- a/src/test/regress/sql/generated_identity.sql +++ b/src/test/regress/sql/generated_identity.sql @@ -1,6 +1,7 @@ CREATE SCHEMA generated_identities; SET search_path TO generated_identities; SET client_min_messages to ERROR; +SET citus.shard_replication_factor TO 1; SELECT 1 from citus_add_node('localhost', :master_port, groupId=>0); @@ -9,6 +10,7 @@ CREATE TABLE smallint_identity_column ( a smallint GENERATED BY DEFAULT AS IDENTITY ); SELECT create_distributed_table('smallint_identity_column', 'a'); +SELECT create_distributed_table_concurrently('smallint_identity_column', 'a'); SELECT create_reference_table('smallint_identity_column'); SELECT citus_add_local_table_to_metadata('smallint_identity_column'); @@ -19,9 +21,12 @@ CREATE TABLE int_identity_column ( a int GENERATED BY DEFAULT AS IDENTITY ); SELECT create_distributed_table('int_identity_column', 'a'); +SELECT create_distributed_table_concurrently('int_identity_column', 'a'); SELECT create_reference_table('int_identity_column'); SELECT citus_add_local_table_to_metadata('int_identity_column'); DROP TABLE int_identity_column; +RESET citus.shard_replication_factor; + CREATE TABLE bigint_identity_column ( a bigint GENERATED BY DEFAULT AS IDENTITY, @@ -98,8 +103,6 @@ SET client_min_messages to ERROR; INSERT INTO partitioned_table (c) SELECT s FROM generate_series(10,20) s; -INSERT INTO partitioned_table (a,b,c) VALUES (997,997,997); - INSERT INTO partitioned_table (a,c) VALUES (998,998); INSERT INTO partitioned_table (a,b,c) OVERRIDING SYSTEM VALUE VALUES (999,999,999); @@ -147,13 +150,15 @@ SELECT * FROM reference_table ORDER BY c ASC; DROP TABLE reference_table; --- https://github.com/citusdata/citus/issues/6694 CREATE TABLE color ( color_id BIGINT GENERATED ALWAYS AS IDENTITY UNIQUE, color_name VARCHAR NOT NULL ); -SELECT create_distributed_table('color', 'color_id'); +SET citus.shard_replication_factor TO 1; +SELECT create_distributed_table_concurrently('color', 'color_id'); +RESET citus.shard_replication_factor; +-- https://github.com/citusdata/citus/issues/6694 CREATE USER identity_test_user; GRANT INSERT ON color TO identity_test_user; GRANT USAGE ON SCHEMA generated_identities TO identity_test_user;