简体   繁体   English

在Cypher中使用match({property})和WHERE子句之间的区别

[英]Difference between using match({property}) and WHERE clause in Cypher

I've noticed that match(a:Vegetable{name:'Cellery'}) return a and match(a:Vegetable) where a.name='Cellery' return a gives me the same result. 我注意到match(a:Vegetable{name:'Cellery'}) return amatch(a:Vegetable) where a.name='Cellery' return a给我相同的结果。

Are there any practical differences between the two? 两者之间是否有实际区别? The first form seems to work well when you know the property value, but is there a way to use wildcards or a LIKE condition with it? 当您知道属性值时,第一种形式似乎可以很好地工作,但是是否可以使用通配符或LIKE条件呢?

The EXPLAIN and PROFILE options show the execution plan of the query. EXPLAINPROFILE选项显示查询的执行计划。

They show the exact same execution plan for both queries (on an empty database). 它们显示两个查询完全相同的执行计划(在空数据库上)。

在此处输入图片说明

在此处输入图片说明

So performance-wise, the two notations should be completely the same. 因此,从性能角度来看,这两种表示法应该完全相同。

The first form seems to work well when you know the property value, but is there a way to use wildcards or a LIKE condition with it? 当您知道属性值时,第一种形式似乎可以很好地工作,但是是否可以使用通配符或LIKE条件呢?

That's correct, WHERE gives you a lot more flexibility. 没错, WHERE为您提供了更多的灵活性。 Basically, the MATCH clause only allows you to check for equalities that could be written as WHERE a.prop1 = value1 AND a.prop2 = value2 AND ... . 基本上, MATCH子句仅允许您检查可以写为WHERE a.prop1 = value1 AND a.prop2 = value2 AND ... Meanwhile, WHERE allows you a lot more: the AND / OR / XOR and NOT logical operators, checking for inequalities; 同时, WHERE还提供了更多功能: AND / OR / XORNOT逻辑运算符,用于检查不等式; using STARTS WITH , CONTAINS , ENDS WITH and regular expressions; 使用STARTS WITHCONTAINSENDS WITH和正则表达式; checking for node types like WHERE (a:SomeLabel) or even checking if the variables of the match are part of a pattern like WHERE NOT (a)-[:SOME_REL]->(:SomeLabel) . 检查像WHERE (a:SomeLabel)这样的节点类型,甚至检查匹配变量是否是WHERE NOT (a)-[:SOME_REL]->(:SomeLabel)

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

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