Repository navigation
Conversation
|
Workflow [PR], commit [1b2737c] Summary: ❌
AI ReviewSummaryThis PR adds a new Findings❌ Blockers
Tests
Final VerdictStatus:
|
| factory.registerTokenizer(AsciiCJKTokenizer::getName(), ITokenizer::Type::AsciiCJK, ascii_cjk_creator); | ||
| factory.registerTokenizer("unicodeWord", ITokenizer::Type::AsciiCJK, ascii_cjk_creator); | ||
|
|
||
| auto segmentation_creator = [](const FieldVector & /*args*/) -> std::unique_ptr<ITokenizer> |
There was a problem hiding this comment.
segmentation(...) currently accepts any parameter list silently.
That makes typoed settings look valid and changes behavior without an explicit error. Please add assertParamsCount(args.size(), 0, SegmentationTokenizer::getExternalName()) here for consistent validation.
There was a problem hiding this comment.
Re-checking current head (76a6efca) this is still live: segmentation_creator still ignores args, so segmentation(...) accepts arbitrary parameters silently while other tokenizers validate arity.
Please add assertParamsCount(args.size(), 0, SegmentationTokenizer::getExternalName()) in this creator.
1d89fb6 to
76a6efc
Compare
| major_part_index.push_back(cur_major_part_index); | ||
| } | ||
| part_begin = i + 1; | ||
| if (isMajorSplitChar(data[i])) |
There was a problem hiding this comment.
❌ buildStateIfNeeded reads data[i] when i == length.
The outer condition uses i <= length, and inside this block we call isMajorSplitChar(data[i]) unconditionally. At i == length this dereferences one byte past the provided buffer, so tokenization depends on accidental padding/null-termination.
Please guard the increment with if (i < length && isMajorSplitChar(data[i])) (or split the end-of-input path) so the tokenizer never reads past length.
| while (pos < length) | ||
| { | ||
| const char c = data[pos]; | ||
| if (!escaped && (c == '%' || c == '_')) |
There was a problem hiding this comment.
❌ This LIKE token extraction can create false negatives for matches that start/end inside a minor segment.
Concrete case:
- row value:
123.45(row tokens are123,123.45,45) - predicate:
LIKE '%23.4%' - this code emits token
23.4
23.4 is not present in row tokens, so the text index can prune a granule that actually contains a matching row. For LIKE/substring predicates we must only emit tokens guaranteed to exist in every real match; boundary-partial segments should be dropped (or the pattern should produce no token for pruning).
| } | ||
|
|
||
|
|
||
| mutable std::vector<size_t> minor_part_starts; |
There was a problem hiding this comment.
❌ SegmentationTokenizer keeps mutable cursor/cache state (previous_data, current_part_i, current_part_j, and the cached parts vectors), so one instance is not thread-safe.
hasAnyTokens/hasAllTokens currently clone only sparseGrams before multi-threaded execution (src/Functions/hasAnyAllTokens.cpp). With this tokenizer now registered globally, hasAnyTokens(..., 'segmentation') can race on shared mutable state and return nondeterministic results.
Please either make this tokenizer stateless per call, or extend the cloning workaround to include Type::Segmentation.
| stringToBloomFilter(data, length, bloom_filter); | ||
| } | ||
|
|
||
| void SegmentationTokenizer::substringToTokens(const char * data, size_t length, std::vector<String> & tokens, bool /*is_prefix*/, bool /*is_suffix*/) const |
There was a problem hiding this comment.
❌ substringToTokens ignores is_prefix / is_suffix and always tokenizes the full substring. That can emit boundary-partial tokens that are not guaranteed to exist in matching rows, which leads to false-negative index pruning.
Concrete case:
- row value:
192.168 - predicate:
startsWith(col, '192.1') - this path can emit
192.1, but row tokens are192,192.168,168
Because startsWith uses substringToTokens(..., true, false), trailing boundary-partial segments should be dropped (and similarly leading ones for suffix mode) before generating pruning tokens.
LLVM Coverage Report
Changed lines: 86.55% (103/119) · Uncovered code |
|
Allow me to ask @Ergus (instead of @alexbakharew) for a review as he was working on full-text search for a longer while. |
|
Hi @scanhex12 I just added this PR to my TODO list ;). To start with I would request to add some documentation for this new tokenizer in order to understand better how it works and when it is useful for (the last part I saw in the opened issue, but we need to put it all together) |
`CoalescingMergeTree` delegates to `SummingSortedAlgorithm` with `aggregate_all_columns = true`. The dedicated branch for that case in `defineColumns` (`src/Processors/Merges/Algorithms/SummingSortedAlgorithm.cpp:267`) wrapped its work in `if (map_name == column.name || !endsWith(map_name, "Map"))` and then fell through to an unconditional `continue`. For any nested column whose parent table name ends with `Map` (e.g. `testMap.key`, `legacy_features_Map.id`), the inner branch was skipped while the `continue` still fired, so the column was added to neither `columns_to_aggregate` nor `column_numbers_not_to_aggregate`. `postprocessChunk` then constructed `res_columns` of size `num_result_columns` and left those slots `nullptr`. `Chunk::setColumns` -> `Chunk::checkNumRowsIsConsistent` dereferenced the null `ColumnPtr`, producing a SIGSEGV in release builds, a `px != 0` assertion in debug builds, and an UBSan `member call on null pointer` report in `arm_asan_ubsan` (STID 1003-326e on the AST fuzzer for PR ClickHouse#104281 and PR ClickHouse#104563). CoalescingMergeTree performs per-column `last_value` coalescing, so nested `Map` arrays must be coalesced element-wise like any other array column. The legacy `nestedName.suffix` routing into `discovered_maps` for `sumMap`-by-key merging is a SummingMergeTree concept that does not apply here, so the Map-suffix exclusion is dropped from the `aggregate_all_columns = true` branch. SummingMergeTree code paths are untouched. Closes ClickHouse#101937 CI report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/104563/c2e0f0fe3b92d48b5a47fa90555f7d4aca54c553/ast_fuzzer_arm_asan_ubsan/ Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Dear @Ergus, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
Hi @scanhex12 Are we continuing with this? |
Ergus
left a comment
There was a problem hiding this comment.
I am looking into this again and I have a main issue with this as implemented (or intended)
From the original description in the feature request I see that:
192.168.1.106 -> [192, 168, 1, 106, 192.168, 168.1, 1.106, 192.168.1, 168.1.106, 192.168.1.106]
IIUC correctly that is the combination that grows with the number of sub-tokens with a quadratic complexity: N*(N+1)/2
An IPV6 address will produce 36 entries in the dictionary...
In this case the index size increase could affect the overall performance more than just getting some false positive in granules exclusion.
What if we rethink the approach a little bit now that we have the positions experimental feature? With position information we won't need to store all the combinations to get correct full filtering.
The trade off is that positions already increase the index size significantly and is disabled by default.
@rschu1ze WDYT?
|
I don't think that it that much worse, than other already existing tokenizers which we can use in text indexes |
|
|
||
| std::vector<String> SegmentationTokenizer::compactTokens(const std::vector<String> & tokens) const | ||
| { | ||
| std::unordered_set<String> result; |
There was a problem hiding this comment.
This has changed on master to use the memory tracking API
| const size_t n_parts = minor_part_starts.size(); | ||
|
|
||
| if (current_part_i >= n_parts) | ||
| return false; |
There was a problem hiding this comment.
IIUC comparing with SparseNGrams I think that in this condition you need to reset:
previous_data = nullptr;
previous_len = 0;
Otherwise you could miss some rows because buildStateIfNeeded can early-returns on a cache hit without re-initializing current_part_i
| SELECT id FROM tab WHERE ip = '192.168.1.106' ORDER BY id; | ||
|
|
||
| SELECT 'prefix segment'; | ||
| SELECT id FROM tab WHERE ip LIKE '192.168.%' ORDER BY id; |
There was a problem hiding this comment.
Will this match equivalent text patterns like 192.168?
What about LIKE '%92.16%'
Or other functions like startWith('192.1')?
There was a problem hiding this comment.
What about LIKE '%92.16%'
IMO, main goal of it to solve problem of "bad" query/lookup pattern.
When someone write search by IP (192.168.1.43) but in bad way.
ip LIKE '%192.168.1.43%' -- we "at least" get 168.1 as useful token
ip LIKE '%192.168.1.43 %' -- we "at least" get 168.1.43 as token
ip LIKE '% 192.168.1.43%' -- we "at least" get 192.168.1 as token
Which marginally, but better than
SELECT tokensForLikePattern('%192.168.1.43%'), tokensForLikePattern('% 192.168.1.43%'), tokensForLikePattern('%192.168.1.43 %'),
['168','1'] ['192','168','1'] ['168','1','43']
For IPv6 or ids with more delimeters, advantage of "saved" tokens should be better/bigger
yes, the ngrams is not actually the best example on how to use the text index. Somehow we still support it for some corner cases and legacy, but now really recommended in most of the cases precisely because of the dictionary size grow. |
I don't like alphatokens* ones either (for log style data). They might work OK for normal text data, but in logs, people tends to have/use those symbols (by which we split) as part of ids (ip, uuid, mac, whatever custom id style they managed to invent). I think, we better be with (may be with better layout) bloom filter style index instead. |
|
Dear @Ergus, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Segmentation tokenizer for text index. This closes #103743
Documentation entry for user-facing changes