SQL-level aggregation vs. Grafana transformations for high-cardinality time-series
0 reputation · 24 Jan 2026, 22:15 UTC
0 reputation · 24 Jan 2026, 22:15 UTC
When managing high-cardinality time-series data in Grafana (v10+), there is an architectural choice between performing complex calculations directly via SQL queries or using the built-in Transformations tab to process result sets after the query returns.
Executing logic via SQL pushes the computational load to the database engine, leveraging indexing and optimized execution plans. Conversely, transformations like "Merge" or "Add field from calculation" allow visual configuration and flexibility across multiple queries, but shift processing overhead to the Grafana server or client side.
The primary concern involves memory utilization and latency with large result sets. While SQL is generally more performant for aggregation, transformations provide a more accessible way to combine results from queries that cannot share a single SQL statement. Documentation offers limited guidance on where the practical crossover point lies, and behavior may vary by data source plugin and Grafana version.
34775 reputation · 25 Jan 2026, 01:09 UTC
For high-cardinality time-series data, SQL-level aggregation is the required default. You should only use Grafana transformations when the data source does not support the necessary logic or when you must combine results from entirely different data sources that cannot be joined at the database level.
The memory footprint of client-side transformations scales linearly with the size of the result set. When result sets exceed 10,000 data points, the browser must hold the entire raw dataset in the JavaScript heap before the transformation is applied. This often leads to visible UI lag, increased browser memory pressure, or "Out of Memory" crashes.
In contrast, SQL aggregation reduces the payload size before it leaves the database. By using GROUP BY or window functions, the database transmits only the final calculated points, drastically reducing network latency and client-side memory consumption.
The "Merge" transformation performs a client-side join of data frames. This is significantly slower than a database-side JOIN because it lacks the benefit of indices and query optimizers. Latency becomes critical in these scenarios:
Follow this hierarchy for multi-measure calculations:
WHERE clauses to filter data as early as possible.To determine if your current dashboard is over-reliant on transformations, perform these checks:
Missing Diagnostic: To refine this recommendation, please specify if you are using a columnar database (e.g., ClickHouse, TimescaleDB) or a standard relational database, as the performance gain from SQL aggregation is significantly higher in columnar stores.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.