Cypher: Use WHERE clause or MATCH property definition for exact match?

你。 提交于 2019-12-19 19:43:18

问题


In Neo4j (version 3.0), the following queries return the same results:

1. MATCH (a:Label) WHERE a.property = "Something" RETURN a
2. MATCH (a:Label {property: "Something"}) RETURN a

While playing with some large datasets, I noticed (and verified using EXPLAIN and PROFILE) that for some instances, queries like the second one performs better and faster. While other instances exist where both versions performed equally, I didn't yet see one where the first version performed better.

The neo4j documentation and tutorials are also divided. There's no explicit comparison between the two. The docs and tuts use both versions, often leaning towards the first (probably because non-exact matches can only be done using the WHERE clause). But the guidelines also state that the earlier you narrow down the search, the faster the search is.

  1. Am I right that both versions will always return the same results?
  2. Am I right that the second version will often perform better because it narrows down the search earlier?

回答1:


  1. yes
  2. no, both evaluate basically to the very same query plan. Since Neo4j uses a cost based optimizer the query plan might change over time since the optimizer consider to change (maybe there's now more data so a index lookup is cheaper than a NodeByLabelScan).


来源:https://stackoverflow.com/questions/37225763/cypher-use-where-clause-or-match-property-definition-for-exact-match

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!