在返回分页数据的同一查询中,有一个技巧可以计算元素总数,例如:
.. 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