1
這兩個假設的Cypher查詢產生相同的結果:爲什麼我應該使用exists()函數進行模式存在?
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
我注意到這些查詢的'PROFILE'輸出有些差異(請參閱我的編輯)。具有'exists()'的查詢具有更緊湊的執行計劃。 –