社交网站的数据库设计。帮助!

发布于 2024-11-17 18:10:46 字数 1418 浏览 2 评论 0原文

我正在寻找一种解决方案,以最有效的方式为社交网站设计表(使用 mySQL)。这是我当前的表格设置:

User_ID  Peer_ID   Message   
001      002       msg from 001 to 002
001      003       msg from 001 to 003
001      004       msg from 001 to 004
001      005       msg from 001 to 005
002      001       msg from 002 to 001
002      003       msg from 002 to 003
002      004       msg from 002 to 004
002      005       msg from 002 to 005
003      001       msg from 003 to 001
003      002       msg from 003 to 002
003      004       msg from 003 to 003
003      005       msg from 003 to 005
and so on...

(最多大约 10,000 名成员,每个成员有 9,999 条消息。即 1 亿行)

我知道规范化的首要规则之一已被破坏,因为 User_ID 列具有重复值。
我宁愿为 User_ID 有一个唯一的键索引列,并在新用户注册时使用 Auto_Increment,从而形成矩阵格式。 IE。列中的 User_ID &标题行中的 Peer_ID。
然而,在这种情况下,最多需要 10,000 列(对于每个 Peer_ID),并且无法在新用户注册时自动生成新列。见下文:

User_ID  001             002             003             004            005
001      NA              msg:001 to 002  msg:001 to 003  msg:001 to 004 msg:001 to 005
002      msg:002 to 001  NA              msg:002 to 003  msg:002 to 004 msg:002 to 005
003      msg:003 to 001  msg:003 to 002  NA              msg:003 to 004 msg:003 to 005
004      msg:004 to 001  msg:004 to 002  msg:004 to 003  NA             msg:004 to 005
005      msg:005 to 001  msg:005 to 002  msg:005 to 003  msg:005 to 004 NA
and so on...

关于如何创建更高效​​的表格设计有什么想法吗?
提前致谢...

I'm looking for a solution to design a table (using mySQL) for a social networking site in the most efficient way. Here is my current table set-out:

User_ID  Peer_ID   Message   
001      002       msg from 001 to 002
001      003       msg from 001 to 003
001      004       msg from 001 to 004
001      005       msg from 001 to 005
002      001       msg from 002 to 001
002      003       msg from 002 to 003
002      004       msg from 002 to 004
002      005       msg from 002 to 005
003      001       msg from 003 to 001
003      002       msg from 003 to 002
003      004       msg from 003 to 003
003      005       msg from 003 to 005
and so on...

(up to approx 10,000 member with 9,999 messages to each respective member. ie 100 Mil rows)

I'm aware that one of the first rules of normalization is broken as the User_ID column has repeating values.
I would rather have a unique key index column for the User_ID and utilize Auto_Increment for when a new user registers, resulting in a matrix format. ie. User_ID in a column & Peer_ID in header row.
However in this case up to 10,000 columns would be required (for each Peer_ID) and no way of auto generating a new column as new users register. See below:

User_ID  001             002             003             004            005
001      NA              msg:001 to 002  msg:001 to 003  msg:001 to 004 msg:001 to 005
002      msg:002 to 001  NA              msg:002 to 003  msg:002 to 004 msg:002 to 005
003      msg:003 to 001  msg:003 to 002  NA              msg:003 to 004 msg:003 to 005
004      msg:004 to 001  msg:004 to 002  msg:004 to 003  NA             msg:004 to 005
005      msg:005 to 001  msg:005 to 002  msg:005 to 003  msg:005 to 004 NA
and so on...

Any ideas on how I can create a more efficient table design?
Thank in advance...

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

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

发布评论

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

评论(2

盗琴音 2024-11-24 18:10:46

您的第一个表设计很好,从行到行重复值没有任何问题。我认为您误解了重复组的概念,它指的是列到列的重复。 (您的第二个设计采用的。)

请参阅 http://en.wikipedia.org/wiki/First_normal_form

You first table design is fine, there's nothing wrong with repeating values from row-to-row. I think you're misunderstanding the concept of repeating groups, which refers to column-to-column repeats. (Which your second design employs.)

See http://en.wikipedia.org/wiki/First_normal_form

也只是曾经 2024-11-24 18:10:46

我做过一个消息系统。如果你想让它像 Gmail 和 Facebook 中的对话一样,这很有趣。

您是否计划在单个对话中显示消息?如果没有,那就非常简单了。

您只需要多一些文件即可。已读/未读标志和日期/时间。

I've done one messaging system. It's interesting if you want to make it like conversation in Gmail and Facebook.

Do you have plan to show messages in a single conversation? If not, it's pretty straight-forward.

You just need a coupole of fileds more. Read/Unread flag and Date/Time.

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