Cypher:使用 WHERE 子句或 MATCH 属性定义进行精确匹配? [英] Cypher: Use WHERE clause or MATCH property definition for exact match?

查看:30
本文介绍了Cypher:使用 WHERE 子句或 MATCH 属性定义进行精确匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Neo4j(3.0 版)中,以下查询返回相同的结果:

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

在处理一些大型数据集时,我注意到(并使用 EXPLAINPROFILE 验证)在某些情况下,像第二个这样的查询执行得更好更快.虽然存在两个版本性能相同的其他实例,但我还没有看到第一个版本性能更好的实例.

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.

neo4j 文档和教程也有划分.两者之间没有明确的比较.docs 和 tuts 使用这两个版本,通常倾向于第一个(可能是因为使用 WHERE 子句可以完成非精确匹配).但指南还指出,越早缩小搜索范围,搜索速度就越快.

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. 两个版本总是返回相同的结果是否正确?
  2. 第二个版本通常会表现得更好,因为它更早地缩小了搜索范围,我是对的吗?

推荐答案

  1. 是的
  2. 不,两者基本上都评估为完全相同的查询计划.由于 Neo4j 使用基于成本的优化器,查询计划可能会随着时间的推移而改变,因为优化器会考虑更改(也许现在有更多数据,因此索引查找比 NodeByLabelScan 便宜).

这篇关于Cypher:使用 WHERE 子句或 MATCH 属性定义进行精确匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆