Make AutoAnalyzeMinCnt configurable
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
We have a hardcoded variable in TiDB called `AutoAnalyzeMinCnt`. We use this variable to control how large a table must be before considering it in the analyze priority queue.
https://github.com/pingcap/tidb/blob/master/pkg/statistics/table.go#L67
Right now, we hardcode it with 1000, which means only table row counts greater than 1000 can be analyzed by the priority queue.
But in two cases we may want to teewking this config:
1. If some tiny tables join with large tables, statistics on those tiny tables can still help. But with this hardcoded variable, we could not let auto-analyze collect the statistics automatically.
2. On TiDB Start or TiDB Zero, we may have very small ad hoc tables in the cluster. There is no need to collect stats for them, and nothing will be hurt because usually, on these tiers, the traffic and queries are very light. So avoiding collecting stats can help us further reduce memory usage.
So it would be nice if we could make this a global-only variable. Then we can tweak this value for different scenarios and clusters.
Contributor guide
Research direction
Start at pkg/statistics/table.go around the AutoAnalyzeMinCnt definition and trace where it controls admission to the analyze priority queue. Then inspect how TiDB exposes global-only variables. Done means the threshold can be changed globally and the priority queue uses the configured value, with coverage for the described small-table cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 56/100