【发布时间】:2017-08-24 23:14:25
【问题描述】:
这两个假设的 Cypher 查询产生相同的结果:
MATCH(s:Start)
WHERE exists((s)-[:CONNECTED_TO]->(:End))
RETURN s
和
MATCH(s:Start)
WHERE (s)-[:CONNECTED_TO]->(:End)
RETURN s
唯一的区别是第二个查询没有调用exists() 函数,但语义上这两个查询是相等的。对吧?
那么,为什么以及何时应该使用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
【问题讨论】: