Skip to main content
Skip to main content

Performance Optimization: Production-Tested Strategies

This guide is part of a collection of findings gained from community meetups. For more real world solutions and insights you can browse by specific problem. Having trouble with Materialized Views? Check out the Materialized Views community insights guide. If you're experiencing slow queries and want more examples, we also have a Query Optimization guide.

Order by Cardinality (Lowest to Highest)

Time Granularity Matters

Focus on Individual Queries, Not Averages

Alexey Milovidov's core insight: "The right way is to ask yourself why this particular query was processed in five seconds... I don't care if median and other queries process quickly I only care about my query"

Instead of looking at average performance, identify specific query patterns that cause problems:

Spot queries with different performance bottlenecks:

The key lesson from production teams: When a query is slow, don't just look at averages. Ask "Why was THIS specific query slow?" and examine the actual resource usage patterns.

Memory vs Row Scanning Trade-offs

Sentry's key insight: "The cardinality of the grouping key that's going to drive memory in this particular situation" - High cardinality aggregations kill performance through memory exhaustion, not row scanning.

Pattern Recognition: When queries fail, determine if it's a memory problem (too many groups) or scanning problem (too many rows).

Compare granularity impact:

High-cardinality danger pattern:

Sentry's sampling solution for memory problems:

The key diagnostic question: Is your query slow because it's reading too many rows, or because it's creating too many aggregation groups? The solution strategies are completely different.

Read Next: