diff --git a/src/backend/distributed/commands/alter_table.c b/src/backend/distributed/commands/alter_table.c index 7a7f7f151..52dc23a51 100644 --- a/src/backend/distributed/commands/alter_table.c +++ b/src/backend/distributed/commands/alter_table.c @@ -162,6 +162,12 @@ typedef struct TableConversionState * ALTER_TABLE_SET_ACCESS_METHOD -> AlterTableSetAccessMethod */ TableConversionFunction function; + + /* + * suppressNoticeMessages determines if we want to suppress NOTICE + * messages that we explicitly issue + */ + bool suppressNoticeMessages; } TableConversionState; @@ -177,7 +183,8 @@ static TableConversionState * CreateTableConversion(TableConversionParameters *p static void CreateDistributedTableLike(TableConversionState *con); static void CreateCitusTableLike(TableConversionState *con); static List * GetViewCreationCommandsOfTable(Oid relationId); -static void ReplaceTable(Oid sourceId, Oid targetId, List *justBeforeDropCommands); +static void ReplaceTable(Oid sourceId, Oid targetId, List *justBeforeDropCommands, + bool suppressNoticeMessages); static void CheckAlterDistributedTableConversionParameters(TableConversionState *con); static char * CreateWorkerChangeSequenceDependencyCommand(char *sequenceSchemaName, char *sequenceName, @@ -522,15 +529,18 @@ ConvertTable(TableConversionState *con) bool includeIndexes = true; if (con->accessMethod && strcmp(con->accessMethod, "columnar") == 0) { - List *explicitIndexesOnTable = GetExplicitIndexOidList(con->relationId); - Oid indexOid = InvalidOid; - foreach_oid(indexOid, explicitIndexesOnTable) + if (!con->suppressNoticeMessages) { - ereport(NOTICE, (errmsg("the index %s on table %s will be dropped, " - "because columnar tables cannot have indexes", - get_rel_name(indexOid), - quote_qualified_identifier(con->schemaName, - con->relationName)))); + List *explicitIndexesOnTable = GetExplicitIndexOidList(con->relationId); + Oid indexOid = InvalidOid; + foreach_oid(indexOid, explicitIndexesOnTable) + { + ereport(NOTICE, (errmsg("the index %s on table %s will be dropped, " + "because columnar tables cannot have indexes", + get_rel_name(indexOid), + quote_qualified_identifier(con->schemaName, + con->relationName)))); + } } includeIndexes = false; @@ -580,9 +590,12 @@ ConvertTable(TableConversionState *con) if (PartitionedTable(con->relationId)) { - ereport(NOTICE, (errmsg("converting the partitions of %s", - quote_qualified_identifier(con->schemaName, - con->relationName)))); + if (!con->suppressNoticeMessages) + { + ereport(NOTICE, (errmsg("converting the partitions of %s", + quote_qualified_identifier(con->schemaName, + con->relationName)))); + } List *partitionList = PartitionList(con->relationId); @@ -617,6 +630,7 @@ ConvertTable(TableConversionState *con) .shardCount = con->shardCount, .cascadeToColocated = cascadeOption, .colocateWith = con->colocateWith, + .suppressNoticeMessages = con->suppressNoticeMessages, /* * Even if we called UndistributeTable with cascade option, we @@ -636,9 +650,12 @@ ConvertTable(TableConversionState *con) } } - ereport(NOTICE, (errmsg("creating a new table for %s", - quote_qualified_identifier(con->schemaName, - con->relationName)))); + if (!con->suppressNoticeMessages) + { + ereport(NOTICE, (errmsg("creating a new table for %s", + quote_qualified_identifier(con->schemaName, + con->relationName)))); + } TableDDLCommand *tableCreationCommand = NULL; foreach_ptr(tableCreationCommand, preLoadCommands) @@ -687,7 +704,8 @@ ConvertTable(TableConversionState *con) CreateCitusTableLike(con); } - ReplaceTable(con->relationId, con->newRelationId, justBeforeDropCommands); + ReplaceTable(con->relationId, con->newRelationId, justBeforeDropCommands, + con->suppressNoticeMessages); TableDDLCommand *tableConstructionCommand = NULL; foreach_ptr(tableConstructionCommand, postLoadCommands) @@ -732,7 +750,8 @@ ConvertTable(TableConversionState *con) .shardCountIsNull = con->shardCountIsNull, .shardCount = con->shardCount, .colocateWith = qualifiedRelationName, - .cascadeToColocated = CASCADE_TO_COLOCATED_NO_ALREADY_CASCADED + .cascadeToColocated = CASCADE_TO_COLOCATED_NO_ALREADY_CASCADED, + .suppressNoticeMessages = con->suppressNoticeMessages }; TableConversionReturn *colocatedReturn = con->function(&cascadeParam); foreignKeyCommands = list_concat(foreignKeyCommands, @@ -875,6 +894,7 @@ CreateTableConversion(TableConversionParameters *params) con->accessMethod = params->accessMethod; con->cascadeToColocated = params->cascadeToColocated; con->cascadeViaForeignKeys = params->cascadeViaForeignKeys; + con->suppressNoticeMessages = params->suppressNoticeMessages; Relation relation = try_relation_open(con->relationId, ExclusiveLock); if (relation == NULL) @@ -1076,7 +1096,8 @@ GetViewCreationCommandsOfTable(Oid relationId) * Source and target tables need to be in the same schema and have the same columns. */ void -ReplaceTable(Oid sourceId, Oid targetId, List *justBeforeDropCommands) +ReplaceTable(Oid sourceId, Oid targetId, List *justBeforeDropCommands, + bool suppressNoticeMessages) { char *sourceName = get_rel_name(sourceId); char *targetName = get_rel_name(targetId); @@ -1087,8 +1108,11 @@ ReplaceTable(Oid sourceId, Oid targetId, List *justBeforeDropCommands) if (!PartitionedTable(sourceId)) { - ereport(NOTICE, (errmsg("Moving the data of %s", - quote_qualified_identifier(schemaName, sourceName)))); + if (!suppressNoticeMessages) + { + ereport(NOTICE, (errmsg("Moving the data of %s", + quote_qualified_identifier(schemaName, sourceName)))); + } appendStringInfo(query, "INSERT INTO %s SELECT * FROM %s", quote_qualified_identifier(schemaName, targetName), @@ -1126,16 +1150,22 @@ ReplaceTable(Oid sourceId, Oid targetId, List *justBeforeDropCommands) ExecuteQueryViaSPI(justBeforeDropCommand, SPI_OK_UTILITY); } - ereport(NOTICE, (errmsg("Dropping the old %s", - quote_qualified_identifier(schemaName, sourceName)))); + if (!suppressNoticeMessages) + { + ereport(NOTICE, (errmsg("Dropping the old %s", + quote_qualified_identifier(schemaName, sourceName)))); + } resetStringInfo(query); appendStringInfo(query, "DROP TABLE %s CASCADE", quote_qualified_identifier(schemaName, sourceName)); ExecuteQueryViaSPI(query->data, SPI_OK_UTILITY); - ereport(NOTICE, (errmsg("Renaming the new table to %s", - quote_qualified_identifier(schemaName, sourceName)))); + if (!suppressNoticeMessages) + { + ereport(NOTICE, (errmsg("Renaming the new table to %s", + quote_qualified_identifier(schemaName, sourceName)))); + } resetStringInfo(query); appendStringInfo(query, "ALTER TABLE %s RENAME TO %s", @@ -1309,23 +1339,26 @@ CheckAlterDistributedTableConversionParameters(TableConversionState *con) } } - /* Notices for no operation UDF calls */ - if (sameDistColumn) + if (!con->suppressNoticeMessages) { - ereport(NOTICE, (errmsg("table is already distributed by %s", - con->distributionColumn))); - } + /* Notices for no operation UDF calls */ + if (sameDistColumn) + { + ereport(NOTICE, (errmsg("table is already distributed by %s", + con->distributionColumn))); + } - if (sameShardCount) - { - ereport(NOTICE, (errmsg("shard count of the table is already %d", - con->shardCount))); - } + if (sameShardCount) + { + ereport(NOTICE, (errmsg("shard count of the table is already %d", + con->shardCount))); + } - if (sameColocateWith) - { - ereport(NOTICE, (errmsg("table is already colocated with %s", - con->colocateWith))); + if (sameColocateWith) + { + ereport(NOTICE, (errmsg("table is already colocated with %s", + con->colocateWith))); + } } } diff --git a/src/backend/distributed/commands/create_distributed_table.c b/src/backend/distributed/commands/create_distributed_table.c index 864056c37..e852aa8e3 100644 --- a/src/backend/distributed/commands/create_distributed_table.c +++ b/src/backend/distributed/commands/create_distributed_table.c @@ -558,9 +558,11 @@ DropFKeysAndUndistributeTable(Oid relationId) char *relationName = get_rel_name(relationId); Oid schemaId = get_rel_namespace(relationId); + /* suppress notices messages not to be too verbose */ TableConversionParameters params = { .relationId = relationId, - .cascadeViaForeignKeys = false + .cascadeViaForeignKeys = false, + .suppressNoticeMessages = true }; UndistributeTable(¶ms); diff --git a/src/backend/distributed/commands/utility_hook.c b/src/backend/distributed/commands/utility_hook.c index 9fe4985d8..77c225495 100644 --- a/src/backend/distributed/commands/utility_hook.c +++ b/src/backend/distributed/commands/utility_hook.c @@ -729,10 +729,18 @@ UndistributeDisconnectedCitusLocalTables(void) * undistribute it via cascade. Here, instead of first dropping foreing * keys then undistributing the table, we just set cascadeViaForeignKeys * to true for simplicity. + * + * We suppress notices messages not to be too verbose. On the other hand, + * as UndistributeTable moves data to a new table, we want to inform user + * as it might take some time. */ + ereport(NOTICE, (errmsg("removing table %s from metadata as it is not " + "connected to any reference tables via foreign keys", + generate_qualified_relation_name(citusLocalTableId)))); TableConversionParameters params = { .relationId = citusLocalTableId, - .cascadeViaForeignKeys = true + .cascadeViaForeignKeys = true, + .suppressNoticeMessages = true }; UndistributeTable(¶ms); } diff --git a/src/include/distributed/metadata_utility.h b/src/include/distributed/metadata_utility.h index 452b2bd22..96db653d0 100644 --- a/src/include/distributed/metadata_utility.h +++ b/src/include/distributed/metadata_utility.h @@ -153,6 +153,12 @@ typedef struct TableConversionParameters * to the table */ bool cascadeViaForeignKeys; + + /* + * suppressNoticeMessages determines if we want to suppress NOTICE + * messages that we explicitly issue + */ + bool suppressNoticeMessages; } TableConversionParameters; typedef struct TableConversionReturn diff --git a/src/test/regress/expected/ref_citus_local_fkeys.out b/src/test/regress/expected/ref_citus_local_fkeys.out index a0b77bcee..80f6c78a6 100644 --- a/src/test/regress/expected/ref_citus_local_fkeys.out +++ b/src/test/regress/expected/ref_citus_local_fkeys.out @@ -52,12 +52,9 @@ NOTICE: executing the command locally: SELECT l1 FROM ref_citus_local_fkeys.cit -- show that we support drop constraint ALTER TABLE citus_local_table DROP CONSTRAINT fkey_local_to_ref; NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1506000, 'ref_citus_local_fkeys', 1506001, 'ref_citus_local_fkeys', 'ALTER TABLE citus_local_table DROP CONSTRAINT fkey_local_to_ref;') -NOTICE: creating a new table for ref_citus_local_fkeys.citus_local_table -NOTICE: Moving the data of ref_citus_local_fkeys.citus_local_table +NOTICE: removing table ref_citus_local_fkeys.citus_local_table from metadata as it is not connected to any reference tables via foreign keys NOTICE: executing the command locally: SELECT l1 FROM ref_citus_local_fkeys.citus_local_table_1506000 citus_local_table -NOTICE: Dropping the old ref_citus_local_fkeys.citus_local_table NOTICE: executing the command locally: DROP TABLE IF EXISTS ref_citus_local_fkeys.citus_local_table_xxxxx CASCADE -NOTICE: Renaming the new table to ref_citus_local_fkeys.citus_local_table -- we support ON UPDATE CASCADE behaviour in "ALTER TABLE ADD fkey citus_local_table (to reference table)" commands ALTER TABLE citus_local_table ADD CONSTRAINT fkey_local_to_ref FOREIGN KEY(l1) REFERENCES reference_table(r1) ON UPDATE CASCADE; NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1506002, 'ref_citus_local_fkeys', 1506001, 'ref_citus_local_fkeys', 'ALTER TABLE citus_local_table ADD CONSTRAINT fkey_local_to_ref FOREIGN KEY(l1) REFERENCES reference_table(r1) ON UPDATE CASCADE;') @@ -79,12 +76,9 @@ NOTICE: executing the command locally: SELECT l1 FROM ref_citus_local_fkeys.cit -- drop constraint for next commands ALTER TABLE citus_local_table DROP CONSTRAINT fkey_local_to_ref; NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1506002, 'ref_citus_local_fkeys', 1506001, 'ref_citus_local_fkeys', 'ALTER TABLE citus_local_table DROP CONSTRAINT fkey_local_to_ref;') -NOTICE: creating a new table for ref_citus_local_fkeys.citus_local_table -NOTICE: Moving the data of ref_citus_local_fkeys.citus_local_table +NOTICE: removing table ref_citus_local_fkeys.citus_local_table from metadata as it is not connected to any reference tables via foreign keys NOTICE: executing the command locally: SELECT l1 FROM ref_citus_local_fkeys.citus_local_table_1506002 citus_local_table -NOTICE: Dropping the old ref_citus_local_fkeys.citus_local_table NOTICE: executing the command locally: DROP TABLE IF EXISTS ref_citus_local_fkeys.citus_local_table_xxxxx CASCADE -NOTICE: Renaming the new table to ref_citus_local_fkeys.citus_local_table INSERT INTO citus_local_table VALUES (2); -- show that we are checking for foreign key constraint while defining, below should fail ALTER TABLE citus_local_table ADD CONSTRAINT fkey_local_to_ref FOREIGN KEY(l1) REFERENCES reference_table(r1); @@ -107,12 +101,9 @@ NOTICE: executing the command locally: INSERT INTO ref_citus_local_fkeys.citus_ -- drop and add constraint for next commands ALTER TABLE citus_local_table DROP CONSTRAINT fkey_local_to_ref; NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1506004, 'ref_citus_local_fkeys', 1506001, 'ref_citus_local_fkeys', 'ALTER TABLE citus_local_table DROP CONSTRAINT fkey_local_to_ref;') -NOTICE: creating a new table for ref_citus_local_fkeys.citus_local_table -NOTICE: Moving the data of ref_citus_local_fkeys.citus_local_table +NOTICE: removing table ref_citus_local_fkeys.citus_local_table from metadata as it is not connected to any reference tables via foreign keys NOTICE: executing the command locally: SELECT l1 FROM ref_citus_local_fkeys.citus_local_table_1506004 citus_local_table -NOTICE: Dropping the old ref_citus_local_fkeys.citus_local_table NOTICE: executing the command locally: DROP TABLE IF EXISTS ref_citus_local_fkeys.citus_local_table_xxxxx CASCADE -NOTICE: Renaming the new table to ref_citus_local_fkeys.citus_local_table ALTER TABLE citus_local_table ADD CONSTRAINT fkey_local_to_ref FOREIGN KEY(l1) REFERENCES reference_table(r1); NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1506005, 'ref_citus_local_fkeys', 1506001, 'ref_citus_local_fkeys', 'ALTER TABLE citus_local_table ADD CONSTRAINT fkey_local_to_ref FOREIGN KEY(l1) REFERENCES reference_table(r1);') -- show that drop table without CASCADE errors out @@ -124,12 +115,9 @@ BEGIN; NOTICE: drop cascades to constraint fkey_local_to_ref on table citus_local_table NOTICE: executing the command locally: DROP TABLE IF EXISTS ref_citus_local_fkeys.reference_table_xxxxx CASCADE NOTICE: drop cascades to constraint fkey_local_to_ref_1506005 on table ref_citus_local_fkeys.citus_local_table_1506005 -NOTICE: creating a new table for ref_citus_local_fkeys.citus_local_table -NOTICE: Moving the data of ref_citus_local_fkeys.citus_local_table +NOTICE: removing table ref_citus_local_fkeys.citus_local_table from metadata as it is not connected to any reference tables via foreign keys NOTICE: executing the command locally: SELECT l1 FROM ref_citus_local_fkeys.citus_local_table_1506005 citus_local_table -NOTICE: Dropping the old ref_citus_local_fkeys.citus_local_table NOTICE: executing the command locally: DROP TABLE IF EXISTS ref_citus_local_fkeys.citus_local_table_xxxxx CASCADE -NOTICE: Renaming the new table to ref_citus_local_fkeys.citus_local_table ROLLBACK; -- drop tables finally DROP TABLE citus_local_table, reference_table; @@ -196,10 +184,7 @@ NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_comm -- tables works fine with remote execution too SET citus.enable_local_execution TO OFF; ALTER TABLE reference_table DROP CONSTRAINT fkey_ref_to_local; -NOTICE: creating a new table for ref_citus_local_fkeys.citus_local_table -NOTICE: Moving the data of ref_citus_local_fkeys.citus_local_table -NOTICE: Dropping the old ref_citus_local_fkeys.citus_local_table -NOTICE: Renaming the new table to ref_citus_local_fkeys.citus_local_table +NOTICE: removing table ref_citus_local_fkeys.citus_local_table from metadata as it is not connected to any reference tables via foreign keys ALTER TABLE reference_table ADD CONSTRAINT fkey_ref_to_local FOREIGN KEY(r1) REFERENCES citus_local_table(l1) ON DELETE NO ACTION; ERROR: cannot execute command because a local execution has accessed a placement in the transaction SET citus.enable_local_execution TO ON; @@ -223,12 +208,9 @@ NOTICE: Replicating reference table "reference_table" to the node localhost:xxx BEGIN; ALTER TABLE reference_table DROP CONSTRAINT fkey_ref_to_local; NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1506007, 'ref_citus_local_fkeys', 1506009, 'ref_citus_local_fkeys', 'ALTER TABLE reference_table DROP CONSTRAINT fkey_ref_to_local;') -NOTICE: creating a new table for ref_citus_local_fkeys.citus_local_table -NOTICE: Moving the data of ref_citus_local_fkeys.citus_local_table +NOTICE: removing table ref_citus_local_fkeys.citus_local_table from metadata as it is not connected to any reference tables via foreign keys NOTICE: executing the command locally: SELECT l1 FROM ref_citus_local_fkeys.citus_local_table_1506009 citus_local_table -NOTICE: Dropping the old ref_citus_local_fkeys.citus_local_table NOTICE: executing the command locally: DROP TABLE IF EXISTS ref_citus_local_fkeys.citus_local_table_xxxxx CASCADE -NOTICE: Renaming the new table to ref_citus_local_fkeys.citus_local_table ROLLBACK; -- show that drop table errors as expected DROP TABLE citus_local_table;