neo4j 密码匹配命令连接
Posted
技术标签:
【中文标题】neo4j 密码匹配命令连接【英文标题】:neo4j cypher Match command concatenation 【发布时间】:2015-06-23 11:38:07 【问题描述】:这两个 Chypher 语句是否相同:
//first
match (a)-[r]->(b),b-[r2]->c
//second
match (a)-[r]->(b)
match b-[r2]->c
【问题讨论】:
是的,它们是相同的 【参考方案1】:这 2 个 Cypher 语句并不相同。我们可以使用PROFILE command 来展示这一点,它向您展示了 Cypher 引擎将如何执行查询。
在以下示例中,查询都以 RETURN a, c
结尾,因为您不能有一个空的 MATCH
子句。
如您所见,第一个查询有一个 NOT(r == r2)
过滤器,而第二个查询没有。这是因为 Cypher 确保单个 MATCH
子句的结果不包含重复关系。
第一次查询
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 | |
==> +----------------+---------------+------+--------+----------------+----------------+
==>
第二次查询
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 | |
==> +----------------+---------------+------+--------+----------------+----------------+
【讨论】:
哇,这真是太棒了,谢谢!我刚刚检查了一下,(a)-[r]->(b),b-[r2]->c
似乎与PROFILE
和(a)-[r]->(b)-[r2]->c
相同,这是有道理的。以上是关于neo4j 密码匹配命令连接的主要内容,如果未能解决你的问题,请参考以下文章