JOIN 适用于无法装入内存的大型 mysql 数据库。

发布于 2024-12-10 00:50:57 字数 404 浏览 2 评论 0原文

JOIN 是 SQL 数据库的一个方便的功能,但对于大型数据库(>10GB)又如何呢?考虑三个(两列)多对多关系的表,因为我们想要获取与一个案例关联的项目(例如一篇文章的标签)。

事实(如果我错了请纠正我): 1. 对于 JOIN,内存中应容纳三个表。 2、单次SELECT by PRIMARY KEY不消耗内存。 3. 当我们有很多并发读连接时,多余的连接将保留在队列中(不会发出不成功的请求或过载)。

那么,执行三个简单的 SELECT 查询不是更好吗?这使得系统有点慢,但我相信处理整个千兆字节大小的表会更有效。

人们可能会认为添加更多是最终的解决方案;但我认为使用多余的 RAM 仍然处理如此大的表并不容易。

将操作限制为带有 PRIMARY KEY 的简单 SELECT 查询可能是有效处理大型数据库的实用方法。

JOIN is a handy feature of SQL databases, but what about large databases (>10GB). Consider three (two-column) tables of many-to-many relationship, as we want to get items associated to one single case (e.g. tags of ONE article).

FACTS (correct me if I'm wrong):
1. For JOIN, three tables should fit within the memory.
2. Single SELECT by PRIMARY KEY does not consume memory.
3. When we have concurrent many concurrent read connections, excess connection will be kept in queue (not making unsuccessful request or overload).

Then, isn't it better to perform three simple SELECT queries. This makes the system a little bit slower, but I believe it is more efficient to deal with the entire tables of Gigabyte size.

One may suggest that adding more is the ultimate solution; but I think still handling such large tables is not easy with excess RAM.

Limiting actions to simple SELECT queries with PRIMARY KEY can be a practical approach to work with large databases efficiently.

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

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

发布评论

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

评论(2

风吹雪碎 2024-12-17 00:50:57

如果您声称最好在三个单独的表上进行选择,然后在数据库引擎之外自行连接数据,那么您就错了。数据库将比您更好地连接您的查询。这些表不必全部装入 RAM 才能使联接发挥作用。

If you are claiming that it's better to do the selects on three separate tables, then join the data yourself outside of the database engine, then you are wrong. The database will do a better job joining your queries than you can. The tables don't all have to fit into RAM for a join to work.

鹤舞 2024-12-17 00:50:57

索引对于大型数据库确实很有帮助。

这些可能会有所帮助 http:// www.databasejournal.com/features/mysql/article.php/1382791/Optimizing-MySQL-Queries-and-Indexes.htm

http://www.tizag.com/mysqlTutorial/mysql-index.php

索引可以数据库实现之间存在差异,如果设计/实现不正确,它们也有缺点(这就是为什么您不只为每个字段建立索引)。

Indexes can be really helpful with large databases.

These may help http://www.databasejournal.com/features/mysql/article.php/1382791/Optimizing-MySQL-Queries-and-Indexes.htm

http://www.tizag.com/mysqlTutorial/mysql-index.php

Indexes can vary among database implementations and they have downsides too if not designed / implemented correctly (that's why you don't just index every field).

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