When to Pre-Aggregate
Decide between live aggregation, materialised views, and downstream OLAP — based on freshness and cost.
Three Strategies for Aggregate Queries
- Live — recompute every time
- Materialized — store and refresh periodically
- Triggered/Cached — update incrementally on every change
Live Aggregation
Simple and always fresh:
SELECT user_id, COUNT(*) FROM orders WHERE status = 'paid' GROUP BY user_id;