Neo4j: WHERE Clause vs Curly Braces in MATCH Clause

PROBLEM

With Cypher Query Language, you can write similar queries that yield the same result.

For example:-

MATCH (p:Person)-[:loves]->(b:Beverage) 
WHERE b.name = 'Dark Roast' 
RETURN p.name as PERSON

… AND …

MATCH (p:Person)-[:loves]->(b:Beverage{name:'Dark Roast'}) 
RETURN p.name as PERSON

… returns the same result.

So, which one is better in terms of performance?

SOLUTION

Neo4j provides a very helpful command called EXPLAIN that allows us to do some investigation ourselves.

The EXPLAIN command displays the query plan without actually executing the query.

To use it, just add EXPLAIN in front of the query.

In this example, both queries produce exactly the same query plan.

In another word, while both queries look slightly different, they perform exactly the same.

Leave a Reply

Your email address will not be published. Required fields are marked *