我无法仅根据全局标识符判断一行位于哪个数据库中
如果我有一个 User
表(以全局 id
作为主键),该表被分片到 10 个数据库 (DB1
-DB10< /code>)基于
用户名
,另一个表尝试使用User
表行的全局id引用
,我无法知道哪个用户所在的DB(1-10)。User
表
这个问题的解决方案是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
或者:
更改您的分片方案,以便根据用于查找此数据的密钥进行分片。如果是按 ID 进行,请始终按 ID 进行,并按 ID 进行分片 (DB = ID % 10)
将
User
表的主键设为username
。强制其唯一性,并使用用户名
作为其他表中的外键,而不是合成标识符。创建一个可引用的查找表,将
id
映射到分片。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.