Embracing the Messiness in Search of Epic Solutions

Neo4j: WHERE Clause vs Curly Braces in MATCH Clause

Posted

in

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.

Comments

Leave a Reply