Skip to content

Commit

Permalink
Code review feedback
Browse files Browse the repository at this point in the history
Clarified a function contracts, added a comment, and inserted explicit
cast to oid for better `pg_dump` compatibility.
  • Loading branch information
jasonmp85 committed Jun 8, 2015
1 parent f1ef1f7 commit 856592f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions distribution_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,24 +373,36 @@ PartitionType(Oid distributedTableId)


/*
* IsDistributedTable simply returns whether the specified table is distributed.
* IsDistributedTable returns whether the specified table is distributed. It
* returns false if the input is InvalidOid.
*/
bool
IsDistributedTable(Oid tableId)
{
Oid tableNamespaceOid = get_rel_namespace(tableId);
Oid metadataNamespaceOid = get_namespace_oid("pgs_distribution_metadata", false);
Oid partitionMetadataTableOid = get_relname_relid("partition", metadataNamespaceOid);
Oid tableNamespaceOid = InvalidOid;
Oid partitionMetadataTableOid = InvalidOid;
bool isDistributedTable = false;
Oid argTypes[] = { OIDOID };
Datum argValues[] = { ObjectIdGetDatum(tableId) };
const int argCount = sizeof(argValues) / sizeof(argValues[0]);
int spiStatus PG_USED_FOR_ASSERTS_ONLY = 0;

/* short-circuit if the input is invalid */
if (tableId == InvalidOid)
{
return false;
}

/*
* The query below hits the partition metadata table, so if we don't detect
* that and short-circuit, we'll get infinite recursion in the planner.
*
* Within CitusDB, a view rewrite the query to reference CitusDB catalogs,
* so we also need to catch whether the table exists in a system namespace.
*/
tableNamespaceOid = get_rel_namespace(tableId);
partitionMetadataTableOid = get_relname_relid("partition", metadataNamespaceOid);
if (IsSystemNamespace(tableNamespaceOid) || tableId == partitionMetadataTableOid)
{
return false;
Expand Down
2 changes: 1 addition & 1 deletion pg_shard--1.2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ BEGIN
partkey)
VALUES (NEW.relation_id,
NEW.partition_method,
column_name_to_column(NEW.relation_id, NEW.key));
column_name_to_column(NEW.relation_id::oid, NEW.key));

RETURN NEW;
END
Expand Down
2 changes: 1 addition & 1 deletion pg_shard.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ ExtractFirstDistributedTableId(Query *query)
{
RangeTblEntry *rangeTableEntry = (RangeTblEntry *) lfirst(rangeTableCell);

if (rangeTableEntry->rtekind == RTE_RELATION && IsDistributedTable(rangeTableEntry->relid))
if (IsDistributedTable(rangeTableEntry->relid))
{
distributedTableId = rangeTableEntry->relid;
break;
Expand Down

0 comments on commit 856592f

Please sign in to comment.