From 1598a1c59d5241f43462acceb2629c734842da77 Mon Sep 17 00:00:00 2001 From: Hanefi Onaldi Date: Wed, 17 May 2023 16:19:56 +0300 Subject: [PATCH] Create a new colocation properly after braking one When braking a colocation, we need to create a new colocation group record in pg_dist_colocation for the relation. It is not sufficient to have a new colocationid value in pg_dist_partition only. This patch also fixes a bug when deleting a colocation group if no tables are left in it. Previously we passed a relation id as a parameter to DeleteColocationGroupIfNoTablesBelong function, where we should have passed a colocation id. (cherry picked from commit c22547d221af72e2764731f8629d37409aa4d905) --- src/backend/distributed/utils/colocation_utils.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/backend/distributed/utils/colocation_utils.c b/src/backend/distributed/utils/colocation_utils.c index a5a32db0e..aeafa175e 100644 --- a/src/backend/distributed/utils/colocation_utils.c +++ b/src/backend/distributed/utils/colocation_utils.c @@ -170,12 +170,11 @@ BreakColocation(Oid sourceRelationId) */ Relation pgDistColocation = table_open(DistColocationRelationId(), ExclusiveLock); - uint32 newColocationId = GetNextColocationId(); - bool localOnly = false; - UpdateRelationColocationGroup(sourceRelationId, newColocationId, localOnly); + uint32 oldColocationId = TableColocationId(sourceRelationId); + CreateColocationGroupForRelation(sourceRelationId); - /* if there is not any remaining table in the colocation group, delete it */ - DeleteColocationGroupIfNoTablesBelong(sourceRelationId); + /* if there is not any remaining table in the old colocation group, delete it */ + DeleteColocationGroupIfNoTablesBelong(oldColocationId); table_close(pgDistColocation, NoLock); }