简体   繁体   中英

Difference in use of constrains to a MATCH-clause in Cypher

Is there any difference between these two queries:

MATCH (p:Person {name:'Alice'})
RETURN p

and

MATCH (p:Person)
WHERE p.name = 'Alice'
RETURN p

I know the result is the same,

but is there any difference in how the query is being executed?

There is no difference between those two queries, the execution plan will be the same.

The first one is just a syntax sugar of the second version.

Cheers

This question already has an accepted answer, but for other questions along the lines of "Is query X and query Y the same?", one can look at their execution plans to compare.

To view the execution plan without running the query, add EXPLAIN before the query and run it, and you'll get a visual of which operators and in which order, would be used to compute the results. The drawback to this is that the estimates of the number of rows can be off, so you can obtain more specific results by adding PROFILE before your query, which actually runs the query. Then by comparing the operators, and the results of each operation, you can conclude whether or not query X and query Y are the same.

In both of your queries, the execution plan looks like

执行计划

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM