简体   繁体   English

密码:使用WHERE子句或MATCH属性定义进行完全匹配吗?

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

In Neo4j (version 3.0), the following queries return the same results: 在Neo4j(3.0版)中,以下查询返回相同的结果:

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. 在处理一些大型数据集时,我注意到(并使用EXPLAINPROFILE进行了验证),在某些情况下,第二个查询之类的查询性能更好,更快。 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. neo4j文档和教程也有所不同。 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). docs和tut使用这两个版本,通常倾向于第一个版本(可能是因为只能使用WHERE子句来完成不完全匹配)。 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. 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). 由于Neo4j使用基于成本的优化器,因此查询计划可能会随时间而改变,因为该优化器会考虑更改(也许现在有更多数据,因此索引查找比NodeByLabelScan便宜)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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