Hi everyone!
I'm trying to query the following pattern:
(a)-[r1]->(b)-[r1|r2*]->(c)-[r1]->(d)
and a, b, c, d might belong to different categories, and they all have the same label.
The Cypher query I'm running is (cat means category):
MATCH p=(a)-[:r1]->(b)-[:r1|r2*1..]->(c)-[:r1]->(d)
WHERE a.cat <> b.cat AND b.cat = c.cat and c.cat <> d.cat and a.cat <> d.cat
RETURN p
The equivalent APOC query I'm using is:
MATCH (a)
CALL apoc.path.expandConfig(a, {
relationshipFilter: 'r1>',
minLevel: 1,
maxLevel:1
})
YIELD path WITH path AS atob,
last(nodes(path)) AS b, a
WHERE a.cat <> b.cat
CALL apoc.path.expandConfig(b, {
relationshipFilter: 'r1>|r2>',
minLevel: 1
})
YIELD path WITH path AS btoc,
last(nodes(path)) AS c, a, b, atob
WHERE b.cat = c.cat
CALL apoc.path.expandConfig(c, {
relationshipFilter: 'r1>',
minLevel: 1,
maxLevel:1
})
YIELD path WITH path AS ctod,
last(nodes(path)) AS d, a, b, c, atob, btoc
WHERE c.cat <> d.cat AND a.cat <> d.cat
WITH atob, [btoc, ctod] AS btod
WITH reduce(acc = atob, x IN btod | apoc.path.combine(acc, x)) AS atod
RETURN atod
The main goal is to compare the performance of these two queries (Cypher and APOC) for research purposes.
The Cypher query is fine, but the APOC query runs forever and returns 0 result (I use apoc.export.csv.query to save it to my disk and the file has 0 lines of record).
I'm running this query on a database with 3087 nodes and 9885 relationships (I guess it's not a huge database?)
I'm wondering if there is anything wrong with my query?
What I'm guessing is the problem of the transitive closure [r1|r2*], if I change it to [r1*] or [r2*], then I can get the result.
Is there anything I could do to improve my APOC query?
Thank you so much!