cockroachdb / cockroachdb/cockroach
opt,stats: consider adding a minimum number of heavy-hitter buckets
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
After the change made in #129378, we now keep track of the most frequent sampled values when building a histogram, and use those "heavy-hitters" to determine some fraction of the histogram boundaries, with the fraction given by `sql.stats.histogram_buckets.max_fraction_most_common_values` (default 10%). When we collect stats on an un-indexed columns, we only create a two-bucket histogram. This prevents the heavy-hitters from being used with the default setting. In such cases where the histogram is small, heavy hitters are probably even more useful than when the histogram is more complete. We should consider adding a minimum bucket count that should be determined by heavy-hitters, so that they can be useful for un-indexed columns.
```
CREATE TABLE t (
single_freq INT -- Mostly unique integers, with one common value.
);
INSERT INTO t (
SELECT
CASE WHEN random() > 0.5 THEN t ELSE 5000 END
FROM generate_series(1, 10000) g(t)
);
ANALYZE t;
SHOW HISTOGRAM ...;
```
Jira issue: CRDB-43711
Contributor guide
Assessment
This issue has not been assessed yet.