citus
citus copied to clipboard
Tables distribution questions
Hi team,
After checking 12.1 doc, we still have questions about tables distribution. We raised questions in Slack but didn't get needed answer
Please help provide answer, thanks:
For example, we have tables with tenant_uuid column, if we distribute tables as below to make them work co-location
SELECT create_distributed_table('table_1', 'tenant_uuid');
SELECT create_distributed_table('table_2', 'tenant_uuid', colocate_with => 'table_1');
SELECT create_distributed_table('table_3', 'tenant_uuid', colocate_with => 'table_1');
...
load data or logical replication from source database
- Does table_1 need to be the first table which have new tenant_id record(earlier than other tables table_2, table_3...)?
- Does table_1 need to have full tenant_id record(not allow table_2, table_3... have the tenant_id which not in table_1 table)?
Thank you
- Does table_1 need to be the first table which have new tenant_id record(earlier than other tables table_2, table_3...)?
No, not necessarily for the distribution/colocation purposes. But if your data model requires that, you may make tenant_uuid a primary key for table_1.
- Does table_1 need to have full tenant_id record(not allow table_2, table_3... have the tenant_id which not in table_1 table)?
Again, if your data model requires this relationship, you may define a foreign_key constraint for tenant_uuid in table_2 and table_3 that references tenant_uuid in table_1.
You may colocate the tables without those constraints as well.