简体   繁体   English

Neo4j查询性能问题

[英]Neo4j Query Performance Issue

I have some performance issue using a specific Cypher Command. 使用特定的Cypher命令时,我遇到一些性能问题。

I look for R nodes not directly connected to a specific set of nodes of type I (Here, nodes with index field at "79" and "4") and I want to maximize the field "score" : 我寻找未直接连接到I类型的特定节点集的R节点(此处,索引字段为“ 79”和“ 4”的节点),并且我想最大化字段“ score”:

MATCH (r:R), (i0:I { index:"79" }), (i1:I { index:"4" })
WHERE NOT r--i0 AND NOT r--i1
RETURN r.index
ORDER BY r.score DESC
LIMIT 5

The query is executed generally in 1250ms. 查询通常在1250毫秒内执行。 If I remove the ORDER BY clause, the request time goes down to 130ms. 如果删除ORDER BY子句,则请求时间将降至130ms。 The order clause iterates on nearly 3300 elements. order子句遍历了将近3300个元素。

Any idea how I can speed up that request ? 知道如何加快请求的速度吗? I am sure there is a way to use another syntax to perform this search. 我敢肯定,有一种方法可以使用另一种语法来执行此搜索。

I think it is normal, by removing the ORDER BY , he will return you the 5 first nodes he can match. 我认为这很正常,通过删除ORDER BY ,他将向您返回他可以匹配的前5个节点。 By adding the ORDER BY, it forces to load all possible matching nodes, depending of the amount of "R" nodes the time will increase. 通过添加ORDER BY,它将强制加载所有可能的匹配节点,具体取决于“ R”节点的数量,时间将增加。

Now : 现在:

Did you "profiled" your query with PROFILE 您是否使用PROFILE “配置了”查询

do you have indexes/constraints on I:index ? 您对I:index有索引/约束吗?

Can you change slightly your query to : 您能否将查询稍微更改为:

MATCH (r:R), (i0:I { index:"79" }), (i1:I { index:"4" })
WHERE NOT EXISTS((r)--(i0)) 
AND NOT EXISTS((r)--(i1))
RETURN r.index
ORDER BY r.score DESC
LIMIT 5

Which version do you use? 您使用哪个版本? try to update to the latest one, also please share your visual query plan by prefixing your query with `PROFILE`` 尝试更新到最新版本,也请通过在查询前添加`PROFILE``来共享您的视觉查询计划

Change it to: 更改为:

MATCH (i0:I { index:"79" }), (i1:I { index:"4" })
MATCH (r:R) 
WHERE NOT r--i0 AND NOT r--i1
WITH r
ORDER BY r.score DESC
LIMIT 5
RETURN r.index

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM