Aggregate State And Merge

Generic Description

Use aggregate state and merge forms when you need to store partial aggregate state now and combine it later without keeping the full raw input stream around.

Simple example:

MATCH (u:User)-[:HAS_APP_SESSION]->(s:AppSession)
WITH u.profile.location.country AS country,
     avg_state(s.duration_seconds) AS duration_state
RETURN country, avg_merge(duration_state) AS avg_duration

Consumer-Level Explanation

State and merge forms matter when you want aggregation to be composable.

Instead of only asking for the final answer, you ask for a mergeable partial answer. That is useful for:

The current implementation now supports broad state and merge coverage across:

More Detailed Explanation

This surface exists because “aggregate now, combine later” is a core optimization primitive.

Without explicit state and merge forms, systems usually end up doing one of two bad things:

Nexyron exposes the idea directly in Cypher through forms such as:

That design also lines up with the current spill-backed executor, which can keep grouped workloads exact on the supported subset by carrying mathematically sufficient partial state rather than inventing approximate shortcuts.

Advanced Example

MATCH (u:User)-[e:VIEWED]->(d:Document)
TIME e.ts BETWEEN datetime('2025-01-01T00:00:00Z') AND datetime('2025-02-01T00:00:00Z')
WITH date_trunc('day', e.ts) AS day_bucket,
     avgstate(properties(d).prize) AS partial_state
RETURN day_bucket,
       avgmerge(partial_state) AS merged_metric
ORDER BY day_bucket

Real Use Cases

Real Limitations And Tradeoffs