Search code examples
neo4jgraph-databasescql

Adding relationship to the existing node inNeo4j


I want to add new relationship to the existing node in Neo4j with this syntax:

MATCH (a:User {name: "Jack", surname: "Roe"}),
(b:User {name: "Jack", surname: "Smith"})
CREATE (a) -[r:Knows]-> (b)
RETURN a,r,b

but I get this warning : enter image description here what does it mean and how should I modify my cypher query?


Solution

  • In your case you have nothing to do.

    The warning, like it's explained in its description, is that you have a disconnected pattern : (a:User {name: "Jack", surname: "Roe"}) and (b:User {name: "Jack", surname: "Smith"}) are not linked.

    So to create the result, Neo4j has to compute all the combinations of this 2 sets :

    • the one for the node a
    • the one for the node b

    So it's a cartesian product between those 2 sets, and it's something that can take a lot of times, specially if one set has a high cardinality.

    In your case, I assume you have one node Roe and an other Jack, so the cartesian product is just 1 x 1, so it's easy.