ArangoDB : How to get all the possible paths between 2 vertices?

旧时模样 提交于 2019-12-02 05:36:12

问题


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


来源:https://stackoverflow.com/questions/29677086/arangodb-how-to-get-all-the-possible-paths-between-2-vertices

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!