Neo4j - 密码 - 变长模式慢
Neo4j - cypher - variable length pattern slow
我正在使用 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
这个工作正常并且 returns 结果很快:Started streaming 60 records after 1 ms and completed after 17 ms.
但是 neo4j 给出以下警告:
This feature is deprecated and will be removed in future versions.
Binding relationships to a list in a variable length pattern is deprecated. (Binding a variable length relationship pattern to a variable ('r') is deprecated and will be unsupported in a future version. The recommended way is to bind the whole path to a variable, then extract the relationships:
MATCH p = (...)-[...]-(...)
WITH *, relationships(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.
17 毫秒与 36931 毫秒
你们有任何关于使用 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
我正在使用 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
这个工作正常并且 returns 结果很快:Started streaming 60 records after 1 ms and completed after 17 ms.
但是 neo4j 给出以下警告:
This feature is deprecated and will be removed in future versions. Binding relationships to a list in a variable length pattern is deprecated. (Binding a variable length relationship pattern to a variable ('r') is deprecated and will be unsupported in a future version. The recommended way is to bind the whole path to a variable, then extract the relationships: MATCH p = (...)-[...]-(...) WITH *, relationships(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.
17 毫秒与 36931 毫秒
你们有任何关于使用 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