我在玩neo4j和cypher,试图找出我的查询速度慢的原因。
以下是我的原始查询,标记为已弃用:
match (h:Hierarchy)-[r:PARENT_OF*1..4]->(s:SoldTo)
where h.id='0100001709'
and all(x in r
where x.to>=date('2022-02-15')
and x.from <= date('2022-02-15')
and x.hvkorg='S000'
and x.hvtweg='D1'
)
and s.loevm=""
and s.aufsd=""
and s.cassd=""
and s.faksd=""
and s.lifsd=""
and s.sperr=""
and s.sperz=""
r>eturn distinct h.id,s.id
这个操作很好,并且很快返回结果:Started streaming 60 records after 1 ms and completed after 17 ms.
然而neo4j给出了以下警告:
此功能已被弃用,并将在未来版本中删除。不赞成以可变长度模式将关系绑定到列表。(不赞成将可变长度关系模式绑定到变量('r'(,将来的版本将不支持该模式。建议的方法是将整个路径绑定到一个变量,然后提取关系:MATCH p=(…(-[…]-(…(与*,关系(p(AS r(
现在,我已经尝试了这个:
match p=(h:Hierarchy)-[:PARENT_OF*1..4]->(s:SoldTo)
with *, relationships(p) as r
where h.id='0100001709'
and all(x in r
where x.to>=date('2022-02-15')
and x.from <= date('2022-02-15')
and x.hvkorg='S000'
and x.hvtweg='D1'
)
and s.loevm=""
and s.aufsd=""
and s.cassd=""
and s.faksd=""
and s.lifsd=""
and s.sperr=""
and s.sperz=""
return distinct h.id,s.id
但是,这是非常缓慢的:Started streaming 60 records in less than 1 ms and completed after 36931 ms.
17ms vs 36931ms
你们中有人建议使用relationships((来加快速度吗?
查询中存在拼写错误。不要扫描第一行,而是放入where子句(位于第#3行到第#2行(。这将启用h处的起始节点,并使查询速度更快。
Original:
match p=(h:Hierarchy)-[:PARENT_OF*1..4]->(s:SoldTo)
with *, relationships(p) as r
where h.id='0100001709'
Updated:
match p=(h:Hierarchy)-[:PARENT_OF*1..4]->(s:SoldTo)
where h.id='0100001709'
with h, s, relationships(p) as r
...
...
return distinct h.id,s.id