citusdata / citus

Distributed PostgreSQL as an extension
https://www.citusdata.com
GNU Affero General Public License v3.0
10.18k stars 652 forks source link

mark_tables_colocated may seperate foreign referenced tables into different colocation groups #1094

Open byucesoy opened 7 years ago

byucesoy commented 7 years ago

If a foreign key is defined to or from a table, we should not allow changing colocation group of this table. Currently we do not have such check.

To replicate the problem;

set citus.shard_replication_factor to 1;

create table g1t1(c int PRIMARY KEY);
create table g1t2(c int, FOREIGN KEY(c) REFERENCES g1t1(c));
create table g2t1(c);

select create_distributed_table('g1t1', 'c');
select create_distributed_table('g1t2', 'c');
select create_distributed_table('g2t1', 'c', colocate_with => 'none');

select mark_tables_colocated('g2t1', ARRAY['g1t2']);

select logicalrelid, colocationid from pg_dist_partition;
 logicalrelid | colocationid 
--------------+--------------
 g1t1         |            2
 g2t1         |            3
 g1t2         |            3

I have two options in my mind to solve this problem;

marcocitus commented 7 years ago

Another, simpler option could be to error out when a table is already in a colocation group with >1 tables.