简体   繁体   English

neo4j cypher匹配命令串联

[英]neo4j cypher Match command concatenation

are these two Chypher statements identical: 这两个Chypher语句是否相同:

//first
match (a)-[r]->(b),b-[r2]->c

//second
match (a)-[r]->(b)
match b-[r2]->c

The 2 Cypher statements are NOT identical. 2个Cypher语句不同。 We can show this by using the PROFILE command , which shows you how the Cypher engine would perform a query. 我们可以使用PROFILE命令显示此信息,该命令向您显示Cypher引擎如何执行查询。

In the following examples, the queries all end with RETURN a, c , since you cannot have a bare MATCH clause. 在以下示例中,所有查询均以RETURN a, c结尾,因为您不能拥有裸露的MATCH子句。

As you can see, the first query has a NOT(r == r2) filter that the second query does not. 如您所见,第一个查询具有一个NOT(r == r2)过滤器,而第二个查询则没有。 This is because Cypher makes sure that the result of a single MATCH clause does not contain duplicate relationships. 这是因为Cypher确保单个MATCH子句的结果不包含重复关系。

  1. First query 第一次查询

     profile match (a)-[r]->(b),b-[r2]->c return a,c; ==> +-----------------------------------------------+ ==> | a | c | ==> +-----------------------------------------------+ ==> | Node[1]{name:"World"} | Node[0]{name:"World"} | ==> +-----------------------------------------------+ ==> 1 row ==> 2 ms ==> ==> Compiler CYPHER 2.3 ==> ==> Planner COST ==> ==> Runtime INTERPRETED ==> ==> Projection ==> | ==> +Filter ==> | ==> +Expand(All)(0) ==> | ==> +Expand(All)(1) ==> | ==> +AllNodesScan ==> ==> +----------------+---------------+------+--------+----------------+----------------+ ==> | Operator | EstimatedRows | Rows | DbHits | Identifiers | Other | ==> +----------------+---------------+------+--------+----------------+----------------+ ==> | Projection | 1 | 1 | 0 | a, b, c, r, r2 | a; c | ==> | Filter | 1 | 1 | 0 | a, b, c, r, r2 | NOT(r == r2) | ==> | Expand(All)(0) | 1 | 2 | 4 | a, b, c, r, r2 | (b)-[r2:]->(c) | ==> | Expand(All)(1) | 2 | 2 | 8 | a, b, r | (b)<-[r:]-(a) | ==> | AllNodesScan | 6 | 6 | 7 | b | | ==> +----------------+---------------+------+--------+----------------+----------------+ ==> 
  2. Second query 第二查询

     profile match (a)-[r]->(b) match b-[r2]->c return a,c; ==> +-----------------------------------------------+ ==> | a | c | ==> +-----------------------------------------------+ ==> | Node[1]{name:"World"} | Node[1]{name:"World"} | ==> | Node[1]{name:"World"} | Node[0]{name:"World"} | ==> +-----------------------------------------------+ ==> 2 rows ==> 2 ms ==> ==> Compiler CYPHER 2.3 ==> ==> Planner COST ==> ==> Runtime INTERPRETED ==> ==> Projection ==> | ==> +Expand(All)(0) ==> | ==> +Expand(All)(1) ==> | ==> +AllNodesScan ==> ==> +----------------+---------------+------+--------+----------------+----------------+ ==> | Operator | EstimatedRows | Rows | DbHits | Identifiers | Other | ==> +----------------+---------------+------+--------+----------------+----------------+ ==> | Projection | 1 | 2 | 0 | a, b, c, r, r2 | a; c | ==> | Expand(All)(0) | 1 | 2 | 4 | a, b, c, r, r2 | (b)-[r2:]->(c) | ==> | Expand(All)(1) | 2 | 2 | 8 | a, b, r | (b)<-[r:]-(a) | ==> | AllNodesScan | 6 | 6 | 7 | b | | ==> +----------------+---------------+------+--------+----------------+----------------+ 

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

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