So I'm generating a rather large Neo4J instance, and I'm loading this using LOAD_CSV. I've read as many blogs as I could find about optimising queries to remove Eager reads from the query plan, but I've come against an example that I can't explain.
Say we have two types of node, A & B. Each has a unique property, name, with a constraint on it:
CREATE CONSTRAINT ON (a:A) ASSERT a.name IS UNIQUE
CREATE CONSTRAINT ON (b:B) ASSERT b.name IS UNIQUE
Now, if we wish to create a relationship between nodes of either type, like so:
MERGE (a:A {name:1})
MERGE (b:B {name:2})
MERGE (a)-[:REL]->(b)
Our query plan comes up with no eagers in at all.
However, if we want to create a relationship between 2 nodes of the same type:
MERGE (a:A {name:1})
MERGE (b:A {name:2})
MERGE (a)-[:REL]->(b)
the profile comes back with an eager read in it!
We may get rid of the eagerness by changing both of the node merges to matches, but this opens us up to the possibility of not creating the relationship we want to create!
My question is why does this happen for this specific case of creating a relationship between the two nodes of the same label?
I discovered this on Neo 2.3.2.