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 c22547d221)
release-11.2-hanefi
Hanefi Onaldi 2023-05-17 16:19:56 +03:00
parent 71385b8a56
commit c71faad606
No known key found for this signature in database
GPG Key ID: F18CDB10BA0DFDC7
1 changed files with 4 additions and 5 deletions

View File

@ -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);
}