Improve error/hint messages related to schema-based sharding (#7027)

Improve error/hint messages related to schema-based sharding
pull/6943/head
Ahmet Gedemenli 2023-06-22 18:10:12 +03:00 committed by GitHub
parent 44e3c3b9c6
commit 99edb2675f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 28 deletions

View File

@ -457,7 +457,8 @@ EnsureUndistributeTenantTableSafe(Oid relationId, const char *operationName)
ereport(ERROR, (errmsg("%s is not allowed for partition table %s in distributed " ereport(ERROR, (errmsg("%s is not allowed for partition table %s in distributed "
"schema %s", operationName, tableName, schemaName), "schema %s", operationName, tableName, schemaName),
errdetail("partition table should be under the same distributed " errdetail("partition table should be under the same distributed "
"schema as its parent and be a tenant table."))); "schema as its parent and be a "
"distributed schema table.")));
} }
/* /*

View File

@ -237,8 +237,8 @@ PostprocessCreateTableStmt(CreateStmt *createStatement, const char *queryString)
{ {
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot create a tenant table by using CREATE TABLE " errmsg("cannot create tables in a distributed schema using "
"OF syntax"))); "CREATE TABLE OF syntax")));
} }
if (createStatement->inhRelations != NIL) if (createStatement->inhRelations != NIL)
@ -254,8 +254,8 @@ PostprocessCreateTableStmt(CreateStmt *createStatement, const char *queryString)
if (IsTenantSchema(schemaId)) if (IsTenantSchema(schemaId))
{ {
ereport(ERROR, (errmsg("tenant tables cannot inherit or " ereport(ERROR, (errmsg("tables in a distributed schema cannot inherit "
"be inherited"))); "or be inherited")));
} }
RangeVar *parentRelation = NULL; RangeVar *parentRelation = NULL;
@ -272,8 +272,8 @@ PostprocessCreateTableStmt(CreateStmt *createStatement, const char *queryString)
*/ */
if (IsTenantSchema(get_rel_namespace(parentRelationId))) if (IsTenantSchema(get_rel_namespace(parentRelationId)))
{ {
ereport(ERROR, (errmsg("tenant tables cannot inherit or " ereport(ERROR, (errmsg("tables in a distributed schema cannot "
"be inherited"))); "inherit or be inherited")));
} }
else if (IsCitusTable(parentRelationId)) else if (IsCitusTable(parentRelationId))
{ {
@ -4257,8 +4257,8 @@ ConvertToTenantTableIfNecessary(AlterObjectSchemaStmt *stmt)
char *schemaName = get_namespace_name(schemaId); char *schemaName = get_namespace_name(schemaId);
char *tableName = stmt->relation->relname; char *tableName = stmt->relation->relname;
ereport(NOTICE, (errmsg("converting table %s to a tenant table in distributed " ereport(NOTICE, (errmsg("Moving %s into distributed schema %s",
"schema %s", tableName, schemaName))); tableName, schemaName)));
CreateTenantSchemaTable(relationId); CreateTenantSchemaTable(relationId);
} }

View File

@ -1446,11 +1446,11 @@ EnsureTableCanBeColocatedWith(Oid relationId, char replicationModel,
ereport(ERROR, (errmsg("cannot colocate tables %s and %s", ereport(ERROR, (errmsg("cannot colocate tables %s and %s",
sourceRelationName, relationName), sourceRelationName, relationName),
errdetail("Cannot colocate tables with tenant tables " errdetail("Cannot colocate tables with distributed schema tables"
"by using colocate_with option."), " by using colocate_with option."),
errhint("Consider using \"CREATE TABLE\" statement " errhint("Consider using \"CREATE TABLE\" statement "
"to create this table as a tenant table in " "to create this table as a single-shard distributed "
"the same schema to automatically colocate " "table in the same schema to automatically colocate "
"it with %s.%s", "it with %s.%s",
sourceRelationSchemaName, sourceRelationName))); sourceRelationSchemaName, sourceRelationName)));
} }

View File

@ -109,7 +109,7 @@ ERROR: relation "tenant_2.test_table2" does not exist
-- verify we can set regular table's schema to distributed schema -- verify we can set regular table's schema to distributed schema
CREATE TABLE regular_schema.test_table3(id int); CREATE TABLE regular_schema.test_table3(id int);
ALTER TABLE regular_schema.test_table3 SET SCHEMA tenant_2; ALTER TABLE regular_schema.test_table3 SET SCHEMA tenant_2;
NOTICE: converting table test_table3 to a tenant table in distributed schema tenant_2 NOTICE: Moving test_table3 into distributed schema tenant_2
-- verify that tenant_2.test_table3 is recorded in pg_dist_partition as a single-shard table. -- verify that tenant_2.test_table3 is recorded in pg_dist_partition as a single-shard table.
SELECT COUNT(*)=1 FROM pg_dist_partition SELECT COUNT(*)=1 FROM pg_dist_partition
WHERE logicalrelid = 'tenant_2.test_table3'::regclass AND WHERE logicalrelid = 'tenant_2.test_table3'::regclass AND
@ -126,7 +126,7 @@ ERROR: relation "regular_schema.test_table3" does not exist
CREATE TABLE tenant_2.test_table4(id int); CREATE TABLE tenant_2.test_table4(id int);
ALTER TABLE tenant_2.test_table4 SET SCHEMA tenant_3; ALTER TABLE tenant_2.test_table4 SET SCHEMA tenant_3;
NOTICE: undistributing table test_table4 in distributed schema tenant_2 before altering its schema NOTICE: undistributing table test_table4 in distributed schema tenant_2 before altering its schema
NOTICE: converting table test_table4 to a tenant table in distributed schema tenant_3 NOTICE: Moving test_table4 into distributed schema tenant_3
-- verify that tenant_3.test_table4 is recorded in pg_dist_partition as a single-shard table. -- verify that tenant_3.test_table4 is recorded in pg_dist_partition as a single-shard table.
SELECT COUNT(*)=1 FROM pg_dist_partition SELECT COUNT(*)=1 FROM pg_dist_partition
WHERE logicalrelid = 'tenant_3.test_table4'::regclass AND WHERE logicalrelid = 'tenant_3.test_table4'::regclass AND
@ -142,7 +142,7 @@ ERROR: relation "tenant_2.test_table4" does not exist
-- verify that we can put a local table in regular schema into distributed schema -- verify that we can put a local table in regular schema into distributed schema
CREATE TABLE regular_schema.pg_local_tbl(id int); CREATE TABLE regular_schema.pg_local_tbl(id int);
ALTER TABLE regular_schema.pg_local_tbl SET SCHEMA tenant_2; ALTER TABLE regular_schema.pg_local_tbl SET SCHEMA tenant_2;
NOTICE: converting table pg_local_tbl to a tenant table in distributed schema tenant_2 NOTICE: Moving pg_local_tbl into distributed schema tenant_2
-- verify that we can put a Citus local table in regular schema into distributed schema -- verify that we can put a Citus local table in regular schema into distributed schema
CREATE TABLE regular_schema.citus_local_tbl(id int); CREATE TABLE regular_schema.citus_local_tbl(id int);
SELECT citus_add_local_table_to_metadata('regular_schema.citus_local_tbl'); SELECT citus_add_local_table_to_metadata('regular_schema.citus_local_tbl');
@ -152,7 +152,7 @@ SELECT citus_add_local_table_to_metadata('regular_schema.citus_local_tbl');
(1 row) (1 row)
ALTER TABLE regular_schema.citus_local_tbl SET SCHEMA tenant_2; ALTER TABLE regular_schema.citus_local_tbl SET SCHEMA tenant_2;
NOTICE: converting table citus_local_tbl to a tenant table in distributed schema tenant_2 NOTICE: Moving citus_local_tbl into distributed schema tenant_2
-- verify that we do not allow a hash distributed table in regular schema into distributed schema -- verify that we do not allow a hash distributed table in regular schema into distributed schema
CREATE TABLE regular_schema.hash_dist_tbl(id int); CREATE TABLE regular_schema.hash_dist_tbl(id int);
SELECT create_distributed_table('regular_schema.hash_dist_tbl', 'id'); SELECT create_distributed_table('regular_schema.hash_dist_tbl', 'id');
@ -183,7 +183,7 @@ NOTICE: undistributing table tenant_tbl in distributed schema tenant_2 before a
CREATE TABLE tenant_2.tenant_tbl2(id int); CREATE TABLE tenant_2.tenant_tbl2(id int);
ALTER TABLE tenant_2.tenant_tbl2 SET SCHEMA tenant_3; ALTER TABLE tenant_2.tenant_tbl2 SET SCHEMA tenant_3;
NOTICE: undistributing table tenant_tbl2 in distributed schema tenant_2 before altering its schema NOTICE: undistributing table tenant_tbl2 in distributed schema tenant_2 before altering its schema
NOTICE: converting table tenant_tbl2 to a tenant table in distributed schema tenant_3 NOTICE: Moving tenant_tbl2 into distributed schema tenant_3
-- verify that we do not allow a local table in regular schema into distributed schema if it has foreign key to a non-reference table in another schema -- verify that we do not allow a local table in regular schema into distributed schema if it has foreign key to a non-reference table in another schema
CREATE TABLE regular_schema.pg_local_tbl1(id int PRIMARY KEY); CREATE TABLE regular_schema.pg_local_tbl1(id int PRIMARY KEY);
CREATE TABLE regular_schema.pg_local_tbl2(id int REFERENCES regular_schema.pg_local_tbl1(id)); CREATE TABLE regular_schema.pg_local_tbl2(id int REFERENCES regular_schema.pg_local_tbl1(id));
@ -193,7 +193,7 @@ DETAIL: "tenant_2.pg_local_tbl2" references "regular_schema.pg_local_tbl1" via
-- verify that we allow a local table in regular schema into distributed schema if it has foreign key to a reference table in another schema -- verify that we allow a local table in regular schema into distributed schema if it has foreign key to a reference table in another schema
CREATE TABLE regular_schema.pg_local_tbl3(id int REFERENCES regular_schema.ref_tbl(id)); CREATE TABLE regular_schema.pg_local_tbl3(id int REFERENCES regular_schema.ref_tbl(id));
ALTER TABLE regular_schema.pg_local_tbl3 SET SCHEMA tenant_2; ALTER TABLE regular_schema.pg_local_tbl3 SET SCHEMA tenant_2;
NOTICE: converting table pg_local_tbl3 to a tenant table in distributed schema tenant_2 NOTICE: Moving pg_local_tbl3 into distributed schema tenant_2
-- verify that we do not allow a table in tenant schema into regular schema if it has foreign key to/from another table in the same schema -- verify that we do not allow a table in tenant schema into regular schema if it has foreign key to/from another table in the same schema
CREATE TABLE tenant_2.tenant_tbl1(id int PRIMARY KEY); CREATE TABLE tenant_2.tenant_tbl1(id int PRIMARY KEY);
CREATE TABLE tenant_2.tenant_tbl2(id int REFERENCES tenant_2.tenant_tbl1(id)); CREATE TABLE tenant_2.tenant_tbl2(id int REFERENCES tenant_2.tenant_tbl1(id));
@ -550,7 +550,7 @@ CREATE TABLE tenant_4.employees OF employee_type (
PRIMARY KEY (name), PRIMARY KEY (name),
salary WITH OPTIONS DEFAULT 1000 salary WITH OPTIONS DEFAULT 1000
); );
ERROR: cannot create a tenant table by using CREATE TABLE OF syntax ERROR: cannot create tables in a distributed schema using CREATE TABLE OF syntax
-- verify that we act accordingly when if not exists is used -- verify that we act accordingly when if not exists is used
CREATE TABLE IF NOT EXISTS tenant_4.tbl_6(a int, b text); CREATE TABLE IF NOT EXISTS tenant_4.tbl_6(a int, b text);
CREATE TABLE IF NOT EXISTS tenant_4.tbl_6(a int, b text); CREATE TABLE IF NOT EXISTS tenant_4.tbl_6(a int, b text);
@ -614,18 +614,18 @@ WHERE logicalrelid = 'regular_schema.local_table_using_like'::regclass;
-- verify that INHERITS syntax is not supported when creating a tenant table -- verify that INHERITS syntax is not supported when creating a tenant table
CREATE TABLE tenant_5.test_table_inherits_1(x int) INHERITS (tenant_5.tbl_1); -- using a table from the same schema CREATE TABLE tenant_5.test_table_inherits_1(x int) INHERITS (tenant_5.tbl_1); -- using a table from the same schema
ERROR: tenant tables cannot inherit or be inherited ERROR: tables in a distributed schema cannot inherit or be inherited
CREATE TABLE tenant_5.test_table_inherits_2(x int) INHERITS (tenant_4.tbl_1); -- using a table from another schema CREATE TABLE tenant_5.test_table_inherits_2(x int) INHERITS (tenant_4.tbl_1); -- using a table from another schema
ERROR: tenant tables cannot inherit or be inherited ERROR: tables in a distributed schema cannot inherit or be inherited
CREATE TABLE tenant_5.test_table_inherits_3(x int) INHERITS (regular_schema.local); -- using a local table CREATE TABLE tenant_5.test_table_inherits_3(x int) INHERITS (regular_schema.local); -- using a local table
ERROR: tenant tables cannot inherit or be inherited ERROR: tables in a distributed schema cannot inherit or be inherited
CREATE TABLE tenant_5.test_table_inherits_4(x int) INHERITS (regular_schema.citus_local); -- using a citus local table CREATE TABLE tenant_5.test_table_inherits_4(x int) INHERITS (regular_schema.citus_local); -- using a citus local table
ERROR: tenant tables cannot inherit or be inherited ERROR: tables in a distributed schema cannot inherit or be inherited
CREATE TABLE tenant_5.test_table_inherits_5(x int) INHERITS (regular_schema.dist); -- using a distributed table CREATE TABLE tenant_5.test_table_inherits_5(x int) INHERITS (regular_schema.dist); -- using a distributed table
ERROR: tenant tables cannot inherit or be inherited ERROR: tables in a distributed schema cannot inherit or be inherited
-- verify that INHERITS syntax is not supported when creating a local table based on a tenant table -- verify that INHERITS syntax is not supported when creating a local table based on a tenant table
CREATE TABLE regular_schema.local_table_using_inherits(x int) INHERITS (tenant_5.tbl_1); CREATE TABLE regular_schema.local_table_using_inherits(x int) INHERITS (tenant_5.tbl_1);
ERROR: tenant tables cannot inherit or be inherited ERROR: tables in a distributed schema cannot inherit or be inherited
CREATE TABLE tenant_5.tbl_2(a int, b text); CREATE TABLE tenant_5.tbl_2(a int, b text);
CREATE SCHEMA "CiTuS.TeeN_108"; CREATE SCHEMA "CiTuS.TeeN_108";
ALTER SCHEMA "CiTuS.TeeN_108" RENAME TO citus_teen_proper; ALTER SCHEMA "CiTuS.TeeN_108" RENAME TO citus_teen_proper;
@ -814,8 +814,8 @@ $$);
CREATE TABLE regular_schema.null_shard_key_1(a int, b text); CREATE TABLE regular_schema.null_shard_key_1(a int, b text);
SELECT create_distributed_table('regular_schema.null_shard_key_1', null, colocate_with => 'tenant_5.tbl_2'); SELECT create_distributed_table('regular_schema.null_shard_key_1', null, colocate_with => 'tenant_5.tbl_2');
ERROR: cannot colocate tables tbl_2 and null_shard_key_1 ERROR: cannot colocate tables tbl_2 and null_shard_key_1
DETAIL: Cannot colocate tables with tenant tables by using colocate_with option. DETAIL: Cannot colocate tables with distributed schema tables by using colocate_with option.
HINT: Consider using "CREATE TABLE" statement to create this table as a tenant table in the same schema to automatically colocate it with tenant_5.tbl_2 HINT: Consider using "CREATE TABLE" statement to create this table as a single-shard distributed table in the same schema to automatically colocate it with tenant_5.tbl_2
SELECT create_distributed_table('regular_schema.null_shard_key_1', 'a', colocate_with => 'tenant_5.tbl_2'); SELECT create_distributed_table('regular_schema.null_shard_key_1', 'a', colocate_with => 'tenant_5.tbl_2');
ERROR: cannot colocate tables tbl_2 and null_shard_key_1 ERROR: cannot colocate tables tbl_2 and null_shard_key_1
DETAIL: Distribution column types don't match for tbl_2 and null_shard_key_1. DETAIL: Distribution column types don't match for tbl_2 and null_shard_key_1.