开发者

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:

  1. 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)

  2. Make the primary key of the User table the username. Enforce its uniqueness and use the username as the foreign key in the other tables, not a synthetic identifier.

  3. Create a lookup table you can reference which maps ids to shards.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜