Check whether relation ID exists in citus_relation_size

pull/1365/head
Marco Slot 2017-04-29 01:39:39 +02:00
parent 4094b45ba9
commit 0b579d027a
3 changed files with 33 additions and 0 deletions

View File

@ -134,6 +134,7 @@ citus_relation_size(PG_FUNCTION_ARGS)
static uint64
DistributedTableSize(Oid relationId, char *sizeQuery)
{
Relation relation = NULL;
Relation pgDistNode = NULL;
List *workerNodeList = NULL;
ListCell *workerNodeCell = NULL;
@ -146,6 +147,9 @@ DistributedTableSize(Oid relationId, char *sizeQuery)
" blocks which contain multi-shard data modifications")));
}
/* try to open relation, will error out if the relation does not exist */
relation = relation_open(relationId, AccessShareLock);
ErrorIfNotSuitableToGetSize(relationId);
pgDistNode = heap_open(DistNodeRelationId(), AccessShareLock);
@ -161,6 +165,7 @@ DistributedTableSize(Oid relationId, char *sizeQuery)
}
heap_close(pgDistNode, NoLock);
heap_close(relation, AccessShareLock);
return totalRelationSize;
}

View File

@ -6,6 +6,22 @@
-- citus_total_relation_size are also tested.
ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 1390000;
ALTER SEQUENCE pg_catalog.pg_dist_jobid_seq RESTART 1390000;
-- Tests with invalid relation IDs
SELECT citus_table_size(1);
ERROR: could not open relation with OID 1
SELECT citus_relation_size(1);
ERROR: could not open relation with OID 1
SELECT citus_total_relation_size(1);
ERROR: could not open relation with OID 1
-- Tests with non-distributed table
CREATE TABLE non_distributed_table (x int);
SELECT citus_table_size('non_distributed_table');
ERROR: cannot calculate the size because relation 'non_distributed_table' is not distributed
SELECT citus_relation_size('non_distributed_table');
ERROR: cannot calculate the size because relation 'non_distributed_table' is not distributed
SELECT citus_total_relation_size('non_distributed_table');
ERROR: cannot calculate the size because relation 'non_distributed_table' is not distributed
DROP TABLE non_distributed_table;
-- Tests on distributed table with replication factor > 1
SELECT citus_table_size('lineitem_hash_part');
ERROR: cannot calculate the size because replication factor is greater than 1

View File

@ -8,6 +8,18 @@
ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 1390000;
ALTER SEQUENCE pg_catalog.pg_dist_jobid_seq RESTART 1390000;
-- Tests with invalid relation IDs
SELECT citus_table_size(1);
SELECT citus_relation_size(1);
SELECT citus_total_relation_size(1);
-- Tests with non-distributed table
CREATE TABLE non_distributed_table (x int);
SELECT citus_table_size('non_distributed_table');
SELECT citus_relation_size('non_distributed_table');
SELECT citus_total_relation_size('non_distributed_table');
DROP TABLE non_distributed_table;
-- Tests on distributed table with replication factor > 1
SELECT citus_table_size('lineitem_hash_part');
SELECT citus_relation_size('lineitem_hash_part');