Repository navigation
Map kv tokenizer minimal - #115579
Map kv tokenizer minimal#115579
Conversation
a601623 to
21857d9
Compare
|
Workflow [PR], commit [2f73ee4] Summary: ✅
AI ReviewSummaryThis PR adds the Findings❌ Blockers
Final Verdict
LLVM Coverage ReportMeasured on commit 2f73ee4.
Changed lines: Changed C/C++ lines covered: 146/158 (92.41%) · Uncovered code |
My biggest reasoning for not putting len at beginning of token was that it will harm across key sorting. (key frequently share the same prefix) |
That's true, we should use |
|
TLDR, i don't care which pr is merged(may be slight edge towards @Ergus, bc in that case, it will be his responsibility ;) )
|
| out.reserve(getLengthOfVarUInt(packed) + key.size() + value.size()); | ||
|
|
||
| /// Keys under 64 bytes pack into one varint byte; skip the writeVarUInt buffer. | ||
| if (packed < 0x80) |
There was a problem hiding this comment.
Let's put the length tie-breaker to the end of the token as discussed in the PR.
There was a problem hiding this comment.
This makes sense for mapContainsKeyLike-style pattern scans. In a gross estimation I think that it adds some extra storage cost to the dictionary (~10-20%)... But that's ok?
There was a problem hiding this comment.
that it adds some extra storage cost to the dictionary (~10-20%).
But why?
This makes sense for mapContainsKeyLike-style pattern scans
That may be useful.
There was also an initial feature request in #110454 to support queries like
SELECT ...
FROM mergeTreeTextIndex('default', 'table', 'idx_key_value_pairs')
WHERE startsWith(token, 'prefix=')
It will be problematically to do this if we put tie-breaker to the beginning of the key.
There was a problem hiding this comment.
There is, one certain advantage of having len at beginning.
If we know key, but don't know which value we are looking.
In that case, (if/when range scan of dictionary will be implemented), it would allow us to read only range of tokens for that key.
With len at end, we can only read all tokens which start from that key prefix. (but filter them by their trailer len after decompression/deserialization)
It's not a best/most representative datasets, but what i have at hand:
┌─────────┬─────────────┬─────────────┬─────────────┬───────────────────┐
│ dataset │ avg key len │ avg val len │ val numeric │ # distinct tokens │
├─────────┼─────────────┼─────────────┼─────────────┼───────────────────┤
│ PE │ 24.6 │ 2.87 │ 100% │ 5,463,164 │
├─────────┼─────────────┼─────────────┼─────────────┼───────────────────┤
│ OTEL │ 11.7 │ 26.3 │ 11.9% │ 435,188 │
└─────────┴─────────────┴─────────────┴─────────────┴───────────────────┘
OTEL LogAttributes — 2M rows, 435,188 tokens
┌────────┬────────────┬───────────┬────────────┬─────────┐
│ PR │ dict │ postings │ total │ vs best │
├────────┼────────────┼───────────┼────────────┼─────────┤
│ 115579 │ 11,250,568 │ 6,400,274 │ 17,675,266 │ best │
├────────┼────────────┼───────────┼────────────┼─────────┤
│ 110757 │ 11,320,878 │ 6,400,274 │ 17,745,567 │ +0.40% │
├────────┼────────────┼───────────┼────────────┼─────────┤
│ 115363 │ 11,322,670 │ 6,400,274 │ 17,747,380 │ +0.41% │
└────────┴────────────┴───────────┴────────────┴─────────┘
ProfileEvents part_log — 2M rows, 5,463,164 tokens
┌────────┬────────────┬────────────┬─────────────┬─────────┐
│ PR │ dict │ postings │ total │ vs best │
├────────┼────────────┼────────────┼─────────────┼─────────┤
│ 115579 │ 47,654,489 │ 99,767,791 │ 147,561,868 │ best │
├────────┼────────────┼────────────┼─────────────┼─────────┤
│ 110757 │ 50,427,402 │ 99,767,791 │ 150,335,091 │ +1.88% │
├────────┼────────────┼────────────┼─────────────┼─────────┤
│ 115363 │ 50,941,720 │ 99,767,791 │ 150,849,609 │ +2.23% │
└────────┴────────────┴────────────┴─────────────┴─────────┘
Pure index-read cost per tokenizer
┌──────────────┬────────────┬──────────────────┬──────────────────┬──────────────────┐
│ query │ granules │ 110757 │ 115363 │ 115579 │
├──────────────┼────────────┼──────────────────┼──────────────────┼──────────────────┤
│ pe eq_rare │ 4/261 │ 699 KB / 16 ms │ 699 KB / 14 ms │ 694 KB / 14 ms │
├──────────────┼────────────┼──────────────────┼──────────────────┼──────────────────┤
│ pe eq_med │ 261/261 │ 8.826 MB / 19 ms │ 8.827 MB / 19 ms │ 8.825 MB / 19 ms │
├──────────────┼────────────┼──────────────────┼──────────────────┼──────────────────┤
│ pe valonly │ 30 vs 261 │ 9.92 MB / 655 ms │ 8.58 MB / 20 ms │ 8.58 MB / 17 ms │
├──────────────┼────────────┼──────────────────┼──────────────────┼──────────────────┤
│ otel eq_rare │ 1/245 │ 188 KB / 14 ms │ 188 KB / 12 ms │ 183 KB / 14 ms │
├──────────────┼────────────┼──────────────────┼──────────────────┼──────────────────┤
│ otel eq_med │ 122/245 │ 7.166 MB / 16 ms │ 7.166 MB / 20 ms │ 7.183 MB / 19 ms │
├──────────────┼────────────┼──────────────────┼──────────────────┼──────────────────┤
│ otel valonly │ 122 vs 245 │ 7.59 MB / 94 ms │ 9.23 MB / 17 ms │ 8.96 MB / 19 ms │
├──────────────┼────────────┼──────────────────┼──────────────────┼──────────────────┤
│ otel eq_low │ 211/245 │ 8.75 MB / 22 ms │ 8.75 MB / 21 ms │ 8.77 MB / 25 ms │
└──────────────┴────────────┴──────────────────┴──────────────────┴──────────────────┘
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes30 object files changed (+189.98 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units861 translation units recompiled, 6350 s compile time in total, 861 of them have a recent master baseline. |
|
What are folks' opinions on key-first vs. value-first in the token? Seems that key-first is great for prefix search when you know the key, while value-first can also serve generic |
|
Maps are expected to be searched by key, not by value. I'd vote for key first |
|
For exact key and value, I suppose both ordering work well since there's an exact needle in either haystack. Agreed that things like |
| case ITokenizer::Type::KeyValuePairs: | ||
| { | ||
| /// This tokenizer does not split strings: `nextInString` throws. | ||
| detail::forEachTokenImpl(tokenizer, data, length, callback); |
There was a problem hiding this comment.
keyValuePairs is supposed to reject string tokenization, but this new forEachToken path only reaches the throwing nextInString when length > 0. With the generic empty-input fast path above, tokens('', 'keyValuePairs') now quietly returns [] instead of the NOT_IMPLEMENTED you test for, and the same hole affects other empty-input forEachToken callers. Please move the KeyValuePairs rejection ahead of the zero-length fast path, or special-case this branch so empty strings still throw.
| /// The `text_index_serialization_version` setting is not validated against the index features: | ||
| /// it is a preference, and `textIndexCreator` raises it to a version that can represent them. | ||
| /// The keyValuePairs tokenizer cannot be combined with a preprocessor, a postprocessor or positions. | ||
| if (tokenizer->getType() == ITokenizer::Type::KeyValuePairs) |
There was a problem hiding this comment.
These keyValuePairs restrictions only run in the validator, but full-definition ATTACH TABLE ... UUID ... (...) does not actually get protected by them: MergeTreeIndexFactory::validate intentionally skips attach-time checks, and textIndexCreator still accepts whatever metadata made it this far. That means a user can bypass the new CREATE-time contract with ATTACH, for example by attaching TYPE text(tokenizer = 'keyValuePairs', support_phrase_search = 1) or even Map(String, UInt64). The build path then treats non-string values as raw bytes via IColumn::getDataAt() or runs through unsupported pre/postprocessor/positions code instead of rejecting the definition. Please enforce the same keyValuePairs invariants in textIndexCreator as well (or make full-definition ATTACH validate like fresh CREATE) and add an ATTACH TABLE ... UUID ... regression.
Use `keyValuePairs` to index label pairs in the `tags` map for new schema version 4 tables. Preserve explicit indexes and earlier schema versions, and carry index declarations through inner-table creation and attachment. Related: #115579
Related: #110757
Related: #110454
Adds a
keyValuePairstext-index tokenizer forMap(String, String)columns. Every(key, value)pair of a row becomes one token, soWHERE m['key'] = 'value'is answered by a single exact token lookup with direct read, instead of reading the map column. An index onmapKeys(m)ormapValues(m)cannot do this: it knows that some key exists and that some value exists, but not that they belong to the same pair.This is a minimal first increment of #110757 by @UnamedRus, split up as discussed in the review of that pull request. Only the tokenizer and
m['key'] = 'value'are here;m['key'] IN (...),mapContainsKey,mapContainsValue, theLIKEand prefix/suffix forms, and the newmapContainsKeyValue/mapContainsKeyValueLikefunctions are left for follow-ups. As a result nothing outside the tokenizer, the index aggregator and the index condition needs to change:TextIndexAnalyzer,MergeTreeReaderTextIndexandoptimizeDirectReadFromTextIndexare untouched.The token layout is
varint((length(key) << 1) | is_rest) ‖ key ‖ value. The length prefix keeps the key/value boundary unambiguous, so keys and values may contain arbitrary bytes, and it makes the tokens of one key a contiguous range of the sorted dictionary, which a later range scan can use.is_restmarks a key's non-first occurrence in a row, so the lookup matches the same occurrence asm['key']when a row contains duplicate keys.Restrictions, all rejected at table creation: keys and values must be
StringorLowCardinality(String)(FixedStringwould store padding bytes that a searched constant does not have, silently missing rows), andpreprocessor,postprocessorandsupport_phrase_searchare not accepted.m['key'] = ''is also true for rows that do not contain the key at all, so that predicate falls back to a scan.This doesn't close issue #110454, because it asks for Map text-index support broadly and this only covers exact element equality.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
New text index tokenizer
keyValuePairs, which indexes aMap(String, String)column directly and answersmap['key'] = 'value'from the index without reading the map column.Workflow [PR]
Sync PR [sync-upstream/pr/115579]
Version info
26.9.1.1446(included in26.9and later)