Dave Zabriskie
Dave Zabriskie

Reputation: 180

Most optimal gremlin query for getting all related vertices

I need to get all the vertices related by any number of relationships to the starting vertex. I have a working query, but it starts to slow significantly after a few hundred edges and the complexity of the graph. Is there any more efficient way of getting the related vertices?

g.V(id)
 .emit()
 .repeat(both())
 .until(cyclicPath())
 .unfold()
 .dedup()
 .toList()

An example in the breakdown in performance was noticed for a subgraph with 202 vertices, 259 edges. After running a profile, it seems to have issued 1,444,439 traversals, taking around 80s.

Additional info: This comes from running using AWS Neptune 1.0.1.0.200258.0

Upvotes: 1

Views: 448

Answers (1)

Daniel Kuppitz
Daniel Kuppitz

Reputation: 10904

Looks like you only want to find all vertices that are somehow connected to the initial vertex. Try this query (it doesn't enable path tracking and thus should be much faster):

g.V(id).emit().repeat(both().dedup())

Upvotes: 3

Related Questions