Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Change your query to the one below. On my laptop, with significatly lower specs than yours, the execution time halves.</p> <pre><code>START start_node=node(36) MATCH (start_node)-[r:COOCCURS_WITH]-(partner) WITH start_node, partner MATCH (partner)-[s:COOCCURS_WITH]-(another_partner)-[:COOCCURS_WITH]-(start_node) RETURN COUNT(DISTINCT s) AS num_partner_partner_links; </code></pre> <p>Also, using your settings doesn't affect performance much as compared to the default settings. I'm afraid that you can't get the performance you want, but this query is a step in the right direction.</p> <p>Usually the traversal API will be faster than Cypher because you explicitly control the traversal. I've mimicked the query as follows:</p> <pre><code>public class NeoTraversal { public static void main(final String[] args) { final GraphDatabaseService db = new GraphDatabaseFactory() .newEmbeddedDatabaseBuilder("/neo4j") .loadPropertiesFromURL(NeoTraversal.class.getClassLoader().getResource("neo4j.properties")) .newGraphDatabase(); final Set&lt;Long&gt; uniquePartnerRels = new HashSet&lt;Long&gt;(); long startTime = System.currentTimeMillis(); final Node start = db.getNodeById(36); for (final Path path : Traversal.description() .breadthFirst() .relationships(Rel.COOCCURS_WITH, Direction.BOTH) .uniqueness(Uniqueness.NODE_GLOBAL) .evaluator(Evaluators.atDepth(1)) .traverse(start)) { Node partner = start.equals(path.startNode()) ? path.endNode() : path.startNode(); for (final Path partnerPath : Traversal.description() .depthFirst() .relationships(Rel.COOCCURS_WITH, Direction.BOTH) .uniqueness(Uniqueness.RELATIONSHIP_PATH) .evaluator(Evaluators.atDepth(2)) .evaluator(Evaluators.includeWhereEndNodeIs(start)) .traverse(partner)) { uniquePartnerRels.add(partnerPath.relationships().iterator().next().getId()); } } System.out.println("Execution time: " + (System.currentTimeMillis() - startTime)); System.out.println(uniquePartnerRels.size()); } static enum Rel implements RelationshipType { COOCCURS_WITH } } </code></pre> <p>This clearly outperforms the cypher query, thus this might be a good alternative for you. Optimization is likely still possible.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload