Neo4j 为什么要使用exists()函数来表示模式存在?
这两个假设的密码查询产生相同的结果:Neo4j 为什么要使用exists()函数来表示模式存在?,neo4j,cypher,Neo4j,Cypher,这两个假设的密码查询产生相同的结果: MATCH(s:Start) WHERE exists((s)-[:CONNECTED_TO]->(:End)) RETURN s 及 唯一的区别是第二个查询没有对函数的调用,但在语义上这两个查询是相等的。对吧? 那么,为什么以及何时应该使用exists()函数将模式作为参数传递 编辑: 我注意到PROFILE的输出中存在一些差异: PROFILE MATCH(s:Start) WHERE exists((s)-[:CONNECTED_TO]->
MATCH(s:Start)
WHERE exists((s)-[:CONNECTED_TO]->(:End))
RETURN s
及
唯一的区别是第二个查询没有对函数的调用,但在语义上这两个查询是相等的。对吧?
那么,为什么以及何时应该使用exists()
函数将模式作为参数传递
编辑:
我注意到PROFILE
的输出中存在一些差异:
PROFILE MATCH(s:Start)
WHERE exists((s)-[:CONNECTED_TO]->(:End))
RETURN s
+------------------+----------------+------+---------+-----------+-----------------------------------------------+
| Operator | Estimated Rows | Rows | DB Hits | Variables | Other |
+------------------+----------------+------+---------+-----------+-----------------------------------------------+
| +ProduceResults | 2 | 1 | 0 | s | s |
| | +----------------+------+---------+-----------+-----------------------------------------------+
| +Filter | 2 | 1 | 5 | s | NestedExpression(Filter-Expand(All)-Argument) |
| | +----------------+------+---------+-----------+-----------------------------------------------+
| +NodeByLabelScan | 3 | 3 | 4 | s | :Start |
+------------------+----------------+------+---------+-----------+-----------------------------------------------+
Total database accesses: 9
PROFILE MATCH(s:Start)
WHERE (s)-[:CONNECTED_TO]->(:End)
RETURN s
+------------------+----------------+------+---------+-------------------------+-------------------------+
| Operator | Estimated Rows | Rows | DB Hits | Variables | Other |
+------------------+----------------+------+---------+-------------------------+-------------------------+
| +ProduceResults | 2 | 1 | 0 | s | s |
| | +----------------+------+---------+-------------------------+-------------------------+
| +SemiApply | 2 | 1 | 0 | s | |
| |\ +----------------+------+---------+-------------------------+-------------------------+
| | +Filter | 1 | 0 | 1 | anon[29], anon[47], s | anon[47]:End |
| | | +----------------+------+---------+-------------------------+-------------------------+
| | +Expand(All) | 1 | 1 | 4 | anon[29], anon[47] -- s | (s)-[:CONNECTED_TO]->() |
| | | +----------------+------+---------+-------------------------+-------------------------+
| | +Argument | 3 | 3 | 0 | s | |
| | +----------------+------+---------+-------------------------+-------------------------+
| +NodeByLabelScan | 3 | 3 | 4 | s | :Start |
+------------------+----------------+------+---------+-------------------------+-------------------------+
Total database accesses: 9
在WHERE子句中使用时,它们在语义上应该是相等的,但是在WHERE子句之外还需要exists() 一个例子是,当您想要一个布尔值来表示模式是否存在时
MATCH (s:Start)
RETURN exists((s)-[:CONNECTED_TO]->(:End)) as connectedToEnd
我注意到这些查询的
PROFILE
输出中存在一些差异(请参见我的编辑)。带有exists()
的查询具有更紧凑的执行计划。
MATCH (s:Start)
RETURN exists((s)-[:CONNECTED_TO]->(:End)) as connectedToEnd