[sqlalchemy] Re: Adjacency List tree - inefficient reading
We have a proof of concept for nested sets in the /examples folder. However what I cant figure out with nested sets is, how do I load only the immediate children of a node ?That is the most common accessor I'd like on a self referential node and I'm not aware of how to do it. It makes it sort of impossible for there to be a .children accessor on a node, unless you load the full subtree and organize. On Jan 18, 2009, at 1:33 PM, Kless wrote: SQA recommends the adjacency list pattern [1] over another patterns: Despite what many online articles say about modified preorder, the adjacency list model is probably the most appropriate pattern for the large majority of hierarchical storage needs, for reasons of concurrency, reduced complexity, and that modified preorder has little advantage over an application which can fully load subtrees into the application space. But should be in mind that it's slow in reads (althought it's fast in writes). In change, the nested sets have very efficient reads at the cost of high maintenance on write/delete operations. If any is interested in tree structures, there is an excelent implementation for django ORM, django-treebeard [2], which has included any benchmarks where you can see the reading differences between different structures. [1] http://www.sqlalchemy.org/docs/05/mappers.html#adjacency-list-relationships [2] http://code.google.com/p/django-treebeard/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Adjacency List tree - inefficient reading
The author of django-treebeard created the ns-tree implementation based on Joe Celko as SQAlchemy's [1]. Here is its implementation [2]. I hope that helps. [1] http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/examples/nested_sets/nested_sets.py [2] http://code.google.com/p/django-treebeard/source/browse/trunk/treebeard/ns_tree.py On 18 ene, 18:47, Michael Bayer mike...@zzzcomputing.com wrote: We have a proof of concept for nested sets in the /examples folder. However what I cant figure out with nested sets is, how do I load only the immediate children of a node ? That is the most common accessor I'd like on a self referential node and I'm not aware of how to do it. It makes it sort of impossible for there to be a .children accessor on a node, unless you load the full subtree and organize. On Jan 18, 2009, at 1:33 PM, Kless wrote: SQA recommends the adjacency list pattern [1] over another patterns: Despite what many online articles say about modified preorder, the adjacency list model is probably the most appropriate pattern for the large majority of hierarchical storage needs, for reasons of concurrency, reduced complexity, and that modified preorder has little advantage over an application which can fully load subtrees into the application space. But should be in mind that it's slow in reads (althought it's fast in writes). In change, the nested sets have very efficient reads at the cost of high maintenance on write/delete operations. If any is interested in tree structures, there is an excelent implementation for django ORM, django-treebeard [2], which has included any benchmarks where you can see the reading differences between different structures. [1]http://www.sqlalchemy.org/docs/05/mappers.html#adjacency-list-relatio... [2]http://code.google.com/p/django-treebeard/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Adjacency List tree - inefficient reading
On 18 Sty, 19:47, Michael Bayer mike...@zzzcomputing.com wrote: However what I cant figure out with nested sets is, how do I load only the immediate children of a node ? That is the most common accessor I'd like on a self referential node and I'm not aware of how to do it. It makes it sort of impossible for there to be a .children accessor on a node, unless you load the full subtree and organize. It is possible if you add a 'depth' column which holds the absolute distance of the node from the tree root. Then, in order to load immediate children of a node, we can make a query: SELECT * FROM nodes WHERE lft node.lft and rgt node.rgt and depth=node.depth+1 Best regards, Adam --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Adjacency List tree - inefficient reading
On Jan 18, 2009, at 1:33 PM, Kless wrote: If any is interested in tree structures, there is an excelent implementation for django ORM, django-treebeard [2], which has included any benchmarks where you can see the reading differences between different structures. [1] http://www.sqlalchemy.org/docs/05/mappers.html#adjacency-list-relationships [2] http://code.google.com/p/django-treebeard/ also of note is that the django adjacency list example does not use joins to load multiple levels of parent/child nodes at once.. SQLAlchemy's relation() function (which means relationship, the name's conflict with the relational term is an historic artifact) supports automatic rendering of self-referential joins which can dramatically decrease the number of round trips needed to load multiple levels of tree nodes. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---