Prevent citus local table creation from a catalog table (#4158)

try_insertselect
Onur Tirtir 2020-09-15 14:30:48 +03:00 committed by GitHub
parent e7079d1384
commit 4118560b75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 8 deletions

View File

@ -202,6 +202,8 @@ ErrorIfUnsupportedCreateCitusLocalTable(Relation relation)
"not exist")));
}
ErrorIfTableIsACatalogTable(relation);
Oid relationId = relation->rd_id;
ErrorIfCoordinatorNotAddedAsWorkerNode();

View File

@ -683,12 +683,7 @@ EnsureRelationCanBeDistributed(Oid relationId, Var *distributionColumn,
TupleDesc relationDesc = RelationGetDescr(relation);
char *relationName = RelationGetRelationName(relation);
if (relation->rd_rel->relnamespace == PG_CATALOG_NAMESPACE)
{
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot distribute catalog tables")));
}
ErrorIfTableIsACatalogTable(relation);
if (!RelationUsesHeapAccessMethodOrNone(relation))
{
@ -834,6 +829,23 @@ EnsureRelationCanBeDistributed(Oid relationId, Var *distributionColumn,
}
/*
* ErrorIfTableIsACatalogTable is a helper function to error out for citus
* table creation from a catalog table.
*/
void
ErrorIfTableIsACatalogTable(Relation relation)
{
if (relation->rd_rel->relnamespace != PG_CATALOG_NAMESPACE)
{
return;
}
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot create a citus table from a catalog table")));
}
/*
* EnsureTableCanBeColocatedWith checks whether a given replication model and
* distribution column type is suitable to distribute a table to be colocated

View File

@ -153,6 +153,7 @@ extern void EnsureHashDistributedTable(Oid relationId);
extern void EnsureSequenceOwner(Oid sequenceOid);
extern void EnsureFunctionOwner(Oid functionId);
extern void EnsureSuperUser(void);
extern void ErrorIfTableIsACatalogTable(Relation relation);
extern void EnsureTableNotDistributed(Oid relationId);
extern void EnsureReplicationSettings(Oid relationId, char replicationModel);
extern bool RegularTable(Oid relationId);

View File

@ -654,6 +654,9 @@ FROM (SELECT tableName FROM pg_catalog.pg_tables WHERE tablename LIKE 'citus_loc
f | t
(1 row)
-- cannot create a citus local table from a catalog table
SELECT create_citus_local_table('pg_class');
ERROR: cannot create a citus table from a catalog table
-- cleanup at exit
DROP SCHEMA citus_local_tables_test_schema, "CiTUS!LocalTables" CASCADE;
NOTICE: drop cascades to 18 other objects

View File

@ -319,6 +319,6 @@ DROP TABLE data_load_test1, data_load_test2;
END;
-- distributing catalog tables is not supported
SELECT create_distributed_table('pg_class', 'relname');
ERROR: cannot distribute catalog tables
ERROR: cannot create a citus table from a catalog table
SELECT create_reference_table('pg_class');
ERROR: cannot distribute catalog tables
ERROR: cannot create a citus table from a catalog table

View File

@ -442,5 +442,8 @@ SELECT relation_is_a_known_shard('citus_local_table_4');
SELECT citus_table_is_visible(tableName::regclass::oid), relation_is_a_known_shard(tableName::regclass)
FROM (SELECT tableName FROM pg_catalog.pg_tables WHERE tablename LIKE 'citus_local_table_4_%') as tableName;
-- cannot create a citus local table from a catalog table
SELECT create_citus_local_table('pg_class');
-- cleanup at exit
DROP SCHEMA citus_local_tables_test_schema, "CiTUS!LocalTables" CASCADE;