Neo4j Cypher通过收集/大小/展开和查询的性能/可伸缩性来计算计数



在返回分页数据的同一查询中,有一个技巧可以计算元素总数,例如:

.. some calculations
WITH childD  
WITH collect({`childD`:childD }) as aggregate
WITH aggregate, size(aggregate) as count 
UNWIND aggregate as item 
WITH count, item.childD as childD 
... proceed

我现在正在决定是否采取这种做法。我关心这样一个查询的可伸缩性和性能。我在使用这种方法时会遇到问题吗?我应该避免它吗?还是这是正常的做法?目前,我只能对20k个节点进行测试,但大约100k或更多。你能从Neo4j Cypher的理论角度回答这个问题吗?谢谢

更新

这就是为什么我使用地图:

WITH childD, weight, totalVotes  
WITH collect({`childD`:childD ,`weight`:weight, `totalVotes`: totalVotes }) as aggregate 
WITH aggregate, size(aggregate) as count 
UNWIND aggregate as item WITH count, item.childD as childD , item.weight as weight, item.totalVotes as totalVotes

是的,这是在Cypher中使用收集和展开来获得组计数的正确方法。但是,我不明白您为什么要在collect语句中创建映射。我会这样做的。

.. some calculations
WITH childD  
WITH collect(childD) as aggregate
WITH aggregate, size(aggregate) as count 
UNWIND aggregate as childD 
WITH count, childD 
... proceed

这篇博文可能会有所帮助。https://medium.com/neo4j/kickstart-your-transition-from-sql-analytic-and-window-functions-to-neo4j-987d67f7fdb4

相关内容

  • 没有找到相关文章