uniq
Introduced in: v1.1.0 Calculates the approximate number of different values of the argument. The function uses an adaptive sampling algorithm. For the calculation state, the function uses a sample of element hash values up to 65536. This algorithm is very accurate and very efficient on the CPU. When the query contains several of these functions, using uniq is almost as fast as using other aggregate functions.Implementation details
Implementation details
This function calculates a hash for all parameters in the aggregate, then uses it in calculations.
It uses an adaptive sampling algorithm.
For the calculation state, the function uses a sample of element hash values up to 65536.
This algorithm is very accurate and very efficient on the CPU.
When the query contains several of these functions, using
uniq is almost as fast as using other aggregate functions.The sample keeps 32-bit hashes, which cannot distinguish more than a few billion values, so in addition
a small heavily-thinned-out sample of full 64-bit hashes is maintained (about one hash per 262144 values,
bounded by 16384 hashes), and the estimate switches to it at around two billion. This keeps the estimate
accurate (within about 1%) for cardinalities of hundreds of billions and more, where servers older
than 26.8 returned garbage (issue #6078). States written by those servers carry no 64-bit sample,
so merging with them keeps only the 32-bit precision for the merged-in values.x— The function takes a variable number of parameters.Tuple(T)orArray(T)orDateorDateTimeorStringor(U)Int*orFloat*orDecimal
UInt64
Examples
Example usage
Query
Response
Query
Response