以下是两个不同的查询及其计划。查询结果完全相同,但请注意查询计划不同。
关键区别在于使用AllRelationships(identifier="r",...)
和TraversalMatcher(trail="(n)-[r WHERE true AND true]->(m)", ...)
问题:
return
不包含n
子句中提到的m
或MATCH
,这表明不需要遍历。查询:
neo4j-sh (?)$ profile start r=relationship(*) return count(r);
+----------+
| count(r) |
+----------+
| 100975 |
+----------+
1 row
ColumnFilter(symKeys=[" INTERNAL_AGGREGATEdd639fdf-1939-4b9c-ba36-213a0e79fff5"], returnItemNames=["count(r)"], _rows=1, _db_hits=0)
EagerAggregation(keys=[], aggregates=["( INTERNAL_AGGREGATEdd639fdf-1939-4b9c-ba36-213a0e79fff5,Count(r))"], _rows=1, _db_hits=0)
AllRelationships(identifier="r", _rows=100975, _db_hits=100975)
neo4j-sh (?)$ profile match n-[r]->m return count(r);
+----------+
| count(r) |
+----------+
| 100975 |
+----------+
1 row
ColumnFilter(symKeys=[" INTERNAL_AGGREGATE961900f2-76e0-40a0-bcab-5e8db2683859"], returnItemNames=["count(r)"], _rows=1, _db_hits=0)
EagerAggregation(keys=[], aggregates=["( INTERNAL_AGGREGATE961900f2-76e0-40a0-bcab-5e8db2683859,Count(r))"], _rows=1, _db_hits=0)
TraversalMatcher(trail="(n)-[r WHERE true AND true]->(m)", _rows=100975, _db_hits=301372)
答案 0 :(得分:0)
我猜顶级查询更快,因为列出的db命中数更小。在底层查询中,我认为它正在迭代图中的所有节点。试试这个,如果你运行:
start n=nodes(*) return count(n);
我打赌你得到:301372