Skip to content

Cherry pick #126549 to 26.8: Limit the total size of text bloom filter indexes and track their memory - #130567

Merged
robot-ch-test-poll2 merged 5 commits into
backport/26.8/126549from
cherrypick/26.8/126549
Nov 12, 2026
Merged

robot-ch-test-poll2 merged 5 commits into
backport/26.8/126549from
cherrypick/26.8/126549

Conversation

@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

Original pull-request #126549

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.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

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

alexey-milovidov and others added 4 commits October 17, 2026 23:43
The text bloom filter skip indexes (`tokenbf_v1`, `ngrambf_v1`, `sparse_grams`)
checked only the size of a single filter (at most `MAX_BLOOM_FILTER_SIZE`, 1 GiB),
but every granule of the index eagerly allocates one filter per indexed column.
Also, the filter was stored in a `std::vector` with the default allocator, and
implicit `operator new` allocations are not refused by the memory tracker by
default, so a one-row `INSERT` into a table with large filters could allocate
past the available RAM and get the server killed by the OOM killer.

- `BloomFilter::Container` now uses `AllocatorWithMemoryTracking`, so the
  allocation of a filter respects the memory limits and fails with
  `MEMORY_LIMIT_EXCEEDED`. This covers all users of `BloomFilter`, including
  the `bloom_filter` index and runtime filters.
- `bloomFilterIndexTextValidator` rejects indexes where the filter size multiplied
  by the number of indexed columns exceeds `MAX_BLOOM_FILTER_SIZE`. The check is
  skipped on `ATTACH`, so existing tables still load.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Address review: an index inherited from the old metadata (for example, of a table
attached after being created by an older version) is revalidated with `attach = false`
on every `ALTER` by `MergeTreeData::checkProperties`, so the check in
`bloomFilterIndexTextValidator` made unrelated alters of such tables fail. Move the
check to `bloomFilterIndexTextCheckTotalSize`, called from `checkProperties`, which
accepts an inherited index as long as its total size does not grow.

Also use `VectorWithMemoryTracking` for `BloomFilter::Container`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…al-size

Limit the total size of text bloom filter indexes and track their memory
@robot-ch-test-poll3 robot-ch-test-poll3 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 pr-bugfix Pull request with bugfix, not backported by default labels Nov 10, 2026
@rschu1ze

Copy link
Copy Markdown
Member

@groeneai Resolve the conflicts

@groeneai

Copy link
Copy Markdown
Collaborator

Resolved, same conflict and resolution as 26.9 (#130568). The only conflict is in MergeTreeData::checkProperties: on master the new bloomFilterIndexTextCheckTotalSize block sits directly above the tryEvaluateIndexExpression block from #118373, which is not on 26.8 (it has no backport label). The resolution keeps the new block and leaves the #118373 block out. The other four source files and both tests merge cleanly. Against backport/26.8/126549 the merge changes exactly the 9 files of #126549, with the same lines as on master (only one blank line in MergeTreeData.cpp sits before the new block instead of after it).

Validated on the 26.8 tree with clang-22, debug build: 05421_bloom_filter_text_index_total_size and 05422_bloom_filter_text_index_total_size_attach pass, 5 runs each with randomized settings.

The merge is on my fork and its first parent is this PR's head, so applying it is a fast-forward:

git fetch https://github.com/groeneai/ClickHouse groeneai/resolve-26.8-cherrypick-126549
git push origin FETCH_HEAD:cherrypick/26.8/126549

(resolved head af2370ffa7988ff2770cb69a652b311641888e08)

@rschu1ze

Copy link
Copy Markdown
Member

@groeneai There are still merge conflicts. Resolve them.

@groeneai

Copy link
Copy Markdown
Collaborator

I can't push to cherrypick/26.8/126549: my account has read-only access to this repository, so the conflicts stay until someone with push access applies the resolution. It is ready on my fork and is still a fast-forward of this PR's head 5a806461500a that merges the current backport/26.8/126549 tip 1492ec0b6a4e:

git fetch https://github.com/groeneai/ClickHouse groeneai/resolve-26.8-cherrypick-126549
git push origin FETCH_HEAD:cherrypick/26.8/126549

(resolved head af2370ffa798, details in my comment above)

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Applied the conflict resolution from @groeneai (af2370ffa798) as a fast-forward of the PR head. Before pushing I checked it: compared with backport/26.8/126549, the merge changes exactly the 9 files of #126549, with the same lines as the original. The only conflict, in MergeTreeData::checkProperties, keeps the new bloomFilterIndexTextCheckTotalSize block and leaves out the code from #118373, which is not on 26.8. MergeTreeData.cpp, MergeTreeIndexBloomFilterText.cpp and BloomFilter.cpp pass a -fsyntax-only check.

@robot-ch-test-poll2
robot-ch-test-poll2 merged commit 70d95b6 into backport/26.8/126549 Nov 12, 2026
2 checks passed
@robot-ch-test-poll2
robot-ch-test-poll2 deleted the cherrypick/26.8/126549 branch November 12, 2026 14:05
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-bugfix Pull request with bugfix, not backported by default 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.

5 participants