Performance Cypher SORT

I am trying to accomplish a fairly general task. I have a substantial data set in a Neo4J database, and from the RESTful web service I want to return the data to pieces from 25 nodes. My model is pretty simple:

(:Tenant {Hash:''})-[:owns]->(:Asset {Hash:'', Name:''})

I have unique property restrictions Hashon both labels.

If I wanted to get the 101st page of data, my cypher request would look like this:

MATCH (:Tenant {Hash:'foo'})-[:owns]->(a:Asset)
RETURN a
ORDER BY a.Hash
SKIP 2500
LIMIT 25

My data set consists of one tenant with assets of ~ 75 KB. The above request takes ~ 30 (!) Seconds to complete. I also notice that the further I advance in the data (i.e., Above SKIP), the longer it takes to return the request.

I quickly realized that the culprit in my performance problems was ORDER BY a.Hash. When I delete it, the query returns with the results of the subsection. This is actually quite unexpected, as I expect the index itself to be ordered as well.

Obviously, to implement reasonable pagination, I have to have a consistent sort order.

  • Any tips on fulfilling this request are being implemented?
  • Alternative swap suggestions? I see the addition of dedicated page nodes, but this will be difficult to maintain.
  • What is the default sort order in any case, and is it sequential?
+4
source share
2 answers

Hey @GeoffreyBraaf , , , , .

Timmy Java, 30 . Cypher 100 . top-n select Cypher 600 . , Cypher 150 .

: https://gist.github.com/jexp/9954509

2.0-maint 2.0.2

: https://github.com/neo4j/neo4j/pull/2230

+2

, , , . java, ?

 try (Transaction tx = graphDb.beginTx()) {
     List<Node> nodes = IteratorUtil.asList(GlobalGraphOperations.at(graphDb)
         .getAllNodesWithLabel(DynamicLabel.label("Asset")));
     Collections.sort(nodes, new NodeComparator());
     final List<Node> result = nodes.subList(4375, 4400);
     tx.success();
 }

 static class NodeComparator implements Comparator<Node> {   
     @Override
     public int compare(final Node o1, final Node o2) {
         return o1.getProperty("hash").toString().compareTo(o2.getProperty("hash").toString());
     }            
 }
+2

Source: https://habr.com/ru/post/1532812/


All Articles