为什么我的 Gremlin 查询会导致如此多的请求?这是正确的行为吗?
Why is my Gremlin query resulting in so many requests? Is this correct behavior?
我正在尝试调试 AWS Neptune 遇到的性能问题。我是 运行 一些 Gremlin 查询,它们似乎总是在数据库上产生 30 个请求。我想知道我的查询是否做错了。
这个问题的奇怪之处在于它是突然发生的。以前,这工作得很好,我们没有遇到性能问题。
我做的每个调用都有两个一般查询,一个针对节点,一个针对边:
nodes = g.V(id).emit().repeat(__.out('manages')).dedup().project('label', 'name', 'job', 'department', 'manager').\
by(__.id()).by('name').by('job').by('department').by('manager').toList()
id_list = list(map(lambda node: node["label"], nodes))
edges = g.V(id).emit().repeat(__.out('manages')).dedup().bothE('similar_to').dedup().\
where(__.and_(__.inV().has(T.id, P.within(id_list)), __.outV().has(T.id, P.within(id_list)))).\
project('from', 'to', 'similarity').by(__.outV().id()).by(__.inV().id()).by('similarity').toList()
基本上,我有两种边缘类型:管理和 similar_to。我尝试使用 'manages' 条边创建一棵树,然后在该树中找到所有 'similar_to' 条边。
这个查询给出了想要的结果,但是它没有优化吗?
两个遍历遵循几乎相同的路径,这使得将它们组合起来很容易:
g.V(id).
emit().
repeat(__.out('manages')).
aggregate('x').
bothE('similar_to').dedup().
filter(__.otherV().where(P.within('x'))).
project('from', 'to', 'similarity').
by(__.outV().id()).
by(__.inV().id()).
by('similarity').
toList()
现在我才意识到我们可以让它变得更简单。由于您要求由 similar_to
连接的两个顶点都是 x
的一部分,这意味着结果中的每条边都必须是 x
中任何顶点的出边。因此,我们可以只使用 outE
和 inV
:
,而不是使用 bothE
和 otherV
(启用路径跟踪)
g.V(id).
emit().
repeat(__.out('manages')).
aggregate('x').
outE('similar_to').dedup().
filter(__.inV().where(P.within('x'))). /* outV is already guaranteed to be within "x" */
project('from', 'to', 'similarity').
by(__.outV().id()).
by(__.inV().id()).
by('similarity').
toList()
我正在尝试调试 AWS Neptune 遇到的性能问题。我是 运行 一些 Gremlin 查询,它们似乎总是在数据库上产生 30 个请求。我想知道我的查询是否做错了。
这个问题的奇怪之处在于它是突然发生的。以前,这工作得很好,我们没有遇到性能问题。
我做的每个调用都有两个一般查询,一个针对节点,一个针对边:
nodes = g.V(id).emit().repeat(__.out('manages')).dedup().project('label', 'name', 'job', 'department', 'manager').\
by(__.id()).by('name').by('job').by('department').by('manager').toList()
id_list = list(map(lambda node: node["label"], nodes))
edges = g.V(id).emit().repeat(__.out('manages')).dedup().bothE('similar_to').dedup().\
where(__.and_(__.inV().has(T.id, P.within(id_list)), __.outV().has(T.id, P.within(id_list)))).\
project('from', 'to', 'similarity').by(__.outV().id()).by(__.inV().id()).by('similarity').toList()
基本上,我有两种边缘类型:管理和 similar_to。我尝试使用 'manages' 条边创建一棵树,然后在该树中找到所有 'similar_to' 条边。
这个查询给出了想要的结果,但是它没有优化吗?
两个遍历遵循几乎相同的路径,这使得将它们组合起来很容易:
g.V(id).
emit().
repeat(__.out('manages')).
aggregate('x').
bothE('similar_to').dedup().
filter(__.otherV().where(P.within('x'))).
project('from', 'to', 'similarity').
by(__.outV().id()).
by(__.inV().id()).
by('similarity').
toList()
现在我才意识到我们可以让它变得更简单。由于您要求由 similar_to
连接的两个顶点都是 x
的一部分,这意味着结果中的每条边都必须是 x
中任何顶点的出边。因此,我们可以只使用 outE
和 inV
:
bothE
和 otherV
(启用路径跟踪)
g.V(id).
emit().
repeat(__.out('manages')).
aggregate('x').
outE('similar_to').dedup().
filter(__.inV().where(P.within('x'))). /* outV is already guaranteed to be within "x" */
project('from', 'to', 'similarity').
by(__.outV().id()).
by(__.inV().id()).
by('similarity').
toList()