我应该拆分一个包含大量数据的表吗?
我正在使用MySQL。我需要将 XML 文件的内容保存到数据库中。文件大小通常小于10k。
该表如下所示:
articles
-----------
id
date
writer
...
file_name
file_content (Text)
file_date
当我仅选择 date
和 writer
时,拆分表会提高性能吗?或者还有其他原因来分割这个表吗?
I'm using MySQL. I need to save contents of XML file to database. The size of file is usually less than 10k.
The table looks like this:
articles
-----------
id
date
writer
...
file_name
file_content (Text)
file_date
Does splitting the table improve performance when I select just date
and writer
? Or is there any other reason to split this table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这称为垂直分区。
基本上,如果您的总数据集非常大(例如,大于 RAM),并且大多数查询不使用大型 file_content 数据,则将其放在另一个表中将使主表小得多,因此更好地缓存在 RAM 中,而且速度要快得多。
当然,检索 file_content 会慢一些,所以这取决于您使用它的频率。
我在论坛上使用了这种技术。我将帖子文本(解析为 HTML 的 bbcode)存储在主表中,并将原始帖子(以 bbcode 形式)存储在另一个表中。显示论坛页面时,仅命中主表。原始帖子文本仅用于编辑帖子。这将 posts 表的大小除以 2,避免了服务器上 RAM 的增加。
This is called vertical partitioning.
Basically if your total data set is very large (say, larger than RAM), and most of your queries do not use the large file_content data, putting it in another table will make the main table much smaller, therefore much better cached in RAM, and much, much faster.
Of course retrieving the file_content will be a little slower, so it depends how often you use it.
I used this technique on a forum. I stored the posts text (bbcode parsed to HTML) in the main table, and the original posts (in bbcode) in another table. When displaying forum pages, only the main table is hit. The original post text is used only for editing posts. This divided the posts table size by 2 and avoided having to double the RAM on this server.