This is the follow up to original question regarding paginating result set for large sub-graph.
Neo4j/Cypher effective pagination with order by over large sub-graph
To recap the node-rel structure:
(:User)-[:FOLLOWS {timestamp}]->(:User)
As suggested by @michael-hanger order by clause has been removed as rel-type chain should be returned in sequential order following timestamp with most recent followers on top.
MATCH (u:User {Id:{id}})<-[f:FOLLOWS]-(follower)
WHERE f.timestamp <= {timestamp}
RETURN follower
LIMIT 100
The problem is that in general case this doesn't work.
What I found is if :User
node has 50 or less :FOLLOWER
relationships everything works fine. Followers always returned ordered by timestamp with most recent on top. But in case you have more then 50 :FOLLOWER
relationships last 50 followers always returned inverted with oldest on top.
i.e. if :User
has 100 followers and you query them as above, you will get list where first 50 ordered from newest to oldest and last 50 from oldest to newest. in general you have such ordering in any case where number of followers is more than 50.
Could anyone advise on this behaviour.