使用 Gremlin 查询语言:查找从给定顶点开始的所有下游(出边)路径。

huangapple go评论75阅读模式
英文:

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

问题

我有一个包含约1000个顶点和3000条边的有向图,其中包含循环。

我试图找出从给定顶点出发的所有下游(出站)路径。

当使用以下Gremlin查询时:

g.V(45712).repeat(out().simplePath()).until(outE().count().is(0)).path()

对于某些路径,由于存在循环,获取结果可能需要很长时间,尽管 simplePath 步骤应该可以防止这种情况。

我尝试通过使用 aggregate 步骤和 without 来优化查询,以便不重复遍历相同的顶点,但现在有些顶点被跳过了。

g.V(45712).repeat(out().where(without('x'))
.aggregate(Scope.local,'x'))
.until(outE().count().is(0))
.path()
英文:

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

答案1

得分: 3

如果您的数据高度相互连接,那可能是一个昂贵的查询。即使是在一个小图中。我曾经看到人们使用约束来尝试限制总搜索量。这些约束可以包括使用 timesloops 来设置最大搜索深度。即使是在我的航线数据集中,这是一个相当小的图,那个查询可能会产生一个非常大的结果集。问题不是您的 Gremlin 查询有问题。更多取决于顶点之间的连接程度。

总的来说,在一般情况下,从给定的起点搜索所有路径可能是一个昂贵的查询。

英文:

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.

huangapple
  • 本文由 发表于 2020年9月11日 23:42:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/63850251.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定