数据库分片策略

发布于 2024-09-17 10:27:41 字数 105 浏览 11 评论 0原文

我想将一个产品表分成许多较小的表,并将该表放在不同的服务器中。 但我遇到了一些问题:如果我用产品 ID 来分片数据库。当有人列出一个产品类别时,如何获得属于某些类别的所有产品。有人有美好的理想吗?

i want to split a product table into many smaller one, and put the table in diffrent server.
but there has some problems with me: if i sharding the database with the product id. how can i get all product belong to some categorys when someone list one product category. anybody get a good ideals ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

碍人泪离人颜 2024-09-24 10:27:41

这是一个好问题。如果您想要做的只是将一些记录放入另一个数据库中,并且您不打算与任何其他表上的这些记录进行联接,那么您所要做的就是告诉您的应用程序在分片 1 中插入记录 1-10000分片 2 中为 10001 -20000。但是,如果您想从分片 1 到分片 2 进行查询,这是行不通的,您将需要像 dbShards。 dbShards是一款不错的分片工具,评价也很好。此外,它们还将帮助您为您的应用程序制定整体分片策略。

希望有帮助。

This is a good question. If all you want to do is put some records in another database and you are not going to be doing joins with those records on any other tables, then yes all you have to do it tell your application to insert records 1-10000 in shard 1 and 10001 -20000 in shard 2. But if you want to do a query from shard 1 to shard 2, that won't work, and you will need a product like dbShards. dbShards is a good sharding tool and has great reviews. Also they will help you develop an overall sharding strategy for your application.

Hope that helps.

将军与妓 2024-09-24 10:27:41

分片的基本问题始终是相同的:您从一开始就不知道如何分片。

如果表中没有 1 亿行,那么很明显您不需要考虑分片。分片不能解决任何类型的查询性能。

我曾经尝试猜测数据库中什么会流行,什么会出现问题,但惨败了。现在我明白,我需要在问题发生时解决这个问题,并且我需要编写良好且干净的代码,以便将来可能进行这样的更改(例如,检查存储库模式)。

有关数据库性能的基本知识也很好。添加修复慢速查询(slowlog 是一个很好的起点)并忽略连接操作。

The basic problem with sharding is always the same: you don't know how to shard from the start.

If you don't have 100 million of rows in table then it's quite obvious you don't need to bother with sharding. Shards are not solving any type of query performance.

I've tried once to guess what will be popular and problematic in DB and failed miserably. Now I understand that I need to tackle that problem when it's happening and I need to write good and clean code to make changes like this possible in the future (check repository pattern for example).

Also basic knowledge about database performance is good. Add to that fixing slow queries (slowlog is a good place to start) and ignore join operations.

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