Cypher query optimization question: MATCH vs. WHERE

51 views
Skip to first unread message

Aseem Kishore

unread,
Oct 26, 2012, 4:52:45 PM10/26/12
to Neo4j Discussion
I realize that MATCH is used to find which paths to traverse and WHERE is used to filter them (presumably after they've been read from disk).

But I know work has also gone into optimizing the Cypher parser.

So is there any difference between these two queries:

START a=node(0)
MATCH a -[rel:FOO|BAR|BAZ]-> b
RETURN b

vs.

START a=node(0)
MATCH a -[rel]-> b
WHERE TYPE(rel) IS 'FOO' OR TYPE(rel) IS 'BAR' OR TYPE(rel) IS 'BAZ'
RETURN b

...? Or is one a best practice over the other?

I give this example specifically around multiple relationship types, but does it make a difference if there's just one vs. many?

(And if you need to check the target node type also, you of course have no choice but to put it in the WHERE.)

Thanks!

Aseem


Michael Hunger

unread,
Oct 26, 2012, 5:56:45 PM10/26/12
to ne...@googlegroups.com
Right now the first one should be faster, in the future it won't make a difference as cypher rewrites the query to evaluate the where expressions as early as possible.

Michael
> --
>
>

Reply all
Reply to author
Forward
0 new messages