简体   繁体   中英

Gremlin: Find all downstream (out) paths from given Vertex

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM