Skip to content

Commit

Permalink
Do the index check in the dedicated check function
Browse files Browse the repository at this point in the history
And minor indentation fixes, removed old comment, update tests.
  • Loading branch information
c2main committed Oct 25, 2023
1 parent 795b0d8 commit 6dfc402
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
45 changes: 29 additions & 16 deletions src/backend/distributed/metadata/metadata_utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,7 @@ DistributedRelationSize(Oid relationId, SizeQueryType sizeQueryType,
return false;
}

Oid checkRelId = relationId;
if (relation->rd_rel->relkind == RELKIND_INDEX)
{
bool missingOk = false;
checkRelId = IndexGetRelation(relation->rd_id, missingOk);
}

ErrorIfNotSuitableToGetSize(checkRelId);
ErrorIfNotSuitableToGetSize(relationId);

table_close(relation, AccessShareLock);

Expand Down Expand Up @@ -584,7 +577,7 @@ DistributedRelationSize(Oid relationId, SizeQueryType sizeQueryType,
/*
* DistributedRelationSizeOnWorker gets the workerNode and relationId to calculate
* size of that relation on the given workerNode by summing up the size of each
* shard placement. If indexId is defined then the relation is an index.
* shard placement.
*/
static bool
DistributedRelationSizeOnWorker(WorkerNode *workerNode, Oid relationId,
Expand All @@ -604,12 +597,12 @@ DistributedRelationSizeOnWorker(WorkerNode *workerNode, Oid relationId,
PGresult *result = NULL;

/* if the relation is an index, update relationId and define indexId */
Oid indexId = InvalidOid;
Oid indexId = InvalidOid;
if (get_rel_relkind(relationId) == RELKIND_INDEX)
{
indexId = relationId;

bool missingOk = false;
bool missingOk = false;
relationId = IndexGetRelation(indexId, missingOk);
}

Expand Down Expand Up @@ -1051,11 +1044,31 @@ ErrorIfNotSuitableToGetSize(Oid relationId)
{
if (!IsCitusTable(relationId))
{
char *relationName = get_rel_name(relationId);
char *escapedQueryString = quote_literal_cstr(relationName);
ereport(ERROR, (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
errmsg("cannot calculate the size because relation %s is not "
"distributed", escapedQueryString)));
if (get_rel_relkind(relationId) != RELKIND_INDEX)
{
char *relationName = get_rel_name(relationId);
char *escapedQueryString = quote_literal_cstr(relationName);
ereport(ERROR, (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
errmsg(
"cannot calculate the size because relation %s "
"is not distributed",
escapedQueryString)));
}
bool missingOk = false;
Oid indexId = relationId;
relationId = IndexGetRelation(relationId, missingOk);
if (!IsCitusTable(relationId))
{
char *tableName = get_rel_name(relationId);
char *escapedTableName = quote_literal_cstr(tableName);
char *indexName = get_rel_name(indexId);
char *escapedIndexName = quote_literal_cstr(indexName);
ereport(ERROR, (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg(
"cannot calculate the size because table %s for "
"index %s is not distributed",
escapedTableName, escapedIndexName)));
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/regress/expected/multi_size_queries.out
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ ERROR: cannot calculate the size because relation 'non_distributed_table' is no
SELECT citus_total_relation_size('non_distributed_table');
ERROR: cannot calculate the size because relation 'non_distributed_table' is not distributed
SELECT citus_table_size('non_distributed_table_pkey');
ERROR: cannot calculate the size because relation 'non_distributed_table' is not distributed
ERROR: cannot calculate the size because table 'non_distributed_table' for index 'non_distributed_table_pkey' is not distributed
SELECT citus_relation_size('non_distributed_table_pkey');
ERROR: cannot calculate the size because relation 'non_distributed_table' is not distributed
ERROR: cannot calculate the size because table 'non_distributed_table' for index 'non_distributed_table_pkey' is not distributed
SELECT citus_total_relation_size('non_distributed_table_pkey');
ERROR: cannot calculate the size because relation 'non_distributed_table' is not distributed
ERROR: cannot calculate the size because table 'non_distributed_table' for index 'non_distributed_table_pkey' is not distributed
DROP TABLE non_distributed_table;
-- fix broken placements via disabling the node
SET client_min_messages TO ERROR;
Expand Down

0 comments on commit 6dfc402

Please sign in to comment.