Christos Hadjinikolis
Christos Hadjinikolis

Reputation: 2158

MATCH clause with filtering properties or MATCH with a WHERE clause?

I just have a very simple question to ask. Assume the sample movie database provided by neo4j and the following two queries:

MATCH (n:Person)-[:ACTED_IN]->(m:Movie {title:"The Matrix"}) 
RETURN n,m

and

MATCH (n:Person)-[:ACTED_IN]->(m:Movie) 
WHERE m.title = "The Matrix" 
RETURN n,m

Are the two queries computationally equivalent or is it the case that the first case is more efficient?

The way I see it, it seems like in the first case, MATCH produces the requested subgraph "on-the-fly" while traversing the original graph. In the second case though, a larger sub-graph is produced by MATCH which is then reduced to the requested one, once the redundant nodes are filtered, right? Can anybody somehow corroborate this assumption, or is it false?

Upvotes: 1

Views: 101

Answers (1)

Evgen
Evgen

Reputation: 1338

If you want to check in your version of neo4j if this queries are the same, you should use profile statement. Look here for more information http://neo4j.com/docs/stable/how-do-i-profile-a-query.html

Upvotes: 1

Related Questions