如何设计问答数据库(MySql)

发布于 2024-07-13 21:20:47 字数 253 浏览 6 评论 0原文

我需要为论坛设计一个数据库。 由于各种原因,我将根帖子与其子帖子分开。 我需要用户输入的文本能够最佳地搜索,从性能的角度来看也是如此。

我的问题是,我应该将每个表(根帖子和子帖子)分成两个表:
root-posts_meta(保存 id、创建时间、浏览次数等数据......)
root-posts_data (id,title,body) 以全文索引

与 sub-posts 表的思路相同。

谢谢。

I need to design a DB for a forum. I am separating the root post from it's sub-posts for various reasons. I need the text the user enters to be optimally search-able, also from performance point of view.

My question, should I separate each table (root-posts and sub-posts) into two tables:
root-posts_meta (hold data such as id,creation time,views,....)
root-posts_data (id,title,body) indexed with full-text

The same idea with the sub-posts table.

Thanks.

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

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

发布评论

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

评论(8

从﹋此江山别 2024-07-20 21:20:47

分离不会影响其可搜索性或搜索性能。 如果这是您唯一关心的问题,您不妨将每个表保留为一张桌子。

The separation isn't going to affect its searchability or search performance. If that's your only concern, you may as well leave each as a single table.

乱了心跳 2024-07-20 21:20:47

正如其他人所说,不要分开桌子。 它没有任何好处,实际上还有性能上的缺点。 添加另一个表意味着它只是您的查询在渲染页面时必须执行的另一个表连接。

As the others have said, don't separate the tables. It has no benefit, and it actually has the disadvantage of performance. Adding another table means it's just another table join your query has to do when rendering a page.

焚却相思 2024-07-20 21:20:47

当我做类似的事情时,我将线程数据放在一个表中,并将帖子数据(包括根帖子)放在另一个表中。 在回答你的问题之前,我必须问你,你真的确定需要将root和sub分开吗?

如果您想坚持根子分离,我认为进一步分离它们不会获得任何好处。

When I made simmilar thing, I've put thread data in one table, and post data (including root posts) in other. Before answering you question, I must ask you, are you really sure you need to separate root and sub?

If you want to stick with root-sub separation, I don't think you will gain anything by separating those even further.

回眸一笑 2024-07-20 21:20:47

无论如何,TEXT 字段都存储在行外。

分离表既不会提高查询的可读性,也不会提高查询的性能。

你最好把它放在一张桌子上。

TEXT fields are stored out of row anyway.

Separating the tables will improve neither readabitily nor performance of your queries.

You better keep it in one table.

初熏 2024-07-20 21:20:47

基本上,在常规论坛应用程序中,根消息和子消息本质上几乎是相同的。 如果您确实想要获得有关新线程启动的一些特殊信息,则可能需要一个名为“线程”的单独表,以及消息表中属于该线程的所有消息。 对于根消息,消息本身的parent_msg_id 可以为null,如果是回复,则可以为另一条消息的id。
像这样:

thread:
- thread_id
- started_ts
- author (long live redundancy!)
- other columns

message:
- message_id
- thread_id (reference to thread-thread_id)
- parent_msg_id (nullabel reference to message.message_id)
- body, author, timestamp etc

Basically root messages and sub messages are pretty much the same thing in nature in a regular forum application. If you really want to have some special information about the start of a new thread, you might want to have a seperate table called thread, and all messages belonging to that thread in the message table. The messages themselves can have a parent_msg_id of null for root messages, or the id of another message if they are replies.
Like this:

thread:
- thread_id
- started_ts
- author (long live redundancy!)
- other columns

message:
- message_id
- thread_id (reference to thread-thread_id)
- parent_msg_id (nullabel reference to message.message_id)
- body, author, timestamp etc
恰似旧人归 2024-07-20 21:20:47

规范化是将数据分成更小的部分,从而创建更好的设计。 不幸的是,单独的表意味着更多的联接,并且联接对性能不利。 因此,您最终会对架构进行反规范化以提高以后的性能。

我建议将这些东西放在同一张表中。

仅当事物确实完全不同时才将它们放在不同的表中,而不仅仅是略有不同,或者您觉得将它们分开会很好。

Normalizing is about splitting the data up into smaller pieces, which creates a better design. Unfortunately separate tables means more joins and joins are bad for performance. So, you end up de-normalizing your schema to improve performance later.

I would suggest keeping those things in the same table.

Only put things in different tables if they really are completely different, not just slightly different or you feel like it would be nice to separate them.

白日梦 2024-07-20 21:20:47

由于 InnoDB 没有 FULLTEXT 支持,并且如果需要某种事务支持,则无法绕过这种分离。
mysql-fulltext

详细解释:
InnoDB没有全文,MyIsam没有TX支持。
以SO为例。 每个问题实体都有投票数、更新它的用户、更改历史记录(在我的系统中我还有很多其他东西,让我们不讨论我所做的业务逻辑)。
其中许多字段必须在实体的生命周期内与其他表中的其他更改(即一个事务下的更改)一起更改,并且我需要数据字段的全文支持。

Since InnoDB has no FULLTEXT support, and if some kind of transaction support is needed, then there is no way around this separation.
mysql-fulltext

Elaborate explanation:
InnoDB does not have full text, MyIsam has no TX support.
Take for example SO. Each question entity has number of votes, users updating it, history of changes (In my system I have many other things, let's not go into the business logic of what I do).
Many of those fields has to change over the life time of the entity in conjunction with other changes in other tables (i.e. changes under one transaction), And I need the full-text support on the data fields.

月下伊人醉 2024-07-20 21:20:47

如果事务支持对您很重要,那么您仍然可以使用一张表来存储数据,并使用类似 Sphinx用于全文搜索。

If transaction support is important to you, then you could still use one table for data and have something like Sphinx for fulltext search.

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