nested-sets

Dealing with nested sets in mysql?

最后都变了- 提交于 2019-11-30 20:10:26
I have decided to follow http://www.artfulsoftware.com/mysqlbook/sampler/mysqled1ch20.html So now I am looking for some help with the code. I am using their data for my testing, So, I visualized the tree being like so: array('value' => 'Richard Shakespeare', array('value' => 'Henry', array('value' => 'Joan'), array('value' => 'Margaret'), array('value' => 'William', array('value' => 'Susana', array('value' => 'Elizabeth Hall', array('value' => 'John Bernard'))), array('value' => 'Hamnet'), array('value' => 'Judith', array('value' => 'Shakespeare Quiney'), array('value' => 'Richard Quiney'),

Move node in Nested Sets tree

偶尔善良 提交于 2019-11-30 14:19:14
问题 I am working on an adjacency list with mySQL and can not (atleast by myself) do the thinking needed to make a decent enough query to be able to move a set of nodes (together with eventual children nodes) around. The table has following columns: id name left right Thanks a lot! 回答1: I'm pretty sure that table is using the Nested Sets design, not Adjacency List. If it were using Adjacency List, it would have a column like parent_id instead of left and right . Moving nodes is royal PITA in

How to repair a corrupted MPTT tree (nested set) in the database using SQL?

主宰稳场 提交于 2019-11-30 10:41:32
问题 I have an MPTT tree of over 100,000 records stored in MySQL using lft , rght and parent_id columns. Now the left/right values became corrupted, while the parent ids are still intact. It would require tons of queries to repair it in the application layer. Is there a good way to put the burden on the database and have it recalculate the left/right values using only SQL? Just to clarify, I need to recalculate the numeric lft/rght values of a nested set, not the ids of neighboring records.

Dealing with nested sets in mysql?

左心房为你撑大大i 提交于 2019-11-30 04:05:48
问题 I have decided to follow http://www.artfulsoftware.com/mysqlbook/sampler/mysqled1ch20.html So now I am looking for some help with the code. I am using their data for my testing, So, I visualized the tree being like so: array('value' => 'Richard Shakespeare', array('value' => 'Henry', array('value' => 'Joan'), array('value' => 'Margaret'), array('value' => 'William', array('value' => 'Susana', array('value' => 'Elizabeth Hall', array('value' => 'John Bernard'))), array('value' => 'Hamnet'),

Mysql: Optimizing finding super node in nested set tree

荒凉一梦 提交于 2019-11-30 02:25:12
I have hierarchical data in a nested set model (table:projects): My table (projects): id, lft, rgt 1, 1, 6 2, 2, 3 3, 4, 5 4, 7, 10 5, 8, 9 6, 11, 12 7, 13, 14 ... Pretty printed: 1 2 3 4 5 6 7 To find the nearest super node of node 3 (knowing its lft value), i can do explain SELECT projects.* FROM projects WHERE 4 BETWEEN projects.lft AND projects.rgt Which gives me a list of the projects in the path down to node 3. Then by grouping and finding MAX(projects.lft) of the results, i get the nearest super node. However, I cannot seem to get this query to run fast, it wont use the indexes i've

BIGINT Out-of-range Error since MySQL 5.5

邮差的信 提交于 2019-11-29 14:06:11
I'm working with nested sets for my CMS but since MySQL 5.5 I can't move a node. The following error gets thrown: Error while reordering docs:Error in MySQL-DB: Invalid SQL: SELECT baum2.id AS id, COUNT(*) AS level FROM elisabeth_tree AS baum1, elisabeth_tree AS baum2 WHERE baum2.lft BETWEEN baum1.lft AND baum1.rgt GROUP BY baum2.lft ORDER BY ABS(baum2.id - 6); error: BIGINT UNSIGNED value is out of range in '( lektoren . baum2 . id - 6)' error number: 1690 Has anyone solved this Problem? I already tried to cast some parts but it wasn't successful. Ben BIGINT UNSIGNED is unsigned and cannot be

Are nested intervals a viable solution to nested set (modified pre-order traversal) RDBMS performance degredation?

别说谁变了你拦得住时间么 提交于 2019-11-29 07:54:39
问题 Among the known limitations of Joe Celko's nested sets (modified pre-order traversal) is marked degredation in performance as the tree grows to a large size. Vadim Tropashko proposed nested intervals, and provides examples and theory explanation in this paper: http://arxiv.org/html/cs.DB/0401014 Is this a viable solution, are there any viable examples (in any language) abstracted away from the native DB layer? 回答1: While I've seen examples for nested sets, I haven't seen much for nested

How to repair a corrupted MPTT tree (nested set) in the database using SQL?

纵然是瞬间 提交于 2019-11-28 17:57:12
问题 I have an MPTT tree of over 100,000 records stored in MySQL using lft , rght and parent_id columns. Now the left/right values became corrupted, while the parent ids are still intact. It would require tons of queries to repair it in the application layer. Is there a good way to put the burden on the database and have it recalculate the left/right values using only SQL? Just to clarify, I need to recalculate the numeric lft/rght values of a nested set, not the ids of neighboring records.

How do you convert a parent-child (adjacency) table to a nested set using PHP and MySQL?

∥☆過路亽.° 提交于 2019-11-28 16:34:29
I've spent the last few hours trying to find the solution to this question online. I've found plenty of examples on how to convert from nested set to adjacency... but few that go the other way around. The examples I have found either don't work or use MySQL procedures. Unfortunately, I can't use procedures for this project. I need a pure PHP solution. I have a table that uses the adjacency model below: id parent_id category 1 0 Books 2 0 CD's 3 0 Magazines 4 1 Books/Hardcover 5 1 Books/Large Format 6 3 Magazines/Vintage And I would like to convert it to a Nested Set table below: id left right

Searching for the best PHP nested sets class (PEAR class excluded)

耗尽温柔 提交于 2019-11-28 07:50:04
I'm looking for a PHP (with MYSQL) nested sets class with all needed functions. For example: createLeftNode, createRightNode,createRootNode, createSubNode,deleteNode and moveTree . Not only 1 left, 1 right, 1 up and 1 down but also a part of a tree in a nother tree. Thanks! Well nested sets are great if you are working with hierarchical data. It's much more complex to implement it only with php arrays especially if you want to save these information in a database. you could try this on. Never used it but after a short code screening it looks almost complete. http://www.edutech.ch/contribution