PERCENTILE_APPROX

Description

Syntax

PERCENTILE_APPROX(expr, DOUBLE p[, DOUBLE compression])

Return the approximation of the point p, where the value of P is between 0 and 1.

Compression param is optional and can be setted to a value in the range of [2048, 10000]. The bigger compression you set, the more precise result and more time cost you will get. If it is not setted or not setted in the correct range, PERCENTILE_APPROX function will run with a default compression param of 10000.

This function uses fixed size memory, so less memory can be used for columns with high cardinality, and can be used to calculate statistics such as tp99.

example

  1. MySQL > select `table`, percentile_approx(cost_time,0.99) from log_statis group by `table`;
  2. +---------------------+---------------------------+
  3. | table | percentile_approx(`cost_time`, 0.99) |
  4. +----------+--------------------------------------+
  5. | test | 54.22 |
  6. +----------+--------------------------------------+
  7. MySQL > select `table`, percentile_approx(cost_time,0.99, 4096) from log_statis group by `table`;
  8. +---------------------+---------------------------+
  9. | table | percentile_approx(`cost_time`, 0.99, 4096.0) |
  10. +----------+--------------------------------------+
  11. | test | 54.21 |
  12. +----------+--------------------------------------+

keyword PERCENTILE_APPROX,PERCENTILE,APPROX