Neo4j Cypher query optimization for better performance

Viewed 30

I'm unable to test this on the big data set right now, but just wondering what Cypher query in Neo4j will work faster in order to properly design the system:

Approach #1:

 WHERE apoc.coll.containsAllSorted($profileDetailedCriterionIds, childD.mandatoryCriterionIds) 

Approach #2:

(p:Profile {id: $profileId})-[:HAS_VOTE_ON]-(c:Criterion)<-[:HAS_VOTE_ON]-(childD) 
WHERE c.id IN childD.mandatoryCriterionIds 
WITH childD, COLLECT(c.id) as cIds, 
WHERE size(cIds) >= size(childD.mandatoryCriterionIds)

where $profileDetailedCriterionIds is a Set of ids provided via query parameter

What approach should I chose for better performance?

1 Answers

Run both queries in a Neo4j browser but put a keyword PROFILE at the start of the query. When both queries are done, it will display a PROFILING or explanation on how the query was executed. Then go to last tab on the left and look that part where you use the APOC function and compare the db hits and page caching without the APOC function.

Related