Neo4j查询性能提升

时间:2017-04-13 17:26:30

标签: performance neo4j cypher

我对Neo4J很新,我使用的查询需要很长时间才能完成。查询如下所示:

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

我试图对其进行分析,看起来当它查找concept_description时,会返回所有可能的节点,而不仅仅是与之前匹配的概念匹配的节点。我做错了什么想法?谢谢!

1 个答案:

答案 0 :(得分:1)

我将尝试解释neo4j查询的机制:

当你这样做时:

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

两个匹配都会独立运行,但是当你做这样的事情时:

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

第二个查询将取决于第一个查询的结果,因此级联将返回正确的结果,并且效率也会更高。