I have csv file containing a one-to-many relation where each element of type A is composed by one or more elements of type B but each element of B refers to only one element of type A.
An example:
A | B
-------------
a1 | b1
a1 | b2
a1 | b3
a2 | b4
I have already created the node in a neo4j graph and now I want to create an edge for these relationships.
I thought this query
LOAD CSV WITH HEADERS FROM "file:///file.csv" AS row
WITH row
MATCH (n:A {A_ID: row.a_id}), (t:B {BID : row.b_id})
MERGE (n)-[:HAS_CONNECTION]->(t);
but Neo4j prompts the following warning:
This query builds a cartesian product between disconnected patterns. If a part of a query contains multiple disconnected patterns, this will build a cartesian product between all those parts. This may produce a large amount of data and slow down query processing. While occasionally intended, it may often be possible to reformulate the query that avoids the use of this cross product, perhaps by adding a relationship between the different parts or by using
OPTIONAL MATCH(identifier is: (t))
So I changed it to:
LOAD CSV WITH HEADERS FROM "file:///file.csv" AS row
WITH row
MATCH (t:B {BID : row.b_id})
WITH row, t
MATCH (n:A {AID: row.a_id})
MERGE (n)-[:HAS_CONNECTION]->(t);
and Neo4j does not complain.
However if I EXPLAIN both the queries the result is the same.
Is neo4j useless complaining about the first query or there are effective benefits with the second?