MYSQl Optimize Table Of Blog Posts With Comments

无人久伴 提交于 2019-12-12 01:18:54

问题


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.


回答1:


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.




回答2:


Please read about database normalization, for example (http://www.devshed.com/c/a/MySQL/An-Introduction-to-Database-Normalization/)

It's true that denormalization (adding redundant data or group it) can improve the performance of your database, but it's also increases the size of your database.
Data integrity should be your primary concern, when it's comes to database acting as a blog back-end.

You should keep your blog comments table separate with a blog post unique-id as a primary key, unless you need something more complicated (like Polymorphic Associations, etc)




回答3:


we can have a completely normalized table structure by having 2 types of tables

type1 table
that stores all the post id --- (index for all post)

type2 table
no of rows in type1 table = number of type2 table each type2 table is named after the post id the type 2 table consist of the comments of its respective post id

there will surely be issues with the maintains of the tables




回答4:


they're is an another way we can solve this problem by the user of xml technology

by saving each post comment thread in a indexed xml files

as xml promotes tree structure IT is good for part comment and 're comment

additional benefits better management and reduces the number ou db query

problem with this solution not optimized for search index



来源:https://stackoverflow.com/questions/3297583/mysql-optimize-table-of-blog-posts-with-comments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!