Tom
Tom

Reputation: 642

Neo4j poor performance on ORDER BY

I have query like this

MATCH (p:Person)-[s:KNOWS]->(t:Person) WHERE s.state = "blocked"
WITH DISTINCT (t) AS user
SKIP 0
LIMIT 10
MATCH (user)<-[r:KNOWS { state: "blocked" }]-(p:Person)
RETURN user.username, SIZE(COLLECT(p.username)) as count

enter image description here

First problem is when I have SKIP for example 100, it's getting slower, any idea why?

Seconds problem is, when I try to add ORDER BY, for example ORDER BY p.createdAt which is date (indexed field), it's always timing out.

Upvotes: 0

Views: 426

Answers (1)

InverseFalcon
InverseFalcon

Reputation: 30407

You might have better performance with a tweak to your initial MATCH:

MATCH (t:Person) 
WHERE ()-[:KNOWS {state:"blocked"}]->(t)
WITH t AS user // no longer need DISTINCT here
...

For better performance you might consider creating a fulltext schema index on :KNOWS relationships by their state property, and use the fulltext index query procedure to do this initial lookup (this is assuming :KNOWS relationships always connect two :Person nodes).

Upvotes: 2

Related Questions