Skip to content

3.9 Fan-out aggregate — count over fetched data

MATCH (me:AssistantUser)-[:EMAILED]->(p:Person)-[:HAS_GITHUB]->(g)
WITH p, COUNT { (g)-[:RAISED]->(:GitHubIssue) } AS issues
ORDER BY issues DESC LIMIT 1
RETURN p.name, issues

Means: “Which person I email has raised the most GitHub issues?”

How it executes:

  • Probe + resolve bridges for all emailed people.
  • For the COUNT { (g)-[:RAISED]->(:GitHubIssue) }, the engine materializes each identity’s issues — but because the issues are only counted, not returned, it can fetch an existence/count shape (a one-page semijoin per author) rather than every issue’s full body.
  • Run the aggregate over the materialized counts, order, take the top.

Aggregates (COUNT, sum, collect, max) work over virtual nodes exactly as over real ones; the engine’s job is to materialize enough to answer them within the caps.