My question is: why is the WHERE statement not working as fast as expected? I have 7 nodes labeled Consumer . Here are some sample data ...
MERGE (c:Consumer {mobileNumber: "000000000000"}) MERGE (:Consumer {mobileNumber: "111111111111"}) MERGE (:Consumer {mobileNumber: "222222222222"}) MERGE (:Consumer {mobileNumber: "333333333333"}) MERGE (:Consumer {mobileNumber: "444444444444"}) MERGE (:Consumer {mobileNumber: "555555555555"}) MERGE (:Consumer {mobileNumber: "666666666666"}) WITH c MATCH (c1:Consumer) WHERE c1.mobileNumber <> "000000000000" MERGE (c)-[:HAS_CONTACT]->(c1)
And between :Consumer(mobileNumber:{"000000000000"}) and all the other 6 nodes there is a HAS_CONTACT connection. There is also a unique index constraint on the mobileNumber field. Now when I try to execute the request below:
PROFILE MATCH (n:Consumer{mobileNumber : "000000000000"}), (m:Consumer{mobileNumber : "111111111111"}) WITH n,m MATCH path = SHORTESTPATH((n)-[contacts:HAS_CONTACT]-(m)) RETURN contacts;
Thus, it works fine, as expected (search nodes based on a unique index). The following is its result: 
Now modify the query above using the WHERE :
PROFILE MATCH (n:Consumer{mobileNumber : "000000000000"}), (m:Consumer) WHERE m.mobileNumber IN (["111111111111"]) WITH n,m MATCH path = SHORTESTPATH((n)-[contacts:HAS_CONTACT]-(m)) RETURN contacts;
Request Result: 
Now, although the above query works fine and gives the same result as the old one. But for endNode, where I used the WHERE , it does not use any indexes. First, it searches for all existing nodes, and then filters the result using the WHERE , which can be too expensive if there are hundreds of thousands of nodes with the same label.
So my questions are:
- Why doesn't it use indexes when I use the
WHERE ? - What is the best way to reference multiple nodes with fewer db deletes?
- Can I use the
IN operator while waiting for an index search?
source share