【发布时间】:2022-01-09 07:20:20
【问题描述】:
我以为我掌握了 neo4j。事实证明我不是。我正在运行一个很长的查询。当我使用任何 2 个可选匹配运行时,它会在 20 秒内运行。但是如果我有任何第三场可选比赛(似乎并不重要),它将需要将近 15 分钟才能运行。我不太明白。我(在某种程度上)理解可选匹配顺序很重要,因为它们将所有已经匹配的东西放在它们之前,并使用这些“行”来检查可选匹配,从而使每个匹配的成本成倍增加。我想如果我在每个语句之间小心地添加“with”语句,我可以尝试仅将必要的内容过滤到每个语句中。
我的可选匹配项之间并没有太大的关系。我实际上会做 3-4 个不同的 neo4j 查询,但我的老板希望我在一个查询中完成所有操作。如果事实证明性能好得多,我可能最终会违背他的意愿。我将为您提供完整的查询,其中更改了一些名称。它不会影响查询或任何事情,我的工作在技术上是开源的,但我仍然不应该分享任何可识别的内容。
我还运行“个人资料”来显示完整的树。
profile
match (ds:Analysis)<-[:OUTPUT]-(a)<-[:INPUT]-(firstSample:Sample)<-[*]-(source:Source)
with ds, firstSample
optional match (ds)<-[*]-(othersample:Sample)
with ds, othersample, firstSample
where not othersample.location is null and not trim(othersample.location) = ''
optional match (source)-[:INPUT]->(oa)-[:OUTPUT]->(specialsample:Sample {sample_type:'protein'})-[*]->(ds)
with ds, othersample, firstSample, source, specialsample
optional match (ds)<-[*]-(finalsample:Sample)
with ds, othersample, firstSample, source, specialsample, finalsample
where not finalsample.metadata is null and not trim(finalsample.metadata) = ''
return ds.id, collect(distinct firstSample), collect(distinct source), collect(distinct othersample), collect(distinct specialsample), ds.alt_id, ds.status, ds.group_name, ds.group_uuid,
ds.created_timestamp, ds.created_email, ds.last_modified_timestamp, ds.last_modified_email, ds.lab_id, ds.data_types, collect(distinct finalsample)
这是挂钩到一个已经编写好的 python 脚本,所以我对输出甚至返回的顺序都没有灵活性,但如果有必要我可以做点什么。
任何建议将不胜感激。 https://i.stack.imgur.com/9psgT.png
【问题讨论】:
-
这是您在此处发布的完整查询还是您删除了部分查询?
-
他们的查询是完整的。我为某些标签提供了一些别名,但这是我理解的完整查询。
标签: python database optimization neo4j cql