Looking for an optimized function for histograms similar to approx_percentile

Hi,
We’re using v7.6 and we’re very satisfied to use approx_percentile in our reports.
Now, we have a new generation of reports that require histograms.
Is there an optimized function for histograms ?

Great question Nabil! I’m checking with the team and will update you soon. Thanks for your patience. :pray:

Hi Nabil! We hope you find this reference helpful. Please keep us updated on how it worls out for you! Cheers :dizzy:

Statistics for a table can be collected and updated on an ad hoc basis by running the ANALYZE command. If autostats are disabled for a table, ANALYZE collects column statistics on every column, as well as histograms on chosen columns. You may designate which columns to collect histograms on with the ANALYZE TABLE table_name COLUMNS … {ENABLE | DISABLE} commands, as described in the docs. Collecting column statistics is strongly recommended for optimal query performance. Collecting histograms is recommended in most situations.

See Histogram vs. Sampling for more details.

@Nabil the way I read your question, you want to compute approximate histograms in a SELECT and return them to the client. We don’t support that. But you could code it in a user-defined aggregate function, especially now that we support Wasm UDFs on SingleStoreDB Cloud. Wasm UDFs can be used to define a UDAF, which is just a package of several UDFs.

1 Like