cockroachdb / cockroachdb/cockroach
sql/stats: support per-statement histogram bucket count in CREATE STATISTICS
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
Currently the histogram bucket count is configurable via the cluster setting `sql.stats.histogram_buckets.count` and the per-table storage parameter `sql_stats_histogram_buckets_count`, but there's no way to override it for a single `CREATE STATISTICS` invocation. This means collecting a one-off high-resolution histogram for diagnostics requires temporarily altering the table's storage parameter and reverting it afterward.
Propose adding an option like `CREATE STATISTICS ... WITH OPTIONS (histogram_buckets = N)` to allow per-statement overrides.
Both `mergeHistograms` (`pkg/sql/stats/merge.go`) and the forecasting system (`pkg/sql/stats/forecast.go`, which operates in quantile-function space) are bucket-count-agnostic, so mixed bucket counts in a column's history are handled gracefully.
Epic: none
Jira issue: CRDB-65478
Contributor guide
Research direction
Start by tracing the CREATE STATISTICS implementation and how it reads sql.stats.histogram_buckets.count and sql_stats_histogram_buckets_count. Review pkg/sql/stats/merge.go and pkg/sql/stats/forecast.go to confirm their bucket-count-agnostic behavior. Done means a single CREATE STATISTICS invocation can override the histogram bucket count without changing the cluster setting or table storage parameter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, sql
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100