简体   繁体   English

Neo4j 查询性能提升

[英]Neo4j query performance improvement

I am quite new with Neo4J and I am using a query which takes really long time to be completed.我对 Neo4J 很陌生,我正在使用一个需要很长时间才能完成的查询。 The query looks like:查询如下所示:

match (pn:person_name)-[:FOR_PERSON]->(p:person)<-[:FOR_PERSON]-(o:obs)-[:HAS_CONCEPT]->(c:concept)<-[:HAS_CONCEPT]-(n:concept_name), (o)-[:AT_LOCATION]->(l:location),

(o)-[:FOR_ENCOUNTER]->(e:encounter)-[:HAS_TYPE]->(et:encounter_type),(c)-[:HAS_CLASS]->(cl:concept_class), 

(c)<-[r:HAS_CONCEPT]-(cd:concept_description)

where pn.given_name="Horatio" AND  pn.middle_name="L" and pn.family_name="Hornblower" with pn, p, o, c,n,e,et,cl,cd,l

return distinct n.name as observation, o.obs_datetime as time, et.description as visittype, l.name as location,cl.name as encountertype,cd.description as description 

ORDER BY o.obs_datetime

I tried to profile it and it appears that when it looks for concept_description , all possible nodes are returned, not only the one that matches our previous matched concept.我尝试对其进行分析,看起来当它查找concept_description ,会返回所有可能的节点,而不仅仅是与我们之前匹配的概念匹配的节点。 Any ideas what I m doing wrong?任何想法我做错了什么? Thank you!谢谢!

I will try explaining the mechanism of neo4j query :我将尝试解释neo4j查询的机制:

when you do :当你这样做时:

MATCH (a:X)-[]-(b:Y), (b:Y)-[]-(c:Z) where b.someField = someValue

both match will run independently but when you do something like this :两个比赛都将独立运行,但是当您执行以下操作时:

MATCH (a:X)-[]-(b:Y) where b.someField = someValue with b match (b)-[]-(c:Z) return a,b,c

second query will be dependent on the outcome of first query and hence cascading will return you correct result and will be more efficient too.第二个查询将取决于第一个查询的结果,因此级联将返回正确的结果并且效率也会更高。

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

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