Repository navigation
Refactor tokenization to forEachToken callback API - #97871
Conversation
Replace the iterator-style nextInStringPadded API with a high-performance forEachToken callback interface: - Remove nextInStringPadded, stringPaddedToBloomFilter, and forEachTokenPadded - Move SSE optimization into SplitByNonAlphaTokenizer::forEachTokenImpl member - forEachToken dispatch uses assert_cast for devirtualized calls - Add forEachTokenToBloomFilter helper replacing stringPaddedToBloomFilter - Update all call sites: hasAnyAllTokens, ngrams, tokens, MergeTree indexes - Clean up includes in MergeTreeIndexConditionText and TextIndexCache The new API assumes column data is always padded (which is guaranteed by ClickHouse's Column types), enabling SIMD optimizations without a separate padded code path. The callback interface avoids per-token virtual dispatch overhead and naturally supports future SIMD and stateful tokenizers.
d163670 to
189f1f0
Compare
Replace the iterator-style nextInStringPadded API with a high-performance forEachToken callback interface: - Remove nextInStringPadded, stringPaddedToBloomFilter, and forEachTokenPadded - Move SSE optimization into SplitByNonAlphaTokenizer::forEachTokenImpl member - forEachToken dispatch uses assert_cast for devirtualized calls - Add forEachTokenToBloomFilter helper replacing stringPaddedToBloomFilter - Update all call sites: hasAnyAllTokens, ngrams, tokens, MergeTree indexes - Clean up includes in MergeTreeIndexConditionText and TextIndexCache The new API assumes column data is always padded (which is guaranteed by ClickHouse's Column types), enabling SIMD optimizations without a separate padded code path. The callback interface avoids per-token virtual dispatch overhead and naturally supports future SIMD and stateful tokenizers.
|
@george-larionov may want to check (he's out at the moment). |
|
(curious if the AI can add any useful comments) |
There was a problem hiding this comment.
Pull request overview
This PR updates ClickHouse’s tokenization pipeline to use the forEachToken callback-style API in several text-index and string-function call sites, removes the old padded iterator variants, and adds a SIMD-optimized callback implementation for SplitByNonAlphaTokenizer.
Changes:
- Replace uses of
nextInStringPadded/forEachTokenPadded/stringPaddedToBloomFilterwithnextInString,forEachToken, andforEachTokenToBloomFilter. - Introduce
SplitByNonAlphaTokenizer::forEachTokenImpl(SIMD-accelerated) and a sharedforEachTokenToBloomFilterhelper. - Adjust includes/forward declarations to match the refactor.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Storages/tests/gtest_SplitByNonAlphaTokenExtractor.cpp | Switch test to nextInString now that padded iterator APIs are removed. |
| src/Storages/MergeTree/TextIndexCache.h | Include cleanup/add ColumnString include for dictionary block token extraction. |
| src/Storages/MergeTree/MergeTreeIndexText.cpp | Use forEachToken when building text-index granules. |
| src/Storages/MergeTree/MergeTreeIndexConditionText.h | Minor include cleanup. |
| src/Storages/MergeTree/MergeTreeIndexConditionText.cpp | Include reordering/adjustment after tokenizer refactor. |
| src/Storages/MergeTree/MergeTreeIndexBloomFilterText.cpp | Replace per-tokenizer padded bloom-filter path with forEachTokenToBloomFilter. |
| src/Interpreters/ITokenizer.h | Remove padded iterator APIs; add forEachToken dispatcher and SIMD callback implementation for SplitByNonAlpha. |
| src/Interpreters/ITokenizer.cpp | Remove nextInStringPadded implementation; add forEachTokenToBloomFilter definition. |
| src/Functions/tokens.cpp | Switch token extraction to forEachToken. |
| src/Functions/ngrams.cpp | Switch ngram extraction loop to forEachToken. |
| src/Functions/hasAnyAllTokens.h | Replace ITokenizer include with forward declaration (reduce coupling). |
| src/Functions/hasAnyAllTokens.cpp | Switch token scanning to forEachToken. |
|
I'm not sure why this test only fails on this PR, since it seems to have nothing to do with these changes. Let's see if it is still there when we re-run the tests. |
…ckHouse into refactor-tokenizer-includes # Conflicts: # src/Functions/hasAnyAllTokens.cpp
george-larionov
left a comment
There was a problem hiding this comment.
All tests passed! LGTM.
| const __m128i haystack = _mm_loadu_si128(reinterpret_cast<const __m128i *>(pos)); | ||
| const size_t haystack_length = 16; | ||
|
|
||
| #if defined(__SSE4_2__) |
There was a problem hiding this comment.
We'll soon move to x86-v3: #90043
I think we can simplify the ifdefs here a bit,. i.e. assume SSE4.2 & remove the SSE 2 path.

Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Refactor tokenization to a new high-performance forEachToken callback interface, replacing the old iterator-style API to support SIMD and stateful tokenizers. Part of #90268.
Documentation entry for user-facing changes
Version info
26.3.1.270