Add IsCitusTable check to citus table utilities (#4028)

pull/3991/head
SaitTalhaNisanci 2020-07-14 18:29:33 +03:00 committed by GitHub
parent 23d44eba9f
commit bc011a6286
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 4 deletions

View File

@ -1386,12 +1386,16 @@ EnsureHashDistributedTable(Oid relationId)
/* /*
* IsDistributedTable returns true if the given relation is * IsHashDistributedTable returns true if the given relation is
* a distributed table. * a distributed table.
*/ */
bool bool
IsHashDistributedTable(Oid relationId) IsHashDistributedTable(Oid relationId)
{ {
if (!IsCitusTable(relationId))
{
return false;
}
CitusTableCacheEntry *sourceTableEntry = GetCitusTableCacheEntry(relationId); CitusTableCacheEntry *sourceTableEntry = GetCitusTableCacheEntry(relationId);
char sourceDistributionMethod = sourceTableEntry->partitionMethod; char sourceDistributionMethod = sourceTableEntry->partitionMethod;
return sourceDistributionMethod == DISTRIBUTE_BY_HASH; return sourceDistributionMethod == DISTRIBUTE_BY_HASH;

View File

@ -466,8 +466,7 @@ bool
IsReferenceTableRTE(Node *node) IsReferenceTableRTE(Node *node)
{ {
Oid relationId = NodeTryGetRteRelid(node); Oid relationId = NodeTryGetRteRelid(node);
return relationId != InvalidOid && IsCitusTable(relationId) && return relationId != InvalidOid && IsReferenceTable(relationId);
IsReferenceTable(relationId);
} }

View File

@ -64,6 +64,10 @@ PG_FUNCTION_INFO_V1(replicate_reference_tables);
bool bool
IsReferenceTable(Oid relationId) IsReferenceTable(Oid relationId)
{ {
if (!IsCitusTable(relationId))
{
return false;
}
CitusTableCacheEntry *tableEntry = GetCitusTableCacheEntry(relationId); CitusTableCacheEntry *tableEntry = GetCitusTableCacheEntry(relationId);
if (tableEntry->partitionMethod != DISTRIBUTE_BY_NONE) if (tableEntry->partitionMethod != DISTRIBUTE_BY_NONE)

View File

@ -1420,7 +1420,7 @@ SELECT tables_colocated('d2', 'none');
SELECT update_distributed_table_colocation('ref', colocate_with => 'none'); SELECT update_distributed_table_colocation('ref', colocate_with => 'none');
ERROR: relation ref should be a hash distributed table ERROR: relation ref should be a hash distributed table
SELECT update_distributed_table_colocation('local_table', colocate_with => 'none'); SELECT update_distributed_table_colocation('local_table', colocate_with => 'none');
ERROR: relation local_table is not distributed ERROR: relation local_table should be a hash distributed table
-- make sure that different types cannot be colocated -- make sure that different types cannot be colocated
SELECT update_distributed_table_colocation('different_d1', colocate_with => 'd1'); SELECT update_distributed_table_colocation('different_d1', colocate_with => 'd1');
ERROR: cannot colocate tables d1 and different_d1 ERROR: cannot colocate tables d1 and different_d1