1
votes

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 ?

1

1 Answers

0
votes

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)