ArangoDB : How to get all the possible paths betwe

2019-03-02 09:43发布

问题:

How to get all the possible paths between 2 vertices (eg. X and Y) with maxDepth = 2?

I tried with TRAVERSAL but it is taking around 10 seconds to execute. Here is the query :

FOR p IN TRAVERSAL(locations, connections, "X", "outbound", { minDepth: 1, maxDepth: 2, paths: true }) 
FILTER p.destination._key == "Y" 
RETURN p.path.vertices[*].name

The locations (vertices) collection has 23753 documents, and the connections (edges) collection has 123414 documents.

回答1:

You can speed up the query a lot if you put the filter for destination right into Traversal via the options filterVertices to give examples of vertices that should be touched by the traversal. With vertexFilterMethod you can define what should happen with all vertices that do not match the example.

So in your query you only want to match the target vertex "Y" and all other vertices should be passed through but not included in the result, exclude.

This makes the later FILTER obsolete. Right now the internal optimizer is not able to do that automagically but this magic is on our roadmap.

This is a query containing the optimization:

FOR p IN TRAVERSAL(locations, connections, "X", "outbound", { minDepth: 1, maxDepth: 2, paths: true, filterVertices: [{_key: "Y"}], vertexFilterMethod: ["exclude"]})
RETURN p.path.vertices[*].name


标签: arangodb aql