...
match (a:A) where ...
...
...
with p1, p2, ... ... => missing "a" here
...
...
merge (b:B{p1: p1, p2: p2})
merge (a)-[:HAS]->(b)
This case generates massive empty nodes and its relationships without any warning if b is massive nodes. So be careful until it can be warned in the future :)
It is expected behavior. Since you did not pass through your value of 'a', then the merge creates a new node, binds it to variable 'a', then relates it to 'b'. This is the behavior of 'merge'.