邻接列表模型或嵌套集模型,我应该使用哪种数据模型来存储层次结构数据?
我必须将我的网络应用程序从 Twitter 获取的消息存储到本地数据库中。存储消息的目的是我需要以分层顺序显示这些消息,即用户通过我的应用程序输入的某些消息(即状态更新)是其他消息的子节点(我必须将它们显示为父消息的子列表项) )。我应该使用邻接列表模型或嵌套集模型哪种数据模型?我必须管理四种类型的消息和消息每个类别中的消息可以有两个子节点。这里还有一个问题是,我在这两种情况下看到(意识到)输入是手动控制的,即如何在嵌套列表中给出对邻接模型中的父节点或右、左节点的引用。我的应用程序从 Twitter 获取消息数据,如下所示:
foreach ($xml4->entry as $status4) {
echo'<li>'.$status4->content.'</li>';
}
所以它没有手册,可以随时获取任意数量的消息。我怎样才能在它的消息之间建立父子关系。目前,用户在不同的窗口中输入消息,对应于四种类型的消息,我的应用程序添加了关键字和消息。将它们取回并显示在差异窗口中。所有这些消息目前都是父消息。现在我如何让用户输入一条消息,该消息可以作为另一个消息的子项保存到数据库中。
I have to store messages that my web app fetch from Twitter into a local database. The purpose of storing messages is that I need to display these messages in a hierarchical order i.e. certain messages(i.e. status updates) that user input through my application are child nodes of others (I have to show them as sub-list item of parent message). Which data model should I use Adjacency List Model OR Nested Set Model? I have to manage four types of messages & messages in each category could have two child node. One more question here is that what I see(realize) in both cases that input is controlled manually that is how reference to parent node in adjacency model or right, left are given in Nested List. My app fetch messages data from twitter like:
foreach ($xml4->entry as $status4) {
echo'<li>'.$status4->content.'</li>';
}
So its no manual, any number of messages can be available anytime. How could I make a parent child relation among messages from it. At the moment, users enter messages in different windows that correspond to four types of messages, my app adds keywords & fetches those back to display in diff windows. All those messages are at the moment parent messages. Now how I make user enter a messages that could be saved into database as child of another.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://dev.mysql.com/tech-resources/articles/hierarchical -data.html
如果您将拥有或多或少深的数据树(从每个根节点开始),请考虑使用嵌套集,因为 AL 会很慢。
http://dev.mysql.com/tech-resources/articles/hierarchical-data.html
If you are going to have more or less deep trees of data (starting from each root node) consider using nested set, because AL will be slow.
当你说
我很困惑。
如果两个子节点中的每一个都可以有更多子节点,那么您所考虑的不是深度,而是节点分支的宽度。
1) 深度确实 = 2
如果你的最大深度确实是 2(换句话说,所有节点都连接到根节点,或者分两步连接到零级节点;但换句话说,对于每个节点来说,没有其他祖先,然后是父母和祖父母)那么你甚至可以直接使用关系模型来存储分层数据(通过自连接,这在最大深度如此低的情况下还不错,或者将数据分成3个实体 - 祖父母,父母和孩子)
2)深度>> 2
如果数字 2 是宽度,深度是可变的并且可能相当深,那么看看嵌套集,还有两种额外的可能性来探索
When you say
i get confused.
If each of the two child nodes can have more children then you are not taking about depth, but width of a branch of a node.
1) depth really = 2
If your max depth is really 2 (in another words, all nodes connect to root, or zero level nodes in 2 steps; yet in another words, for each node there is no other ancestor then parent and grandparent) then you could even use relational model directly to store hierarchical data (either through self join, which is not so bad with such low maximum depth or by splitting the data into 3 entities - grandparents, parents and children)
2) depth >> 2
If number 2 was the width and the depth is variable and potentially quite deep then look at nested sets, with two additional possibilities to explore