percentile_cont and
percentile_disc functions.
tdigest is one of two advanced percentile approximation aggregates provided in TimescaleDB Toolkit. It is a
space-efficient aggregation, and it provides more accurate estimates at extreme quantiles than traditional methods.
tdigest is somewhat dependent on input order. If tdigest is run on the same data arranged in different order, the
results should be nearly equal, but they are unlikely to be exact.
The other advanced percentile approximation aggregate is uddsketch, which produces stable estimates
within a guaranteed relative error. If you aren’t sure which to use, try the default percentile estimation method,
percentile_agg. It uses the uddsketch algorithm with some sensible defaults.
Two-step aggregation
This group of functions uses the two-step aggregation pattern. Rather than calculating the final result in one step, you first create an intermediate aggregate by using the aggregate function. Then, use any of the accessors on the intermediate aggregate to calculate a final result. You can also roll up multiple intermediate aggregates with the rollup functions. The two-step aggregation pattern has several advantages:- More efficient because multiple accessors can reuse the same aggregate
- Easier to reason about performance, because aggregation is separate from final computation
- Easier to understand when calculations can be rolled up into larger intervals, especially in window functions and continuous aggregates
- Perform retrospective analysis even when underlying data is dropped, because the intermediate aggregate stores extra information not available in the final result
Samples
Aggregate and roll up percentile data to calculate daily percentiles
Create an hourly continuous aggregate that contains a percentile aggregate:Available functions
Aggregate
tdigest(): aggregate data in a t-digest for percentile calculation
Accessors
approx_percentile(): estimate the value at a given percentile from a t-digestapprox_percentile_rank(): estimate the percentile rank of a given value from a t-digestmax_val(): get the maximum value from a t-digestmean(): calculate the exact mean from values in a t-digestmin_val(): get the minimum value from a t-digestnum_vals(): get the number of values in a t-digest
Rollup
rollup(): combine multiple t-digest aggregates