I can't tell in which DB a row is located from just the global identifier
If I have a User
table (with a global id
as primary key) that is sharded across 10 databases (DB1
-DB10
) based on the username
, and another table tries to refer to the User
开发者_开发问答table using the User
table row's global id
, there is no way for me to know which DB (1-10) that user is located in.
What is the solution to this problem?
Either:
Change your sharding scheme so that you shard based on the key you use to look up this data. If it's by ID, always do it by ID, and shard it by ID (DB = ID % 10)
Make the primary key of the
User
table theusername
. Enforce its uniqueness and use theusername
as the foreign key in the other tables, not a synthetic identifier.Create a lookup table you can reference which maps
id
s to shards.
精彩评论