Skip to content

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

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

robot-ch-test-poll merged 5 commits into
backport/26.3/126549from
cherrypick/26.3/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. 26.3 conflicts in four files, each because the context around #126549's lines differs on 26.3. The resolution applies only #126549's own lines to the 26.3 side:

  • BloomFilter.cpp: on master the MAX_BLOOM_FILTER_SIZE definition sits next to hash helpers 26.3 does not have. Only the definition is removed (it moves to the header).
  • BloomFilter.h: the context is master's libdivide-config.h include and BloomFilterHashPair, both absent on 26.3. Only the Common/VectorWithMemoryTracking.h include and the MAX_BLOOM_FILTER_SIZE definition are added (the Container change merges cleanly).
  • MergeTreeData.cpp: 26.3 has the older validate(index, attach) call and not the tryEvaluateIndexExpression block from Reject a skip index whose expression cannot be evaluated #118373 (no backport label). The new bloomFilterIndexTextCheckTotalSize block goes after 26.3's validate call.
  • MergeTreeIndices.h: 26.3's bloomFilterIndexTextCreator / bloomFilterIndexTextValidator declarations keep their older signatures, and the new declaration is added after them.

Against backport/26.3/126549 the merge changes exactly the 9 files of #126549, the added and removed lines are the same as in #126549, and the tests are byte-identical. The new check also fits 26.3 as is: the filter size is the first of the last three index arguments for ngrambf_v1, tokenbf_v1 and sparse_grams there too, and BloomFilterParameters already limits a single filter to 1 GiB.

Validated on the 26.3 tree with clang-21 (its pinned compiler), 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 official 26.3.42.3 build accepts the two-column tokenbf_v1(536870913, 3, 0) index that 05421 expects to be rejected.

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.3-cherrypick-126549
git push origin FETCH_HEAD:cherrypick/26.3/126549

(resolved head ee6950fdfc7e8c6a5303c1bf857eb0810998a84b)

@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.3/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.3/126549 tip 1583874196a3:

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

(resolved head ee6950fdfc7e, details in my comment above)

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Applied groeneai's resolution (ee6950fdfc7e), a fast-forward of the PR head that merges backport/26.3/126549. Before pushing I checked that the diff against backport/26.3/126549 touches exactly the 9 files of #126549, with the same added and removed lines, and that the symbols it uses (VectorWithMemoryTracking, SparseGramsTokenizer::getBloomFilterIndexName, getFieldsFromIndexArgumentsAST, old_metadata in checkProperties) all exist on 26.3.

@robot-ch-test-poll
robot-ch-test-poll merged commit 06b6774 into backport/26.3/126549 Nov 12, 2026
2 checks passed
@robot-ch-test-poll
robot-ch-test-poll deleted the cherrypick/26.3/126549 branch November 12, 2026 14:15
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