The first one is as follows: given a sequence of properties that specify a path, I should return the the end node. i.e.
start r=node(0)
match r<-[:R]-({n:"aaa"})<-[:R]-({n:"bbb"})<-[:R]-(x {n:"ccc"})
return x as node
And the second one is kind of opposite: given a node's identifier (for simplicity suppose it is the node's ID), return the path (sequence of properties name
) from the root to the node (it's guaranteed to be unique). As for now, I'm just using the shortestPath
:
start n=node(1000), root = node(0)
match p = shortestPath(root<-[:R*]-n)
return
reduce(fullpath = '', pt IN nodes(p) | fullpath + pt.n)
as path
The queries are run from embedded database and aren't satisfying me with their speed, so I'd like to have them translated into TraversalDescription
s, but they should change dynamically, and I don't quite understand how to do this.
Or maybe these queries aren't optimal? The one with the shortestPath
runs for <= 1ms, while the one with variable length runs for 10ms per single query (that's unacceptable). Maybe you have some performance tips for me?