Skip to content

Limit the total size of text bloom filter indexes and track their memory - #126549

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-bloom-filter-index-total-size
Oct 21, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-bloom-filter-index-total-size

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

The text bloom filter skip indexes (tokenbf_v1, ngrambf_v1, sparse_grams) checked only the size of a single filter (at most 1 GiB), but every granule of the index eagerly allocates one filter per indexed column. The filter was stored in a std::vector with the default allocator, and such 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.
  • CREATE TABLE and ALTER TABLE ... ADD INDEX reject text bloom filter indexes where the filter size multiplied by the number of indexed columns exceeds 1 GiB. The check is skipped on ATTACH and for an index inherited from the old metadata as long as it does not grow, so existing tables still load and can be altered.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Bloom filters of skip indexes respect the memory limits, so creating large filters fails with MEMORY_LIMIT_EXCEEDED instead of the server being killed by the OOM killer. Text bloom filter indexes (tokenbf_v1, ngrambf_v1, sparse_grams) with the total size of filters in a granule (filter size multiplied by the number of columns) over 1 GiB are rejected on creation.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/126549]

Version info

  • Merged into: 26.11.1.385-master (included in 26.11 and later)
  • Backported to: 26.9.28.163

alexey-milovidov and others added 2 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]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fd395b8]

Summary: ✅


AI Review

Summary

The PR makes BloomFilter allocations enforce memory limits and caps text bloom filters at 1 GiB per index granule. The previous legacy-table alteration issue is fixed, but replay of an already committed index addition can still stall replication during upgrades.

Findings

❌ Blockers

  • src/Storages/MergeTree/MergeTreeData.cpp:1423: An oversized ADD INDEX accepted by an older replica is rejected when an upgraded replica replays it. StorageReplicatedMergeTree::setTableStructure calls setProperties with attach = false, and a newly arriving index has no old_index exemption. Every retry fails with BAD_ARGUMENTS, blocking subsequent metadata changes behind the committed entry. Enforce the cap on originating DDL and exempt committed metadata replay.
Tests
  • ⚠️ Add a focused regression for replaying an oversized index addition committed before an upgrade or by an older replica. The existing attach/alter test starts with the index already present locally and cannot exercise this case. The replay failure was established by tracing the current code; a multi-version reproduction was not run.
Final Verdict

Status: ❌ Block. Preserve replay of committed replicated metadata and cover that path with a regression test.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 18, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-text-index Full-text search: inverted/text index in MergeTree (tokenizers, posting lists, GIN-style index bu... label Oct 18, 2026
Comment thread src/Interpreters/BloomFilter.h Resolved
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]>
old_index = &candidate;

bloomFilterIndexTextCheckTotalSize(index, old_index);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Exempt committed replicated index additions from the new limit

During a rolling upgrade, an older replica can still commit ALTER TABLE ... ADD INDEX idx (a, b) TYPE tokenbf_v1(536870913, 3, 0) GRANULARITY 1. The upgraded replica applies that entry through StorageReplicatedMergeTree::executeMetadataAlter → setTableStructure → setProperties(new_metadata, old_metadata), whose default attach is false. Since idx is absent from the previous local metadata, old_index is null and this call throws BAD_ARGUMENTS on every retry. The metadata change is already committed in Keeper, and subsequent metadata changes cannot pass the failed entry (ReplicatedMergeTreeQueue orders them through alter_sequence). This also affects entries queued before the replica was upgraded, without any concurrent old-version DDL.

Keep the limit on originating DDL, but treat replay of committed metadata like loading existing metadata. The inherited-index exception alone cannot cover an index that the replica has not applied yet. Please add focused regression coverage for this replay path; no inserted data or large filter allocation is needed.

@clickhouse-gh

clickhouse-gh Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing fd395b872 with master 607e4c1e3 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 074719710; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

336 translation units recompiled, 3303 s compile time in total, 326 of them have a recent master baseline.

Translation units without a recent master baseline:

  • src/Functions/hasAnyAllTokens.cpp: 6.5 s

Job report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect.

@alexey-milovidov alexey-milovidov self-assigned this Oct 21, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 21, 2026
Merged via the queue into master with commit 5a80646 Oct 21, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-bloom-filter-index-total-size branch October 21, 2026 04:41
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 21, 2026
@rschu1ze rschu1ze added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Nov 10, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 10, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 10, 2026
Backport #126549 to 26.10: Limit the total size of text bloom filter indexes and track their memory
robot-clickhouse-ci-2 added a commit that referenced this pull request Nov 12, 2026
Cherry pick #126549 to 26.9: Limit the total size of text bloom filter indexes and track their memory
robot-clickhouse added a commit that referenced this pull request Nov 12, 2026
robot-ch-test-poll2 added a commit that referenced this pull request Nov 12, 2026
Cherry pick #126549 to 26.8: Limit the total size of text bloom filter indexes and track their memory
robot-clickhouse added a commit that referenced this pull request Nov 12, 2026
robot-ch-test-poll added a commit that referenced this pull request Nov 12, 2026
Cherry pick #126549 to 26.3: Limit the total size of text bloom filter indexes and track their memory
robot-clickhouse added a commit that referenced this pull request Nov 12, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 12, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 12, 2026
Backport #126549 to 26.8: Limit the total size of text bloom filter indexes and track their memory
alexey-milovidov added a commit that referenced this pull request Nov 12, 2026
Backport #126549 to 26.3: Limit the total size of text bloom filter indexes and track their memory
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 13, 2026
Backport #126549 to 26.9: Limit the total size of text bloom filter indexes and track their memory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-text-index Full-text search: inverted/text index in MergeTree (tokenizers, posting lists, GIN-style index bu... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants