使用Mysql实现的投票系统(带账户)的性能PHP
我目前正在创建一个投票系统,其中包含好的和坏的评论选项。基本上,这个想法就像 Facebook 的想法一样,但有一个糟糕的评论选项(或更多)。这是表结构
id | comment_id | voter_id | voter_option
所以,一旦用户投票,一条记录将以上述格式存储在mysql数据库中,为什么我这样做是因为我不希望用户重新投票,并且想记录他们喜欢/不喜欢什么。
我的问题是,我想,如果我的网站上有 10,000 条评论,每个评论都有 1,000 票,那么我的数据库就会变得非常大,有什么好的方法(可能是例子)来防止数据库变得太大?或者我需要为我的案例中的每条评论创建一个表格,提前致谢。
I'm currently creating a voting system with good and bad option for a comment. Basically, the idea is like facebook's one, but have a bad option(or more) for the comment. Here is the table structure
id | comment_id | voter_id | voter_option
So, once the user vote it, a record will be store in the mysql database on the above format, why I'm doing this is because I don't want the user re-vote, and want to record what they like/dislike.
my question is, I think, if there have 10,000 comments in my website, and each comments got 1,000 votes, then my database is become very large, are there any good method(example maybe) to prevent the database become too large? Or I need to create a table for each comments in my case, thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的评论表是什么样的?如果有很多帖子,数据库只会变得很大,如果你查询正确并且你的表大小合理,那么表中的 10,000 个条目对于 mysql 来说是幼稚的。
就性能而言,当有人喜欢/不喜欢评论时,您可能会对所有投票进行统计并将该值存储在评论行中,这样当您查询评论时,您将获得其最后已知的像/dislike 计数,不必在每次查询评论时都进行计数。
编辑:我应该添加,确保您的索引是整数(根据它们的列名判断)并且您使用外键进行数据限制。使用外键,您可以保持表干净,例如,如果有人删除评论,您可以告诉表根据该 id 删除级联,这样评论就会被删除,该评论的所有投票都会从其他评论中删除桌子。 http://en.wikipedia.org/wiki/Foreign_key
What does your comments table look like? The database will only get large if there's many posts, 10,000 entries in a table is childsplay for mysql if you query correctly and your table is a sane size.
Performance wise, it may be an idea that when someone likes/dislikes a comment, you do a tally of all the votes and store that value in the comment row, this way when you query out the comment you'll have its last known like/dislike count and don't have to do that counting each time you query for comments.
Edit: I should add, make sure your indexes are ints (judging by the column names they are) and you're using foreign keys for data restraints. With foreign keys you can keep your tables clean, for example, if someone deletes a comment you can tell your tables to delete cascade, based on that id, so the comment gets deleted, all of the votes for that comment get deleted from the other table. http://en.wikipedia.org/wiki/Foreign_key