我一直在试验模式解析的优化,但似乎越来越困惑
下面是我的初始查询:
MATCH (a:Actor)-[:ACTED_IN]->(m:Movie)
WHERE 2000 <= m.year <= 2005 AND a.born.year >= 1980
RETURN a.name AS Actor, a.born AS Born,
collect(DISTINCT m.title) AS Movies ORDER BY Actor
通过分析,我得到:
密码版本:,计划员:成本,运行时间:流水线。152毫秒内总共41944次db命中。
我尝试了以下重写:
profile MATCH (a:Actor)
WHERE a.born.year >= 1980
// Add a WITH clause to create the list using pattern comprehension
with a
match (a)-[:ACTED_IN]-(m:Movie)
where 2000 <= m.year <= 2005
// filter the result of the pattern comprehension to return only lists with elements
// return the Actor, Born, and Movies
return a.name as Actor, a.born as Born, [(a)-[:ACTED_IN]-(m) | m.title] as Movies
order by a
通过分析,我得到:
密码版本:,计划员:成本,运行时间:流水线。47879总db命中在47毫秒。
然后我尝试另一种重写:
profile MATCH (a:Actor)
WHERE a.born.year >= 1980
// Add a WITH clause to create the list using pattern comprehension
// filter the result of the pattern comprehension to return only lists with elements
// return the Actor, Born, and Movies
with a, [ (a)-[:ACTED_IN]-(m:Movie) where 2000 <= m.year <= 2005 | m.title] as Movies
return a.name as Actor, a.born as Born, Movies
order by a
密码版本:,计划员:成本,运行时间:流水线化。6毫秒内总共59251次db命中。
每一个性能都比另一个差。虽然我可以查看查询计划来了解差异。但与使用collect语句的初始查询相比,是否有一种方法可以使用模式理解来实际减少数据库命中?
1条答案
按热度按时间f1tvaqid1#
请向我们显示您上次查询的配置文件结果;我在电影数据库中测试了它,它与原始查询相比运行良好(46 ms与原始:120 db点击)。另外,检查Actor.born.year是否有索引。