如何实现嵌套注释系统?

时间:2023-01-28 14:31:05

What would be the ideal way to implement this sort of thing? The idea I have in my head right now is to have a comments table and have each comment have a thread identifier and parent comment identifier. The thread identifier would indicate to which thread the comment belongs to and would allow for a simple MySQL statement using the WHERE clause. Each comment would have an auto_increment identifier as per usual database design and the parent identifier column would indicate which comment this comment is a child of.

实现这类事情的理想方式是什么?我现在脑子里想的是有一个评论表,每个评论都有一个线程标识符和父评论标识符。线程标识符将指示注释所属的线程,并允许使用WHERE子句的简单MySQL语句。根据通常的数据库设计,每个注释都有一个auto_increment标识符,而父标识符列将指示该注释是其子项的注释。

This type of design would put most of the stress on the PHP aspect of things because it would only be one SQL call to get all comments from a thread. Another implementation I found was having an SQL query for each nesting level. This solution would place the stress on the SQL sides of things.

这种类型的设计会将大部分压力放在PHP方面,因为它只是一个SQL调用来获取线程的所有注释。我发现的另一个实现是为每个嵌套级别提供SQL查询。这个解决方案会把压力放在事物的SQL方面。

How would SO implement this? Currently I'm at a loss because I am not sure which solution is the "best" solution and I am still quite new to database design, PHP, and JQuery.

如何实现这一点?目前我很茫然,因为我不确定哪种解决方案是“最佳”解决方案,而且我对数据库设计,PHP和JQuery还是一个新手。

Thanks.

1 个解决方案

#1


6  

Look at Managing Hierarchical Data in MySQL, specifically the section called "Nested Set Model". You may have to read through it a few times before it makes sense (I did) but it's worth it. It's a very powerful way to work with nested data and retrieve the parts you want with only one query.

查看MySQL中的Managing Hierarchical Data,特别是“嵌套集模型”一节。在它有意义之前你可能需要阅读几次(我做过),但这是值得的。这是一种非常强大的方法,可以使用嵌套数据并仅使用一个查询检索所需的部分。

On the downside, for updates you have to do a lot more work.

在缺点方面,对于更新,您必须做更多的工作。

#1


6  

Look at Managing Hierarchical Data in MySQL, specifically the section called "Nested Set Model". You may have to read through it a few times before it makes sense (I did) but it's worth it. It's a very powerful way to work with nested data and retrieve the parts you want with only one query.

查看MySQL中的Managing Hierarchical Data,特别是“嵌套集模型”一节。在它有意义之前你可能需要阅读几次(我做过),但这是值得的。这是一种非常强大的方法,可以使用嵌套数据并仅使用一个查询检索所需的部分。

On the downside, for updates you have to do a lot more work.

在缺点方面,对于更新,您必须做更多的工作。