繁体   English   中英

Neo4j密码查询改进(性能)

[英]Neo4j cypher query improvement (performance)

我有以下密码查询:

CALL apoc.index.nodes('node_auto_index','pref_label:(Foo)')
YIELD node, weight 
WHERE node.corpus = 'my_corpus'
WITH node, weight 
MATCH (selected:ontoterm{corpus:'my_corpus'})-[:spotted_in]->(:WEBSITE)<-[:spotted_in]-(node:ontoterm{corpus:'my_corpus'}) 
WHERE selected.uri = 'http://uri1' 
      OR selected.uri = 'http://uri2' 
      OR selected.uri = 'http://uri3' 
RETURN DISTINCT node, weight 
ORDER BY weight DESC LIMIT 10

第一部分(直到WITH)运行非常快(Lucene旧索引),并返回约100个节点。 uri属性也是唯一的(选择= 3个节点),我有〜300个WEBSITE节点。 执行时间为48749毫秒。

轮廓: 在此处输入图片说明

如何重组查询以提高性能? 为何配置文件中有〜13.8 Mio行?

我认为问题出在WITH子句中,它极大地扩展了结果。 InverseFalcon的答案使查询速度更快:49-> 18秒(但仍然不够快)。 为了避免巨大的扩展,我收集了网站。 以下查询耗时60ms

MATCH (selected:ontoterm)-[:spotted_in]->(w:WEBSITE)
WHERE selected.uri in ['http://avgl.net/carbon_terms/Faser', 'http://avgl.net/carbon_terms/Carbon', 'http://avgl.net/carbon_terms/Leichtbau']
AND selected.corpus = 'carbon_terms'
with collect(distinct(w)) as websites
CALL apoc.index.nodes('node_auto_index','pref_label:(Fas OR Fas*)^10 OR pref_label_deco:(Fas OR Fas*)^3 OR alt_label:(Fa)^5') YIELD node, weight 
WHERE node.corpus = 'carbon_terms' AND node:ontoterm 
WITH websites, node, weight
match (node)-[:spotted_in]->(w:WEBSITE)
where w in websites
return node, weight
ORDER BY weight  DESC
LIMIT 10

我在您的计划中没有看到NodeUniqueIndexSeek的任何情况,因此无法有效地查找selected节点。

确保对:ontoterm(uri)有唯一的约束。

设置唯一约束后,尝试一下:

PROFILE CALL apoc.index.nodes('node_auto_index','pref_label:(Foo)')
YIELD node, weight 
WHERE node.corpus = 'my_corpus' AND node:ontoterm
WITH node, weight 
MATCH (selected:ontoterm)
WHERE selected.uri in ['http://uri1', 'http://uri2', 'http://uri3']
AND selected.corpus = 'my_corpus'
WITH node, weight, selected
MATCH (selected)-[:spotted_in]->(:WEBSITE)<-[:spotted_in]-(node) 
RETURN DISTINCT node, weight 
ORDER BY weight DESC LIMIT 10

看一下查询计划。 您应该在那里看到某个地方的NodeUniqueIndexSeek,并希望您应该看到数据库命中率下降。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM