简体   繁体   中英

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

在此处输入图片说明

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.

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).

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