release-26.2: sql/stats: make table statistics cache size configurable#169247
Merged
trunk-io[bot] merged 2 commits intoApr 28, 2026
Merged
Conversation
Replace the hardcoded table statistics cache size (previously passed through server config plumbing as `defaultSQLTableStatCacheSize = 256`) with a cluster setting `sql.stats.table_statistics_cache.capacity`. The `ShouldEvict` callback now reads the setting dynamically, so the cache resizes on the next insertion after the setting is changed. This removes the `cacheSize int` parameter from `NewTableStatisticsCache` along with the `SQLConfig.TableStatCacheSize` field and associated plumbing through `server_controller_new_server.go`. Informs: cockroachdb#54030 Release note (sql change): The new cluster setting `sql.stats.table_statistics_cache.capacity` controls the maximum number of tables whose statistics are retained in the in-memory LRU cache (default: 256). Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
Add a `mon.BytesMonitor` to the table statistics cache, tracking memory usage under the `server-cache-mon` → `root` SQL memory pool hierarchy. Each cache entry's memory footprint is estimated when populated (accounting for histogram buckets, datum sizes, column IDs, and string fields) and tracked via a `mon.BoundAccount`. When a `Grow` or `Resize` call fails (e.g. because the SQL memory pool is exhausted), LRU entries are evicted until the cumulative freed memory exceeds the new entry's size, ensuring a net decrease even under concurrent memory pressure. If eviction is insufficient, the new entry is removed — callers who were already waiting still receive the stats, but the entry won't be retained for future lookups. On refresh the size delta between the old and new stats is reserved or released. A new `LRUEntry` method is added to `cache.UnorderedCache` to support the eviction logic. Fixes: cockroachdb#54030 Release note: None Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
Contributor
|
😎 Merged successfully - details. |
|
Thanks for opening a backport. Before merging, please confirm that the change does not break backwards compatibility and otherwise complies with the backport policy. Include a brief release justification in the PR description explaining why the backport is appropriate. All backports must be reviewed by the TL for the owning area. While the stricter LTS policy does not yet apply, please exercise judgment and consider gating non-critical changes behind a disabled-by-default feature flag when appropriate. |
Member
Collaborator
Author
|
TFTR! /trunk merge |
mw5h
approved these changes
Apr 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport 2/3 commits from #168711.
/cc @cockroachdb/release
stats: make table statistics cache size configurable
Replace the hardcoded table statistics cache size (previously passed
through server config plumbing as
defaultSQLTableStatCacheSize = 256)with a cluster setting
sql.stats.table_statistics_cache.capacity. TheShouldEvictcallback now reads the setting dynamically, so the cacheresizes on the next insertion after the setting is changed.
This removes the
cacheSize intparameter fromNewTableStatisticsCachealong with the
SQLConfig.TableStatCacheSizefield and associatedplumbing through
server_controller_new_server.go.Informs: #54030
Release note (sql change): The new cluster setting
sql.stats.table_statistics_cache.capacitycontrols the maximum numberof tables whose statistics are retained in the in-memory LRU cache
(default: 256).
Co-Authored-By: roachdev-claude roachdev-claude-bot@cockroachlabs.com
stats: add memory monitoring to table statistics cache
Add a
mon.BytesMonitorto the table statistics cache, tracking memoryusage under the
server-cache-mon→rootSQL memory pool hierarchy.Each cache entry's memory footprint is estimated when populated
(accounting for histogram buckets, datum sizes, column IDs, and string
fields) and tracked via a
mon.BoundAccount.When a
GroworResizecall fails (e.g. because the SQL memory poolis exhausted), LRU entries are evicted until the cumulative freed memory
exceeds the new entry's size, ensuring a net decrease even under
concurrent memory pressure. If eviction is insufficient, the new entry
is removed — callers who were already waiting still receive the stats,
but the entry won't be retained for future lookups. On refresh the size
delta between the old and new stats is reserved or released.
A new
LRUEntrymethod is added tocache.UnorderedCacheto supportthe eviction logic.
Fixes: #54030
Release note: None
Co-Authored-By: roachdev-claude roachdev-claude-bot@cockroachlabs.com
Fixes ENGREQ-437
Release justification: scalability improvement requested via ENGREQ