neo4j cypher 匹配命令串联

标签 neo4j cypher

这两个 Chypher 语句是否相同:

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

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

最佳答案

2 个 Cypher 语句并不相同。我们可以使用 PROFILE command 来显示这一点,它向您展示了 Cypher 引擎将如何执行查询。

在下面的示例中,查询都以 RETURN a, c 结尾,因为您不能有一个裸露的 MATCH 子句。

如您所见,第一个查询有一个 NOT(r == r2) 过滤器,而第二个查询没有。这是因为 Cypher 确保单个 MATCH 子句的结果不包含重复关系。

  1. 第一次查询

    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. 第二次查询

    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 |                |
    ==> +----------------+---------------+------+--------+----------------+----------------+
    

关于neo4j cypher 匹配命令串联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31001752/

相关文章:

algorithm - 如何在运行 Neo4j 的 louvain 算法 : java. lang.ArrayIndexOutOfBoundsException : -1? 的上下文中修复以下错误

clojure - Datomic 与 Neo4j 相比如何?

neo4j - 在 Neo4j 中将箭头/关系建模为节点

java - 如何使用密码迭代具有多个值的列?

csv - neo4j 导入带有关系的 CSV

neo4j - 我如何使用 Cypher 获得两个节点之间相同关系的数量

python-3.x - neo4j - python 驱动程序,服务不可用

python - neo4j,在论坛结构中,如何查找每个帖子得到了多少回复(包括 child 的 child ......)

java - 如何使用 Cypher 返回节点的所有属性及其名称和值

database - neo4j 2.1.7 : How can I index my current data which was there before