cockroachdb / cockroachdb/cockroach

opt,stats: consider adding a minimum number of heavy-hitter buckets

Open
#133,644 1 comment 0 reactions 0 assignees View on GitHub
A-sql-table-stats C-enhancement O-qa T-sql-queries
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.