我无法仅根据全局标识符判断一行位于哪个数据库中

发布于 2024-11-25 11:33:25 字数 253 浏览 6 评论 0原文

如果我有一个 User 表(以全局 id 作为主键),该表被分片到 10 个数据库 (DB1-DB10< /code>)基于用户名,另一个表尝试使用User表行的全局id引用User,我无法知道哪个用户所在的DB(1-10)。

这个问题的解决方案是什么?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北音执念 2024-12-02 11:33:25

或者:

  1. 更改您的分片方案,以便根据用于查找此数据的密钥进行分片。如果是按 ID 进行,请始终按 ID 进行,并按 ID 进行分片 (DB = ID % 10)

  2. User 表的主键设为 username 。强制其唯一性,并使用用户名作为其他表中的外键,而不是合成标识符。

  3. 创建一个可引用的查找表,将 id 映射到分片。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文