Skip to content

Cherry pick #104063 to 26.2: Bypass index uncompressed cache when its size is zero - #104157

Merged
al13n321 merged 6 commits into
backport/26.2/104063from
cherrypick/26.2/104063
May 5, 2026
Merged

al13n321 merged 6 commits into
backport/26.2/104063from
cherrypick/26.2/104063

Conversation

@robot-ch-test-poll1

Copy link
Copy Markdown
Contributor

Original pull-request #104063

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

al13n321 and others added 5 commits May 4, 2026 19:09
`index_uncompressed_cache_size = 0` (the server default) is documented
as disabling the cache, but `Context::getIndexUncompressedCache`
returned a non-null `UncompressedCache` of capacity zero.
`MergeTreeIndexReader` -> `MergeTreeReaderStream::init` then took the
`CachedCompressedReadBuffer` path, where every skip-index block read
acquired the global `CacheBase` mutex twice (lookup + insert), evicted
itself immediately via `removeOverflow`, and unconditionally bumped
`UncompressedCacheMisses` and `UncompressedCacheWeightLost`. On a query
evaluating skip indexes with small `GRANULARITY` this materialized as
hundreds of thousands of contended mutex acquisitions per query and
tens of GB of phantom `UncompressedCacheWeightLost`, with zero
`UncompressedCacheHits`.

The original code created the cache object only when the size was
non-zero. The `if (size)` guard at the call site was dropped to allow
runtime resizing via `SYSTEM RELOAD CONFIG`. Restore the bypass by
tracking whether the cache should be used in a separate flag, set when
the cache is constructed and re-evaluated by
`updateIndexUncompressedCacheConfiguration`. `getIndexUncompressedCache`
returns nullptr when the flag is false; `MergeTreeReaderStream::init`
already falls through to `CompressedReadBufferFromFile` on a null
pointer. Runtime resize 0 -> N still works because the flag is
refreshed after `setMaxSizeInBytes`.

The data uncompressed cache is unaffected because
`MergeTreeReadPoolBase` already gates `getUncompressedCache` on
`pool_settings.use_uncompressed_cache`; the index path had no such
guard.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Spins up a server with `index_uncompressed_cache_size = 0`, runs a
query that exercises a `bloom_filter` skip index, and asserts that
`UncompressedCacheHits`, `UncompressedCacheMisses`, and
`UncompressedCacheWeightLost` in `system.query_log` are all zero - the
bypass path verified.

Then enables the cache via `SYSTEM RELOAD CONFIG`, asserts misses
appear on the first query and hits on a repeated one, and finally
restores the original config (also via `SYSTEM RELOAD CONFIG`) and
re-asserts that the profile events are zero again. This covers the
runtime resize path in `Context::updateIndexUncompressedCacheConfiguration`
in both directions.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ed-cache

Bypass index uncompressed cache when its size is zero
@robot-ch-test-poll1 robot-ch-test-poll1 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels May 5, 2026
@al13n321
al13n321 merged commit 1ba6286 into backport/26.2/104063 May 5, 2026
@al13n321
al13n321 deleted the cherrypick/26.2/104063 branch May 5, 2026 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants