# `VERSION::6.1.0` The Memory Quota for the Gathering Job

+ **`tidb_mem_quota_analyze`**
    + Minimum value: should be greater than the maximum memory usage when TiDB collects statistics from the table with the most columns.
    + Maximum value: should be less than the available memory when TiDB is not collecting statistics
    + Note: This TiDB variable is not applicable to TiDB Cloud.
------------------------------------------------------------------------------
In TiDB, the system variable `tidb_mem_quota_analyze` is used to control the memory allocation for statistics collection.

To determine an appropriate value for `tidb_mem_quota_analyze`, consider the data size of the cluster. When using the default sampling rate, focus primarily on the number of columns, the size of column values, and TiDB's memory configuration. Here are guidelines for setting the maximum and minimum values:

- Minimum value: This should exceed the maximum memory usage required when TiDB collects statistics from the table with the most columns.
- Maximum value: This should be less than the available memory when TiDB is not engaged in statistics collection.

The estimated memory consumption for statistics can be calculated using the following formula:

Memory = (Number of buckets + `TopN` Count) * Column Width * Number of Columns/Indexes to be statistics analyzed

The default number of buckets is 256, and the default `TopN` count is 500. If there is insufficient memory available, it is recommended to adjust the number of buckets and `TopN` count accordingly, for example by setting buckets to 64 and `TopN` to 100.

For instance, if there are 1,000 tables with `buckets=256` and `TopN=500`, and on average each table collects statistical information for only 4 indexes with an average data size of 1KB, the approximate memory consumption would be:
`(256 + 500) * 1KB * 1000 * 4 = 2GB`

Note: This TiDB variable is not applicable to TiDB Cloud.