Skip to content

stats: respect table-level params in auto stats refresher#167540

Open
yuzefovich wants to merge 1 commit intocockroachdb:masterfrom
yuzefovich:stats-fix
Open

stats: respect table-level params in auto stats refresher#167540
yuzefovich wants to merge 1 commit intocockroachdb:masterfrom
yuzefovich:stats-fix

Conversation

@yuzefovich
Copy link
Copy Markdown
Member

@yuzefovich yuzefovich commented Apr 4, 2026

This commit fixes a bug where we could ignore sql_stats_automatic_full_collection_enabled and sql_stats_automatic_partial_collection_enabled table-level storage parameters in the auto stats refresher. In particular, we had a couple of helper methods that would take a TableDescriptor as an argument, and if that happens to be nil, then we'd default to the corresponding cluster setting. The thing is that we don't always fetch the TableDescriptor (we only do so only if the maybeRefreshStats goroutine has been running for at least 1 minute, meaning that there were previous long stats collections during the current refresh cycle). This commit fixes the bug by propagating the table-level parameters directly which side-steps the nil TableDescriptor issue (we do keep all overrides in the global map).

Note that we probably could have caught this bug in the logic tests, but we reduce DefaultRefreshInterval to 1ms in there, so we happened to fetch the TableDescriptor most (all?) of the time.

Epic: None

Release note (bug fix): Previously, CockroachDB might not have respected the table-level parameters sql_stats_automatic_full_collection_enabled and sql_stats_automatic_partial_collection_enabled and defaulted to using the corresponding cluster settings when deciding whether to perform automatic statistic collection on a table. This is now fixed.

This commit fixes a bug where we could ignore
`sql_stats_automatic_full_collection_enabled` and
`sql_stats_automatic_partial_collection_enabled` table-level storage
parameters in the auto stats refresher. In particular, we had a couple
of helper methods that would take a TableDescriptor as an argument, and
if that happens to be nil, then we'd default to the corresponding
cluster setting. The thing is that we don't always fetch the
TableDescriptor (we only do so only if the `maybeRefreshStats` goroutine
has been running for at least 1 minute, meaning that there were previous
long stats collections during the current refresh cycle). This commit
fixes the bug by propagating the table-level parameters directly which
side-steps the nil TableDescriptor issue (we do keep all overrides in
the global map).

Note that we probably could have caught this bug in the logic tests, but
we reduce DefaultRefreshInterval to 1ms in there, so we happened to
fetch the TableDescriptor most (all?) of the time.

Release note (bug fix): Previously, CockroachDB might not have respected
the table-level parameters `sql_stats_automatic_full_collection_enabled`
and `sql_stats_automatic_partial_collection_enabled` and defaulted to
using the corresponding cluster settings when deciding whether to
perform automatic statistic collection on a table. This is now fixed.
@yuzefovich yuzefovich added backport-26.1.x Flags PRs that need to be backported to 26.1 backport-26.2.x Flags PRs that need to be backported to 26.2 labels Apr 4, 2026
@trunk-io
Copy link
Copy Markdown
Contributor

trunk-io bot commented Apr 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

@yuzefovich yuzefovich requested a review from michae2 April 4, 2026 19:04
@yuzefovich yuzefovich marked this pull request as ready for review April 4, 2026 19:04
@yuzefovich yuzefovich requested a review from a team as a code owner April 4, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-26.1.x Flags PRs that need to be backported to 26.1 backport-26.2.x Flags PRs that need to be backported to 26.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants