MYSQl优化博客文章与评论 [英] MYSQl Optimize Table Of Blog Posts With Comments

查看:177
本文介绍了MYSQl优化博客文章与评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个mysql表,将持有我的博客文章和一些他们的信息。我想能够添加评论的博客帖子,并让他们保存在mysql。我的问题是天气我应该做一个表称为评论,并有所有的评论有博客文章ID,所以我只会选择相应的评论,如下:

Im making a mysql table which will be holding my blog posts and some of their information. I want to be able to add comments the the blog posts and have them saved in mysql. My question is weather I should make a table called comments and have all the comments there have the blog post id, so I would only select the corresponding comments like this:

select from comments where id = blogpostid

将所有注释放入数组,并将它们保存在我的博客帖子表的长文本字段中,因此每一行(博客帖子)将包含其注释。

Or my other idea was to put all the comments in an array, and save them in a longtext field in my blog posts table, so each row(blog post) will contain its comments.

接受任何其他想法,但对我来说速度先到。

I will accept any other ideas, but for me speed comes first.

推荐答案

有一个很好的规范化,单独的注释表是正确的。

Having a nicely normalized, separate comments table is the right thing.

使用适当的索引,它会工作正常。我怀疑是否会有这样的交通,将有理由解除规范化的结构的速度。

With the proper indexes, it will work fine. I doubt whether there'll ever be the kind of traffic that would justify de-normalizing the structure for speed.

这篇关于MYSQl优化博客文章与评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆