Multiple neo4j node join: "This query builds a cartesian product between disconnected patterns"

Viewed 1025

I'm running this query:

MATCH (a:TEST:LOC1),(b:TEST_JOIN:LOC1),(c:TEST:LOC1)
WHERE a._out = b._in and b._out = c._in and c._text = 'P'
CREATE (a)-[r:TEST_JOIN]->(c)

It runs very slowly, and the execution plan says: "This query builds a cartesian product between disconnected patterns"

All the properties are indexed and I have tried:

MATCH (c:TEST:LOC1) where c._text='P' with c
MATCH (a:TEST:LOC1),(b:TEST_JOIN:LOC1)
WHERE a._out = b._in and b._out = c._in
CREATE (a)-[r:TEST_JOIN]->(c)

Sorry if this is basic. Does anyone know how to optimise this? Many thanks in advance.

2 Answers
Related