From 8455d1a4efbab594b8ffda7f54d08fe4ed6b5840 Mon Sep 17 00:00:00 2001 From: Burak Yucesoy Date: Tue, 1 Aug 2017 09:15:54 +0300 Subject: [PATCH] Ensure we are allowing partitioned tables at all appropriate places --- src/backend/distributed/master/master_stage_protocol.c | 7 ++----- src/backend/distributed/utils/citus_ruleutils.c | 8 ++------ .../distributed/worker/worker_data_fetch_protocol.c | 2 +- src/backend/distributed/worker/worker_drop_protocol.c | 7 +------ 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/backend/distributed/master/master_stage_protocol.c b/src/backend/distributed/master/master_stage_protocol.c index 6297b4da1..ac60b5f4d 100644 --- a/src/backend/distributed/master/master_stage_protocol.c +++ b/src/backend/distributed/master/master_stage_protocol.c @@ -27,6 +27,7 @@ #if (PG_VERSION_NUM >= 100000) #include "catalog/partition.h" #endif +#include "distributed/citus_ruleutils.h" #include "distributed/colocation_utils.h" #include "distributed/connection_management.h" #include "distributed/multi_client_executor.h" @@ -344,11 +345,7 @@ CheckDistributedTable(Oid relationId) char *relationName = get_rel_name(relationId); /* check that the relationId belongs to a table */ - char tableType = get_rel_relkind(relationId); - if (!(tableType == RELKIND_RELATION || tableType == RELKIND_FOREIGN_TABLE)) - { - ereport(ERROR, (errmsg("relation \"%s\" is not a table", relationName))); - } + EnsureRelationKindSupported(relationId); if (!IsDistributedTable(relationId)) { diff --git a/src/backend/distributed/utils/citus_ruleutils.c b/src/backend/distributed/utils/citus_ruleutils.c index 19d340187..4cd3b7a1a 100644 --- a/src/backend/distributed/utils/citus_ruleutils.c +++ b/src/backend/distributed/utils/citus_ruleutils.c @@ -307,12 +307,7 @@ pg_get_tableschemadef_string(Oid tableRelationId, bool includeSequenceDefaults) initStringInfo(&buffer); - relationKind = relation->rd_rel->relkind; -#if (PG_VERSION_NUM >= 100000) - if (relationKind == RELKIND_RELATION || relationKind == RELKIND_PARTITIONED_TABLE) -#else - if (relationKind == RELKIND_RELATION) -#endif + if (RegularTable(tableRelationId)) { appendStringInfoString(&buffer, "CREATE "); @@ -461,6 +456,7 @@ pg_get_tableschemadef_string(Oid tableRelationId, bool includeSequenceDefaults) * If the relation is a foreign table, append the server name and options to * the create table statement. */ + relationKind = relation->rd_rel->relkind; if (relationKind == RELKIND_FOREIGN_TABLE) { ForeignTable *foreignTable = GetForeignTable(tableRelationId); diff --git a/src/backend/distributed/worker/worker_data_fetch_protocol.c b/src/backend/distributed/worker/worker_data_fetch_protocol.c index 739d29d84..115fcb319 100644 --- a/src/backend/distributed/worker/worker_data_fetch_protocol.c +++ b/src/backend/distributed/worker/worker_data_fetch_protocol.c @@ -690,7 +690,7 @@ LocalTableSize(Oid relationId) Datum relationIdDatum = ObjectIdGetDatum(relationId); relationType = get_rel_relkind(relationId); - if (relationType == RELKIND_RELATION) + if (RegularTable(relationId)) { Datum tableSizeDatum = DirectFunctionCall1(pg_table_size, relationIdDatum); diff --git a/src/backend/distributed/worker/worker_drop_protocol.c b/src/backend/distributed/worker/worker_drop_protocol.c index f5cc4f6dc..92ecee7a4 100644 --- a/src/backend/distributed/worker/worker_drop_protocol.c +++ b/src/backend/distributed/worker/worker_drop_protocol.c @@ -62,12 +62,7 @@ worker_drop_distributed_table(PG_FUNCTION_ARGS) /* first check the relation type */ distributedRelation = relation_open(relationId, AccessShareLock); relationKind = distributedRelation->rd_rel->relkind; - if (relationKind != RELKIND_RELATION && relationKind != RELKIND_FOREIGN_TABLE) - { - char *relationName = generate_relation_name(relationId, NIL); - ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), - errmsg("%s is not a regular or foreign table", relationName))); - } + EnsureRelationKindSupported(relationId); /* close the relation since we do not need anymore */ relation_close(distributedRelation, AccessShareLock);