Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

neo4j

cypher

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.

like image 761
ChrisE Avatar asked Feb 03 '26 13:02

ChrisE


1 Answers

I would try this

MATCH (c:TEST:LOC1) where c._text='P' with c
MATCH (b:TEST_JOIN:LOC1) where b._out = c._in with b, c
Match (a:Test:LOC1) WHERE a._out = b._in with a, c
CREATE (a)-[r:TEST_JOIN]->(c)
like image 180
Evgen Avatar answered Feb 05 '26 09:02

Evgen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!