1

We heavily use the tree doctrine extension in our zf2 project - with some big tree data structures. We know that inserts and updates in a nested set are expensive. We also know that the tree plugin uses the "root" column to find out which tree shall be updated.

Yesterday I read the tree documentation again and found: "Support for multiple roots in nested-set" What does it mean and how does it work? I couldn't find any documentation for this feature.

Our hope would be that we could define a second root item of a lower branch of a big tree so that inserts and updates into this lower branch will not affect the whole tree but only this branch. Is it possible?

1 Answers1

1

yes it is possible, tree root branches will be separated by level 0 nodes, see mapping example of TreeRoot column there should be examples for all mapping types to map treeRoot column. The column must be of the same type as ID, it does not support a ManyToOne relation for now, but there is a plan someday to support it.

root1
    child
root2
    child
        child2

When updating or inserting any child on root2 or root1 branch, it will affect only that certain branch. Also note that, tree is still not concurrently safe, you have to manage locking yourself, see documentation reference here.

The doc directory contains most of the information given here.

Gediminas
  • 868
  • 7
  • 11
  • What you are talking about is that what we already do. In your example, I suppose, "child" of "root1" and "child" of "root2" are not the same instance, because on child can only have one parent. Am I correct? – Martin Zeller Aug 12 '15 at 11:34
  • What I meant was if one child could have multiple roots. Because I thought of a structure like that: - root1 -- child1 --- child3 -- child2 --- child4 In this case the "root" column of all elements would have the ID of "root1". Here I thought that "child2" should be a "root" element for child4, so that an insert of a new child below "child2" would only affect the "lft" and "rgt" columns of the elements below "child2" - and not of all elements of "root1" - just to speed up the updates. Do you understand what I mean? – Martin Zeller Aug 12 '15 at 11:44
  • OK, I misunderstood the question, that is not supported. guess the best option for you would be to migrate to custom strategy for tree storage, which you should choose based on your needs, if sorting is not necessary probably a closure tree would be a good option, though implemented manually. – Gediminas Aug 13 '15 at 12:14