Reputation: 1496
I have a directed graph with around 1000 vertices and 3000 edges that contains cycles.
I am trying to find all downstream (out) paths from given Vertex.
When using following Gremlin query
g.V(45712).repeat(out().simplePath()).until(outE().count().is(0)).path()
For some paths it takes forever to get the result because of the cycles, although the simplePath
step should prevent this.
I tried to optimize the query and not go over the same Vertex twice using aggregate
step and without
, but now some Vertices are being skipped.
g.V(45712).repeat(out().where(without('x'))
.aggregate(Scope.local,'x'))
.until(outE().count().is(0))
.path()
Thanks
Upvotes: 1
Views: 744
Reputation: 14391
If your data is highly connected, that can be an expensive query. Even with a small graph. I have seen people use constraints to try and restrict the total amount of searching. These could include using times
or loops
to set a maximum search depth. Even with my air-routes data set, which is really quite a small graph, that query could yield a very large result set. It's not so much that your Gremlin is wrong. It's more going to depend on how connected the vertices are.
Searching for all paths from a given start in general is likely to be expensive query.
Upvotes: 2