From 161093908e7906c44b22b9633c65fc55fd50b005 Mon Sep 17 00:00:00 2001 From: Metin Doslu Date: Fri, 14 Oct 2016 13:39:29 +0300 Subject: [PATCH] Convert colocationid to uint32 --- src/backend/distributed/citus--6.0-10--6.0-11.sql | 2 ++ src/backend/distributed/metadata/metadata_sync.c | 4 ++-- src/backend/distributed/test/colocation_utils.c | 2 +- src/backend/distributed/utils/colocation_utils.c | 12 ++++++------ src/backend/distributed/utils/metadata_cache.c | 2 +- src/include/distributed/colocation_utils.h | 2 +- src/include/distributed/metadata_cache.h | 2 +- src/include/distributed/pg_dist_colocation.h | 2 +- src/include/distributed/pg_dist_partition.h | 2 +- 9 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/backend/distributed/citus--6.0-10--6.0-11.sql b/src/backend/distributed/citus--6.0-10--6.0-11.sql index 9c818c293..8dda70294 100644 --- a/src/backend/distributed/citus--6.0-10--6.0-11.sql +++ b/src/backend/distributed/citus--6.0-10--6.0-11.sql @@ -103,4 +103,6 @@ $cdbdt$; COMMENT ON FUNCTION citus_drop_trigger() IS 'perform checks and actions at the end of DROP actions'; +ALTER TABLE pg_dist_partition ALTER COLUMN colocationid TYPE integer; + RESET search_path; diff --git a/src/backend/distributed/metadata/metadata_sync.c b/src/backend/distributed/metadata/metadata_sync.c index 5980b6425..11f794e0c 100644 --- a/src/backend/distributed/metadata/metadata_sync.c +++ b/src/backend/distributed/metadata/metadata_sync.c @@ -215,14 +215,14 @@ DistributionCreateCommand(DistTableCacheEntry *cacheEntry) char *qualifiedRelationName = generate_qualified_relation_name(relationId); char *partitionKeyColumnName = ColumnNameToColumn(relationId, partitionKeyString); - uint64 colocationId = cacheEntry->colocationId; + uint32 colocationId = cacheEntry->colocationId; char replicationModel = cacheEntry->replicationModel; appendStringInfo(insertDistributionCommand, "INSERT INTO pg_dist_partition " "(logicalrelid, partmethod, partkey, colocationid, repmodel) " "VALUES " - "(%s::regclass, '%c', column_name_to_column(%s,%s), %lu, '%c')", + "(%s::regclass, '%c', column_name_to_column(%s,%s), %d, '%c')", quote_literal_cstr(qualifiedRelationName), distributionMethod, quote_literal_cstr(qualifiedRelationName), diff --git a/src/backend/distributed/test/colocation_utils.c b/src/backend/distributed/test/colocation_utils.c index 1e538edc7..ad83d5304 100644 --- a/src/backend/distributed/test/colocation_utils.c +++ b/src/backend/distributed/test/colocation_utils.c @@ -35,7 +35,7 @@ Datum get_table_colocation_id(PG_FUNCTION_ARGS) { Oid distributedTableId = PG_GETARG_OID(0); - int colocationId = TableColocationId(distributedTableId); + uint32 colocationId = TableColocationId(distributedTableId); PG_RETURN_INT32(colocationId); } diff --git a/src/backend/distributed/utils/colocation_utils.c b/src/backend/distributed/utils/colocation_utils.c index f2d634ea2..f74791513 100644 --- a/src/backend/distributed/utils/colocation_utils.c +++ b/src/backend/distributed/utils/colocation_utils.c @@ -23,10 +23,10 @@ /* - * TableColocationId function returns co-location id of given table. This function errors - * out if given table is not distributed. + * TableColocationId function returns co-location id of given table. This function + * errors out if given table is not distributed. */ -uint64 +uint32 TableColocationId(Oid distributedTableId) { DistTableCacheEntry *cacheEntry = DistributedTableCacheEntry(distributedTableId); @@ -44,8 +44,8 @@ TableColocationId(Oid distributedTableId) bool TablesColocated(Oid leftDistributedTableId, Oid rightDistributedTableId) { - uint64 leftColocationId = INVALID_COLOCATION_ID; - uint64 rightColocationId = INVALID_COLOCATION_ID; + uint32 leftColocationId = INVALID_COLOCATION_ID; + uint32 rightColocationId = INVALID_COLOCATION_ID; if (leftDistributedTableId == rightDistributedTableId) { @@ -112,7 +112,7 @@ ShardsColocated(ShardInterval *leftShardInterval, ShardInterval *rightShardInter List * ColocatedTableList(Oid distributedTableId) { - int tableColocationId = TableColocationId(distributedTableId); + uint32 tableColocationId = TableColocationId(distributedTableId); List *colocatedTableList = NIL; Relation pgDistPartition = NULL; diff --git a/src/backend/distributed/utils/metadata_cache.c b/src/backend/distributed/utils/metadata_cache.c index de2be6101..8ae60fd89 100644 --- a/src/backend/distributed/utils/metadata_cache.c +++ b/src/backend/distributed/utils/metadata_cache.c @@ -276,7 +276,7 @@ LookupDistTableCacheEntry(Oid relationId) HeapTuple distPartitionTuple = NULL; char *partitionKeyString = NULL; char partitionMethod = 0; - uint64 colocationId = INVALID_COLOCATION_ID; + uint32 colocationId = INVALID_COLOCATION_ID; char replicationModel = 0; List *distShardTupleList = NIL; int shardIntervalArrayLength = 0; diff --git a/src/include/distributed/colocation_utils.h b/src/include/distributed/colocation_utils.h index c32ed8a01..4ca8b54e1 100644 --- a/src/include/distributed/colocation_utils.h +++ b/src/include/distributed/colocation_utils.h @@ -17,7 +17,7 @@ #define INVALID_COLOCATION_ID 0 -extern uint64 TableColocationId(Oid distributedTableId); +extern uint32 TableColocationId(Oid distributedTableId); extern bool TablesColocated(Oid leftDistributedTableId, Oid rightDistributedTableId); extern bool ShardsColocated(ShardInterval *leftShardInterval, ShardInterval *rightShardInterval); diff --git a/src/include/distributed/metadata_cache.h b/src/include/distributed/metadata_cache.h index 7cd38c39f..3e64c80c5 100644 --- a/src/include/distributed/metadata_cache.h +++ b/src/include/distributed/metadata_cache.h @@ -40,7 +40,7 @@ typedef struct /* pg_dist_partition metadata for this table */ char *partitionKeyString; char partitionMethod; - uint64 colocationId; + uint32 colocationId; char replicationModel; /* pg_dist_shard metadata (variable-length ShardInterval array) for this table */ diff --git a/src/include/distributed/pg_dist_colocation.h b/src/include/distributed/pg_dist_colocation.h index e7acefa6c..a0250c643 100644 --- a/src/include/distributed/pg_dist_colocation.h +++ b/src/include/distributed/pg_dist_colocation.h @@ -18,7 +18,7 @@ */ typedef struct FormData_pg_dist_colocation { - int colocationid; + uint32 colocationid; int shardcount; int replicationfactor; Oid distributioncolumntype; diff --git a/src/include/distributed/pg_dist_partition.h b/src/include/distributed/pg_dist_partition.h index b80b89fcb..11e2063c1 100644 --- a/src/include/distributed/pg_dist_partition.h +++ b/src/include/distributed/pg_dist_partition.h @@ -25,7 +25,7 @@ typedef struct FormData_pg_dist_partition char partmethod; /* partition method; see codes below */ #ifdef CATALOG_VARLEN /* variable-length fields start here */ text partkey; /* partition key expression */ - uint64 colocationid; /* id of the co-location group of particular table belongs to */ + uint32 colocationid; /* id of the co-location group of particular table belongs to */ char repmodel; /* replication model; see codes below */ #endif } FormData_pg_dist_partition;