Skip to content

sql/stats: add per-table sql_stats_forecasts_min_goodness_of_fit stor…#169686

Draft
michae2 wants to merge 1 commit intocockroachdb:masterfrom
michae2:michae2/forecast-min-gof-table-setting
Draft

sql/stats: add per-table sql_stats_forecasts_min_goodness_of_fit stor…#169686
michae2 wants to merge 1 commit intocockroachdb:masterfrom
michae2:michae2/forecast-min-gof-table-setting

Conversation

@michae2
Copy link
Copy Markdown
Collaborator

@michae2 michae2 commented May 4, 2026

…age parameter

The cluster setting sql.stats.forecasts.min_goodness_of_fit controls the minimum R² (goodness of fit) threshold for statistics forecasts, but it applies cluster-wide. For tables with irregular growth patterns (e.g. very large tables with 26B+ rows), the default threshold (0.95) can be too strict, causing useful forecasts to be rejected.

This change adds a per-table storage parameter
sql_stats_forecasts_min_goodness_of_fit that overrides the cluster setting for individual tables:

ALTER TABLE t SET (sql_stats_forecasts_min_goodness_of_fit = 0.80)

The implementation follows the pattern of the existing forecast_stats (ForecastStatsEnabled) table-level override:

  • A nullable double field on TableDescriptor (proto field 73)
  • A cluster version gate (V26_3_ForecastMinGoodnessOfFitTableSetting)
  • The resolved value is threaded through the stats cache alongside the existing forecast bool, and passed as a parameter to ForecastTableStatistics instead of reading the cluster setting inside that function.

Release note (sql change): Added per-table storage parameter sql_stats_forecasts_min_goodness_of_fit to override the cluster setting sql.stats.forecasts.min_goodness_of_fit on individual tables. This allows tuning the forecast goodness-of-fit threshold per table via ALTER TABLE t SET (sql_stats_forecasts_min_goodness_of_fit = 0.80).

…age parameter

The cluster setting sql.stats.forecasts.min_goodness_of_fit controls the
minimum R² (goodness of fit) threshold for statistics forecasts, but it
applies cluster-wide. For tables with irregular growth patterns (e.g.
very large tables with 26B+ rows), the default threshold (0.95) can be
too strict, causing useful forecasts to be rejected.

This change adds a per-table storage parameter
`sql_stats_forecasts_min_goodness_of_fit` that overrides the cluster
setting for individual tables:

    ALTER TABLE t SET (sql_stats_forecasts_min_goodness_of_fit = 0.80)

The implementation follows the pattern of the existing `forecast_stats`
(ForecastStatsEnabled) table-level override:
- A nullable double field on TableDescriptor (proto field 73)
- A cluster version gate (V26_3_ForecastMinGoodnessOfFitTableSetting)
- The resolved value is threaded through the stats cache alongside the
  existing `forecast bool`, and passed as a parameter to
  ForecastTableStatistics instead of reading the cluster setting inside
  that function.

Release note (sql change): Added per-table storage parameter
`sql_stats_forecasts_min_goodness_of_fit` to override the cluster
setting `sql.stats.forecasts.min_goodness_of_fit` on individual tables.
This allows tuning the forecast goodness-of-fit threshold per table
via `ALTER TABLE t SET (sql_stats_forecasts_min_goodness_of_fit = 0.80)`.

Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
@trunk-io
Copy link
Copy Markdown
Contributor

trunk-io Bot commented May 4, 2026

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants