简体   繁体   中英

Neo4J / Cypher Query very slow with order by property

I have a graph database with 5M of nodes and 10M of relationships. I'm on a Macbook Pro with 4GB RAM. I have already try to adjust java heap size and neo4j memory without success.

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. But when i add an "ORDER BY" this query takes a long time => 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. 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.

Also consider using a single MATCH statement if that suits your needs:

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.

Everything seems to be ok with these indexes, all the relations with the date property are indexed.

But the query is still too long ... Nothing has changed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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