简体   繁体   English

Neo4J / Cypher Query 按属性排序非常慢

[英]Neo4J / Cypher Query very slow with order by property

I have a graph database with 5M of nodes and 10M of relationships.我有一个包含 5M 节点和 10M 关系的图形数据库。 I'm on a Macbook Pro with 4GB RAM.我使用的是 4GB RAM 的 Macbook Pro。 I have already try to adjust java heap size and neo4j memory without success.我已经尝试调整java堆大小和neo4j内存但没有成功。

My problem is that i have a simply cypher query like that :我的问题是我有一个简单的密码查询:

MATCH (pet:Pet {id:52163})-[r:FOLLOWS]->(friend) 
MATCH (friend)-[r:POSTED]->(n) 
RETURN friend.id, TYPE(r),LABELS(n),n.id
LIMIT 30;

This query takes 100ms , which is impressive.这个查询需要 100ms ,这是令人印象深刻的。 But when i add an "ORDER BY" this query takes a long time => 8s :/但是当我添加“ORDER BY”时,这个查询需要很长时间=> 8s:/

MATCH (pet:Pet {id:52163})-[r:FOLLOWS]->(friend) 
MATCH (friend)-[r:POSTED]->(n) 
RETURN friend.id, TYPE(r),LABELS(n),n.id
ORDER BY r.date DESC
LIMIT 30;

Does Someone has an idea ?有人有想法吗?

You might want to consider relationship indexes to speed up your query. 您可能需要考虑关系索引以加快查询速度。 The date property could be indexed this way. date属性可以通过这种方式建立索引。 You're using the ORDER BY keyword which will almost always make your query slower as it needs to iterate the entire result set to perform the ordering. 您正在使用ORDER BY关键字,这几乎总是会使您的查询变慢,因为它需要迭代整个结果集以执行排序。

Also consider using a single MATCH statement if that suits your needs: 如果适合您的需求,还可以考虑使用单个MATCH语句:

MATCH (pet:Pet {id:52163})-[r:FOLLOWS]->(friend)-[r:POSTED]->(n) 

Thanks for your answer ! 感谢您的回答 !

I reimported my database with the Michael Hunger's batch-importer, with node_auto_index and relationship_auto_index on date property. 我重新导入我与迈克尔饥饿的批量进口的数据库,node_auto_index和relationship_auto_index的date财产。

Everything seems to be ok with these indexes, all the relations with the date property are indexed. 这些索引似乎一切正常,所有与date属性的关系都被索引了。

But the query is still too long ... Nothing has changed 但是查询仍然太长...什么都没有改变

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

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