# Count-Min Sketch - Cont'd

+ The minimal count value is return.
+ Due to the large memory consumption of CM sketch, it is not enabled by default.


![`smart`](CountMinSketch02_aa_002_20230915.png)
------------------------------------------------------------------------------
To query the frequency of a particular element, one can hash the element to determine its index in the array and then simply return the count at that index. However, due to the possibility of hash collisions—where different elements map to the same index—this method can lead to overestimations of frequency. To address this, the following optimizations are employed:

1. Utilize multiple arrays and hash functions to compute the array index for each element.
2. When querying the frequency of an element, return the smallest count value from the arrays corresponding to the different hash functions.

Despite these optimizations, the `Count-Min Sketch` structure's two-dimensional array can consume significant memory, particularly when adding additional hash functions to mitigate hash collisions. Consequently, by default, the collection of `Count-Min Sketch` statistics for columns is not performed.

Note:
Due to potential inaccuracies and substantial memory consumption associated with the Count-Min Sketch, it has been disabled by default starting from version 5.3 of the TiDB database. If one wishes to enable it by default in subsequent versions, the system variable `tidb_analyze_version` can be set to 1.

More details can be found here: [Count-Min Sketch Documentation](https://docs.pingcap.com/tidb/stable/statistics#count-min-sketch).