We have a requirement to clone a tree from a given root node into exactly the same tree structure from a newly created Root node. The cloned tree only has to traverse down to level "n" and only traverse certain relationships.
Does anyone have any suggestions for the most efficient way of doing this? Our initial experiments have taken somewhere in the region of "minutes" and have put a medium-large load on the server.
If so, then it would help to know what's going on in the query, and I'd request you PROFILE your query and add the query plan (after expanding all elements of the plan) to your question.
I think this gets messy, as the cloned relationships attach to all outside nodes as well as to the original nodes, leaving an exercise for the caller on how to delete all the relationships between the clones and the originals.
I've added an APOC feature request for a new procedure apoc.refactor.cloneSubgraph() that is aimed at this particular use case: cloning nodes and the relationships between them, only creating relationships between the clones and not to any of the originals, and allowing a means to define a replacement or standin for nodes when it comes to relationship creation. For this example, it could be used to clone a branch and attach the branch to a different root node instead of the old root (or instead of cloning the old root).