Optimization 限制密码查询

Optimization 限制密码查询,optimization,neo4j,cypher,Optimization,Neo4j,Cypher,我目前正在使用一个拥有50000个节点和200万个关系的neo4j数据库来执行cypherMATCH查询,如下所示: start startnode = node(42660), endnode = node(30561) match startnode-[r*1..3]->endnode return r; 这个查询本身提供443行,但我只希望Cypher找到5个匹配项并仅返回这些匹配项。请允许我澄清:我不仅希望Cypher只返回5个结果,还希望Cypher在找到5个结果后停止查询。我

我目前正在使用一个拥有50000个节点和200万个关系的neo4j数据库来执行cypher
MATCH
查询,如下所示:

start startnode = node(42660), endnode = node(30561)
match startnode-[r*1..3]->endnode
return r;
这个查询本身提供443行,但我只希望Cypher找到5个匹配项并仅返回这些匹配项。请允许我澄清:我不仅希望Cypher只返回5个结果,还希望Cypher在找到5个结果后停止查询。我不希望Cypher获得所有443个结果。

当前是否可以使用
限制
子句来实现这一点?或者
LIMIT
是否会等待找到所有443个结果,然后只返回前5个

EDIT:对于这样的复杂查询,
LIMIT
子句是否只会找到前几个结果

start graphnode = node(1), startnode = node(42660), endnode = node(30561)
match startnode<-[:CONTAINS]-graphnode-[:CONTAINS]->endnode
with startnode, endnode
match startnode-[r1*1..1]->endnode
with r1, startnode, endnode
limit 30
match startnode-[r2*2..2]->endnode
with r1, r2, startnode, endnode
limit 30
match startnode-[r3*3..3]->endnode
with r1, r2, r3, startnode, endnode
limit 30
return r1,r2,r3;

这取决于你在做什么,但在这种情况下,如果你在
return
之后添加
limit 5
,它将能够延迟返回并跳过其余的匹配。如果您想要排序或聚合,它将无法为您这样做。如果您发现这不是行为,请在github上报告问题(以及您正在使用的版本等)

新查询的更新

start graphnode=node(1),startnode=node(42660),endnode=node(30561)
匹配StartNodeNode//您需要这个,还是它总是会是真的?
使用startnode,endnode//同上。如果它不需要在这里,就把它拿出来。
匹配startnode-[r1*1..1]->endnode//这可能可以简化为startnode-[r1]->endnode
使用r1、开始节点、结束节点
限制30//限制到在上一个匹配中找到的前30个(这应该是惰性的)
匹配startnode-[r2*2..2]->endnode//查找两个级别的深度
使用r1、r2、开始节点、结束节点
限制30//限制到在上一个匹配中找到的前30个(这应该是惰性的)
匹配startnode-[r3*3..3]->endnode
return r1、r2、r3//最后一次与您一起使用是无关的,return将以相同的方式运行
限30人;

所以,我假设你在问一个问题,因为这个查询很慢。我可以问一下,为什么要这样分解它,而不是仅仅
startnode-[r*1..3]>endnode
,以及
limit 30
?你真的需要第一次匹配,还是不需要检查?您能提供
配置文件的输出吗?

我不确定这是否是正常行为。我尝试了一个复杂的查询
start-graphnode=node(1),startnode=node(42660),endnode=node(30561)匹配startnode和startnode,endnode匹配startnode-[r1*1..1]->endnode和r1,startnode,endnode限制30匹配startnode-[r2*2..]->endnode和r1,r2,startnode,endnode限制30匹配startnode-[r3*3..]->带有r1、r2、r3、startnode、endnode limit 30的endnode返回r1、r2、r3。尽管有种种限制,但我还是花了一分钟才得到结果。为了便于阅读,我在问题中提出了这个复杂的查询。我正在分解查询,因为我稍后打算为限制输入参数。例如,我希望能够将整个路径列表的限制设置为30,并减少每层的限制。(如果
1..1
生成1条路径,那么我希望
2..2
的限制为29)。此外,我已经删除了第一个匹配/与;那张支票没有必要。但是,我仍然遇到性能问题。我将尽快添加一个
profile
输出。我还尝试将查询扩展到
4..4
,但最终没有结果,可能是GC转储。这是我在日志中发现的:
GC-Monitor:Application-threads额外被阻止14813ms[总阻止时间:182.589s]
如果您需要扩展帮助,请发布新问题或在twitter@wefreema上向我发送消息。
==> ColumnFilter(symKeys=["  UNNAMED216", "endnode", "r1", "startnode", "r2", "r3"],   returnItemNames=["r1", "r2", "r3"], _rows=30, _db_hits=0)
==> Slice(limit="Literal(30)", _rows=30, _db_hits=0)
==>   PatternMatch(g="(startnode)-['  UNNAMED216']-(endnode)", _rows=30, _db_hits=0)
==>     ColumnFilter(symKeys=["endnode", "  UNNAMED140", "r1", "startnode", "r2"], returnItemNames=["r1", "r2", "startnode", "endnode"], _rows=1, _db_hits=0)
==>       Slice(limit="Literal(30)", _rows=1, _db_hits=0)
==>         PatternMatch(g="(startnode)-['  UNNAMED140']-(endnode)", _rows=1, _db_hits=0)
==>           ColumnFilter(symKeys=["startnode", "endnode", "  UNNAMED68", "r1"], returnItemNames=["r1", "startnode", "endnode"], _rows=1, _db_hits=0)
==>             Slice(limit="Literal(30)", _rows=1, _db_hits=0)
==>               PatternMatch(g="(startnode)-['  UNNAMED68']-(endnode)", _rows=1, _db_hits=0)
==>                 NodeById(name="Literal(List(30561))", identifier="endnode", _rows=1, _db_hits=1)
==>                   NodeById(name="Literal(List(42660))", identifier="startnode", _rows=1, _db_hits=1)
start graphnode = node(1), startnode = node(42660), endnode = node(30561)
match startnode<-[:CONTAINS]-graphnode-[:CONTAINS]->endnode // do you need this, or is it always going to be true?
with startnode, endnode                                     // ditto. take it out if it doesn't need to be here.
match startnode-[r1*1..1]->endnode // this can probably be simplified to just startnode-[r1]->endnode
with r1, startnode, endnode 
limit 30 // limit to the first 30 it finds in the previous match (this should be lazy)
match startnode-[r2*2..2]->endnode // finds 2 levels deep
with r1, r2, startnode, endnode
limit 30 // limit to the first 30 it finds in the previous match (this should be lazy)
match startnode-[r3*3..3]->endnode
return r1,r2,r3 // the last with you had was extraneous, return will function the same way
limit 30;