Create a new colocation properly after breaking one (#6929)

When breaking 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.

Fixes: #6928
pull/7173/head
Hanefi Onaldi 2023-09-05 11:21:47 +03:00 committed by GitHub
commit 1d540b60fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 5 deletions

View File

@ -175,12 +175,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);
}