0
votes

My query is taking 52 seconds to load (returning 1419 rows)

MATCH (sn:Snapshot)--(z:Requirement {type:'super'})--(m:Requirement {type:'sub'}) MATCH (m)-[r1]-(c:Code)-[rv1]-(sn) MATCH (m)-[r2]-(t:Test)-[rv2]-(sn) RETURN DISTINCT z AS super, COLLECT(DISTINCT m) AS sub, COLLECT(DISTINCT [c,r1,rv1]) AS code,COLLECT(DISTINCT [t,r2,rv2]) AS test

I have about 634228 relationships and 91176 nodes.

I have indexes on the nodes and auto indexes on the relationships. I have been trying many approaches but can't find the way to reduce the time.

Please let me know if you need more information about it, I'm a beginner with Neo4j.

Thank you.

1
Which Neo4j version have you running? Do you have an index on :Requirement {type} ? Is that an initial or subsequent query? Please share your query plan (prefix your query with "PROFILE"). - Michael Hunger
version 2.2.0. I didn't have type as an index on :Requirement. I added it but didn't get any time improvement (still around 50 seconds). It is a subsequent query, so the db is already cached. After running profile: CYPHER 2.2, planner: COST. 58815057 total db hits in 57774 ms oi59.tinypic.com/1zlqg3s.jpg Thank you! - Adam Souceck
My data model is optimized for preventing duplicates and holding information on the relationships. Should I modify it to get better query performance (but a lot of data redundancy)? - Adam Souceck

1 Answers

1
votes

Cou can try to get the cardinality down in between otherwise for every path matched with :Code it will execute a match with :Test.

MATCH (sn:Snapshot)--(z:Requirement {type:'super'})--(m:Requirement {type:'sub'})
WITH distinct z,m
MATCH (m)-[r1]-(c:Code)-[rv1]-(sn)
WITH m, COLLECT(DISTINCT [c,r1,rv1]) AS code
MATCH (m)-[r2]-(t:Test)-[rv2]-(sn)
RETURN z AS super, COLLECT(DISTINCT m) AS sub, code ,COLLECT(DISTINCT [t,r2,rv2]) AS test